Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
openlcb::LatencyTestConsumer Class Reference

This event consumer works together with the hub_test application in order to detect the response latency of a node. More...

#include <LatencyTestConsumer.hxx>

Inheritance diagram for openlcb::LatencyTestConsumer:
openlcb::SimpleEventHandler openlcb::EventHandler

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 &registry_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 &registry_entry, EventReport *event, BarrierNotifiable *done)=0
 Called on incoming EventReport messages.
 
virtual void handle_consumer_identified (const EventRegistryEntry &registry_entry, EventReport *event, BarrierNotifiable *done)
 Called on another node sending ConsumerIdentified for this event.
 
virtual void handle_consumer_range_identified (const EventRegistryEntry &registry_entry, EventReport *event, BarrierNotifiable *done)
 Called on another node sending ConsumerRangeIdentified.
 
virtual void handle_producer_identified (const EventRegistryEntry &registry_entry, EventReport *event, BarrierNotifiable *done)
 Called on another node sending ProducerIdentified for this event.
 
virtual void handle_producer_range_identified (const EventRegistryEntry &registry_entry, EventReport *event, BarrierNotifiable *done)
 Called on another node sending ProducerRangeIdentified for this event.
 
virtual void handle_identify_producer (const EventRegistryEntry &registry_entry, EventReport *event, BarrierNotifiable *done)=0
 Called on another node sending IdentifyProducer.
 

Private Member Functions

void reply ()
 

Private Attributes

Nodenode_
 Which node should be sending responses.
 
HookFn hook_
 The owner's hook will be invoked and run (asynchronous) before replying.
 
EventReportevent_
 Incoming event report we are working on.
 
BarrierNotifiabledone_ {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.
 

Detailed Description

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.

Member Typedef Documentation

◆ HookFn

using openlcb::LatencyTestConsumer::HookFn = std::function<void(Notifiable *)>

To complete the hook, call the notifiable.

Definition at line 65 of file LatencyTestConsumer.hxx.

Constructor & Destructor Documentation

◆ LatencyTestConsumer()

openlcb::LatencyTestConsumer::LatencyTestConsumer ( Node node,
HookFn  hook = nullptr 
)
inline

Definition at line 67 of file LatencyTestConsumer.hxx.

Member Function Documentation

◆ handle_identify_consumer()

void openlcb::LatencyTestConsumer::handle_identify_consumer ( const EventRegistryEntry registry_entry,
EventReport event,
BarrierNotifiable done 
)
inlineoverridevirtual

Called on another node sending IdentifyConsumer.

Parameters
eventstores information about the incoming message. Filled: src_node, event, mask=1. Not filled: state.
registry_entrygives the registry entry for which the current handler is being called.
donemust be notified when the processing is done.

Implements openlcb::EventHandler.

Definition at line 89 of file LatencyTestConsumer.hxx.

◆ handle_identify_global()

void openlcb::LatencyTestConsumer::handle_identify_global ( const EventRegistryEntry registry_entry,
EventReport event,
BarrierNotifiable done 
)
inlineoverridevirtual

Called on the need of sending out identification messages.

Parameters
eventis NULL. This happens on startup, or when a global or addressed IdentifyGlobal message arrives. Might have destination node id!
registry_entrygives the registry entry for which the current handler is being called.
donemust be notified when the processing is done.

Implements openlcb::EventHandler.

Definition at line 75 of file LatencyTestConsumer.hxx.

◆ reply()

void openlcb::LatencyTestConsumer::reply ( )
inlineprivate

Definition at line 105 of file LatencyTestConsumer.hxx.

Member Data Documentation

◆ done_

BarrierNotifiable* openlcb::LatencyTestConsumer::done_ {nullptr}
private

Will notify this after sending the reply.

Definition at line 128 of file LatencyTestConsumer.hxx.

◆ event_

EventReport* openlcb::LatencyTestConsumer::event_
private

Incoming event report we are working on.

Definition at line 125 of file LatencyTestConsumer.hxx.

◆ EVENT_BASE

constexpr EventId openlcb::LatencyTestConsumer::EVENT_BASE = 0x0900013900000000
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.

◆ hook_

HookFn openlcb::LatencyTestConsumer::hook_
private

The owner's hook will be invoked and run (asynchronous) before replying.

Definition at line 122 of file LatencyTestConsumer.hxx.

◆ node_

Node* openlcb::LatencyTestConsumer::node_
private

Which node should be sending responses.

Definition at line 118 of file LatencyTestConsumer.hxx.


The documentation for this class was generated from the following file: