Some checks failed
Build / idf-build (push) Has been cancelled
适配ESP-IDF v6.0编译 补充项目相关文档 * 修复16处头文件缺失、flash配置错误、WiFi断开原因码兼容问题 * 新增ESP-IDF v6.0迁移适配文档 * 更新变更日志,补充v1.0.0功能清单及v1.1.0版本规划 * 整理讨论记录,新增v6.0适配及国内大模型接入内容
62 lines
1.8 KiB
C
62 lines
1.8 KiB
C
#include "message_bus.h"
|
|
#include "mimi_config.h"
|
|
#include "esp_log.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/queue.h"
|
|
#include <string.h>
|
|
|
|
static const char *TAG = "bus";
|
|
|
|
static QueueHandle_t s_inbound_queue;
|
|
static QueueHandle_t s_outbound_queue;
|
|
|
|
esp_err_t message_bus_init(void)
|
|
{
|
|
s_inbound_queue = xQueueCreate(MIMI_BUS_QUEUE_LEN, sizeof(mimi_msg_t));
|
|
s_outbound_queue = xQueueCreate(MIMI_BUS_QUEUE_LEN, sizeof(mimi_msg_t));
|
|
|
|
if (!s_inbound_queue || !s_outbound_queue) {
|
|
ESP_LOGE(TAG, "Failed to create message queues");
|
|
return ESP_ERR_NO_MEM;
|
|
}
|
|
|
|
ESP_LOGI(TAG, "Message bus initialized (queue depth %d)", MIMI_BUS_QUEUE_LEN);
|
|
return ESP_OK;
|
|
}
|
|
|
|
esp_err_t message_bus_push_inbound(const mimi_msg_t *msg)
|
|
{
|
|
if (xQueueSend(s_inbound_queue, msg, pdMS_TO_TICKS(1000)) != pdTRUE) {
|
|
ESP_LOGW(TAG, "Inbound queue full, dropping message");
|
|
return ESP_ERR_NO_MEM;
|
|
}
|
|
return ESP_OK;
|
|
}
|
|
|
|
esp_err_t message_bus_pop_inbound(mimi_msg_t *msg, uint32_t timeout_ms)
|
|
{
|
|
TickType_t ticks = (timeout_ms == UINT32_MAX) ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms);
|
|
if (xQueueReceive(s_inbound_queue, msg, ticks) != pdTRUE) {
|
|
return ESP_ERR_TIMEOUT;
|
|
}
|
|
return ESP_OK;
|
|
}
|
|
|
|
esp_err_t message_bus_push_outbound(const mimi_msg_t *msg)
|
|
{
|
|
if (xQueueSend(s_outbound_queue, msg, pdMS_TO_TICKS(1000)) != pdTRUE) {
|
|
ESP_LOGW(TAG, "Outbound queue full, dropping message");
|
|
return ESP_ERR_NO_MEM;
|
|
}
|
|
return ESP_OK;
|
|
}
|
|
|
|
esp_err_t message_bus_pop_outbound(mimi_msg_t *msg, uint32_t timeout_ms)
|
|
{
|
|
TickType_t ticks = (timeout_ms == UINT32_MAX) ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms);
|
|
if (xQueueReceive(s_outbound_queue, msg, ticks) != pdTRUE) {
|
|
return ESP_ERR_TIMEOUT;
|
|
}
|
|
return ESP_OK;
|
|
}
|