73 lines
2.3 KiB
C
73 lines
2.3 KiB
C
#include <zephyr/kernel.h>
|
|
#include <zephyr/logging/log.h>
|
|
#include <string.h>
|
|
|
|
#include "fs_mgmt.h"
|
|
#include "ble_mgmt.h"
|
|
#include "buzz_proto.h"
|
|
#include "fw_mgmt.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 > CONFIG_BUZZ_PROTO_SLAB_SIZE) {
|
|
LOG_ERR("Received data too large for proto buf (%u > %u)", len, CONFIG_BUZZ_PROTO_SLAB_SIZE);
|
|
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)
|
|
{
|
|
uint8_t hw_id[8];
|
|
LOG_INF("Starting app version %s (state: 0x%02x zephyr %s) on %s (Rev: %s, SOC: %s)", fw_mgmt_get_fw_version_string(), fw_mgmt_get_fw_state(), fw_mgmt_get_kernel_version_string(), fw_mgmt_get_board_name(), strlen(fw_mgmt_get_board_revision()) ? fw_mgmt_get_board_revision() : "N/A", fw_mgmt_get_soc_name());
|
|
if (fw_mgmt_get_id(hw_id, sizeof(hw_id)) >= 0) {
|
|
LOG_INF("Device EUI64: %02X%02X-%02X%02X-%02X%02X-%02X%02X", hw_id[0], hw_id[1], hw_id[2], hw_id[3], hw_id[4], hw_id[5], hw_id[6], hw_id[7]);
|
|
} else {
|
|
LOG_ERR("Failed to get device ID");
|
|
}
|
|
|
|
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);
|
|
} |