UI 代码纳入规范检查:大括号 K&R 化、strcpy 换 memcpy 等违规修复

- pre-commit 配置:移除 Drivers/BSP/UI/ 整目录排除,14 个 UI 源文件全部受 cppcheck + 规范检查
- ui_net_sink.c:11 处 Allman 大括号归并 K&R,i/c 声明改即用
- ui_port.c:7 处大括号归并
- ui_net_sink_backend_mcu.c:2 处大括号归并
- ui_menu_view.c:menu_frame_t 指针改 const
- ui_page_net_cfg.c:6 处 strcpy 改 memcpy

验证:pre-commit 全钩子通过、模拟器 0 警、菜单/内容页像素回归 PASS、Keil 0 错 0 警
This commit is contained in:
2026-09-13 19:38:14 +08:00
parent cb8cea38b2
commit 34528a9798
6 changed files with 36 additions and 53 deletions
+13 -26
View File
@@ -54,8 +54,7 @@ static uint32_t g_gen; /* 建立监听时的网络代次号(变化
* 限定条件:无
* 函数说明:对全部数据字节做异或累加(协议约定的简单校验);len 为 0 时返回 0
*/
static uint8_t remo_crc(const uint8_t *d, int len)
{
static uint8_t remo_crc(const uint8_t *d, int len) {
int i;
uint8_t c = 0;
@@ -72,8 +71,7 @@ static uint8_t remo_crc(const uint8_t *d, int len)
* 限定条件:p 指向至少 2 字节可写空间
* 函数说明:网络协议多字节字段统一采用大端序传输
*/
static void put_u16(uint8_t *p, uint16_t v)
{
static void put_u16(uint8_t *p, uint16_t v) {
p[0] = (uint8_t)(v >> 8);
p[1] = (uint8_t)(v & 0xFF);
}
@@ -85,8 +83,7 @@ static void put_u16(uint8_t *p, uint16_t v)
* 限定条件:p 指向至少 4 字节可写空间
* 函数说明:网络协议多字节字段统一采用大端序传输
*/
static void put_u32(uint8_t *p, uint32_t v)
{
static void put_u32(uint8_t *p, uint32_t v) {
p[0] = (uint8_t)(v >> 24);
p[1] = (uint8_t)(v >> 16);
p[2] = (uint8_t)(v >> 8);
@@ -101,8 +98,7 @@ static void put_u32(uint8_t *p, uint32_t v)
* 函数说明:帧格式 [TAG_DEVICE][CMD][LEN_H][LEN_LO][DATA][CRC];CRC 为 payload 异或;
* 无连接时直接返回
*/
static void remo_send(uint8_t cmd, const uint8_t *data, uint16_t len)
{
static void remo_send(uint8_t cmd, const uint8_t *data, uint16_t len) {
uint8_t *p;
if (g_client < 0) {
@@ -128,8 +124,7 @@ static void remo_send(uint8_t cmd, const uint8_t *data, uint16_t len)
* 限定条件:g_client >= 0
* 函数说明:payload 为 [宽u16][高u16][缓冲字节数u32],共 6 字节(大端)
*/
static void remo_send_init(void)
{
static void remo_send_init(void) {
uint8_t init[8];
put_u16(init, UI_W);
@@ -158,8 +153,7 @@ static void remo_send_init(void)
* 位图后回送 [偏移u32][位图 3200B],非 0 偏移暂不支持
* 3. 未知命令码静默丢弃
*/
static void remo_handle(const uint8_t *f, int n)
{
static void remo_handle(const uint8_t *f, int n) {
uint8_t tag;
uint8_t cmd;
uint16_t len;
@@ -270,8 +264,7 @@ static rm_parser_t g_rm; /* 全局解析器:状态跨 poll 调用保持(
* 限定条件:无
* 函数说明:新建连接、连接断开或长度越界失步时调用,清除半帧残留
*/
static void rm_parser_reset(void)
{
static void rm_parser_reset(void) {
g_rm.st = RM_ST_TAG;
g_rm.pos = 0;
g_rm.plen = 0;
@@ -288,8 +281,7 @@ static void rm_parser_reset(void)
* 3. payload 长度越界(>RM_MAX_RX_PAYLOAD)判为损坏并复位
* 4. 整帧 CRC 通过才回调 remo_handle;状态跨多次 recv 保持
*/
static void rm_parser_feed(uint8_t b)
{
static void rm_parser_feed(uint8_t b) {
switch (g_rm.st) {
case RM_ST_TAG:
if (b != TAG_CLIENT) {
@@ -351,8 +343,7 @@ static void rm_parser_feed(uint8_t b)
* 限定条件:net_* 网络子系统可用
* 函数说明:绑定 g_port 与任意本地地址并进入监听;成功后写回 g_listen
*/
static int bind_listen(void)
{
static int bind_listen(void) {
int ls;
struct net_sockaddr_in addr;
@@ -386,8 +377,7 @@ static int bind_listen(void)
* 限定条件:网络子系统已初始化(模拟器端 Winsock 已就绪)
* 函数说明:创建流式 Socket 并绑定端口进入监听;成功才记录网络代次号
*/
int ui_net_sink_start(uint16_t port)
{
int ui_net_sink_start(uint16_t port) {
g_port = port;
if (bind_listen() < 0) {
@@ -413,11 +403,8 @@ int ui_net_sink_start(uint16_t port)
* 5. 对端关闭/真错误时关闭客户端;若监听 Socket 随客户端失效
* (MCU 单连接模型)则重建监听,等待重连
*/
void ui_net_sink_poll(void)
{
void ui_net_sink_poll(void) {
int n;
int i;
int c;
/* 网络重建(代次变化):旧监听/客户端已随芯片复位失效,重建监听 */
if (net_get_generation() != g_gen) {
@@ -442,7 +429,7 @@ void ui_net_sink_poll(void)
/* 无客户端时尝试接受连接 */
if (g_client < 0) {
c = net_accept(g_listen, NULL, NULL);
int c = net_accept(g_listen, NULL, NULL);
if (c >= 0) {
g_client = c;
rm_parser_reset();
@@ -453,7 +440,7 @@ void ui_net_sink_poll(void)
/* 有客户端时非阻塞收帧,逐字节喂入解析状态机 */
n = net_recv(g_client, g_rx, (int)sizeof(g_rx), NET_MSG_DONTWAIT);
if (n > 0) {
for (i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
rm_parser_feed((uint8_t)g_rx[i]);
}
} else if (n == 0) {