kopia lustrzana https://github.com/bristol-seds/pico-tracker
[sequencer] pass the cycle time to the sequencer so the backlog rate can be kept constant at one-per-hour
rodzic
901ad31ead
commit
0316a3480d
|
@ -26,6 +26,6 @@
|
||||||
|
|
||||||
#include "samd20.h"
|
#include "samd20.h"
|
||||||
|
|
||||||
void run_sequencer(uint32_t n);
|
void run_sequencer(uint32_t n, uint32_t cycle_time_s);
|
||||||
|
|
||||||
#endif /* SEQUENCER_H */
|
#endif /* SEQUENCER_H */
|
||||||
|
|
|
@ -275,31 +275,30 @@ volatile uint8_t run_flag = 1; /* run immediately after init */
|
||||||
|
|
||||||
uint8_t in_cold_out = 1; /* test temperature immediately after init */
|
uint8_t in_cold_out = 1; /* test temperature immediately after init */
|
||||||
uint32_t cold_out_count = 0;
|
uint32_t cold_out_count = 0;
|
||||||
|
uint32_t cycle_time_s = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the hibernate time in seconds
|
* Sets the cycle time in seconds
|
||||||
*/
|
*/
|
||||||
void set_hibernate_time(uint8_t cold_out)
|
void set_cycle_time(uint8_t cold_out)
|
||||||
{
|
{
|
||||||
uint32_t hibernate_time_s;
|
|
||||||
|
|
||||||
if (cold_out == 0) { /* Normal operations */
|
if (cold_out == 0) { /* Normal operations */
|
||||||
if (gps_is_locked() == GPS_NO_LOCK) { /* no lock */
|
if (gps_is_locked() == GPS_NO_LOCK) { /* no lock */
|
||||||
hibernate_time_s = 0; /* shortest hibernate */
|
cycle_time_s = 0; /* shortest hibernate */
|
||||||
|
|
||||||
} else if ((get_battery_charge_state() != BATTERY_DISCHARGING) || /* plenty of power */
|
} else if ((get_battery_charge_state() != BATTERY_DISCHARGING) || /* plenty of power */
|
||||||
(gps_get_flight_state() == GPS_FLIGHT_STATE_LAUNCH)) { /* or during launch */
|
(gps_get_flight_state() == GPS_FLIGHT_STATE_LAUNCH)) { /* or during launch */
|
||||||
hibernate_time_s = CYCLE_TIME_FAST;
|
cycle_time_s = CYCLE_TIME_FAST;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
hibernate_time_s = CYCLE_TIME_SLOW;
|
cycle_time_s = CYCLE_TIME_SLOW;
|
||||||
}
|
}
|
||||||
} else { /* cold out */
|
} else { /* cold out */
|
||||||
hibernate_time_s = COLD_OUT_SECONDS;
|
cycle_time_s = COLD_OUT_SECONDS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set this */
|
/* hibernate until this time is up */
|
||||||
rtc_hibernate_time(hibernate_time_s);
|
rtc_hibernate_time(cycle_time_s);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Called when it's time to run again
|
* Called when it's time to run again
|
||||||
|
@ -349,12 +348,12 @@ int main(void)
|
||||||
in_cold_out = 1; /* cold */
|
in_cold_out = 1; /* cold */
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
in_cold_out = 0; /* ready to go! */
|
in_cold_out = 0; /* ready to go! */
|
||||||
gps_init(); /* init the gps! */
|
gps_init(); /* init the gps! */
|
||||||
run_sequencer(n++); /* run for the first time! */
|
run_sequencer(n++, cycle_time_s); /* run for the first time! */
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
run_sequencer(n++); /* Run */
|
run_sequencer(n++, cycle_time_s); /* run */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clocks off */
|
/* Clocks off */
|
||||||
|
@ -370,7 +369,7 @@ int main(void)
|
||||||
hf_clock_disable();
|
hf_clock_disable();
|
||||||
|
|
||||||
/* Hibernate timing */
|
/* Hibernate timing */
|
||||||
set_hibernate_time(in_cold_out);
|
set_cycle_time(in_cold_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Idle */
|
/* Idle */
|
||||||
|
|
|
@ -117,7 +117,7 @@ void telemetry_sequence(struct tracker_datapoint* dp, uint32_t n)
|
||||||
/**
|
/**
|
||||||
* Run sequence n
|
* Run sequence n
|
||||||
*/
|
*/
|
||||||
void run_sequencer(uint32_t n)
|
void run_sequencer(uint32_t n, uint32_t cycle_time_s)
|
||||||
{
|
{
|
||||||
struct tracker_datapoint* dp;
|
struct tracker_datapoint* dp;
|
||||||
|
|
||||||
|
@ -131,12 +131,15 @@ void run_sequencer(uint32_t n)
|
||||||
telemetry_sequence(dp, n);
|
telemetry_sequence(dp, n);
|
||||||
|
|
||||||
/* Backlog */
|
/* Backlog */
|
||||||
if (gps_is_locked() == GPS_LOCKED) { /* gps is locked. we can use this data */
|
if ((gps_is_locked() == GPS_LOCKED) && /* gps is locked. we can use this data */
|
||||||
|
(cycle_time_s > 0)) { /* and an actual cycle */
|
||||||
|
|
||||||
/* Accumulator for backlog */
|
/* Accumulator for backlog */
|
||||||
accumulator_add(dp);
|
accumulator_add(dp);
|
||||||
|
|
||||||
/* Record */
|
/* Record */
|
||||||
if ((n % 15) == 10) { /* Once per hour with 4 minute wakeup */
|
uint32_t rate = 3600 / cycle_time_s; /* once per hour */
|
||||||
|
if ((n % rate) == 0) {
|
||||||
|
|
||||||
/* replace some values from this sample with averages */
|
/* replace some values from this sample with averages */
|
||||||
accumulator_read(dp);
|
accumulator_read(dp);
|
||||||
|
|
Ładowanie…
Reference in New Issue