添加demo板兼容逻辑

添加规则处理函数(未测试)
添加总usrcfg.h文件
This commit is contained in:
murmur 2023-06-02 10:23:26 +08:00
parent 9b76e1fbe8
commit e35670b6a9
10 changed files with 161 additions and 42 deletions

View File

@ -17,15 +17,15 @@
#include <board.h>
#include <ttmsg/ttmsg.h>
#include <cfg.h>
#include <usrcfg.h>
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;
}
}
//发送数据
}
}

View File

@ -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))
{

View File

@ -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);

View File

@ -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)
{

View File

@ -23,7 +23,7 @@
#define MAX_LEN 15
#include <cJSON.h>
#include <finsh.h>
#include <usrcfg.h>
//#include <stdio.h>
//#include <stdlib.h> //用于strtod函数
//#include <string.h>
@ -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) //最后一次采集不延时

View File

@ -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, );

View File

@ -40,7 +40,7 @@
*/
#include <rtthread.h>
#include <ttmsg/ttmsg.h>
/* 定时器的控制块 */
@ -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");
}

17
applications/usrcfg.h Normal file
View File

@ -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_ */

View File

@ -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)

View File

@ -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