DeterministicESPAsyncWebServer v6.28.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
sercos.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file sercos.h
6 * @brief SERCOS III motion-bus telegram + IDN codec (DETWS_ENABLE_SERCOS).
7 *
8 * SERCOS III is the real-time drive/motion bus over Ethernet (raw L2, ethertype 0x88CD, on the shipped
9 * services/rawl2). The master cyclically sends **MDT** (Master Data Telegrams) carrying setpoints to the
10 * drives, and the drives answer with **AT** (Acknowledge / drive Telegrams) carrying actual values. Both
11 * carry a short SERCOS header then the cyclic device data; a separate **service channel** transfers
12 * parameters addressed by an **IDN** (IDentification Number):
13 *
14 * Telegram header: [type MDT/AT : 1][phase/counter : 1][cycle count : 2]
15 * IDN (16 bit): S/P bit(1) | parameter-set(3) | data-block(12) -> "S-0-0100" style addressing
16 *
17 * This provides the MDT/AT telegram framing + the IDN encode/decode (the addressing every drive
18 * parameter uses). The isochronous timing + the ring/line topology are the hardware-gated part. Pure,
19 * zero heap, no stdlib, host-testable.
20 */
21
22#ifndef DETERMINISTICESPASYNCWEBSERVER_SERCOS_H
23#define DETERMINISTICESPASYNCWEBSERVER_SERCOS_H
24
25#include "ServerConfig.h"
26#include <stddef.h>
27#include <stdint.h>
28
29#if DETWS_ENABLE_SERCOS
30
31// SERCOS telegram types + header length: wire values, so integer constants in a struct.
32struct Sercos
33{
34 static constexpr uint8_t SERCOS_TEL_MDT = 0x00; ///< Master Data Telegram (master -> drives).
35 static constexpr uint8_t SERCOS_TEL_AT = 0x01; ///< Acknowledge Telegram (drive -> master).
36 static constexpr uint8_t SERCOS_HDR_LEN = 4;
37};
38
39/**
40 * @brief Encode a SERCOS IDN (16-bit) from its parts.
41 * @param is_product true = a P-parameter (product-specific), false = an S-parameter (standard).
42 * @param param_set the parameter set 0..7.
43 * @param data_block the data block number 0..4095.
44 * @return the 16-bit IDN: bit15 = S/P, bits14..12 = set, bits11..0 = block.
45 */
46uint16_t detws_sercos_idn(bool is_product, uint8_t param_set, uint16_t data_block);
47
48/** @brief Decode a SERCOS IDN into its parts (any out-pointer may be null). */
49void detws_sercos_idn_parse(uint16_t idn, bool *is_product, uint8_t *param_set, uint16_t *data_block);
50
51/**
52 * @brief Build a SERCOS telegram: [type][phase][cycle:2 LE][data...].
53 * @param type SERCOS_TEL_MDT or SERCOS_TEL_AT.
54 * @param phase the communication phase / counter byte.
55 * @param cycle the cycle count.
56 * @param data the cyclic device data (may be null if data_len == 0).
57 * @return the telegram length (4 + data_len), or 0 on overflow.
58 */
59size_t detws_sercos_build(uint8_t type, uint8_t phase, uint16_t cycle, const uint8_t *data, size_t data_len,
60 uint8_t *out, size_t cap);
61
62/** @brief A parsed SERCOS telegram (data points into the input). */
63struct SercosTelegram
64{
65 uint8_t type;
66 uint8_t phase;
67 uint16_t cycle;
68 const uint8_t *data;
69 size_t data_len;
70};
71
72/** @brief Parse a SERCOS telegram. @return true if @p len >= 4 and the type is MDT/AT. */
73bool detws_sercos_parse(const uint8_t *frame, size_t len, SercosTelegram *out);
74
75#endif // DETWS_ENABLE_SERCOS
76#endif // DETERMINISTICESPASYNCWEBSERVER_SERCOS_H
User-facing configuration for DeterministicESPAsyncWebServer.