This commit is contained in:
2026-08-31 23:12:28 -04:00
parent 2152b8f727
commit 089be9564b
13 changed files with 147 additions and 39 deletions
+15 -3
View File
@@ -31,8 +31,12 @@ RTC_RFM69_STATUS set_time_from_rfm69(identifier_results id_data)
TIME.Year = RX_DATA.msg[5];
TIME.Wday = RX_DATA.msg[6];
rtc_write_time(TIME);
return RTC_RFM69_SET_TIME_SUCCESS;
// Only claim success once the time actually landed in the RTC,
// so a failed write is retried next cycle.
if (rtc_write_time(TIME) == 0) {
return RTC_RFM69_SET_TIME_SUCCESS;
}
LOG("RTC write failed\n");
}
}
return RTC_RFM69_SET_TIME_FAILED;
@@ -78,8 +82,16 @@ uint8_t rtc_read_time_array(uint8_t* data)
time_struct rtc_read_time(void)
{
if (rtc_read_time_array(DATA_BUFFER_7)) {
// RTC unreachable: mark every field with an unmistakably invalid value
// rather than transmitting whatever was read last. The base station
// sees month 0xFF and knows the timestamp is unusable.
LOG("RTC read failed\n");
TIME.Second = TIME.Minute = TIME.Hour = 0xFF;
TIME.Wday = TIME.Day = TIME.Month = TIME.Year = 0xFF;
return TIME;
}
rtc_read_time_array(DATA_BUFFER_7);
TIME.Second = BCD2DEC(DATA_BUFFER_7[0]);
TIME.Minute = BCD2DEC(DATA_BUFFER_7[1]);
TIME.Hour = BCD2DEC((DATA_BUFFER_7[2] & ~(1 << 6)));