Files
mayhem-firmware/firmware/common/flex_defs.hpp
T
VasylSamoilov cf44076a34 FLEX RX: comprehensive decoder rewrite (#3131)
Baseband (proc_flex.cpp):
- Fix numeric vector field width (3-bit n+1 for types 3,4,7)
- Fix capcode range classification for long address components
- Add long address decode (Set 1-2, 1-3/1-4, 2-3)
- Add vector checksum validation (4-bit nibble sum)
- Add tone-only boundary detection via vector pre-scan
- Add idle phase detection (skip all-zeros/all-ones before BCH)
- Skip spurious TON for capcode 1 (BCH-corrected idle artifact)
- Add BIW parsing: SSID1/SSID2, DATE, TIME, TZ, SYSMSG, CHAN
- Add alpha fragment flags: frag, more_frag, seq, new, maildrop, sig
- Add secure message enc= field (alpha/binary/separate)
- Add numbered numeric flags: seq, new, fmt
- Add HEX/Binary header decode: block_bits, new, maildrop, rtl
- Add short instruction decode: temp group slot/target, sys events
- Add short message (SMSG) decode: tone/numeric/source/numbered
- Add group/temp-group/priority flags per address
- Add S2 C-pattern detection with ±1 symbol boundary correction
- Extract FIW roaming, repeat, traffic fields
- Replace snprintf with lightweight str_* helpers (no heap/_sbrk)
- Mark uncorrectable BCH words as ? instead of aborting phase
- ETX/NUL handling: trim trailing padding, show mid-message as ?

App (ui_flex_rx.cpp):
- Add status bar: cycle/frame, bitrate, polarity, time, timezone
- Add network info bar: LID, CZ, CC, roaming flag
- Pipe-delimited serial output for all message types
- BIW events to serial and status bar (not console)
- Human-readable console: +GRP for temp group, G/TG/P flags
- USB serial via UsbSerialAsyncmsg

Packet (flex_defs.hpp):
- uint64_t capcode (long address support)
- 256-byte message buffer
- Fragment flags, BIW raw values, address type, group/priority

Known limitation: phase label unreliable on multi-phase modes
(3200/2FSK, 6400/4FSK). Data always decodes correctly.
2026-04-10 08:37:38 +02:00

63 lines
2.1 KiB
C++

#ifndef __FLEX_DEFS_H__
#define __FLEX_DEFS_H__
#include <cstdint>
#include <array>
#include "baseband.hpp"
namespace flex {
enum class FlexMode : uint8_t {
FLEX_1600_2FSK,
FLEX_3200_2FSK,
FLEX_3200_4FSK,
FLEX_6400_4FSK
};
struct FlexStats {
uint32_t symbols_processed;
uint32_t total_frames;
uint32_t correct_frames;
};
struct FlexPacket {
uint32_t bitrate; // 1600, 3200, 6400
uint64_t capcode; // supports long addresses (up to 4,297,068,542)
uint32_t function; // 0-3 (or BIW word index for type=9)
uint32_t type; // 0=SEC 1=INS 2=TON 3=NUM 4=SNUM 5=ALN 6=HEX 7=NNUM 8=SMSG 9=BIW
char message[256]; // Decoded message text (not used for BIW)
uint32_t status; // 0=OK, other=Errors
uint8_t cycle; // FIW cycle (0-14)
uint8_t frame; // FIW frame (0-127)
char phase; // 'A','B','C','D'
uint8_t is_inverted; // 1=inverted polarity
uint8_t addr_type; // 0=short 1=long 2=temp 3=oper 4=net 5=info 6=rsvd 7=unk
// Fragment flags (ALN/SEC/HEX)
uint8_t frag; // F field: 3=first, 0/1/2=continuation
uint8_t more_frag; // C bit
uint8_t seq; // N field (0-63)
uint8_t is_new; // R bit
uint8_t maildrop; // M bit
uint8_t sig; // 7-bit signature
uint8_t has_flags; // 1=fragment flags valid
uint8_t sec_enc; // secure encoding (0-3)
uint8_t nnum_s; // NNUM S flag
uint8_t fiw_roaming; // FIW n bit: 1=roaming supported
uint8_t is_group; // 1=group address
uint8_t is_temp_group; // 1=temporary group
uint8_t is_priority; // 1=priority address (in BIW1 P section)
// BIW raw values (type=9 only). biw_field identifies the content.
// 0=SSID1 1=DATE 2=TIME 5=SYSINFO 7=SSID2
uint8_t biw_field; // BIW type field (0-7)
uint16_t biw_v1; // field-dependent value 1
uint16_t biw_v2; // field-dependent value 2
uint16_t biw_v3; // field-dependent value 3
uint16_t biw_v4; // field-dependent value 4
};
} /* namespace flex */
#endif /*__FLEX_DEFS_H__*/