1
µTasker general / Re: Newbie's firsttime with uTasker
« on: March 05, 2009, 05:19:54 AM »
Ok i've changed the following code and things seemed to have sped up a bit but it's like it comes in bursts but just isn't a steady enough speed to keep communication with my device going.
Not sure if I placed the iRxReceived = iExpectedbytes = 0; in the correct place but it seems to work better now.
Now I'm not sure if buffered TCP would work since the device needs to make a request and then get a response before it can make another request or it'll just timeout and go back to the very first request it made.
Code: [Select]
static int fnReadIrd(unsigned char * buf)
{
static int iRxReceived = 0; // the number of byte received (until now)
static int iExpectedbytes = 0;
unsigned char ucInputMessage; // reserve space for receiving messages
iRxReceived = iExpectedbytes = 0;
while (fnRead(SerialPortID, &ucInputMessage, 1) != 0) { // read each presently available input byte
if (iRxReceived == 0) { // searching for sync byte
if (ucInputMessage != 0x21) {
continue; // still not found sync byte
}
iRxReceived = 1; // synchronised
buf[0] = ucInputMessage;
}
else {
if (iRxReceived >= RX_BUFFER_SIZE) { // protect buffer overrun on invalid frames
iRxReceived = iExpectedbytes = 0; // go back to sync hunt mode
continue;
}
buf[iRxReceived++] = ucInputMessage; // collect message content
if (iRxReceived == 3) { // the expected length is now known
iExpectedbytes = (ucInputMessage + 4); // note the expected length
}
if (iRxReceived == iExpectedbytes) { // the complete message has now been collected
return iExpectedbytes; // inform of the frame length so that it can be processed
}
}
}
return -1; // frame not yet ready
}
Not sure if I placed the iRxReceived = iExpectedbytes = 0; in the correct place but it seems to work better now.
Now I'm not sure if buffered TCP would work since the device needs to make a request and then get a response before it can make another request or it'll just timeout and go back to the very first request it made.