|
Open Model Railroad Network (OpenMRN)
|
This event consumer works together with the hub_test application in order to detect the response latency of a node. More...
#include <LatencyTestConsumer.hxx>
Public Types | |
| using | HookFn = std::function< void(Notifiable *)> |
| To complete the hook, call the notifiable. | |
Public Types inherited from openlcb::EventHandler | |
| using | EventReport = openlcb::EventReport |
| using | EventRegistryEntry = openlcb::EventRegistryEntry |
| using | EventId = openlcb::EventId |
Public Member Functions | |
| LatencyTestConsumer (Node *node, HookFn hook=nullptr) | |
| void | handle_identify_global (const EventRegistryEntry ®istry_entry, EventReport *event, BarrierNotifiable *done) override |
| Called on the need of sending out identification messages. | |
| void | handle_identify_consumer (const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override |
| Called on another node sending IdentifyConsumer. | |
Public Member Functions inherited from openlcb::SimpleEventHandler | |
| IGNOREFN (handle_event_report) | |
| IGNOREFN (handle_consumer_identified) | |
| IGNOREFN (handle_consumer_range_identified) | |
| IGNOREFN (handle_producer_identified) | |
| IGNOREFN (handle_producer_range_identified) | |
| IGNOREFN (handle_identify_consumer) | |
| IGNOREFN (handle_identify_producer) | |
Public Member Functions inherited from openlcb::EventHandler | |
| virtual void | handle_event_report (const EventRegistryEntry ®istry_entry, EventReport *event, BarrierNotifiable *done)=0 |
| Called on incoming EventReport messages. | |
| virtual void | handle_consumer_identified (const EventRegistryEntry ®istry_entry, EventReport *event, BarrierNotifiable *done) |
| Called on another node sending ConsumerIdentified for this event. | |
| virtual void | handle_consumer_range_identified (const EventRegistryEntry ®istry_entry, EventReport *event, BarrierNotifiable *done) |
| Called on another node sending ConsumerRangeIdentified. | |
| virtual void | handle_producer_identified (const EventRegistryEntry ®istry_entry, EventReport *event, BarrierNotifiable *done) |
| Called on another node sending ProducerIdentified for this event. | |
| virtual void | handle_producer_range_identified (const EventRegistryEntry ®istry_entry, EventReport *event, BarrierNotifiable *done) |
| Called on another node sending ProducerRangeIdentified for this event. | |
| virtual void | handle_identify_producer (const EventRegistryEntry ®istry_entry, EventReport *event, BarrierNotifiable *done)=0 |
| Called on another node sending IdentifyProducer. | |
Private Member Functions | |
| void | reply () |
Private Attributes | |
| Node * | node_ |
| Which node should be sending responses. | |
| HookFn | hook_ |
| The owner's hook will be invoked and run (asynchronous) before replying. | |
| EventReport * | event_ |
| Incoming event report we are working on. | |
| BarrierNotifiable * | done_ {nullptr} |
| Will notify this after sending the reply. | |
Static Private Attributes | |
| static constexpr EventId | EVENT_BASE = 0x0900013900000000 |
| This is within NMRA ID 1, which is not assigned. | |
This event consumer works together with the hub_test application in order to detect the response latency of a node.
The theory of operation is that hub_test sends out an identify consumer message with a given event ID, and this consumer is going to respond. The hub_test then measures the response latency. There is a big event range being advertised (32 bits), and hub_test will send events with different IDs to be able to match request to response.
Here in the consumer the only thing we need to do is respond to identify consumer messages with consumer identified.
An additional feature is to be able to measure an arbitrary processing step inside the node. For this purpose we have a hook function. When the identify producer message comes in, we call the hook. When the measured process completes, it should notify the given notifiable. Only thereafter the consumer will reply on the bus. Requests' handling is not parallelized. If the hook process cannot complete the requests fast enough, the node will run out of memory and crash.
Definition at line 61 of file LatencyTestConsumer.hxx.
| using openlcb::LatencyTestConsumer::HookFn = std::function<void(Notifiable *)> |
To complete the hook, call the notifiable.
Definition at line 65 of file LatencyTestConsumer.hxx.
Definition at line 67 of file LatencyTestConsumer.hxx.
|
inlineoverridevirtual |
Called on another node sending IdentifyConsumer.
| event | stores information about the incoming message. Filled: src_node, event, mask=1. Not filled: state. |
| registry_entry | gives the registry entry for which the current handler is being called. |
| done | must be notified when the processing is done. |
Implements openlcb::EventHandler.
Definition at line 89 of file LatencyTestConsumer.hxx.
|
inlineoverridevirtual |
Called on the need of sending out identification messages.
| event | is NULL. This happens on startup, or when a global or addressed IdentifyGlobal message arrives. Might have destination node id! |
| registry_entry | gives the registry entry for which the current handler is being called. |
| done | must be notified when the processing is done. |
Implements openlcb::EventHandler.
Definition at line 75 of file LatencyTestConsumer.hxx.
|
inlineprivate |
Definition at line 105 of file LatencyTestConsumer.hxx.
|
private |
Will notify this after sending the reply.
Definition at line 128 of file LatencyTestConsumer.hxx.
|
private |
Incoming event report we are working on.
Definition at line 125 of file LatencyTestConsumer.hxx.
|
staticconstexprprivate |
This is within NMRA ID 1, which is not assigned.
Lower four bytes are the id.
Definition at line 115 of file LatencyTestConsumer.hxx.
|
private |
The owner's hook will be invoked and run (asynchronous) before replying.
Definition at line 122 of file LatencyTestConsumer.hxx.
|
private |
Which node should be sending responses.
Definition at line 118 of file LatencyTestConsumer.hxx.