X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=src%2Fao_gps.c;h=562899cd030c2a24405ea9b0ac00e34bad82747b;hp=147b665c363de0cdc63a929254ea96f9f07f1c9f;hb=bfe1e76c82738baaf65abbc58c3244a07ea8fefe;hpb=ee4919dd771b00e2a2dd1083c9528efa7baab50f diff --git a/src/ao_gps.c b/src/ao_gps.c index 147b665c..562899cd 100644 --- a/src/ao_gps.c +++ b/src/ao_gps.c @@ -15,17 +15,34 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#ifndef AO_GPS_TEST #include "ao.h" +#endif __xdata uint8_t ao_gps_mutex; __xdata struct ao_gps_data ao_gps_data; -const char ao_gps_config[] = { - /* Serial param - binary, 4800 baud, 8 bits, 1 stop, no parity */ +const char ao_gps_set_binary[] = { '$', 'P', 'S', 'R', 'F', '1', '0', '0', ',', '0', ',', - '4', '8', '0', '0', ',', '8', ',', '1', ',', '0', '*', - '0', 'F', '\r','\n', + '9', '6', '0', '0', ',', '8', ',', '1', ',', '0', '*', + '0', 'C', '\r','\n', + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + 0xa0, 0xa2, 0x00, 0x09, /* length 9 bytes */ + 134, /* Set binary serial port */ + 0, 0, 0x25, 0x80, /* 9600 baud */ + 8, /* data bits */ + 1, /* stop bits */ + 0, /* parity */ + 0, /* pad */ + 0x01, 0x34, 0xb0, 0xb3, +}; +const char ao_gps_config[] = { 0xa0, 0xa2, 0x00, 0x0e, /* length: 14 bytes */ 136, /* mode control */ 0, 0, /* reserved */ @@ -44,22 +61,6 @@ const char ao_gps_config[] = { 143, /* static navigation */ 0, /* disable */ 0x00, 0x8f, 0xb0, 0xb3, - - 0xa0, 0xa2, 0x00, 0x08, /* length: 8 bytes */ - 166, /* Set message rate */ - 2, /* enable/disable all messages */ - 0, /* message id (ignored) */ - 0, /* update rate (0 = disable) */ - 0, 0, 0, 0, /* reserved */ - 0x00, 0xa8, 0xb0, 0xb3, - - 0xa0, 0xa2, 0x00, 0x08, /* length: 8 bytes */ - 166, /* Set message rate */ - 0, /* enable/disable one message */ - 41, /* message 41 */ - 1, /* once per second */ - 0, 0, 0, 0, /* reserved */ - 0x00, 0xd0, 0xb0, 0xb3, }; #define NAV_TYPE_GPS_FIX_TYPE_MASK (7 << 0) @@ -233,15 +234,72 @@ ao_sirf_parse_41(void) } } +void +ao_gps_setup(void) __reentrant +{ + uint8_t i, j; + for (j = 0; j < 2; j++) { +#ifdef AO_GPS_TEST + ao_serial_set_speed(j); +#endif + for (i = 255; i != 0; i--) + ao_serial_putchar(0); + + for (i = 0; i < sizeof (ao_gps_set_binary); i++) + ao_serial_putchar(ao_gps_set_binary[i]); + } +} + +static const char ao_gps_set_message_rate[] = { + 0xa0, 0xa2, 0x00, 0x08, + 166, + 0, +#define SET_MESSAGE_RATE_ID 6 +#define SET_MESSAGE_RATE 7 + +}; + +void +ao_sirf_set_message_rate(uint8_t msg, uint8_t rate) +{ + uint16_t cksum = 0x00a6; + uint8_t i; + + for (i = 0; i < sizeof (ao_gps_set_message_rate); i++) + ao_serial_putchar(ao_gps_set_message_rate[i]); + ao_serial_putchar(msg); + ao_serial_putchar(rate); + cksum = 0xa6 + msg + rate; + for (i = 0; i < 4; i++) + ao_serial_putchar(0); + ao_serial_putchar((cksum >> 8) & 0x7f); + ao_serial_putchar(cksum & 0xff); + ao_serial_putchar(0xb0); + ao_serial_putchar(0xb3); +} + +static const uint8_t sirf_disable[] = { + 2, + 4, + 9, + 10, + 27, + 50, + 52, + 4, +}; + void ao_gps(void) __reentrant { - char c; uint8_t i; uint16_t cksum; - for (i = 0; (c = ao_gps_config[i]); i++) - ao_serial_putchar(c); + for (i = 0; i < sizeof (ao_gps_config); i++) + ao_serial_putchar(ao_gps_config[i]); + for (i = 0; i < sizeof (sirf_disable); i++) + ao_sirf_set_message_rate(sirf_disable[i], 0); + ao_sirf_set_message_rate(41, 1); for (;;) { /* Locate the begining of the next record */ while (ao_sirf_byte() != 0xa0) @@ -259,10 +317,11 @@ ao_gps(void) __reentrant /* message ID */ i = data_byte (); /* 0 */ + printf ("message %d len %d\n", i, ao_sirf_len); switch (i) { case 41: - if (ao_sirf_len < 91) + if (ao_sirf_len < 90) break; ao_sirf_parse_41(); break; @@ -290,6 +349,21 @@ ao_gps(void) __reentrant ao_gps_data.flags = (ao_sirf_data.num_sv << AO_GPS_NUM_SAT_SHIFT) & AO_GPS_NUM_SAT_MASK; 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; + ao_gps_data.longitude = ao_sirf_data.lon; + ao_gps_data.altitude = ao_sirf_data.alt_msl / 100; + ao_gps_data.ground_speed = ao_sirf_data.ground_speed; + ao_gps_data.course = ao_sirf_data.course / 200; + ao_gps_data.hdop = ao_sirf_data.hdop; + ao_gps_data.climb_rate = ao_sirf_data.climb_rate; + if (ao_sirf_data.h_error > 6553500) + ao_gps_data.h_error = 65535; + else + ao_gps_data.h_error = ao_sirf_data.h_error / 100; + if (ao_sirf_data.v_error > 6553500) + ao_gps_data.v_error = 65535; + else + ao_gps_data.v_error = ao_sirf_data.v_error / 100; ao_mutex_put(&ao_gps_mutex); ao_wakeup(&ao_gps_data); break;