C-ITS Sniffer v2: ST7735-Display, SPI2-Fix, Single-Core-Fix, 5-min-Zähler

- ST7735 SPI-Treiber (80x160, 5x7-Font) mit Debug-Panel (5MIN/FRM/DROP/SRC/FREE/CH)
- SPI2_HOST statt SPI1_HOST (SPI1 = Flash-reserviert auf ESP32-C5)
- xTaskCreate statt xTaskCreatePinnedToCore (C5 ist Single-Core)
- SD-Karte (SPI 1-bit, 32 GB, FAT32) + Flash-storage-Fallback
- Serial-REPL: stats, seron, seroff, reboot
- APA102 RGB-Status-LED (blau=boot, gruen=armed, rot=fehler)
- Build: ESP-IDF v6.1-dev, RISC-V, ~920 KB

Replaced old block1-4 prototype with full modular firmware.
This commit is contained in:
clawdia committed 2026-11-10 10:21:23 +01:00
1 parent b852826f5c
commit d1b3d1bae6
24 files changed
+1552 -698

No files matched your search

+106
View File
@@ -0,0 +1,106 @@
#include "cits_parse.h"
#include <string.h>
esp_err_t cits_parse_80211(const uint8_t *f, uint16_t len, ieee80211_hdr_t *o)
{
if (!f || len < 14) {
return ESP_ERR_INVALID_SIZE;
}
memset(o, 0, sizeof(*o));
uint16_t fc = (uint16_t)(f[0] | (f[1] << 8));
o->type = (uint8_t)((fc >> 2) & 0x03);
o->subtype = (uint8_t)((fc >> 4) & 0x0F);
o->to_ds = (fc >> 8) & 1;
o->from_ds = (fc >> 9) & 1;
o->more_frag = (fc >> 10) & 1;
o->retry = (fc >> 11) & 1;
o->protected_ = (fc >> 14) & 1;
o->order = (fc >> 15) & 1;
/* Address count: data -> 3 (4 if WDS to_ds&&from_ds), mgmt -> 3, ctrl -> 2 */
int naddr;
if (o->type == 2) {
naddr = (o->to_ds && o->from_ds) ? 4 : 3;
} else if (o->type == 0) {
naddr = 3;
} else {
naddr = 2;
}
int off = 4;
if ((uint32_t)off + (uint32_t)naddr * 6 > len) {
return ESP_ERR_INVALID_SIZE;
}
memcpy(o->da, f + off, 6); off += 6;
memcpy(o->sa, f + off, 6); off += 6;
memcpy(o->bssid, f + off, 6); off += 6;
o->addr_count = naddr;
if (o->type == 2) {
off += 4; /* seq control + frame-control word */
}
o->is_data = (o->type == 2);
if ((uint32_t)off <= len) {
o->payload = f + off;
o->payload_len = (uint16_t)(len - off);
} else {
o->payload = NULL;
o->payload_len = 0;
}
return ESP_OK;
}
esp_err_t cits_parse_asdu(const uint8_t *p, uint16_t len, cits_msg_t *o)
{
if (!p || len < 7) {
return ESP_ERR_INVALID_SIZE;
}
memset(o, 0, sizeof(*o));
o->asdu_id = p[0];
o->asdu_version = p[1];
o->asdu_len = (uint16_t)(p[2] | (p[3] << 8)); /* ASdu body length (BE) */
switch (o->asdu_id) {
case 0x01: o->type = CITS_SPM; break;
case 0x02: o->type = CITS_SPT; break;
case 0x03: o->type = CITS_SPS; break;
case 0x04: o->type = CITS_SPA; break;
case 0x05: o->type = CITS_MAP; break;
case 0x06: o->type = CITS_CAM; break;
case 0x07: o->type = CITS_DENM; break;
default: o->type = CITS_UNKNOWN; break;
}
/* ASdu body begins after: id(1) ver(1) len(2) protov(1) len2(2) = 7 bytes */
int b = 7;
if (o->type == CITS_SPM && (uint16_t)(b + 6) <= len) {
o->site_id = (uint32_t)(p[b] << 16) | (p[b + 1] << 8) | p[b + 2];
o->num_phases = p[b + 5];
/* first SignalPhase: phaseId(1) stateId(2) ... -> state is bytes 6..7 */
if (o->num_phases >= 1 && (uint16_t)(b + 8) <= len) {
o->phase0_state = p[b + 7]; /* ASN.1 INTEGER state value (0-5) */
}
} else if (o->type == CITS_CAM && (uint16_t)(b + 5) <= len) {
/* msgIssueID(2) then stationID(21): take leading 3 bytes as a hint */
o->station_id = (uint32_t)(p[b + 2] << 16) | (p[b + 3] << 8) | p[b + 4];
}
return ESP_OK;
}
const char *cits_type_name(cits_msg_type_t t)
{
switch (t) {
case CITS_SPM: return "SpMS";
case CITS_SPT: return "SpTM";
case CITS_SPS: return "SpSM";
case CITS_SPA: return "SpAM";
case CITS_MAP: return "MAPM";
case CITS_CAM: return "CAM";
case CITS_DENM: return "DENM";
default: return "raw";
}
}