From 0e9a61bdf409736db9f86f071a82346e512b9e15 Mon Sep 17 00:00:00 2001
From: Zhangwen <13970730+mkc46119@user.noreply.gitee.com>
Date: Thu, 13 Mar 2025 19:59:48 +0800
Subject: [PATCH] =?UTF-8?q?feature=EF=BC=9A1.tcp=E6=9C=8D=E5=8A=A1?=
=?UTF-8?q?=E5=AE=8C=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
keilp/cc_as_stc02_ps5ws.uvprojx | 5 ++
source/app/task_game.c | 23 ++++++-
source/app/task_game.h | 2 +
source/app/task_w600.c | 40 ++++++++++++-
source/app/task_w600.h | 22 +++++++
source/app/task_w600_ptc.c | 86 +++++++++++++++++++++++++++
source/app/task_w600_ptc.h | 102 ++++++++++++++++++++++++++++++++
source/msp/msp_adc.c | 61 ++++++++++---------
8 files changed, 309 insertions(+), 32 deletions(-)
create mode 100644 source/app/task_w600_ptc.c
create mode 100644 source/app/task_w600_ptc.h
diff --git a/keilp/cc_as_stc02_ps5ws.uvprojx b/keilp/cc_as_stc02_ps5ws.uvprojx
index 29bc1aa..5646501 100644
--- a/keilp/cc_as_stc02_ps5ws.uvprojx
+++ b/keilp/cc_as_stc02_ps5ws.uvprojx
@@ -403,6 +403,11 @@
1
..\source\msp\msp_adc.c
+
+ task_game.c
+ 1
+ ..\source\app\task_game.c
+
diff --git a/source/app/task_game.c b/source/app/task_game.c
index 0922a52..83ff7a0 100644
--- a/source/app/task_game.c
+++ b/source/app/task_game.c
@@ -17,6 +17,7 @@
#include "../msp/uart0.h"
#include "../msp/uart3.h"
#include "../bsp/bsp_WT2605B.h"
+#include "../app/task_w600.h"
// 系统不识别的码:无效码 0x3FFF,0x0000
@@ -29,6 +30,7 @@
S_TASK_GAME _s_task_game;
+
#define GAME_OID_ZBT 0x3133
#define GAME_OID_SHERT 0x3142
#define GAME_OID_ZMG 0x3152
@@ -129,6 +131,7 @@ void L3_task_game_init(void)
#define D_task_GAME_SWITCH 0x51
#define D_task_GAME_PLAY 0x52
#define D_task_GAME_COMPLETED 0x53
+#define D_task_GAME_NET_SUBMIT 0x54
void L3_task_game_handler(S_TASK_GAME *s)
@@ -162,12 +165,12 @@ void L3_task_game_handler(S_TASK_GAME *s)
}
if (s->game_info[i].game_oid == s->read_oid)
{
- s->game_info_index = i;
+ s->game_info_index = i;
s->eeror_times = 0;
s->start_seconds = s_nos_tick.t_1s;
for (j = 0; j < game_supported_oid_max; j++)
{
- s->game_info[s->game_info_index].game_supported_oid[j].handled = 0;
+ s->game_info[s->game_info_index].game_supported_oid[j].handled = 0;
}
L2_WT2605B_Broadcast(s->game_info[i].game_audio);
L2_task_go_Tdelay(D_task_READ_OID,D_Tdelay_100ms);
@@ -256,6 +259,7 @@ void L3_task_game_handler(S_TASK_GAME *s)
L0_uart0_sendstr("It's completed.");
// 游戏完成
L2_WT2605B_Broadcast(&audio_game_complete);
+ L2_task_go_Tdelay(D_task_GAME_NET_SUBMIT,D_Tdelay_300ms);
}
else
{
@@ -267,8 +271,21 @@ void L3_task_game_handler(S_TASK_GAME *s)
{
L2_WT2605B_Broadcast(s->game_info[s->game_info_index].game_supported_oid[s->game_point_index].point_audio);
}
+ L2_task_go_Tdelay(D_task_READ_OID,D_Tdelay_300ms);
}
-
+ TTSS_Task_step(D_task_GAME_NET_SUBMIT)
+ U8 seconds = s_nos_tick.t_1s - s->start_seconds;
+ _s_task_w600_para.Send_Submit_Flag = 1;
+ _s_task_w600_para.submittaskpkg.Plan_ID[0] = _s_task_w600_para.queryackpkg.Plan_ID[0];
+ _s_task_w600_para.submittaskpkg.Plan_ID[1] = _s_task_w600_para.queryackpkg.Plan_ID[1];
+ _s_task_w600_para.submittaskpkg.Game_ID[0] = s->game_info[s->game_info_index].game_oid >> 8 & 0xFF;
+ _s_task_w600_para.submittaskpkg.Game_ID[1] = s->game_info[s->game_info_index].game_oid >> 0 & 0xFF;
+ _s_task_w600_para.submittaskpkg.Second[0] = seconds >> 8 & 0xFF;
+ _s_task_w600_para.submittaskpkg.Second[1] = seconds >> 0 & 0xFF;
+ _s_task_w600_para.submittaskpkg.Error_Time[0] = 0;
+ _s_task_w600_para.submittaskpkg.Error_Time[1] = _s_task_game.eeror_times;
+ _s_task_w600_para.submittaskpkg.Score[0] = 0;
+ _s_task_w600_para.submittaskpkg.Score[1] = 0;
L2_task_go_Tdelay(D_task_READ_OID,D_Tdelay_300ms);
TTSS_Task_end();
diff --git a/source/app/task_game.h b/source/app/task_game.h
index ce80995..4f98197 100644
--- a/source/app/task_game.h
+++ b/source/app/task_game.h
@@ -54,6 +54,8 @@ typedef struct _s_task_game
}S_TASK_GAME;
+
+
extern S_TASK_GAME _s_task_game;
extern void L3_task_game_init(void);
diff --git a/source/app/task_w600.c b/source/app/task_w600.c
index 4e0bf9f..03b2ff7 100644
--- a/source/app/task_w600.c
+++ b/source/app/task_w600.c
@@ -51,6 +51,14 @@ void L3_uart2_wifi_parse(void)
ts_uart[uNum2].r.ok = 0;
Lc_buf_copy_uc(wifi_rev_buf, ts_uart[uNum2].r.buf, ts_uart[uNum2].r.num);
wifi_rev_buf[ts_uart[uNum2].r.num] = 0;
+ if (_s_task_w600_para.st_cip_ok == 1)
+ {
+ if (wifi_rev_buf,ts_uart[uNum2].r.num)
+ {
+ _s_task_w600_para.Recieve_QueryAck_Flag = 1;
+ }
+ return;
+ }
tmp_num = 0;
while(*ptr != 0)
{
@@ -118,6 +126,12 @@ void L3_task_W600_flow_init(U8 mode)
_s_task_w600_para.mode = mode;
_s_task_w600_para.send = 0;
_s_task_w600_para.conn_ok = 0;
+ _s_task_w600_para.Send_Query_Flag = 1;
+ _s_task_w600_para.Recieve_QueryAck_Flag = 0;
+ _s_task_w600_para.Send_Submit_Flag = 0;
+ _s_task_w600_para.queryackpkg.Plan_ID[0] = 0;
+ _s_task_w600_para.queryackpkg.Plan_ID[1] = 0;
+
}
//------------------------ GM35 Flow Handle -----------------------------------
@@ -155,6 +169,8 @@ void L3_task_W600_flow_init(U8 mode)
#define TTSS_TASK_GM35_FLOW_ST_SAMRTCSTOP 0x34
#define TTSS_TASK_GM35_FLOW_ST_SAMRTCSTOPPED 0x35
+#define TTSS_TASK_GM35_SEND_TPC 0x35
+
#define INS_TIMEOUT 5
#define GM35_SEND_DATA_INTERVAL 300
@@ -326,7 +342,27 @@ void L2_task_W600_flow_handle(struct _s_task_W600_Para *s)
s->send = 0;
}
TTSS_Task_step(TTSS_TASK_GM35_FLOW_ST_DATA)
- L2_task_go(TTSS_TASK_GM35_FLOW_ST_DATA);
+ if (s->Send_Query_Flag == 1)
+ {
+ U8 num = constructor_QueryTaskPkg();
+ s->Send_Query_Flag = 0;
+ L0_uart2_sendArray(&_s_task_w600_para.querytaskpkg,num);
+
+ }
+ else if (s->Send_Submit_Flag == 1)
+ {
+ U8 num = constructor_SubmitTaskPkg();
+ s->Send_Submit_Flag = 0;
+ L0_uart2_sendArray(&_s_task_w600_para.submittaskpkg,num);
+ }
+ else if (s->Recieve_QueryAck_Flag == 1)
+ {
+ s->Recieve_QueryAck_Flag = 0;
+ // 根据_s_task_w600_para.queryackpkg.Game_ID[2] 找见响应音频
+ // L2_WT2605B_Broadcast(s->game_info[i].game_audio);
+
+ }
+ L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_ST_DATA,D_Tdelay_100ms);
/*******************************************s->mode = W600_SC(按键进入)********************************************** */
TTSS_Task_step(TTSS_TASK_GM35_FLOW_ST_SMARTCONFIG)
@@ -377,6 +413,8 @@ void L2_task_W600_flow_handle(struct _s_task_W600_Para *s)
}
+
+
diff --git a/source/app/task_w600.h b/source/app/task_w600.h
index 0998445..ef3221c 100644
--- a/source/app/task_w600.h
+++ b/source/app/task_w600.h
@@ -20,6 +20,8 @@
#include "../tpc/at0d0a.h"
#include "../tpc/ccmodbus.h"
#include "../msp/msp_eeprom.h"
+#include "../app/task_w600_tpc.h"
+
////<<<<<<<<<<<<<<<<<<< GM35模块 AT操作指令 <<<<<<<<<<<<<<<<<<<<<<<<
#define AT_INS_ATE1 "ATE1\r\n" //模块查询+打开回显
@@ -47,6 +49,10 @@
#define AT_INS_AP_SEND "AT+CIPSENDEX=0,6\r\n" //
#define AT_INS_AP_SERVER_CLOSE "AT+CIPSERVER=0\r\n" //关闭服务器 2-1
#define AT_INS_AP_CLOSE "AT+CWQAP\r\n" //断开AP连接
+
+
+
+
////<<<<<<<<<<<<<<<<<<<_s_task_test_<<<<<<<<<<<<<<<<<<<<<<<<
enum _s_w600_mode
{
@@ -90,6 +96,22 @@ struct _s_task_W600_Para
vU8 gm35_reboot_times; //gm35重启次数
vU8 smartc_ok; //smartconfig是否成功
+
+ //任务请求
+ QueryTaskPkg querytaskpkg;
+ //请求响应
+ QueryAckPkg queryackpkg;
+ //成绩提交
+ SubmitTaskPkg submittaskpkg;
+ // 发送请求标志位 1发送请求 0不发送请求
+ U8 Send_Query_Flag;
+ // 接收到响应标志 0未接收 1接收
+ U8 Recieve_QueryAck_Flag;
+ // 发送提交标志 1发送提交 0不发送提交
+ U8 Send_Submit_Flag;
+
+
+
};
extern struct _s_task_W600_Para _s_task_w600_para;
diff --git a/source/app/task_w600_ptc.c b/source/app/task_w600_ptc.c
new file mode 100644
index 0000000..a2ba41d
--- /dev/null
+++ b/source/app/task_w600_ptc.c
@@ -0,0 +1,86 @@
+#include "../app/task_w600_ptc.h"
+#include "../app/task_w600.h"
+
+
+U8 constructor_QueryTaskPkg()
+{
+ _s_task_w600_para.querytaskpkg.filter[0] = 0xAA;
+ _s_task_w600_para.querytaskpkg.filter[1] = 0xBB;
+ _s_task_w600_para.querytaskpkg.num = 0x07;
+ _s_task_w600_para.querytaskpkg.cmd = 0xA1;
+ _s_task_w600_para.querytaskpkg.did[0] = G.mcu_id[3];
+ _s_task_w600_para.querytaskpkg.did[1] = G.mcu_id[4];
+ _s_task_w600_para.querytaskpkg.did[2] = G.mcu_id[5];
+ _s_task_w600_para.querytaskpkg.did[3] = G.mcu_id[6];
+ _s_task_w600_para.querytaskpkg.crc[0] = 0xCC;
+ _s_task_w600_para.querytaskpkg.crc[1] = 0xDD;
+
+ //CRC
+ // crc16(_s_task_w600_para.crc, &_s_task_w600_para.cmder, num - 2);
+ return _s_task_w600_para.querytaskpkg.num + 3;
+}
+
+U8 constructor_SubmitTaskPkg()
+{
+ _s_task_w600_para.submittaskpkg.filter[0] = 0xAA;
+ _s_task_w600_para.submittaskpkg.filter[1] = 0xBB;
+ _s_task_w600_para.submittaskpkg.num = 0x11;
+ _s_task_w600_para.submittaskpkg.cmd = 0xA3;
+ _s_task_w600_para.submittaskpkg.did[0] = G.mcu_id[3];
+ _s_task_w600_para.submittaskpkg.did[1] = G.mcu_id[4];
+ _s_task_w600_para.submittaskpkg.did[2] = G.mcu_id[5];
+ _s_task_w600_para.submittaskpkg.did[3] = G.mcu_id[6];
+ // 其他属性在游戏完成时赋值
+ _s_task_w600_para.submittaskpkg.cmd[0] = 0xCC;
+ _s_task_w600_para.submittaskpkg.crc[1] = 0xDD;
+
+ //CRC
+ // crc16(_s_task_w600_para.crc, &_s_task_w600_para.cmder, num - 2);
+ return _s_task_w600_para.submittaskpkg.num + 3;
+
+}
+
+U8 parse_QueryAckPkg(U8* d,U8 num)
+{
+ if (num != 0x0F)
+ {
+ return 0;
+ }
+ _s_task_w600_para.queryackpkg.filter[0] = d[0];
+ _s_task_w600_para.queryackpkg.filter[1] = d[1];
+
+ if ( _s_task_w600_para.queryackpkg.filter[0] != 0xAA ||
+ _s_task_w600_para.queryackpkg.filter[1] != 0xBB )
+ {
+ return 0;
+ }
+ _s_task_w600_para.queryackpkg.num = d[2];
+ _s_task_w600_para.queryackpkg.cmd = d[3];
+ _s_task_w600_para.queryackpkg.did[0] = d[4];
+ _s_task_w600_para.queryackpkg.did[1] = d[5];
+ _s_task_w600_para.queryackpkg.did[2] = d[6];
+ _s_task_w600_para.queryackpkg.did[3] = d[7];
+ _s_task_w600_para.queryackpkg.Plan_ID[0] = d[8];
+ _s_task_w600_para.queryackpkg.Plan_ID[1] = d[9];
+ _s_task_w600_para.queryackpkg.Game_ID[0] = d[10];
+ _s_task_w600_para.queryackpkg.Game_ID[1] = d[11];
+ _s_task_w600_para.queryackpkg.Tranning_Status = d[12];
+ // 其他属性在游戏完成时赋值
+ _s_task_w600_para.queryackpkg.crc[0] = d[13];
+ _s_task_w600_para.queryackpkg.crc[1] = d[14];
+
+ if ( _s_task_w600_para.queryackpkg.crc[0] != 0xCC ||
+ _s_task_w600_para.queryackpkg.crc[1] != 0xDD )
+ {
+ return 0;
+ }
+ //CRC
+ // crc16(_s_task_w600_para.crc, &_s_task_w600_para.cmder, num - 2);
+ return 1;
+
+
+
+
+}
+
+
diff --git a/source/app/task_w600_ptc.h b/source/app/task_w600_ptc.h
new file mode 100644
index 0000000..68386d2
--- /dev/null
+++ b/source/app/task_w600_ptc.h
@@ -0,0 +1,102 @@
+ ////////////////////////////////////////////////////////////////////////////
+///@copyright Copyright (c) 2018, 传控科技 All rights reserved.
+///-------------------------------------------------------------------------
+/// @file bsp_gc6133.c.h
+/// @brief bsp @ driver config
+///-------------------------------------------------------------------------
+/// @version 1.0
+/// @author CC
+/// @date 20180331
+/// @note cc_AS_stc02
+
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef _app_task_w600_TPC_H
+#define _app_task_w600_TPC_H
+
+#include "../clib/type.h"
+
+typedef struct {
+ //起始码
+ U8 filter[2];
+ //长度
+ U8 num;
+ //Cmd
+ U8 cmd;
+ //设备ID
+ U8 did[4];
+ //校验
+ U8 crc[2];
+}QueryTaskPkg;
+
+typedef struct {
+ //起始码
+ U8 filter[2];
+ //长度
+ U8 num;
+ //Cmd
+ U8 cmd;
+ //设备ID
+ U8 did[4];
+ //训练方案编号
+ U8 Plan_ID[2];
+ //游戏ID
+ U8 Game_ID[2];
+ //训练完成情况
+ U8 Tranning_Status; //0正常训练;1今日训练完成;2今日无训练任务
+ //校验
+ U8 crc[2];
+}QueryAckPkg;
+
+typedef struct {
+ //起始码
+ U8 filter[2];
+ //长度
+ U8 num;
+ //Cmd
+ U8 cmd;
+ //设备ID
+ U8 did[4];
+ //训练方案编号
+ U8 Plan_ID[2];
+ //游戏ID
+ U8 Game_ID[2];
+ //游戏时长
+ U8 Second[2];
+ //错误次数
+ U8 Error_Time[2];
+ //得分
+ U8 Score[2];
+ //校验
+ U8 crc[2];
+}SubmitTaskPkg;
+
+
+extern U8 constructor_QueryTaskPkg(void);
+extern U8 constructor_SubmitTaskPkg(void);
+extern U8 parse_QueryAckPkg(void);
+
+
+
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/source/msp/msp_adc.c b/source/msp/msp_adc.c
index c48c9f9..5f90dc3 100644
--- a/source/msp/msp_adc.c
+++ b/source/msp/msp_adc.c
@@ -1,33 +1,6 @@
#include "../msp/msp_adc.h"
#include "../msp/uart0.h"
-
-
-/*********
-1、给 MCU 的 内部 ADC 模块电源打开后,需等待约 1ms, 等 MCU 内部的 ADC 电源稳定 后再让 ADC 工作;
-2、适当加长对外部信号的采样时间,就是对 ADC 内部采样保持电容的充电或放电时间,时间够, 内部才能和外部电势相等。
-19.1.1 ADC 控制寄存器(ADC_CONTR),PWM 触发 ADC 控制
-符号 地址 B7 B6 B5 B4 B3 B2 B1 B0
-ADC_CONTR BCH ADC_POWER ADC_START ADC_FLAG ADC_EPWMT ADC_CHS[3:0]
-ADC_POWER:ADC
-电源控制位 0:
-关闭 ADC 电源 1:打开 ADC 电源。
-建议进入空闲模式和掉电模式前将 ADC 电源关闭,以降低功耗
-特别注意: 1、给 MCU 的 内部 ADC 模块电源打开后,需等待约 1ms, 等 MCU 内部的 ADC 电源稳定 后再让 ADC 工作;
-2、适当加长对外部信号的采样时间,就是对 ADC 内部采样保持电容的充电或放电时间,时间够内部才能和外部电势相等。
-ADC_START:ADC 转换启动控制位。写入 1 后开始 ADC 转换,转换完成后硬件自动将此位清零。
-0:无影响。即使 ADC 已经开始转换工作,写 0 也不会停止A/D 转换。
-1:开始 ADC 转换,转换完成后硬件自动将此位清零。
-ADC_FLAG:ADC 转换结束标志位。当 ADC 完成一次转换后,硬件会自动将此位置 1,
-并向 CPU 提出 中断请求。此标志位必须软件清零。
-
-层次 >逻辑 >数据流 >测试 >工具 > 代码
-套路(方法论)才是最主要的
- 12位 800K
- 反推
-22M / 64(采样的总时间)=
-
-*********/
-
+#include
void L0_ADC_init(void)
{
@@ -92,6 +65,38 @@ U16 L1_ADC_Read(u8 CHA)
return adc_data;
}
+//平均值滤波
+U16 ADC_Average_Filter(U8 N)
+{
+ U16 sum = 0;
+ U16 Aver = 0;
+ U8 i;
+ U16 arr[10] = 0;
+ FP32 Variance = 0;
+// 平均值
+ for(i = 0; i < N; i++)
+ {
+ arr[i] = L1_ADC_Read(12);
+ sum += L1_ADC_Read(12);
+ }
+ Aver = sum/N;
+
+ for (i = 0; i < N; i++)
+ {
+ L0_uart0_ushex(arr[i]);
+ L0_uart0_0d0a();
+ }
+
+ // 方差
+ for(i = 0; i < N; i++)
+ {
+ Variance += (arr[i] - Aver) * (arr[i] - Aver);
+ }
+ Variance /= N;
+ // printf("%.7f", Variance);
+ return Aver;
+}
+
#if 0
U16 L1_ADC_Read(u8 CHA)