TT12-MCU/applications/repeatSend.c

122 lines
3.2 KiB
C
Raw Normal View History

2023-06-16 03:26:01 +00:00
/*
* 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程序。固定数据包循环重发
2023-06-16 08:20:18 +00:00
#include <rtthread.h>
#define LOG_TAG "repeatSend"
2023-06-16 08:20:18 +00:00
#define LOG_LVL LOG_LVL_DBG
#include <ulog.h>
#include <ttTR.h>
#include <usrcfg.h>
2023-06-16 08:20:18 +00:00
/* 定时器的控制块 */
static rt_timer_t timer1;
static struct rt_event readyToSend;
#define TIME_IS_UP 1<<1
void upTTflagtmp(void)
{
rt_event_send(&readyToSend, TT_IS_OK);
}
2023-06-16 08:20:18 +00:00
void repeatSend_thread_entry()
{
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)
2023-06-16 08:20:18 +00:00
{
LOG_D("TT is ready.");
char *f = "2023_06_17_16_30_00_000.bin";
static rt_uint8_t d[30][200] = { };
static rt_uint8_t s[30] = { };
rt_uint8_t len = 0;
len = pack_File(f, 0, d, s);
if (len && (tcpInit() == RT_EOK))
2023-06-16 08:20:18 +00:00
{
for (size_t var = 0; var < len; var++)
{
sendMsg(d[var], s[var]);
rt_thread_mdelay(1000);
// LOG_HEX("d", 27, d[var], s[var]);
}
tcpClose();
LOG_I("send msg Done.");
//记录次数
//此次数为发送成功次数
add_val("okCnt");
2023-06-16 08:20:18 +00:00
}
}
else
{
LOG_W("TT is not ready.");
2023-06-16 08:20:18 +00:00
}
}
}
}
/* 定时器1超时函数 */
static void timeout1(void *parameter)
{
LOG_D("定时时间到,准备发送数据");
2023-06-16 08:20:18 +00:00
rt_event_send(&readyToSend, TIME_IS_UP);
}
void timer_demo()
{
/* 创建定时器1 周期定时器 */
timer1 = rt_timer_create("repeatSendtimer", timeout1,
RT_NULL, rt_tick_from_millisecond(1*60*1000),
2023-06-16 08:20:18 +00:00
RT_TIMER_FLAG_PERIODIC);
/* 启动定时器1 */
if (timer1 != RT_NULL)
rt_timer_start(timer1);
// rt_err_t result = rt_event_init(&readyToSend, "readyToSend", RT_IPC_FLAG_PRIO);
/* 创建 serial 线程 */
rt_thread_t thread = rt_thread_create("repsendT", repeatSend_thread_entry, RT_NULL, 1024*3, 25+1, 10);
2023-06-16 08:20:18 +00:00
/* 创建成功则启动线程 */
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_err_t result = rt_event_init(&readyToSend, "repSend", RT_IPC_FLAG_PRIO);
rt_hw_stm32_eth_init();//激活网口
2023-06-16 08:20:18 +00:00
}
INIT_APP_EXPORT(inievt);
INIT_APP_EXPORT(timer_demo);
MSH_CMD_EXPORT(upTTflagtmp,);