44 template<
typename T> T
as()
const {
45 static_assert(
sizeof(T) <= 4,
"SDO values are at most 4 bytes");
46 if constexpr (std::is_same_v<T, float>) {
48 std::memcpy(&f, &this->value,
sizeof(f));
50 }
else if constexpr (std::is_signed_v<T>) {
51 if (this->size == 0 || this->size >= 4)
52 return static_cast<T
>(
static_cast<int32_t
>(this->
value));
53 uint32_t sign = 1u << (this->size * 8 - 1);
54 return static_cast<T
>(
static_cast<int32_t
>((this->value ^ sign) - sign));
56 return static_cast<T
>(this->
value);
126 if (can_id < 0x701 || can_id > 0x77F ||
len != 1)
128 node = can_id - 0x700;
130 const auto raw =
static_cast<NMTState>(data[0] & 0x7F);
141 if (can_id < 0x81 || can_id > 0xFF ||
len != 8)
143 node = can_id - 0x80;
bool decode_heartbeat(uint32_t can_id, const uint8_t *data, size_t len, uint8_t &node, NMTState &state)
void(*)(void *context, uint32_t can_id, const uint8_t *data, uint8_t len) FrameCallback
@ NMT_STATE_PRE_OPERATIONAL
const LogString * sdo_result_to_string(SDOResult result)
@ NMT_COMMAND_RESET_COMMUNICATION
@ NMT_COMMAND_PRE_OPERATIONAL
bool decode_emcy(uint32_t can_id, const uint8_t *data, size_t len, uint8_t &node, Emergency &emcy)
const LogString * nmt_state_to_string(NMTState state)
const LogString * node_event_to_string(NodeEvent event)
@ SDO_RESULT_SIZE_MISMATCH
@ SDO_RESULT_TRANSPORT_ERROR
constexpr std::array< NMTState, 4 > NMT_STATES
void(*)(void *context, const SDOReply &reply) SDOCallback
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
std::array< uint8_t, 5 > manufacturer_data