Beispiel #1
0
/*------------------------------------------------------------
 * Function Name  : BootLink
 * Description    : 上电后联机
 * Input          : None
 * Output         : None
 * Return         : None
 *------------------------------------------------------------*/
void BootLink( void )
{
	uint8_t process = 0;
	uint32_t cnt = 0;
	const uint8_t FONT_SIZE = 16;
	const uint16_t draw_process_x = 360;
	const uint16_t draw_process_y = 350;											
	
	//初始化警告
	InitErr(&GeneralWarning);
	
	link_init();

	lcd_show_image(303,80,LOGO_PIC);	//加载鑫高LOGO
	
	lcd_show_image(draw_process_x-1,draw_process_y-1,PROCESS_PIC);
	
	SetGeneralTimeOut(0);
	
	while ( 1 )
	{
		link_cycle(&process);

		if (GetGeneralTimeOut() == TIMEOUT)		
		{
			SetGeneralTimeOut(10);
			cnt++;
			
			DrawProcess(FONT_SIZE,process,draw_process_x,draw_process_y);
		}
		
		LoadStartMachineWords(cnt);

		if (LINK_SUCCESS == GetLinkStatus())	   //联机成功
		{
			SetLinkStatus(LINK_IDLE);	
			
 			LssuedProtectBit();		//设置系统保护位 			
			PCM_GeneralWarningHandlerProcess(BLACK);				
			break;	
		}

		if (cnt > MIN_CNT_LINK_WAIT)					  //联机时,收到数据等待时间
		{
			if ( process )
			{
				if (cnt > MAX_CNT_LINK_WAIT)
				{
					SetLinkStatus(LINK_UNLINK);	
					break;
				}
			}
			else
			{
				SetLinkStatus(LINK_UNLINK);			
				break;
			}													
		}
	}	
}
DWORD WINAPI SFMReader(PVOID pData)
{
	CRDPSFMData	*device = reinterpret_cast<CRDPSFMData*>(pData);
	Debug::PrintLine(Debug::FIBRE, "This is reader %d %d", device->Card(), device->Port());

	GetLinkControl(device);
	GetLinkStatus(device);
	while (!device->Kill()) {
		// Reset the SFM port to make sure the inbound and outbound buffers are empty.
		SFMInterface::doFlushFifos(device->mHandle);

		//Debug::PrintLine(Debug::FIBRE, "SFMReader %d %d waiting on handle %d", device->Card(), device->Port(),
		//								device->GetStartReadHandle());
		DWORD state = WaitForSingleObject(device->GetStartReadHandle(), 2000);
		//Debug::PrintLine(Debug::FIBRE, "SFMReader %d %d: WaitForSingleObject returned %d", device->Card(), device->Port(), state);
		GetLinkControl(device);
		GetLinkStatus(device);
		if (state == WAIT_TIMEOUT) {
			//Debug::PrintLine(Debug::FIBRE, "SFMReader %d %d: startRead timeout", device->Card(), device->Port());
		} else if (state == WAIT_FAILED) {
			Debug::PrintLine(Debug::FIBRE, "SFMReader %d %d: startRead wait failed - %d", device->Card(), device->Port(), GetLastError());
		} else if (state != WAIT_OBJECT_0) {
			Debug::PrintLine(Debug::FIBRE, "SFMReader %d %d: startRead wait returned %d", device->Card(), device->Port(), state);
		} else {
			// signalled,  Start reading
			Debug::PrintLine(Debug::FIBRE, "SFMReader %d %d: startRead signalled", device->Card(), device->Port());
			Debug::PrintLine(Debug::FIBRE, "SFMReader %d %d: reading %d pulses", device->Card(), device->Port(), device->GetPulses());
			device->InitialiseRead();
			while (!device->ReadTransferComplete()) {
				//Sleep(3000);	// TEMP delay
				for (int chanOffset = 0; chanOffset < Global::CHANNELS_PER_FIBRE; chanOffset++) {
					device->ReceiveData(chanOffset);	// read channel A, B
				}
				device->IncrementReadCount();
			}	// while (!device->ReadTransferComplete())
			Debug::PrintLine(Debug::FIBRE, "SFMReader setting readcomplete on %d", device->GetReadCompleteHandle());
			SetEvent(device->GetReadCompleteHandle());
		}
		device->ClearAbortRead();
	}
	Debug::PrintLine(Debug::FIBRE, "SFMReader %d %d about to exit", device->Card(), device->Port());
	CloseHandle(device->mHandle);
	device->mHandle = INVALID_HANDLE_VALUE;
	Debug::PrintLine(Debug::FIBRE, "SFMReader %d %d exits", device->Card(), device->Port());
	return 0;
}
/*------------------------------------------------------------
 * Function Name  : HardTestInit
 * Description    : 初始化
 * Input          : None
 * Output         : None
 * Return         : None
 *------------------------------------------------------------*/
