2018 revision to classic DataBus AVC code.

Dependencies:   LSM303DLM Servo SerialGraphicLCD L3G4200D IncrementalEncoder SimpleShell

Files at this revision

API Documentation at this revision

Comitter:
shimniok
Date:
Sun Dec 16 04:18:42 2018 +0000
Parent:
19:0d1728091519
Child:
21:020f4ebbb13a
Commit message:
Added gps interrupt handler, fixed command line gps query

Changed in this revision

Ublox6.cpp Show annotated file Show diff for this revision Revisions of this file
Ublox6.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Ublox6.cpp	Sat Dec 15 21:38:11 2018 +0000
+++ b/Ublox6.cpp	Sun Dec 16 04:18:42 2018 +0000
@@ -46,7 +46,7 @@
     latest = tmp;
 }
 
-int Ublox6::parse(unsigned char cc)
+int Ublox6::parse(int cc)
 {
     //unsigned char cc = buf[out++];
     //out &= (MAX_LENGTH-1);
@@ -61,16 +61,13 @@
             checkOk = false;
             if (cc == SYNC1) {
                 state++;
-                puts("SYNC1");
             }
             break;
         case 1:    // wait for sync 2 (0x62)
             if (cc == SYNC2) {
                 state++;
-                puts("SYNC2");
             } else {
                 state = 0;
-                puts("NO SYNC2");
             }
             break;
         case 2:    // wait for class code
@@ -92,9 +89,7 @@
             state++;
             break;
         case 5:    // wait for length uint8_t 2
-            length |= (unsigned int) cc << 8;
-            printf("len=%d\n", length);
-            ck1 += cc;
+            length |= (unsigned int) cc << 8;            ck1 += cc;
             ck2 += ck1;
             idx = 0;
             state++;
@@ -116,9 +111,7 @@
         case 8: {  // wait for checksum 2
             chk2 = cc;
             checkOk = ck1 == chk1  &&  ck2 == chk2;
-            if (!checkOk) {
-                puts("BAD CHKSUM\n");
-            } else {
+            if (checkOk) {
                 switch (code) {
                 case 0x01:      // NAV-
                     switch (id) {
@@ -128,14 +121,12 @@
                         // vAcc = ULONG(24); // mm
                         // hAcc = ULONG(20); // mm
                         _ready |= POSLLH_BIT;
-                        puts("LAT/LON");
                         break;
                     case DOP_MSG:  // NAV-DOP
                         //gDOP = ((float) UINT(4))/100.0;
                         //tDOP = ((float) UINT(8))/100.0;
                         //vDOP = ((float) UINT(10))/100.0;
                         tmp.hdop = ((float) UINT(12))/100.0;
-                        puts("HDOP");
                         _ready |= DOP_BIT;
                         break;
                     case SOL_MSG:  // NAV-SOL
@@ -144,7 +135,6 @@
                         //pAcc = ULONG(24);
                         tmp.svcount = data[47];
                         _ready |= SOL_BIT;
-                        puts("SVCOUNT");
                         break;
                     case VELNED_MSG:  // NAV-VELNED
                         tmp.speed = ULONG(20)/100.0;
@@ -152,14 +142,10 @@
                         tmp.course = ((float) LONG(24))/100000.0;
                         //cAcc = ((float) LONG(32))/100000.0;
                         _ready |= VELNED_BIT;                                
-                        puts("SPD/COURSE");
                         break;
                     default:
-                        printf("OTHER=0x%04x\n", id);
                         break;
                     }
-                    if (_ready)
-                        printf("_ready = 0x%04x 0x%04x\n", _ready, READY_BITS);
                     break;
                 case 0x05:      // ACK-
                     switch (id) {
@@ -180,15 +166,16 @@
 
     if ((_ready & READY_BITS) == READY_BITS) {
         latest = tmp;
+        _ready = 0;
+        status = 1;
+
+        // clear tmp
         tmp.lat = 0;
         tmp.lon = 0;
         tmp.speed = 0;
         tmp.course = 0;
         tmp.hdop = 0;
         tmp.svcount = 0;
-        _ready = 0;
-        status = 1;
-        _available = true;
     }
 
     return status;
--- a/Ublox6.h	Sat Dec 15 21:38:11 2018 +0000
+++ b/Ublox6.h	Sun Dec 16 04:18:42 2018 +0000
@@ -21,7 +21,7 @@
      * @param cc is the character to parse
      * @return 1 when entire packet of data obtained, 0  otherwise
      */    
-    int parse(unsigned char cc);
+    int parse(int cc);
 
     /** Read the latest data from GPS
      * @param lat latitude in degrees
--- a/main.cpp	Sat Dec 15 21:38:11 2018 +0000
+++ b/main.cpp	Sun Dec 16 04:18:42 2018 +0000
@@ -26,20 +26,18 @@
 DigitalOut led1(LED1);
 DigitalOut led3(LED3);
 
+RawSerial s(UART1TX, UART1RX, 38400);
+
 void read_gps();
 
-void do_gps() {
-    RawSerial s(UART1TX, UART1RX, 38400);
-    while (1) {
-        int c = s.getc();
-        if (ublox.parse(c)) {
+void gps_handler() {
+    if (s.readable()) {
+        if (ublox.parse(s.getc())) {
             led3 = !led3;
-            read_gps();
         }
     }
 }
 
-
 /******** SHELL COMMANDS ********/
 
 void test() {
@@ -80,6 +78,15 @@
     printf("Encoder: %d\n", u->encoder());
 }
 
+void bridge_uart1() {
+    RawSerial s(UART1TX, UART1RX, 38400);
+    while (1) {
+        if (pc.readable()) s.putc(pc.getc());
+        if (s.readable()) pc.putc(s.getc());
+    }
+}
+
+
 void reset()
 {
     NVIC_SystemReset();
@@ -90,12 +97,11 @@
 // main() runs in its own thread in the OS
 int main()
 {   
+    //bridge_uart1();
+    
     printf("Bootup...\n");
     fflush(stdout);
     
-    do_gps();
-    while(1);
-    
     printf("Loading config...\n");
     config.add("intercept_distance", Config::DOUBLE);
     config.add("waypoint_threshold", Config::DOUBLE);
@@ -140,11 +146,15 @@
     updaterThread.start(callback(u, &Updater::start));
 
     printf("Starting gps...\n");
+    s.attach(&gps_handler);
+
+    /*
     Thread gpsThread;
     gpsThread.set_priority(osPriorityHigh);
     gpsThread.start(&do_gps);
+    */
     
-/*
+    /*
     FILE *fp;
     char buf[128];
     printf("Initializing the block device... ");