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
|
2023-07-28 08:29:57 +00:00
|
|
|
|
* 处理TT相关的初始化、状态切换等逻辑
|
2023-06-01 09:10:00 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
|
|
|
|
|
2023-08-08 06:31:16 +00:00
|
|
|
|
#define LOG_TAG "core"
|
2023-06-01 09:10:00 +00:00
|
|
|
|
#define LOG_LVL LOG_LVL_DBG
|
|
|
|
|
#include <ulog.h>
|
|
|
|
|
#include <board.h>
|
|
|
|
|
#include <ttmsg/ttmsg.h>
|
2023-06-20 10:09:07 +00:00
|
|
|
|
//#include <cfg.h>
|
2023-06-02 02:23:26 +00:00
|
|
|
|
#include <usrcfg.h>
|
2023-08-31 09:14:48 +00:00
|
|
|
|
#include <ttTR/ttTR.h>
|
2023-07-28 08:29:57 +00:00
|
|
|
|
|
2023-08-01 08:27:21 +00:00
|
|
|
|
//static struct rt_event sw_check; //软件条件
|
|
|
|
|
static struct rt_event chkSta; //发送条件,含两部分,1-超时或文件准备好,2-TT满足通信条件
|
2023-06-20 10:09:07 +00:00
|
|
|
|
|
2023-07-28 08:29:57 +00:00
|
|
|
|
|
2023-06-06 07:45:13 +00:00
|
|
|
|
#define ALL_READY 1
|
2023-06-01 09:10:00 +00:00
|
|
|
|
|
2023-08-04 10:13:59 +00:00
|
|
|
|
//static int maxTTWaitTime = 4;
|
|
|
|
|
//static int maxTTRetryCnt = 3;
|
2023-06-01 09:10:00 +00:00
|
|
|
|
|
2023-07-28 08:29:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rt_sem_t TTReady= RT_NULL;//天通具备发送状态后 rt_sem_release(TTReady);
|
2023-08-29 11:29:58 +00:00
|
|
|
|
rt_sem_t cfgUpdate = RT_NULL;//配置文件更新
|
|
|
|
|
rt_sem_t shuntDownTT = RT_NULL;//关闭TT
|
2023-09-14 09:30:01 +00:00
|
|
|
|
rt_sem_t okTosend = RT_NULL;//可以发送后续文件。仅一个线程,文件依次发送
|
2023-08-29 11:29:58 +00:00
|
|
|
|
rt_sem_t okToreport = RT_NULL;//配置信息ACK
|
2023-08-08 08:38:50 +00:00
|
|
|
|
static rt_thread_t initThread=RT_NULL;
|
|
|
|
|
static rt_thread_t deinitThread=RT_NULL;
|
2023-08-30 10:00:42 +00:00
|
|
|
|
static rt_timer_t tmrToPNTT=RT_NULL;
|
2023-09-10 03:35:17 +00:00
|
|
|
|
static uint8_t isWindowMode=0;//RTC引起TT开机
|
|
|
|
|
static uint8_t isFileMode=0;//file is ok
|
2024-01-07 12:21:31 +00:00
|
|
|
|
|
|
|
|
|
//是否为idle状态。idle状态下TT未开启,232无数据
|
|
|
|
|
uint8_t isIdle(void)
|
|
|
|
|
{
|
|
|
|
|
if (!isTCPok() && !isEthUP() &&!isFileMode && !isWindowMode && !isManualWindow() && !is232Busy()) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-15 01:45:50 +00:00
|
|
|
|
uint8_t isInFileMode(void)
|
|
|
|
|
{
|
|
|
|
|
return isFileMode;
|
|
|
|
|
}
|
2023-07-28 08:29:57 +00:00
|
|
|
|
|
|
|
|
|
SYS_CFG scfg={
|
|
|
|
|
.sendInterval =60,
|
|
|
|
|
.maxTTWaitTime = 4,
|
|
|
|
|
.maxTTRetryCnt = 3,
|
|
|
|
|
.minTTPeriCnt=5,
|
|
|
|
|
.minTTsinal=5,
|
2023-07-29 08:08:15 +00:00
|
|
|
|
.timeout=5,
|
2023-08-08 06:31:16 +00:00
|
|
|
|
.maxSizePerFile=1024,
|
|
|
|
|
// .openWindowTime[]={0x02, 0x0F, 0x03, 0x1E, 0x08, 0x0F, 0x09, 0x1E}
|
2023-07-28 08:29:57 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2023-09-02 08:39:08 +00:00
|
|
|
|
* 初始化必要的文件
|
2023-07-28 08:29:57 +00:00
|
|
|
|
*/
|
2023-09-02 08:39:08 +00:00
|
|
|
|
void initFiles()
|
2023-07-28 08:29:57 +00:00
|
|
|
|
{
|
2023-08-27 04:31:54 +00:00
|
|
|
|
|
|
|
|
|
//无配置文件则新建
|
2023-09-02 08:39:08 +00:00
|
|
|
|
if (!getFileSize("cfg.ini"))
|
2023-08-27 04:31:54 +00:00
|
|
|
|
{
|
2023-09-02 08:39:08 +00:00
|
|
|
|
//copy backup
|
|
|
|
|
if (getFileSize("sd/cfg.ini")) {
|
|
|
|
|
copy("sd/cfg.ini","cfg.ini");
|
|
|
|
|
LOG_I("copied new cfg file.");
|
2023-08-27 04:31:54 +00:00
|
|
|
|
}
|
2023-09-02 08:39:08 +00:00
|
|
|
|
//creat new
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const char *cfgstr =
|
|
|
|
|
"[config]\n"
|
2023-09-14 11:55:33 +00:00
|
|
|
|
"# V1.9\n"
|
2023-09-02 08:39:08 +00:00
|
|
|
|
"#定时(默认每小时)上报时刻,\n"
|
|
|
|
|
"sendInterval=15\n"
|
|
|
|
|
"# 最大文件大小,超过此大小则进入发送流程\n"
|
|
|
|
|
"maxSizePerFile=1024 \n"
|
|
|
|
|
"# 最小等待时间(S),超时后进入待机模式(暂未使用)\n"
|
|
|
|
|
"minSecToSleep=30 \n"
|
|
|
|
|
|
|
|
|
|
"# TT最长等待激活时间(M),超时后重启\n"
|
|
|
|
|
"maxTTWaitTime=10\n"
|
|
|
|
|
"# TT最大重试次数\n"
|
|
|
|
|
"maxTTRetryCnt=3\n"
|
|
|
|
|
"# TT最低信号值\n"
|
|
|
|
|
"minTTsinal=3\n"
|
|
|
|
|
"# TT状态检测周期数,连续满足归为一次判决,减少波动的影响\n"
|
|
|
|
|
"minTTPeriCnt=3\n"
|
|
|
|
|
|
|
|
|
|
"# 压缩方式,0-不压缩\n"
|
|
|
|
|
"compressType=0\n"
|
|
|
|
|
"# 加密方式,0-不加密\n"
|
|
|
|
|
"encrytType=1\n"
|
|
|
|
|
"# 开窗时间(UTC+8),持续时间(H)。以【,】为分隔符\n"
|
2023-09-14 11:55:33 +00:00
|
|
|
|
"openWindowTime=02,00,03,30,08,00,09,00\n"
|
2023-09-02 08:39:08 +00:00
|
|
|
|
"#超时时间(M),主动开机上报数据情况下最后一次通信后开始计时,超时后关闭TT\n"
|
2023-09-14 11:55:33 +00:00
|
|
|
|
"timeout=10\n"
|
2023-09-02 08:39:08 +00:00
|
|
|
|
"# 工作模式,1-TT,2-BD\n"
|
|
|
|
|
"commMode=1\n"
|
|
|
|
|
"# 自毁功能开关,1-开启,0-跟关闭\n"
|
|
|
|
|
"selfDesSW=0\n"
|
|
|
|
|
"# 位置告警功能开关,1-开启,0-关闭\n"
|
2023-09-14 11:55:33 +00:00
|
|
|
|
"locAlert=0;\n"
|
2023-09-02 08:39:08 +00:00
|
|
|
|
"# 定时上报位置信息间隔(M)\n"
|
2023-09-14 11:55:33 +00:00
|
|
|
|
"locRepInterval=5\n"
|
2023-09-03 11:45:08 +00:00
|
|
|
|
"isMaWin=-1\n"
|
2023-09-02 08:39:08 +00:00
|
|
|
|
"[stats]\n"
|
|
|
|
|
"# 继电器开关次数,影响继电器寿命(<10W次)\n"
|
|
|
|
|
"swCnt=12\n"
|
|
|
|
|
"# 第一次上电就满足硬件条件的次数,\n"
|
|
|
|
|
"oneShotCnt=0\n"
|
|
|
|
|
"# 重启次数\n"
|
|
|
|
|
"bootCnt=13\n"
|
|
|
|
|
"# 发送总次数,由软件条件触发\n"
|
|
|
|
|
"sendCnt=0\n"
|
|
|
|
|
"# TT初始化失败次数,由MaxRetryCnt次失败后触发\n"
|
|
|
|
|
"errCnt=0\n"
|
|
|
|
|
"# 最短激活时间\n"
|
|
|
|
|
"minActiveTime=0\n"
|
|
|
|
|
"# 最长激活时间\n"
|
|
|
|
|
"maxActiveTime=0\n"
|
|
|
|
|
"# 平均激活时间,暂不考虑实现\n"
|
|
|
|
|
"meanActiveTime=0\n"
|
|
|
|
|
|
|
|
|
|
"# 总定时器超时次数\n"
|
|
|
|
|
"allCnt=0\n"
|
|
|
|
|
"# 发送成功次数\n"
|
|
|
|
|
"okCnt=0\n";
|
|
|
|
|
LOG_W("no cfg file found, creat one.");
|
|
|
|
|
int fd = open(LJW_CFG_FILE_NAME, O_WRONLY | O_CREAT);
|
|
|
|
|
if (fd > 0) {
|
|
|
|
|
write(fd, cfgstr, strlen(cfgstr));
|
|
|
|
|
close(fd);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LOG_E("failed to creat cfg file.");
|
|
|
|
|
}
|
2023-08-27 04:31:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-02 08:39:08 +00:00
|
|
|
|
|
|
|
|
|
//map file
|
|
|
|
|
if (!getFileSize("map.geojson")) {
|
|
|
|
|
if (getFileSize("sd/map.geojson")) {
|
|
|
|
|
copy("sd/map.geojson","map.geojson");
|
|
|
|
|
LOG_I("copied new map file.");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
const char *cfgstr =
|
|
|
|
|
"{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{},\"geometry\":{\"coordinates\":[[[109.85768145990244,18.422149049902515],[109.85578152088834,18.418353201926465],[109.86089674131063,18.41424527209267],[109.86531775324693,18.418387867583846],[109.86491584307038,18.421785068111333],[109.85768145990244,18.422149049902515]]],\"type\":\"Polygon\"}}]}";
|
|
|
|
|
LOG_W("no map file found, creat map one.");
|
2023-09-10 10:22:08 +00:00
|
|
|
|
int fd = open("map.geojson", O_WRONLY | O_CREAT);
|
2023-09-02 08:39:08 +00:00
|
|
|
|
if (fd > 0) {
|
|
|
|
|
write(fd, cfgstr, strlen(cfgstr));
|
|
|
|
|
close(fd);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LOG_E("failed to creat map file.");
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-29 11:29:58 +00:00
|
|
|
|
}
|
2023-09-04 09:45:03 +00:00
|
|
|
|
|
2023-09-06 01:51:08 +00:00
|
|
|
|
// checkFlash();
|
2023-09-02 08:39:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新全局参数
|
|
|
|
|
*/
|
|
|
|
|
static void initCfg(void)
|
|
|
|
|
{
|
|
|
|
|
initFiles();
|
2023-08-27 04:31:54 +00:00
|
|
|
|
|
|
|
|
|
scfg.maxTTWaitTime = get_cfg("maxTTWaitTime");
|
|
|
|
|
scfg.maxTTRetryCnt = get_cfg("maxTTRetryCnt");
|
|
|
|
|
scfg.minTTPeriCnt = get_cfg("minTTPeriCnt");
|
|
|
|
|
scfg.minTTsinal = get_cfg("minTTsinal");
|
|
|
|
|
scfg.timeout = get_cfg("timeout");
|
|
|
|
|
scfg.maxSizePerFile = get_cfg("maxSizePerFile");
|
|
|
|
|
scfg.locRepInterval = get_cfg("locRepInterval");
|
2023-09-06 01:51:08 +00:00
|
|
|
|
scfg.isMaWin = get_cfg("isMaWin");
|
2023-09-11 10:36:42 +00:00
|
|
|
|
scfg.locAlert = get_cfg("locAlert");
|
2023-08-27 04:31:54 +00:00
|
|
|
|
|
2023-09-06 01:51:08 +00:00
|
|
|
|
char str[sizeof(scfg.openWindowTime)*4];
|
2023-08-27 04:31:54 +00:00
|
|
|
|
get_cfgs("openWindowTime", str);
|
|
|
|
|
size_t len = str2Byte(str, 3, 10, scfg.openWindowTime);
|
2023-09-03 11:45:08 +00:00
|
|
|
|
// LOG_HEX("win",16,scfg.openWindowTime,len);
|
2023-08-27 04:31:54 +00:00
|
|
|
|
updateAlarm(scfg.openWindowTime, len);
|
2023-09-15 08:36:52 +00:00
|
|
|
|
startAlarm();
|
2023-08-27 04:31:54 +00:00
|
|
|
|
|
|
|
|
|
LOG_D("cfg updated.");
|
2023-08-29 11:29:58 +00:00
|
|
|
|
}
|
|
|
|
|
static void updatecfg(void)
|
|
|
|
|
{
|
2023-08-27 04:31:54 +00:00
|
|
|
|
//等待更新
|
2023-07-28 08:29:57 +00:00
|
|
|
|
while(1)
|
|
|
|
|
{
|
2023-09-06 01:51:08 +00:00
|
|
|
|
// rt_thread_mdelay(10*1000);//10s写入一次数据到文件
|
|
|
|
|
if(rt_sem_take(cfgUpdate, RT_WAITING_FOREVER) == RT_EOK)
|
2023-07-28 08:29:57 +00:00
|
|
|
|
{
|
2023-08-30 02:45:32 +00:00
|
|
|
|
updateAllSysCfg(&scfg, 0);
|
2023-07-28 08:29:57 +00:00
|
|
|
|
}
|
2023-08-29 11:29:58 +00:00
|
|
|
|
|
2023-07-28 08:29:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void sysSemInit()
|
|
|
|
|
{
|
2023-09-14 09:30:01 +00:00
|
|
|
|
okTosend = rt_sem_create("okTosend", 0, RT_IPC_FLAG_FIFO);//同一时间仅一个线程发送文件
|
2023-08-29 11:29:58 +00:00
|
|
|
|
cfgUpdate = rt_sem_create("cfgUpdate", 0, RT_IPC_FLAG_FIFO);//更新cfg
|
2023-08-30 02:45:32 +00:00
|
|
|
|
shuntDownTT = rt_sem_create("shuntDNTT", 0, RT_IPC_FLAG_FIFO);//关闭TT
|
2023-08-29 11:29:58 +00:00
|
|
|
|
okToreport = rt_sem_create("reportINFO", 0, RT_IPC_FLAG_FIFO);//关闭TT
|
2023-08-30 02:45:32 +00:00
|
|
|
|
// rt_event_init(&chkSta, "chkSta", RT_IPC_FLAG_FIFO);//检查天通状态
|
2023-08-27 04:31:54 +00:00
|
|
|
|
// rt_sem_release(cfgUpdate); //上电更新值
|
2023-08-08 06:31:16 +00:00
|
|
|
|
|
2023-09-05 10:53:01 +00:00
|
|
|
|
// initCfgMutex();
|
2023-08-29 11:29:58 +00:00
|
|
|
|
// void reportINFO();
|
|
|
|
|
reportINFO();
|
2023-08-08 06:31:16 +00:00
|
|
|
|
/* 创建 serial 线程 */
|
2023-08-30 02:45:32 +00:00
|
|
|
|
rt_thread_t thread = rt_thread_create("updatecfg", updatecfg, RT_NULL, 1024 * 5, 27+1, 10);
|
2023-08-29 11:29:58 +00:00
|
|
|
|
/* 创建成功则启动线程 */
|
|
|
|
|
if (thread != RT_NULL)
|
|
|
|
|
{
|
|
|
|
|
rt_thread_startup(thread);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG_E("thread 'updatecfg' create failure.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-08-08 06:31:16 +00:00
|
|
|
|
|
2023-07-28 08:29:57 +00:00
|
|
|
|
// LOG_D("sysSemInit DONE.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-04 06:09:39 +00:00
|
|
|
|
void sysEventInit(void)
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
2023-08-01 08:27:21 +00:00
|
|
|
|
rt_err_t result = rt_event_init(&chkSta, "chkSta", RT_IPC_FLAG_PRIO);
|
2023-06-16 03:18:52 +00:00
|
|
|
|
|
2023-06-01 09:10:00 +00:00
|
|
|
|
if (result != RT_EOK)
|
|
|
|
|
{
|
|
|
|
|
LOG_E("init event failed.\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-01 08:27:21 +00:00
|
|
|
|
void sysInit(void)
|
|
|
|
|
{
|
|
|
|
|
sysSemInit();
|
2023-09-02 11:33:16 +00:00
|
|
|
|
initCfg();
|
2023-09-05 10:53:01 +00:00
|
|
|
|
checkManualWindow();
|
2023-09-15 09:25:52 +00:00
|
|
|
|
if (isManualWindow()) {//手动开窗优先级最高
|
2023-08-29 11:29:58 +00:00
|
|
|
|
initTT();
|
2023-09-15 09:25:52 +00:00
|
|
|
|
}
|
|
|
|
|
else if (isInWindowZone()) {//开机检查是否在开窗区间内,是则给TT开机
|
2023-08-29 11:29:58 +00:00
|
|
|
|
setWindowMode();
|
2023-09-15 09:25:52 +00:00
|
|
|
|
initTT();
|
2023-08-29 11:29:58 +00:00
|
|
|
|
}
|
2023-09-10 02:09:28 +00:00
|
|
|
|
else if (isNeedRestore()) {//Restoring configuration after a crash
|
|
|
|
|
initTT();
|
|
|
|
|
}
|
2023-09-14 11:55:33 +00:00
|
|
|
|
if (getCntOfFileToSend()) {
|
|
|
|
|
LOG_I("cached file(s) to send");
|
|
|
|
|
fileIsReady();
|
|
|
|
|
}
|
2023-09-05 10:53:01 +00:00
|
|
|
|
|
2023-08-01 08:27:21 +00:00
|
|
|
|
}
|
|
|
|
|
//INIT_COMPONENT_EXPORT(sysInit);
|
|
|
|
|
|
|
|
|
|
void timerIsReady(void)
|
|
|
|
|
{
|
2023-08-04 06:09:39 +00:00
|
|
|
|
rt_event_send(&chkSta, TIMER_IS_OUT);
|
2023-09-03 08:54:23 +00:00
|
|
|
|
stopTM();//停止而不是重置,避免超时时间小于未激活重试时间的情况下意外关机。
|
2023-08-01 08:27:21 +00:00
|
|
|
|
}
|
|
|
|
|
void fileIsReady(void)
|
2023-06-06 07:45:13 +00:00
|
|
|
|
{
|
2023-08-04 06:09:39 +00:00
|
|
|
|
rt_event_send(&chkSta, FILE_IS_OK);
|
|
|
|
|
stopTM();
|
2023-06-06 07:45:13 +00:00
|
|
|
|
}
|
2023-09-14 11:55:33 +00:00
|
|
|
|
static int isTTok=0;
|
2023-08-01 08:27:21 +00:00
|
|
|
|
void TTIsReady(void)
|
2023-06-06 07:45:13 +00:00
|
|
|
|
{
|
2023-09-14 09:30:01 +00:00
|
|
|
|
isTTok=1;
|
2023-09-14 11:55:33 +00:00
|
|
|
|
// rt_event_send(&chkSta, TT_IS_OK);
|
|
|
|
|
// rt_sem_release(TTReady);
|
2023-08-31 08:12:44 +00:00
|
|
|
|
// resetTM();
|
2023-06-06 07:45:13 +00:00
|
|
|
|
}
|
2023-09-14 09:30:01 +00:00
|
|
|
|
void TTIsNotReady(void)
|
|
|
|
|
{
|
|
|
|
|
isTTok=0;
|
|
|
|
|
// rt_event_send(&chkSta, TT_IS_OK);
|
|
|
|
|
// resetTM();
|
|
|
|
|
}
|
2023-08-30 10:00:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 关闭超时定时器,定时时间到后关闭TT
|
|
|
|
|
*/
|
2023-08-31 08:12:44 +00:00
|
|
|
|
void stopTM(void)
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
2023-08-30 10:00:42 +00:00
|
|
|
|
if (!tmrToPNTT) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
rt_timer_stop(tmrToPNTT);
|
|
|
|
|
rt_timer_stop(tmrToPNTT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新开窗flag以关闭超时机制
|
|
|
|
|
*/
|
|
|
|
|
void setWindowMode(void)
|
|
|
|
|
{
|
|
|
|
|
isWindowMode = 1;
|
|
|
|
|
stopTM();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 恢复超时机制
|
|
|
|
|
*/
|
|
|
|
|
void clearWindowMode(void)
|
|
|
|
|
{
|
|
|
|
|
isWindowMode = 0;
|
|
|
|
|
stopTM();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 重启超时定时器,定时时间到后关闭TT
|
|
|
|
|
* 逻辑是非开窗(包括自动、手动)状态下TT无接收数据则启动关机倒计时
|
|
|
|
|
*/
|
2023-08-31 08:12:44 +00:00
|
|
|
|
void d_remain(void);
|
|
|
|
|
void resetTM(void)
|
2023-08-30 10:00:42 +00:00
|
|
|
|
{
|
|
|
|
|
// LOG_D("try to reset");
|
|
|
|
|
if (tmrToPNTT == RT_NULL) {
|
2023-08-31 08:12:44 +00:00
|
|
|
|
LOG_E("tmrToPNTT is NULL");
|
2023-08-30 10:00:42 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-09-05 10:53:01 +00:00
|
|
|
|
if (isManualWindow()) {
|
2023-09-15 08:36:52 +00:00
|
|
|
|
stopAlarm();
|
2023-09-05 10:53:01 +00:00
|
|
|
|
stopTM();
|
|
|
|
|
LOG_W("TIMEOUT stopped.[isManualMode]");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-09-15 08:36:52 +00:00
|
|
|
|
if (isWindowMode) {
|
|
|
|
|
stopTM();
|
|
|
|
|
LOG_W("TIMEOUT stopped.[isWindowMode]");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-09-10 03:35:17 +00:00
|
|
|
|
if (isFileMode) {
|
|
|
|
|
stopTM();
|
|
|
|
|
LOG_W("TIMEOUT stopped.[isFileMode]");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-08-30 10:00:42 +00:00
|
|
|
|
|
|
|
|
|
rt_tick_t t= rt_tick_from_millisecond(scfg.timeout*60*1000);
|
|
|
|
|
rt_timer_control(tmrToPNTT, RT_TIMER_CTRL_SET_TIME,(void*) &t);
|
2023-08-31 08:12:44 +00:00
|
|
|
|
// rt_timer_stop(tmrToPNTT);
|
2023-08-30 10:00:42 +00:00
|
|
|
|
int i=0;
|
|
|
|
|
while(rt_timer_start(tmrToPNTT) != RT_EOK)
|
|
|
|
|
{
|
|
|
|
|
if (i++ > 10) {
|
|
|
|
|
LOG_E("TIMEOUT fault.");
|
2023-08-31 08:12:44 +00:00
|
|
|
|
return;
|
2023-08-30 10:00:42 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2023-08-31 08:12:44 +00:00
|
|
|
|
rt_thread_mdelay(200);
|
2023-08-30 10:00:42 +00:00
|
|
|
|
}
|
2023-08-31 08:12:44 +00:00
|
|
|
|
LOG_W("%d minutes from now to power down TT.",scfg.timeout);
|
|
|
|
|
|
|
|
|
|
// d_remain();
|
|
|
|
|
// rt_thread_mdelay(500);
|
|
|
|
|
// d_remain();
|
|
|
|
|
// rt_thread_mdelay(500);
|
|
|
|
|
// d_remain();
|
|
|
|
|
// rt_thread_mdelay(500);
|
|
|
|
|
// d_remain();
|
2023-08-30 10:00:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-31 08:12:44 +00:00
|
|
|
|
void d_remain(void)
|
2023-08-30 10:00:42 +00:00
|
|
|
|
{
|
|
|
|
|
if (tmrToPNTT == RT_NULL) {
|
2023-08-31 08:12:44 +00:00
|
|
|
|
LOG_W("tmrToPNTT is NULL");
|
2023-08-30 10:00:42 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rt_tick_t arg1,arg2;
|
|
|
|
|
rt_timer_control(tmrToPNTT, RT_TIMER_CTRL_GET_TIME, (void*)&arg1);
|
|
|
|
|
rt_timer_control(tmrToPNTT, RT_TIMER_CTRL_GET_REMAIN_TIME, (void*)&arg2);
|
2023-08-31 08:12:44 +00:00
|
|
|
|
|
2023-08-30 10:00:42 +00:00
|
|
|
|
rt_uint32_t arg3=0;
|
|
|
|
|
rt_timer_control(tmrToPNTT, RT_TIMER_CTRL_GET_STATE, (void*)&arg3);
|
|
|
|
|
LOG_D("%s",arg3?"YES":"NO");
|
2023-08-31 08:12:44 +00:00
|
|
|
|
if (arg3) {
|
|
|
|
|
int tmp=(arg2-rt_tick_get())/1000;
|
|
|
|
|
LOG_D("t=%ld,0x%X -> 0x%X",tmp,rt_tick_get(),arg2);
|
|
|
|
|
LOG_D("%dm%ds / %d min",tmp/60,tmp%60,arg1/60000);
|
|
|
|
|
}
|
2023-08-30 10:00:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 定时器超时函数 */
|
|
|
|
|
static void timeoutFunc(void *parameter)
|
|
|
|
|
{
|
2023-08-31 08:12:44 +00:00
|
|
|
|
stopTM();
|
2023-09-02 07:23:32 +00:00
|
|
|
|
if (deinitThread) {
|
2023-08-31 08:12:44 +00:00
|
|
|
|
LOG_W("timeout leads to shunt down TT");
|
2023-08-30 10:00:42 +00:00
|
|
|
|
// rt_thread_mdelay(3000);// no delay
|
2023-08-31 08:12:44 +00:00
|
|
|
|
deInitTT();//Function[rt_mutex_take] shall not be used in ISR
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-01 09:10:00 +00:00
|
|
|
|
}
|
2023-06-02 06:37:58 +00:00
|
|
|
|
|
2023-07-28 08:29:57 +00:00
|
|
|
|
|
|
|
|
|
//extern void ttinfoInit(void);
|
|
|
|
|
//extern void startTTinfo(void);
|
2023-06-01 09:10:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* 监控TT状态。需求条件1:TT连续5个周期为激活状态且信号强度不低于5。
|
|
|
|
|
*/
|
|
|
|
|
void checkTT()
|
|
|
|
|
{
|
2023-06-20 10:09:07 +00:00
|
|
|
|
repGetTT(); //持续更新
|
2023-06-06 07:45:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-01 08:27:21 +00:00
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
char fname[60];
|
|
|
|
|
uint8_t index;
|
|
|
|
|
}FILE_INFO;
|
|
|
|
|
|
|
|
|
|
static void upSendFile_thread_entry(void *parameter)
|
2023-06-06 07:45:13 +00:00
|
|
|
|
{
|
2023-08-01 08:27:21 +00:00
|
|
|
|
FILE_INFO *f = RT_NULL;
|
|
|
|
|
f = (FILE_INFO *) parameter;
|
2023-09-14 09:30:01 +00:00
|
|
|
|
// rt_mutex_take(okTosend, RT_WAITING_FOREVER);
|
2023-08-17 01:22:02 +00:00
|
|
|
|
static rt_uint8_t d[BUFFER_ROW][200] = { };//need static?
|
2023-08-04 10:13:59 +00:00
|
|
|
|
static rt_uint8_t s[BUFFER_ROW] = { };
|
2023-09-13 10:34:19 +00:00
|
|
|
|
memset(s,0,BUFFER_ROW);
|
2023-09-06 03:18:11 +00:00
|
|
|
|
if (!getFileSize(f->fname)) {
|
|
|
|
|
LOG_W("file '%s' is empty.",f->fname);
|
|
|
|
|
clearFileToSend(f->fname);
|
2023-09-14 09:30:01 +00:00
|
|
|
|
rt_sem_release(okTosend);
|
2023-09-06 03:18:11 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-11-09 09:12:57 +00:00
|
|
|
|
if (getFileSize(f->fname) > scfg.maxSizePerFile+500) {//部分demo数据体积>>1k
|
2023-08-08 06:31:16 +00:00
|
|
|
|
LOG_W("file '%s' is too large to send.",f->fname);
|
|
|
|
|
clearFileToSend(f->fname);
|
2023-09-14 09:30:01 +00:00
|
|
|
|
rt_sem_release(okTosend);
|
2023-08-08 06:31:16 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-09-06 03:18:11 +00:00
|
|
|
|
|
2023-08-08 06:31:16 +00:00
|
|
|
|
LOG_D("ready to send '%s---%d'",f->fname,f->index);
|
2023-11-09 09:12:57 +00:00
|
|
|
|
// uint8_t len = pack_File(f->fname, 0, d, s);
|
|
|
|
|
uint8_t len = pack_data(f->fname, 0, d, s);
|
|
|
|
|
|
|
|
|
|
// for (size_t i = 0; i < len; i++) {
|
2023-09-13 10:34:19 +00:00
|
|
|
|
// LOG_HEX("msg",27,d[i],s[i]);
|
2023-11-09 09:12:57 +00:00
|
|
|
|
// }
|
2023-08-04 10:13:59 +00:00
|
|
|
|
// list_thread();
|
2023-08-24 03:06:44 +00:00
|
|
|
|
if (len)
|
2023-06-20 10:09:07 +00:00
|
|
|
|
{
|
2023-08-01 08:27:21 +00:00
|
|
|
|
LOG_D("%d pack(s) to send", f->index ? 1 : len);
|
2023-09-14 09:30:01 +00:00
|
|
|
|
uint8_t issendall=1;
|
2023-09-13 10:34:19 +00:00
|
|
|
|
for (size_t var = 0; (var < len && s[var]!=0); var++)
|
2023-06-06 07:45:13 +00:00
|
|
|
|
{
|
2023-08-01 08:27:21 +00:00
|
|
|
|
if (!f->index || (var+1) == f->index)
|
|
|
|
|
{ //index=0 全发,或者仅发index
|
2023-09-15 01:32:27 +00:00
|
|
|
|
if (isTTjh() && sendMsg(d[var], s[var]) == RT_EOK) {
|
2023-09-01 08:59:49 +00:00
|
|
|
|
LOG_D("send pack[%d] with %d bytes done.",var+1,s[var]);
|
2023-09-14 09:30:01 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2023-09-15 01:32:27 +00:00
|
|
|
|
LOG_E("TT未到位或发送失败");
|
2023-09-14 09:30:01 +00:00
|
|
|
|
issendall=0;
|
2023-09-15 01:32:27 +00:00
|
|
|
|
// break;
|
2023-09-14 09:30:01 +00:00
|
|
|
|
}
|
2024-01-18 03:00:07 +00:00
|
|
|
|
rt_thread_mdelay(4000);//发送间隔,目前服务器未处理,暂设为3s避免粘包
|
2023-06-06 07:45:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-14 09:30:01 +00:00
|
|
|
|
if (issendall) {
|
|
|
|
|
LOG_I("upSendFile '%s' done.",f->fname);
|
|
|
|
|
clearFileToSend(f->fname);//由于没有准确的校核机制,此处自能认为是发送成功
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-08 08:38:50 +00:00
|
|
|
|
|
2023-08-08 06:31:16 +00:00
|
|
|
|
// list_thread();
|
2023-08-29 11:29:58 +00:00
|
|
|
|
|
2023-06-06 07:45:13 +00:00
|
|
|
|
}
|
2023-08-29 11:29:58 +00:00
|
|
|
|
//当前文件处理完后置位
|
2023-09-14 09:30:01 +00:00
|
|
|
|
rt_sem_release(okTosend);
|
2023-06-01 09:10:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-01 08:27:21 +00:00
|
|
|
|
/**
|
|
|
|
|
* 发送文件
|
|
|
|
|
* @param f 待发文件,指完整路径名
|
|
|
|
|
* @param index 指定发送的切片索引,为0时表示全部发送
|
|
|
|
|
*/
|
|
|
|
|
void upSendFile(const char *f, int index)
|
2023-06-06 07:45:13 +00:00
|
|
|
|
{
|
2023-08-01 08:27:21 +00:00
|
|
|
|
static FILE_INFO info;
|
2023-08-31 08:12:44 +00:00
|
|
|
|
rt_memset(&info, 0, sizeof(FILE_INFO));
|
2023-08-01 08:27:21 +00:00
|
|
|
|
strcpy(info.fname, f);
|
|
|
|
|
info.index = index;
|
|
|
|
|
|
2023-06-06 07:45:13 +00:00
|
|
|
|
/* 创建 serial 线程 */
|
2023-09-13 10:34:19 +00:00
|
|
|
|
rt_thread_t thread = rt_thread_create("SendFile", upSendFile_thread_entry, (void *) &info, 1024 * 10, 27, 10);
|
2023-06-20 10:09:07 +00:00
|
|
|
|
/* 创建成功则启动线程 */
|
|
|
|
|
if (thread != RT_NULL)
|
|
|
|
|
{
|
|
|
|
|
rt_thread_startup(thread);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-07-26 08:26:53 +00:00
|
|
|
|
LOG_E("thread 'upSendFile' create failure.");
|
2023-06-20 10:09:07 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-06-06 07:45:13 +00:00
|
|
|
|
}
|
2023-08-01 08:27:21 +00:00
|
|
|
|
void d_upSendFile(int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
int index=0;
|
|
|
|
|
if (argc == 3) {
|
|
|
|
|
index = atoi(argv[2]);
|
|
|
|
|
}
|
|
|
|
|
upSendFile(argv[1], index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取本地待发文件列表并倒序发送
|
|
|
|
|
*/
|
|
|
|
|
void getAndSendFile()
|
|
|
|
|
{
|
2023-09-13 06:31:48 +00:00
|
|
|
|
// resetTM();
|
2023-09-10 08:02:33 +00:00
|
|
|
|
isFileMode=0;//逻辑不是很准确
|
2023-09-05 10:53:01 +00:00
|
|
|
|
//优先发送未达指定大小的文件
|
|
|
|
|
char fnow[50];
|
|
|
|
|
getLstCacheFileName(fnow);
|
2024-01-08 03:19:27 +00:00
|
|
|
|
if (getFileSize(fnow)) {//非空情况下加入待发列表
|
|
|
|
|
manualAaddlst(fnow);
|
|
|
|
|
updateCacheFileName();
|
|
|
|
|
cryptCdata(fnow);//密文覆盖明文
|
|
|
|
|
}
|
|
|
|
|
// rt_thread_mdelay(1000);
|
2023-09-05 10:53:01 +00:00
|
|
|
|
|
|
|
|
|
|
2023-09-06 03:18:11 +00:00
|
|
|
|
|
|
|
|
|
uint8_t cnt = (uint8_t)getCntOfFileToSend();
|
2023-08-08 06:31:16 +00:00
|
|
|
|
if(cnt)
|
|
|
|
|
{
|
2023-08-08 08:38:50 +00:00
|
|
|
|
LOG_I("ready to send %d file(s).",cnt);
|
2023-08-08 06:31:16 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LOG_W("no files waiting to be sent.");
|
2023-08-30 10:00:42 +00:00
|
|
|
|
resetTM();//启动超时
|
2023-08-08 06:31:16 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-08-01 08:27:21 +00:00
|
|
|
|
|
2023-09-14 09:30:01 +00:00
|
|
|
|
rt_sem_release(okTosend);//初始赋值
|
2023-09-06 03:18:11 +00:00
|
|
|
|
static int index[MAX_KEY_LEN];
|
|
|
|
|
char f[cnt][MAX_KEY_LEN];
|
|
|
|
|
getFilesToSend(f, index);
|
2023-11-16 08:44:26 +00:00
|
|
|
|
for (int var = 0; var < 1; ++var) {
|
2023-09-06 03:18:11 +00:00
|
|
|
|
for (int i = cnt-1; i > -1; i--)//倒序发送
|
2023-08-01 08:27:21 +00:00
|
|
|
|
{
|
2023-09-14 09:30:01 +00:00
|
|
|
|
LOG_D("f[%d]=%s",i,f[i]);
|
2023-09-06 03:18:11 +00:00
|
|
|
|
// continue;
|
2023-09-14 09:30:01 +00:00
|
|
|
|
if (rt_sem_take(okTosend, RT_WAITING_FOREVER) == RT_EOK)
|
2023-09-10 03:35:17 +00:00
|
|
|
|
{
|
2023-09-06 03:18:11 +00:00
|
|
|
|
rt_thread_mdelay(1000);//thread close
|
|
|
|
|
upSendFile(f[i],index[i]);
|
2023-08-08 08:38:50 +00:00
|
|
|
|
}
|
2023-08-01 08:27:21 +00:00
|
|
|
|
}
|
2023-09-15 01:45:50 +00:00
|
|
|
|
}
|
2023-08-21 09:18:07 +00:00
|
|
|
|
//发送完毕
|
2023-08-25 00:08:30 +00:00
|
|
|
|
LOG_D("mission done.");
|
2023-08-21 09:18:07 +00:00
|
|
|
|
resetTM();
|
2023-08-01 08:27:21 +00:00
|
|
|
|
}
|
2023-07-20 07:29:37 +00:00
|
|
|
|
|
2023-07-26 08:26:53 +00:00
|
|
|
|
static void chkAndSendFile_thread_entry()
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
2023-08-08 06:31:16 +00:00
|
|
|
|
while (1)
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
2023-08-30 10:00:42 +00:00
|
|
|
|
// int e;
|
2023-09-06 03:18:11 +00:00
|
|
|
|
LOG_I("ready and waiting",scfg.sendInterval);
|
2023-09-13 10:34:19 +00:00
|
|
|
|
if (rt_event_recv(&chkSta, FILE_IS_OK | TIMER_IS_OUT, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
|
2023-08-30 10:00:42 +00:00
|
|
|
|
RT_WAITING_FOREVER, RT_NULL) == RT_EOK) //条件1满足
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
2023-09-16 09:09:24 +00:00
|
|
|
|
isFileMode=1;
|
2023-08-01 08:27:21 +00:00
|
|
|
|
LOG_I("等待TT就绪");
|
2023-08-21 09:18:07 +00:00
|
|
|
|
LOG_I("当前规则为:连续%d个采集周期TT信号质量不低于%d",scfg.minTTPeriCnt,scfg.minTTsinal);
|
2023-08-08 06:31:16 +00:00
|
|
|
|
initTT();
|
2023-06-01 09:10:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-14 11:55:33 +00:00
|
|
|
|
TTIsNotReady();//复位
|
|
|
|
|
|
2023-09-03 08:54:23 +00:00
|
|
|
|
size_t maxCnt = 0xffff;
|
2023-09-14 11:55:33 +00:00
|
|
|
|
if (!isWindowMode && !isManualWindow())
|
|
|
|
|
{
|
2023-09-03 08:54:23 +00:00
|
|
|
|
maxCnt = scfg.maxTTRetryCnt;
|
|
|
|
|
}
|
2023-09-14 11:55:33 +00:00
|
|
|
|
|
2023-09-03 08:54:23 +00:00
|
|
|
|
for (size_t var = 0; var < maxCnt; var++) //轮询尝试
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
2023-09-14 11:55:33 +00:00
|
|
|
|
rt_tick_t tm = rt_tick_get_millisecond();
|
|
|
|
|
LOG_I("第%d/%d次尝试。", var + 1, maxCnt);
|
|
|
|
|
int flag=0;
|
|
|
|
|
while (1)
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
2023-09-14 11:55:33 +00:00
|
|
|
|
if (isTTok)
|
2023-08-15 09:10:18 +00:00
|
|
|
|
{
|
2023-09-14 11:55:33 +00:00
|
|
|
|
isTTok=0;
|
2024-01-15 10:27:37 +00:00
|
|
|
|
rt_thread_mdelay(15000);
|
2023-09-14 11:55:33 +00:00
|
|
|
|
getAndSendFile();
|
|
|
|
|
flag=1;
|
|
|
|
|
break;
|
2023-08-15 09:10:18 +00:00
|
|
|
|
}
|
2023-09-14 11:55:33 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//not ready
|
|
|
|
|
if ((rt_tick_get_millisecond() - tm) > rt_tick_from_millisecond(scfg.maxTTWaitTime * 60 * 1000)) //超时
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rt_thread_mdelay(1000);
|
|
|
|
|
}
|
2023-08-08 06:31:16 +00:00
|
|
|
|
}
|
2023-09-14 11:55:33 +00:00
|
|
|
|
} //end while
|
2023-09-03 10:12:55 +00:00
|
|
|
|
|
2023-09-14 11:55:33 +00:00
|
|
|
|
if (flag) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if ((var + 1) < maxCnt)
|
|
|
|
|
{
|
|
|
|
|
LOG_W("第%d次尝试中TT准备失败,重试。", var + 1);
|
|
|
|
|
deInitTT();
|
|
|
|
|
rt_thread_mdelay(5000);
|
|
|
|
|
initTT();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG_E("TT准备失败");
|
2023-09-03 10:12:55 +00:00
|
|
|
|
deInitTT();
|
2023-09-25 01:51:35 +00:00
|
|
|
|
isFileMode=0;
|
2023-09-03 10:12:55 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2023-06-01 09:10:00 +00:00
|
|
|
|
}
|
2023-09-13 10:34:19 +00:00
|
|
|
|
// LOG_W("--------one loop DONE--------");
|
2023-06-01 09:10:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-06 07:45:13 +00:00
|
|
|
|
|
2023-07-20 07:29:37 +00:00
|
|
|
|
|
2023-08-01 08:27:21 +00:00
|
|
|
|
/**
|
|
|
|
|
* 检查状态并发送文件
|
|
|
|
|
*/
|
2023-07-26 08:26:53 +00:00
|
|
|
|
void chkAndSendFile()
|
2023-06-06 07:45:13 +00:00
|
|
|
|
{
|
2023-08-30 10:00:42 +00:00
|
|
|
|
sysEventInit();//必须此处初始化,不然EVENT无法加入链表
|
|
|
|
|
if (!tmrToPNTT) {
|
|
|
|
|
tmrToPNTT = rt_timer_create("TTtimeout", timeoutFunc,
|
|
|
|
|
RT_NULL, rt_tick_from_millisecond(scfg.timeout*60*1000),
|
2023-08-31 08:12:44 +00:00
|
|
|
|
RT_TIMER_FLAG_PERIODIC);//|RT_TIMER_FLAG_SOFT_TIMER);
|
2023-08-30 10:00:42 +00:00
|
|
|
|
}
|
2023-06-06 07:45:13 +00:00
|
|
|
|
/* 创建 serial 线程 */
|
2023-08-30 02:45:32 +00:00
|
|
|
|
rt_thread_t thread = rt_thread_create("chk&send", chkAndSendFile_thread_entry, RT_NULL, 1024 * 5, 19, 10);
|
2023-06-20 10:09:07 +00:00
|
|
|
|
/* 创建成功则启动线程 */
|
|
|
|
|
if (thread != RT_NULL)
|
|
|
|
|
{
|
|
|
|
|
rt_thread_startup(thread);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-07-26 08:26:53 +00:00
|
|
|
|
LOG_E("thread 'chk&send' create failure.");
|
2023-06-20 10:09:07 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-06-06 07:45:13 +00:00
|
|
|
|
}
|
2023-08-08 06:31:16 +00:00
|
|
|
|
INIT_APP_EXPORT(chkAndSendFile);
|
2023-07-20 07:29:37 +00:00
|
|
|
|
|
2023-07-28 08:29:57 +00:00
|
|
|
|
//RT_TICK_PER_SECOND
|
2023-07-20 07:29:37 +00:00
|
|
|
|
//tcp连接保活
|
|
|
|
|
//实际场景不存在中间断掉的可能
|
2023-07-27 07:46:45 +00:00
|
|
|
|
void initTT_thread_entry()
|
2023-07-20 07:29:37 +00:00
|
|
|
|
{
|
2023-07-28 08:29:57 +00:00
|
|
|
|
pwTT_thread_entry("1");
|
2023-08-21 09:18:07 +00:00
|
|
|
|
// rt_thread_mdelay(15000);//wait TT to boot up
|
2023-09-02 08:39:08 +00:00
|
|
|
|
static uint8_t cnt=0;
|
2023-08-08 08:38:50 +00:00
|
|
|
|
while (1)
|
2023-07-20 07:29:37 +00:00
|
|
|
|
{
|
2023-08-04 06:09:39 +00:00
|
|
|
|
if (!isTTon()) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 08:29:57 +00:00
|
|
|
|
if (!tmrToPNTT) {
|
|
|
|
|
tmrToPNTT = rt_timer_create("TTtimeout", timeoutFunc,
|
|
|
|
|
RT_NULL, rt_tick_from_millisecond(scfg.timeout*60*1000),
|
2023-08-03 03:04:50 +00:00
|
|
|
|
RT_TIMER_FLAG_ONE_SHOT);//|RT_TIMER_FLAG_SOFT_TIMER);
|
2023-07-20 07:29:37 +00:00
|
|
|
|
}
|
2023-08-04 06:09:39 +00:00
|
|
|
|
|
2023-09-02 07:23:32 +00:00
|
|
|
|
if (!isEthUP())//只初始化一次
|
|
|
|
|
{
|
2023-07-27 07:46:45 +00:00
|
|
|
|
LOG_D("init eth...");
|
2023-08-21 09:18:07 +00:00
|
|
|
|
rt_pin_write(ETH_RESET_PIN, PIN_HIGH);
|
2023-09-02 07:23:32 +00:00
|
|
|
|
if (rt_hw_stm32_eth_init() == RT_EOK)//激活网口
|
2023-07-27 07:46:45 +00:00
|
|
|
|
{
|
2023-09-02 08:39:08 +00:00
|
|
|
|
LOG_I("eth inited DONE.");
|
2023-09-02 07:23:32 +00:00
|
|
|
|
};
|
2023-07-27 07:46:45 +00:00
|
|
|
|
}
|
|
|
|
|
else if (!isTCPok()) //判断TCP连接是否正常,异常自动重连
|
2023-07-20 07:29:37 +00:00
|
|
|
|
{
|
2023-09-02 07:23:32 +00:00
|
|
|
|
if (tcpInit() != RT_EOK)
|
|
|
|
|
{
|
2023-09-10 07:06:44 +00:00
|
|
|
|
if (cnt >= 10)
|
2023-09-04 09:45:03 +00:00
|
|
|
|
{
|
|
|
|
|
cnt=0;
|
|
|
|
|
LOG_E("TT is not responded, check the power or TT device.");
|
|
|
|
|
deInitTT();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-09-02 07:23:32 +00:00
|
|
|
|
if (isEthUP())
|
|
|
|
|
{
|
2023-09-02 08:39:08 +00:00
|
|
|
|
cnt++;
|
|
|
|
|
LOG_D("[%d] retry.",cnt);
|
2023-08-31 08:12:44 +00:00
|
|
|
|
rt_hw_stm32_eth_deinit();
|
2023-09-02 07:23:32 +00:00
|
|
|
|
continue;
|
2023-08-31 08:12:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-02 07:23:32 +00:00
|
|
|
|
else
|
2023-07-27 07:46:45 +00:00
|
|
|
|
{
|
2023-09-02 08:39:08 +00:00
|
|
|
|
LOG_I("TCP is ready.");
|
2023-07-27 07:46:45 +00:00
|
|
|
|
tcpRecMQ(); //开启tcp接收线程
|
|
|
|
|
recTT();
|
2023-08-15 09:10:18 +00:00
|
|
|
|
repGetTT();
|
2023-08-25 08:36:00 +00:00
|
|
|
|
reportLoc();
|
2023-09-14 11:55:33 +00:00
|
|
|
|
if (getCntOfFileToSend()) fileIsReady();
|
2023-08-30 10:00:42 +00:00
|
|
|
|
// resetTM();//启动超时,激活后开启
|
2023-07-27 07:46:45 +00:00
|
|
|
|
}
|
2023-07-20 07:29:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 07:46:45 +00:00
|
|
|
|
rt_thread_mdelay(3000); //chk with 3 second interval
|
2023-07-20 07:29:37 +00:00
|
|
|
|
}
|
2023-08-08 08:38:50 +00:00
|
|
|
|
|
|
|
|
|
initThread=RT_NULL;
|
2023-11-05 01:26:23 +00:00
|
|
|
|
pwTT_thread_entry("0");
|
2023-08-21 03:17:40 +00:00
|
|
|
|
// list_thread();
|
|
|
|
|
// cmd_free();
|
2023-07-20 07:29:37 +00:00
|
|
|
|
}
|
2023-07-28 08:29:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void deInitTT_thread_entry()
|
2023-07-27 07:46:45 +00:00
|
|
|
|
{
|
2023-08-23 06:41:29 +00:00
|
|
|
|
if (deinitThread != RT_NULL && rt_sem_take(shuntDownTT, RT_WAITING_FOREVER) == RT_EOK)
|
2023-07-28 08:29:57 +00:00
|
|
|
|
{
|
2023-08-21 03:17:40 +00:00
|
|
|
|
deinitThread =RT_NULL;
|
2023-08-04 06:09:39 +00:00
|
|
|
|
tcpClose();
|
2023-08-24 03:06:44 +00:00
|
|
|
|
if (isEthUP()) {
|
|
|
|
|
rt_hw_stm32_eth_deinit(); //qu激活网口
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-04 06:09:39 +00:00
|
|
|
|
pwTT_thread_entry("0");
|
2023-09-15 09:25:52 +00:00
|
|
|
|
// startAlarm();
|
2023-08-23 06:41:29 +00:00
|
|
|
|
clearWindowMode();
|
2023-09-15 09:25:52 +00:00
|
|
|
|
// setManualWindow(-1);
|
2023-09-10 02:09:28 +00:00
|
|
|
|
setWorkSta(0);
|
2023-09-16 09:09:24 +00:00
|
|
|
|
// isFileMode=0;
|
2023-07-28 08:29:57 +00:00
|
|
|
|
LOG_W("shunt down TT DONE");
|
|
|
|
|
}
|
2023-08-24 03:06:44 +00:00
|
|
|
|
// initThread = RT_NULL;
|
2023-08-23 06:41:29 +00:00
|
|
|
|
deinitThread = RT_NULL;
|
2023-11-05 01:26:23 +00:00
|
|
|
|
pwTT_thread_entry("0");
|
2023-08-29 11:29:58 +00:00
|
|
|
|
// list_thread();
|
2023-07-27 07:46:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 08:29:57 +00:00
|
|
|
|
/**
|
|
|
|
|
* TT上电,初始化TT相关的网络、TCP等,并保活
|
|
|
|
|
*/
|
|
|
|
|
void initTT()
|
|
|
|
|
{
|
|
|
|
|
/* 创建 serial 线程 */
|
2023-08-08 08:38:50 +00:00
|
|
|
|
if (initThread != RT_NULL) {
|
2023-09-02 07:23:32 +00:00
|
|
|
|
LOG_W("TT is already running.");
|
2023-08-08 08:38:50 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-09-08 09:26:13 +00:00
|
|
|
|
set3SRTC();
|
2023-09-10 02:09:28 +00:00
|
|
|
|
setWorkSta(1);
|
2023-09-16 09:09:24 +00:00
|
|
|
|
// isFileMode=1;
|
2023-09-02 11:33:16 +00:00
|
|
|
|
initThread = rt_thread_create("initTT", initTT_thread_entry, RT_NULL, 1024 * 5, 25, 10);
|
2023-07-28 08:29:57 +00:00
|
|
|
|
/* 创建成功则启动线程 */
|
2023-08-08 08:38:50 +00:00
|
|
|
|
if (initThread != RT_NULL)
|
2023-07-28 08:29:57 +00:00
|
|
|
|
{
|
2023-08-08 08:38:50 +00:00
|
|
|
|
rt_thread_startup(initThread);
|
2023-07-28 08:29:57 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG_E("thread 'initTT' create failure.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 创建 serial 线程 */
|
2023-08-08 08:38:50 +00:00
|
|
|
|
if (deinitThread != RT_NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-09-02 11:33:16 +00:00
|
|
|
|
deinitThread = rt_thread_create("deInitTT", deInitTT_thread_entry, RT_NULL, 1024 * 5, 25, 10);
|
2023-07-28 08:29:57 +00:00
|
|
|
|
/* 创建成功则启动线程 */
|
2023-08-08 08:38:50 +00:00
|
|
|
|
if (deinitThread != RT_NULL)
|
2023-07-28 08:29:57 +00:00
|
|
|
|
{
|
2023-08-08 08:38:50 +00:00
|
|
|
|
rt_thread_startup(deinitThread);
|
2023-07-28 08:29:57 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG_E("thread 'deInitTT' create failure.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TT上电,初始化TT相关的网络、TCP等,并保活
|
|
|
|
|
*/
|
2023-07-27 07:46:45 +00:00
|
|
|
|
void deInitTT()
|
2023-07-20 07:29:37 +00:00
|
|
|
|
{
|
2023-07-28 08:29:57 +00:00
|
|
|
|
rt_sem_release(shuntDownTT);
|
2023-07-20 07:29:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define FUNC_DEMO
|
|
|
|
|
#ifdef FUNC_DEMO //测试时导出命令到控制台
|
2023-08-30 10:00:42 +00:00
|
|
|
|
MSH_CMD_EXPORT_ALIAS(TTIsReady,ttisok,TT_IS_OK);
|
2023-08-04 06:09:39 +00:00
|
|
|
|
MSH_CMD_EXPORT(fileIsReady,fileIsReady);
|
2023-08-30 10:00:42 +00:00
|
|
|
|
//MSH_CMD_EXPORT(chkAndSendFile, chkAndSendFile);
|
|
|
|
|
//MSH_CMD_EXPORT(getAndSendFile, getAndSendFile);
|
2023-07-28 08:29:57 +00:00
|
|
|
|
MSH_CMD_EXPORT(initTT,初始化TT);
|
2024-01-05 00:36:41 +00:00
|
|
|
|
MSH_CMD_EXPORT(deInitTT,去初始化TT,勿在初始化过程中使用);
|
|
|
|
|
MSH_CMD_EXPORT(d_remain,time remain);
|
2023-08-21 09:18:07 +00:00
|
|
|
|
MSH_CMD_EXPORT(resetTM,resetTM);
|
2023-08-01 08:27:21 +00:00
|
|
|
|
MSH_CMD_EXPORT(d_upSendFile,d_upSendFile);
|
2023-07-20 07:29:37 +00:00
|
|
|
|
#endif
|