11#if DETWS_ENABLE_SERCOS
15uint16_t detws_sercos_idn(
bool is_product, uint8_t param_set, uint16_t data_block)
17 return (uint16_t)(((is_product ? 1u : 0u) << 15) | ((uint32_t)(param_set & 0x7) << 12) | (data_block & 0x0FFF));
20void detws_sercos_idn_parse(uint16_t idn,
bool *is_product, uint8_t *param_set, uint16_t *data_block)
23 *is_product = (idn & 0x8000) != 0;
25 *param_set = (uint8_t)((idn >> 12) & 0x7);
27 *data_block = (uint16_t)(idn & 0x0FFF);
30size_t detws_sercos_build(uint8_t type, uint8_t phase, uint16_t cycle,
const uint8_t *data,
size_t data_len,
31 uint8_t *out,
size_t cap)
33 if (!out || (data_len && !data) || (type != Sercos::SERCOS_TEL_MDT && type != Sercos::SERCOS_TEL_AT))
35 size_t n = Sercos::SERCOS_HDR_LEN + data_len;
40 out[2] = (uint8_t)cycle;
41 out[3] = (uint8_t)(cycle >> 8);
43 memcpy(out + Sercos::SERCOS_HDR_LEN, data, data_len);
47bool detws_sercos_parse(
const uint8_t *frame,
size_t len, SercosTelegram *out)
49 if (!frame || !out || len < Sercos::SERCOS_HDR_LEN)
51 if (frame[0] != Sercos::SERCOS_TEL_MDT && frame[0] != Sercos::SERCOS_TEL_AT)
54 out->phase = frame[1];
55 out->cycle = (uint16_t)(frame[2] | (frame[3] << 8));
56 out->data = (len > Sercos::SERCOS_HDR_LEN) ? (frame + Sercos::SERCOS_HDR_LEN) :
nullptr;
57 out->data_len = len - Sercos::SERCOS_HDR_LEN;
SERCOS III motion-bus telegram + IDN codec (DETWS_ENABLE_SERCOS).