uint receiveVar(char* p_c) { // Receive the data by stepping the machine until it outputs // something do { // While there's no data, run the timeout counter RECEIVE_ERROR re; uint32_t u32_count = 0; while (!isCharReady()) { if (u32_count < RECEIVE_TIMEOUT) u32_count++; doHeartbeat(); } // Step the machine *p_c = inChar(); if (u32_count >= RECEIVE_TIMEOUT) notifyOfTimeout(); re = stepReceiveMachine(*p_c); if (re != ERR_NONE) { outString("Data receive error: "); outString(getReceiveErrorString()); outChar('\n'); } } while (!isReceiveMachineChar() && !isReceiveMachineData()); // Note that p_c already contains the received character, since it's // always the last thing received from inChar(). return getReceiveMachineIndex(); }
int Comm::comm_gets( char *Buffer, int max ) { unsigned char c; int x=0; Buffer = NULL; do { ssize_t rv = read( m_fd, &c, 1 ); Buffer[ x++ ] = c; } while( isCharReady() && ( x<max ) ); Buffer[x-1]=0; return x; }
void Comm::FlushInQue( void ) { while( isCharReady() ) { comm_getc(); } }