diff --git a/firmware/inc/hw_config/low-power-solar.h b/firmware/inc/hw_config/low-power-solar.h index 6f915f7..d5880b4 100644 --- a/firmware/inc/hw_config/low-power-solar.h +++ b/firmware/inc/hw_config/low-power-solar.h @@ -168,8 +168,8 @@ /** * Cycle Times */ -#define CYCLE_TIME_FAST (60) -#define CYCLE_TIME_SLOW (120) +#define CYCLE_TIME_FAST (0) /* shortest hibernate */ +#define CYCLE_TIME_SLOW (100) /* once every two minutes */ /** * Radio diff --git a/firmware/inc/rtc.h b/firmware/inc/rtc.h new file mode 100644 index 0000000..89927b6 --- /dev/null +++ b/firmware/inc/rtc.h @@ -0,0 +1,38 @@ +/* + * Initialised RTC to provide 1Hz event and interrupt + * Copyright (C) 2016 Richard Meadows + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef RTC_H +#define RTC_H + +/* Counts seconds since last aprs */ +uint32_t get_since_aprs_s(void); +void clear_since_aprs_s(void); + +/* Initialises RTC to provide 1Hz event and interrupt */ +void rtc_init(void); +/* Sets the hibernate time */ +void rtc_hibernate_time(uint32_t time_s); + + +#endif /* RTC_H */ diff --git a/firmware/src/rtc.c b/firmware/src/rtc.c index 7b06969..269e285 100644 --- a/firmware/src/rtc.c +++ b/firmware/src/rtc.c @@ -66,6 +66,16 @@ void rtc_init(void) * ============================================================================= */ +/* Seconds since APRS transmission */ +uint32_t since_aprs_s = 0; +uint32_t get_since_aprs_s(void) { + return since_aprs_s; +} +void clear_since_aprs_s(void) { + since_aprs_s = 0; +} + + #define HIBERNATE_TIME_MAX (3600) /* Hibernate should always be set lower that this */ volatile uint32_t hibernate_time_s = 0; void run_kick(void); @@ -77,8 +87,12 @@ uint32_t tick = 0; */ void rtc_hibernate_time(uint32_t time_s) { + /* set hibernate time */ hibernate_time_s = time_s; - tick = 20; /* start at t+20 seconds */ + + /* clear ticks */ + since_aprs_s += tick; + tick = 0; } /** * Interrupt for RTC, called at 1Hz @@ -90,12 +104,15 @@ void RTC_Handler(void) /* Check sleep time */ if (tick >= hibernate_time_s) { - /* Reset */ - tick = 0; /* zero tick */ - hibernate_time_s = HIBERNATE_TIME_MAX; /* set hibernate to max */ + /* clear ticks */ + since_aprs_s += tick; + tick = 0; + + /* set hibernate time to max */ + hibernate_time_s = HIBERNATE_TIME_MAX; /* Do something */ - run_kick(); + } else { /* Increment tick */ tick++; diff --git a/firmware/src/sequencer.c b/firmware/src/sequencer.c index 303c91d..06b57d8 100644 --- a/firmware/src/sequencer.c +++ b/firmware/src/sequencer.c @@ -34,6 +34,7 @@ #include "location.h" #include "accumulator.h" #include "battery.h" +#include "rtc.h" void rtty_telemetry(struct tracker_datapoint* dp); @@ -55,10 +56,6 @@ void telemetry_sequence(struct tracker_datapoint* dp, uint32_t n) location_prefix_update(dp->latitude, dp->longitude); kick_the_watchdog(); - /* DEATHWISH */ - /* CEASE TRANSMISSIONS AT THE END OF 2016 */ - if (dp->time.year > 2016) { return; } - /* Telemetry */ #if RF_TX_ENABLE #if TELEMETRY_ENABLE @@ -79,38 +76,46 @@ void telemetry_sequence(struct tracker_datapoint* dp, uint32_t n) #endif /* TELEMETRY_ENABLE */ + /* CEASE APRS AT THE END OF 2016 */ + if (dp->time.year > 2016) { return; } + /* APRS */ #if APRS_ENABLE + if (get_since_aprs_s() >= 60) { /* limit APRS frequency to once per minute */ + clear_since_aprs_s(); #if APRS_USE_GEOFENCE - if (location_aprs_should_tx()) { /* transmit only when we *should* */ + if (location_aprs_should_tx()) { /* transmit only when we *should* */ #endif - /* APRS */ - aprs_telemetry(dp, n); + /* APRS */ + aprs_telemetry(dp, n); #if APRS_USE_GEOFENCE - } -#endif -#endif /* APRS_ENABLE */ - - - /* ARISS */ -#if ARISS_ENABLE - if ((get_battery_use_state() == BATTERY_GOOD) && /* battery good, */ - (get_battery_charge_state() == BATTERY_CHARGING) && /* receiving power and */ - ((n % 4) == 0)) { /* one-in-four times */ -#if ARISS_USE_GEOFENCE - if (location_aprs_could_tx()) { /* transmit anywhere it's not disallowed */ -#endif - - /* ARISS */ - ariss_telemetry(dp); - -#if ARISS_USE_GEOFENCE } #endif - } + + /* CEASE ARISS AT THE END OF SEPTEMBER */ + if (dp->time.month > 9) { return; } + + /* ARISS */ +#if ARISS_ENABLE + if ((get_battery_use_state() == BATTERY_GOOD) && /* battery good, */ + (get_battery_charge_state() == BATTERY_CHARGING) && /* receiving power and */ + ((n % 3) == 0)) { /* one-in-three times */ +#if ARISS_USE_GEOFENCE + if (location_aprs_could_tx()) { /* transmit anywhere it's not disallowed */ +#endif + + /* ARISS */ + ariss_telemetry(dp); + +#if ARISS_USE_GEOFENCE + } +#endif + } #endif /* ARISS_ENABLE */ + } +#endif /* APRS_ENABLE */ #endif /* RF_TX_ENABLE */