44 4,
"OpenMRN",
"Undefined model",
"Undefined HW version",
"0.9"};
47 const char *user_description)
49 ::lseek(fd, 0, SEEK_SET);
51 memset(&data, 0,
sizeof(data));
56 auto *p = (
const uint8_t *)&data;
57 const int len =
sizeof(data);
60 int ret = ::write(fd, p, len - ofs);
63 LOG(
FATAL,
"Init SNIP file: Could not write to fd %d: %s", fd,
70static size_t find_string_at(
const openlcb::Payload& payload,
size_t start_pos,
string* output) {
71 if (start_pos >= payload.size()) {
75 size_t epos = payload.find(
'\0', start_pos);
76 output->assign(payload.substr(start_pos, epos - start_pos));
77 if (epos == string::npos) {
92 char sys_ver = payload[0];
95 pos = find_string_at(payload, pos, &output->
model_name);
99 for (
int i = 4; i < sys_ver; ++i)
102 pos = find_string_at(payload, pos, &discard);
104 if (pos == string::npos)
110 pos = find_string_at(payload, pos, &output->
user_name);
#define LOG(level, message...)
Conditionally write a message to the logging output.
static const int FATAL
Loglevel that kills the current process.
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.
Structure representing the layout of the memory space for Simple Node Identification user-editable da...
Structure representing the layout of the memory space for Simple Node Identification manufacturer-spe...
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.