TT12-MCU/applications/repeatSend.c
CSSC-WORK\murmur 62d45ba6a3 调整子包之间发送间隔为3s。
版本号小增。
2023-06-19 17:17:06 +08:00

142 lines
3.7 KiB
C

/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-06-16 murmur the first version
*/
//姿态调配用demo程序。固定数据包循环重发
#include <rtthread.h>
#define LOG_TAG "repeatSend"
#define LOG_LVL LOG_LVL_DBG
#include <ulog.h>
#include <ttTR.h>
#include <usrcfg.h>
/* 定时器的控制块 */
static rt_timer_t timer1;
static struct rt_event readyToSend;
static rt_sem_t ttack= RT_NULL;
#define TIME_IS_UP 1<<1
void upTTflagtmp(void)
{
// rt_event_send(&readyToSend, TT_IS_OK);
rt_sem_release(ttack);
}
void repeatSend_thread_entry()
{
static rt_uint8_t d[10][200] = { };
static rt_uint8_t s[10] = { };
while(tcpInit() != RT_EOK)
{
LOG_W("TT server is not ready.");
rt_thread_mdelay(100);
}
LOG_D("TT server is ready.");
while (1)
{
if (rt_event_recv(&readyToSend, TIME_IS_UP, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER,
RT_NULL) == RT_EOK)
{
//记录次数
//此次数为总定时超时次数
add_val("allCnt");
// if (rt_event_recv(&readyToSend, TT_IS_OK, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
// rt_tick_from_millisecond(1 * 60 * 1000),
// RT_NULL) == RT_EOK)//等待1分钟
if(rt_sem_take(ttack, rt_tick_from_millisecond(1 * 60 * 1000)) == RT_EOK)
{
LOG_D("TT is ready.");
char *f = "2023_06_17_16_30_00_000.bin";
rt_uint8_t len = 0;
len = pack_File(f, 0, d, s);
LOG_D("Pack done.");
if (len)
{
for (size_t var = 0; var < len; var++)
{
sendMsg(d[var], s[var]);
rt_uint8_t rd[30];
tcpRec(rd);
LOG_HEX("ack",16,rd,30);
rt_thread_mdelay(3000);
// LOG_HEX("d", 27, d[var], s[var]);
}
// tcpClose();
LOG_I("send msg Done.");
//记录次数
//此次数为发送成功次数
add_val("okCnt");
}
}
else
{
LOG_W("TT is not ready.");
}
}
}
}
/* 定时器1超时函数 */
static void timeout1(void *parameter)
{
LOG_D("定时时间到,准备发送数据");
rt_event_send(&readyToSend, TIME_IS_UP);
}
void timer_demo()
{
/* 创建定时器1 周期定时器 */
timer1 = rt_timer_create("repeatSendtimer", timeout1,
RT_NULL, rt_tick_from_millisecond(5*60*1000),
RT_TIMER_FLAG_PERIODIC);
/* 启动定时器1 */
if (timer1 != RT_NULL)
rt_timer_start(timer1);
/* 创建 serial 线程 */
rt_thread_t thread = rt_thread_create("repSendT", repeatSend_thread_entry, RT_NULL, 1024*3, 25+1, 10);
/* 创建成功则启动线程 */
if (thread != RT_NULL)
{
rt_thread_startup(thread);
}
else
{
LOG_E("Failed to create thread.");
}
}
MSH_CMD_EXPORT(timer_demo,)
void inievt()
{
pwTT_thread_entry("1");//开机
rt_event_init(&readyToSend, "repSend", RT_IPC_FLAG_PRIO);
ttack = rt_sem_create("ttack", 0, RT_IPC_FLAG_PRIO);
rt_hw_stm32_eth_init();//激活网口
rt_thread_mdelay(10*1000);
repGetTT();//持续更新
// runTT();
}
INIT_APP_EXPORT(inievt);
INIT_APP_EXPORT(timer_demo);
MSH_CMD_EXPORT(upTTflagtmp,);