35#ifndef _OPENLCB_BROADCASTTIMECLIENT_HXX_
36#define _OPENLCB_BROADCASTTIMECLIENT_HXX_
55 bool configure_agent =
false)
59 , immediatePending_(false)
118 event->event_write_helper<1>()->WriteAsync(
125 event->event_write_helper<2>()->WriteAsync(
127 WriteHelper::global(),
137 event->event_write_helper<2>()->WriteAsync(
139 WriteHelper::global(),
157 event->event_write_helper<1>()->WriteAsync(
180 event->event_write_helper<1>()->WriteAsync(
182 WriteHelper::global(),
199 if (event->
state == EventState::VALID)
202 if ((event->
event & 0x000000000000F000ULL) == 0x2000ULL)
338 time_t old_seconds = 0;
339 time_t new_seconds = 0;
342 old_seconds =
time();
352 immediatePending_ =
false;
437 uint16_t immediatePending_ : 1;
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
See OSMutexLock in os/OS.hxx.
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.
void notify() override
Implementation of the barrier semantics.
BarrierNotifiable * new_child()
Call this for each child task.
static long long get_monotonic()
Get the monotonic time since the system started.
static EventRegistry * instance()
Return type for a state flow callback.
void notify() override
Wakeup call arrived.
void start_flow(Callback c)
Resets the flow to the specified state and starts it.
Action call_immediately(Callback c)
Imediately call the next state upon return.
Action wait_and_call(Callback c)
Wait for resource to become available before proceeding to next state.
Action sleep_and_call(::Timer *timer, long long timeout_nsec, Callback c)
Suspends execution of this control flow for a specified time.
struct tm * gmtime_r(struct tm *result)
Get the time as a standard struct tm.
uint16_t started_
true if clock is started
time_t seconds_
Clock time at the last time update.
long long timestamp_
OS time at the last time update.
time_t compare_realtime(time_t t1, time_t t2)
Get the difference in time scaled to real time.
time_t time()
Get the time as a value of seconds relative to the system epoch.
int16_t rate_
effective clock rate
void trigger()
This will wakeup the timer prematurely, immediately.
Implementation of a Broadcast Time Protocol client.
void handle_identify_consumer(const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
Handle requested identification message.
void start_stop_logic(bool started)
Perform a bit of logic that is required whenever the clock's running state is changed.
void handle_identify_global(const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
Handle requested identification message.
void handle_updates(EventReport *event, bool report)
Handle an incoming time update.
void handle_identify_producer(const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
Handle requested identification message.
Action rollover_pending()
Wait on the completion of a date rollover sequence.
uint16_t waiting_
true if stateflow is waiting
~BroadcastTimeClient()
Destructor.
uint16_t rolloverPendingDate_
a day rollover is about to occur
void sleeping()
Setup the state flags to reflect that we are in a sleep_and_call().
bool is_server_self() override
Test if this is a server.
void wakeup()
wakeup the state machine.
uint16_t serverDetected_
has a time server been detected
Action client_update()
Notification arrived that we should update our state.
uint16_t rolloverPending_
a day rollover is about to occur
void handle_event_report(const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
Handle an incoming event report.
BroadcastTimeClient(Node *node, NodeID clock_id, bool configure_agent=false)
Constructor.
bool is_server_detected() override
Has a time server been detected?
Action initialize()
Initialize client by sending a time query.
Action client_update_maybe()
Test if we are ready to update the client, or if we may want to wait for more messages (in the form o...
uint16_t rolloverPendingYear_
a day rollover is about to occur
Action client_update_commit()
commit the client update.
void handle_producer_identified(const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
Handle an incoming producer identified.
uint16_t sleeping_
future immediate upate expected
uint16_t configureAgent_
instance can be used to configure clock
uint16_t immediateUpdate_
true if the update should be immediate
void waiting()
Setup the state flags to reflect that we are in a wait_and_call().
Implementation of Broadcast Time Protocol.
StateFlowTimer timer_
timer helper
int16_t rateRequested_
pending clock rate
void service_callbacks(time_t old, time_t current)
Service all of the attached update subscribers.
Node * node()
Accessor method to get the Node reference.
NodeID clock_id()
Accessor method to get the (48-bit) Clock ID.
struct tm tm_
the time we are last set to as a struct tm
void query()
Query the current time.
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.
EventId event
Stores the event ID or beginning of range for which to register the given handler.
Base class for NMRAnet nodes conforming to the asynchronous interface.
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
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.
#define MSEC_TO_NSEC(_msec)
Convert a millisecond value to a nanosecond value.
#define SEC_TO_NSEC(_sec)
Convert a second value to a nanosecond value.
@ EVENT_SET_SUFFIX_MASK
suffix max for setting a property
@ QUERY_EVENT_SUFFIX
query event suffix value
@ MTI_PRODUCER_IDENTIFIED_RANGE
producer broadcast about a range of producers
@ MTI_CONSUMER_IDENTIFIED_UNKNOWN
consumer broadcast, validity unknown
@ MTI_PRODUCER_IDENTIFIED_UNKNOWN
producer broadcast, validity unknown
@ MTI_CONSUMER_IDENTIFIED_RANGE
consumer broadcast about a range of consumers
Shared notification structure that is assembled for each incoming event-related message,...
EventState state
For producer/consumer identified messages, specifies the state of the producer/consumer as the sender...
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...