markqvist___RNode_Firmware/Framing.h
GlassOnTin 033ddd6757 Add GPS beacon and LXMF telemetry for T-Beam Supreme and Heltec V4
Standalone GPS beacon mode: when no KISS host is connected for 15s,
the RNode transmits position and battery telemetry over LoRa.

Two beacon paths:
- LXMF (recommended): encrypted per-packet messages with announces,
  compatible with Sideband and any LXMF application. Supports IFAC
  network authentication.
- Legacy JSON: plaintext or encrypted raw packets for simple collectors.

Key changes:
- GPS support for T-Beam Supreme S3 (L76K) and Heltec V4 (external)
- SX1262 radio fixes: IQ polarity, DCD preamble lockup, RX reliability
- LXMF identity management with NVS-backed Ed25519/X25519 keys
- IFAC authentication (CMD_IFAC_KEY 0x89) for private networks
- Per-channel serial isolation (USB, BLE, WiFi)
- GPS status page in OLED display rotation
- Provisioning via rnlog: provision-lxmf, provision-ifac
- Documentation in Documentation/BEACON.md
2026-03-12 17:01:29 +00:00

153 lines
No EOL
4.3 KiB
C

// Copyright (C) 2024, Mark Qvist
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef FRAMING_H
#define FRAMING_H
#define FEND 0xC0
#define FESC 0xDB
#define TFEND 0xDC
#define TFESC 0xDD
#define CMD_UNKNOWN 0xFE
#define CMD_DATA 0x00
#define CMD_FREQUENCY 0x01
#define CMD_BANDWIDTH 0x02
#define CMD_TXPOWER 0x03
#define CMD_SF 0x04
#define CMD_CR 0x05
#define CMD_RADIO_STATE 0x06
#define CMD_RADIO_LOCK 0x07
#define CMD_DETECT 0x08
#define CMD_IMPLICIT 0x09
#define CMD_LEAVE 0x0A
#define CMD_ST_ALOCK 0x0B
#define CMD_LT_ALOCK 0x0C
#define CMD_PROMISC 0x0E
#define CMD_READY 0x0F
#define CMD_STAT_RX 0x21
#define CMD_STAT_TX 0x22
#define CMD_STAT_RSSI 0x23
#define CMD_STAT_SNR 0x24
#define CMD_STAT_CHTM 0x25
#define CMD_STAT_PHYPRM 0x26
#define CMD_STAT_BAT 0x27
#define CMD_STAT_CSMA 0x28
#define CMD_STAT_TEMP 0x29
#define CMD_STAT_GPS 0x2A
#define CMD_GPS_NMEA 0x2B
#define CMD_DIAG 0x2C
#define CMD_BLINK 0x30
#define CMD_RANDOM 0x40
#define CMD_FB_EXT 0x41
#define CMD_FB_READ 0x42
#define CMD_FB_WRITE 0x43
#define CMD_FB_READL 0x44
#define CMD_DISP_READ 0x66
#define CMD_DISP_INT 0x45
#define CMD_DISP_ADDR 0x63
#define CMD_DISP_BLNK 0x64
#define CMD_DISP_ROT 0x67
#define CMD_DISP_RCND 0x68
#define CMD_NP_INT 0x65
#define CMD_BT_CTRL 0x46
#define CMD_BT_UNPAIR 0x70
#define CMD_BT_PIN 0x62
#define CMD_DIS_IA 0x69
#define CMD_WIFI_MODE 0x6A
#define CMD_WIFI_SSID 0x6B
#define CMD_WIFI_PSK 0x6C
#define CMD_WIFI_CHN 0x6E
#define CMD_WIFI_IP 0x84
#define CMD_WIFI_NM 0x85
#define CMD_BCN_KEY 0x86
#define CMD_LXMF_HASH 0x87
#define CMD_LXMF_TEST 0x88
#define CMD_IFAC_KEY 0x89
#define CMD_TRANSPORT_ID 0x8A
#define CMD_BOARD 0x47
#define CMD_PLATFORM 0x48
#define CMD_MCU 0x49
#define CMD_FW_VERSION 0x50
#define CMD_CFG_READ 0x6D
#define CMD_ROM_READ 0x51
#define CMD_ROM_WRITE 0x52
#define CMD_CONF_SAVE 0x53
#define CMD_CONF_DELETE 0x54
#define CMD_DEV_HASH 0x56
#define CMD_DEV_SIG 0x57
#define CMD_FW_HASH 0x58
#define CMD_HASHES 0x60
#define CMD_FW_UPD 0x61
#define CMD_UNLOCK_ROM 0x59
#define ROM_UNLOCK_BYTE 0xF8
#define CMD_RESET 0x55
#define CMD_RESET_BYTE 0xF8
#define CMD_LOG 0x80
#define CMD_TIME 0x81
#define CMD_MUX_CHAIN 0x82
#define CMD_MUX_DSCVR 0x83
#define DETECT_REQ 0x73
#define DETECT_RESP 0x46
#define RADIO_STATE_OFF 0x00
#define RADIO_STATE_ON 0x01
#define NIBBLE_SEQ 0xF0
#define NIBBLE_FLAGS 0x0F
#define FLAG_SPLIT 0x01
#define SEQ_UNSET 0xFF
#define CMD_ERROR 0x90
#define ERROR_INITRADIO 0x01
#define ERROR_TXFAILED 0x02
#define ERROR_EEPROM_LOCKED 0x03
#define ERROR_QUEUE_FULL 0x04
#define ERROR_MEMORY_LOW 0x05
#define ERROR_MODEM_TIMEOUT 0x06
// Channel constants
#define CHANNEL_USB 0
#define CHANNEL_BT 1
#define CHANNEL_WIFI 2
// Compile-time channel count per platform
#if HAS_WIFI == true
#define NUM_CHANNELS 3
#elif HAS_BLUETOOTH == true || HAS_BLE == true
#define NUM_CHANNELS 2
#else
#define NUM_CHANNELS 1
#endif
// Per-channel parser state
typedef struct {
bool in_frame;
bool escape;
uint8_t command;
size_t frame_len;
uint8_t cmdbuf[CMD_L];
#if NUM_CHANNELS > 1
uint8_t pktbuf[MTU];
uint16_t pkt_len;
#endif
} ChannelState;
#endif