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>
|
2023-06-20 10:09:07 +00:00
|
|
|
|
//#include <cfg.h>
|
2023-06-02 02:23:26 +00:00
|
|
|
|
#include <usrcfg.h>
|
2023-06-06 07:45:13 +00:00
|
|
|
|
#include <ttTR.h>
|
2023-06-20 10:09:07 +00:00
|
|
|
|
static struct rt_event sw_check; //软件条件
|
|
|
|
|
static struct rt_event hw_check; //硬件条件
|
|
|
|
|
|
|
|
|
|
extern rt_sem_t TTReady;
|
2023-06-06 07:45:13 +00:00
|
|
|
|
#define ALL_READY 1
|
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-06 07:45:13 +00:00
|
|
|
|
static void initEvent(void)
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
|
|
|
|
/* 事 件 控 制 块 */
|
|
|
|
|
|
2023-06-06 07:45:13 +00:00
|
|
|
|
rt_err_t result = rt_event_init(&sw_check, "SHcheck", RT_IPC_FLAG_PRIO);
|
2023-06-16 03:18:52 +00:00
|
|
|
|
result = rt_event_init(&hw_check, "HWcheck", RT_IPC_FLAG_PRIO) | result;
|
|
|
|
|
|
2023-06-01 09:10:00 +00:00
|
|
|
|
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
|
|
|
|
|
2023-06-06 07:45:13 +00:00
|
|
|
|
void upSWflag(void)
|
|
|
|
|
{
|
|
|
|
|
rt_event_send(&sw_check, FILE_IS_OK);
|
|
|
|
|
}
|
|
|
|
|
void upTTflag(void)
|
|
|
|
|
{
|
|
|
|
|
rt_event_send(&sw_check, TT_IS_OK);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
//INIT_COMPONENT_EXPORT(t3);
|
2023-06-06 07:45:13 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void getFileData_thread_entry(void)
|
|
|
|
|
{
|
|
|
|
|
//等待事件
|
2023-06-20 10:09:07 +00:00
|
|
|
|
extern struct rt_event hw_check; //硬件条件
|
2023-06-06 07:45:13 +00:00
|
|
|
|
|
|
|
|
|
static rt_uint8_t d[10][200] = { };
|
|
|
|
|
static rt_uint8_t s[10] = { };
|
|
|
|
|
|
2023-06-20 10:09:07 +00:00
|
|
|
|
while (tcpInit() != RT_EOK)
|
2023-06-06 07:45:13 +00:00
|
|
|
|
{
|
2023-06-20 10:09:07 +00:00
|
|
|
|
LOG_W("TT server is not ready.");
|
|
|
|
|
rt_thread_mdelay(100);
|
|
|
|
|
}
|
|
|
|
|
LOG_D("TT server is ready.");
|
2023-06-06 07:45:13 +00:00
|
|
|
|
|
2023-06-20 10:09:07 +00:00
|
|
|
|
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)
|
2023-06-06 07:45:13 +00:00
|
|
|
|
{
|
|
|
|
|
|
2023-06-20 10:09:07 +00:00
|
|
|
|
//get file to be send
|
|
|
|
|
char *f = "2023_06_16_10_28_00_123.bin";
|
|
|
|
|
// char *f="1023_05_19_15_29_59_254.txt";
|
|
|
|
|
// pack file
|
|
|
|
|
rt_uint8_t len = 0;
|
|
|
|
|
len = pack_File(f, 0, d, s);
|
|
|
|
|
rt_kprintf("len is %d\n", len);
|
|
|
|
|
if (len)
|
2023-06-06 07:45:13 +00:00
|
|
|
|
{
|
2023-06-20 10:09:07 +00:00
|
|
|
|
for (size_t var = 0; var < len; var++)
|
2023-06-06 07:45:13 +00:00
|
|
|
|
{
|
2023-06-20 10:09:07 +00:00
|
|
|
|
sendMsg(d[var], s[var]);
|
|
|
|
|
// LOG_D("i = %d", var);
|
|
|
|
|
// LOG_HEX("d", 27, d[var], s[var]);
|
2023-06-06 07:45:13 +00:00
|
|
|
|
}
|
2023-06-20 10:09:07 +00:00
|
|
|
|
tcpClose();
|
|
|
|
|
LOG_I("Done.");
|
2023-06-06 07:45:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-01 09:10:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-06 07:45:13 +00:00
|
|
|
|
//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);
|
2023-06-20 10:09:07 +00:00
|
|
|
|
/* 创建成功则启动线程 */
|
|
|
|
|
if (thread != RT_NULL)
|
|
|
|
|
{
|
|
|
|
|
rt_thread_startup(thread);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG_E("thread 'PSmsg' create failure.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-06-06 07:45:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void try()
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
|
|
|
|
static rt_err_t rst = RT_ERROR;
|
|
|
|
|
updatecfg();
|
2023-06-06 07:45:13 +00:00
|
|
|
|
static rt_uint8_t d[10][200] = { };
|
2023-06-16 08:20:18 +00:00
|
|
|
|
static rt_uint8_t s[10] = { };
|
|
|
|
|
|
2023-06-20 10:09:07 +00:00
|
|
|
|
while (1)
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
2023-06-06 07:45:13 +00:00
|
|
|
|
// int e;
|
|
|
|
|
LOG_I("等待软件就绪");
|
2023-06-01 09:10:00 +00:00
|
|
|
|
rst = rt_event_recv(&sw_check, FILE_IS_OK | TIMER_IS_OUT, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
|
2023-06-20 10:09:07 +00:00
|
|
|
|
RT_WAITING_FOREVER, RT_NULL);
|
|
|
|
|
if (rst == RT_EOK) //软件条件满足
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
2023-06-02 02:23:26 +00:00
|
|
|
|
//检查硬件条件
|
2023-06-06 07:45:13 +00:00
|
|
|
|
LOG_I("软件就绪,开始等待TT");
|
|
|
|
|
// continue;
|
2023-06-02 02:23:26 +00:00
|
|
|
|
checkTT();
|
|
|
|
|
//打包数据
|
|
|
|
|
|
2023-06-01 09:10:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-20 10:09:07 +00:00
|
|
|
|
for (size_t var = 0; var < maxTTRetryCnt; var++) //轮询尝试
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
2023-06-20 10:09:07 +00:00
|
|
|
|
LOG_I("第%d次尝试。", var + 1);
|
|
|
|
|
// rst = rt_event_recv(&sw_check, TT_IS_OK, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, maxTTWaitTime*60*1000,
|
|
|
|
|
// RT_NULL);
|
|
|
|
|
rst = rt_sem_take(TTReady, rt_tick_from_millisecond(maxTTWaitTime * 60 * 1000));
|
|
|
|
|
if (rst == RT_EOK) //硬件条件满足
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
2023-06-16 08:20:18 +00:00
|
|
|
|
LOG_I("TT准备就绪");
|
2023-06-06 07:45:13 +00:00
|
|
|
|
rt_event_send(&hw_check, ALL_READY);
|
2023-06-01 09:10:00 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2023-06-20 10:09:07 +00:00
|
|
|
|
else if (rst == -RT_ETIMEOUT)
|
|
|
|
|
; //超时则重试
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
2023-06-20 10:09:07 +00:00
|
|
|
|
LOG_W("第%d次尝试中TT准备失败。", var + 1);
|
2023-06-06 07:45:13 +00:00
|
|
|
|
// pwTT_thread_entry("0");
|
2023-06-02 02:23:26 +00:00
|
|
|
|
rt_thread_mdelay(1000);
|
|
|
|
|
checkTT();
|
|
|
|
|
// continue;
|
2023-06-01 09:10:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-06 07:45:13 +00:00
|
|
|
|
//continue;
|
2023-06-02 02:23:26 +00:00
|
|
|
|
//发送数据
|
2023-06-06 07:45:13 +00:00
|
|
|
|
//可能有多个待发文件,每个文件打包后为一个二维数组
|
|
|
|
|
// 如果先打包后发送,需要三维数组,和大内存占用
|
|
|
|
|
// 故改为“打包-发送”轮询操作
|
|
|
|
|
//gg();
|
|
|
|
|
#ifdef _NO
|
|
|
|
|
char *f="1023_05_19_15_29_59_254.txt";
|
2023-06-20 10:09:07 +00:00
|
|
|
|
// pack file
|
2023-06-06 07:45:13 +00:00
|
|
|
|
// static rt_uint8_t d[10][200] = { };
|
|
|
|
|
// static rt_uint8_t s[10] = { };
|
|
|
|
|
rt_uint8_t len = 0;
|
2023-06-20 10:09:07 +00:00
|
|
|
|
// LOG_D("%p--%p",d,s);
|
|
|
|
|
// LOG_I("pack %s ...",f);
|
2023-06-06 07:45:13 +00:00
|
|
|
|
len = pack_File(f, 0, d, s);
|
|
|
|
|
rt_kprintf("len is %d\n", len);
|
|
|
|
|
if (len)
|
|
|
|
|
{
|
2023-06-20 10:09:07 +00:00
|
|
|
|
for (size_t var = 0; var < len; ++var)
|
|
|
|
|
{
|
|
|
|
|
// LOG_HEX("d",27,d[var],s[var]);
|
2023-06-06 07:45:13 +00:00
|
|
|
|
|
2023-06-20 10:09:07 +00:00
|
|
|
|
}
|
2023-06-06 07:45:13 +00:00
|
|
|
|
LOG_I("Done.");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2023-06-20 10:09:07 +00:00
|
|
|
|
LOG_I("----------------------------");
|
2023-06-06 07:45:13 +00:00
|
|
|
|
//initEvent();
|
|
|
|
|
// rt_thread_mdelay(100);
|
|
|
|
|
|
2023-06-01 09:10:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-06 07:45:13 +00:00
|
|
|
|
|
2023-06-20 10:09:07 +00:00
|
|
|
|
MSH_CMD_EXPORT(gg, file);
|
2023-06-06 07:45:13 +00:00
|
|
|
|
|
|
|
|
|
void smsg()
|
|
|
|
|
{
|
|
|
|
|
/* 创建 serial 线程 */
|
|
|
|
|
rt_thread_t thread = rt_thread_create("checkSta", try, RT_NULL, 1024 * 5, 24, 10);
|
2023-06-20 10:09:07 +00:00
|
|
|
|
/* 创建成功则启动线程 */
|
|
|
|
|
if (thread != RT_NULL)
|
|
|
|
|
{
|
|
|
|
|
rt_thread_startup(thread);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG_E("thread 'checkSta' create failure.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-06-06 07:45:13 +00:00
|
|
|
|
}
|
2023-06-19 07:56:45 +00:00
|
|
|
|
//INIT_COMPONENT_EXPORT(smsg);
|
2023-06-20 10:09:07 +00:00
|
|
|
|
MSH_CMD_EXPORT(smsg, smsg);
|