DeterministicESPAsyncWebServer
v6.28.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
snp.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 snp.h
6
* @brief GE Fanuc SNP (Series Ninety Protocol) serial frame codec (DETWS_ENABLE_SNP).
7
*
8
* SNP is the GE Fanuc Series 90 (90-30 / 90-70) master-slave serial protocol over RS-485. A message is
9
* a BCC-checked frame delimited by control characters:
10
*
11
* [SOH-or-other-control][data...][checksum]
12
*
13
* SNP frames the payload with an ASCII/binary control byte, a length, the data, and an arithmetic-sum
14
* BCC (the low byte of the sum of every framed byte). This builds/validates that frame so a device can
15
* read/write registers on a Series 90 PLC; the RS-485 UART transport (and the SNP-X session setup) is
16
* the remaining device step. Pure, zero heap, no stdlib, host-testable.
17
*/
18
19
#ifndef DETERMINISTICESPASYNCWEBSERVER_SNP_H
20
#define DETERMINISTICESPASYNCWEBSERVER_SNP_H
21
22
#include "
ServerConfig.h
"
23
#include <stddef.h>
24
#include <stdint.h>
25
26
#if DETWS_ENABLE_SNP
27
28
/** @brief SNP control bytes (subset). */
29
// SNP control bytes: wire values compared/emitted, so integer constants in a namespacing struct.
30
struct
Snp
31
{
32
static
constexpr
uint8_t SNP_ENQ = 0x05;
///< enquiry / attach.
33
static
constexpr
uint8_t SNP_ACK = 0x06;
///< acknowledge.
34
static
constexpr
uint8_t SNP_NAK = 0x15;
///< negative acknowledge.
35
static
constexpr
uint8_t SNP_SOH = 0x01;
///< start of header (a request/response frame).
36
static
constexpr
uint8_t SNP_EOT = 0x04;
///< end of transmission.
37
};
38
39
/** @brief Arithmetic-sum BCC: the low 8 bits of the sum of @p len bytes. */
40
uint8_t detws_snp_bcc(
const
uint8_t *bytes,
size_t
len);
41
42
/**
43
* @brief Build an SNP frame: [control][length][data...][BCC]. length is the data byte count.
44
* @return the frame length (2 + data_len + 1), or 0 on overflow / bad args (data_len > 255).
45
*/
46
size_t
detws_snp_build(uint8_t control,
const
uint8_t *data,
size_t
data_len, uint8_t *out,
size_t
cap);
47
48
/** @brief A parsed SNP frame (data points into the input). */
49
struct
SnpFrame
50
{
51
uint8_t control;
52
const
uint8_t *data;
53
size_t
data_len;
54
};
55
56
/** @brief Validate the BCC and parse an SNP frame. @return true if the BCC matches and it is well-formed. */
57
bool
detws_snp_parse(
const
uint8_t *frame,
size_t
len, SnpFrame *out);
58
59
#endif
// DETWS_ENABLE_SNP
60
#endif
// DETERMINISTICESPASYNCWEBSERVER_SNP_H
ServerConfig.h
User-facing configuration for DeterministicESPAsyncWebServer.
src
services
snp
snp.h
Generated by
1.9.8