#include "../BoomCast_Waveshare_Arduino/boomcast_schedule.h" #include "../BoomCast_Waveshare_Arduino/boomcast_rtc.h" #include #include #include time_t at(int month, int day, int hour, int minute = 0, int dst = -1) { tm t{}; t.tm_year = 126; t.tm_mon = month-1; t.tm_mday = day; t.tm_hour = hour; t.tm_min = minute; t.tm_isdst = dst; return mktime(&t); } int main() { setenv("TZ", "CET-1CEST,M3.5.0,M10.5.0/3", 1); tzset(); BoomScheduleConfig c; c.enabled = true; using namespace BoomSchedule; assert(active(c, at(10,9,23))); // Friday assert(active(c, at(10,10,0,59))); // Friday window until 01:00 assert(!active(c, at(10,10,1))); assert(nextTransition(c, at(10,9,23)) == at(10,10,1)); assert(!active(c, at(10,10,11,59))); assert(active(c, at(10,10,12))); assert(active(c, at(10,11,1,59))); assert(!active(c, at(10,11,2))); assert(active(c, at(10,12,1,59))); // Sunday into Monday uses Sunday assert(!active(c, at(10,12,2))); assert(nextTransition(c, at(10,12,3)) == at(10,12,12)); // reboot offline assert(shouldMonitor(c, at(10,12,3), false, false)); // invalid RTC fail open assert(!shouldMonitor(c, at(10,12,3), true, false)); // offline valid RTC assert(shouldMonitor(c, at(10,12,3), true, true)); // override assert(!shouldMonitor(c, at(10,12,3), true, false)); // expiration/return c.enabled = false; assert(active(c, at(10,12,3))); assert(!nextTransition(c, at(10,12,3))); c.enabled = true; c.weekdayStart = c.weekdayEnd = c.weekendStart = c.weekendEnd = 720; assert(active(c, at(10,12,3))); assert(nextTransition(c, at(10,12,3)) == 0); c.weekdayStart = c.weekendStart = 9*60; c.weekdayEnd = c.weekendEnd = 17*60; assert(!active(c, at(10,12,8,59))); assert(active(c, at(10,12,9))); assert(!active(c, at(10,12,17))); // Overnight spring gap: non-existent 02:30 resolves to 03:30. c.weekdayStart = c.weekendStart = 12*60; c.weekdayEnd = c.weekendEnd = 150; assert(active(c, at(3,29,3,29))); assert(!active(c, at(3,29,3,30))); assert(nextTransition(c, at(3,28,23)) == at(3,29,3,30)); // Autumn repeated hour: both 02:15s remain monitored, ends at later 02:30. assert(active(c, at(10,25,2,15,1))); assert(active(c, at(10,25,2,15,0))); assert(nextTransition(c, at(10,24,23)) == at(10,25,2,30,0)); assert(!active(c, at(10,25,2,30,0))); // Repeated start chooses first occurrence; overlapping windows stay active. c.weekdayStart = c.weekendStart = 150; c.weekdayEnd = c.weekendEnd = 240; assert(active(c, at(10,25,2,30,1))); assert(active(c, at(10,25,2,15,0))); c.weekdayStart=1440; assert(!c.valid()); assert(active(c, at(10,12,3))); uint8_t rtc[7] = {0x30,0x15,0x10,0x10,0x06,0x10,0x26}; time_t decoded; assert(BoomRtc::decode(0, rtc, decoded)); assert(decoded == at(10,10,12,15) + 30); // UTC 10:15 = Amsterdam 12:15 assert(!BoomRtc::decode(0x20, rtc, decoded)); // clock stopped assert(!BoomRtc::decode(0x08, rtc, decoded)); // 12h mode unsupported rtc[0] |= 0x80; assert(!BoomRtc::decode(0, rtc, decoded)); // oscillator fault rtc[0] = 0x6a; assert(!BoomRtc::decode(0, rtc, decoded)); // malformed BCD rtc[0] = 0; rtc[3] = 0x31; rtc[5] = 0x02; assert(!BoomRtc::decode(0, rtc, decoded)); // impossible February day puts("Scheduler calendar, DST, clock validity and override policy checks passed"); }