From 16d3e235db9c6b9ae4722e1e3dccb9838ac544a1 Mon Sep 17 00:00:00 2001 From: murmur Date: Sun, 11 Jun 2023 16:32:09 +0800 Subject: [PATCH] =?UTF-8?q?tcp=E8=BF=9E=E6=8E=A5=E5=8E=BB=E6=8E=89http?= =?UTF-8?q?=E5=89=8D=E7=BC=80=20tcpdemo.c=20=E4=BA=A4=E6=8D=A2=E6=8E=A5?= =?UTF-8?q?=E6=94=B6=E5=8F=91=E9=80=81=E9=A1=BA=E5=BA=8F=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0xh=E5=80=BC99=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/_main.c | 6 +++--- applications/getinfo.c | 11 ++++++---- applications/tcpdemo.c | 44 ++++++++++++++++++++++---------------- applications/tools.c | 21 +++++++++++++----- applications/ttTR.c | 3 ++- applications/ttmsg/ttmsg.c | 7 +++--- 6 files changed, 57 insertions(+), 35 deletions(-) diff --git a/applications/_main.c b/applications/_main.c index 7f7c02d..51f1162 100644 --- a/applications/_main.c +++ b/applications/_main.c @@ -94,7 +94,7 @@ void checkTT() memset(&cfg, 0, sizeof(CFG)); // cfg.s = 1; - cfg.cnt = 10;//maxTTWaitTime/cfg.s-2;//避免通信异常 + cfg.cnt = maxTTWaitTime*60/cfg.s-2;//避免通信异常 extern void getTTinfo_thread_entry(void* parameter); #define NEW_THREAD #ifdef NEW_THREAD @@ -151,7 +151,7 @@ static void getFileData_thread_entry(void) if (len) { for (size_t var = 0; var < len; var++) { -// LOG_HEX("d",27,d[var],s[var]); + LOG_HEX("d",27,d[var],s[var]); // sendMsg(d[var], s[var]); } sendMsgs(d, s, len); @@ -286,7 +286,7 @@ static void try() { LOG_I("第%d次尝试。",var+1); //rt_tick_from_millisecond(maxTTWaitTime * 1000) - rst = rt_event_recv(&sw_check, TT_IS_OK, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, 30*1000, + rst = rt_event_recv(&sw_check, TT_IS_OK, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, maxTTWaitTime*60*1000, RT_NULL); if (rst == RT_EOK)//硬件条件满足 { diff --git a/applications/getinfo.c b/applications/getinfo.c index 63fa1dc..a9eeee1 100644 --- a/applications/getinfo.c +++ b/applications/getinfo.c @@ -7,7 +7,7 @@ #include #define LOG_TAG "getinfo" -#define LOG_LVL LOG_LVL_DBG +#define LOG_LVL LOG_LVL_INFO #include //#define HTTP_GET_URL "http://www.rt-thread.com/service/rt-thread.txt" @@ -101,7 +101,7 @@ rt_uint8_t info2HEX(TT *TTinfo, rt_uint8_t *buffer) static int minTTPeriCnt=5; -static int minTTsinal=5; +static int minTTsinal=3; static int minActiveTime=0; static int maxActiveTime=0; //extern struct rt_event sw_check;//软件条件 @@ -148,8 +148,11 @@ static void rulecheck(void) if (!okCnt) { LOG_I("当前规则为:连续%d个采集周期TT信号质量不低于%d",minTTPeriCnt,minTTsinal); } - - if (atoi(TTinfo->sim) & !(atoi(TTinfo->xh) < minTTsinal) ) {// + int xh=atoi(TTinfo->xh); + if (xh == 99) { + xh=0; + } + if (atoi(TTinfo->jh) && !(xh < minTTsinal) ) {// okCnt += 1; LOG_D("第%d次符合规则。",okCnt); } diff --git a/applications/tcpdemo.c b/applications/tcpdemo.c index e1febe1..bb9ca3f 100644 --- a/applications/tcpdemo.c +++ b/applications/tcpdemo.c @@ -33,7 +33,7 @@ #define BUFSZ 1024 -static const char send_data[] = {0x88,0xAA,0xBB,0x88,0x00,0x01,0x00,0x00,0x70,0x21,0x00,0x03,0x49,0x41,0x43,0x4B};//"This is TCP Client from RT-Thread."; /* 发送用到的数据 */ +static const char send_data[] = {0x88,0xAA,0xBB,0x88,0x00,0x01,0x00,0x00,0x10,0xA0,0x00,0x10,0x00,0x31,0x33,0x39,0x32,0x00,0x10,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00};//"This is TCP Client from RT-Thread."; /* 发送用到的数据 */ void tcpclient(int argc, char **argv) { int ret; @@ -96,6 +96,25 @@ void tcpclient(int argc, char **argv) while (1) { + + /* 发送数据到sock连接 */ + ret = send(sock, send_data, sizeof(send_data), 0); + if (ret < 0) + { + /* 发送失败,关闭这个连接 */ + closesocket(sock); + rt_kprintf("\nsend error,close the socket.\r\n"); + + rt_free(recv_data); + break; + } + else if (ret == 0) + { + /* 打印send函数返回值为0的警告信息 */ + rt_kprintf("\n Send warning,send function return 0.\r\n"); + } + + /* 从sock连接中接收最大BUFSZ - 1字节数据 */ bytes_received = recv(sock, recv_data, BUFSZ - 1, 0); if (bytes_received < 0) @@ -135,7 +154,10 @@ void tcpclient(int argc, char **argv) else { /* 在控制终端显示收到的数据 */ - rt_kprintf("\nReceived data = %s ", recv_data); + for (size_t var = 0; var < bytes_received; ++var) { + rt_kprintf(" %02X ", recv_data[var]); + } +// rt_kprintf("\nReceived data = %02X ", recv_data); closesocket(sock); // rt_kprintf("\n got a 'q' or 'Q',close the socket.\r\n"); @@ -144,23 +166,7 @@ void tcpclient(int argc, char **argv) break; } - /* 发送数据到sock连接 */ - ret = send(sock, send_data, strlen(send_data), 0); - if (ret < 0) - { - /* 发送失败,关闭这个连接 */ - closesocket(sock); - rt_kprintf("\nsend error,close the socket.\r\n"); - - rt_free(recv_data); - break; - } - else if (ret == 0) - { - /* 打印send函数返回值为0的警告信息 */ - rt_kprintf("\n Send warning,send function return 0.\r\n"); - } - } + } return; } diff --git a/applications/tools.c b/applications/tools.c index edcd7b4..07d3040 100644 --- a/applications/tools.c +++ b/applications/tools.c @@ -8,7 +8,12 @@ #include #include - +#ifdef _CFGALL +int sendInterval =60; +int maxTTWaitTime = 4; +int maxTTRetryCnt = 3; +int minTTPeriCnt=5; +int minTTsinal=5; /** * 以HEX显示文件内容 */ @@ -25,10 +30,16 @@ void updatecfg(void) //因为不知原因,采用事件集独立更新配置出错 //独立响应单个参数更新事件,程序上更复杂也没特别必要 //现采用事件通知、统一全部重新加载 - - - +while(1) +{ + maxTTWaitTime = get_cfg("maxTTWaitTime"); + maxTTRetryCnt = get_cfg("maxTTRetryCnt"); + static int minTTPeriCnt=5; + static int minTTsinal=5; } +} +#endif + void sDemo() { @@ -38,7 +49,7 @@ void sDemo() upSWflag(); } -MSH_CMD_EXPORT(sDemo,swTest); +MSH_CMD_EXPORT(sDemo,喂文件数据); static struct rt_thread infoTT_thread; void ttinfoInit() diff --git a/applications/ttTR.c b/applications/ttTR.c index 259e2a9..03aa798 100644 --- a/applications/ttTR.c +++ b/applications/ttTR.c @@ -20,7 +20,7 @@ #define BUFSZ 1024 #define RETRYCNT 10 -#define URL "http://10.10.10.72" +#define URL "10.10.10.72" #define PORT 8005 int sock=0; @@ -78,6 +78,7 @@ static int tcpInit(void) static int tcpSend(const rt_uint8_t *send_data, size_t len) { + LOG_HEX("send",27,send_data,len); /* 发送数据到sock连接 */ int ret = send(sock, send_data, len, 0); diff --git a/applications/ttmsg/ttmsg.c b/applications/ttmsg/ttmsg.c index cd923a6..33fc6f8 100644 --- a/applications/ttmsg/ttmsg.c +++ b/applications/ttmsg/ttmsg.c @@ -463,10 +463,11 @@ static int pf_thread_entry(void* parameter) { for (size_t var = 0; var < len; var++) { -// sendMsg(d[var], s[var]); + sendMsg(d[var], s[var]); LOG_D("i = %d",var); LOG_HEX("d", 27, d[var], s[var]); } +// sendMsgs(d, s, len); LOG_I("Done."); } return RT_EOK; @@ -527,13 +528,13 @@ void pwTT_thread_entry(void *parameter) if (rt_pin_read(TT_EN)) { //#ifdef NO_RELAY - LOG_I("set TT %s", "ON"); + LOG_I("set TT %s", "OFF"); //#endif add_val("swCnt");//更新统计值 } else { - LOG_I("set TT %s", "OFF"); + LOG_I("set TT %s", "ON"); } }