diff --git a/applications/_main.c b/applications/_main.c index 3b52a45..47d5541 100644 --- a/applications/_main.c +++ b/applications/_main.c @@ -17,15 +17,15 @@ #include #include #include - +#include struct rt_event sw_check;//软件条件 struct rt_event hw_check;//硬件条件 -#define FILE_IS_OK 1 -#define TIMER_IS_OUT 1<<1 -#define TT_IS_OK 1<<2 +//#define FILE_IS_OK 1 +//#define TIMER_IS_OUT 1<<1 +//#define TT_IS_OK 1<<2 -static maxWaitTime = 4; -static maxRetryCnt = 3; +static int maxTTWaitTime = 4; +static int maxTTRetryCnt = 3; static init() { @@ -43,8 +43,8 @@ static init() */ static void updatecfg() { - maxWaitTime = get_cfg("maxWaitTime"); - maxRetryCnt = get_cfg("maxRetryCnt"); + maxTTWaitTime = get_cfg("maxTTWaitTime"); + maxTTRetryCnt = get_cfg("maxTTRetryCnt"); } /** @@ -52,11 +52,34 @@ static void updatecfg() */ void checkTT() { + static rt_thread_t thread = RT_NULL; //上电 pwTT_thread_entry("1"); -// rt_thread_create(name, entry, parameter, stack_size, priority, tick) - getTT(); + //延时30s等待系统启动、可以GET信息,避免不必要的错误 + rt_thread_mdelay(1000*30); + + char c[3][10]={"getTT","","3"} ; + getTT(3,c); // getTTinfo_thread_entry() +#ifdef NEW_THREAD + static CFG cfg; + memset(&cfg, 0, sizeof(CFG)); + + cfg.s = 3; + cfg.cnt = maxTTWaitTime/cfg.s-2;//避免通信异常 + /* 创建 serial 线程 */ + thread = rt_thread_create("getTT", getTTinfo_thread_entry, (void *) &cfg, 1024 * 3, 25, 10); + /* 创建成功则启动线程 */ + if (thread != RT_NULL) + { + rt_thread_startup(thread); + } + else + { + LOG_E("thread 'getTT' create failure."); + return; + } +#endif } void try() @@ -68,31 +91,32 @@ void try() int e; rst = rt_event_recv(&sw_check, FILE_IS_OK | TIMER_IS_OUT, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &e); - if (rst == RT_EOK) + if (rst == RT_EOK)//软件条件满足 { - //上电 - pwTT_thread_entry("1"); + //检查硬件条件 + checkTT(); + //打包数据 + } - for (size_t var = 0; var < maxRetryCnt; ++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(maxWaitTime * 1000), + rst = rt_event_recv(&sw_check, TT_IS_OK, RT_EVENT_FLAG_CLEAR, rt_tick_from_millisecond(maxTTWaitTime * 1000), &e); - if (rst == RT_ETIMEOUT) - { - pwTT_thread_entry("0"); - rt_thread_mdelay(1000); - pwTT_thread_entry("1"); - } - else if (rst == RT_EOK) + if (rst == RT_EOK)//硬件条件满足 { break; } - else + elseif(rst == RT_ETIMEOUT);//超时则重试 { - LOG_E("Unknown error."); + pwTT_thread_entry("0"); + rt_thread_mdelay(1000); + checkTT(); +// continue; } } + //发送数据 + } } diff --git a/applications/cfg.c b/applications/cfg.c index 7a33750..3d80fa5 100644 --- a/applications/cfg.c +++ b/applications/cfg.c @@ -132,7 +132,7 @@ MSH_CMD_EXPORT(cfg, config params. 配置系统参数,支持参数) * @param k * return 成功返回值,错误返回RT_ERROR */ -static long get_val(const char *k) +long get_val(const char *k) { long v= ini_getl("stats", k, -1, LJW_CFG_FILE_NAME); if( v == -1) @@ -145,7 +145,7 @@ static long get_val(const char *k) } } -static int set_val(const char *k, long v) +int set_val(const char *k, long v) { if(!ini_putl("stats",k,v,LJW_CFG_FILE_NAME)) { diff --git a/applications/cfg.h b/applications/cfg.h index b13ade7..b43f0b3 100644 --- a/applications/cfg.h +++ b/applications/cfg.h @@ -31,6 +31,8 @@ typedef struct int get_cfg(const char *k); int set_cfg(const char *k, const char*v); int add_val(const char *k); +long get_val(const char *k); +int set_val(const char *k, long v); int setFileToSend(const char *f, int v); int getFilesToSend(char (*kstr)[MAX_KEY_LEN], int *v); diff --git a/applications/demo.c b/applications/demo.c index b528cc0..245f6eb 100644 --- a/applications/demo.c +++ b/applications/demo.c @@ -20,6 +20,7 @@ void getcfg(void) // extern struct rt_messagequeue update_cfg; extern struct rt_event update_cfg; CFG_MSG msg; + pwTT_thread_entry("1"); while (1) { @@ -43,7 +44,7 @@ void getcfg(void) void mpcfg() { /* 创建线程 */ - rt_thread_t thread = rt_thread_create("getcfg", getcfg, RT_NULL, 1024 * 1, 20, 10); + rt_thread_t thread = rt_thread_create("getcfg", getcfg, RT_NULL, 1024 * 2, 20, 10); /* 创建成功则启动线程 */ if (thread != RT_NULL) { diff --git a/applications/getinfo.c b/applications/getinfo.c index 8d84ae4..b975e44 100644 --- a/applications/getinfo.c +++ b/applications/getinfo.c @@ -23,7 +23,7 @@ #define MAX_LEN 15 #include #include - +#include //#include //#include //用于strtod函数 //#include @@ -48,6 +48,7 @@ typedef struct static TT tmp; static TT *TTinfo=&tmp; +static rt_tick_t bootstamp=0; //rt_memset(&tmp,0,sizeof(TT)); //TTinfo = rt_malloc(sizeof(TT)); @@ -89,10 +90,67 @@ rt_uint8_t info2HEX(TT *TTinfo, rt_uint8_t *buffer) } -//TT TTinfo; -//TTinfo = (TT*)malloc(sizeof(TT)); -//TTinfo = &tmp; +static int minTTPeriCnt=5; +static int minTTsinal=5; +static int minActiveTime=0; +static int maxActiveTime=0; +extern struct rt_event sw_check;//软件条件 +static void updatecfg() +{ + minTTsinal = get_cfg("minTTsinal"); + minTTPeriCnt = get_cfg("minTTPeriCnt"); + minActiveTime = get_val("minActiveTime"); + maxActiveTime = get_val("maxActiveTime"); + LOG_D("加载参数完成"); +} +void initcfg() +{ + updatecfg(); + bootstamp = rt_tick_get_millisecond(); +} + +void updateSta() +{ + uint16_t v = (rt_tick_get_millisecond()-bootstamp)/1000;//转换为秒 + LOG_D("耗时%dS.",v); + if ((minActiveTime ==0) | (minActiveTime > v)) { + minTTsinal = v; + set_val("minActiveTime", v); + } + if (v>maxActiveTime) { + maxActiveTime=v; + set_val("maxActiveTime", v); + } +} + +/** + * 按规则检查TT状态 + */ +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) ) {// + okCnt += 1; + LOG_D("第%d次符合规则。",okCnt); + } + else { + okCnt = 0; + LOG_D("不符合。"); + return; + } + if (okCnt > minTTPeriCnt -1) { + //TT具备发送条件 + rt_event_send(&sw_check, TT_IS_OK); + LOG_D("符合规则,TT具备发送状态。"); + updateSta(); + } + + +} /* 数据解析 */ static void tt_parse(rt_uint8_t *data) { @@ -196,6 +254,7 @@ static int webclient_get_data(const char *url) void getTTinfo_thread_entry(void* parameter) { +// bootstamp = rt_tick_get(); CFG* cfg = RT_NULL; cfg = (CFG*) parameter; @@ -223,6 +282,7 @@ void getTTinfo_thread_entry(void* parameter) web_free(url); 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, TTinfo->wd, TTinfo->ele); if (i != cfg->cnt - 1) //最后一次采集不延时 diff --git a/applications/main.c b/applications/main.c index f3a28a3..d28ca7c 100644 --- a/applications/main.c +++ b/applications/main.c @@ -132,4 +132,4 @@ void pp(int argc, char **argv) MSH_CMD_EXPORT(pp, 打包文件。); extern int rt_hw_stm32_eth_init(void); -//MSH_CMD_EXPORT(rt_hw_stm32_eth_init, 初始化网络。); +MSH_CMD_EXPORT(rt_hw_stm32_eth_init, 初始化网络。); diff --git a/applications/timer.c b/applications/timer.c index d0fa3de..c7270a7 100644 --- a/applications/timer.c +++ b/applications/timer.c @@ -40,7 +40,7 @@ */ #include - +#include /* 定时器的控制块 */ @@ -72,6 +72,7 @@ static void timeout1(void *parameter) rt_timer_stop(timer1); rt_kprintf("periodic timer was stopped! \n"); +// pwTT_thread_entry("0"); } @@ -84,7 +85,7 @@ static void timeout1(void *parameter) static void timeout2(void *parameter) { - +// pwTT_thread_entry("1"); rt_kprintf("one shot timer is timeout\n"); } diff --git a/applications/usrcfg.h b/applications/usrcfg.h new file mode 100644 index 0000000..89533f6 --- /dev/null +++ b/applications/usrcfg.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2023-06-02 murmur the first version + */ +#ifndef APPLICATIONS_USRCFG_H_ +#define APPLICATIONS_USRCFG_H_ + +#define FILE_IS_OK 1 +#define TIMER_IS_OUT 1<<1 +#define TT_IS_OK 1<<2 + +#endif /* APPLICATIONS_USRCFG_H_ */ diff --git a/drivers/board.h b/drivers/board.h index 57ff4cf..3c5bd84 100644 --- a/drivers/board.h +++ b/drivers/board.h @@ -66,7 +66,7 @@ extern "C" * such as #define BSP_UART1_RX_USING_DMA * */ - +#ifdef WORK_BOARD #define BSP_USING_UART1 #define BSP_UART1_TX_PIN "PB6" #define BSP_UART1_RX_PIN "PB7" @@ -76,7 +76,17 @@ extern "C" #define BSP_UART3_TX_PIN "PB10" #define BSP_UART3_RX_PIN "PB11" #define BSP_UART3_RX_USING_DMA +#else +#define BSP_USING_UART1 +#define BSP_UART1_TX_PIN "PA9" +#define BSP_UART1_RX_PIN "PA10" +#define BSP_UART1_RX_USING_DMA +#define BSP_USING_UART3 +#define BSP_UART3_TX_PIN "PB10" +#define BSP_UART3_RX_PIN "PB11" +#define BSP_UART3_RX_USING_DMA +#endif /*-------------------------- UART CONFIG END --------------------------*/ @@ -370,12 +380,16 @@ extern "C" /*#define BSP_USING_ON_CHIP_FLASH*/ - -#define LED_HEART GET_PIN(E,3) -#define LED_HEART_DEBUG GET_PIN(B,3) -#define TT_EN GET_PIN(B,0) -#ifndef ETH_RESET_PIN -#define ETH_RESET_PIN GET_PIN(A, 4)//E-7 +#ifdef WORK_BOARD + #define LED_HEART GET_PIN(E,3) + #define LED_HEART_DEBUG GET_PIN(B,3) + #define TT_EN GET_PIN(B,0) + #define ETH_RESET_PIN GET_PIN(A, 4)//E-7 +#else + #define LED_HEART GET_PIN(E,3) +// #define LED_HEART_DEBUG GET_PIN(B,3) + #define TT_EN GET_PIN(B,0) + #define ETH_RESET_PIN GET_PIN(E, 7) #endif ////#define RESET_LB GET_PIN(E, 1) ////#define RESET_UB GET_PIN(E, 0) diff --git a/rtconfig.h b/rtconfig.h index 4470269..a4b4e94 100644 --- a/rtconfig.h +++ b/rtconfig.h @@ -370,7 +370,7 @@ /* end of RT-Thread online packages */ /* samples: kernel and components samples */ - +#define WORK_BOARD /* end of samples: kernel and components samples */ #define RT_STUDIO_BUILT_IN