kopia lustrzana https://github.com/bristol-seds/pico-tracker
Improved gps error handling, more work to do here however
rodzic
c2118dbdc4
commit
c40105dacb
|
@ -29,6 +29,7 @@
|
|||
* GPS Error types
|
||||
*/
|
||||
enum gps_error_t {
|
||||
GPS_NOERROR,
|
||||
GPS_ERROR_BAD_CHECKSUM,
|
||||
GPS_ERROR_INVALID_FRAME,
|
||||
};
|
||||
|
@ -37,6 +38,7 @@ void gps_update_time(void);
|
|||
void gps_update_position(void);
|
||||
int gps_update_time_pending(void);
|
||||
int gps_update_position_pending(void);
|
||||
enum gps_error_t gps_get_error_state(void);
|
||||
|
||||
struct ubx_nav_posllh gps_get_nav_posllh();
|
||||
struct ubx_nav_sol gps_get_nav_sol();
|
||||
|
|
|
@ -63,17 +63,21 @@ void read_gps_time(void)
|
|||
idle(IDLE_WAIT_FOR_GPS);
|
||||
}
|
||||
|
||||
/* Time */
|
||||
struct ubx_nav_timeutc gt = gps_get_nav_timeutc();
|
||||
time.year = gt.payload.year;
|
||||
time.month = gt.payload.month;
|
||||
time.day = gt.payload.day;
|
||||
time.hour = gt.payload.hour;
|
||||
time.minute = gt.payload.min;
|
||||
time.second = gt.payload.sec;
|
||||
time.valid = gt.payload.valid;
|
||||
if (gps_get_error_state() == GPS_NOERROR) {
|
||||
|
||||
/* TODO calculate epoch time here */
|
||||
/* Time */
|
||||
struct ubx_nav_timeutc gt = gps_get_nav_timeutc();
|
||||
time.year = gt.payload.year;
|
||||
time.month = gt.payload.month;
|
||||
time.day = gt.payload.day;
|
||||
time.hour = gt.payload.hour;
|
||||
time.minute = gt.payload.min;
|
||||
time.second = gt.payload.sec;
|
||||
time.valid = gt.payload.valid;
|
||||
|
||||
/* TODO calculate epoch time here */
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -76,6 +76,9 @@ struct tracker_datapoint* collect_data(void)
|
|||
idle(IDLE_WAIT_FOR_GPS);
|
||||
}
|
||||
|
||||
/* At this point the gps could be in an error state */
|
||||
/* We still use the old values however. */
|
||||
|
||||
/* GPS Status */
|
||||
struct ubx_nav_sol sol = gps_get_nav_sol();
|
||||
datapoint.satillite_count = sol.payload.numSV;
|
||||
|
@ -87,10 +90,10 @@ struct tracker_datapoint* collect_data(void)
|
|||
datapoint.latitude = pos.payload.lat;
|
||||
datapoint.longitude = pos.payload.lon;
|
||||
datapoint.altitude = pos.payload.height;
|
||||
}
|
||||
}
|
||||
|
||||
/* GPS Powersave */
|
||||
gps_set_powersave_auto();
|
||||
|
||||
return &datapoint;
|
||||
return &datapoint;
|
||||
}
|
||||
|
|
|
@ -66,6 +66,8 @@ int32_t ubx_index = SFD_WAITING;
|
|||
uint16_t ubx_payload_length = 0;
|
||||
uint8_t ubx_irq_buffer[UBX_BUFFER_LEN];
|
||||
|
||||
volatile enum gps_error_t gps_error_state;
|
||||
|
||||
/**
|
||||
* UBX Messages
|
||||
*/
|
||||
|
@ -98,9 +100,9 @@ volatile ubx_message_t* const ubx_messages[] = {
|
|||
* Platform specific handlers
|
||||
*/
|
||||
#define _send_buffer(tx_data, length) \
|
||||
usart_write_buffer_wait(GPS_SERCOM, tx_data, length)
|
||||
do { usart_write_buffer_wait(GPS_SERCOM, tx_data, length); } while (0)
|
||||
#define _error_handler(error_type) \
|
||||
/* TODO */
|
||||
do { gps_error_state = error_type; } while (0)
|
||||
|
||||
|
||||
|
||||
|
@ -241,6 +243,9 @@ void _ubx_send_message(ubx_message_t* message, uint8_t* payload, uint16_t length
|
|||
/* Clear the message state */
|
||||
message->state = UBX_PACKET_WAITING;
|
||||
|
||||
/* Clear error state */
|
||||
gps_error_state = GPS_NOERROR;
|
||||
|
||||
/* Copy little endian */
|
||||
memcpy(ubx_buffer, &ubx_header, 2); ubx_buffer += 2; /* Header */
|
||||
memcpy(ubx_buffer, &message->id, 2); ubx_buffer += 2; /* Message Type */
|
||||
|
@ -254,12 +259,15 @@ void _ubx_send_message(ubx_message_t* message, uint8_t* payload, uint16_t length
|
|||
/**
|
||||
* Polls the GPS for packets
|
||||
*/
|
||||
void _ubx_poll(ubx_message_t* message) {
|
||||
enum gps_error_t _ubx_poll(ubx_message_t* message) {
|
||||
/* Send the message */
|
||||
_ubx_send_message(message, NULL, 0);
|
||||
|
||||
/* Wait for acknoledge */
|
||||
while (message->state == UBX_PACKET_WAITING);
|
||||
while (message->state == UBX_PACKET_WAITING &&
|
||||
gps_error_state == GPS_NOERROR);
|
||||
|
||||
return gps_error_state;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -305,17 +313,28 @@ void gps_update_position(void)
|
|||
*/
|
||||
int gps_update_time_pending(void)
|
||||
{
|
||||
return (ubx_nav_timeutc.state == UBX_PACKET_WAITING);
|
||||
return (ubx_nav_timeutc.state == UBX_PACKET_WAITING &&
|
||||
gps_error_state == GPS_NOERROR);
|
||||
}
|
||||
/**
|
||||
* Indicates a pending position update from the GPS
|
||||
*/
|
||||
int gps_update_position_pending(void)
|
||||
{
|
||||
return (ubx_nav_posllh.state == UBX_PACKET_WAITING) ||
|
||||
(ubx_nav_sol.state == UBX_PACKET_WAITING);
|
||||
return (((ubx_nav_posllh.state == UBX_PACKET_WAITING) ||
|
||||
(ubx_nav_sol.state == UBX_PACKET_WAITING)) &&
|
||||
gps_error_state == GPS_NOERROR);
|
||||
|
||||
//(ubx_nav_status.state == UBX_PACKET_WAITING);
|
||||
}
|
||||
/**
|
||||
* Gets the current error state of the GPS to check validity of last
|
||||
* request
|
||||
*/
|
||||
enum gps_error_t gps_get_error_state(void)
|
||||
{
|
||||
return gps_error_state;
|
||||
}
|
||||
/**
|
||||
* Return the latest received messages
|
||||
*/
|
||||
|
@ -347,7 +366,7 @@ uint8_t gps_is_locked(void)
|
|||
*/
|
||||
void gps_set_platform_model(void)
|
||||
{
|
||||
/* Send the poll request */
|
||||
/* Poll for the current settings */
|
||||
_ubx_poll((ubx_message_t*)&ubx_cfg_nav5);
|
||||
|
||||
/* If we need to update */
|
||||
|
@ -366,7 +385,7 @@ void gps_set_platform_model(void)
|
|||
*/
|
||||
void gps_set_timepulse_five(uint32_t frequency)
|
||||
{
|
||||
/* Send the Request */
|
||||
/* Poll for the current settings */
|
||||
_ubx_poll((ubx_message_t*)&ubx_cfg_tp5);
|
||||
|
||||
/* Define the settings we want */
|
||||
|
@ -391,7 +410,7 @@ void gps_set_timepulse_five(uint32_t frequency)
|
|||
*/
|
||||
void gps_set_gnss(void)
|
||||
{
|
||||
/* Read the current settings */
|
||||
/* Poll for the current settings */
|
||||
_ubx_poll((ubx_message_t*)&ubx_cfg_gnss);
|
||||
|
||||
switch (ubx_cfg_gnss.payload.msgVer) {
|
||||
|
|
Ładowanie…
Reference in New Issue