DeterministicESPAsyncWebServer v6.28.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
ocit.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 ocit.h
6 * @brief OCIT-Outstations message codec (DETWS_ENABLE_OCIT).
7 *
8 * OCIT (Open Communication Interface for Road Traffic Control) is the DE/AT/CH open field-controller
9 * interface between central traffic computers, field controllers, and detectors. The OCIT-Outstations
10 * (OCIT-O) message set exchanges **objects** identified by an object type + instance, carrying typed
11 * values, in a compact binary message:
12 *
13 * [message-type : 1][object-type : 2][instance : 2][data-type : 1][value...]
14 *
15 * where message-type is a get / set / report, object-type + instance address the field object (a signal
16 * group, a detector, a controller state), and the data-type tags the value (a bool, a byte, a 16/32-bit
17 * integer, or a raw octet string). This codec builds/parses those messages. Pure, zero heap, no stdlib,
18 * host-testable; the OCIT transport (TCP / the OCIT-O BTPPL profile) is the shipped transport.
19 */
20
21#ifndef DETERMINISTICESPASYNCWEBSERVER_OCIT_H
22#define DETERMINISTICESPASYNCWEBSERVER_OCIT_H
23
24#include "ServerConfig.h"
25#include <stddef.h>
26#include <stdint.h>
27
28#if DETWS_ENABLE_OCIT
29
30// OCIT message types: wire bytes compared/emitted, so integer constants in a namespacing struct.
31// (OcitMsg is the parsed-message struct below; these codes live in OcitMsgType.)
32struct OcitMsgType
33{
34 static constexpr uint8_t OCIT_MSG_GET = 0x01; ///< read an object value.
35 static constexpr uint8_t OCIT_MSG_SET = 0x02; ///< write an object value.
36 static constexpr uint8_t OCIT_MSG_REPORT = 0x03; ///< an unsolicited value report.
37 static constexpr uint8_t OCIT_MSG_ERROR = 0x0F; ///< error response.
38};
39
40/** @brief OCIT value data types. */
41// OCIT value data types: wire bytes, so integer constants in a namespacing struct.
42struct OcitType
43{
44 static constexpr uint8_t OCIT_TYPE_BOOL = 0x01; ///< 1 byte (0/1).
45 static constexpr uint8_t OCIT_TYPE_BYTE = 0x02; ///< 1 byte.
46 static constexpr uint8_t OCIT_TYPE_UINT16 = 0x03; ///< 2 bytes, big-endian.
47 static constexpr uint8_t OCIT_TYPE_UINT32 = 0x04; ///< 4 bytes, big-endian.
48 static constexpr uint8_t OCIT_TYPE_OCTETS = 0x05; ///< raw octet string (length is the remaining message).
49};
50
51/**
52 * @brief Build an OCIT message: [msg-type][object-type:2][instance:2][data-type][value...].
53 * @param msg_type OCIT_MSG_*.
54 * @param object_type the object type id.
55 * @param instance the object instance.
56 * @param data_type OCIT_TYPE_*.
57 * @param value the value bytes (big-endian for the integer types; may be null if value_len == 0).
58 * @param value_len value length.
59 * @return the message length (6 + value_len), or 0 on overflow / bad args.
60 */
61size_t detws_ocit_build(uint8_t msg_type, uint16_t object_type, uint16_t instance, uint8_t data_type,
62 const uint8_t *value, size_t value_len, uint8_t *out, size_t cap);
63
64/** @brief Convenience: build a SET of a uint16 value. */
65size_t detws_ocit_set_u16(uint16_t object_type, uint16_t instance, uint16_t value, uint8_t *out, size_t cap);
66
67/** @brief A parsed OCIT message (value points into the input). */
68struct OcitMsg
69{
70 uint8_t msg_type;
71 uint16_t object_type;
72 uint16_t instance;
73 uint8_t data_type;
74 const uint8_t *value;
75 size_t value_len;
76};
77
78/** @brief Parse an OCIT message. @return true if @p len >= 6. */
79bool detws_ocit_parse(const uint8_t *msg, size_t len, OcitMsg *out);
80
81/** @brief Read a big-endian uint16 value out of a parsed message (0 if the type/length does not match). */
82uint16_t detws_ocit_value_u16(const OcitMsg *m);
83
84#endif // DETWS_ENABLE_OCIT
85#endif // DETERMINISTICESPASYNCWEBSERVER_OCIT_H
User-facing configuration for DeterministicESPAsyncWebServer.