Files
sambu 870a16f25a feat(lock): 补齐需求规格里的门锁密码校验(需求→设计→代码→测试追溯闭环)
背景:docs/01 的 FR-04 与 docs/03 §6.2 门锁状态机写明“密码校验 + 连错 3 次冷却 30 秒”,
README/用户手册也照此描述;但实现侧 lock 命令只把参数当密码就上锁,从不校验——文档与代码不符。
本提交把实现补齐,使文档描述与代码一致。

- device.h:Device 增加 lock_attempts / lock_until_ts 字段(追加在结构体末尾,原有字段偏移不变),
  新增 SHS_LOCK_DEFAULT_PASSWORD(1234) / SHS_LOCK_MAX_ATTEMPTS(3) / SHS_LOCK_COOLDOWN_SECONDS(30)
  与 device_lock_try_password()(错误码语义:OK / ERR_PARAM+剩余次数 / ERR_STATE+冷却秒数)
- device.c:实现密码校验、失败计数、达上限转入冷却、冷却期内拒绝(含 now_ts=0 不依赖时钟的约定)
- commands.c:lock 支持 on|off 直控、<密码> 校验、unlock 解锁第一把锁;help 用法同步
- tests/unit/test_branch.c:新增 19 项断言覆盖正确/错误/达上限/冷却期/冷却结束/非门锁设备/空指针
- scripts/demo.txt 增加 lock 4 1234;scripts/acceptance.sh 新增 A9(3 项断言)
- README 与 docs/04 的 lock 用法改正

实测:CTest 14/14 通过(unit.branch 133 项断言);acceptance.sh A1~A9 共 24 项断言全通过
2026-09-14 20:57:02 +08:00

31 lines
750 B
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 智能家居控制系统 —— 无人值守演示脚本(回放用)
# '#' 开头为注释;空行忽略。运行:./build/debug/smart_home --replay scripts/demo.txt
help
list
list 灯
power 1 on
dim 1 70
power 3 off
# 注:离线设备会被拒绝——#8 阳台灯为离线,power 8 on 返回 SHS_ERR_STATE,
# 该负例由 scripts/acceptance.sh 与单元测试断言,回放脚本只走正常路径
# 门锁:解锁 → 带密码上锁(错误密码与冷却路径由 acceptance.sh A9 与单元测试覆盖)
lock unlock
lock 4 1234
scene 回家
sensors
ac 2 24
scene 睡眠
schedule set 0 7 1
schedule set 0 9 2
schedule set 0 18 3
schedule set 0 23 4
schedule show
report
frame 1 2 1
frame 1 1 0
log 10
save
list
selftest
quit