主流程

This commit is contained in:
kirl committed 2026-08-01 02:41:29 +08:00
1 parent f96e72dbb8
commit 0045c0c390
10 files changed
+216 -74

No files matched your search

+11 -40
View File
@@ -9,6 +9,7 @@
#include "servo.h"
#include "protocol.h"
#include "actuator.h"
#include "rgb.h"
#include <string.h>
#include <stdlib.h>
@@ -22,6 +23,8 @@
#include "esp_netif.h"
#include "nvs_flash.h"
#ifdef EDC_DEBUG_WEB
static const char *TAG = "WEB_CTRL";
/* ---- WiFi 配置 ---- */
@@ -791,37 +794,9 @@ static esp_err_t favicon_handler(httpd_req_t *req)
}
/* ============================================================
* 协议状态 API
* 协议状态 API (从 actuator 读取最近 Cycle 快照)
* ============================================================ */
/* 最近收到的 Cycle 快照 (由 edc_proto_on_cycle 更新, web 读取) */
static edc_cycle_t s_web_cycle;
static volatile bool s_web_cycle_valid;
static portMUX_TYPE s_web_lock = portMUX_INITIALIZER_UNLOCKED;
void edc_proto_on_cycle(const edc_cycle_t *cycle, edc_channel_t ch)
{
static uint16_t s_last_done_id = 0xFFFF;
portENTER_CRITICAL(&s_web_lock);
memcpy(&s_web_cycle, cycle, sizeof(edc_cycle_t));
s_web_cycle_valid = true;
portEXIT_CRITICAL(&s_web_lock);
ESP_LOGI(TAG, "Cycle #%u via %s, %u frags",
cycle->cycle_id, ch == EDC_CH_I2C ? "I2C" : "UART",
cycle->frag_count);
/* I2C / UART 冗余下发, 同一 cycle_id 只回一次 DONE */
if (cycle->cycle_id == s_last_done_id) {
return;
}
s_last_done_id = cycle->cycle_id;
/* 回复 MPU: Cycle 已收到 (后续实际执行电机后应移到执行完毕处) */
edc_proto_send_done(cycle->cycle_id);
}
static esp_err_t api_proto_status_handler(httpd_req_t *req)
{
edc_proto_stat_t stat;
@@ -837,18 +812,13 @@ static esp_err_t api_proto_status_handler(httpd_req_t *req)
(stat.last_channel == EDC_CH_UART) ? "UART" : "none",
stat.done_sent, stat.request_sent);
portENTER_CRITICAL(&s_web_lock);
bool valid = s_web_cycle_valid;
edc_cycle_t cycle;
if (valid) memcpy(&cycle, &s_web_cycle, sizeof(edc_cycle_t));
portEXIT_CRITICAL(&s_web_lock);
if (valid) {
const edc_cycle_t *cycle = actuator_get_last_cycle();
if (cycle) {
off += snprintf(json + off, sizeof(json) - off,
",\"cycle\":{\"id\":%u,\"frags\":%u,\"data\":[",
cycle.cycle_id, cycle.frag_count);
for (int i = 0; i < cycle.frag_count; i++) {
edc_fragment_t *f = &cycle.fragments[i];
cycle->cycle_id, cycle->frag_count);
for (int i = 0; i < cycle->frag_count; i++) {
const edc_fragment_t *f = &cycle->fragments[i];
off += snprintf(json + off, sizeof(json) - off,
"%s{\"sx\":%u,\"sy\":%u,\"sa\":%.1f,\"tx\":%u,\"ty\":%u,\"ta\":%.1f}",
(i > 0) ? "," : "",
@@ -874,7 +844,6 @@ static esp_err_t api_proto_request_handler(httpd_req_t *req)
static esp_err_t api_proto_done_handler(httpd_req_t *req)
{
edc_cycle_t cycle;
edc_proto_stat_t stat;
edc_proto_get_stats(&stat);
/* 对最近收到的 cycle 发送 DONE */
@@ -1084,3 +1053,5 @@ void web_ctrl_init(void)
wifi_init_sta();
http_server_init();
}
#endif /* EDC_DEBUG_WEB */