SH2SC-EDT
Self-Healing Hardware and Software Complex for Encrypted Data Transmission
Loading...
Searching...
No Matches
transmitter.h
Go to the documentation of this file.
1
11#pragma once
12
13#include <Arduino.h>
14#include "protocol.h"
15#include "csprng.h"
16#include <ChaChaPoly.h>
17
22const uint8_t TX_BUTTON_PIN = 3;
23const uint8_t ENTROPY_RING_OSC_PIN = 2;
24const uint8_t TX_LCD_ADDR = 0x3E;
25const uint8_t TX_LCD_COLS = 16;
26const uint8_t TX_LCD_ROWS = 2;
// end group tx_hw_pins
28
33const uint16_t DEBOUNCE_DELAY_MS = 50;
35const uint32_t RECONNECT_INTERVAL_MS = 2000;
// end group tx_timing
37
83
88void tx_setup();
89
97void tx_loop();
98
111void suspendSession();
112
119bool readButtonPress();
120
131void sendHelloPacket();
132
150void sendPacket(uint8_t noteIndex, uint16_t noteDurationMs, uint8_t seqNum);
151
161void formAndSendPacket(uint8_t note_idx, uint16_t duration_ms);
162
173void sendFinPacket();
174
186void updateTxDisplay(TxState state, uint16_t seqNum, uint8_t retries);
187
207void generateEntropyPool(uint8_t* outputSeed);
ChaCha20-based CSPRNG for SH2SC-EDT — Transmitter Node A (ATmega328P).
Shared C2P-ARQ protocol definitions for SH2SC-EDT (Transmitter Node A).
static uint16_t seqNum
Packet sequence number (0–65535, wraps).
const uint8_t TX_BUTTON_PIN
Tactile start button (INPUT_PULLUP, active LOW).
Definition transmitter.h:22
const uint8_t TX_LCD_COLS
Number of columns on the TX LCD.
Definition transmitter.h:25
const uint8_t ENTROPY_RING_OSC_PIN
Hardware ring oscillator entropy source (INT0).
Definition transmitter.h:23
const uint8_t TX_LCD_ROWS
Number of rows on the TX LCD.
Definition transmitter.h:26
const uint8_t TX_LCD_ADDR
I2C address of the Aip31068 16x2 LCD display.
Definition transmitter.h:24
const uint16_t DEBOUNCE_DELAY_MS
Definition transmitter.h:33
const uint32_t RECONNECT_INTERVAL_MS
Auto-reconnect HelloPacket broadcast interval (ms) while in RECONNECTING state.
Definition transmitter.h:35
void suspendSession()
Suspend the current C2P-ARQ session and enter the Self-Healing reconnect loop.
void updateTxDisplay(TxState state, uint16_t seqNum, uint8_t retries)
Refresh the TX LCD with the current ARQ status and FSM state label.
void sendHelloPacket()
Generate a fresh 12-byte CSPRNG session nonce and transmit it as a HelloPacket.
void sendFinPacket()
Construct and transmit the FLAG_FIN session-close packet.
TxState
Finite State Machine states for the C2P-ARQ Transmitter (Node A).
Definition transmitter.h:72
@ SENDING_FIN
All notes delivered; transmitting the FLAG_FIN teardown packet.
@ WAITING_ACK
DataPacket sent; listening on the feedback line for ACK or NACK.
@ SENDING_HELLO
Generating a CSPRNG nonce and transmitting the SYN handshake packet.
@ IDLE
Waiting for a button press to begin melody playback.
@ SENDING
Constructing, encrypting, and transmitting the current DataPacket.
@ WAITING_HELLO_ACK
HelloPacket sent; awaiting RX nonce-acceptance ACK.
@ WAIT_BETWEEN_NOTES
ACK received; holding the inter-note gap before advancing melodyIndex.
@ RECONNECTING
Link lost mid-melody; broadcasting HelloPackets every RECONNECT_INTERVAL_MS.
@ WAITING_FIN_ACK
FIN packet sent; awaiting RX acknowledgement before erasing the session nonce.
void generateEntropyPool(uint8_t *outputSeed)
Harvest 256 bits of hardware entropy and write them to outputSeed.
void tx_loop()
Execute one non-blocking FSM tick for the Transmitter node.
void tx_setup()
Initialise TX hardware: UART, I2C LCD, button pin, ring-oscillator entropy.
bool readButtonPress()
Read and debounce the start button using a millis()-based filter.
void formAndSendPacket(uint8_t note_idx, uint16_t duration_ms)
High-level wrapper called by the SENDING FSM state.
void sendPacket(uint8_t noteIndex, uint16_t noteDurationMs, uint8_t seqNum)
Encrypt and transmit a single DataPacket for the given note.