void HardTestInit( void )
{
	//初始化虚拟键	
	DummyKeyInit(&DummyKey,GUI_HardTestPageFuncKey);
	
	//按键初始化
	KeyValueInit();
	
	if (GetLinkStatus() != LINK_IDLE)
	{
		strcpy(HardTest.data_left[ABSOLUTE_LEFT],"------");
		strcpy(HardTest.data_left[OPPOSITE_LEFT],"------");
		strcpy(HardTest.data_right[ABSOLUTE_RIGHT],"------");
		strcpy(HardTest.data_right[OPPOSITE_RIGHT],"------");
	}
}
/*
 * Function:     wimaxcu_get_user_link_status
 * Description:  Get the link status
 * Return:       0 for success (connected) or 1 for failure
 */
int wimaxcu_get_user_link_status(WIMAX_API_DEVICE_ID_P p_device_id)
{
	WIMAX_API_RET wmxStatus = WIMAX_API_RET_SUCCESS;
	WIMAX_API_CONNECTED_NSP_INFO ConnectedNSP;
	WIMAX_API_LINK_STATUS_INFO LinkStatus;

	wmxStatus = GetConnectedNSP(p_device_id, &ConnectedNSP);
	if (WIMAX_API_RET_SUCCESS != wmxStatus) {
		printf("Link Status: Network is not connected.\n");
		return 1;
	}
	wmxStatus = GetLinkStatus(p_device_id, &LinkStatus);
	if (WIMAX_API_RET_SUCCESS != wmxStatus) {
		PrintWmxStatus(wmxStatus);
		return 1;
	}
	PrintUserLinkStatus(&LinkStatus);
	return 0;
}
/*
 * Function:
 * Description:
 * Param:
 * Return:
 */
void wimaxcu_get_conn_nsp(WIMAX_API_DEVICE_ID_P p_device_id)
{
	WIMAX_API_RET wmxStatus = WIMAX_API_RET_SUCCESS;
	WIMAX_API_CONNECTED_NSP_INFO ConnectedNSP;
	WIMAX_API_LINK_STATUS_INFO LinkStatus;

	wmxStatus = GetLinkStatus(p_device_id, &LinkStatus);
	if (WIMAX_API_RET_SUCCESS != wmxStatus) {
		PrintWmxStatus(wmxStatus);
		return;
	}

	wmxStatus = GetConnectedNSP(p_device_id, &ConnectedNSP);
	if (WIMAX_API_RET_SUCCESS != wmxStatus) {
		PrintWmxStatus(wmxStatus);
		return;
	}
	ConnectedNSP.RSSI = LinkStatus.RSSI;
	ConnectedNSP.CINR = LinkStatus.CINR;
	PrintConnectedNSPInfo(&ConnectedNSP);
}
/*------------------------------------------------------------
 * Function Name  : GetHardTestDataFromPrm
 * Description    : 从下位机获取数据
 * Input          : None
 * Output         : None
 * Return         : None
 *------------------------------------------------------------*/
void GetHardTestDataFromPrm( void )
{
	static uint8_t sendType = 0;
	static STATUS_CMD_ENCHANGE_TypeDef s_statusCmd = SEND_CMD_ENCHANGE;
	
	comm_cycle(&smpl_c);
	
	if (GetLinkStatus() != LINK_IDLE)
	{
		return;
	}
	
	switch ( s_statusCmd )
	{
		case SEND_CMD_ENCHANGE:
			sendType ^= 0x01;
			if (sendType)
			{
				cmd_send_start_pkg(pPCM_Lssued,SEND_ACODE);
				s_statusCmd = SEND_CMD_ABSOLUTE_WAIT;
			}
			else
			{
				cmd_send_start_pkg(pPCM_Lssued,SEND_RCODE);	
				s_statusCmd = SEND_CMD_RELATIVE_WAIT;
			}			
			break;
			
		case SEND_CMD_ABSOLUTE_WAIT:
			if (GetStatusPrmReply() == ERROR)
			{
				return;
			}
			SetSendCmdTimeOut(100);
			s_statusCmd = SEND_CMD_ABSOLUTE;
			break;
			
		case SEND_CMD_ABSOLUTE:
			if (GetSendCmdTimeOut() == TIMEOUT)
			{
				GetInputDataFromPrm();
				GetAbsoluteCodeFromPrm();
				RefreshHardTest(ABSOLUTE_CODE);
				s_statusCmd = SEND_CMD_ENCHANGE;
			}
			break;
		
		case SEND_CMD_RELATIVE_WAIT:
			if (GetStatusPrmReply() == ERROR)
			{
				return;
			}
			SetSendCmdTimeOut(100);
			s_statusCmd = SEND_CMD_RELATIVE;
			break;
		
		case SEND_CMD_RELATIVE:
			if (GetSendCmdTimeOut() == TIMEOUT)
			{
				GetInputDataFromPrm();
				GetOppositeCodeFromPrm();
				RefreshHardTest(OPPOSITE_CODE);
				s_statusCmd = SEND_CMD_ENCHANGE;
			}
			break;
	}
}