16#include <ChaChaPoly.h>
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).
const uint8_t TX_LCD_COLS
Number of columns on the TX LCD.
const uint8_t ENTROPY_RING_OSC_PIN
Hardware ring oscillator entropy source (INT0).
const uint8_t TX_LCD_ROWS
Number of rows on the TX LCD.
const uint8_t TX_LCD_ADDR
I2C address of the Aip31068 16x2 LCD display.
const uint16_t DEBOUNCE_DELAY_MS
const uint32_t RECONNECT_INTERVAL_MS
Auto-reconnect HelloPacket broadcast interval (ms) while in RECONNECTING state.
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).
@ 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.