Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
SimpleNodeInfo.hxx
Go to the documentation of this file.
1
35#ifndef _NRMANET_SIMPLENODEINFO_HXX_
36#define _NRMANET_SIMPLENODEINFO_HXX_
37
38#include "openlcb/If.hxx"
41
42namespace openlcb
43{
44
45
48void init_snip_user_file(int fd, const char *user_name,
49 const char *user_description);
50
57{
58public:
59 SNIPHandler(If *iface, Node* node, SimpleInfoFlow *response_flow)
61 , node_(node)
62 , responseFlow_(response_flow)
63 {
64 HASSERT(SNIP_STATIC_DATA.version == 4);
67 }
68
70 {
73 }
74
76 {
77 if (!nmsg()->dstNode)
78 return release_and_exit();
79 if (node_ && nmsg()->dstNode != node_)
80 return release_and_exit();
81 return allocate_and_call(responseFlow_, STATE(send_response_request));
82 }
83
84 Action send_response_request()
85 {
86 auto *b = get_allocation_result(responseFlow_);
87 b->data()->reset(nmsg(), SNIP_DYNAMIC_FILENAME == nullptr ? SNIP_STATIC_RESPONSE : SNIP_RESPONSE, Defs::MTI_IDENT_INFO_REPLY);
88 responseFlow_->send(b);
89 return release_and_exit();
90 }
91
92private:
97
98 Node* node_;
99 SimpleInfoFlow *responseFlow_;
100};
101
105 void clear() {
106 manufacturer_name.clear();
107 model_name.clear();
108 hardware_version.clear();
109 software_version.clear();
110 user_name.clear();
111 user_description.clear();
112 }
121
123 string user_name;
126};
127
135 const openlcb::Payload &payload, SnipDecodedData *output);
136
137} // namespace openlcb
138
139#endif // _NRMANET_SIMPLENODEINFO_HXX_
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
Definition StateFlow.hxx:61
void register_handler(HandlerType *handler, ID id, ID mask)
Adds a new handler to this dispatcher.
void unregister_handler(HandlerType *handler, ID id, ID mask)
Removes a specific instance of a handler from this dispatcher.
Base::Action Action
Allows using Action without having StateFlowBase:: prefix in front of it.
void send(MessageType *msg, unsigned priority=UINT_MAX) OVERRIDE
Sends a message to the state flow for processing.
Abstract class representing an OpenLCB Interface.
Definition If.hxx:185
MessageDispatchFlow * dispatcher()
Definition If.hxx:224
Base class for incoming message handler flows.
Definition If.hxx:400
GenMessage * nmsg()
Returns the NMRAnet message we received.
Definition If.hxx:413
Base class for NMRAnet nodes conforming to the asynchronous interface.
Definition Node.hxx:52
Handler for the Simple Node Information Protocol requests.
static const SimpleInfoDescriptor SNIP_RESPONSE[]
Defines the SNIP response fields.
static const SimpleInfoDescriptor SNIP_STATIC_RESPONSE[]
Defines the SNIP response fields without dynamic file.
Action entry() OVERRIDE
Entry into the StateFlow activity.
StateFlow for sending out medium-sized data payloads like the Simple Node Ident Info protocol.
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...
Definition macros.h:180
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
Definition macros.h:138
const SimpleNodeStaticValues SNIP_STATIC_DATA
This static data will be exported as the first block of SNIP.
void decode_snip_response(const openlcb::Payload &payload, SnipDecodedData *output)
Takes an NMRANet SNIP repsonse message paylaod and splits it up into individual fields of the respons...
void init_snip_user_file(int fd, const char *user_name, const char *user_description)
Helper function for test nodes.
string Payload
Container that carries the data bytes in an NMRAnet message.
const char *const SNIP_DYNAMIC_FILENAME
The SNIP dynamic data will be read from this file.
The generic interface for NMRAnet network interfaces.
@ MTI_IDENT_INFO_REQUEST
request node identity
@ MTI_EXACT
match mask for a single MTI
This structure defines how to piece together a reply to a Simple Info request, sich as SNIP.
Holds the data we decoded from a SNIP response.
void clear()
Resets all entries to empty.
string hardware_version
SNIP response field.
string manufacturer_name
SNIP response field.
string user_description
SNIP response field.
string software_version
SNIP response field.
string user_name
SNIP response field.
string model_name
SNIP response field.