docs+experiment: C5 RX-Diagnose 2026-11-17
- RX-Pfad auf 2.4GHz/5GHz ch36 bewiesen funktionsfaehig; 5900/11p cb=0 - TLSF-Crash geloest: bertrik fixed-buffer Sniffer (pioarduino/IDF 5.5.5) - Hauptverdacht 11p-Arming; naechster Versuch jstsmthrgk set_fix_rate - docs/C5-RX-DIAGNOSIS-2026-11-17.md + experiments/bertrik-c5-sniffer/
This commit is contained in:
1 parent
3d660b9d04
commit
bd1817c982
6 files changed
+342
No files matched your search
@@ -0,0 +1,56 @@
|
||||
# bertrik-c5-sniffer (Experiment)
|
||||
|
||||
Minimaler, **stabiler** C-ITS-Sniffer für den Lilygo T-Dongle C5, basierend auf
|
||||
[bertrik/its-g5-receiver](https://github.com/bertrik/its-g5-receiver)
|
||||
(`esp32-c5-sniffer`). Gebaut mit **PlatformIO + pioarduino** (ESP-IDF 5.5.5,
|
||||
Arduino-Core 3.3.11) — nicht IDF-nativ.
|
||||
|
||||
**Warum dieses Experiment:** Die IDF-nativen Builds crashten (TLSF/`multi_heap`-
|
||||
Assert). bertriks **fixe Ringbuffer** (kein `malloc` im RX-Callback) laufen auf
|
||||
dem T-Dongle stabil. Der RX-Pfad ist auf 2.4 GHz und 5 GHz ch36 nachgewiesen
|
||||
funktionsfähig; nur 5900/11p liefert `cb_all=0`. Details + nächste Schritte:
|
||||
[`../../docs/C5-RX-DIAGNOSIS-2026-11-17.md`](../../docs/C5-RX-DIAGNOSIS-2026-11-17.md).
|
||||
|
||||
## Dateien
|
||||
- `esp32-c5-sniffer.ino` — Sniffer. Aktueller Stand: **5900/11p-Arming**.
|
||||
Diagnose-Zähler `cb_all`/`cb_nonmisc`/`its` werden **vor** jedem Filter erhöht.
|
||||
Output: `STATS …` alle 2 s + `FRAME len=… rssi=… <hex>` auf `Serial` (USB-CDC).
|
||||
- `platformio.ini` — pioarduino-Platform 55.03.311, Board `esp32-c5-devkitc1-n4`
|
||||
mit T-Dongle-Overrides (16 MB / dio / 80 MHz), USB-CDC-Flags.
|
||||
- `esp_wifi_secret.h` — extern-Deklarationen der PHY-Funktionen
|
||||
(`phy_11p_set`, `phy_change_channel`).
|
||||
|
||||
## Build
|
||||
```bash
|
||||
cd experiments/bertrik-c5-sniffer
|
||||
pio run -e tdongle-c5 # erster Build ~14 min (Downloads), danach ~17 s
|
||||
```
|
||||
Ergebnis: `.pio/build/tdongle-c5/{bootloader,partitions,firmware}.bin`.
|
||||
|
||||
## Flash (OpenOCD USB-JTAG — esptool-write geht auf diesem Stick nicht)
|
||||
Offsets: bootloader `0x2000`, partitions `0x8000`, boot_app0 `0xe000`,
|
||||
firmware `0x10000`. **`adapter speed 2000`** ist Pflicht (sonst USB-Abbruch beim
|
||||
großen Firmware-Write). Vollständige Sequenz inkl. WDT-Reset + USB-Power-Cycle:
|
||||
siehe Diagnose-Doc, Abschnitt „Flash-Prozedur".
|
||||
|
||||
## Kontrolltest-Methode (Band isolieren)
|
||||
Im `.ino` den Arming-Block in `setup()` ersetzen und neu builden/flashen:
|
||||
```cpp
|
||||
// 2.4 GHz ch6 (normales WiFi, kein 11p):
|
||||
ESP_ERROR_CHECK(esp_wifi_set_channel(6, WIFI_SECOND_CHAN_NONE));
|
||||
// ODER 5 GHz ch36 (5180 MHz, normales WiFi, kein 11p):
|
||||
ESP_ERROR_CHECK(esp_wifi_set_channel(36, WIFI_SECOND_CHAN_NONE));
|
||||
```
|
||||
Steigt `cb_all` → RX-Pfad funktioniert (Referenzwerte: ch6 ≈1800/30 s,
|
||||
ch36 ≈490/30 s). Bleibt `cb_all=0` nur bei 5900/11p → Problem ist 11p-spezifisch.
|
||||
|
||||
## Aktuelles 5900/11p-Arming (bertrik)
|
||||
```cpp
|
||||
phy_11p_set(1, 0);
|
||||
ESP_ERROR_CHECK(esp_wifi_set_channel(140, WIFI_SECOND_CHAN_NONE));
|
||||
phy_change_channel(5900, 1, 0, 0);
|
||||
```
|
||||
**Nächster Versuch:** alternatives Arming nach
|
||||
[jstsmthrgk](https://git.devlol.org/jstsmthrgk/simple-its-g5-receiver-firmware)
|
||||
(`esp_wifi_internal_set_fix_rate` + `esp_wifi_set_protocol` +
|
||||
`esp_wifi_set_bandwidth`). Siehe Diagnose-Doc.
|
||||
@@ -0,0 +1,126 @@
|
||||
// Diagnostic C-ITS sniffer for Lilygo T-Dongle C5, based on bertrik/its-g5-receiver
|
||||
// (proven fixed-ringbuffer approach, Arduino/pioarduino = ESP-IDF 5.5.5).
|
||||
// Changes vs bertrik: frames+stats on Serial (USB-CDC, the T-Dongle's only USB port),
|
||||
// no NeoPixel/MiniShell, cb counters BEFORE filtering to prove driver RX delivery.
|
||||
#include <stdlib.h>
|
||||
#include <atomic>
|
||||
#include <cstring>
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_wifi_secret.h"
|
||||
|
||||
static const int CHANNEL = 5900;
|
||||
static const size_t QUEUE_SIZE = 8;
|
||||
static const int MAX_PACKET_LEN = 2400;
|
||||
|
||||
typedef struct {
|
||||
unsigned long millis;
|
||||
int rssi;
|
||||
size_t len;
|
||||
uint8_t data[MAX_PACKET_LEN];
|
||||
} packet_t;
|
||||
|
||||
static packet_t queue[QUEUE_SIZE];
|
||||
static std::atomic<int> writeIndex = 0;
|
||||
static std::atomic<int> readIndex = 0;
|
||||
static std::atomic<uint32_t> droppedPackets = 0;
|
||||
|
||||
// diagnostic counters (incremented in the RX callback, before any filtering)
|
||||
static std::atomic<uint32_t> cb_all = 0; // every callback invocation
|
||||
static std::atomic<uint32_t> cb_nonmisc = 0; // non-MISC frames
|
||||
static std::atomic<uint32_t> its_frames = 0; // broadcast frames enqueued
|
||||
static std::atomic<int> last_rssi = 0;
|
||||
static volatile int armed = 0;
|
||||
|
||||
static bool enqueue(unsigned long ms, int rssi, size_t length, const uint8_t *data)
|
||||
{
|
||||
if (length > MAX_PACKET_LEN) return false;
|
||||
int w = writeIndex.load(std::memory_order_relaxed);
|
||||
int r = readIndex.load(std::memory_order_acquire);
|
||||
int next = (w + 1) % QUEUE_SIZE;
|
||||
if (next == r) return false; // full
|
||||
packet_t &pkt = queue[w];
|
||||
pkt.millis = ms;
|
||||
pkt.rssi = rssi;
|
||||
pkt.len = length;
|
||||
memcpy(pkt.data, data, length);
|
||||
writeIndex.store(next, std::memory_order_release);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool dequeue(packet_t *pkt)
|
||||
{
|
||||
int r = readIndex.load(std::memory_order_relaxed);
|
||||
int w = writeIndex.load(std::memory_order_acquire);
|
||||
if (r == w) return false; // empty
|
||||
*pkt = queue[r];
|
||||
readIndex.store((r + 1) % QUEUE_SIZE, std::memory_order_release);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void wifi_sniffer_cb(void *rawpkt, wifi_promiscuous_pkt_type_t type)
|
||||
{
|
||||
cb_all.fetch_add(1, std::memory_order_relaxed);
|
||||
wifi_promiscuous_pkt_t *pkt = (wifi_promiscuous_pkt_t *)rawpkt;
|
||||
if (pkt->rx_ctrl.sig_len <= 4) return;
|
||||
size_t len = pkt->rx_ctrl.sig_len - 4;
|
||||
if (type == WIFI_PKT_MISC) return;
|
||||
cb_nonmisc.fetch_add(1, std::memory_order_relaxed);
|
||||
last_rssi.store(pkt->rx_ctrl.rssi, std::memory_order_relaxed);
|
||||
if (pkt->rx_ctrl.rx_state) return;
|
||||
// broadcast only (802.11p DA = ff:ff:ff:ff:ff:ff at payload[4])
|
||||
if (len < (4 + 6) || memcmp(&pkt->payload[4], "\xFF\xFF\xFF\xFF\xFF\xFF", 6)) return;
|
||||
its_frames.fetch_add(1, std::memory_order_relaxed);
|
||||
if (!enqueue(millis(), pkt->rx_ctrl.rssi, len, pkt->payload)) {
|
||||
droppedPackets.fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(115200); // USB-CDC (ARDUINO_USB_CDC_ON_BOOT=1)
|
||||
delay(2000);
|
||||
Serial.println("BOOT: T-Dongle C5 ITS-G5 sniffer (bertrik fixed-buffer, IDF5.5)");
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL));
|
||||
|
||||
wifi_promiscuous_filter_t wifi_filter;
|
||||
wifi_filter.filter_mask = WIFI_PROMIS_FILTER_MASK_ALL & ~WIFI_PROMIS_FILTER_MASK_FCSFAIL;
|
||||
ESP_ERROR_CHECK(esp_wifi_set_promiscuous_filter(&wifi_filter));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(wifi_sniffer_cb));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_promiscuous(true));
|
||||
// C-ITS ITS-G5: 802.11p @ 5900 MHz (ch140), 10 MHz bandwidth.
|
||||
phy_11p_set(1, 0);
|
||||
ESP_ERROR_CHECK(esp_wifi_set_channel(140, WIFI_SECOND_CHAN_NONE));
|
||||
phy_change_channel(CHANNEL, 1, 0, 0);
|
||||
armed = 1;
|
||||
Serial.println("ARMED: ch140 / 5900 MHz 802.11p, promiscuous on");
|
||||
}
|
||||
|
||||
static void print_stats(void)
|
||||
{
|
||||
Serial.printf("STATS cb_all=%lu cb_nonmisc=%lu its=%lu dropped=%lu rssi=%d armed=%d heap=%u\n",
|
||||
(unsigned long)cb_all.load(), (unsigned long)cb_nonmisc.load(),
|
||||
(unsigned long)its_frames.load(), (unsigned long)droppedPackets.load(),
|
||||
last_rssi.load(), armed, (unsigned)ESP.getFreeHeap());
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
static unsigned long last_stats = 0;
|
||||
packet_t pkt;
|
||||
while (dequeue(&pkt)) {
|
||||
Serial.printf("FRAME len=%u rssi=%d ms=%lu:", (unsigned)pkt.len, pkt.rssi, pkt.millis);
|
||||
for (size_t i = 0; i < pkt.len && i < 48; i++) Serial.printf(" %02X", pkt.data[i]);
|
||||
Serial.println();
|
||||
}
|
||||
if (millis() - last_stats >= 2000) {
|
||||
last_stats = millis();
|
||||
print_stats();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
void phy_change_channel(int,int,int,int);
|
||||
void phy_11p_set(int,int);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
[platformio]
|
||||
default_envs = tdongle-c5
|
||||
src_dir = .
|
||||
|
||||
[env]
|
||||
platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.311/platform-espressif32.zip
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
|
||||
[env:tdongle-c5]
|
||||
board = esp32-c5-devkitc1-n4
|
||||
; Lilygo T-Dongle C5 = 16 MB flash (W25Q128), DIO @ 80 MHz, single USB-Serial-JTAG port
|
||||
board_upload.flash_size = 16MB
|
||||
board_upload.maximum_size = 16777216
|
||||
board_build.partitions = default_16MB.csv
|
||||
board_build.flash_mode = dio
|
||||
board_build.f_flash = 80000000L
|
||||
upload_port = /dev/cits59
|
||||
build_flags =
|
||||
-D ARDUINO_USB_MODE=1
|
||||
-D ARDUINO_USB_CDC_ON_BOOT=1
|
||||
Reference in new issue
Block a user