vor ble umbau

This commit is contained in:
2026-03-12 07:07:00 +01:00
parent 96aed70fc6
commit 5bb0d345da
45 changed files with 3681 additions and 48 deletions

66
firmware/src/main.c Normal file
View File

@@ -0,0 +1,66 @@
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <string.h>
#include "fs_mgmt.h"
#include "ble_mgmt.h"
#include "buzz_proto.h"
LOG_MODULE_REGISTER(main);
void ble_rx_cb(const uint8_t *data, uint16_t len)
{
uint8_t *buf;
/* 1. Länge prüfen (darf SLAB_BLOCK_SIZE = 256 nicht überschreiten) */
if (len > 256) {
LOG_ERR("Received data too large for proto buf (%u bytes)", len);
return;
}
/* 2. Speicher aus dem Protokoll-Slab-Pool anfordern (Zero-Wait) */
if (buzz_proto_buf_alloc(&buf) != 0) {
LOG_ERR("No free memory slabs for incoming BLE frame!");
return;
}
/* 3. Daten in den allokierten Slab kopieren */
memcpy(buf, data, len);
/* 4. Nachrichten-Struktur für den Protokoll-Thread füllen */
struct buzz_frame_msg msg = {
.data_ptr = buf,
.length = len,
.reply_cb = ble_mgmt_send,
.max_payload = ble_mgmt_get_max_payload(),
};
/* 5. Frame asynchron an den Protokoll-Thread übergeben */
if (buzz_proto_submit_frame(&msg) != 0) {
LOG_ERR("Failed to submit frame to proto thread (Queue full)");
buzz_proto_buf_free(&buf); /* Speicher bei Fehler sofort wieder freigeben */
}
}
int main(void)
{
LOG_INF("Starting app on %s (SOC: %s)", CONFIG_BOARD, CONFIG_SOC);
int rc;
rc = fs_mgmt_init();
if (rc < 0) {
LOG_ERR("Failed to initialize file system management: %d", rc);
return rc;
}
/* BLE-Subsystem initialisieren und RX-Callback registrieren */
rc = ble_mgmt_init(ble_rx_cb, CONFIG_BLE_MGMT_DEFAULT_DEVICE_NAME);
if (rc < 0) {
LOG_ERR("Failed to initialize BLE management: %d", rc);
return rc;
}
LOG_INF("Init complete");
k_sleep(K_FOREVER);
}