15size_t pc_lon_build_nv(uint8_t msg_code, uint16_t selector,
const uint8_t *value,
size_t value_len, uint8_t *out,
18 if (!out || (value_len && !value) || selector > Lon::LON_NV_SELECTOR_MAX)
22 size_t n = 3 + value_len;
28 out[1] = (uint8_t)(selector >> 8);
29 out[2] = (uint8_t)selector;
32 memcpy(out + 3, value, value_len);
37bool pc_lon_parse_nv(
const uint8_t *pdu,
size_t len, LonNv *out)
39 if (!pdu || !out || len < 3)
43 out->msg_code = pdu[0];
44 out->selector = (uint16_t)(((pdu[1] & 0x3F) << 8) | pdu[2]);
45 out->value = (len > 3) ? (pdu + 3) :
nullptr;
46 out->value_len = len - 3;
50void pc_lon_snvt_temp_encode(
double celsius, uint8_t out[2])
53 double kelvin_hundredths = (celsius + 273.15) * 100.0;
54 int32_t v = (int32_t)(kelvin_hundredths >= 0 ? kelvin_hundredths + 0.5 : kelvin_hundredths - 0.5);
63 uint16_t u = (uint16_t)v;
64 out[0] = (uint8_t)(u >> 8);
68double pc_lon_snvt_temp_decode(
const uint8_t in[2])
70 int16_t v = (int16_t)((in[0] << 8) | in[1]);
71 return (
double)v / 100.0 - 273.15;
74void pc_lon_snvt_switch_encode(
double percent, uint8_t state, uint8_t out[2])
85 uint8_t v = (uint8_t)(percent * 2.0 + 0.5);
90void pc_lon_snvt_switch_decode(
const uint8_t in[2],
double *percent, uint8_t *state)
94 *percent = (double)in[0] / 2.0;
LonWorks / LON-IP (ISO/IEC 14908) network-variable codec (PC_ENABLE_LONWORKS).