Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Convert.hxx
Go to the documentation of this file.
1
35#ifndef _OPENLCB_CONVERT_HXX_
36#define _OPENLCB_CONVERT_HXX_
37
38#include <endian.h>
39#include <string.h>
40
41#include "openlcb/Defs.hxx"
42
43namespace openlcb
44{
45
52extern string node_id_to_buffer(NodeID id);
60extern void node_id_to_data(NodeID id, void *data);
61
68extern NodeID buffer_to_node_id(const string &buf);
74extern NodeID data_to_node_id(const void *d);
75
77extern Payload eventid_to_buffer(uint64_t eventid);
78
81inline uint64_t data_to_eventid(const void *data)
82{
83 uint64_t ret = 0;
84 memcpy(&ret, data, 8);
85 return be64toh(ret);
86}
87
90extern string error_to_buffer(uint16_t error_code, uint16_t mti);
91
94extern string error_to_buffer(uint16_t error_code);
95
97extern void error_to_data(uint16_t error_code, void *data);
98
100extern uint16_t data_to_error(const void *data);
101
103extern void append_error_to_buffer(uint16_t error_code, Payload *p);
104
114extern void buffer_to_error(const Payload &payload, uint16_t *error_code,
115 uint16_t *mti, string *error_message);
116
121extern Payload error_payload(uint16_t error_code, Defs::MTI incoming_mti);
122
124extern string EMPTY_PAYLOAD;
125
127inline unsigned node_high(NodeID id)
128{
129 return id >> 32;
130}
132inline unsigned node_low(NodeID id)
133{
134 return id & 0xffffffffU;
135}
136
137} // namespace openlcb
138
139#endif
string EMPTY_PAYLOAD
A global class / variable for empty or not-yet-initialized payloads.
Definition If.cxx:152
void node_id_to_data(NodeID id, void *data)
Convenience function to render a 48-bit NMRAnet node ID into an existing buffer.
Definition If.cxx:52
string node_id_to_buffer(NodeID id)
Convenience function to render a 48-bit NMRAnet node ID into a new buffer.
Definition If.cxx:45
uint64_t data_to_eventid(const void *data)
Takes 8 bytes (big-endian) from *data, and returns the event id they represent.
Definition Convert.hxx:81
NodeID data_to_node_id(const void *d)
Converts 6 bytes of big-endian data to a node ID.
Definition If.cxx:59
uint64_t NodeID
48-bit NMRAnet Node ID type
uint16_t data_to_error(const void *data)
Parses an error code from a payload object at a given pointer.
Definition If.cxx:84
void error_to_data(uint16_t error_code, void *data)
Writes an error code into a payload object at a given pointer.
Definition If.cxx:78
NodeID buffer_to_node_id(const string &buf)
Converts a 6-byte-long buffer to a node ID.
Definition If.cxx:66
unsigned node_high(NodeID id)
Definition Convert.hxx:127
void append_error_to_buffer(uint16_t error_code, Payload *p)
Appends an error to the end of an existing buffer.
Definition If.cxx:106
string Payload
Container that carries the data bytes in an NMRAnet message.
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
void buffer_to_error(const Payload &payload, uint16_t *error_code, uint16_t *mti, string *error_message)
Parses the payload of an Optional Interaction Rejected or Terminate Due To Error message.
Definition If.cxx:112
Payload error_payload(uint16_t error_code, Defs::MTI incoming_mti)
Generates the payload for an OIR or TDE message.
Definition If.cxx:135
unsigned node_low(NodeID id)
Definition Convert.hxx:132
string error_to_buffer(uint16_t error_code, uint16_t mti)
Formats a payload for response of error response messages such as OPtioanl Interaction Rejected or Te...
Definition If.cxx:90
MTI
Known Message type indicators.