tcp连接去掉http前缀

tcpdemo.c 交换接收发送顺序
添加xh值99处理逻辑
This commit is contained in:
murmur 2023-06-11 16:32:09 +08:00
parent 88d2f1d0fc
commit 16d3e235db
6 changed files with 57 additions and 35 deletions

View File

@ -94,7 +94,7 @@ void checkTT()
memset(&cfg, 0, sizeof(CFG)); memset(&cfg, 0, sizeof(CFG));
// //
cfg.s = 1; cfg.s = 1;
cfg.cnt = 10;//maxTTWaitTime/cfg.s-2;//避免通信异常 cfg.cnt = maxTTWaitTime*60/cfg.s-2;//避免通信异常
extern void getTTinfo_thread_entry(void* parameter); extern void getTTinfo_thread_entry(void* parameter);
#define NEW_THREAD #define NEW_THREAD
#ifdef NEW_THREAD #ifdef NEW_THREAD
@ -151,7 +151,7 @@ static void getFileData_thread_entry(void)
if (len) if (len)
{ {
for (size_t var = 0; var < len; var++) { 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]); // sendMsg(d[var], s[var]);
} }
sendMsgs(d, s, len); sendMsgs(d, s, len);
@ -286,7 +286,7 @@ static void try()
{ {
LOG_I("第%d次尝试。",var+1); LOG_I("第%d次尝试。",var+1);
//rt_tick_from_millisecond(maxTTWaitTime * 1000) //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); RT_NULL);
if (rst == RT_EOK)//硬件条件满足 if (rst == RT_EOK)//硬件条件满足
{ {

View File

@ -7,7 +7,7 @@
#include <webclient.h> #include <webclient.h>
#define LOG_TAG "getinfo" #define LOG_TAG "getinfo"
#define LOG_LVL LOG_LVL_DBG #define LOG_LVL LOG_LVL_INFO
#include <ulog.h> #include <ulog.h>
//#define HTTP_GET_URL "http://www.rt-thread.com/service/rt-thread.txt" //#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 minTTPeriCnt=5;
static int minTTsinal=5; static int minTTsinal=3;
static int minActiveTime=0; static int minActiveTime=0;
static int maxActiveTime=0; static int maxActiveTime=0;
//extern struct rt_event sw_check;//软件条件 //extern struct rt_event sw_check;//软件条件
@ -148,8 +148,11 @@ static void rulecheck(void)
if (!okCnt) { if (!okCnt) {
LOG_I("当前规则为:连续%d个采集周期TT信号质量不低于%d",minTTPeriCnt,minTTsinal); LOG_I("当前规则为:连续%d个采集周期TT信号质量不低于%d",minTTPeriCnt,minTTsinal);
} }
int xh=atoi(TTinfo->xh);
if (atoi(TTinfo->sim) & !(atoi(TTinfo->xh) < minTTsinal) ) {// if (xh == 99) {
xh=0;
}
if (atoi(TTinfo->jh) && !(xh < minTTsinal) ) {//
okCnt += 1; okCnt += 1;
LOG_D("第%d次符合规则。",okCnt); LOG_D("第%d次符合规则。",okCnt);
} }

View File

@ -33,7 +33,7 @@
#define BUFSZ 1024 #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) void tcpclient(int argc, char **argv)
{ {
int ret; int ret;
@ -96,6 +96,25 @@ void tcpclient(int argc, char **argv)
while (1) 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字节数据 */ /* 从sock连接中接收最大BUFSZ - 1字节数据 */
bytes_received = recv(sock, recv_data, BUFSZ - 1, 0); bytes_received = recv(sock, recv_data, BUFSZ - 1, 0);
if (bytes_received < 0) if (bytes_received < 0)
@ -135,7 +154,10 @@ void tcpclient(int argc, char **argv)
else 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); closesocket(sock);
// rt_kprintf("\n got a 'q' or 'Q',close the socket.\r\n"); // rt_kprintf("\n got a 'q' or 'Q',close the socket.\r\n");
@ -144,23 +166,7 @@ void tcpclient(int argc, char **argv)
break; 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; return;
} }

View File

@ -8,7 +8,12 @@
#include <dfs_file.h> #include <dfs_file.h>
#include <usrcfg.h> #include <usrcfg.h>
#ifdef _CFGALL
int sendInterval =60;
int maxTTWaitTime = 4;
int maxTTRetryCnt = 3;
int minTTPeriCnt=5;
int minTTsinal=5;
/** /**
* HEX显示文件内容 * 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() void sDemo()
{ {
@ -38,7 +49,7 @@ void sDemo()
upSWflag(); upSWflag();
} }
MSH_CMD_EXPORT(sDemo,swTest); MSH_CMD_EXPORT(sDemo,);
static struct rt_thread infoTT_thread; static struct rt_thread infoTT_thread;
void ttinfoInit() void ttinfoInit()

View File

@ -20,7 +20,7 @@
#define BUFSZ 1024 #define BUFSZ 1024
#define RETRYCNT 10 #define RETRYCNT 10
#define URL "http://10.10.10.72" #define URL "10.10.10.72"
#define PORT 8005 #define PORT 8005
int sock=0; int sock=0;
@ -78,6 +78,7 @@ static int tcpInit(void)
static int tcpSend(const rt_uint8_t *send_data, size_t len) static int tcpSend(const rt_uint8_t *send_data, size_t len)
{ {
LOG_HEX("send",27,send_data,len);
/* 发送数据到sock连接 */ /* 发送数据到sock连接 */
int ret = send(sock, send_data, len, 0); int ret = send(sock, send_data, len, 0);

View File

@ -463,10 +463,11 @@ static int pf_thread_entry(void* parameter)
{ {
for (size_t var = 0; var < len; var++) for (size_t var = 0; var < len; var++)
{ {
// sendMsg(d[var], s[var]); sendMsg(d[var], s[var]);
LOG_D("i = %d",var); LOG_D("i = %d",var);
LOG_HEX("d", 27, d[var], s[var]); LOG_HEX("d", 27, d[var], s[var]);
} }
// sendMsgs(d, s, len);
LOG_I("Done."); LOG_I("Done.");
} }
return RT_EOK; return RT_EOK;
@ -527,13 +528,13 @@ void pwTT_thread_entry(void *parameter)
if (rt_pin_read(TT_EN)) if (rt_pin_read(TT_EN))
{ {
//#ifdef NO_RELAY //#ifdef NO_RELAY
LOG_I("set TT %s", "ON"); LOG_I("set TT %s", "OFF");
//#endif //#endif
add_val("swCnt");//更新统计值 add_val("swCnt");//更新统计值
} }
else else
{ {
LOG_I("set TT %s", "OFF"); LOG_I("set TT %s", "ON");
} }
} }