From 88d2f1d0fc88240138c6b8078afa7321a26639a1 Mon Sep 17 00:00:00 2001 From: murmur Date: Tue, 6 Jun 2023 15:45:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90=E8=A7=84?= =?UTF-8?q?=E5=88=99=E6=A1=86=E6=9E=B6=20=E5=9F=BA=E6=9C=AC=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E6=95=B0=E6=8D=AE=E6=89=93=E5=8C=85=EF=BC=88=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E6=96=87=E4=BB=B6=EF=BC=89=20TCPclient=20=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E5=A4=B1=E8=B4=A5=E6=9A=82=E6=9C=AA=E5=AE=9A=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/_main.c | 288 +++++++++++++++++++++++++++++---- applications/cfg.c | 6 +- applications/cfg.h | 13 +- applications/comp.c | 4 +- applications/demo.c | 82 +++++----- applications/getinfo.c | 108 ++++++++----- applications/main.c | 21 +-- applications/tcpdemo.c | 10 +- applications/tools.c | 73 +++++++++ applications/ttTR.c | 4 +- applications/ttmsg/ttmsg.c | 151 +++++++++-------- applications/uart_dma_sample.c | 23 +-- applications/usrcfg.h | 15 ++ rtconfig.h | 22 +-- 14 files changed, 592 insertions(+), 228 deletions(-) create mode 100644 applications/tools.c diff --git a/applications/_main.c b/applications/_main.c index b798c02..7f7c02d 100644 --- a/applications/_main.c +++ b/applications/_main.c @@ -18,20 +18,23 @@ #include #include #include -struct rt_event sw_check;//软件条件 -struct rt_event hw_check;//硬件条件 +#include +static struct rt_event sw_check;//软件条件 +static struct rt_event hw_check;//硬件条件 //#define FILE_IS_OK 1 //#define TIMER_IS_OUT 1<<1 //#define TT_IS_OK 1<<2 +#define ALL_READY 1 static int maxTTWaitTime = 4; static int maxTTRetryCnt = 3; -static initEvent(void) +static void initEvent(void) { /* 事 件 控 制 块 */ - rt_err_t result = rt_event_init(&sw_check, "SHcheck", RT_IPC_FLAG_FIFO); + rt_err_t result = rt_event_init(&sw_check, "SHcheck", RT_IPC_FLAG_PRIO); + result = rt_event_init(&hw_check, "HWcheck", RT_IPC_FLAG_PRIO); if (result != RT_EOK) { LOG_E("init event failed.\n"); @@ -39,6 +42,15 @@ static initEvent(void) } INIT_COMPONENT_EXPORT(initEvent); +void upSWflag(void) +{ + rt_event_send(&sw_check, FILE_IS_OK); +} +void upTTflag(void) +{ + rt_event_send(&sw_check, TT_IS_OK); +} + /** * 更新各参数 */ @@ -47,19 +59,20 @@ static void updatecfg() maxTTWaitTime = get_cfg("maxTTWaitTime"); maxTTRetryCnt = get_cfg("maxTTRetryCnt"); } -extern struct rt_event update_cfg; -void t3(void) -{ - int32_t e; - int rst = rt_event_recv(&update_cfg, CFGCHANGEED, RT_EVENT_FLAG_OR , RT_WAITING_FOREVER, &e); - if (rst == RT_EOK) { -// update_cfg(); - LOG_I("ggxb"); - } -} +//extern struct rt_event update_cfg; +//void t3(void) +//{ +// int32_t e; +// int rst = rt_event_recv(&update_cfg, CFGCHANGEED, RT_EVENT_FLAG_OR , RT_WAITING_FOREVER, &e); +// if (rst == RT_EOK) { +//// update_cfg(); +// LOG_I("ggxb"); +// } +//} //INIT_COMPONENT_EXPORT(t3); - +extern void ttinfoInit(void); +extern void startTTinfo(void); /** * 监控TT状态。需求条件1:TT连续5个周期为激活状态且信号强度不低于5。 */ @@ -67,19 +80,24 @@ void checkTT() { static rt_thread_t thread = RT_NULL; //上电 - pwTT_thread_entry("1"); +// pwTT_thread_entry("1"); //延时30s等待系统启动、可以GET信息,避免不必要的错误 - rt_thread_mdelay(1000*30); +// rt_thread_mdelay(1000*3); - char c[3][10]={"getTT","","3"} ; - getTT(3,c); +// char c[3][10]={"getTT","10","1"} ; +//// getTT(3,c); +// getTT(1, RT_NULL); // getTTinfo_thread_entry() -#ifdef NEW_THREAD - static CFG cfg; - memset(&cfg, 0, sizeof(CFG)); +//#define NEW_THREAD - cfg.s = 3; - cfg.cnt = maxTTWaitTime/cfg.s-2;//避免通信异常 + static CFG cfg; + memset(&cfg, 0, sizeof(CFG)); +// + cfg.s = 1; + cfg.cnt = 10;//maxTTWaitTime/cfg.s-2;//避免通信异常 + extern void getTTinfo_thread_entry(void* parameter); +#define NEW_THREAD +#ifdef NEW_THREAD /* 创建 serial 线程 */ thread = rt_thread_create("getTT", getTTinfo_thread_entry, (void *) &cfg, 1024 * 3, 25, 10); /* 创建成功则启动线程 */ @@ -93,43 +111,247 @@ void checkTT() return; } #endif + + +// ttinfoInit(); +// startTTinfo(); + +// rt_thread_create("getS", startTTinfo, RT_NULL, 1024 * 3, 25, 10); + } -void try() + +static void getFileData_thread_entry(void) +{ + //等待事件 + extern struct rt_event hw_check;//硬件条件 + while(1) + { + if (rt_event_recv(&hw_check, ALL_READY, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, + RT_WAITING_FOREVER, RT_NULL) == RT_EOK) + { + +//get file to be send + char *f="2023_05_22_11_27_12_245.txt"; +// char *f="1023_05_19_15_29_59_254.txt"; +// pack file + + static rt_uint8_t d[10][200] = { }; + static rt_uint8_t s[10] = { }; + rt_uint8_t len = 0; +#define __PCK + #ifdef __PCK +// LOG_D("%p--%p",d,s); +// LOG_I("pack %s ...",f); + static MSG cfg; + rt_memset(&cfg, 0, sizeof(MSG)); // 分配空间 + + len = pack_File(f, 0, d, s); + rt_kprintf("len is %d\n", len); + if (len) + { + for (size_t var = 0; var < len; var++) { +// LOG_HEX("d",27,d[var],s[var]); +// sendMsg(d[var], s[var]); + } + sendMsgs(d, s, len); + LOG_I("Done."); + } + + +#else + rt_uint8_t *buffer = RT_NULL; + static MSG cfg; +// static rt_uint8_t len=0; + + { +// + rt_memset(&cfg, 0, sizeof(MSG)); // 分配空间 + rt_uint8_t rst = packInit(&cfg, f, 0); + if (rst != RT_EOK) + { + return 0; + } + + int fd_in = -1; //, fd_out = -1; + + static size_t file_size = 0; + // rt_uint8_t *buffer = RT_NULL; + static size_t flen = 150; // 每包数据初始长度,最大不超过 FRAME_DATA_LEN_MAX +// rt_uint8_t len = 0; + + fd_in = open(f, O_RDONLY, 0); + if (fd_in < 0) + { + LOG_E("open the input file : %s error!\n", f); + close(fd_in); + return len; + } + + file_size = lseek(fd_in, 0, SEEK_END); + LOG_I("file size is %d bytes.", file_size); + lseek(fd_in, 0, SEEK_SET); +// static rt_uint8_t *buffer = RT_NULL; + buffer = rt_malloc(file_size); + if (buffer == RT_NULL) + { + LOG_E("No memory for read %s.", f); + return 0; + } + + read(fd_in, buffer, file_size); +// LOG_HEX() + close(fd_in); + // 粗略调整每包大小 + if (file_size > (size_t)FRAME_DATA_LEN_MAX) + { + while (file_size % flen < flen / 1.2 && flen < FRAME_DATA_LEN_MAX) // 阈值约83% + { + flen += 1; + } + if (file_size % flen < flen / 1.2) + { // 到达限制仍不符合要求 + flen = 150; + while (file_size % flen < flen / 2.5 && flen < FRAME_DATA_LEN_MAX) // 调整阈值为40% + { + flen += 1; + } + } + } + else + { + flen = file_size; + } + LOG_I("flen is %d",flen); +// s[0] = packMsg(&cfg, buffer, flen, d[0]); + len = packMsgs(&cfg, buffer, file_size, flen, d, s); + if (fd_in >= 0) + { + close(fd_in); + } + + if (buffer != RT_NULL) + { + LOG_D("try to free buf."); + rt_free(buffer); + LOG_D("free buf done."); + } + } +#endif + + } + } +} + +//MSH_CMD_EXPORT(getFileData_thread_entry,tet); +static void gg(void) +{ + /* 创建 serial 线程 */ + rt_thread_t thread = rt_thread_create("PSmsg", getFileData_thread_entry, RT_NULL, 1024 * 12, 27, 10); + /* 创建成功则启动线程 */ + if (thread != RT_NULL) + { + rt_thread_startup(thread); + } + else + { + LOG_E("thread 'PSmsg' create failure."); + return; + } +} + +static void try() { static rt_err_t rst = RT_ERROR; updatecfg(); + static rt_uint8_t d[10][200] = { }; + static rt_uint8_t s[10] = { }; while(1) { - int e; +// int e; + LOG_I("等待软件就绪"); rst = rt_event_recv(&sw_check, FILE_IS_OK | TIMER_IS_OUT, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, - RT_WAITING_FOREVER, &e); + RT_WAITING_FOREVER, RT_NULL); if (rst == RT_EOK)//软件条件满足 { //检查硬件条件 + LOG_I("软件就绪,开始等待TT"); +// continue; checkTT(); //打包数据 } - for (size_t var = 0; var < maxTTRetryCnt; ++var)//轮询尝试 + for (size_t var = 0; var < maxTTRetryCnt; var++)//轮询尝试 { - rst = rt_event_recv(&sw_check, TT_IS_OK, RT_EVENT_FLAG_CLEAR, rt_tick_from_millisecond(maxTTWaitTime * 1000), - &e); + 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, + RT_NULL); if (rst == RT_EOK)//硬件条件满足 { + LOG_I("TT准备OK"); + rt_event_send(&hw_check, ALL_READY); break; } - elseif(rst == RT_ETIMEOUT);//超时则重试 + else if(rst == RT_ETIMEOUT);//超时则重试 { - pwTT_thread_entry("0"); + LOG_W("第%d次尝试中TT准备失败。",var+1); +// pwTT_thread_entry("0"); rt_thread_mdelay(1000); checkTT(); // continue; } } - +//continue; //发送数据 +//可能有多个待发文件,每个文件打包后为一个二维数组 +// 如果先打包后发送,需要三维数组,和大内存占用 +// 故改为“打包-发送”轮询操作 +//gg(); +#ifdef _NO + char *f="1023_05_19_15_29_59_254.txt"; + // pack file +// static rt_uint8_t d[10][200] = { }; +// static rt_uint8_t s[10] = { }; + rt_uint8_t len = 0; + // LOG_D("%p--%p",d,s); + // LOG_I("pack %s ...",f); + len = pack_File(f, 0, d, s); + rt_kprintf("len is %d\n", len); + if (len) + { + for (size_t var = 0; var < len; ++var) { + // LOG_HEX("d",27,d[var],s[var]); + + } + LOG_I("Done."); + } +#endif +LOG_I("----------------------------"); +//initEvent(); +// rt_thread_mdelay(100); + } } + +MSH_CMD_EXPORT(gg,file); + +void smsg() +{ + /* 创建 serial 线程 */ + rt_thread_t thread = rt_thread_create("checkSta", try, RT_NULL, 1024 * 5, 24, 10); + /* 创建成功则启动线程 */ + if (thread != RT_NULL) + { + rt_thread_startup(thread); + } + else + { + LOG_E("thread 'checkSta' create failure."); + return; + } +} +INIT_COMPONENT_EXPORT(smsg); +MSH_CMD_EXPORT(smsg,smsg); diff --git a/applications/cfg.c b/applications/cfg.c index 06b6e47..e351435 100644 --- a/applications/cfg.c +++ b/applications/cfg.c @@ -25,7 +25,7 @@ void iniEvent(void) { /* 事 件 控 制 块 */ - rt_err_t result = rt_event_init(&update_cfg, "update_cfg", RT_IPC_FLAG_FIFO); + rt_err_t result = rt_event_init(&update_cfg, "cfg", RT_IPC_FLAG_FIFO); if (result != RT_EOK) { LOG_E("init event failed.\n"); @@ -33,7 +33,7 @@ void iniEvent(void) } } /* 导出到自动初始化 */ -INIT_COMPONENT_EXPORT(iniEvent); +//INIT_COMPONENT_EXPORT(iniEvent); /** * 设置config项 @@ -54,7 +54,7 @@ int set_cfg(const char *k, const char*v) //以下消息队列通知各线程更新参数 // CFG_MSG msg; - rt_err_t result; +// rt_err_t result; rt_event_send(&update_cfg, CFGCHANGEED|COMPRESSTYPE); diff --git a/applications/cfg.h b/applications/cfg.h index b43f0b3..e5d7d41 100644 --- a/applications/cfg.h +++ b/applications/cfg.h @@ -9,12 +9,13 @@ */ #include -/* 串口接收消息结构*/ -typedef struct -{ - char key[10]; - char value[10]; -} CFG_MSG; + + +//typedef struct +//{ +// char key[10]; +// char value[10]; +//} CFG_MSG; #define CFGCHANGEED 1 #define SENDINTERVAL 1<<1 diff --git a/applications/comp.c b/applications/comp.c index 4a9d61a..fd31a2d 100644 --- a/applications/comp.c +++ b/applications/comp.c @@ -161,7 +161,7 @@ _exit: return ret; } - +#ifdef USE_D static int compress_file(int fd_in, int *fout) { @@ -301,7 +301,7 @@ _exit: return ret; } - +#endif void comp_file_test(int argc, char **argv) { diff --git a/applications/demo.c b/applications/demo.c index 245f6eb..10e3d2c 100644 --- a/applications/demo.c +++ b/applications/demo.c @@ -13,50 +13,50 @@ #include #include #include -#include +#include -void getcfg(void) -{ -// extern struct rt_messagequeue update_cfg; - extern struct rt_event update_cfg; - CFG_MSG msg; - pwTT_thread_entry("1"); - while (1) - { - - -// rt_memset(&msg, 0, sizeof(msg)); -// /* 从消息队列中读取消息*/ -// rt_err_t result = rt_mq_recv(&update_cfg, &msg, sizeof(msg), RT_WAITING_NO); +//void getcfg(void) +//{ +//// extern struct rt_messagequeue update_cfg; +// extern struct rt_event update_cfg; +// CFG_MSG msg; +// pwTT_thread_entry("1"); +// while (1) +// { +// +// +//// rt_memset(&msg, 0, sizeof(msg)); +//// /* 从消息队列中读取消息*/ +//// rt_err_t result = rt_mq_recv(&update_cfg, &msg, sizeof(msg), RT_WAITING_NO); +//// if (result == RT_EOK) +//// { +//// LOG_I("updatecfg:%10s -->%s", msg.key, msg.value); +//// } +// rt_uint32_t e; +// rt_err_t result = rt_event_recv(&update_cfg, CFGCHANGEED|COMPRESSTYPE, RT_EVENT_FLAG_OR|RT_EVENT_FLAG_CLEAR, RT_WAITING_NO, &e); // if (result == RT_EOK) +// { +// LOG_I("updatecfg"); +// } +// rt_thread_delay(100); +// } +//} +//void mpcfg() +//{ +///* 创建线程 */ +// rt_thread_t thread = rt_thread_create("getcfg", getcfg, RT_NULL, 1024 * 2, 20, 10); +// /* 创建成功则启动线程 */ +// if (thread != RT_NULL) // { -// LOG_I("updatecfg:%10s -->%s", msg.key, msg.value); +// rt_thread_startup(thread); +// // rt_kprintf("done"); // } - rt_uint32_t e; - rt_err_t result = rt_event_recv(&update_cfg, CFGCHANGEED|COMPRESSTYPE, RT_EVENT_FLAG_OR|RT_EVENT_FLAG_CLEAR, RT_WAITING_NO, &e); - if (result == RT_EOK) - { - LOG_I("updatecfg"); - } - rt_thread_delay(100); - } -} -void mpcfg() -{ -/* 创建线程 */ - rt_thread_t thread = rt_thread_create("getcfg", getcfg, RT_NULL, 1024 * 2, 20, 10); - /* 创建成功则启动线程 */ - if (thread != RT_NULL) - { - rt_thread_startup(thread); - // rt_kprintf("done"); - } - else - { - LOG_E("thread 'pmsg' create failure."); - return RT_ERROR; - } -} +// else +// { +// LOG_E("thread 'pmsg' create failure."); +// return RT_ERROR; +// } +//} /* 导出到自动初始化 */ //INIT_COMPONENT_EXPORT(mpcfg); -MSH_CMD_EXPORT(mpcfg, 线程消息接收测试); +//MSH_CMD_EXPORT(mpcfg, 线程消息接收测试); diff --git a/applications/getinfo.c b/applications/getinfo.c index b975e44..63fa1dc 100644 --- a/applications/getinfo.c +++ b/applications/getinfo.c @@ -12,7 +12,7 @@ //#define HTTP_GET_URL "http://www.rt-thread.com/service/rt-thread.txt" #ifndef TT_IP -#define TT_IP "http://192.168.0.232:4005" +#define TT_IP "http://10.10.10.72:4005" #endif #define TT_SIM TT_IP "/action/webGetSIMState"//SIM #define TT_XH TT_IP "/action/webGetTDSignal"//信号值 @@ -29,28 +29,37 @@ //#include char *infoH[] = { TT_SIM, TT_XH, TT_RW, TT_JH, TT_DW}; -typedef struct -{ - rt_uint8_t cnt; - rt_uint8_t s; -} CFG; +//typedef struct +//{ +// rt_uint8_t cnt; +// rt_uint8_t s; +//} CFG; typedef struct { char sim[MAX_LEN]; // SIM - rt_uint8_t xh; // 信号值 - rt_uint8_t rw; // 入网 - rt_uint8_t jh; // 激活 - char *jd; // 经度 - char *wd; // 纬度 - char *ele; // 高度 -} TT; + char xh[MAX_LEN]; // SIM + char rw[MAX_LEN]; // SIM + char jh[MAX_LEN]; // SIM + char jd[MAX_LEN]; // SIM + char wd[MAX_LEN]; // SIM + char ele[MAX_LEN]; // SIM +// rt_uint8_t sim; // SIM +// rt_uint8_t xh; // 信号值 +// rt_uint8_t rw; // 入网 +// rt_uint8_t jh; // 激活 +// char *jd; // 经度 +// char *wd; // 纬度 +// char *ele; // 高度 +}TT; -static TT tmp; -static TT *TTinfo=&tmp; +TT tmp={.sim="0",.xh="0",.jh="0",.jd=":0.000000",.wd=":0.000000",.ele=":0.000000"}; +//memset(&tmp,0x00,sizeof(TT)); +TT *TTinfo=&tmp; static rt_tick_t bootstamp=0; -//rt_memset(&tmp,0,sizeof(TT)); +//rt_memset(TTinfo,0,sizeof(TT)); +//TT *TTinfo=RT_NULL; //TTinfo = rt_malloc(sizeof(TT)); /** * @description: 将TT结构体转换为数组 @@ -95,7 +104,8 @@ static int minTTPeriCnt=5; static int minTTsinal=5; static int minActiveTime=0; static int maxActiveTime=0; -extern struct rt_event sw_check;//软件条件 +//extern struct rt_event sw_check;//软件条件 +extern void upTTflag(void); static void updatecfg() { minTTsinal = get_cfg("minTTsinal"); @@ -110,12 +120,15 @@ void initcfg() bootstamp = rt_tick_get_millisecond(); } -void updateSta() +/** + * 更新统计信息 + */ +static void updateSta() { uint16_t v = (rt_tick_get_millisecond()-bootstamp)/1000;//转换为秒 - LOG_D("耗时%dS.",v); + LOG_I("耗时%dS.",v); if ((minActiveTime ==0) | (minActiveTime > v)) { - minTTsinal = v; + minActiveTime = v; set_val("minActiveTime", v); } if (v>maxActiveTime) { @@ -127,27 +140,40 @@ void updateSta() /** * 按规则检查TT状态 */ -void rulecheck(void) +static void rulecheck(void) { //默认为 TT连续5个周期为激活状态且信号强度不低于5。 //满足加1,不满足清零 - static int okCnt=0; - LOG_I("当前规则为:连续%d个采集周期TT信号质量不低于%d",minTTPeriCnt,minTTsinal); - if (atoi(TTinfo->jh) & !(atoi(TTinfo->xh) < minTTsinal) ) {// + static rt_uint16_t okCnt=0; + if (!okCnt) { + LOG_I("当前规则为:连续%d个采集周期TT信号质量不低于%d",minTTPeriCnt,minTTsinal); + } + + if (atoi(TTinfo->sim) & !(atoi(TTinfo->xh) < minTTsinal) ) {// okCnt += 1; LOG_D("第%d次符合规则。",okCnt); } else { okCnt = 0; - LOG_D("不符合。"); + LOG_W("不符合。"); return; } - if (okCnt > minTTPeriCnt -1) { + if (okCnt >= minTTPeriCnt) { //TT具备发送条件 - rt_event_send(&sw_check, TT_IS_OK); +// rt_event_send(&sw_check, TT_IS_OK); + upTTflag(); LOG_D("符合规则,TT具备发送状态。"); - updateSta(); +// updateSta(); + okCnt = minTTPeriCnt -1; } +// if (okCnt > minTTPeriCnt) { +// //TT具备发送条件 +//// rt_event_send(&sw_check, TT_IS_OK); +// upTTflag(); +// okCnt = 2; +// LOG_I("符合规则,TT具备发送状态。"); +//// updateSta(); +// } } @@ -168,9 +194,9 @@ static void tt_parse(rt_uint8_t *data) item = cJSON_GetObjectItem(object, "tdsignal"); if (item) { - TTinfo->xh = atoi(item->valuestring); +// TTinfo->xh = atoi(item->valuestring); // tmp.xh = item->valuestring; -// strcpy(TTinfo->xh,item->valuestring); + strcpy(TTinfo->xh,item->valuestring); // rt_kprintf("\nxh:%s ", item->valuestring); // rt_kprintf("\nxh:%s ", TTinfo->xh); cJSON_Delete(root); @@ -180,8 +206,9 @@ static void tt_parse(rt_uint8_t *data) item = cJSON_GetObjectItem(object, "tdnetregstate"); if (item) { - TTinfo->rw = atoi(item->valuestring); +// TTinfo->rw = atoi(item->valuestring); // rt_kprintf("\nrw:%s ", TTinfo.rw); + strcpy(TTinfo->rw,item->valuestring); cJSON_Delete(root); return RT_EOK; } @@ -189,8 +216,9 @@ static void tt_parse(rt_uint8_t *data) item = cJSON_GetObjectItem(object, "tdpsstate"); if (item) { - TTinfo->jh = atoi(item->valuestring); +// TTinfo->jh = atoi(item->valuestring); // rt_kprintf("\njh:%s ", TTinfo.jh); + strcpy(TTinfo->jh,item->valuestring); cJSON_Delete(root); return RT_EOK; } @@ -198,13 +226,16 @@ static void tt_parse(rt_uint8_t *data) item = cJSON_GetObjectItem(object, "latitude"); if (item) { - TTinfo->wd = item->valuestring; +// TTinfo->wd = item->valuestring; + strcpy(TTinfo->wd,item->valuestring); item = cJSON_GetObjectItem(object, "longitude"); - TTinfo->jd = item->valuestring; +// TTinfo->jd = item->valuestring; + strcpy(TTinfo->jd,item->valuestring); item = cJSON_GetObjectItem(object, "elevation"); - TTinfo->ele = item->valuestring; +// TTinfo->ele = item->valuestring; + strcpy(TTinfo->ele,item->valuestring); // rt_kprintf("%5s%5s%5s%5s%15s%15s%10s\n", TTinfo->sim, TTinfo->xh, TTinfo->rw, // TTinfo->jh, TTinfo->jd, TTinfo->wd,TTinfo->ele); @@ -283,7 +314,7 @@ void getTTinfo_thread_entry(void* parameter) rt_thread_mdelay(100); } rulecheck(); - rt_kprintf("%5s%5d%5d%5d%15s%15s%10s\n", TTinfo->sim, TTinfo->xh, TTinfo->rw, TTinfo->jh, TTinfo->jd, + rt_kprintf("%5s%5s%5s%5s%15s%15s%10s\n", TTinfo->sim, TTinfo->xh, TTinfo->rw, TTinfo->jh, TTinfo->jd, TTinfo->wd, TTinfo->ele); if (i != cfg->cnt - 1) //最后一次采集不延时 { @@ -331,6 +362,11 @@ void getTT(int argc, char **argv) return RT_ERROR; } +// struct rt_thread infoTT_thread; +// ALIGN(RT_ALIGN_SIZE) +// static char thread2_stack[1024*3]; +// rt_thread_init(&infoTT_thread, "getTT", getTTinfo_thread_entry, (void *) &cfg, &thread2_stack[0], sizeof(thread2_stack), 25, 10); +// rt_thread_startup(&infoTT_thread); } /* 导出到自动初始化 */ diff --git a/applications/main.c b/applications/main.c index cca3d79..ad815f6 100644 --- a/applications/main.c +++ b/applications/main.c @@ -15,18 +15,19 @@ #include #include #include -#include -/// -static rt_uint8_t d[35][200] = { }; -static rt_uint8_t s[35] = { }; +//#include + + +//static rt_uint8_t d[35][200] = { }; +//static rt_uint8_t s[35] = { }; void pfdemo(void) { // #define cmb_println(...) rt_kprintf(__VA_ARGS__);rt_kprintf("\r\n"); // char *f = "1023_05_19_15_29_59_254.txt"; // char *f = "2023_05_19_15_29_59_255.txt"; char *f = "2023_05_22_11_27_12_245.txt"; -// rt_uint8_t d[10][200] = { }; -// rt_uint8_t s[10] = { }; + static rt_uint8_t d[10][200] = { }; + static rt_uint8_t s[10] = { }; rt_uint8_t len = 0; LOG_D("%p--%p",d,s); LOG_I("pack %s ...",f); @@ -55,13 +56,13 @@ int main(void) // #define LED_HEART GET_PIN(E,3) /* 设置PIN脚模式为输出 */ rt_pin_mode(LED_HEART, PIN_MODE_OUTPUT); -// rt_pin_mode(LED_HEART_DEBUG, PIN_MODE_OUTPUT); + rt_pin_mode(LED_HEART_DEBUG, PIN_MODE_OUTPUT); rt_pin_mode(ETH_RESET_PIN, PIN_MODE_OUTPUT); rt_pin_mode(TT_EN, PIN_MODE_OUTPUT); // rt_pin_write(ETH_RESET_PIN, PIN_LOW);//关闭ETH - + rt_pin_write(TT_EN, PIN_HIGH);//关闭TT // rt_err_t ret = RT_EOK; /* 设 置 日 期 */ // ret = set_date(2018, 12, 3); @@ -84,14 +85,14 @@ int main(void) { /* 拉低PIN脚 */ rt_pin_write(LED_HEART, PIN_LOW); -// rt_pin_write(LED_HEART_DEBUG, PIN_LOW); + rt_pin_write(LED_HEART_DEBUG, PIN_HIGH); /* 延时1ms,省电 */ rt_thread_mdelay(10); //去掉延时,共用print替换 // rt_kprintf("Heartbeat.\n"); /* 拉高PIN脚 */ rt_pin_write(LED_HEART, PIN_HIGH); -// rt_pin_write(LED_HEART_DEBUG, PIN_HIGH); + rt_pin_write(LED_HEART_DEBUG, PIN_LOW); rt_thread_mdelay(1000); diff --git a/applications/tcpdemo.c b/applications/tcpdemo.c index 4208362..e1febe1 100644 --- a/applications/tcpdemo.c +++ b/applications/tcpdemo.c @@ -33,7 +33,7 @@ #define BUFSZ 1024 -static const char send_data[] = "This is TCP Client from RT-Thread."; /* 发送用到的数据 */ +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."; /* 发送用到的数据 */ void tcpclient(int argc, char **argv) { int ret; @@ -47,7 +47,7 @@ void tcpclient(int argc, char **argv) if (argc < 3) { rt_kprintf("Usage: tcpclient URL PORT\n"); - rt_kprintf("Like: tcpclient 192.168.12.44 5000\n"); + rt_kprintf("Like: tcpclient 10.10.10.72 8005\n"); return ; } @@ -136,6 +136,12 @@ void tcpclient(int argc, char **argv) { /* 在控制终端显示收到的数据 */ rt_kprintf("\nReceived data = %s ", recv_data); + closesocket(sock); +// rt_kprintf("\n got a 'q' or 'Q',close the socket.\r\n"); + + /* 释放接收缓冲 */ + rt_free(recv_data); + break; } /* 发送数据到sock连接 */ diff --git a/applications/tools.c b/applications/tools.c new file mode 100644 index 0000000..edcd7b4 --- /dev/null +++ b/applications/tools.c @@ -0,0 +1,73 @@ + + +#include +#define LOG_TAG "tool" +#define LOG_LVL LOG_LVL_DBG +#include +//#include +#include +#include + + +/** + * 以HEX显示文件内容 + */ +void hex() +{ + +} + +/** + * 更新全局参数 + */ +void updatecfg(void) +{ +//因为不知原因,采用事件集独立更新配置出错 +//独立响应单个参数更新事件,程序上更复杂也没特别必要 +//现采用事件通知、统一全部重新加载 + + + +} + +void sDemo() +{ +// extern struct rt_event sw_check;//软件条件 +// rt_event_send(&sw_check, FILE_IS_OK); + void upSWflag(void); + upSWflag(); +} + +MSH_CMD_EXPORT(sDemo,swTest); + +static struct rt_thread infoTT_thread; +void ttinfoInit() +{ + static CFG cfg; + memset(&cfg, 0, sizeof(CFG)); + + cfg.s = 1; + cfg.cnt = 10; //避免通信异常 + extern void getTTinfo_thread_entry(void* parameter); +// extern void getTTinfo_thread_entry(void* parameter); +// struct rt_thread infoTT_thread; + ALIGN(RT_ALIGN_SIZE) + static char thread2_stack[1024 * 3]; + rt_thread_init(&infoTT_thread, "getTT", getTTinfo_thread_entry, (void *) &cfg, &thread2_stack[0], + sizeof(thread2_stack), 25, 10); +// rt_thread_startup(&infoTT_thread); +} + +void startTTinfo(void) +{ + if (&infoTT_thread == RT_NULL) { + //to Init + } + if ((infoTT_thread.stat & RT_THREAD_STAT_MASK) == RT_THREAD_INIT) { + + } + rt_thread_startup(&infoTT_thread); +} +//MSH_CMD_EXPORT(ttinfoInit,init ttinfo); +//INIT_COMPONENT_EXPORT(ttinfoInit); + diff --git a/applications/ttTR.c b/applications/ttTR.c index 23a314e..259e2a9 100644 --- a/applications/ttTR.c +++ b/applications/ttTR.c @@ -15,12 +15,12 @@ #include #define LOG_TAG "ttTR" -#define LOG_LVL LOG_LVL_INFO +#define LOG_LVL LOG_LVL_DBG #include #define BUFSZ 1024 #define RETRYCNT 10 -#define URL "http://192.168.0.232" +#define URL "http://10.10.10.72" #define PORT 8005 int sock=0; diff --git a/applications/ttmsg/ttmsg.c b/applications/ttmsg/ttmsg.c index ee2d21e..cd923a6 100644 --- a/applications/ttmsg/ttmsg.c +++ b/applications/ttmsg/ttmsg.c @@ -290,76 +290,78 @@ LOG_HEX("buf",16,buf,100); */ rt_uint8_t pack_File(const char *fin, rt_uint8_t flag, const rt_uint8_t (*dout)[200], rt_uint8_t *arrLen) { - static MSG cfg; - rt_memset(&cfg, 0, sizeof(MSG)); // 分配空间 - rt_uint8_t rst = packInit(&cfg, fin, flag); - if (rst != RT_EOK) - { - return 0; - } - - int fd_in = -1; //, fd_out = -1; - - static size_t file_size = 0; -// rt_uint8_t *buffer = RT_NULL; - size_t flen = 150; // 每包数据初始长度,最大不超过 FRAME_DATA_LEN_MAX - rt_uint8_t len = 0; - - fd_in = open(fin, O_RDONLY, 0); - if (fd_in < 0) - { - LOG_E("open the input file : %s error!\n", fin); - close(fd_in); - return len; - } - - file_size = lseek(fd_in, 0, SEEK_END); - LOG_I("file size is %d bytes.",file_size); - lseek(fd_in, 0, SEEK_SET); - rt_uint8_t *buffer=RT_NULL ; - buffer = rt_malloc(file_size); - if (buffer == RT_NULL) { - LOG_E("No memory for read %s.",fin); - return 0; - } - - read(fd_in, buffer, file_size); - close(fd_in); - // 粗略调整每包大小 - if (file_size > FRAME_DATA_LEN_MAX) { - while (file_size % flen < flen / 1.2 && flen < FRAME_DATA_LEN_MAX) // 阈值约83% - { - flen += 1; - } - if (file_size % flen < flen / 1.2) - { // 到达限制仍不符合要求 - flen = 150; - while (file_size % flen < flen / 2.5 && flen < FRAME_DATA_LEN_MAX) // 调整阈值为40% + extern MSG cfg; +// rt_memset(&cfg, 0, sizeof(MSG)); // 分配空间 + rt_uint8_t rst = packInit(&cfg, fin, flag); + if (rst != RT_EOK) { - flen += 1; + return 0; } - } - } - else { - flen = file_size; - } - LOG_I("len of data per pack is %d Bytes.",flen); - LOG_I("cnt of packages is %d",(file_size / flen) + (file_size % flen > 0 ? 1 : 0)); - len = packMsgs(&cfg, buffer, file_size, flen, dout, arrLen); + int fd_in = -1; //, fd_out = -1; - if (fd_in >= 0) - { - close(fd_in); - } + static size_t file_size = 0; + rt_uint8_t len=0; + // rt_uint8_t *buffer = RT_NULL; + static size_t flen = 150; // 每包数据初始长度,最大不超过 FRAME_DATA_LEN_MAX + // rt_uint8_t len = 0; - if (buffer!=RT_NULL) - { - LOG_D("try to free buf."); - rt_free(buffer); - LOG_D("free buf done."); - } -// LOG_D("%p--%p",dout,arrLen); + fd_in = open(fin, O_RDONLY, 0); + if (fd_in < 0) + { + LOG_E("open the input file : %s error!\n", fin); + close(fd_in); + return len; + } + + file_size = lseek(fd_in, 0, SEEK_END); + LOG_I("file size is %d bytes.", file_size); + lseek(fd_in, 0, SEEK_SET); + rt_uint8_t *buffer = RT_NULL; + buffer = rt_malloc(file_size); + if (buffer == RT_NULL) + { + LOG_E("No memory for read %s.", fin); + return 0; + } + + read(fd_in, buffer, file_size); + // LOG_HEX() + close(fd_in); + // 粗略调整每包大小 + if (file_size > (size_t)FRAME_DATA_LEN_MAX) + { + while (file_size % flen < flen / 1.2 && flen < FRAME_DATA_LEN_MAX) // 阈值约83% + { + flen += 1; + } + if (file_size % flen < flen / 1.2) + { // 到达限制仍不符合要求 + flen = 150; + while (file_size % flen < flen / 2.5 && flen < FRAME_DATA_LEN_MAX) // 调整阈值为40% + { + flen += 1; + } + } + } + else + { + flen = file_size; + } + LOG_I("flen is %d",flen); + // s[0] = packMsg(&cfg, buffer, flen, d[0]); + len = packMsgs(&cfg, buffer, file_size, flen, dout, arrLen); + if (fd_in >= 0) + { + close(fd_in); + } + + if (buffer != RT_NULL) + { + LOG_D("try to free buf."); + rt_free(buffer); + LOG_D("free buf done."); + } return len; @@ -509,20 +511,24 @@ MSH_CMD_EXPORT(pmsg, 打包文件。); void pwTT_thread_entry(void *parameter) { // LOG_I("--%s--",parameter); - if (parameter == NULL) + if (strcmp(parameter,"NULL")==0) { +// LOG_I("null"); int f = rt_pin_read(TT_EN); rt_pin_write(TT_EN, !f); } else { - rt_bool_t flag = (rt_bool_t) parameter; + rt_bool_t flag = (rt_bool_t) atoi(parameter); +// LOG_I("flag is %d",flag); rt_pin_write(TT_EN, flag); } if (rt_pin_read(TT_EN)) { +//#ifdef NO_RELAY LOG_I("set TT %s", "ON"); +//#endif add_val("swCnt");//更新统计值 } else @@ -534,14 +540,17 @@ void pwTT_thread_entry(void *parameter) static int swTT(int argc, char **argv) { - int f = NULL;//不带参数时argv[1]为NULL - if (argc == 2) + static char s[5]="NULL"; + if (argc >= 2) { - f = atoi(argv[1]); + rt_strcpy(s,argv[1]); + } + else { + rt_strcpy(s,"NULL"); } /* 创建线程 */ - rt_thread_t thread = rt_thread_create("sw_TT", pwTT_thread_entry, (void *) f, 1024 * 2, 25, 10); + rt_thread_t thread = rt_thread_create("sw_TT", pwTT_thread_entry, (void *) s, 1024 * 2, 25, 10); /* 创建成功则启动线程 */ if (thread != RT_NULL) { diff --git a/applications/uart_dma_sample.c b/applications/uart_dma_sample.c index 4553998..e63135c 100644 --- a/applications/uart_dma_sample.c +++ b/applications/uart_dma_sample.c @@ -17,13 +17,17 @@ #include #include -#include +#include #define LOG_TAG "uart" #define LOG_LVL LOG_LVL_DBG #include +#ifdef WORK_BOARD +#define SAMPLE_UART_NAME "uart1" /* 串口设备名称 */ +#else #define SAMPLE_UART_NAME "uart3" /* 串口设备名称 */ +#endif #define MAX_SIZE_TO_SAVE 1024*2 /* 串口接收消息结构*/ struct rx_msg @@ -61,22 +65,19 @@ static void serial_thread_entry(void *parameter) rt_err_t result; rt_uint32_t rx_length; static char rx_buffer[RT_SERIAL_RB_BUFSZ + 1]; -// extern struct rt_messagequeue update_cfg; - extern struct rt_event update_cfg; -// CFG_MSG cfg; while (1) { // rt_memset(&cfg, 0, sizeof(cfg)); rt_memset(&msg, 0, sizeof(msg)); /* 从消息队列中读取消息*/ - rt_uint32_t e; - rt_err_t result = rt_event_recv(&update_cfg, CFGCHANGEED|MAXSIZEPERFILE, RT_EVENT_FLAG_OR|RT_EVENT_FLAG_CLEAR, RT_WAITING_NO, &e); - if (result == RT_EOK) - { - LOG_I("updatecfg"); - } - result = rt_mq_recv(&rx_mq, &msg, sizeof(msg), RT_WAITING_NO); +// rt_uint32_t e; +// rt_err_t result = rt_event_recv(&update_cfg, CFGCHANGEED|MAXSIZEPERFILE, RT_EVENT_FLAG_OR|RT_EVENT_FLAG_CLEAR, RT_WAITING_NO, &e); +// if (result == RT_EOK) +// { +// LOG_I("updatecfg"); +// } + result = rt_mq_recv(&rx_mq, &msg, sizeof(msg), RT_WAITING_FOREVER); if (result == RT_EOK) { /* 从串口读取数据*/ diff --git a/applications/usrcfg.h b/applications/usrcfg.h index 1b280e7..13d2080 100644 --- a/applications/usrcfg.h +++ b/applications/usrcfg.h @@ -10,10 +10,25 @@ #ifndef APPLICATIONS_USRCFG_H_ #define APPLICATIONS_USRCFG_H_ +#include "cfg.h" #define WORK_BOARD #define FILE_IS_OK 1 #define TIMER_IS_OUT 1<<1 #define TT_IS_OK 1<<2 + +typedef struct +{ + rt_uint8_t cnt; + rt_uint8_t s; +} CFG; + + +//struct rt_event sw_check;//软件条件 + + + + + #endif /* APPLICATIONS_USRCFG_H_ */ diff --git a/rtconfig.h b/rtconfig.h index 3f086b0..929bcf0 100644 --- a/rtconfig.h +++ b/rtconfig.h @@ -49,7 +49,7 @@ #define RT_USING_DEVICE #define RT_USING_CONSOLE #define RT_CONSOLEBUF_SIZE 256 -#define RT_CONSOLE_DEVICE_NAME "uart1" +#define RT_CONSOLE_DEVICE_NAME "uart3" /* end of Kernel Device Object */ #define RT_VER_NUM 0x40101 /* end of RT-Thread Kernel */ @@ -68,8 +68,8 @@ #define RT_USING_FINSH #define FINSH_USING_MSH #define FINSH_THREAD_NAME "tshell" -#define FINSH_THREAD_PRIORITY 20 -#define FINSH_THREAD_STACK_SIZE 4096 +#define FINSH_THREAD_PRIORITY 30 +#define FINSH_THREAD_STACK_SIZE 4096*2 #define FINSH_USING_HISTORY #define FINSH_HISTORY_LINES 5 #define FINSH_USING_SYMTAB @@ -155,8 +155,8 @@ /* Static IPv4 Address */ -#define RT_LWIP_IPADDR "192.168.0.30" -#define RT_LWIP_GWADDR "192.168.0.1" +#define RT_LWIP_IPADDR "10.10.10.10" +#define RT_LWIP_GWADDR "10.10.10.1" #define RT_LWIP_MSKADDR "255.255.255.0" /* end of Static IPv4 Address */ #define RT_LWIP_UDP @@ -269,12 +269,12 @@ /* tools packages */ -#define PKG_USING_CMBACKTRACE -#define PKG_CMBACKTRACE_PLATFORM_M4 -#define PKG_CMBACKTRACE_DUMP_STACK -#define PKG_CMBACKTRACE_PRINT_CHINESE_UTF8 -#define PKG_USING_CMBACKTRACE_V10401 -#define PKG_CMBACKTRACE_VER_NUM 0x10401 +//#define PKG_USING_CMBACKTRACE +//#define PKG_CMBACKTRACE_PLATFORM_M4 +//#define PKG_CMBACKTRACE_DUMP_STACK +//#define PKG_CMBACKTRACE_PRINT_CHINESE_UTF8 +//#define PKG_USING_CMBACKTRACE_V10401 +//#define PKG_CMBACKTRACE_VER_NUM 0x10401 /* end of tools packages */ /* system packages */