DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
hostlink.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 hostlink.h
6 * @brief Omron Host Link (C-mode) frame codec (DETWS_ENABLE_HOSTLINK) - zero-heap ASCII
7 * command/response framing for the Omron serial host-link protocol, the RS-232/485
8 * sibling of FINS.
9 *
10 * A Host Link frame is ASCII:
11 * @code
12 * @ UU XX <text> FF * CR
13 * @endcode
14 * - `@` start, `UU` the 2-digit unit/node number, `XX` the 2-char header code (e.g. `RD`),
15 * `<text>` the data, `FF` the 2-hex-char FCS, then the `*` + CR (0x0D) terminator.
16 * - FCS = the 8-bit XOR of every character from `@` through the last text character,
17 * rendered as two uppercase hex digits.
18 * - A response's text begins with a 2-char end code (00 = normal).
19 *
20 * This is the frame codec (build + FCS-validated parse); the serial transport is the app's.
21 *
22 * @author Douglas Quigg (dstroy0)
23 * @date 2026
24 */
25
26#ifndef DETERMINISTICESPASYNCWEBSERVER_HOSTLINK_H
27#define DETERMINISTICESPASYNCWEBSERVER_HOSTLINK_H
28
29#include "ServerConfig.h"
30
31#if DETWS_ENABLE_HOSTLINK
32
33#include <stddef.h>
34#include <stdint.h>
35
36/** @brief FCS: 8-bit XOR of [data, data+len). */
37uint8_t hostlink_fcs(const char *data, size_t len);
38
39/**
40 * @brief Build a frame: `@UU` + header_code(2) + text + FCS(2 hex) + `*` + CR.
41 * @param node unit/node number (0-99, rendered as 2 BCD-style digits).
42 * @param header_code the 2-character header code (e.g. "RD"); must be 2 chars.
43 * @return total characters written (NOT counting the NUL), or 0 on overflow / bad input.
44 * @note The frame is NUL-terminated, so @p cap must hold the frame plus one terminator
45 * byte; the return value is the frame length, so callers may also treat @p buf as a
46 * C-string.
47 */
48size_t hostlink_build(char *buf, size_t cap, uint8_t node, const char *header_code, const char *text, size_t text_len);
49
50/** @brief A parsed frame; @ref text points INTO the source buffer (after the header, before the FCS). */
51struct HostlinkFrame
52{
53 uint8_t node;
54 char header_code[3]; ///< 2 chars + NUL
55 const char *text;
56 size_t text_len;
57};
58
59/**
60 * @brief Parse + FCS-validate a frame (command or response).
61 * @return true on a complete, FCS-valid `@...*CR` frame; false otherwise.
62 */
63bool hostlink_parse(const char *buf, size_t len, HostlinkFrame *out);
64
65/** @brief Read a response's 2-char end code (the first two text characters) as a byte. */
66bool hostlink_end_code(const HostlinkFrame *f, uint8_t *code);
67
68#endif // DETWS_ENABLE_HOSTLINK
69
70#endif // DETERMINISTICESPASYNCWEBSERVER_HOSTLINK_H
User-facing configuration for DeterministicESPAsyncWebServer.