ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
ocit.h
Go to the documentation of this file.
1// ProtoCore v1.0.16 - 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 (PROTOCORE_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 PROTOCORE_OCIT_H
22#define PROTOCORE_OCIT_H
23
24#include "protocore_config.h" // the entry point: protocore_types.h for the widths
25
26#if PROTOCORE_ENABLE_OCIT
27
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.)
32#define OCIT_MSG_GET 0x01 ///< read an object value.
33#define OCIT_MSG_SET 0x02 ///< write an object value.
34#define OCIT_MSG_REPORT 0x03 ///< an unsolicited value report.
35#define OCIT_MSG_ERROR 0x0F ///< error response.
36
37/** @brief OCIT value data types. */
38#define OCIT_TYPE_BOOL 0x01 ///< 1 byte (0/1).
39#define OCIT_TYPE_BYTE 0x02 ///< 1 byte.
40#define OCIT_TYPE_UINT16 0x03 ///< 2 bytes, big-endian.
41#define OCIT_TYPE_UINT32 0x04 ///< 4 bytes, big-endian.
42#define OCIT_TYPE_OCTETS 0x05 ///< raw octet string (length is the remaining message).
43
44/**
45 * @brief Build an OCIT message: [msg-type][object-type:2][instance:2][data-type][value...].
46 * @param msg_type OCIT_MSG_*.
47 * @param object_type the object type id.
48 * @param instance the object instance.
49 * @param data_type OCIT_TYPE_*.
50 * @param value the value bytes (big-endian for the integer types; may be null if value_len == 0).
51 * @param value_len value length.
52 * @return the message length (6 + value_len), or 0 on overflow / bad args.
53 */
54size_t protocore_ocit_build(uint8_t msg_type, uint16_t object_type, uint16_t instance, uint8_t data_type,
55 const uint8_t *value, size_t value_len, uint8_t *out, size_t cap);
56
57/** @brief Convenience: build a SET of a uint16 value. */
58size_t protocore_ocit_set_u16(uint16_t object_type, uint16_t instance, uint16_t value, uint8_t *out, size_t cap);
59
60/** @brief A parsed OCIT message (value points into the input). */
61typedef struct
62{
63 uint8_t msg_type;
64 uint16_t object_type;
65 uint16_t instance;
66 uint8_t data_type;
67 const uint8_t *value;
68 size_t value_len;
69} OcitMsg;
70
71/** @brief Parse an OCIT message. @return true if @p len >= 6. */
72proto_bool protocore_ocit_parse(const uint8_t *msg, size_t len, OcitMsg *out);
73
74/** @brief Read a big-endian uint16 value out of a parsed message (0 if the type/length does not match). */
75uint16_t protocore_ocit_value_u16(const OcitMsg *m);
76
78
79#endif // PROTOCORE_ENABLE_OCIT
80
81#endif // PROTOCORE_OCIT_H
#define PROTOCORE_BEGIN_DECLS
Give a header's declarations C linkage, so their symbol names carry no parameter types.
Definition types.h:96
_Bool proto_bool
The truth value.
Definition types.h:64
#define PROTOCORE_END_DECLS
Definition types.h:97