I have the CMUcam Version 1 and I am interfacing it with the Axon.
I'm having an issue with receiving a packet from the CMUcam because the packets can be of different lengths.
For example for the track color command , I receive back the following type of packet. Please note that the packet received is in ASCII so '30' is really two bytes - '3' and '0'
M mx my x1 y1 x2 y2 pixels confidence
So for example I could receive the following packet
M 30 29 6 15 43 89 11 7
That packet above is really 24 individual bytes
77 32 51 48 32 50 57 32 54 32 49 53 32 52 51 32 56 57 32 49 49 32 55 13
In my code I have each ASCII number converted to decimal , so the character '3' is converted to the value 3.
My problem is as follows:
I could receive a packet that is short and not necessarily 24 individual bytes
For example , I could get one of these
M 0 0 0 0 0 0 0 0
M 3 9 6 5 3 9 1 7
This means that I can't just do CMUcam_Echo(23); , because I don't know how many characters to expect
I guess my only option is to not expect any exact number of characters, and after every space character ( decimal value of 32) then expect one more character. Then once I receive the \r (carriage return) byte ( decimal value of 13), I know that I am done taking in bytes.
Is there another way to do it?
P.S. The CMUcam_Echo is just a modified version of Admin's Blackfin_Echo
//Receive Repeat Response data from Blackfin, store into an array of size response_counter
void CMUcam_Echo(int response_counter) //echos # of characters expected for each command
int temp; // set up temporary variable
int counter=0; //set the counter to 0
rprintfInit(uart1SendByte);//change UART to bluetooth
temp=uart0GetByte();//returns -1 if no data present
if (temp != -1)//if data received
// rprintf("%c",temp); // send "temp" out to USB
response[counter]=temp & 0x0F;//store values into an array, &0x0F strips ascii off to use in char strings
counter++; // add one to "counter" array
if(counter >= response_counter || temp == '\n') // once the counter equals the echo_counter OR you get a new line from the temp
rprintf("\r\n\r\n"); // send out carrier return and new line out to USB
uartFlushReceiveBuffer(0);//flush out receive camera buffer to stop phase shifting
break; //Get out of the while routine and exit the subroutine