From 98dd4840bb40a0766ca4e78209a088d263f6bbed Mon Sep 17 00:00:00 2001 From: "CSSC-WORK\\murmur" Date: Tue, 25 Jul 2023 14:55:03 +0800 Subject: [PATCH] =?UTF-8?q?func.c=20=E6=9B=B4=E6=96=B0upSend=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/func/func.c | 61 ++++++++++++++++++++++++++++++-------- applications/main.c | 2 +- applications/ttmsg/ttmsg.c | 4 ++- applications/uart_3S.c | 2 +- 4 files changed, 54 insertions(+), 15 deletions(-) diff --git a/applications/func/func.c b/applications/func/func.c index 7b82ceb..0c8d846 100644 --- a/applications/func/func.c +++ b/applications/func/func.c @@ -82,8 +82,39 @@ RT_WEAK int getPowerLevel(void) return 0; } +typedef struct +{ + rt_uint8_t len; + rt_uint8_t data[]; +} SMSG;//single messgae +void upSend_thread_entry(void* parameter) +{ + SMSG* msg = RT_NULL; + msg = (SMSG*) parameter; + //打包数据 + uint8_t dout[200]; + static MSG cfg; + rt_memset(&cfg, 0, sizeof(MSG)); // 分配空间 + char fin[30]; + time2Str(fin); + strcat(fin,".bin"); + packInit(&cfg, fin, 0); //写入配置 + cfg.fcurpiece[0] = 1; + cfg.fallpiece[0] = 1; + size_t rst = packMsg(&cfg, msg->data, msg->len, dout); + LOG_HEX("upSend", 27, dout, rst); + if (rst) + { + if (sendMsg(dout, rst) == RT_EOK) + { + tcpClose(); + LOG_I("send to TT Done."); + }; + } + return 0; +} /** * 上傳天通數據 * @param din 待發送數據 @@ -93,20 +124,26 @@ return 0; RT_WEAK int upSend(uint8_t *din, size_t len) { //此函数有打包操作,需线程操作 - LOG_D("upsend."); - return 0; +// LOG_D("upsend."); +// return 0; + static SMSG msg; + memset(&msg, 0, sizeof(SMSG)); + memcpy(msg.data,din,len); + msg.len=len; - uint8_t dout[200]; - //打包数据 - static MSG cfg; - rt_memset(&cfg, 0, sizeof(MSG)); // 分配空间 - char *fin; - time2Str(fin); - packInit(&cfg, fin, 0); //写入配置 - size_t rst = packMsg(&cfg, din, len, dout); - LOG_HEX("upSend", 16, dout, rst); - return 0; + /* 创建 serial 线程 */ + rt_thread_t thread = rt_thread_create("upSend", upSend_thread_entry, (void *) &msg, 1024 * 10, 27, 10); + /* 创建成功则启动线程 */ + if (thread != RT_NULL) + { + rt_thread_startup(thread); + } + else + { + LOG_E("thread 'upSend' create failure."); + return; + } } /** diff --git a/applications/main.c b/applications/main.c index 8596025..2c28f85 100644 --- a/applications/main.c +++ b/applications/main.c @@ -131,7 +131,7 @@ void show_version(void) uint8_t t[10]; size_t len=time2Byte(t); bytes2str(t, len, 10, "", str); - rt_kprintf("SW Version: %s build%s\n","1.44",bytes2str(t, len, 10, "", str)); + rt_kprintf("SW Version: %s, build-%s\n","1.45",bytes2str(t, len, 10, "", str)); } MSH_CMD_EXPORT(show_version,显示版本号); diff --git a/applications/ttmsg/ttmsg.c b/applications/ttmsg/ttmsg.c index 0dd8a8e..b7fdfc0 100644 --- a/applications/ttmsg/ttmsg.c +++ b/applications/ttmsg/ttmsg.c @@ -122,7 +122,9 @@ static size_t getID(const char *str, rt_uint8_t *out) tmp[i] = v; } - LOG_HEX("file ID",16,tmp,len); +// LOG_HEX("file ID",16,tmp,len); + char idstr[30]; + LOG_I("msg id:%s",bytes2str(tmp, len, 16, "_", idstr)); memcpy(out, tmp, len); return len; } diff --git a/applications/uart_3S.c b/applications/uart_3S.c index ea838e4..f80d395 100644 --- a/applications/uart_3S.c +++ b/applications/uart_3S.c @@ -30,7 +30,7 @@ #define SAMPLE_UART_NAME "uart3" /* 串口设备名称 */ #endif #define MAX_SIZE_TO_SAVE 1024*2 -#define MIN_FRAME_LEN 11 +#define MIN_FRAME_LEN 10 /* 串口接收消息结构*/ struct rx_msg {