Permalink
Browse files

Fixed number of sats and tidied up the GPS code a bit. still working …

…on temp sensor
  • Loading branch information...
1 parent 656fcaf commit 2c704b54f3600f9af5e12453a984ba39ea8717c2 @jonsowman jonsowman committed Mar 26, 2012
Showing with 18 additions and 49 deletions.
  1. +15 −44 firmware/gps.c
  2. +1 −2 firmware/gps.h
  3. +2 −3 firmware/main.c
View
@@ -36,7 +36,7 @@ void gps_init(void)
/**
* Poll the GPS for a position message then extract the useful
- * information from it.
+ * information from it - POSLLH.
*/
void gps_get_position(int32_t* lat, int32_t* lon, int32_t* alt)
{
@@ -103,63 +103,34 @@ void gps_get_time(uint8_t* hour, uint8_t* minute, uint8_t* second)
* Check the navigation status to determine the quality of the
* fix currently held by the receiver with a NAV-STATUS message.
*/
-uint8_t gps_check_lock(void)
+void gps_check_lock(uint8_t* lock, uint8_t* sats)
{
// Construct the request to the GPS
- uint8_t request[8] = {0xB5, 0x62, 0x01, 0x03, 0x00, 0x00,
- 0x04, 0x0D};
+ uint8_t request[8] = {0xB5, 0x62, 0x01, 0x06, 0x00, 0x00,
+ 0x07, 0x16};
_gps_send_msg(request, 8);
// Get the message back from the GPS
- uint8_t buf[24];
- for(uint8_t i = 0; i < 24; i++)
+ uint8_t buf[60];
+ for(uint8_t i = 0; i < 60; i++)
buf[i] = _gps_get_byte();
// Verify the sync and header bits
if( buf[0] != 0xB5 || buf[1] != 0x62 )
led_set(LED_RED, 1);
- if( buf[2] != 0x01 || buf[3] != 0x03 )
+ if( buf[2] != 0x01 || buf[3] != 0x06 )
led_set(LED_RED, 1);
- if( !_gps_verify_checksum(&buf[2], 20) ) led_set(LED_RED, 1);
+ // Check 60 bytes minus SYNC and CHECKSUM (4 bytes)
+ if( !_gps_verify_checksum(&buf[2], 56) ) led_set(LED_RED, 1);
- return buf[10];
-}
-
-/**
- * Return the number of satellites the receiver is currently
- * tracking using the RXM-SVSI message.
- */
-uint8_t gps_num_sats(void)
-{
- uint8_t request[8] = {0xB5, 0x62, 0x02, 0x20, 0x00, 0x00,
- 0x22, 0x68};
- _gps_send_msg(request, 8);
-
- // Get the message back from the GPS
- // The length of the message varies depending on the number of
- // sats we are tracking. We should really clock in all of the
- // message and verify the checksum. This solution is lazy.
- uint8_t buf[15];
- for(uint8_t i = 0; i < 15; i++)
- buf[i] = _gps_get_byte();
-
- // Force flush since there's a tonne of data remaining
- _gps_flush_buffer();
-
- // Verify the sync and header bits
- if( buf[0] != 0xB5 || buf[1] != 0x62 )
- led_set(LED_RED, 1);
- if( buf[2] != 0x02 || buf[3] != 0x20 )
- led_set(LED_RED, 1);
-
- /*char s[20];
- sprintf(s, "%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);
- radio_transmit_string(s);*/
-
- // FIXME: We should check the UBX checksum here
+ // Return the value if GPSfixOK is set in 'flags'
+ if( buf[17] & 0x01 )
+ *lock = buf[16];
+ else
+ *lock = 0;
- return buf[13];
+ *sats = buf[53];
}
/**
View
@@ -12,8 +12,7 @@
void gps_init(void);
void gps_get_position(int32_t* lat, int32_t* lon, int32_t* alt);
void gps_get_time(uint8_t* hour, uint8_t* min, uint8_t* second);
-uint8_t gps_check_lock(void);
-uint8_t gps_num_sats(void);
+void gps_check_lock(uint8_t* lock, uint8_t* sats);
bool _gps_verify_checksum(uint8_t* data, uint8_t len);
void gps_ubx_checksum(uint8_t* data, uint8_t len, uint8_t* cka, uint8_t* ckb);
void _gps_send_msg(uint8_t* data, uint8_t len);
View
@@ -43,7 +43,7 @@ int main()
int32_t lat = 0, lon = 0, alt = 0;
uint32_t ticks = 0;
- uint8_t hour = 0, minute = 0, second = 0;
+ uint8_t hour = 0, minute = 0, second = 0, lock = 0, sats = 0;
while(true)
{
@@ -53,13 +53,12 @@ int main()
int16_t temperature = 0;
// Get information from the GPS
- uint8_t lock = gps_check_lock();
+ gps_check_lock(&lock, &sats);
if( lock == 0x02 || lock == 0x03 || lock == 0x04 )
{
gps_get_position(&lat, &lon, &alt);
gps_get_time(&hour, &minute, &second);
}
- uint8_t sats = gps_num_sats();
led_set(LED_GREEN, 0);

0 comments on commit 2c704b5

Please sign in to comment.