From 656fde2902464407bb966973bbc5944e24498392 Mon Sep 17 00:00:00 2001 From: "CSSC-WORK\\murmur" Date: Thu, 20 Jul 2023 16:18:42 +0800 Subject: [PATCH] =?UTF-8?q?tools.c=20update=20bytes2str()=20=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=A7=A3=E6=9E=90=E5=90=8C=E6=84=8F=E6=94=BE=E5=85=A5?= =?UTF-8?q?=20func.c=20=E4=B8=AD=E6=9C=89parseTTData()=20=E5=88=A4?= =?UTF-8?q?=E6=96=AD=20=E6=9B=B4=E6=96=B0parseTTData=E5=87=BD=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=AF=B9=E7=B2=98=E5=8C=85=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/_main.c | 2 +- applications/func/func.c | 79 +++++++++++++++++++++++++------------- applications/tools.c | 4 +- applications/ttmsg/ttmsg.c | 13 ++++--- 4 files changed, 63 insertions(+), 35 deletions(-) diff --git a/applications/_main.c b/applications/_main.c index b583cb2..c11a7e8 100644 --- a/applications/_main.c +++ b/applications/_main.c @@ -244,7 +244,7 @@ void iniCnt() LOG_W("TT server is not ready."); tcpInit(); LOG_D("s=%d",isTCPok()); - rt_thread_mdelay(5000); +// rt_thread_mdelay(5000); } { LOG_D("TT server is ready."); diff --git a/applications/func/func.c b/applications/func/func.c index d3880ce..46bc0c7 100644 --- a/applications/func/func.c +++ b/applications/func/func.c @@ -114,7 +114,7 @@ RT_WEAK int upSend(uint8_t *din, size_t len) */ void selfTest() { - LOG_D("FUNC = selftest"); + LOG_I("FUNC = selftest"); rt_uint8_t rst[100]={0x5A, 0xA5, 0x32, 0x3E, 0x0A, 0x41}; int p = 6; rt_uint8_t sysSta=1,xh=0,jh=0,commSpeed=0; @@ -581,6 +581,18 @@ void parse3SData(uint8_t *din, size_t count) } } +void chkACK(uint8_t *msg, size_t size) +{ + rt_uint8_t ackgood[] = { 0x88, 0xAA, 0xBB, 0x88, 0x41, 0x43, 0x4B }; //前四字节=帧头、后三字节=ACK + if (rt_memcmp(msg, ackgood, 4) == 0 && rt_memcmp(msg + size - 3, ackgood + 4, 3) == 0) + { + LOG_I("data is ACK."); + } + else { + LOG_W("NONE FUNCTION MATCH."); + } +} + /** * @brief 解析TT数据,TT收到的指令必是单指令,解析容易。 * @@ -594,39 +606,52 @@ void parseTTData(uint8_t *din, size_t len) * | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | * +---------------------+-----------+-----------+-----------+-----------+---------+---------------------+------------+ * | fstart[4] | fnum[2] | bak[2] | ftype[2] | fdlen[2] | fcrc[1] | ftccid[4] | rawData[N] | -* | 0x88,0xAA,0xBB,0x88 | 0x00,0x01 | 0x00,0x22 | 0x70,0x21 | 0x00,0xAA | 0x00 | 0x27,0x22,0x22,0x22 | | +* | 0x88,0xAA,0xBB,0x88 | 0x00,0x01 | 0x00,0x00 | 0x70,0x21 | 0x00,0xAA | 0x00 | 0x27,0x22,0x22,0x22 | | * +---------------------+-----------+-----------+-----------+-----------+---------+---------------------+------------+ */ - uint8_t head[]={0x88,0xAA,0xBB,0x88, 0x00,0x01, 0x00,0x22, 0x70,0x21, 0x00,0xaa, 0x00, 0x27,0x22,0x22,0x22 }; + uint8_t head[]={0x88,0xAA,0xBB,0x88, 0x00,0x01, 0x00,0x00, 0x70,0x21, 0x00,0xaa, 0x00, 0x27,0x22,0x22,0x22 }; //fstart[4] fnum[2]  bak[2]  ftype[2]  fdlen[2]  fcrc[1] ftccid[4] -// uint8_t rst[10]; -// size_t n=isInByte(din, len, head, 10, rst); -// uint8_t ndin[200]; -// for (size_t i = 0; i < n; i++) -// { -// int n=rst[i+1] -// memcpy(ndin,din,rst[i+1]-rst[i]); -// } - - uint8_t rst = memcmp(din,head,10);//只比较到ftype - if (rst) - { - LOG_W("帧头不匹配"); + uint8_t rst[10]; + size_t n=isInByte(din, len, head, 10, rst); + uint8_t ndin[200]; + if (!n) { + LOG_W("无匹配数据"); return; } - - uint8_t id[30]=""; - LOG_D("get new data: id=\"%s\", cur/all=[%d/%d]",bytes2str(din+17,7,10,"_",id),din[25],din[26]); - if (din[24] >> 7) // fcfg=数据类型。解析TT收到的数据时仅需解析“命令”,“数据”传输是单向的。 + for (size_t i = 0; i < n; i++) { - LOG_W("浮标端仅接受指令,暂不支持数据。"); - return; - } - uint8_t rawData[200]; - uint8_t rawDataLen=len-27; - memcpy(rawData, din + 27, rawDataLen); - parse3SData(rawData,rawDataLen); + //按帧头分割 + int cnt=(i+1> 7) // fcfg=数据类型。解析TT收到的数据时仅需解析“命令”,“数据”传输是单向的。 + { + LOG_W("浮标端仅接受指令,暂不支持数据。"); + return; + } + uint8_t rawData[200]; + uint8_t rawDataLen=cnt-27; + memcpy(rawData, ndin + 27, rawDataLen); + parse3SData(rawData,rawDataLen); + } + } // switch (din[24] & 0x7F) // 识别指令的目标地址 // { diff --git a/applications/tools.c b/applications/tools.c index 98c2834..f6bc338 100644 --- a/applications/tools.c +++ b/applications/tools.c @@ -243,7 +243,9 @@ char *bytes2str(uint8_t *din, size_t count, int radix, char *sep, char *str) strcat(rst,sep); // printf("rst=%s,s=%s\n",rst,s); } - strncpy(str,rst,strlen(rst)-strlen(sep));//去掉末尾的连接符 + int len = strlen(rst)-strlen(sep); + strncpy(str,rst,len);//去掉末尾的连接符 + str[len]='\0'; return str; } diff --git a/applications/ttmsg/ttmsg.c b/applications/ttmsg/ttmsg.c index 8a08e96..0dd8a8e 100644 --- a/applications/ttmsg/ttmsg.c +++ b/applications/ttmsg/ttmsg.c @@ -544,15 +544,16 @@ void recTT_thread_entry() { //收到数据长度为0表示tcp断开 break; } - LOG_D("%d Bytes received from TT",msg.size); + LOG_I("%d Bytes received from TT",msg.size); LOG_HEX("TTrec", 16, msg.data, msg.size); //此处处理接收到数据 - rt_uint8_t rec_good[] = { 0x88, 0xAA, 0xBB, 0x88, 0x41,0x43,0x4B }; //前四字节=帧头、后三字节=ACK - if (rt_memcmp(msg.data, rec_good, 4) == 0 && rt_memcmp(msg.data+msg.size-3, rec_good+4, 3) == 0) +// rt_uint8_t rec_good[] = { 0x88, 0xAA, 0xBB, 0x88, 0x41,0x43,0x4B }; //前四字节=帧头、后三字节=ACK +// if (rt_memcmp(msg.data, rec_good, 4) == 0 && rt_memcmp(msg.data+msg.size-3, rec_good+4, 3) == 0) +// { +// LOG_I("ack is good."); +// } +// else { - LOG_I("ack is good."); - } - else { LOG_D("try to parse data."); parseTTData(msg.data,msg.size); }