Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
BroadcastTimeClient.cxx
Go to the documentation of this file.
1
36
37namespace openlcb
38{
39
40//
41// BroadcastTimeClient::handle_updates()
42//
44{
47
48 switch (type)
49 {
51 {
52 int min = BroadcastTimeDefs::event_to_min(event->event);
53 int hour = BroadcastTimeDefs::event_to_hour(event->event);
54 if (min >= 0 && hour >= 0)
55 {
56 tm_.tm_sec = 0;
57 tm_.tm_min = min;
58 tm_.tm_hour = hour;
59 immediateUpdate_ = report;
60 break;
61 }
62 // invalid event data, bail
63 return;
64 }
66 {
67 int day = BroadcastTimeDefs::event_to_day(event->event);
68 int month = BroadcastTimeDefs::event_to_month(event->event);
69 if (day >= 0 && month >= 0)
70 {
71 tm_.tm_mday = day;
72 tm_.tm_mon = month - 1;
73 if (report)
74 {
76 }
77 break;
78 }
79 // invalid event data, bail
80 return;
81 }
83 {
84 tm_.tm_year = BroadcastTimeDefs::event_to_year(event->event) - 1900;
85 if (report)
86 {
88 }
89 break;
90 }
92 {
94 break;
95 }
97 if (report)
98 {
101 rolloverPending_ = true;
102 }
103 break;
105 start_stop_logic(false);
106 // no further processing required
107 return;
109 start_stop_logic(true);
110 // no further processing required
111 return;
112 default:
113 // uninteresting event type
114 return;
115 }
116
117 if (!report)
118 {
119 // An immediate update is expected in the future
120 immediatePending_ = true;
121 }
122
123 wakeup();
124}
125
126} // namespace openlcb
void start_stop_logic(bool started)
Perform a bit of logic that is required whenever the clock's running state is changed.
void handle_updates(EventReport *event, bool report)
Handle an incoming time update.
uint16_t rolloverPendingDate_
a day rollover is about to occur
void wakeup()
wakeup the state machine.
uint16_t rolloverPending_
a day rollover is about to occur
uint16_t rolloverPendingYear_
a day rollover is about to occur
uint16_t immediateUpdate_
true if the update should be immediate
int16_t rateRequested_
pending clock rate
struct tm tm_
the time we are last set to as a struct tm
static int event_to_day(uint64_t event)
Get the day from the event.
static int event_to_month(uint64_t event)
Get the month from the event.
static int event_to_min(uint64_t event)
Get the minutes from the event.
static EventType get_event_type(uint16_t suffix)
Get the EventTuype from the event suffix number.
static int16_t event_to_rate(uint64_t event)
Get the rate from the event.
static int event_to_year(uint64_t event)
Get the year from the event.
@ DATE_ROLLOVER
date rollover event
static int event_to_hour(uint64_t event)
Get the hour from the event.
Shared notification structure that is assembled for each incoming event-related message,...
EventId event
The event ID from the incoming message.