int getSerial(){ int res; char str[16]; mySerial.read(str,2); sscanf(str,"%d",&res); return res; }
void Recieve(uint8_t* in_buf) { // Read Header ardu.read( input_buffer, HEADER_SIZE ) ; for (int i=0; i<HEADER_SIZE; i++) memcpy(&in_buf[i],&input_buffer[i],sizeof(uint8_t)); // in_buf[i] = input_buffer[i]; #ifndef NDEBUG // Check Header fprintf(stdout, "Message header:\n"); for (int i=0; i<HEADER_SIZE; i++) { fprintf(stdout, " %02x",in_buf[i]); } fprintf(stdout, "\n\n"); #endif int N = buf[N_INDEX]; int L = buf[L_INDEX]+1; int nbytes_body = N * L; ardu.read( input_buffer, nbytes_body ) ; for (int i=0; i<nbytes_body; i++) memcpy(&in_buf[i+HEADER_SIZE],&input_buffer[i],sizeof(uint8_t)); // in_buf[i+HEADER_SIZE] = input_buffer[i]; #ifndef NDEBUG fprintf(stdout, "Message body:\n"); for (int i=0; i<N; i++) { for (int j=0; j<L; j++) { fprintf(stdout, " %02x",in_buf[HEADER_SIZE+i*L+j]); } fprintf(stdout, "\n"); } fprintf(stdout, "END\n"); #endif }
int main(int argc,char** argv) { char response[3]; serial_stream.Open( argv[1] ) ; serial_stream.SetBaudRate( SerialStreamBuf::BAUD_115200 ) ; serial_stream.SetCharSize( SerialStreamBuf::CHAR_SIZE_8 ) ; serial_stream.SetFlowControl( SerialStreamBuf::FLOW_CONTROL_NONE ) ; serial_stream.SetParity( SerialStreamBuf::PARITY_NONE ) ; serial_stream.SetNumOfStopBits(0) ; while (1) { serial_stream<<"ABCD"; cout<<"waiting response"<<endl; serial_stream.read(response,3); cout<<response<<endl; } return 0; }
void read(char *in, size_t numbytes){ ardu.read(in,numbytes); }