kopia lustrzana https://github.com/bristol-seds/pico-tracker
Collect GPS data asynchronously. Maybe we can reduce the update rate on the GPS to save power?
rodzic
a625416787
commit
599e677a20
|
@ -33,7 +33,6 @@
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
IDLE_NONE,
|
IDLE_NONE,
|
||||||
IDLE_WAIT_FOR_GPS = 0x90137526,
|
|
||||||
IDLE_TELEMETRY_ACTIVE = 0x15476064,
|
IDLE_TELEMETRY_ACTIVE = 0x15476064,
|
||||||
IDLE_WAIT_FOR_NEXT_TELEMETRY = 0x36749870,
|
IDLE_WAIT_FOR_NEXT_TELEMETRY = 0x36749870,
|
||||||
} idle_wait_t;
|
} idle_wait_t;
|
||||||
|
@ -43,12 +42,10 @@ typedef enum {
|
||||||
* is triggered. Values defined to be well above values encountered in
|
* is triggered. Values defined to be well above values encountered in
|
||||||
* normal operation.
|
* normal operation.
|
||||||
*/
|
*/
|
||||||
#define MAXIDLE_WAIT_FOR_GPS 2400
|
|
||||||
#define MAXIDLE_WHILE_TELEMETRY_ACTIVE 60000
|
#define MAXIDLE_WHILE_TELEMETRY_ACTIVE 60000
|
||||||
#define MAXIDLE_WAIT_FOR_NEXT_TELEMETRY 30000
|
#define MAXIDLE_WAIT_FOR_NEXT_TELEMETRY 30000
|
||||||
|
|
||||||
struct idle_counter {
|
struct idle_counter {
|
||||||
uint32_t wait_for_gps;
|
|
||||||
uint32_t while_telemetry_active;
|
uint32_t while_telemetry_active;
|
||||||
uint32_t wait_for_next_telemetry;
|
uint32_t wait_for_next_telemetry;
|
||||||
};
|
};
|
||||||
|
|
|
@ -115,7 +115,7 @@ void read_gps_time(void)
|
||||||
while (gps_update_time_pending() &&
|
while (gps_update_time_pending() &&
|
||||||
(cron_current_job_ticks() - ticks_delta_start) <= 3) {
|
(cron_current_job_ticks() - ticks_delta_start) <= 3) {
|
||||||
|
|
||||||
idle(IDLE_WAIT_FOR_GPS);
|
idle(IDLE_WAIT_FOR_NEXT_TELEMETRY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If no error and no timeout */
|
/* If no error and no timeout */
|
||||||
|
@ -220,7 +220,7 @@ void do_cron(void)
|
||||||
if ((time.second % 30) == 0) {
|
if ((time.second % 30) == 0) {
|
||||||
dp = collect_data();
|
dp = collect_data();
|
||||||
memcpy(&dp->time, &time, sizeof(struct tracker_time));
|
memcpy(&dp->time, &time, sizeof(struct tracker_time));
|
||||||
} else if ((time.second % 30) == 20) {
|
} else if ((time.second % 30) == 25) {
|
||||||
collect_data_async();
|
collect_data_async();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,12 +34,6 @@
|
||||||
#include "telemetry.h"
|
#include "telemetry.h"
|
||||||
#include "watchdog.h"
|
#include "watchdog.h"
|
||||||
|
|
||||||
/**
|
|
||||||
* GPS timeout and retries
|
|
||||||
*/
|
|
||||||
#define GPS_POSITION_RETRIES 5
|
|
||||||
uint32_t ticks_delta_start;
|
|
||||||
|
|
||||||
struct tracker_datapoint datapoint = {.time={0}};
|
struct tracker_datapoint datapoint = {.time={0}};
|
||||||
|
|
||||||
void xosc_measure_callback(uint32_t result)
|
void xosc_measure_callback(uint32_t result)
|
||||||
|
@ -49,10 +43,13 @@ void xosc_measure_callback(uint32_t result)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collect data asynchronously
|
* Collect data asynchronously. Should be run a few seconds before the collect_data routine
|
||||||
*/
|
*/
|
||||||
void collect_data_async(void)
|
void collect_data_async(void)
|
||||||
{
|
{
|
||||||
|
/* Ask GPS for latest fix */
|
||||||
|
gps_update_position();
|
||||||
|
|
||||||
/* Measure XOSC against gps timepulse */
|
/* Measure XOSC against gps timepulse */
|
||||||
measure_xosc(XOSC_MEASURE_TIMEPULSE, xosc_measure_callback);
|
measure_xosc(XOSC_MEASURE_TIMEPULSE, xosc_measure_callback);
|
||||||
|
|
||||||
|
@ -60,12 +57,10 @@ void collect_data_async(void)
|
||||||
start_adc_conversion_sequence();
|
start_adc_conversion_sequence();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Collect Data synchronously and return datapoint
|
* Collects data synchronously and return datapoint
|
||||||
*/
|
*/
|
||||||
struct tracker_datapoint* collect_data(void)
|
struct tracker_datapoint* collect_data(void)
|
||||||
{
|
{
|
||||||
uint8_t gps_retries = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ---- Analogue ----
|
* ---- Analogue ----
|
||||||
*/
|
*/
|
||||||
|
@ -73,31 +68,17 @@ struct tracker_datapoint* collect_data(void)
|
||||||
datapoint.solar = get_solar(); /* Will return zero by default */
|
datapoint.solar = get_solar(); /* Will return zero by default */
|
||||||
datapoint.temperature = telemetry_si_temperature();
|
datapoint.temperature = telemetry_si_temperature();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ---- GPS ----
|
* ---- GPS ----
|
||||||
*/
|
*/
|
||||||
do {
|
if (gps_update_position_pending() || (gps_get_error_state() != GPS_NOERROR)) {
|
||||||
/* Record current ticks */
|
/* Error updating GPS position */
|
||||||
ticks_delta_start = cron_current_job_ticks();
|
|
||||||
|
|
||||||
gps_update_position();
|
/* TODO: Hit reset on the GPS? */
|
||||||
|
/* In the meantime just wait for the watchdog */
|
||||||
|
while (1);
|
||||||
|
|
||||||
/* Wait for the gps update. Timeout after 3 ticks */
|
} else { /* GPS position updated correctly */
|
||||||
while (gps_update_position_pending() &&
|
|
||||||
(cron_current_job_ticks() - ticks_delta_start) <= 3) {
|
|
||||||
|
|
||||||
idle(IDLE_WAIT_FOR_GPS);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* In the case of a error or timeout keep retrying up to 5
|
|
||||||
* times */
|
|
||||||
} while (((gps_get_error_state() != GPS_NOERROR) ||
|
|
||||||
(cron_current_job_ticks() - ticks_delta_start) > 3)
|
|
||||||
&& gps_retries++ < GPS_POSITION_RETRIES);
|
|
||||||
|
|
||||||
/* Halt and wait for hw watchdog */
|
|
||||||
if (gps_retries >= GPS_POSITION_RETRIES) { while (1); }
|
|
||||||
|
|
||||||
/* GPS Status */
|
/* GPS Status */
|
||||||
struct ubx_nav_sol sol = gps_get_nav_sol();
|
struct ubx_nav_sol sol = gps_get_nav_sol();
|
||||||
|
@ -114,6 +95,7 @@ struct tracker_datapoint* collect_data(void)
|
||||||
|
|
||||||
/* GPS Powersave */
|
/* GPS Powersave */
|
||||||
gps_set_powersave_auto();
|
gps_set_powersave_auto();
|
||||||
|
}
|
||||||
|
|
||||||
return &datapoint;
|
return &datapoint;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,9 +47,6 @@ idle_wait_t last_idle_t = IDLE_NONE;
|
||||||
void increment_idle_counter(idle_wait_t idle_t)
|
void increment_idle_counter(idle_wait_t idle_t)
|
||||||
{
|
{
|
||||||
switch (idle_t) {
|
switch (idle_t) {
|
||||||
case IDLE_WAIT_FOR_GPS:
|
|
||||||
idle_count.wait_for_gps++;
|
|
||||||
break;
|
|
||||||
case IDLE_TELEMETRY_ACTIVE:
|
case IDLE_TELEMETRY_ACTIVE:
|
||||||
idle_count.while_telemetry_active++;
|
idle_count.while_telemetry_active++;
|
||||||
break;
|
break;
|
||||||
|
@ -66,8 +63,7 @@ void increment_idle_counter(idle_wait_t idle_t)
|
||||||
*/
|
*/
|
||||||
void check_idle_counters(void)
|
void check_idle_counters(void)
|
||||||
{
|
{
|
||||||
if ((idle_count.wait_for_gps > MAXIDLE_WAIT_FOR_GPS) ||
|
if ((idle_count.while_telemetry_active > MAXIDLE_WHILE_TELEMETRY_ACTIVE) ||
|
||||||
(idle_count.while_telemetry_active > MAXIDLE_WHILE_TELEMETRY_ACTIVE) ||
|
|
||||||
(idle_count.wait_for_next_telemetry > MAXIDLE_WAIT_FOR_NEXT_TELEMETRY)) {
|
(idle_count.wait_for_next_telemetry > MAXIDLE_WAIT_FOR_NEXT_TELEMETRY)) {
|
||||||
/* Oh dear. Let's die here */
|
/* Oh dear. Let's die here */
|
||||||
while (1);
|
while (1);
|
||||||
|
@ -80,7 +76,6 @@ void check_idle_counters(void)
|
||||||
*/
|
*/
|
||||||
void clear_idle_counters(void)
|
void clear_idle_counters(void)
|
||||||
{
|
{
|
||||||
SET_COUNT_MAX(wait_for_gps);
|
|
||||||
SET_COUNT_MAX(while_telemetry_active);
|
SET_COUNT_MAX(while_telemetry_active);
|
||||||
SET_COUNT_MAX(wait_for_next_telemetry);
|
SET_COUNT_MAX(wait_for_next_telemetry);
|
||||||
|
|
||||||
|
@ -118,8 +113,7 @@ void kick_the_watchdog(void)
|
||||||
void idle(idle_wait_t idle_t)
|
void idle(idle_wait_t idle_t)
|
||||||
{
|
{
|
||||||
/* Check valid */
|
/* Check valid */
|
||||||
if ((idle_t != IDLE_WAIT_FOR_GPS) &&
|
if ((idle_t != IDLE_TELEMETRY_ACTIVE) &&
|
||||||
(idle_t != IDLE_TELEMETRY_ACTIVE) &&
|
|
||||||
(idle_t != IDLE_WAIT_FOR_NEXT_TELEMETRY)) {
|
(idle_t != IDLE_WAIT_FOR_NEXT_TELEMETRY)) {
|
||||||
/* Oh dear */
|
/* Oh dear */
|
||||||
while (1);
|
while (1);
|
||||||
|
|
Ładowanie…
Reference in New Issue