# HG changeset patch # User Ethan Zonca # Date 2016-10-11 22:04:28 # Node ID b32b9376de928a47618d5f6bef7cd6b433d6e0dd # Parent 0b86288f0749f35549be3188bd0b375a602a3885 Schedule wspr transmissions properly diff --git a/src/main.c b/src/main.c --- a/src/main.c +++ b/src/main.c @@ -18,8 +18,7 @@ enum _state { - SYSTEM_POWERUP_SYNC = 0, // on powerup, get a GPS fix and set the RTC - SYSTEM_IDLE, // awaiting RTC interrupt for wakeup TODO wake up before scheduled time to get fix? + SYSTEM_IDLE = 0, // awaiting RTC interrupt for wakeup TODO wake up before scheduled time to get fix? SYSTEM_GPSACQ, // RTC interrupted SYSTEM_WSPRTX, // Wait for timeslot and actually transmit the message }; @@ -44,6 +43,8 @@ int main(void) uint32_t gps_polltimer = 0; uint32_t fix_acq_starttime = 0; + uint32_t nextwspr_time = 0; + uint32_t last_wspr_tx_time = 0; uint8_t fix_ok = 0; uint8_t numsats = 0; @@ -51,11 +52,36 @@ int main(void) while (1) { + // Every 10 minutes, wake up and try to wspr + if(HAL_GetTick() - last_wspr_tx_time > 60000 * 10) + { + state = SYSTEM_GPSACQ; + } + // Update fix status every 2 seconds if(HAL_GetTick() - gps_polltimer > 2000) { if(gps_ison()) - gps_update_data(); + { + gps_update_data(); + gps_getdata()->minute; + gps_getdata()->second; + + // If odd minute + if(gps_getdata()->minute % 2) + { + volatile uint8_t minute = gps_getdata()->minute; + // Wait until even minute, coming soon + nextwspr_time = HAL_GetTick() + (60000 - (gps_getdata()->second * 1000)); + + } + // If even minute + else + { + // Wait until odd minute, one minute and some change away + nextwspr_time = HAL_GetTick() + 60000 + (60000 - (gps_getdata()->second * 1000)); + } + } gps_polltimer = HAL_GetTick(); } @@ -84,7 +110,7 @@ int main(void) if(!gps_ison()) { - fix_starttime = HAL_GetTick(); + fix_acq_starttime = HAL_GetTick(); gps_poweron(); // power on and initialize GPS module } @@ -117,14 +143,27 @@ int main(void) // Wait for wspr countdown timer to expire and go to tx // if(timeout_expired) // { -// wspr_transmit(); -// } + + // If we're after the minute but not more than 2s after the minute, start tx + if(HAL_GetTick() >= nextwspr_time) + { + if(HAL_GetTick() < nextwspr_time + 2000) + { + wspr_transmit(); + last_wspr_tx_time = HAL_GetTick(); + state = SYSTEM_IDLE; + } + else + { + // Window was missed, go back to idle, and try again after time delay + last_wspr_tx_time = HAL_GetTick(); + state = SYSTEM_IDLE; + } + } // Schedule next wakeup (maybe 2mins prior ot timeslot if no osc trim) // Next wakeup should enter SYSTEM_GPSACQ state... -// state = SYSTEM_IDLE; - } break; }