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