- 新增 `lastWorkerExecUs()`:获取最近一次 worker 任务执行耗时(µs)。 - 引入 `SpiProfile` 结构体:事务级详细剖析,记录 SPI 事务各阶段的时间戳。 - 实现 `lastProfile()`:诊断用,获取最近一次事务剖析快照。 - SPI 时钟配置提升至 13.3 MHz,改善性能。 - 修改前端 JavaScript 轮询逻辑:新增 uptime 检查,更好地处理 ESP32 重启状态。 - SPI 测速 HTML 的计时单位由毫秒改为微秒显示。 - 新建 `spi_ring_cache.h`:共享 SPI ring push 缓存工具。 - 新增 `http_util.h`:共享 HTTP 处理器工具,含 JSON 拼接与查询参数解析。 - 引入 `json_parse.h`:轻量级 JSON 解析器,针对扁平 JSON 对象设计。 - 新增 Windows 环境下的项目构建批处理脚本。 - 重构 CAN 反馈处理:从推送式改为请求驱动架构,降低内存占用、提升效率。
67 lines
1.8 KiB
C++
67 lines
1.8 KiB
C++
/*
|
|
* motor_version.cpp - GD32 多电机版本推送解析与缓存 (SPI TYPE 0xC6)
|
|
*
|
|
* 镜像 motor_state.cpp 的互斥保护缓存模型。
|
|
*/
|
|
#include "monitor/motor_version.h"
|
|
#include "monitor/spi_ring_cache.h"
|
|
|
|
#include <string.h>
|
|
|
|
namespace {
|
|
|
|
static SemaphoreHandle_t s_mux = nullptr;
|
|
static motor_version_table_t s_table = {};
|
|
|
|
} // namespace
|
|
|
|
bool onMotorVersionEvent(const uint8_t *payload, size_t len)
|
|
{
|
|
if (payload == nullptr || len < MOTORVER_HEADER_LEN) {
|
|
return false;
|
|
}
|
|
|
|
const uint8_t count = payload[0];
|
|
|
|
ringCacheEnsureMux(&s_mux);
|
|
if (s_mux == nullptr) return false;
|
|
if (xSemaphoreTake(s_mux, pdMS_TO_TICKS(20)) != pdTRUE) return false;
|
|
|
|
size_t offset = MOTORVER_HEADER_LEN;
|
|
for (uint8_t i = 0; i < count; ++i) {
|
|
if (offset + MOTORVER_ENTRY_SIZE > len) {
|
|
break;
|
|
}
|
|
const uint8_t node = payload[offset];
|
|
if (node >= 1 && node <= MOTORVER_MAX_NODES) {
|
|
motor_version_slot_t &slot = s_table.slots[node - 1];
|
|
slot.node_id = node;
|
|
slot.seq = rdU32Le(&payload[offset + 1]);
|
|
memcpy(slot.version, &payload[offset + 5], MOTORVER_DLC);
|
|
slot.recv_ms = esp_timer_get_time() / 1000;
|
|
slot.valid = true;
|
|
s_table.have_data = true;
|
|
}
|
|
offset += MOTORVER_ENTRY_SIZE;
|
|
}
|
|
|
|
xSemaphoreGive(s_mux);
|
|
return true;
|
|
}
|
|
|
|
bool getLatestMotorVersion(motor_version_table_t *out)
|
|
{
|
|
if (out == nullptr) return false;
|
|
ringCacheEnsureMux(&s_mux);
|
|
if (s_mux == nullptr) return false;
|
|
|
|
bool ok = false;
|
|
if (xSemaphoreTake(s_mux, pdMS_TO_TICKS(20)) == pdTRUE) {
|
|
if (s_table.have_data) {
|
|
*out = s_table;
|
|
ok = true;
|
|
}
|
|
xSemaphoreGive(s_mux);
|
|
}
|
|
return ok;
|
|
} |