2023-06-01 09:10:00 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*
|
|
|
|
|
* Change Logs:
|
|
|
|
|
* Date Author Notes
|
|
|
|
|
* 2023-06-01 murmur the first version
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
|
|
|
|
|
|
|
|
|
#define LOG_TAG "main_scha"
|
|
|
|
|
#define LOG_LVL LOG_LVL_DBG
|
|
|
|
|
#include <ulog.h>
|
|
|
|
|
#include <board.h>
|
|
|
|
|
#include <ttmsg/ttmsg.h>
|
|
|
|
|
#include <cfg.h>
|
2023-06-02 02:23:26 +00:00
|
|
|
|
#include <usrcfg.h>
|
2023-06-01 09:10:00 +00:00
|
|
|
|
struct rt_event sw_check;//软件条件
|
|
|
|
|
struct rt_event hw_check;//硬件条件
|
2023-06-02 02:23:26 +00:00
|
|
|
|
//#define FILE_IS_OK 1
|
|
|
|
|
//#define TIMER_IS_OUT 1<<1
|
|
|
|
|
//#define TT_IS_OK 1<<2
|
2023-06-01 09:10:00 +00:00
|
|
|
|
|
2023-06-02 02:23:26 +00:00
|
|
|
|
static int maxTTWaitTime = 4;
|
|
|
|
|
static int maxTTRetryCnt = 3;
|
2023-06-01 09:10:00 +00:00
|
|
|
|
|
2023-06-02 06:37:58 +00:00
|
|
|
|
static initEvent(void)
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
|
|
|
|
/* 事 件 控 制 块 */
|
|
|
|
|
|
|
|
|
|
rt_err_t result = rt_event_init(&sw_check, "SHcheck", RT_IPC_FLAG_FIFO);
|
|
|
|
|
if (result != RT_EOK)
|
|
|
|
|
{
|
|
|
|
|
LOG_E("init event failed.\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-02 06:37:58 +00:00
|
|
|
|
INIT_COMPONENT_EXPORT(initEvent);
|
2023-06-01 09:10:00 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新各参数
|
|
|
|
|
*/
|
|
|
|
|
static void updatecfg()
|
|
|
|
|
{
|
2023-06-02 02:23:26 +00:00
|
|
|
|
maxTTWaitTime = get_cfg("maxTTWaitTime");
|
|
|
|
|
maxTTRetryCnt = get_cfg("maxTTRetryCnt");
|
2023-06-01 09:10:00 +00:00
|
|
|
|
}
|
2023-06-02 06:37:58 +00:00
|
|
|
|
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);
|
2023-06-01 09:10:00 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 监控TT状态。需求条件1:TT连续5个周期为激活状态且信号强度不低于5。
|
|
|
|
|
*/
|
|
|
|
|
void checkTT()
|
|
|
|
|
{
|
2023-06-02 02:23:26 +00:00
|
|
|
|
static rt_thread_t thread = RT_NULL;
|
2023-06-01 09:10:00 +00:00
|
|
|
|
//上电
|
|
|
|
|
pwTT_thread_entry("1");
|
2023-06-02 02:23:26 +00:00
|
|
|
|
//延时30s等待系统启动、可以GET信息,避免不必要的错误
|
|
|
|
|
rt_thread_mdelay(1000*30);
|
|
|
|
|
|
|
|
|
|
char c[3][10]={"getTT","","3"} ;
|
|
|
|
|
getTT(3,c);
|
2023-06-01 09:10:00 +00:00
|
|
|
|
// getTTinfo_thread_entry()
|
2023-06-02 02:23:26 +00:00
|
|
|
|
#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
|
2023-06-01 09:10:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void try()
|
|
|
|
|
{
|
|
|
|
|
static rt_err_t rst = RT_ERROR;
|
|
|
|
|
updatecfg();
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
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);
|
2023-06-02 02:23:26 +00:00
|
|
|
|
if (rst == RT_EOK)//软件条件满足
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
2023-06-02 02:23:26 +00:00
|
|
|
|
//检查硬件条件
|
|
|
|
|
checkTT();
|
|
|
|
|
//打包数据
|
|
|
|
|
|
2023-06-01 09:10:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-02 02:23:26 +00:00
|
|
|
|
for (size_t var = 0; var < maxTTRetryCnt; ++var)//轮询尝试
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
2023-06-02 02:23:26 +00:00
|
|
|
|
rst = rt_event_recv(&sw_check, TT_IS_OK, RT_EVENT_FLAG_CLEAR, rt_tick_from_millisecond(maxTTWaitTime * 1000),
|
2023-06-01 09:10:00 +00:00
|
|
|
|
&e);
|
2023-06-02 02:23:26 +00:00
|
|
|
|
if (rst == RT_EOK)//硬件条件满足
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-06-02 02:23:26 +00:00
|
|
|
|
elseif(rst == RT_ETIMEOUT);//超时则重试
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
2023-06-02 02:23:26 +00:00
|
|
|
|
pwTT_thread_entry("0");
|
|
|
|
|
rt_thread_mdelay(1000);
|
|
|
|
|
checkTT();
|
|
|
|
|
// continue;
|
2023-06-01 09:10:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-02 02:23:26 +00:00
|
|
|
|
//发送数据
|
|
|
|
|
|
2023-06-01 09:10:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|