Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
BroadcastTimeServer.hxx
Go to the documentation of this file.
1
35#ifndef _OPENLCB_BROADCASTTIMESERVER_HXX_
36#define _OPENLCB_BROADCASTTIMESERVER_HXX_
37
40
41namespace openlcb
42{
43
44class BroadcastTimeServerTime;
45class BroadcastTimeServerSync;
46class BroadcastTimeServerSet;
47class BroadcastTimeServerAlarm;
48
59{
60public:
66
69
72 bool is_server_detected() override
73 {
74 return true;
75 }
76
79 bool is_server_self() override
80 {
81 return true;
82 }
83
84#if defined(GTEST)
85 void shutdown();
86
87 bool is_shutdown();
88#endif
89
90private:
96 EventReport *event,
97 BarrierNotifiable *done) override
98 {
99 AutoNotify an(done);
100 if (event->dst_node && event->dst_node != node_)
101 {
102 // not for us
103 return;
104 }
105
106 if (is_terminated())
107 {
109 }
110
111 event->event_write_helper<1>()->WriteAsync(
112 node_, Defs::MTI_PRODUCER_IDENTIFIED_RANGE, WriteHelper::global(),
113 eventid_to_buffer(EncodeRange(entry.event, 0x1 << 16)),
114 done->new_child());
115
116 // we can configure ourselves
117 event->event_write_helper<2>()->WriteAsync(
118 node_, Defs::MTI_CONSUMER_IDENTIFIED_RANGE, WriteHelper::global(),
119 eventid_to_buffer(EncodeRange(entry.event + 0x8000, 0x1 << 15)),
120 done->new_child());
121 }
122
128 EventReport *event,
129 BarrierNotifiable *done) override
130 {
131 AutoNotify an(done);
132
133 if (event->event >= (eventBase_ + 0x8000))
134 {
135 // we can configure ourselves
136 event->event_write_helper<1>()->WriteAsync(
138 WriteHelper::global(),
139 eventid_to_buffer(EncodeRange(entry.event + 0x8000, 0x1 << 15)),
140 done->new_child());
141 }
142 }
143
149 EventReport *event,
150 BarrierNotifiable *done) override
151 {
152 AutoNotify an(done);
153 event->event_write_helper<1>()->WriteAsync(
154 node_, Defs::MTI_PRODUCER_IDENTIFIED_RANGE, WriteHelper::global(),
155 eventid_to_buffer(EncodeRange(entry.event, 0x1 << 16)),
156 done->new_child());
157 }
158
164 EventReport *event,
165 BarrierNotifiable *done) override;
166
167
174 const EventRegistryEntry &registry_entry, EventReport *event,
175 BarrierNotifiable *done) override;
176
182 EventReport *event,
183 BarrierNotifiable *done) override;
184
187 virtual void set_shortcut(uint64_t event) override;
188
192 {
193 return sleep_and_call(&timer_, MSEC_TO_NSEC(300),
195 }
196
199 Action query_response();
200
201 //BroadcastTimeAlarmDate alarmDate_; ///< date rollover alarm
203 uint16_t updateRequested_ : 1;
204#if defined(GTEST)
205 uint16_t shutdown_ : 1;
206#endif
207
212
213 friend class BroadcastTimeServerTime;
214 friend class BroadcastTimeServerSync;
215 friend class BroadcastTimeServerSet;
216 friend class BroadcastTimeServerAlarm;
217
218
220};
221
222} // namespace openlcb
223
224#endif // _OPENLCB_BROADCASTTIMESERVER_HXX_
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
Definition StateFlow.hxx:61
This class sends a notification in its destructor.
A BarrierNotifiable allows to create a number of child Notifiable and wait for all of them to finish.
BarrierNotifiable * new_child()
Call this for each child task.
Return type for a state flow callback.
bool is_terminated()
void start_flow(Callback c)
Resets the flow to the specified state and starts it.
Action sleep_and_call(::Timer *timer, long long timeout_nsec, Callback c)
Suspends execution of this control flow for a specified time.
Specialization of the BroacastTimeAlarm to expire on the necessary clock minutes that must be produce...
State machine for sending the clock set sequence.
State machine for sending the clock sync sequence.
State machine for sending the clock time events.
Implementation of a Broadcast Time Protocol server.
void handle_consumer_range_identified(const EventRegistryEntry &registry_entry, EventReport *event, BarrierNotifiable *done) override
Called on another node sending ConsumerRangeIdentified.
void handle_event_report(const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
Handle an incoming event report.
void handle_consumer_identified(const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
Handle an incoming consumer identified.
void handle_identify_global(const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
Handle requested identification message.
bool is_server_self() override
Test if this is a server.
Action query_response()
Respond to a query by scheduling a sync.
Action entry()
Entry to state machine.
virtual void set_shortcut(uint64_t event) override
Try the possible set event shortcut.
bool is_server_detected() override
Has a time server been detected?
time_t secondsRequested_
pending clock time in seconds
uint16_t updateRequested_
clock settings have change
void handle_identify_producer(const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
Handle requested identification message.
void handle_identify_consumer(const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
Handle requested identification message.
Implementation of Broadcast Time Protocol.
StateFlowTimer timer_
timer helper
Node * node()
Accessor method to get the Node reference.
NodeID clock_id()
Accessor method to get the (48-bit) Clock ID.
EventId eventBase_
48-bit unique identifier for the clock instance
Node * node_
OpenLCB node to export the consumer on.
Structure used in registering event handlers.
Base class for NMRAnet nodes conforming to the asynchronous interface.
Definition Node.hxx:52
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
Definition macros.h:171
uint64_t EncodeRange(uint64_t begin, unsigned size)
Creates a single encoded event range from the beginning of the range and the number fo events to cove...
uint64_t NodeID
48-bit NMRAnet Node ID type
Payload eventid_to_buffer(uint64_t eventid)
Converts an Event ID to a Payload suitable to be sent as an event report.
Definition If.cxx:72
#define MSEC_TO_NSEC(_msec)
Convert a millisecond value to a nanosecond value.
Definition os.h:268
@ MTI_PRODUCER_IDENTIFIED_RANGE
producer broadcast about a range of producers
@ MTI_CONSUMER_IDENTIFIED_RANGE
consumer broadcast about a range of consumers
Shared notification structure that is assembled for each incoming event-related message,...
EventId event
The event ID from the incoming message.
Node * dst_node
nullptr for global messages; points to the specific virtual node for addressed events identify messag...