From 6f94d7b52a44a06cd0095341e685b7d3508eb70a Mon Sep 17 00:00:00 2001 From: "CSSC-WORK\\murmur" Date: Sat, 26 Aug 2023 16:49:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0sram=E5=90=8E=E4=B8=8D?= =?UTF-8?q?=E7=A8=B3=E5=AE=9A=EF=BC=8C=E6=9A=82=E5=AD=98=E5=90=8E=E5=9B=9E?= =?UTF-8?q?=E9=80=80=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/alarmer.c | 6 +- applications/core.c | 11 +-- applications/func/func.c | 166 +++++++++++++++++++++++++++++++++---- applications/getinfo.c | 5 +- applications/ttTR.c | 4 +- applications/ttmsg/ttmsg.c | 8 ++ applications/uart_3S.c | 2 +- rtconfig.h | 2 +- 8 files changed, 173 insertions(+), 31 deletions(-) diff --git a/applications/alarmer.c b/applications/alarmer.c index 81c8e01..a1fef32 100644 --- a/applications/alarmer.c +++ b/applications/alarmer.c @@ -310,7 +310,7 @@ int isInWindowZone() // //} -//MSH_CMD_EXPORT(stopAlarm,stop); -//MSH_CMD_EXPORT(startAlarm,start); -//MSH_CMD_EXPORT(isInWindow,isInWindow); +MSH_CMD_EXPORT(stopAlarm,stop); +MSH_CMD_EXPORT(startAlarm,start); +MSH_CMD_EXPORT(isInWindowZone,isInWindow); //MSH_CMD_EXPORT(getCurrentTime,getCurrentTime); diff --git a/applications/core.c b/applications/core.c index 5f1e746..a7b42b7 100644 --- a/applications/core.c +++ b/applications/core.c @@ -463,11 +463,11 @@ void initTT_thread_entry() else if (!isTCPok()) //判断TCP连接是否正常,异常自动重连 { // LOG_W("TT server is not ready,--%d",isTCPok()); -// tcpInit(); - if (tcpInit() != RT_EOK) { - cmd_free(); - //此处 - } + tcpInit(); +// if (tcpInit() != RT_EOK) { +// cmd_free(); +// //此处 +// } // rt_thread_mdelay(1000); if (isTCPok()) { @@ -476,6 +476,7 @@ void initTT_thread_entry() recTT(); repGetTT(); reportLoc(); + LOG_D("threads are ready."); } } diff --git a/applications/func/func.c b/applications/func/func.c index 2e679ea..08833a6 100644 --- a/applications/func/func.c +++ b/applications/func/func.c @@ -18,6 +18,7 @@ extern SYS_CFG scfg; extern int cryptSingleMsg(uint8_t *din, size_t len, uint8_t *dout); extern int pointInPolygon(int polyCorners,float polyX[], float polyY[],float x,float y); +void selfTest(void); /** * 将收发数据以ASCII字符形式存入log * @param din 待存储数据 @@ -25,7 +26,7 @@ extern int pointInPolygon(int polyCorners,float polyX[], float polyY[],float x,f * @return 1-发送的数据,0-接收的数据,其它为发送失败的数据 */ int trDataTolog(uint8_t *din, size_t len, uint8_t isTx) -{ +{return; char fn[60] = "\n"; initDataLogPath(fn); @@ -82,6 +83,7 @@ void setCommMode(int isTT) //write to cfg file set_cfg("commMode", isTT); LOG_D("set commMode to %s",isTT?"TT":"BD"); + selfTest(); } int getCommMode() @@ -211,7 +213,7 @@ void upSend_thread_entry(void* parameter) RT_WEAK int upSend(uint8_t *din, size_t len) { LOG_D("try to upsend to TT."); - +//return; // if (one_msg_send_done == RT_NULL) { // one_msg_send_done = rt_sem_create("senddone", 1, RT_IPC_FLAG_PRIO); // } @@ -246,7 +248,7 @@ RT_WEAK int upSend(uint8_t *din, size_t len) /** * 系统自检,自动发送自检结果 */ -void selfTest() +void selfTest(void) { LOG_I("FUNC = selftest"); rt_uint8_t rst[200]={0x5A, 0xA5, ADDR_ANJI, ADDR_TT, _CMD_SELF_TEST>>8, _CMD_SELF_TEST & 0xff}; @@ -256,24 +258,25 @@ void selfTest() rst[p++]=0x00; rst[p++]=0x09; - rst[p++] = sysSta; - rst[p++] = getXh();//xh,jh - rst[p++] = isTTjh(); - rst[p++] = commSpeed; - rst[p++] = getPowerLevel(); + rst[p++] = sysSta; //系统状态 + rst[p++] = getXh();//xh,jh //信号值 + rst[p++] = isTTjh(); //激活 + rst[p++] = commSpeed; //速率 +// rst[p++] = scfg.commMode; + rst[p++] = getPowerLevel(); //电量 - //flash 剩餘空間 + //flash 剩餘空間 //FLASH剩余空间 uint16_t cap = getFreeSpace("/"); rst[p++] = (uint8_t)(cap >> 8); rst[p++] = (uint8_t)(cap & 0xff); //SD卡剩餘空間 - cap = getFreeSpace("/sd"); + cap = getFreeSpace("/sd"); //SD卡剩余空间 rst[p++] = (uint8_t)(cap >> 8); rst[p++] = (uint8_t)(cap & 0xff); //添加配置文件信息 - uint8_t size = sizeof(scfg); + uint8_t size = sizeof(scfg); //配置文件信息 memcpy(rst + p,&scfg, size); p+=size; @@ -385,6 +388,7 @@ void openWindow(int t) rt_timer_start(timer1); LOG_D("手动开窗完成,%d分钟后自动关窗。",t); } + selfTest(); } /** @@ -634,7 +638,7 @@ int isInFence(uint8_t *loc); */ static void reportLoc_thread_entry(void *parameter) { -#define CHECK_INTERVAL 15000 +#define CHECK_INTERVAL 6000 size_t i = 0; while (isTCPok()) { @@ -1057,8 +1061,15 @@ void chkACK(uint8_t *msg, size_t size) * @param din * @param len */ -void parseTTData(uint8_t *din, size_t len) +void parseTTData_thread_entry(void *parameter) { + + SMSG* msg = RT_NULL; + msg = (SMSG*) parameter; + uint8_t din[500]; + memcpy(din,msg->data,msg->len); + size_t len = (size_t)msg->len; + /** * +---------------------+-----------+-----------+-----------+-----------+---------+---------------------+------------+ * | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | @@ -1116,7 +1127,28 @@ void parseTTData(uint8_t *din, size_t len) } } +void parseTTData(uint8_t *din, size_t len) +{ + static SMSG msg; + memset(&msg, 0, sizeof(SMSG)); + memcpy(msg.data,din,len); + msg.len=len; + /* 创建 serial 线程 */ + rt_thread_t thread = rt_thread_create("parseTT", parseTTData_thread_entry, (void *) &msg, 1024 * 5, 27-1, 10); + /* 创建成功则启动线程 */ + if (thread != RT_NULL) + { + rt_thread_startup(thread); + return RT_EOK; + } + else + { + LOG_E("thread 'parseTT' create failure."); + return -RT_ERROR; + } + +} /** * get file size in byte * @param file file name whith fullpath @@ -1215,6 +1247,109 @@ void d_cacheData() cacheDataToFile(demo, len); } +#ifdef TR_USE_THREAD +void parseRS232_thread_entry(void *parameter) +{ + + SMSG* msg = RT_NULL; + msg = (SMSG*) parameter; + uint8_t din[500]; + memcpy(din,msg->data,msg->len); + size_t len = (size_t)msg->len; + +//有HEX有ASCII,统一按HEX解析 + //部分数据以10字节(20字符)的0数据开始,如深度查询,心跳包等 + //处理思路是先不管前导0,对应指令手动加前导数据 +// uint8_t asciiHead[]={0x41, 0x54, 0x2B, 0x53, 0x4E, 0x44,};//"AT+SND" + uint8_t hexHead[]={0x5a, 0xa5};//"5AA5" + //由于帧头有多种,且ascii和hex混发,无法处理粘包 + +// LOG_D("data is %s",isDataASCII(din, len)?"ASCII":"BIN"); + //check +// if (memcmp(din,asciiHead,sizeof(asciiHead)) == 0) { + if (isDataASCII(din, len)) { + //ascii + LOG_I("type = ASCII"); + trDataTolog(din, len, 0); + + + uint8_t index[10]; + uint8_t tmpHead[]={0x35, 0x41, 0x41, 0x35}; + size_t n=isInByte(din, len, tmpHead, sizeof(tmpHead), index); +// LOG_D("n=%d",n); + if (!n) { + LOG_W("RS232中无匹配帧"); + return; + } + for (size_t i = 0; i < n; i++) + { + //按帧头分割 + uint8_t ndin[400]; + int cnt=(i+1 -//#include - +#endif #include #include /** diff --git a/applications/getinfo.c b/applications/getinfo.c index 740ab06..2da0b19 100644 --- a/applications/getinfo.c +++ b/applications/getinfo.c @@ -201,6 +201,7 @@ static void rulecheck(void) } if (okCnt >= scfg.minTTPeriCnt) { //TT具备发送条件 + LOG_I("----"); TTIsReady(); LOG_I("符合规则,TT具备发送状态。"); okCnt = scfg.minTTPeriCnt -1; @@ -455,7 +456,7 @@ void repGetTT_thread_entry(void* parameter) appendInfo(rstInfo, RST_LEN, buffer, len); } rulecheck(); - rt_thread_mdelay(10 * 1000);//间隔3s更新一次数据 + rt_thread_mdelay(3 * 1000);//间隔3s更新一次数据 } memset(rstInfo,0x3f,RST_LEN);//初始化 } @@ -469,7 +470,7 @@ void repGetTT(void) {} memset(rstInfo,0x3f,RST_LEN);//初始化 /* 创建 serial 线程 */ - rt_thread_t thread = rt_thread_create("repGetTT", repGetTT_thread_entry, RT_NULL, 1024 * 5, 27, 10); + rt_thread_t thread = rt_thread_create("repGetTT", repGetTT_thread_entry, RT_NULL, 1024 * 10, 27+2, 10); /* 创建成功则启动线程 */ if (thread != RT_NULL) { diff --git a/applications/ttTR.c b/applications/ttTR.c index 819754f..7ac7fa8 100644 --- a/applications/ttTR.c +++ b/applications/ttTR.c @@ -21,13 +21,13 @@ #include #include -#define BUFSZ 200 +#define BUFSZ 2000 #define RETRYCNT 10 #define URL TTIP #define PORT 8005 static int sock=0; -static int flag=0; +volatile int flag=0; void tcpClose(void) { /* 关闭这个连接 */ diff --git a/applications/ttmsg/ttmsg.c b/applications/ttmsg/ttmsg.c index cd95d0a..5dd5207 100644 --- a/applications/ttmsg/ttmsg.c +++ b/applications/ttmsg/ttmsg.c @@ -483,3 +483,11 @@ void recTT(void) } } MSH_CMD_EXPORT(recTT,TTrx demo.) + +/** + * 更新目标地址 + */ +void updateTargetAddr(uint8_t *din, uint8_t *addr) +{ + memcpy(din+13,addr,4); +} diff --git a/applications/uart_3S.c b/applications/uart_3S.c index 29edcbd..5636676 100644 --- a/applications/uart_3S.c +++ b/applications/uart_3S.c @@ -80,7 +80,7 @@ static void serial_thread_entry(void *parameter) // struct rx_msg msg; rt_err_t result; rt_uint32_t rx_length=0;//单次收到的数据长度 - static char rx_buffer[RT_SERIAL_RB_BUFSZ/4 + 1]; + static char rx_buffer[RT_SERIAL_RB_BUFSZ + 1]; while (1) { diff --git a/rtconfig.h b/rtconfig.h index e7de1da..229164b 100644 --- a/rtconfig.h +++ b/rtconfig.h @@ -309,7 +309,7 @@ #define SYSWATCH_EXCEPT_CONFIRM_TMO 15 #define SYSWATCH_EXCEPT_RESUME_DLY 15 #define SYSWATCH_THREAD_PRIO 0 -#define SYSWATCH_THREAD_STK_SIZE 1024 +#define SYSWATCH_THREAD_STK_SIZE 1024*2 #define SYSWATCH_THREAD_NAME "syswatch" #define SYSWATCH_WDT_NAME "wdt" #define SYSWATCH_WDT_TIMEOUT 5