void clsCMM::Input() { printf("[CMM] Input start\n"); ADDRESSEDPACKAGE package; while (1) { int nToRead = MAX_CMMBUFFER-m_nBuffer; int nRead = read(m_nsCMM, m_szBuffer+m_nBuffer, nToRead); if (nRead < 0) { nRead = 0; //read returns -1 on occassion of no byte read usleep(20000); continue; } m_nBuffer += nRead; #if (_DEBUG & DEBUGFLAG_CMM) printf("[CMM] ReadCommand, read byte %d, buffer size %d\n", nRead, m_nBuffer); #endif if (ParseBuffer(m_szBuffer, m_nBuffer, &package)) { ProcessPackage(&package); //analysis buffer to extrace telegraph package from it } usleep(20000); } }
void clsCMM::Listen() { //begin receive data struct sockaddr_in from; socklen_t fromlen = sizeof(from); ADDRESSEDPACKAGE package; printf("[CMM] Net started\n"); while (1) { int nRecv = ::recvfrom(m_socket, m_bufferNet, MAXSIZE_TELEGRAPH-m_nBufferNet, 0, (struct sockaddr *)&from, &fromlen); if (nRecv == -1) { printf("[CMM] socket disconnected.\n"); break; } // printf("[CMM] %d bytes received from %s\n", nRecv, inet_ntoa(from.sin_addr)); m_nBufferNet += nRecv; /* for (int i=0; i<m_nBufferNet; i++) { printf("%02x ", (unsigned char)m_bufferNet[i]); } printf("\n");*/ if (ParseBuffer(m_bufferNet, m_nBufferNet, &package)) { ProcessPackage(&package); //analysis buffer to extrace telegraph package from it } // usleep(20000); //so far only process packages from ground station } ::close(m_socket); }
/* * BSDReceive * * 接收数据 * 将数据循环接收到receive_data[]缓冲区中, * 并从中分离出包 * (对于终端来说,接收到的包类型只有“控制”一种。。。) * * 应该单独开一个线程专门接收数据。。。 */ void BSDReceive(void) { static void *receive_buff = (void*)receive_data; int rec_num; while(1) { rec_num = recv(client_fd, receive_buff, 128, 0); if(rec_num > 0){ int n; printf("received:\n\t"); for(n = 0; n < rec_num; n++) { printf("%4x", receive_data[n] & 0xff); } printf("\n"); ProcessPackage((com_pack*)receive_buff); } else { printf("nothing received...\n"); } sleep(1); } }
INT KGC_CoordinatorClient::Activate() { if (!m_piSocket) return Connect(m_strCoordinatorIp.c_str(), m_nCoordinatorPort); ProcessPackage(); return TRUE; }
int main(int argc, char * argv[]) { sPackage * psRcvPackage; while (1) { if (udp.available() > 0) { psRcvPackage = NULL; psRcvPackage = RecebePacote(ETHERNET); if (psRcvPackage == NULL) { continue; } ProcessPackage(psRcvPackage); } if (Serial.available() > 0) { psRcvPackage = NULL; psRcvPackage = RecebePacote(SERIAL); if (psRcvPackage == NULL) { continue; } ProcessPackage(psRcvPackage); } } }
void KPlayerServer::ProcessNetwork(void) { int nRetCode = false; while (true) { int nEventCount = 0; KG_SOCKET_EVENT* pSocketEvent = NULL; KG_SOCKET_EVENT* pSocketEventEnd = NULL; nRetCode = m_SocketServerAcceptor.Wait(m_nSocketEventCount, m_pSocketEventArray, &nEventCount); KGLOG_PROCESS_ERROR(nRetCode); if (nEventCount == 0) break; pSocketEventEnd = m_pSocketEventArray + nEventCount; for (pSocketEvent = m_pSocketEventArray; pSocketEvent < pSocketEventEnd; pSocketEvent++) { // Process new connection accept // KG_SOCKET_EVENT_ACCEPT event must be processed before any other event, // because Maybe uEventFlag = KG_SOCKET_EVENT_ACCEPT | KG_SOCKET_EVENT_IN. if (pSocketEvent->uEventFlag & KG_SOCKET_EVENT_ACCEPT) { ProcessNewConnection(pSocketEvent->piSocket); KG_COM_RELEASE(pSocketEvent->piSocket); continue; } if (!(pSocketEvent->uEventFlag & KG_SOCKET_EVENT_IN)) { KGLogPrintf(KGLOG_DEBUG, "Unexpected socket event: %u", pSocketEvent->uEventFlag); KG_COM_RELEASE(pSocketEvent->piSocket); continue; } ProcessPackage(pSocketEvent->piSocket); KG_COM_RELEASE(pSocketEvent->piSocket); } } Exit0: return; }
void KSimulateRelay::Activate() { ProcessAcceptor(); ProcessPackage(); }