Zac Dannelly
/
fullAppBoardGet
Reveive the full data from the application board
main.cpp@0:89906fbcaff9, 2015-04-19 (annotated)
- Committer:
- dannellyz
- Date:
- Sun Apr 19 19:37:35 2015 +0000
- Revision:
- 0:89906fbcaff9
Code to receive the full appborad data
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dannellyz | 0:89906fbcaff9 | 1 | // Example of parsing the serial string from the fullAppBaordSend |
dannellyz | 0:89906fbcaff9 | 2 | /* Code derived from the work of Joe Bradshaw: |
dannellyz | 0:89906fbcaff9 | 3 | http://developer.mbed.org/users/jebradshaw/ */ |
dannellyz | 0:89906fbcaff9 | 4 | /******************Declaration of necessary libraries and objects************************/ |
dannellyz | 0:89906fbcaff9 | 5 | #include "mbed.h" |
dannellyz | 0:89906fbcaff9 | 6 | DigitalOut myled(LED1); //LED to show functionality |
dannellyz | 0:89906fbcaff9 | 7 | Serial pc(USBTX, USBRX); //tx, rx via USB connection |
dannellyz | 0:89906fbcaff9 | 8 | Serial xbee(p9, p10); //tx, rx via Xbee socket |
dannellyz | 0:89906fbcaff9 | 9 | int main() { |
dannellyz | 0:89906fbcaff9 | 10 | /******************Establishment of Vaiables*********************************************/ |
dannellyz | 0:89906fbcaff9 | 11 | char abstr[25]; //used to store the whole app board string |
dannellyz | 0:89906fbcaff9 | 12 | int joystick; //int value corresponding to the joystick bus |
dannellyz | 0:89906fbcaff9 | 13 | float Lpot; //float corresponding to left potentiometer |
dannellyz | 0:89906fbcaff9 | 14 | float Rpot; //float corresponding to right potentiometer |
dannellyz | 0:89906fbcaff9 | 15 | /******************While loop call to run code indefinitely******************************/ |
dannellyz | 0:89906fbcaff9 | 16 | while(1) { |
dannellyz | 0:89906fbcaff9 | 17 | //clear out the remaining characters in the buffer |
dannellyz | 0:89906fbcaff9 | 18 | while(xbee.readable()) |
dannellyz | 0:89906fbcaff9 | 19 | char c = xbee.getc(); |
dannellyz | 0:89906fbcaff9 | 20 | //read the serial string from the xbee (starts with '$', ends with \r\n |
dannellyz | 0:89906fbcaff9 | 21 | xbee.scanf("$%s\r\n", &abstr); |
dannellyz | 0:89906fbcaff9 | 22 | //Verify that the string has the APPBOARD header |
dannellyz | 0:89906fbcaff9 | 23 | if(strncmp(abstr, "APPBOARD", 9)){ |
dannellyz | 0:89906fbcaff9 | 24 | //Verify the tring was able to be parsed |
dannellyz | 0:89906fbcaff9 | 25 | if (sscanf(abstr, "APPBOARD,%f,%f,%d",&Lpot,&Rpot,&joystick) >= 1) { |
dannellyz | 0:89906fbcaff9 | 26 | //Print values to screen |
dannellyz | 0:89906fbcaff9 | 27 | pc.printf("Mbed: L-%.02f: R-%.02f Joystick:%d\r\n",Lpot,Rpot,joystick);} |
dannellyz | 0:89906fbcaff9 | 28 | //Incorrect parse |
dannellyz | 0:89906fbcaff9 | 29 | else{pc.printf("BAD parse %s\r\n", abstr);} |
dannellyz | 0:89906fbcaff9 | 30 | }//if(sscanf |
dannellyz | 0:89906fbcaff9 | 31 | myled = !myled; //toggle LED for activity verification |
dannellyz | 0:89906fbcaff9 | 32 | }//while(1) |
dannellyz | 0:89906fbcaff9 | 33 | }//main |