Colin Stearns / Mbed 2 deprecated qcControl

Dependencies:   mbed

Fork of dgps by Colin Stearns

Committer:
stearnsc
Date:
Tue Apr 01 17:58:35 2014 +0000
Revision:
8:28b866df62cf
Parent:
7:c75d5e5e6bfc
Child:
9:da906eeac51e
Child:
17:323fc40376d5
cs: move GPS parsing into handleGPS; initial flightControl implemented. Doesn't compile.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stearnsc 0:9c001c4e7bf4 1 #include "mbed.h"
stearnsc 0:9c001c4e7bf4 2 #include <string>
stearnsc 0:9c001c4e7bf4 3 #include <sstream>
dylanembed123 7:c75d5e5e6bfc 4 #include "adapt/usb.h"
dylanembed123 7:c75d5e5e6bfc 5 #include "adapt/camera.h"
stearnsc 8:28b866df62cf 6
stearnsc 0:9c001c4e7bf4 7 Serial pc(USBTX,USBRX);
stearnsc 0:9c001c4e7bf4 8 Serial xbee(p9,p10);//tx, rx
stearnsc 0:9c001c4e7bf4 9 Serial gps(p28,p27);
dylanembed123 6:434d20e99e49 10 Serial camera(p13,p14);
stearnsc 0:9c001c4e7bf4 11
stearnsc 0:9c001c4e7bf4 12 typedef struct {
stearnsc 0:9c001c4e7bf4 13 int latitude; //in .0001 minutes
stearnsc 0:9c001c4e7bf4 14 int longitude; //in .0001 minutes
stearnsc 0:9c001c4e7bf4 15 int altitude; //in decimeters
stearnsc 0:9c001c4e7bf4 16 int time; //in milliseconds
stearnsc 0:9c001c4e7bf4 17 } GpsData;
stearnsc 0:9c001c4e7bf4 18
stearnsc 8:28b866df62cf 19 void readSerial(Serial &s, char str[], int size)
stearnsc 8:28b866df62cf 20 {
stearnsc 8:28b866df62cf 21 for (int i = 0; i < size; i++) {
stearnsc 8:28b866df62cf 22 str[i] = s.getc();
stearnsc 0:9c001c4e7bf4 23 }
stearnsc 0:9c001c4e7bf4 24 }
stearnsc 0:9c001c4e7bf4 25
stearnsc 0:9c001c4e7bf4 26 //sends: "$<command>*<checksum>\r\l"
stearnsc 8:28b866df62cf 27 void sendGpsCommand(string command)
stearnsc 8:28b866df62cf 28 {
stearnsc 0:9c001c4e7bf4 29 uint8_t checksum = 0;
stearnsc 0:9c001c4e7bf4 30 pc.printf("Sending command to gps: ");
stearnsc 0:9c001c4e7bf4 31 gps.putc('$');
stearnsc 0:9c001c4e7bf4 32 pc.putc('$');
stearnsc 0:9c001c4e7bf4 33 char c;
stearnsc 8:28b866df62cf 34 for (int i = 0; i < command.length(); i++) {
stearnsc 0:9c001c4e7bf4 35 c = command[i];
stearnsc 0:9c001c4e7bf4 36 checksum ^= c;
stearnsc 0:9c001c4e7bf4 37 gps.putc(c);
stearnsc 0:9c001c4e7bf4 38 pc.putc(c);
stearnsc 0:9c001c4e7bf4 39 }
stearnsc 0:9c001c4e7bf4 40 gps.putc('*');
stearnsc 0:9c001c4e7bf4 41 pc.putc('*');
stearnsc 0:9c001c4e7bf4 42 string checkSumString;
stearnsc 8:28b866df62cf 43 while (checksum > 0) {
stearnsc 0:9c001c4e7bf4 44 uint8_t checksumChar = checksum & 0x0F;
stearnsc 8:28b866df62cf 45 if (checksumChar >= 10) {
stearnsc 0:9c001c4e7bf4 46 checksumChar -= 10;
stearnsc 8:28b866df62cf 47 checksumChar += 'A';
stearnsc 0:9c001c4e7bf4 48 } else {
stearnsc 8:28b866df62cf 49 checksumChar += '0';
stearnsc 0:9c001c4e7bf4 50 }
stearnsc 0:9c001c4e7bf4 51 checkSumString.push_back((char) checksumChar);
stearnsc 8:28b866df62cf 52 checksum = checksum >> 4;
stearnsc 0:9c001c4e7bf4 53 }
stearnsc 0:9c001c4e7bf4 54
stearnsc 8:28b866df62cf 55 for (int i = checkSumString.length() - 1; i >= 0; i--) {
stearnsc 0:9c001c4e7bf4 56 gps.putc(checkSumString[i]);
stearnsc 8:28b866df62cf 57 pc.putc(checkSumString[i]);
stearnsc 8:28b866df62cf 58 }
stearnsc 0:9c001c4e7bf4 59 gps.putc('\r');
stearnsc 0:9c001c4e7bf4 60 pc.putc('\r');
stearnsc 0:9c001c4e7bf4 61 gps.putc('\n');
stearnsc 0:9c001c4e7bf4 62 pc.putc('\n');
stearnsc 0:9c001c4e7bf4 63 }
stearnsc 8:28b866df62cf 64 //
stearnsc 8:28b866df62cf 65 ////cs: little endian parsing
stearnsc 8:28b866df62cf 66 //int nextInt(char *data, int i)
stearnsc 8:28b866df62cf 67 //{
stearnsc 8:28b866df62cf 68 // i |= data[i];
stearnsc 8:28b866df62cf 69 // i |= (data[i + 1] << 8);
stearnsc 8:28b866df62cf 70 // i |= (data[i + 2] << 16);
stearnsc 8:28b866df62cf 71 // i |= (data[i + 3] << 24);
stearnsc 8:28b866df62cf 72 // return i;
stearnsc 8:28b866df62cf 73 //}
stearnsc 0:9c001c4e7bf4 74
stearnsc 8:28b866df62cf 75 //void handleXbeeGps()
stearnsc 8:28b866df62cf 76 //{
stearnsc 8:28b866df62cf 77 // static bool reading = false;
stearnsc 8:28b866df62cf 78 // static char packet[16];
stearnsc 8:28b866df62cf 79 // static int i = 0;
stearnsc 8:28b866df62cf 80 //
stearnsc 8:28b866df62cf 81 // char c = xbee.getc();
stearnsc 8:28b866df62cf 82 // if (reading) {
stearnsc 8:28b866df62cf 83 // packet[i] = c;
stearnsc 8:28b866df62cf 84 // i++;
stearnsc 8:28b866df62cf 85 // if (i == 16) {
stearnsc 8:28b866df62cf 86 // i = 0;
stearnsc 8:28b866df62cf 87 // otherGps.latitude = nextInt(packet, 0);
stearnsc 8:28b866df62cf 88 // otherGps.longitude = nextInt(packet, 4);
stearnsc 8:28b866df62cf 89 // otherGps.altitude = nextInt(packet, 8);
stearnsc 8:28b866df62cf 90 // otherGps.time = nextInt(packet, 12);
stearnsc 8:28b866df62cf 91 //
stearnsc 8:28b866df62cf 92 // pc.printf("His GPS data: Lat: %d, Lon: %d, Alt: %d, Time:%d\r\n",
stearnsc 8:28b866df62cf 93 // otherGps.latitude, otherGps.longitude, otherGps.altitude, otherGps.time
stearnsc 8:28b866df62cf 94 // );
stearnsc 8:28b866df62cf 95 // reading = false;
stearnsc 8:28b866df62cf 96 // }
stearnsc 8:28b866df62cf 97 // } else if (c == 'X') {
stearnsc 8:28b866df62cf 98 // reading = true;
stearnsc 8:28b866df62cf 99 // }
stearnsc 8:28b866df62cf 100 //}
dylanembed123 7:c75d5e5e6bfc 101
dylanembed123 7:c75d5e5e6bfc 102
stearnsc 8:28b866df62cf 103 int main()
stearnsc 8:28b866df62cf 104 {
dylanembed123 7:c75d5e5e6bfc 105 ImageHandle imageHand;
dylanembed123 7:c75d5e5e6bfc 106 GPSHand gpsHand;
stearnsc 8:28b866df62cf 107
dylanembed123 7:c75d5e5e6bfc 108 /// Main Loop
stearnsc 8:28b866df62cf 109 while(true) {
stearnsc 8:28b866df62cf 110 gps.baud(57600);
stearnsc 8:28b866df62cf 111 xbee.baud(9600);
stearnsc 8:28b866df62cf 112 pc.baud(57600);
stearnsc 8:28b866df62cf 113
stearnsc 8:28b866df62cf 114 sendGpsCommand("PMTK301,1");
stearnsc 8:28b866df62cf 115 while(true) {
stearnsc 8:28b866df62cf 116 pc.putc(gps.getc());
stearnsc 8:28b866df62cf 117 }
stearnsc 8:28b866df62cf 118 gps.attach(&handleGpsData, Serial::RxIrq);
stearnsc 8:28b866df62cf 119 xbee.attach(&handleXbeeGps, Serial::RxIrq)//;
dylanembed123 6:434d20e99e49 120 }