DeterministicESPAsyncWebServer v6.28.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
iccp.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 iccp.h
6 * @brief ICCP / TASE.2 (IEC 60870-6) inter-control-center telemetry codec (DETWS_ENABLE_ICCP).
7 *
8 * ICCP (TASE.2, IEC 60870-6) exchanges real-time power-grid telemetry between control centers. It is an
9 * application profile *on top of MMS* (the shipped services/mms): a TASE.2 "indication point" (a data
10 * value with quality + timestamp) is transferred as an MMS Read on a named object. This codec builds the
11 * TASE.2 data value - the standard `Data_Value` structure a Read carries:
12 *
13 * Data_Value ::= SEQUENCE { value CHOICE {state/discrete/real/...}, flags DataFlags, timestamp }
14 *
15 * simplified here to the common **StateQ** (a discrete state 0..3 + a quality-flags byte) and **RealQ**
16 * (an IEEE-754-ish scaled real + quality) indication points that most bilateral tables use. The result
17 * is a BER blob the caller wraps in an MMS Read response (`detws_mms_read_response`). Pure, zero heap,
18 * no stdlib, host-testable; the TASE.2 bilateral-table + MMS transport are the shipped services.
19 */
20
21#ifndef DETERMINISTICESPASYNCWEBSERVER_ICCP_H
22#define DETERMINISTICESPASYNCWEBSERVER_ICCP_H
23
24#include "ServerConfig.h"
25#include <stddef.h>
26#include <stdint.h>
27
28#if DETWS_ENABLE_ICCP
29
30/** @brief TASE.2 quality flags (DataFlags, the common bits). */
31// TASE.2 quality/state wire values + the 2-bit quality mask, so integer constants in a struct.
32struct Iccp
33{
34 static constexpr uint8_t ICCP_QUAL_VALID = 0x00; ///< value is valid.
35 static constexpr uint8_t ICCP_QUAL_HELD = 0x01; ///< value is held (frozen).
36 static constexpr uint8_t ICCP_QUAL_SUSPECT = 0x02; ///< value is suspect.
37 static constexpr uint8_t ICCP_QUAL_NOTVALID = 0x03; ///< value is not valid.
38 static constexpr uint8_t ICCP_QUAL_MASK = 0x03;
39 static constexpr uint8_t ICCP_STATE_BETWEEN = 0x00; ///< StateQ: intermediate.
40 static constexpr uint8_t ICCP_STATE_OFF = 0x01;
41 static constexpr uint8_t ICCP_STATE_ON = 0x02;
42 static constexpr uint8_t ICCP_STATE_INVALID = 0x03;
43};
44
45/**
46 * @brief Build a TASE.2 StateQ Data_Value: a discrete state + quality flags.
47 * @param state the 2-bit state (ICCP_STATE_*).
48 * @param flags the quality flags byte (ICCP_QUAL_*).
49 * @param time the 4-octet TimeStamp (seconds since 1970; big-endian), or null for no timestamp.
50 * @return the BER length written, or 0 on overflow.
51 *
52 * Encodes `[A2 { 85 <stateAndQuality byte> [17 <4-octet time>] }]` (context-tagged StateQ structure).
53 */
54size_t detws_iccp_state_q(uint8_t state, uint8_t flags, const uint8_t time[4], uint8_t *out, size_t cap);
55
56/**
57 * @brief Build a TASE.2 RealQ Data_Value: a scaled real value (milli-units) + quality flags.
58 * @param milli the value in 1/1000 units (so 12.345 -> 12345), a signed 32-bit integer.
59 * @param flags the quality flags byte.
60 * @param time the 4-octet TimeStamp, or null.
61 * @return the BER length written, or 0 on overflow.
62 *
63 * Encodes `[A3 { 02 <INTEGER milli> 85 <quality byte> [17 <time>] }]`.
64 */
65size_t detws_iccp_real_q(int32_t milli, uint8_t flags, const uint8_t time[4], uint8_t *out, size_t cap);
66
67#endif // DETWS_ENABLE_ICCP
68#endif // DETERMINISTICESPASYNCWEBSERVER_ICCP_H
User-facing configuration for DeterministicESPAsyncWebServer.