DeterministicESPAsyncWebServer v6.28.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
atc.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 atc.h
6 * @brief ATC (Advanced Traffic Controller) field-I/O interop snapshot (DETWS_ENABLE_ATC).
7 *
8 * The ATC standard moves traffic cabinets to a standard Linux engine with an ITS-Cabinet / ATC field-I/O
9 * API (the FIO): the controller reads detector/input points and drives signal/output points through a
10 * fixed I/O map. ATC is a host-platform spec more than a wire protocol, so the useful slice for this
11 * library is *interop*: exposing this device's field-I/O (which it already gathers via the shipped NTCIP
12 * / NEMA-TS2 / gpio services) to an ATC engine over the existing HTTP surface, as a compact JSON snapshot.
13 *
14 * This is that snapshot codec: a fixed table of named field-I/O points (each an input or output bit or
15 * byte) that `detws_atc_snapshot_json` serializes as `{"inputs":[...],"outputs":[...]}` for a GET, and a
16 * setter to drive an output point from an ATC command. Pure, zero heap, no stdlib, host-testable.
17 */
18
19#ifndef DETERMINISTICESPASYNCWEBSERVER_ATC_H
20#define DETERMINISTICESPASYNCWEBSERVER_ATC_H
21
22#include "ServerConfig.h"
23#include <stddef.h>
24#include <stdint.h>
25
26#if DETWS_ENABLE_ATC
27
28/** @brief One ATC field-I/O point. */
29struct AtcPoint
30{
31 const char *name; ///< the FIO point name (borrowed), e.g. "det.1", "phase.2.green".
32 bool is_output; ///< true = an output (a driver the controller sets), false = an input (a sensor).
33 uint8_t value; ///< the current 8-bit value (a bit is 0/1; a byte is 0..255).
34};
35
36/** @brief The field-I/O map: a fixed table of points the ATC engine sees. */
37struct AtcFieldIo
38{
39 AtcPoint *points;
40 size_t count;
41};
42
43/**
44 * @brief Serialize the field-I/O map as `{"inputs":[{"name":..,"value":..},...],"outputs":[...]}`.
45 * @return length written (excl NUL), or 0 on overflow / bad args. Point names are JSON-escaped.
46 */
47size_t detws_atc_snapshot_json(const AtcFieldIo *io, char *out, size_t cap);
48
49/**
50 * @brief Drive an output point by name from an ATC command.
51 * @return true if the named point exists and is an output (its value is set); false otherwise.
52 */
53bool detws_atc_set_output(AtcFieldIo *io, const char *name, uint8_t value);
54
55/** @brief Read a point's value by name; @p found (may be null) reports whether it existed. */
56uint8_t detws_atc_get(const AtcFieldIo *io, const char *name, bool *found);
57
58#endif // DETWS_ENABLE_ATC
59#endif // DETERMINISTICESPASYNCWEBSERVER_ATC_H
User-facing configuration for DeterministicESPAsyncWebServer.