- 将全局变量g_esp32OtaMutex和g_esp32OtaOccupied内聚到Esp32OtaCore类中 - 通过Esp32OtaCore::initMutex()方法初始化互斥锁替代原main.cpp中的全局初始化 - 重构HealthMonitor中WiFi连接状态管理,推送连接状态到本地成员而非直接查询 - 优化OtaCoordinator中const方法的线程安全实现,移除不必要的const_cast转换 - 封装OtaRelay的队列访问器,提供getDispatchQueue()和getResultQueue()方法 - 解决BLE与WiFi之间的横向耦合问题,通过OtaCoordinator进行射频共存管理 - 移除transport/spi_master.cpp中的CANFD接口实现到独立的canfd_bridge模块 - 优化BLE OTA中ESP32会话的幂等性和新会话处理逻辑 BREAKING CHANGE: 移除了ota_mutex.h全局头文件,相关功能迁移至Esp32OtaCore类中管理
70 lines
2.0 KiB
C++
70 lines
2.0 KiB
C++
/*
|
|
* canfd_bridge.cpp - CANFD 3通道通信桥接实现(M4: 从 SpiMaster 提取)
|
|
*/
|
|
#include <string.h>
|
|
#include "canfd_bridge.h"
|
|
#include "spi_master.h"
|
|
|
|
/**
|
|
* @brief 发送一帧 CANFD 数据,可选等待并读取响应。
|
|
* 通过 SpiMaster 的公共 syncTransfer() 完成 SPI 传输。
|
|
* 注意: syncTransfer 内部会加 SPI 互斥锁,FreeRTOS mutex 为递归锁故安全。
|
|
*/
|
|
int canFdSend(can_channel_t channel, uint32_t ext_id,
|
|
const uint8_t *data, uint8_t dlc,
|
|
uint8_t *recv_buf, uint8_t recv_max,
|
|
uint32_t timeout_ms)
|
|
{
|
|
if (channel >= CAN_CHANNEL_MAX || dlc > CAN_MAX_DLC || !data) {
|
|
return -1;
|
|
}
|
|
|
|
uint8_t tx_buf[72];
|
|
size_t tx_len = 0;
|
|
|
|
tx_buf[tx_len++] = (uint8_t)(channel & CAN_CHANNEL_MASK);
|
|
tx_buf[tx_len++] = (uint8_t)((ext_id >> 24) & 0xFF);
|
|
tx_buf[tx_len++] = (uint8_t)((ext_id >> 16) & 0xFF);
|
|
tx_buf[tx_len++] = (uint8_t)((ext_id >> 8) & 0xFF);
|
|
tx_buf[tx_len++] = (uint8_t)(ext_id & 0xFF);
|
|
memcpy(&tx_buf[tx_len], data, dlc);
|
|
tx_len += dlc;
|
|
|
|
esp_err_t ret = SpiMaster::instance().syncTransfer(
|
|
0, tx_buf, tx_len, recv_buf, recv_max, timeout_ms);
|
|
if (ret != ESP_OK) {
|
|
return -1;
|
|
}
|
|
|
|
return (int)recv_max;
|
|
}
|
|
|
|
/**
|
|
* @brief 发送一帧无需响应的 CANFD 数据。
|
|
*/
|
|
int canFdSendNoReply(can_channel_t channel, uint32_t ext_id,
|
|
const uint8_t *data, uint8_t dlc)
|
|
{
|
|
if (channel >= CAN_CHANNEL_MAX || dlc > CAN_MAX_DLC || !data) {
|
|
return -1;
|
|
}
|
|
|
|
uint8_t tx_buf[72];
|
|
size_t tx_len = 0;
|
|
|
|
tx_buf[tx_len++] = (uint8_t)(channel & CAN_CHANNEL_MASK);
|
|
tx_buf[tx_len++] = (uint8_t)((ext_id >> 24) & 0xFF);
|
|
tx_buf[tx_len++] = (uint8_t)((ext_id >> 16) & 0xFF);
|
|
tx_buf[tx_len++] = (uint8_t)((ext_id >> 8) & 0xFF);
|
|
tx_buf[tx_len++] = (uint8_t)(ext_id & 0xFF);
|
|
memcpy(&tx_buf[tx_len], data, dlc);
|
|
tx_len += dlc;
|
|
|
|
esp_err_t ret = SpiMaster::instance().send(0, tx_buf, tx_len);
|
|
if (ret != ESP_OK) {
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|