refactor(device): 重构SPI命令处理为模块化架构
- 将原有的 monolithic app_spi_command.cpp 拆分为多个专门的命令处理器文件 - 新增 spi_command_handler.h 定义命令处理器接口和上下文结构 - 新增 app_spi_command_defs.h 提取公共协议常量定义 - 新增多个具体命令处理器实现文件: - app_spi_cmd_boot_request.cpp (进入Bootloader命令) - app_spi_cmd_ota_wait.cpp (OTA等待响应命令) - app_spi_cmd_ping.cpp (APP心跳ping命令) - app_spi_cmd_can_bridge.cpp (SPI到CAN桥接命令) - 修改 app_spi_command.cpp 仅负责SPI链路管理和命令路由逻辑 - 更新配置文件添加新源文件到项目编译列表 - 调整全局实例为对象实例(AppSpiCommandBus),移除静态方法依赖 - 更新README文档说明新的SPI命令总线拆分架构 - 微调版本号(patch: 0 -> 1, build: 2 -> 0)
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
#include "device/spi_command_handler.h"
|
||||
#include "device/app_spi_command.h"
|
||||
#include "device/app_spi_command_defs.h"
|
||||
#include "sys/config.h"
|
||||
#include "main.h"
|
||||
#include <cstring>
|
||||
|
||||
namespace {
|
||||
|
||||
class SpiAppPingHandler final : public ISpiCommandHandler {
|
||||
public:
|
||||
bool canHandle(uint8_t frame_type) const override
|
||||
{
|
||||
return frame_type == SpiDefs::kTypeAppPing;
|
||||
}
|
||||
|
||||
void handle(AppSpiCommand &bus, const SpiCommandContext &ctx) override
|
||||
{
|
||||
|
||||
uint8_t alive_payload[19];
|
||||
std::memset(alive_payload, 0, sizeof(alive_payload));
|
||||
alive_payload[0] = 0xA1U; /* magic */
|
||||
alive_payload[1] = 0x55U; /* APP version tag */
|
||||
alive_payload[2] = (uint8_t)APP_FW_VERSION_MAJOR;
|
||||
alive_payload[3] = (uint8_t)APP_FW_VERSION_MINOR;
|
||||
alive_payload[4] = (uint8_t)APP_FW_VERSION_PATCH;
|
||||
alive_payload[5] = (uint8_t)APP_FW_VERSION_BUILD;
|
||||
alive_payload[6] = 0xAAU; /* BOOT version tag */
|
||||
|
||||
const volatile uint32_t *bv0 = (const volatile uint32_t *)CONFIG_BOOT_VERSION_ADDR0;
|
||||
const volatile uint32_t *bv1 = (const volatile uint32_t *)CONFIG_BOOT_VERSION_ADDR1;
|
||||
uint32_t bw0 = *bv0;
|
||||
uint32_t bw1 = *bv1;
|
||||
alive_payload[7] = (uint8_t)(bw0 & 0xFFU);
|
||||
alive_payload[8] = (uint8_t)((bw0 >> 16) & 0xFFU);
|
||||
alive_payload[9] = (uint8_t)(bw1 & 0xFFU);
|
||||
alive_payload[10] = (uint8_t)((bw1 >> 16) & 0xFFU);
|
||||
|
||||
alive_payload[11] = (uint8_t)(g_app_uptime_sec & 0xFFU);
|
||||
alive_payload[12] = (uint8_t)((g_app_uptime_sec >> 8) & 0xFFU);
|
||||
alive_payload[13] = (uint8_t)((g_app_uptime_sec >> 16) & 0xFFU);
|
||||
alive_payload[14] = (uint8_t)((g_app_uptime_sec >> 24) & 0xFFU);
|
||||
|
||||
bus.buildResponse(ctx.tx_buf, ctx.tx_buf_size, ctx.tx_len,
|
||||
SpiDefs::kRspAck, alive_payload, sizeof(alive_payload));
|
||||
}
|
||||
};
|
||||
|
||||
static SpiAppPingHandler s_handler;
|
||||
|
||||
} // namespace
|
||||
|
||||
void registerSpiAppPingCommand(AppSpiCommand &bus)
|
||||
{
|
||||
bus.registerHandler(&s_handler);
|
||||
}
|
||||
Reference in New Issue
Block a user