Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
M mx my x1 y1 x2 y2 pixels confidence
M 30 29 6 15 43 89 11 7
77 32 51 48 32 50 57 32 54 32 49 53 32 52 51 32 56 57 32 49 49 32 55 13
M 0 0 0 0 0 0 0 0M 3 9 6 5 3 9 1 7
//Receive Repeat Response data from Blackfin, store into an array of size response_countervoid 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 int middleten; int middle; rprintfInit(uart1SendByte);//change UART to bluetooth while(1) { 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 } } } }
//Receive Repeat Response data from Blackfin, store into an array of size response_countervoid CMUcam_Echo(int response_counter) //echos # of characters expected for each command{ signed char temp; int state = 1; response[0] = 0; // 0 bytes in "response" are set while(state) { temp = uart0GetByte(); // read next byte; If we've got -1 then we need to bail out! if (temp == -1) state = 0; // No more chars available! Bail out! else switch (state) { case 1: // Start state (hunt for chars state) switch(temp) { case ' ': break; // ignore all spaces case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': // I'm going to start reading an new byte! response[0]++; // Start an new byte, count the byte! response[response[0]] = temp & 0x0F; // Init the response state=2; // Let the state machine know we're reading an number break; case 'M': // Add a similar for each other letter you might expect in the stream case 'X': // Example of an other letter response[0]++; response[response[0]]=temp; if (response[0] >= (response_counter-1)) state = 0; break; case 13: case 10: // Bug. Why am I getting "-1"? state = 0; break; default: // Error! I encountered something that shouldn't be! response[0]=0; state = 0; break; } break; case 2: // Read number switch (temp) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': response[response[0]] = (response[response[0]] * 10) + (temp & 0x0F); break; case ' ': // I'm done with this char if (response[0] >= (response_counter-1)) state = 0; else state=1; break; case 13: case 10: state = 0; break; default: // Input error! I encountered something that shouldn't be! response[0]=0; state=0; break; } break; default: // Bug! How do you handle such errors on an MCU? state = 0; break; } } // Ok, I'm done parsing the input! // This code was in the original proc, I'm not sure what it does / if it's necesary //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}
I'm in state "1"? Expect an "M", an number or an space char; If I get an "M" mark it and stay in state 1; If I get an space ignore it and stay in state 1; If I get an number start reading the number and move to state 2! I'm in state 2? If the current char is an number add it to the previously read number; If it's something else then mark the number done and go back to state "1"
//Receive Repeat Response data from Blackfin, store into an array of size response_countervoid CMUcam_Echo(int response_counter) //echos # of characters expected for each command{ signed char temp; response[0] = 0; // 0 bytes in "response" are set temp = uart0GetByte(); while((response[0] < (response_counter-1)) && (temp != -1)) { if ((temp >= '0') && (temp <= '9')) { response[0]++; response[response[0]] = temp & 0x0F; temp = uart0GetByte(); while ((temp >= '0') && (temp <= '9')) { response[response[0]] = (response[response[0]] * 10) + (temp & 0x0F); temp = uart0GetByte(); } } else if (temp == ' ') { temp = uart0GetByte(); // Ignore space } else if (temp == 'M') { // Do something with the "M" if you find it interesting temp = uart0GetByte(); // Prep the next byte } else temp = -1; // bail out } // Ok, I'm done parsing the input! // This code was in the original proc, I'm not sure what it does / if it's necesary //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}
Funny how I was using Finite State Machines all this time in some of my other software projects and I didn't even know it had a name.
And out of curiosity, why do you want to use Raw Serial output mode?