feat(match): 同步比赛计时与装甲板扣血许可
构建客户端 / 检查(类型 + 单元测试) (push) Canceled after 0s
构建客户端 / Linux x64(deb + AppImage) (push) Canceled after 0s
构建客户端 / Windows x64(NSIS 安装包) (push) Canceled after 0s
构建客户端 / macOS 通用(.app + .dmg) (push) Canceled after 0s

- feat(client): 增加裁判比赛计时、技术暂停与选手端局域网同步
- feat(armor): 红蓝共用通用固件,按客户端选队并显示网络连接状态
- feat(armor): 仅在对局进行中允许扣血,其他阶段保留受击闪烁
- feat(client): 将计时置于血条中间并增加开赛前五秒全屏动画
- fix(client): 修复连续血条、对手镜像和图传断连灰度遮罩
- fix(client): 统一界面中文字体并整理各页面文案
- fix(maintenance): 备份迁移装甲板分区,恢复 SDK 构建与固件打包
- refactor(repo): 按 armor、vt 和 client 整理工程与脚本,移除旧参考实现
- test: 补充线路、受击许可、回环 UDP、维护和 HUD 验证
- docs: 同步构建、协议、比赛控制和硬件验证边界

验证:前端构建与 19 项相关测试通过;核心 91 项单元测试与 2 项回环 UDP 集成测试通过;装甲板规则 25 项、线路 26 项、Tauri 51 项测试通过;独立探测器 5 项与目录回归 4 项通过。完成 C3 两组阈值实际编译、导出与 ZIP 校验,检查 900×600 / 1280×720 页面、倒计时和随包中文字体。
未执行烧录、板上运行、跨电脑广播或硬件稳定性验证。
This commit is contained in:
sloray committed 2026-10-22 17:08:49 +08:00
1 parent 72901939c6
commit f7ca246b68
581 files changed
+6596 -7683

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
# This crate is built for the host, not the ESP32.
#
# It sits inside the firmware's directory tree, so cargo would otherwise inherit
# ../.cargo/config.toml and try to cross-compile it for the Xtensa target - which
# fails, because that config's ldproxy linker is only valid inside the ESP-IDF
# build. Overriding `target` back to the host triple is enough to make `cargo test`
# work here; the firmware pulls this crate in as a path dependency and cross-compiles
# it along with everything else, unaffected by this file.
[build]
target = "aarch64-apple-darwin"
+7
View File
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "protocol"
version = "0.1.0"
+6
View File
@@ -0,0 +1,6 @@
[package]
name = "protocol"
version = "0.1.0"
edition = "2021"
[dependencies]
+11
View File
@@ -0,0 +1,11 @@
# protocol
图传与装甲板共用的 UDP 线路格式及帧重组库,不依赖 ESP-IDF,可在主机上测试。
在本目录执行,Windows MSVC 示例:
```powershell
cargo +stable test --locked --target x86_64-pc-windows-msvc --config 'unstable.build-std=[]'
```
其他平台换成对应的宿主 target。字段布局、版本兼容、重组策略与拒收条件见[UDP 协议](../../docs/protocol/udp.md),测试方法见[开发与验证](../../docs/development/firmware.md#主机测试)。
+83
View File
@@ -0,0 +1,83 @@
use crate::{decode_header, encode_header_into, Header, MsgType, HEADER_LEN, PROTOCOL_VERSION};
/// 与队伍设置分开,裁判下发扣血许可时不取得操作手的改色控制权。
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ArmorDamageControl {
pub board_id: u32,
pub session: u64,
pub sequence: u64,
pub enabled: bool,
}
impl ArmorDamageControl {
pub fn encode(&self) -> Option<Vec<u8>> {
if self.board_id == 0 || self.session == 0 || self.sequence == 0 {
return None;
}
let mut out = Vec::with_capacity(HEADER_LEN + 21);
encode_header_into(
&Header {
msg_type: MsgType::ArmorDamageControl,
version: PROTOCOL_VERSION,
..Default::default()
},
&mut out,
);
out.extend(self.board_id.to_le_bytes());
out.extend(self.session.to_le_bytes());
out.extend(self.sequence.to_le_bytes());
out.push(u8::from(self.enabled));
Some(out)
}
pub fn decode(bytes: &[u8]) -> Option<Self> {
let h = decode_header(bytes)?;
if h.msg_type != MsgType::ArmorDamageControl
|| h.sender_id != 0
|| bytes.len() != HEADER_LEN + 21
{
return None;
}
let p = &bytes[HEADER_LEN..];
let value = Self {
board_id: u32::from_le_bytes(p[0..4].try_into().ok()?),
session: u64::from_le_bytes(p[4..12].try_into().ok()?),
sequence: u64::from_le_bytes(p[12..20].try_into().ok()?),
enabled: match p[20] {
0 => false,
1 => true,
_ => return None,
},
};
(value.board_id != 0 && value.session != 0 && value.sequence != 0).then_some(value)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn damage_control_is_exact_bounded_and_distinct_from_team_control() {
for enabled in [false, true] {
let value = ArmorDamageControl {
board_id: 17,
session: 88,
sequence: 123,
enabled,
};
let bytes = value.encode().unwrap();
assert_eq!(ArmorDamageControl::decode(&bytes), Some(value));
assert!(crate::ArmorControl::decode(&bytes).is_none());
for n in 0..bytes.len() {
assert!(ArmorDamageControl::decode(&bytes[..n]).is_none());
}
for (at, b) in [(4, 6), (5, 99), (HEADER_LEN + 20, 2)] {
let mut bad = bytes.clone();
bad[at] = b;
assert!(ArmorDamageControl::decode(&bad).is_none());
}
let mut bad = bytes;
bad.push(0);
assert!(ArmorDamageControl::decode(&bad).is_none());
}
}
}
File diff suppressed because it is too large. Load diff
+155
View File
@@ -0,0 +1,155 @@
//! 比赛计时快照。旧固件忽略新增的类型 7;不改变已有消息布局。
use crate::{decode_header, encode_header_into, Header, MsgType, HEADER_LEN, PROTOCOL_VERSION};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MatchState {
pub session: u64,
pub sequence: u64,
/// idle/preparation/ready/countdown/running/paused/finished = 0..6。
pub phase: u8,
/// 暂停前的阶段;未暂停时为 0。
pub resume_phase: u8,
/// 无/选手/官方 = 0/1/2。
pub pause_kind: u8,
/// 申请方 0/1;非选手暂停为 255。
pub applicant: u8,
pub remaining_ms: u32,
pub elapsed_ms: u32,
/// 无限时或未暂停时为 u32::MAX。
pub pause_remaining_ms: u32,
pub pause_elapsed_ms: u32,
/// UTF-8,至多 192 字节,不允许控制字符。
pub reason: String,
}
impl MatchState {
pub fn valid(&self) -> bool {
self.session != 0
&& self.phase <= 6
&& self.remaining_ms <= 180_000
&& self.elapsed_ms <= 180_000
&& self.reason.len() <= 192
&& !self.reason.chars().any(char::is_control)
&& if self.phase == 5 {
(1..=4).contains(&self.resume_phase)
&& !self.reason.trim().is_empty()
&& match self.pause_kind {
1 => self.applicant <= 1 && self.pause_remaining_ms <= 300_000,
2 => self.applicant == 255 && self.pause_remaining_ms == u32::MAX,
_ => false,
}
} else {
self.resume_phase == 0
&& self.pause_kind == 0
&& self.applicant == 255
&& self.pause_remaining_ms == u32::MAX
&& self.pause_elapsed_ms == 0
&& self.reason.is_empty()
}
}
pub fn encode(&self) -> Option<Vec<u8>> {
if !self.valid() {
return None;
}
let mut out = Vec::with_capacity(HEADER_LEN + 37 + self.reason.len());
encode_header_into(
&Header {
msg_type: MsgType::MatchState,
version: PROTOCOL_VERSION,
..Default::default()
},
&mut out,
);
out.extend(self.session.to_le_bytes());
out.extend(self.sequence.to_le_bytes());
out.extend([
self.phase,
self.resume_phase,
self.pause_kind,
self.applicant,
]);
for n in [
self.remaining_ms,
self.elapsed_ms,
self.pause_remaining_ms,
self.pause_elapsed_ms,
] {
out.extend(n.to_le_bytes());
}
out.push(self.reason.len() as u8);
out.extend(self.reason.as_bytes());
Some(out)
}
pub fn decode(bytes: &[u8]) -> Option<Self> {
let header = decode_header(bytes)?;
if header.msg_type != MsgType::MatchState || header.sender_id != 0 {
return None;
}
let p = bytes.get(HEADER_LEN..)?;
if p.len() < 37 || p.len() != 37 + p[36] as usize {
return None;
}
let n = |at| Some(u32::from_le_bytes(p.get(at..at + 4)?.try_into().ok()?));
let state = Self {
session: u64::from_le_bytes(p[0..8].try_into().ok()?),
sequence: u64::from_le_bytes(p[8..16].try_into().ok()?),
phase: p[16],
resume_phase: p[17],
pause_kind: p[18],
applicant: p[19],
remaining_ms: n(20)?,
elapsed_ms: n(24)?,
pause_remaining_ms: n(28)?,
pause_elapsed_ms: n(32)?,
reason: std::str::from_utf8(&p[37..]).ok()?.into(),
};
state.valid().then_some(state)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn bounded_exact_roundtrip() {
let s = MatchState {
session: 9,
sequence: 21,
phase: 5,
resume_phase: 4,
pause_kind: 1,
applicant: 0,
remaining_ms: 61_000,
elapsed_ms: 119_000,
pause_remaining_ms: 280_000,
pause_elapsed_ms: 20_000,
reason: "更换电池".into(),
};
let bytes = s.encode().unwrap();
assert_eq!(MatchState::decode(&bytes), Some(s.clone()));
for len in 0..bytes.len() {
assert!(MatchState::decode(&bytes[..len]).is_none());
}
let mut bad = bytes.clone();
bad.push(0);
assert!(MatchState::decode(&bad).is_none());
for (at, value) in [
(5, 99),
(HEADER_LEN + 16, 9),
(HEADER_LEN + 18, 3),
(HEADER_LEN + 19, 2),
(HEADER_LEN + 37, 255),
] {
let mut bad = bytes.clone();
bad[at] = value;
assert!(MatchState::decode(&bad).is_none(), "offset {at}");
}
let mut bad = s.clone();
bad.reason = "长".repeat(65);
assert!(bad.encode().is_none());
bad.reason = "换\n电池".into();
assert!(bad.encode().is_none());
}
}