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 "repeadSend"
|
|
|
|
#define LOG_LVL LOG_LVL_DBG
|
|
|
|
#include <ulog.h>
|
|
|
|
|
|
|
|
#include <ttTR.h>
|
|
|
|
|
|
|
|
/* 定时器的控制块 */
|
|
|
|
static rt_timer_t timer1;
|
|
|
|
static struct rt_event readyToSend;
|
|
|
|
#define TIME_IS_UP 1<<1
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
char *f = "2023_06_16_10_28_00_123.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))
|
|
|
|
{
|
|
|
|
// rt_event_send(&tcp_chk, TT_TCP_OK);
|
|
|
|
for (size_t var = 0; var < len; var++)
|
|
|
|
{
|
|
|
|
sendMsg(d[var], s[var]);
|
|
|
|
// LOG_D("i = %d", var);
|
|
|
|
LOG_HEX("d", 27, d[var], s[var]);
|
|
|
|
}
|
|
|
|
tcpClose();
|
|
|
|
LOG_I("Done.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* 定时器1超时函数 */
|
|
|
|
static void timeout1(void *parameter)
|
|
|
|
{
|
|
|
|
|
|
|
|
LOG_D("定时时间到,开始发送数据");
|
|
|
|
rt_event_send(&readyToSend, TIME_IS_UP);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void timer_demo()
|
|
|
|
{
|
|
|
|
/* 创建定时器1 周期定时器 */
|
|
|
|
timer1 = rt_timer_create("repeadSendtimer", timeout1,
|
|
|
|
RT_NULL, rt_tick_from_millisecond(30*1000),
|
|
|
|
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("send", repeatSend_thread_entry, RT_NULL, 1024*1, 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()
|
|
|
|
{
|
|
|
|
rt_err_t result = rt_event_init(&readyToSend, "readyToSend", RT_IPC_FLAG_PRIO);
|
|
|
|
}
|
|
|
|
INIT_APP_EXPORT(inievt);
|