diff --git a/src/gps.c b/src/gps.c --- a/src/gps.c +++ b/src/gps.c @@ -40,7 +40,6 @@ void gps_init() // done in poweron uart_init(); gps_poweron(); - HAL_Delay(500); // // uart1 ubx only // @@ -212,36 +211,61 @@ void gps_update_time(uint8_t* hour, uint void gps_check_lock(uint8_t* lock, uint8_t* sats) { // Construct the request to the GPS - uint8_t request[8] = {0xB5, 0x62, 0x01, 0x06, 0x00, 0x00, 0x07, 0x16}; + uint8_t request[8] = {0xB5, 0x62, 0x01, 0x07, 0x00, 0x00, 0xFF, 0xFF}; + + + volatile uint8_t check_a = 0; + volatile uint8_t check_b = 0; + for(uint8_t i = 2; i<6; i++) + { + check_a += request[i]; + check_b += check_a; + } + request[6] = check_a; + request[7] = check_b; + uint8_t flushed = uart_gethandle()->Instance->RDR; HAL_UART_Transmit(uart_gethandle(), request, 8, 100); // Get the message back from the GPS - uint8_t buf[60]; - for(uint8_t i=0; i<60; i++) + uint8_t buf[100]; + for(uint8_t i=0; i<100; i++) buf[i] = 0xaa; - volatile HAL_StatusTypeDef res = HAL_UART_Receive(uart_gethandle(), buf, 60, 3000); - - // Verify the sync and header bits -// if( buf[0] != 0xB5 || buf[1] != 0x62 ) -// led_set(LED_RED, 1); -// if( buf[2] != 0x01 || buf[3] != 0x06 ) -// led_set(LED_RED, 1); + volatile HAL_StatusTypeDef res = HAL_UART_Receive(uart_gethandle(), buf, 100, 3000); // Check 60 bytes minus SYNC and CHECKSUM (4 bytes) - if( !_gps_verify_checksum(&buf[2], 56) ) + if( !_gps_verify_checksum(&buf[2], 96) ) led_blink(2); - // Return the value if GPSfixOK is set in 'flags' - if( buf[17] & 0x01 ) - *lock = buf[16]; - else - *lock = 0; + //volatile uint32_t gpstime_ms = (buf[6+0] << 24) | (buf[6+1] << 16) | buf[6+2] << 8) | (buf[6+3]); + + volatile uint8_t month = buf[6+6]; + volatile uint8_t day = buf[6+7]; + volatile uint8_t hour = buf[6+8]; + volatile uint8_t minute = buf[6+9]; + volatile uint8_t second = buf[6+10]; + volatile uint8_t valid = buf[6+11] & 0b1111; + volatile uint8_t fixtype = buf[6+20]; + + volatile uint8_t sats_in_solution = buf[6+23]; - *sats = buf[53]; + volatile uint32_t longitude = (buf[6+24] << 24) | (buf[6+25] << 16) | (buf[6+26] << 8) | (buf[6+27]); + volatile uint32_t latitude = (buf[6+28] << 24) | (buf[6+29] << 16) | (buf[6+30] << 8) | (buf[6+31]); + volatile uint32_t altitude_sealevel = (buf[6+36] << 24) | (buf[6+37] << 16) | (buf[6+38] << 8) | (buf[6+39]); + volatile uint32_t groundspeed = (buf[6+60] << 24) | (buf[6+61] << 16) | (buf[6+62] << 8) | (buf[6+63]); + volatile uint16_t pdop = (buf[6+76] << 8) | (buf[6+77]); +// +// // Return the value if GPSfixOK is set in 'flags' +// if( buf[17] & 0x01 ) +// *lock = buf[16]; +// else +// *lock = 0; + *lock = fixtype; + + *sats = sats_in_solution; } /**