Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
[fw/altos] / src / ao_gps.c
index 811ac2a8aae0aee4f1a3c0643da7c61e3aa34ff7..c4c434fdba41885384d2ffa8fbf638b42018f3d8 100644 (file)
 __xdata uint8_t ao_gps_mutex;
 __xdata struct ao_gps_data     ao_gps_data;
 
-static const char ao_gps_set_nmea[] = "$PSRF100,0,57600,8,1,0*37\r\n";
+static const char ao_gps_set_nmea[] = "\r\n$PSRF100,0,57600,8,1,0*37\r\n";
 
 const char ao_gps_config[] = {
+
        0xa0, 0xa2, 0x00, 0x0e, /* length: 14 bytes */
        136,                    /* mode control */
        0, 0,                   /* reserved */
@@ -224,17 +225,18 @@ ao_sirf_parse_41(void)
        }
 }
 
-void
+static void
 ao_gps_setup(void) __reentrant
 {
-       uint8_t i;
+       uint8_t i, k;
        ao_serial_set_speed(AO_SERIAL_SPEED_4800);
-       for (i = 0; i < 16; i++)
+       for (i = 0; i < 64; i++)
                ao_serial_putchar(0x00);
-       for (i = 0; i < sizeof (ao_gps_set_nmea) - 1; i++)
-               ao_serial_putchar(ao_gps_set_nmea[i]);
+       for (k = 0; k < 3; k++)
+               for (i = 0; i < sizeof (ao_gps_set_nmea); i++)
+                       ao_serial_putchar(ao_gps_set_nmea[i]);
        ao_serial_set_speed(AO_SERIAL_SPEED_57600);
-       for (i = 0; i < 16; i++)
+       for (i = 0; i < 64; i++)
                ao_serial_putchar(0x00);
 }
 
@@ -279,6 +281,7 @@ ao_gps(void) __reentrant
        uint8_t i, k;
        uint16_t cksum;
 
+       ao_gps_setup();
        for (k = 0; k < 5; k++)
        {
                for (i = 0; i < sizeof (ao_gps_config); i++)
@@ -289,9 +292,9 @@ ao_gps(void) __reentrant
        }
        for (;;) {
                /* Locate the begining of the next record */
-               while (ao_sirf_byte() != 0xa0)
+               while (ao_sirf_byte() != (uint8_t) 0xa0)
                        ;
-               if (ao_sirf_byte() != 0xa2)
+               if (ao_sirf_byte() != (uint8_t) 0xa2)
                        continue;
 
                /* Length */
@@ -321,9 +324,9 @@ ao_gps(void) __reentrant
                cksum |= ao_sirf_byte();
                if (ao_sirf_cksum != cksum)
                        continue;
-               if (ao_sirf_byte() != 0xb0)
+               if (ao_sirf_byte() != (uint8_t) 0xb0)
                        continue;
-               if (ao_sirf_byte() != 0xb3)
+               if (ao_sirf_byte() != (uint8_t) 0xb3)
                        continue;
 
                switch (i) {
@@ -332,7 +335,7 @@ ao_gps(void) __reentrant
                        ao_gps_data.hour = ao_sirf_data.utc_hour;
                        ao_gps_data.minute = ao_sirf_data.utc_minute;
                        ao_gps_data.second = ao_sirf_data.utc_second / 1000;
-                       ao_gps_data.flags = (ao_sirf_data.num_sv << AO_GPS_NUM_SAT_SHIFT) & AO_GPS_NUM_SAT_MASK;
+                       ao_gps_data.flags = ((ao_sirf_data.num_sv << AO_GPS_NUM_SAT_SHIFT) & AO_GPS_NUM_SAT_MASK) | AO_GPS_RUNNING;
                        if ((ao_sirf_data.nav_type & NAV_TYPE_GPS_FIX_TYPE_MASK) >= NAV_TYPE_4_SV_KF)
                                ao_gps_data.flags |= AO_GPS_VALID;
                        ao_gps_data.latitude = ao_sirf_data.lat;