完成定时发送功能

This commit is contained in:
CSSC-WORK\murmur 2023-06-16 16:20:18 +08:00
parent 4d76431e9d
commit 30286c7ad0
6 changed files with 91 additions and 7 deletions

View File

@ -271,7 +271,8 @@ static void try()
static rt_err_t rst = RT_ERROR;
updatecfg();
static rt_uint8_t d[10][200] = { };
static rt_uint8_t s[10] = { };
static rt_uint8_t s[10] = { };
while(1)
{
// int e;
@ -296,7 +297,7 @@ static void try()
RT_NULL);
if (rst == RT_EOK)//硬件条件满足
{
LOG_I("TT准备OK");
LOG_I("TT准备就绪");
rt_event_send(&hw_check, ALL_READY);
break;
}

View File

@ -8,3 +8,86 @@
* 2023-06-16 murmur the first version
*/
//姿态调配用demo程序。固定数据包循环重发
#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);

View File

@ -140,5 +140,5 @@ int timer_sample(void)
/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(timer_sample, timer sample);
//MSH_CMD_EXPORT(timer_sample, timer sample);

View File

@ -60,7 +60,7 @@ void hexFile_thread_entry(void* parameter)
fd_in = open(fin, O_RDONLY, 0);
if (fd_in < 0)
{
rt_kprintf("[hex] open the input file : %s error!\n", fin);
LOG_E("[hex] open the input file : %s error.", fin);
return RT_ERROR;
}
size_t file_size = lseek(fd_in, 0, SEEK_END);
@ -83,7 +83,7 @@ void hexFile_thread_entry(void* parameter)
memset(buffer, 0x00, READ_BUFFER_SIZE);
read(fd_in, buffer, block_size);
LOG_HEX("hex_file:",27,buffer,block_size);
LOG_HEX("hex_file",27,buffer,block_size);
}
rt_free(buffer);

View File

@ -79,7 +79,7 @@ int tcpInit(void)
static int tcpSend(const rt_uint8_t *send_data, size_t len)
{
LOG_HEX("send",27,send_data,len);
// LOG_HEX("send",27,send_data,len);
/* 发送数据到sock连接 */
int ret = send(sock, send_data, len, 0);

View File

@ -174,7 +174,7 @@ static int uart_dma_sample(int argc, char *argv[])
/* 创建定时器1 周期定时器 */
timer1 = rt_timer_create("rxtimer", timeout1,
RT_NULL, 10,
RT_NULL, 60,
RT_TIMER_FLAG_PERIODIC);