- A12 单一命令处理器(cmd*.c):一行 JSON 进出、seq 全局判重(32 条按值)、
限幅 / 空槽一律拒 / 拒绝记事件;命令号与错误码冻结(进 flash)。新增 power 命令,
fan 改为只抬不压的下限(t_thermal_set_floor)。rail_set_mv 注明不拿锁,调用方包 xact。
- A13 USB-Serial-JTAG 分帧(ulink*.c):@C / @R 前缀 + CRC-16,日志行首 @ 垫空格,
任意切块可切;关掉 USB 副控制台(它绕开驱动写 FIFO)。PC 端客户端 tools/prlink.py。
- A14 + C1(netcfg / mlink / cmd_net):topic phonerail/<mac>/{cmd,rsp,tele,state},
mqtts(evse-ca 编进固件)、1 s 遥测、遗嘱离线;wifi / mqtt 配置只收 USB、存 NVS,
net 永不回显密码。
- 协议定稿写进需求文档 §10.8(A12 / A13 / A14 三节);N7 撤销改 D7(机架管理前后端)。
宿主机 23 个 ctest / 400 例全绿;板 B 已烧 0.1.0-a14,经 WiFi → 公网 → 8883 TLS 真连网验过。
固件 0xE2220 / 1 MB 分区只剩 12%,C2 前要重排分区表。
Co-Authored-By: Claude Opus 5.5 <[email protected]>
97 行
3.6 KiB
CMake
97 行
3.6 KiB
CMake
# PhoneRail 宿主机构建 —— 不依赖 ESP-IDF,用来跑单元测试(CTest)。
|
||
#
|
||
# bash host/test.sh 配置 + 编译 + ctest
|
||
#
|
||
# 与 IDF 目标共享的源码只有 ../main 里的与硬件无关部分。
|
||
# 新增一个既要上板又要被测的 .c,必须同时加进:
|
||
# ../main/CMakeLists.txt 的 SRCS 和 下面的 PHONERAIL_CORE_SRCS
|
||
# HAL 里新增一路实现则要同时加进:
|
||
# ../components/phonerail_hal/CMakeLists.txt 的 SRCS(esp 那份)
|
||
# 和下面的 PHONERAIL_HAL_SIM_SRCS(sim 那份)
|
||
# 新增一个器件驱动则是:
|
||
# ../components/drv/CMakeLists.txt 的 SRCS 和 下面的 PHONERAIL_DRV_SRCS
|
||
cmake_minimum_required(VERSION 3.16)
|
||
project(phonerail_host C)
|
||
|
||
set(CMAKE_C_STANDARD 11)
|
||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||
add_compile_options(-Wall -Wextra -Werror)
|
||
|
||
set(FW_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..)
|
||
|
||
# ---- 被测代码 -------------------------------------------------------------
|
||
set(PHONERAIL_CORE_SRCS
|
||
${FW_ROOT}/main/version.c
|
||
${FW_ROOT}/main/rail.c
|
||
${FW_ROOT}/main/rail_cfg.c
|
||
${FW_ROOT}/main/i2cbus.c
|
||
${FW_ROOT}/main/slot.c
|
||
${FW_ROOT}/main/sched.c
|
||
${FW_ROOT}/main/tasks.c
|
||
${FW_ROOT}/main/t_safety.c
|
||
${FW_ROOT}/main/t_actuator.c
|
||
${FW_ROOT}/main/t_thermal.c
|
||
${FW_ROOT}/main/evlog.c
|
||
${FW_ROOT}/main/cmd_json.c
|
||
${FW_ROOT}/main/cmd.c
|
||
${FW_ROOT}/main/cmd_exec.c
|
||
${FW_ROOT}/main/cmd_report.c
|
||
${FW_ROOT}/main/ulink.c
|
||
${FW_ROOT}/main/cmd_net.c
|
||
${FW_ROOT}/main/netcfg.c
|
||
${FW_ROOT}/main/mlink.c
|
||
)
|
||
|
||
# HAL:接口在 include/,宿主机链 sim/ 的实现(esp/ 那份只有 IDF 目标编)。
|
||
set(PHONERAIL_HAL_DIR ${FW_ROOT}/components/phonerail_hal)
|
||
set(PHONERAIL_HAL_SIM_SRCS
|
||
${PHONERAIL_HAL_DIR}/hal_err.c
|
||
${PHONERAIL_HAL_DIR}/hal_i2c_acct.c
|
||
${PHONERAIL_HAL_DIR}/sim/hal_lock_sim.c
|
||
${PHONERAIL_HAL_DIR}/sim/sim_hal.c
|
||
${PHONERAIL_HAL_DIR}/sim/hal_i2c_sim.c
|
||
${PHONERAIL_HAL_DIR}/sim/hal_gpio_sim.c
|
||
${PHONERAIL_HAL_DIR}/sim/sim_sr595.c
|
||
${PHONERAIL_HAL_DIR}/sim/sim_pca9555.c
|
||
${PHONERAIL_HAL_DIR}/sim/hal_pwm_sim.c
|
||
${PHONERAIL_HAL_DIR}/sim/hal_time_sim.c
|
||
${PHONERAIL_HAL_DIR}/sim/hal_store_sim.c
|
||
)
|
||
|
||
# 器件驱动:与平台无关(只经 hal_i2c_*),两个目标编的是同一份源码。
|
||
set(PHONERAIL_DRV_DIR ${FW_ROOT}/components/drv)
|
||
set(PHONERAIL_DRV_SRCS
|
||
${PHONERAIL_DRV_DIR}/ina226.c
|
||
${PHONERAIL_DRV_DIR}/dac63204.c
|
||
${PHONERAIL_DRV_DIR}/sr595.c
|
||
${PHONERAIL_DRV_DIR}/pca9555.c
|
||
${PHONERAIL_DRV_DIR}/tca9548a.c
|
||
${PHONERAIL_DRV_DIR}/ch224a.c
|
||
)
|
||
|
||
add_library(phonerail_core STATIC
|
||
${PHONERAIL_CORE_SRCS} ${PHONERAIL_HAL_SIM_SRCS} ${PHONERAIL_DRV_SRCS})
|
||
target_include_directories(phonerail_core PUBLIC
|
||
${FW_ROOT}/main
|
||
${PHONERAIL_HAL_DIR}/include
|
||
${PHONERAIL_HAL_DIR}/sim
|
||
${PHONERAIL_DRV_DIR}/include)
|
||
|
||
# ---- 测试框架 Unity(从 ESP-IDF v5.4 原样复制到 third_party/,与上板测试同一套)
|
||
add_library(unity STATIC ${FW_ROOT}/third_party/unity/unity.c)
|
||
target_include_directories(unity PUBLIC ${FW_ROOT}/third_party/unity)
|
||
target_compile_definitions(unity PUBLIC UNITY_OUTPUT_COLOR)
|
||
# 第三方源码不吃本工程的 -Werror
|
||
target_compile_options(unity PRIVATE -w)
|
||
|
||
# ---- 测试用例:test/test_*.c 一个文件一个可执行 + 一条 ctest ---------------
|
||
enable_testing()
|
||
|
||
file(GLOB PHONERAIL_TESTS ${FW_ROOT}/test/test_*.c)
|
||
foreach(test_src ${PHONERAIL_TESTS})
|
||
get_filename_component(test_name ${test_src} NAME_WE)
|
||
add_executable(${test_name} ${test_src})
|
||
target_link_libraries(${test_name} PRIVATE phonerail_core unity)
|
||
add_test(NAME ${test_name} COMMAND ${test_name})
|
||
endforeach()
|