// Receive full frame int SerialIntrf::Rx(int DevAddr, uint8_t *pBuff, int BuffLen) { int count = 0; if (pBuff && StartRx(DevAddr)) { count = RxData(pBuff, BuffLen); StopRx(); } return count; }
//*************************************************************************** //! \brief 主函数 //*************************************************************************** void main (void) { WDTR = 0x5A; SYS_Init(); // Wifi_Rest(); // while(1) { WDTR = 0x5A; LinkCheck (); // WiFi连接断开 检测 RxData (); // 串口接收数据处理 TxData (); // 串口数据发送 TimeFlag (); // 时间标志位处理 Sd_Send (); // 与主机通信 发送处理函数 Sd_Receive (); // 与主机通信 接受处理函数 } }
int main(void) { spi_init(); setup(); #ifdef Rx_mode cc2500_mode(1); //configure device in rx/tx mode (1 - rx ,0 - tx) #else if Tx_mode cc2500_mode(0); #endif while (1) { request_received = 1; // for testing only. // PWR_EnterSleepMode(PWR_SLEEPEntry_WFI); //wfi();// commented temporary by rb must remove it.(15/11/14) if (request_received) // must be high on external interrupt { request_received = 0; #ifdef Rx_mode RxData(); #else if Tx_mode TxData("id+key no which is pressed"); #endif } // loop_T(); not needed for receiver at this place. // loop_R(); if(take_action!=0) { switch(take_action) { case 49: led_toggle; case 50: ; default: ; } take_action = 0; } } }
/*=========================================================================== METHOD: SendCtl (Public Method) DESCRIPTION: Send a control message to the lower layer PARAMETERS: msgType [ I ] - eQMUXDMessageType pData [I/O] - input or output specific to ioctl request value RETURN VALUE: int - control message return value (0 for success) ===========================================================================*/ int cSocket::SendCtl( UINT msgType, void * pData ) { if (mSocket == INVALID_HANDLE_VALUE) { TRACE( "Invalid file handle\n" ); return -EBADFD; } BYTE msg[sizeof( sQMUXDHeader ) + PAYLOAD_SIZE]; memset( &msg[0], 0, sizeof( msg ) ); // The important QMUXD header values sQMUXDHeader * pHdr = (sQMUXDHeader *)&msg[0]; pHdr->mTotalSize = sizeof( msg ); pHdr->mQMUXDClientID = mQMUXDClientID; pHdr->mQMUXDMsgID = (eQMUXDMessageTypes)msgType; pHdr->mQMUXDClientIDDuplicate = mQMUXDClientID; // mQMUXDTxID could go to INT_MAX, but rather than dealing with possible // overflow in qmuxd or one of the lower layers, we'll stop early mQMUXDTxID++; if (mQMUXDTxID > 100000) { mQMUXDTxID = 1; } pHdr->mTxID = ++mQMUXDTxID; // The Payload BYTE * pPayload = &msg[sizeof( sQMUXDHeader )]; if (msgType == (int)eQMUXD_MSG_ALLOC_QMI_CLIENT_ID) { memcpy( &mQMUXServiceID, pData, 4 ); memcpy( &pPayload[0], &mQMUXServiceID, 4 ); } else if (msgType == (int)eQMUXD_MSG_RELEASE_QMI_CLIENT_ID) { memcpy( &pPayload[0], &mQMUXServiceID, 4 ); memcpy( &pPayload[4], &mQMUXClientID, 4 ); } // Send the message int rc = send( mSocket, &msg[0], sizeof( msg ), 0 ); if (rc != sizeof( msg )) { TRACE( "bad write %d\n", rc ); return rc; } if (mpRxCallback == 0) { // No one is currently reading, need to trigger a read // so our data can be recieved RxData( &msg[0], sizeof( msg ), 0 ); } // Wait for the response (10s timeout) DWORD val; rc = mCtrlMsgComplete.Wait( 10000, val ); if (rc != 0) { TRACE( "bad SendCtl() wait %d\n", rc ); return rc; } if (msgType == (int)eQMUXD_MSG_ALLOC_QMI_CLIENT_ID) { // Grab the client ID mQMUXClientID = val; } return 0; }
void loop_R() { Read_Config_Regs(); RxData(); }
RF= 0; LF= 0; RB= 0; LB= 0; } /*************************************************************************** * Function: Interrupt Service Routine * Input: none * Output: none * Logic: whenever serial interrupt occurs it executes this routine * and after this it returns to the main function * serial interrupt occurs whenever data is recieved or transmitted. ****************************************************************************/ void serial_int_isr(void)interrupt 4 { rx_data = RxData(); //get the received data datasend(rx_data); RI = 0; //Clear receive interrupt. Must be cleared by the user. TI = 0; //Clear transmit interrupt. Must be cleared by the user. if (rx_data== 0x38) buzzer=0; //buzzer on if (rx_data == 0x39) buzzer = 1; //buzzer off if(rx_data==0x30) forward(); //move forward if(rx_data==0x31) backward(); //move backward if(rx_data==0x32) right(); //turn right if(rx_data==0x33) left(); //turn left