CITS Sniffer v4: Inline Implementierungen - alle Funktionen direkt in app_main.c

This commit is contained in:
Clawdia
2026-05-18 14:32:06 +02:00
parent b46283d94f
commit f98e76aa9e
8 changed files with 1134 additions and 3154 deletions
BIN
View File
Binary file not shown.
View File
+994 -996
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1 +1 @@
e11a375c54805d5ec75761e2cb35e1136a7bcaea b46283d94f52be2ae733c3c4636292be93dc71fb
+97 -2113
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -955,7 +955,7 @@
}, },
{ {
"directory": "/home/claw/.openclaw/agents/wisp/workspace/cits-sniffer/build", "directory": "/home/claw/.openclaw/agents/wisp/workspace/cits-sniffer/build",
"command": "/home/claw/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/riscv32-esp-elf-gcc -DESP_PLATFORM -DIDF_VER=\\\"v5.5.1\\\" -DSOC_MMU_PAGE_SIZE=CONFIG_MMU_PAGE_SIZE -DSOC_XTAL_FREQ_MHZ=CONFIG_XTAL_FREQ -D_GLIBCXX_HAVE_POSIX_SEMAPHORE -D_GLIBCXX_USE_POSIX_SEMAPHORE -D_GNU_SOURCE -D_POSIX_READER_WRITER_LOCKS -D PROJECT_NAME=\\\"cits-sniffer\\\" -DPROJECT_VER=\\\"e11a375-dirty\\\" -I/home/claw/.openclaw/agents/wisp/workspace/cits-sniffer/build/config -I/home/claw/esp/esp-idf/components/esp_app_format/include -I/home/claw/esp/esp-idf/components/newlib/platform_include -I/home/claw/esp/esp-idf/components/freertos/config/include -I/home/claw/esp/esp-idf/components/freertos/config/include/freertos -I/home/claw/esp/esp-idf/components/freertos/config/riscv/include -I/home/claw/esp/esp-idf/components/freertos/FreeRTOS-Kernel/include -I/home/claw/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/riscv/include -I/home/claw/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/riscv/include/freertos -I/home/claw/esp/esp-idf/components/freertos/esp_additions/include -I/home/claw/esp/esp-idf/components/esp_hw_support/include -I/home/claw/esp/esp-idf/components/esp_hw_support/include/soc -I/home/claw/esp/esp-idf/components/esp_hw_support/include/soc/esp32c5 -I/home/claw/esp/esp-idf/components/esp_hw_support/dma/include -I/home/claw/esp/esp-idf/components/esp_hw_support/ldo/include -I/home/claw/esp/esp-idf/components/esp_hw_support/debug_probe/include -I/home/claw/esp/esp-idf/components/esp_hw_support/mspi_timing_tuning/include -I/home/claw/esp/esp-idf/components/esp_hw_support/mspi_timing_tuning/tuning_scheme_impl/include -I/home/claw/esp/esp-idf/components/esp_hw_support/power_supply/include -I/home/claw/esp/esp-idf/components/esp_hw_support/port/esp32c5/. -I/home/claw/esp/esp-idf/components/esp_hw_support/port/esp32c5/include -I/home/claw/esp/esp-idf/components/esp_hw_support/port/esp32c5/private_include -I/home/claw/esp/esp-idf/components/esp_hw_support/mspi_timing_tuning/port/esp32c5/. -I/home/claw/esp/esp-idf/components/esp_hw_support/mspi_timing_tuning/port/esp32c5/include -I/home/claw/esp/esp-idf/components/heap/include -I/home/claw/esp/esp-idf/components/heap/tlsf -I/home/claw/esp/esp-idf/components/log/include -I/home/claw/esp/esp-idf/components/soc/include -I/home/claw/esp/esp-idf/components/soc/esp32c5 -I/home/claw/esp/esp-idf/components/soc/esp32c5/include -I/home/claw/esp/esp-idf/components/soc/esp32c5/register -I/home/claw/esp/esp-idf/components/hal/platform_port/include -I/home/claw/esp/esp-idf/components/hal/esp32c5/include -I/home/claw/esp/esp-idf/components/hal/include -I/home/claw/esp/esp-idf/components/esp_rom/include -I/home/claw/esp/esp-idf/components/esp_rom/esp32c5/include -I/home/claw/esp/esp-idf/components/esp_rom/esp32c5/include/esp32c5 -I/home/claw/esp/esp-idf/components/esp_rom/esp32c5 -I/home/claw/esp/esp-idf/components/esp_common/include -I/home/claw/esp/esp-idf/components/esp_system/include -I/home/claw/esp/esp-idf/components/esp_system/port/soc -I/home/claw/esp/esp-idf/components/esp_system/port/include/riscv -I/home/claw/esp/esp-idf/components/esp_system/port/include/private -I/home/claw/esp/esp-idf/components/riscv/include -I/home/claw/esp/esp-idf/components/lwip/include -I/home/claw/esp/esp-idf/components/lwip/include/apps -I/home/claw/esp/esp-idf/components/lwip/include/apps/sntp -I/home/claw/esp/esp-idf/components/lwip/lwip/src/include -I/home/claw/esp/esp-idf/components/lwip/port/include -I/home/claw/esp/esp-idf/components/lwip/port/freertos/include -I/home/claw/esp/esp-idf/components/lwip/port/esp32xx/include -I/home/claw/esp/esp-idf/components/lwip/port/esp32xx/include/arch -I/home/claw/esp/esp-idf/components/lwip/port/esp32xx/include/sys -march=rv32imac_zicsr_zifencei -fdiagnostics-color=always -ffunction-sections -fdata-sections -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=unused-but-set-variable -Wno-error=deprecated-declarations -Wextra -Wno-error=extra -Wno-unused-parameter -Wno-sign-compare -Wno-enum-conversion -gdwarf-4 -ggdb -nostartfiles -Og -fno-shrink-wrap -fmacro-prefix-map=/home/claw/.openclaw/agents/wisp/workspace/cits-sniffer=. -fmacro-prefix-map=/home/claw/esp/esp-idf=/IDF -fstrict-volatile-bitfields -fno-jump-tables -fno-tree-switch-conversion -std=gnu17 -Wno-old-style-declaration -o esp-idf/esp_app_format/CMakeFiles/__idf_esp_app_format.dir/esp_app_desc.c.obj -c /home/claw/esp/esp-idf/components/esp_app_format/esp_app_desc.c", "command": "/home/claw/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/riscv32-esp-elf-gcc -DESP_PLATFORM -DIDF_VER=\\\"v5.5.1\\\" -DSOC_MMU_PAGE_SIZE=CONFIG_MMU_PAGE_SIZE -DSOC_XTAL_FREQ_MHZ=CONFIG_XTAL_FREQ -D_GLIBCXX_HAVE_POSIX_SEMAPHORE -D_GLIBCXX_USE_POSIX_SEMAPHORE -D_GNU_SOURCE -D_POSIX_READER_WRITER_LOCKS -D PROJECT_NAME=\\\"cits-sniffer\\\" -DPROJECT_VER=\\\"b46283d-dirty\\\" -I/home/claw/.openclaw/agents/wisp/workspace/cits-sniffer/build/config -I/home/claw/esp/esp-idf/components/esp_app_format/include -I/home/claw/esp/esp-idf/components/newlib/platform_include -I/home/claw/esp/esp-idf/components/freertos/config/include -I/home/claw/esp/esp-idf/components/freertos/config/include/freertos -I/home/claw/esp/esp-idf/components/freertos/config/riscv/include -I/home/claw/esp/esp-idf/components/freertos/FreeRTOS-Kernel/include -I/home/claw/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/riscv/include -I/home/claw/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/riscv/include/freertos -I/home/claw/esp/esp-idf/components/freertos/esp_additions/include -I/home/claw/esp/esp-idf/components/esp_hw_support/include -I/home/claw/esp/esp-idf/components/esp_hw_support/include/soc -I/home/claw/esp/esp-idf/components/esp_hw_support/include/soc/esp32c5 -I/home/claw/esp/esp-idf/components/esp_hw_support/dma/include -I/home/claw/esp/esp-idf/components/esp_hw_support/ldo/include -I/home/claw/esp/esp-idf/components/esp_hw_support/debug_probe/include -I/home/claw/esp/esp-idf/components/esp_hw_support/mspi_timing_tuning/include -I/home/claw/esp/esp-idf/components/esp_hw_support/mspi_timing_tuning/tuning_scheme_impl/include -I/home/claw/esp/esp-idf/components/esp_hw_support/power_supply/include -I/home/claw/esp/esp-idf/components/esp_hw_support/port/esp32c5/. -I/home/claw/esp/esp-idf/components/esp_hw_support/port/esp32c5/include -I/home/claw/esp/esp-idf/components/esp_hw_support/port/esp32c5/private_include -I/home/claw/esp/esp-idf/components/esp_hw_support/mspi_timing_tuning/port/esp32c5/. -I/home/claw/esp/esp-idf/components/esp_hw_support/mspi_timing_tuning/port/esp32c5/include -I/home/claw/esp/esp-idf/components/heap/include -I/home/claw/esp/esp-idf/components/heap/tlsf -I/home/claw/esp/esp-idf/components/log/include -I/home/claw/esp/esp-idf/components/soc/include -I/home/claw/esp/esp-idf/components/soc/esp32c5 -I/home/claw/esp/esp-idf/components/soc/esp32c5/include -I/home/claw/esp/esp-idf/components/soc/esp32c5/register -I/home/claw/esp/esp-idf/components/hal/platform_port/include -I/home/claw/esp/esp-idf/components/hal/esp32c5/include -I/home/claw/esp/esp-idf/components/hal/include -I/home/claw/esp/esp-idf/components/esp_rom/include -I/home/claw/esp/esp-idf/components/esp_rom/esp32c5/include -I/home/claw/esp/esp-idf/components/esp_rom/esp32c5/include/esp32c5 -I/home/claw/esp/esp-idf/components/esp_rom/esp32c5 -I/home/claw/esp/esp-idf/components/esp_common/include -I/home/claw/esp/esp-idf/components/esp_system/include -I/home/claw/esp/esp-idf/components/esp_system/port/soc -I/home/claw/esp/esp-idf/components/esp_system/port/include/riscv -I/home/claw/esp/esp-idf/components/esp_system/port/include/private -I/home/claw/esp/esp-idf/components/riscv/include -I/home/claw/esp/esp-idf/components/lwip/include -I/home/claw/esp/esp-idf/components/lwip/include/apps -I/home/claw/esp/esp-idf/components/lwip/include/apps/sntp -I/home/claw/esp/esp-idf/components/lwip/lwip/src/include -I/home/claw/esp/esp-idf/components/lwip/port/include -I/home/claw/esp/esp-idf/components/lwip/port/freertos/include -I/home/claw/esp/esp-idf/components/lwip/port/esp32xx/include -I/home/claw/esp/esp-idf/components/lwip/port/esp32xx/include/arch -I/home/claw/esp/esp-idf/components/lwip/port/esp32xx/include/sys -march=rv32imac_zicsr_zifencei -fdiagnostics-color=always -ffunction-sections -fdata-sections -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=unused-but-set-variable -Wno-error=deprecated-declarations -Wextra -Wno-error=extra -Wno-unused-parameter -Wno-sign-compare -Wno-enum-conversion -gdwarf-4 -ggdb -nostartfiles -Og -fno-shrink-wrap -fmacro-prefix-map=/home/claw/.openclaw/agents/wisp/workspace/cits-sniffer=. -fmacro-prefix-map=/home/claw/esp/esp-idf=/IDF -fstrict-volatile-bitfields -fno-jump-tables -fno-tree-switch-conversion -std=gnu17 -Wno-old-style-declaration -o esp-idf/esp_app_format/CMakeFiles/__idf_esp_app_format.dir/esp_app_desc.c.obj -c /home/claw/esp/esp-idf/components/esp_app_format/esp_app_desc.c",
"file": "/home/claw/esp/esp-idf/components/esp_app_format/esp_app_desc.c", "file": "/home/claw/esp/esp-idf/components/esp_app_format/esp_app_desc.c",
"output": "esp-idf/esp_app_format/CMakeFiles/__idf_esp_app_format.dir/esp_app_desc.c.obj" "output": "esp-idf/esp_app_format/CMakeFiles/__idf_esp_app_format.dir/esp_app_desc.c.obj"
}, },
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"version": "1.2", "version": "1.2",
"project_name": "cits-sniffer", "project_name": "cits-sniffer",
"project_version": "e11a375-dirty", "project_version": "b46283d-dirty",
"project_path": "/home/claw/.openclaw/agents/wisp/workspace/cits-sniffer", "project_path": "/home/claw/.openclaw/agents/wisp/workspace/cits-sniffer",
"idf_path": "/home/claw/esp/esp-idf", "idf_path": "/home/claw/esp/esp-idf",
"build_dir": "/home/claw/.openclaw/agents/wisp/workspace/cits-sniffer/build", "build_dir": "/home/claw/.openclaw/agents/wisp/workspace/cits-sniffer/build",
+40 -42
View File
@@ -18,18 +18,13 @@
#include "esp_timer.h" #include "esp_timer.h"
#include "nvs_flash.h" #include "nvs_flash.h"
#include "esp_vfs_fat.h" #include "esp_vfs_fat.h"
#include "esp_vfs.h"
#include "wear_levelling.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
// ==================== Forward Declarations ==================== // ==================== Typedefs ====================
// Block 1: Hardware
extern esp_err_t initialize_wifi(void);
extern esp_err_t start_promiscuous_mode(uint32_t channel);
extern esp_err_t init_nvs_flash(void);
extern void register_cits_commands(void);
// Block 2: Parser
typedef struct { typedef struct {
uint32_t timestamp_sec; uint32_t timestamp_sec;
uint32_t timestamp_usec; uint32_t timestamp_usec;
@@ -40,28 +35,17 @@ typedef struct {
int16_t rssi; int16_t rssi;
} cits_message_t; } cits_message_t;
extern esp_err_t cits_parser_init(void);
extern void cits_process_packet(void *packet_info);
// Block 3: CSV Writer
extern esp_err_t csv_writer_init(void);
extern void csv_store_cits_message(cits_message_t *msg);
extern void csv_writer_deinit(void);
// ==================== Constants ==================== // ==================== Constants ====================
static const char *TAG = "CITS_SNIFFER"; static const char *TAG = "CITS_SNIFFER";
#define CITS_CHANNEL_0_MHZ 5900 #define CITS_CHANNEL_0_MHZ 5900
#define CSV_WRITE_INTERVAL_SEC (600)
// ==================== External PHY Functions ==================== // ==================== CSV State ====================
// Diese kommen vom ESP-IDF / proprietären WiFi-Layer
// ==================== CSV File Handle ====================
static FILE *csv_file = NULL; static FILE *csv_file = NULL;
static char current_filename[64]; static char current_filename[64];
static time_t last_write_time = 0; static time_t last_write_time = 0;
#define CSV_WRITE_INTERVAL_SEC (600)
static void write_csv_header(FILE *fp) static void write_csv_header(FILE *fp)
{ {
@@ -100,6 +84,15 @@ static esp_err_t create_new_csv_file(void)
ESP_LOGI(TAG, "Neue CSV-Datei: %s", current_filename); ESP_LOGI(TAG, "Neue CSV-Datei: %s", current_filename);
return ESP_OK; return ESP_OK;
} }
static void csv_store_cits_message(cits_message_t *msg)
{
if (csv_file != NULL) {
write_csv_row(csv_file, msg);
fflush(csv_file);
}
}
// ==================== Promiscuous Callback ==================== // ==================== Promiscuous Callback ====================
static void sniffer_callback(void *buf, wifi_promiscuous_pkt_type_t type) static void sniffer_callback(void *buf, wifi_promiscuous_pkt_type_t type)
@@ -122,23 +115,14 @@ static void sniffer_callback(void *buf, wifi_promiscuous_pkt_type_t type)
cits_message_t msg = { cits_message_t msg = {
.timestamp_sec = sec, .timestamp_sec = sec,
.timestamp_usec = usec, .timestamp_usec = usec,
.length = pkt->rx_ctrl.sig_len, .length = (pkt->rx_ctrl.sig_len > 65535) ? 65535 : pkt->rx_ctrl.sig_len,
.channel = (uint8_t)(CITS_CHANNEL_0_MHZ % 256), .channel = (uint8_t)(CITS_CHANNEL_0_MHZ % 256),
.rssi = pkt->rx_ctrl.rssi, .rssi = pkt->rx_ctrl.rssi,
}; };
csv_store_cits_message(&msg); csv_store_cits_message(&msg);
} }
// ==================== Partition Table ==================== // ==================== Flash Storage ====================
// partition.csv content embedded for flash:
// # ESP-ADF Partition Table
// # Name, Type, SubType, Offset, Size, Flags
// nvs, data, nvs, 0x9000, 0x4000,
// phy_init, data, phy, 0xd000, 0x1000,
// factory, app, factory, 0x10000, 0x3E0000,
// storage, data, fat, , 0x200000,
// ==================== Init Functions ====================
static esp_err_t setup_flash_storage(void) static esp_err_t setup_flash_storage(void)
{ {
@@ -156,6 +140,29 @@ static esp_err_t setup_flash_storage(void)
return ESP_OK; return ESP_OK;
} }
// ==================== WiFi Init (inline Block 1) ====================
static esp_err_t initialize_wifi(void)
{
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
nvs_flash_erase();
ret = nvs_flash_init();
}
if (ret != ESP_OK) {
ESP_LOGE(TAG, "NVS Flash init fehlgeschlagen: %s", esp_err_to_name(ret));
return ret;
}
ESP_LOGI(TAG, "NVS Flash OK");
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL));
ESP_ERROR_CHECK(esp_wifi_start());
ESP_LOGI(TAG, "WiFi initialisiert");
return ESP_OK;
}
static esp_err_t init_promiscuous(void) static esp_err_t init_promiscuous(void)
{ {
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
@@ -181,20 +188,11 @@ void app_main(void)
ESP_LOGI(TAG, "=== C-ITS SNIFFER FÜR ESP32-C5 ==="); ESP_LOGI(TAG, "=== C-ITS SNIFFER FÜR ESP32-C5 ===");
ESP_LOGI(TAG, "Starte..."); ESP_LOGI(TAG, "Starte...");
// NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
nvs_flash_erase();
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
ESP_LOGI(TAG, "NVS Flash OK");
// WiFi Setup // WiFi Setup
ESP_ERROR_CHECK(initialize_wifi()); ESP_ERROR_CHECK(initialize_wifi());
ESP_ERROR_CHECK(init_promiscuous()); ESP_ERROR_CHECK(init_promiscuous());
// CSV Writer // Flash Storage
ESP_ERROR_CHECK(setup_flash_storage()); ESP_ERROR_CHECK(setup_flash_storage());
ESP_ERROR_CHECK(create_new_csv_file()); ESP_ERROR_CHECK(create_new_csv_file());
last_write_time = time(NULL); last_write_time = time(NULL);