From 30286c7ad0bc2d1dee515e452a7481ad31b224e0 Mon Sep 17 00:00:00 2001 From: "CSSC-WORK\\murmur" Date: Fri, 16 Jun 2023 16:20:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=AE=9A=E6=97=B6=E5=8F=91?= =?UTF-8?q?=E9=80=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/_main.c | 5 +- applications/repeatSend.c | 83 ++++++++++++++++++++++++++++++++++ applications/timer.c | 2 +- applications/tools.c | 4 +- applications/ttTR.c | 2 +- applications/uart_dma_sample.c | 2 +- 6 files changed, 91 insertions(+), 7 deletions(-) diff --git a/applications/_main.c b/applications/_main.c index 2f9b5be..8118dbc 100644 --- a/applications/_main.c +++ b/applications/_main.c @@ -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; } diff --git a/applications/repeatSend.c b/applications/repeatSend.c index 875e44f..05dd661 100644 --- a/applications/repeatSend.c +++ b/applications/repeatSend.c @@ -8,3 +8,86 @@ * 2023-06-16 murmur the first version */ //姿态调配用demo程序。固定数据包循环重发 + +#include + +#define LOG_TAG "repeadSend" +#define LOG_LVL LOG_LVL_DBG +#include + +#include + +/* 定时器的控制块 */ +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); diff --git a/applications/timer.c b/applications/timer.c index c7270a7..27250c2 100644 --- a/applications/timer.c +++ b/applications/timer.c @@ -140,5 +140,5 @@ int timer_sample(void) /* 导出到 msh 命令列表中 */ -MSH_CMD_EXPORT(timer_sample, timer sample); +//MSH_CMD_EXPORT(timer_sample, timer sample); diff --git a/applications/tools.c b/applications/tools.c index 4b7aedc..86bf2f2 100644 --- a/applications/tools.c +++ b/applications/tools.c @@ -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); diff --git a/applications/ttTR.c b/applications/ttTR.c index a5f920f..cadecb4 100644 --- a/applications/ttTR.c +++ b/applications/ttTR.c @@ -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); diff --git a/applications/uart_dma_sample.c b/applications/uart_dma_sample.c index 2d482a9..a444f1b 100644 --- a/applications/uart_dma_sample.c +++ b/applications/uart_dma_sample.c @@ -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);