From 4d76431e9d117c3d1a938d76e99dd0ab352c3a66 Mon Sep 17 00:00:00 2001 From: "CSSC-WORK\\murmur" Date: Fri, 16 Jun 2023 11:26:01 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/repeatSend.c | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 applications/repeatSend.c diff --git a/applications/repeatSend.c b/applications/repeatSend.c new file mode 100644 index 0000000..875e44f --- /dev/null +++ b/applications/repeatSend.c @@ -0,0 +1,10 @@ +/* + * 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程序。固定数据包循环重发 From 30286c7ad0bc2d1dee515e452a7481ad31b224e0 Mon Sep 17 00:00:00 2001 From: "CSSC-WORK\\murmur" Date: Fri, 16 Jun 2023 16:20:18 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E5=8F=91=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); From a8853d57b5042e788248b3c6e4c128358c3fae12 Mon Sep 17 00:00:00 2001 From: "CSSC-WORK\\murmur" Date: Sat, 17 Jun 2023 18:26:40 +0800 Subject: [PATCH 3/6] =?UTF-8?q?log2file.c=20=E6=B5=8B=E8=AF=95ok=20?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E5=8F=91=E9=80=81=E6=B5=8B=E8=AF=95ok=20?= =?UTF-8?q?=E6=8C=81=E7=BB=ADtt=20getinfo.c=20=E5=BE=85=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .config | 30 +++---------- applications/cfg.c | 3 +- applications/cfg.ini | 9 +++- applications/getinfo.c | 81 +++++++++++++++++++++++++++------- applications/log2file.c | 72 ++++++++++++++++++++++++++++++ applications/main.c | 22 ++------- applications/repeatSend.c | 70 ++++++++++++++++++++--------- applications/tools.c | 41 +++++++++-------- applications/ttmsg/ttmsg.c | 12 ++--- applications/uart_dma_sample.c | 2 +- applications/usrcfg.h | 1 + applications/w25q.c | 8 ++-- packages/pkgs.json | 7 +-- rtconfig.h | 17 +++---- 14 files changed, 245 insertions(+), 130 deletions(-) create mode 100644 applications/log2file.c diff --git a/.config b/.config index 48d314d..9a5e59d 100644 --- a/.config +++ b/.config @@ -344,7 +344,7 @@ CONFIG_ULOG_OUTPUT_TAG=y # end of log format CONFIG_ULOG_BACKEND_USING_CONSOLE=y -# CONFIG_ULOG_BACKEND_USING_FILE is not set +CONFIG_ULOG_BACKEND_USING_FILE=y # CONFIG_ULOG_USING_FILTER is not set # CONFIG_ULOG_USING_SYSLOG is not set # CONFIG_RT_USING_UTEST is not set @@ -574,27 +574,7 @@ CONFIG_PKG_CJSON_VER="v1.7.15" # # tools packages # -CONFIG_PKG_USING_CMBACKTRACE=y -# CONFIG_PKG_CMBACKTRACE_PLATFORM_M0_M0PLUS is not set -# CONFIG_PKG_CMBACKTRACE_PLATFORM_M3 is not set -CONFIG_PKG_CMBACKTRACE_PLATFORM_M4=y -# CONFIG_PKG_CMBACKTRACE_PLATFORM_M7 is not set -# CONFIG_PKG_CMBACKTRACE_PLATFORM_M33 is not set -# CONFIG_PKG_CMBACKTRACE_PLATFORM_NOT_SELECTED is not set -CONFIG_PKG_CMBACKTRACE_DUMP_STACK=y -# CONFIG_PKG_CMBACKTRACE_PRINT_ENGLISH is not set -# CONFIG_PKG_CMBACKTRACE_PRINT_CHINESE is not set -CONFIG_PKG_CMBACKTRACE_PRINT_CHINESE_UTF8=y -# CONFIG_CMB_USING_FAL_FLASH_LOG is not set -CONFIG_PKG_CMBACKTRACE_PATH="/packages/tools/CmBacktrace" -CONFIG_PKG_USING_CMBACKTRACE_V10401=y -# CONFIG_PKG_USING_CMBACKTRACE_V10400 is not set -# CONFIG_PKG_USING_CMBACKTRACE_V10300 is not set -# CONFIG_PKG_USING_CMBACKTRACE_V10202 is not set -# CONFIG_PKG_USING_CMBACKTRACE_V10200 is not set -# CONFIG_PKG_USING_CMBACKTRACE_LATEST_VERSION is not set -CONFIG_PKG_CMBACKTRACE_VER="v1.4.1" -CONFIG_PKG_CMBACKTRACE_VER_NUM=0x10401 +# CONFIG_PKG_USING_CMBACKTRACE is not set # CONFIG_PKG_USING_EASYFLASH is not set # CONFIG_PKG_USING_EASYLOGGER is not set # CONFIG_PKG_USING_SYSTEMVIEW is not set @@ -719,9 +699,9 @@ CONFIG_PKG_SYSWATCH_VER="latest" # CONFIG_PKG_USING_RAMDISK is not set CONFIG_PKG_USING_MININI=y CONFIG_PKG_MININI_PATH="/packages/system/minIni" -CONFIG_PKG_USING_MININI_V120=y -# CONFIG_PKG_USING_MININI_LATEST_VERSION is not set -CONFIG_PKG_MININI_VER="v1.2.0" +# CONFIG_PKG_USING_MININI_V120 is not set +CONFIG_PKG_USING_MININI_LATEST_VERSION=y +CONFIG_PKG_MININI_VER="latest" # CONFIG_PKG_USING_QBOOT is not set # CONFIG_PKG_USING_PPOOL is not set # CONFIG_PKG_USING_OPENAMP is not set diff --git a/applications/cfg.c b/applications/cfg.c index e351435..3d69adf 100644 --- a/applications/cfg.c +++ b/applications/cfg.c @@ -7,7 +7,8 @@ * Date Author Notes * 2023-05-29 murmur the first version */ -#include "../packages/minIni-v1.2.0/dev/minIni.h" +//#include "../packages/minIni-v1.2.0/dev/minIni.h" +#include "minIni.h" #ifdef PKG_USING_MININI #define LJW_CFG_FILE_NAME "/cfg/cfg.ini" diff --git a/applications/cfg.ini b/applications/cfg.ini index 933d3f6..ef8dc7b 100644 --- a/applications/cfg.ini +++ b/applications/cfg.ini @@ -1,5 +1,5 @@ [config] -# V1.4 +# V1.5 #发送间隔(M),以零点为基准时刻 sendInterval=60 # 用于保存串口数据的单文件最大值(Byte) @@ -17,7 +17,7 @@ maxTTRetryCnt=3 # TT最低信号值 minTTsinal=5 # TT状态检测周期数 -minTTPeriCnt=5 +minTTPeriCnt=2 compressType=1 encrytType=1 # 开窗时间(UTC+8),持续时间(H)。支持多组,组与组之间采用【;】为分隔符 @@ -40,6 +40,11 @@ minActiveTime=0 maxActiveTime=0 # 平均激活时间,暂不考虑实现 meanActiveTime=0 + +# 总定时器超时次数 +allCnt=0 +# 发送成功次数 +okCnt=0 [tosend] # 文件名=待发包。值为0表示全发。 2023_05_22_11_27_12_245.txt=12 diff --git a/applications/getinfo.c b/applications/getinfo.c index a9eeee1..038ca79 100644 --- a/applications/getinfo.c +++ b/applications/getinfo.c @@ -1,7 +1,7 @@ - +#include #include //#include <../packages/webclient-v2.2.0/inc/webclient.h> #include @@ -29,11 +29,7 @@ //#include char *infoH[] = { TT_SIM, TT_XH, TT_RW, TT_JH, TT_DW}; -//typedef struct -//{ -// rt_uint8_t cnt; -// rt_uint8_t s; -//} CFG; + typedef struct { @@ -53,7 +49,7 @@ typedef struct // char *ele; // 高度 }TT; -TT tmp={.sim="0",.xh="0",.jh="0",.jd=":0.000000",.wd=":0.000000",.ele=":0.000000"}; +TT tmp={.sim="-",.xh="-",.jh="-",.jd=":0.000000",.wd=":0.000000",.ele=":0.000000"}; //memset(&tmp,0x00,sizeof(TT)); TT *TTinfo=&tmp; static rt_tick_t bootstamp=0; @@ -106,6 +102,7 @@ static int minActiveTime=0; static int maxActiveTime=0; //extern struct rt_event sw_check;//软件条件 extern void upTTflag(void); +extern void upTTflagtmp(void);//临时demo static void updatecfg() { minTTsinal = get_cfg("minTTsinal"); @@ -165,6 +162,7 @@ static void rulecheck(void) //TT具备发送条件 // rt_event_send(&sw_check, TT_IS_OK); upTTflag(); + upTTflagtmp(); LOG_D("符合规则,TT具备发送状态。"); // updateSta(); okCnt = minTTPeriCnt -1; @@ -311,6 +309,12 @@ void getTTinfo_thread_entry(void* parameter) } if (webclient_get_data(url) != RT_EOK) { + strcpy(TTinfo->sim,"-"); + strcpy(TTinfo->xh,"-"); + strcpy(TTinfo->jh,"-"); + strcpy(TTinfo->jd,"-"); + strcpy(TTinfo->wd,"-"); + strcpy(TTinfo->ele,"-"); break; } web_free(url); @@ -348,9 +352,6 @@ void getTT(int argc, char **argv) cfg.s = atoi(argv[2]); } -// LOG_D("cnt-%d",cfg.cnt); -// LOG_D("s-%d",cfg.s); - /* 创建 serial 线程 */ rt_thread_t thread = rt_thread_create("getTT", getTTinfo_thread_entry, (void *) &cfg, 1024 * 3, 25, 10); /* 创建成功则启动线程 */ @@ -365,13 +366,63 @@ void getTT(int argc, char **argv) return RT_ERROR; } -// struct rt_thread infoTT_thread; -// ALIGN(RT_ALIGN_SIZE) -// static char thread2_stack[1024*3]; -// rt_thread_init(&infoTT_thread, "getTT", getTTinfo_thread_entry, (void *) &cfg, &thread2_stack[0], sizeof(thread2_stack), 25, 10); -// rt_thread_startup(&infoTT_thread); } /* 导出到自动初始化 */ MSH_CMD_EXPORT(getTT, 获取天通信息,支持参数。 "getTT 3 1" means try 3 times with 1 second interval.); //MSH_CMD_EXPORT_ALIAS(webclient_get_data, gTTinfo, GET info of TT server.); + +int isTTon(void) +{ + return !rt_pin_read(TT_EN); +} + +void repGetTT_thread_entry(void* parameter) +{ + while(!isTTon())//第一次运行时未上电则等待 + {} + while(isTTon())//中间未上电则退出 + { + for (size_t var = 0; var < (sizeof(infoH) / sizeof(infoH[0])); var++) //轮询每个参数 + { + static char *url = RT_NULL; + url = web_strdup(*(infoH + var)); + if (url == RT_NULL) + { + LOG_E("no memory for create getTT url buffer.\n"); +// return -RT_ENOMEM; + } + if (webclient_get_data(url) != RT_EOK) + { + strcpy(TTinfo->sim,"-"); + strcpy(TTinfo->xh,"-"); + strcpy(TTinfo->jh,"-"); + strcpy(TTinfo->jd,"-"); + strcpy(TTinfo->wd,"-"); + strcpy(TTinfo->ele,"-"); + break; + } + web_free(url); + rt_thread_mdelay(100); + } + rulecheck(); + rt_thread_mdelay(3 * 1000);//间隔3s更新一次数据 + } +} + +void repGetTT() +{ + /* 创建 serial 线程 */ + rt_thread_t thread = rt_thread_create("repGetTT", repGetTT_thread_entry, RT_NULL, 1024 * 3, 25, 10); + /* 创建成功则启动线程 */ + if (thread != RT_NULL) + { + rt_thread_startup(thread); + // rt_kprintf("done"); + } + else + { + LOG_E("thread 'repGetTT' create failure."); + return RT_ERROR; + } +} diff --git a/applications/log2file.c b/applications/log2file.c new file mode 100644 index 0000000..216afce --- /dev/null +++ b/applications/log2file.c @@ -0,0 +1,72 @@ +/* + * 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 + */ + + +#include <..\rt-thread\components\utilities\ulog\backend\ulog_be.h> + +/* +* 后端注册表 +*/ +struct _log_file +{ + const char *name; //文件名 + ulog_backend_t backend; + struct ulog_file_be *file_be; + const char *dir_path; //保存路径 + rt_size_t max_num; //保存最大文件数量 + rt_size_t max_size; //保存最大文件大小 + rt_size_t buf_size; //文件保存缓存大小 +}; +/* +* 文件后端标识 +*/ +typedef enum +{ + console_id, + sys_id, + motion_id, +}ulog_file_be_name; + +#define ROOT_PATH "/log" //设置保存路径 +#define FILE_SIZE 512 * 1024 //设置单个文件大小 +#define BUFF_SIZE 512 //设备缓存区大小 + +static struct ulog_backend sys_log_backend; +static struct ulog_file_be sys_log_file; + +static struct _log_file table[] = +{ + {"motion" ,ROOT_PATH,5,FILE_SIZE,BUFF_SIZE}, + {"sys" ,&sys_log_backend,&sys_log_file,ROOT_PATH,10,FILE_SIZE,BUFF_SIZE}, +}; +/* Private function prototypes -----------------------------------------------*/ +/** + * @brief 系统日志文件后端初始化. + * @param None. + * @retval None. + * @note None. +*/ +void sys_log_file_backend_init(void) +{ + struct ulog_file_be *file_be = &sys_log_file; + uint8_t id = sys_id; + file_be->parent = sys_log_backend; + + ulog_file_backend_init( file_be, + table[id].name, + table[id].dir_path, + table[id].max_num, + table[id].max_size, + table[id].buf_size); + + ulog_file_backend_enable(file_be); //必须使能才能有效 +} +MSH_CMD_EXPORT(sys_log_file_backend_init,log2file); +//INIT_APP_EXPORT(sys_log_file_backend_init); diff --git a/applications/main.c b/applications/main.c index 0bbf12f..5fb49d6 100644 --- a/applications/main.c +++ b/applications/main.c @@ -18,8 +18,6 @@ //#include -//static rt_uint8_t d[35][200] = { }; -//static rt_uint8_t s[35] = { }; void pfdemo(void) { // #define cmb_println(...) rt_kprintf(__VA_ARGS__);rt_kprintf("\r\n"); @@ -62,25 +60,11 @@ int main(void) rt_pin_mode(TT_EN, PIN_MODE_OUTPUT); // rt_pin_write(ETH_RESET_PIN, PIN_LOW);//关闭ETH - rt_pin_write(TT_EN, PIN_HIGH);//关闭TT -// rt_err_t ret = RT_EOK; - /* 设 置 日 期 */ -// ret = set_date(2018, 12, 3); -// if (ret != RT_EOK) -// { -// rt_kprintf("set RTC date failed\n"); -// return ret; -// } -// /* 设 置 时 间 */ -// ret = set_time(11, 15, 50); -// if (ret != RT_EOK) -// { -// rt_kprintf("set RTC time failed\n"); -//// return ret; -// } +// rt_pin_write(TT_EN, PIN_HIGH);//关闭TT + + -// rt_kprintf("%d ms since boot.\n",rt_tick_get_millisecond()); while (1) { /* 拉低PIN脚 */ diff --git a/applications/repeatSend.c b/applications/repeatSend.c index 05dd661..11241bf 100644 --- a/applications/repeatSend.c +++ b/applications/repeatSend.c @@ -11,17 +11,20 @@ #include -#define LOG_TAG "repeadSend" +#define LOG_TAG "repeatSend" #define LOG_LVL LOG_LVL_DBG #include #include - +#include /* 定时器的控制块 */ 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); +} void repeatSend_thread_entry() { while (1) @@ -29,22 +32,37 @@ void repeatSend_thread_entry() 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)) +//记录次数 +//此次数为总定时超时次数 + 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) { - // rt_event_send(&tcp_chk, TT_TCP_OK); - for (size_t var = 0; var < len; var++) + 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)) { - sendMsg(d[var], s[var]); -// LOG_D("i = %d", var); - LOG_HEX("d", 27, d[var], s[var]); + 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"); } - tcpClose(); - LOG_I("Done."); + } + else + { + LOG_W("TT is not ready."); } } } @@ -53,7 +71,7 @@ void repeatSend_thread_entry() static void timeout1(void *parameter) { - LOG_D("定时时间到,开始发送数据"); + LOG_D("定时时间到,准备发送数据"); rt_event_send(&readyToSend, TIME_IS_UP); } @@ -64,8 +82,8 @@ void repeatSend_thread_entry() void timer_demo() { /* 创建定时器1 周期定时器 */ - timer1 = rt_timer_create("repeadSendtimer", timeout1, - RT_NULL, rt_tick_from_millisecond(30*1000), + timer1 = rt_timer_create("repeatSendtimer", timeout1, + RT_NULL, rt_tick_from_millisecond(1*60*1000), RT_TIMER_FLAG_PERIODIC); /* 启动定时器1 */ @@ -74,7 +92,7 @@ void repeatSend_thread_entry() // 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); + rt_thread_t thread = rt_thread_create("repsendT", repeatSend_thread_entry, RT_NULL, 1024*3, 25+1, 10); /* 创建成功则启动线程 */ if (thread != RT_NULL) { @@ -88,6 +106,16 @@ void repeatSend_thread_entry() MSH_CMD_EXPORT(timer_demo,定时发送) void inievt() { - rt_err_t result = rt_event_init(&readyToSend, "readyToSend", RT_IPC_FLAG_PRIO); + + pwTT_thread_entry("1"); + rt_err_t result = rt_event_init(&readyToSend, "repSend", RT_IPC_FLAG_PRIO); + rt_hw_stm32_eth_init();//激活网口 } INIT_APP_EXPORT(inievt); +INIT_APP_EXPORT(timer_demo); + + +MSH_CMD_EXPORT(upTTflagtmp,喂数据); + + + diff --git a/applications/tools.c b/applications/tools.c index 86bf2f2..ce7d66b 100644 --- a/applications/tools.c +++ b/applications/tools.c @@ -121,25 +121,25 @@ MSH_CMD_EXPORT(hexFile,以HEX方式显示文件内容); */ int time2Str(char *str) { - struct tm *tm, tm_tmp; - time_t now = time(RT_NULL); - time_t t = (time_t)0; - - if (gettimeofday(&now, RT_NULL) >= 0) - { -// t = now.tv_sec; - } - tm = localtime_r(&t, &tm_tmp); - -// static time_t now; -// static struct tm *tm, tm_tmp; +// struct tm *tm, tm_tmp; +// time_t now = time(RT_NULL); +// time_t t = (time_t)0; // -// now = time(RT_NULL); -// tm = gmtime_r(&now, &tm_tmp); +// if (gettimeofday(&now, RT_NULL) >= 0) +// { +//// t = now.tv_sec; +// } +// tm = localtime_r(&t, &tm_tmp); + + static time_t now; + static struct tm *tm, tm_tmp; + + now = time(RT_NULL); + tm = localtime_r(&now, &tm_tmp); /* show the time format MM-DD HH:MM:SS */ - size_t len = rt_snprintf(str, 20, "%04d_%02d_%02d_%02d_%02d_%02d_%03d", tm->tm_year, tm->tm_mon, - tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); + size_t len = rt_snprintf(str, 30, "%04d_%02d_%02d_%02d_%02d_%02d_%03d", 2000+tm->tm_year-100, tm->tm_mon+1, + tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec,tm->tm_sec); str[len]='\0'; return len; @@ -148,8 +148,13 @@ int time2Str(char *str) - - +void tm2str(int argc, char **argv) +{ + char s[30]; + time2Str(s); + LOG_I("-is %s",s); +} +MSH_CMD_EXPORT(tm2str,时间转换为字符串) void sDemo() { diff --git a/applications/ttmsg/ttmsg.c b/applications/ttmsg/ttmsg.c index 9b466c9..f39a2a9 100644 --- a/applications/ttmsg/ttmsg.c +++ b/applications/ttmsg/ttmsg.c @@ -518,7 +518,7 @@ MSH_CMD_EXPORT(pmsg, 打包文件。); void pwTT_thread_entry(void *parameter) { // LOG_I("--%s--",parameter); - if (strcmp(parameter,"NULL")==0)//无参数 + if (strcmp(parameter,"NULL")==0)//无参数,状态翻转 { // LOG_I("null"); int f = rt_pin_read(TT_EN); @@ -526,9 +526,9 @@ void pwTT_thread_entry(void *parameter) } else { - rt_bool_t flag = (rt_bool_t) atoi(parameter); + rt_bool_t flag = !(rt_bool_t) atoi(parameter); if ((rt_bool_t)rt_pin_read(TT_EN) != flag) {//目标状态与当前状态一致才响应 - rt_pin_write(TT_EN, flag); + rt_pin_write(TT_EN, flag);// } } @@ -536,13 +536,13 @@ void pwTT_thread_entry(void *parameter) if (rt_pin_read(TT_EN))//检查设置后状态 { //#ifdef NO_RELAY - LOG_I("set TT %s", "OFF"); + LOG_I("set TT %s", "OFF");//高电平关断 //#endif add_val("swCnt");//更新统计值 } else { - LOG_I("set TT %s", "ON"); + LOG_I("set TT %s", "ON");//低电平开启 } } @@ -592,7 +592,7 @@ void recTT_thread_entry() static void recTT(void) { - /* 创建 serial 线程 */ + /* 创建线程 */ rt_thread_t thread = rt_thread_create("recTT", recTT_thread_entry, RT_NULL, 1024 * 12, 27, 10); /* 创建成功则启动线程 */ if (thread != RT_NULL) diff --git a/applications/uart_dma_sample.c b/applications/uart_dma_sample.c index a444f1b..d5d1dff 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, 60, + RT_NULL, rt_tick_from_millisecond(40*1000), RT_TIMER_FLAG_PERIODIC); diff --git a/applications/usrcfg.h b/applications/usrcfg.h index 0648a36..4ab0173 100644 --- a/applications/usrcfg.h +++ b/applications/usrcfg.h @@ -23,6 +23,7 @@ typedef struct { rt_uint8_t cnt; rt_uint8_t s; + rt_uint8_t repeat; } CFG; diff --git a/applications/w25q.c b/applications/w25q.c index 3e2540c..691bd68 100644 --- a/applications/w25q.c +++ b/applications/w25q.c @@ -23,6 +23,7 @@ int rt_hw_spi_flash_init(void) { + rt_kprintf("SW Version: %s\n","1.3(temp)"); __HAL_RCC_GPIOB_CLK_ENABLE(); // __HAL_RCC_GPIOD_CLK_ENABLE(); // rt_kprintf("sfud success.\n"); @@ -34,10 +35,7 @@ int rt_hw_spi_flash_init(void) rt_kprintf("sfud error.\n"); return -RT_ERROR; }; -// rt_kprintf("--%d.\n",rt_tick_get_millisecond()-t); -// rt_device_register(&(rtt_dev->flash_device), "W25Q128", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE); - - rt_kprintf("sfud success.\n"); +// rt_kprintf("sfud success.\n"); return RT_EOK; } /* 导出到自动初始化 */ @@ -51,7 +49,7 @@ void w25q128_mount(void) dev = rt_device_find("W25Q128"); if(dev != RT_NULL) { if(dfs_mount("W25Q128", "/", "elm", 0, 0) == 0){ - rt_kprintf("spi_flash mount to spi!\n"); +// rt_kprintf("spi_flash mount to spi!\n"); } else { rt_kprintf("spi_flash mount to spi failed!\n"); } diff --git a/packages/pkgs.json b/packages/pkgs.json index 07a4868..9410958 100644 --- a/packages/pkgs.json +++ b/packages/pkgs.json @@ -9,11 +9,6 @@ "ver": "v1.7.15", "name": "CJSON" }, - { - "path": "/packages/tools/CmBacktrace", - "ver": "v1.4.1", - "name": "CMBACKTRACE" - }, { "path": "/packages/system/syswatch", "ver": "latest", @@ -21,7 +16,7 @@ }, { "path": "/packages/system/minIni", - "ver": "v1.2.0", + "ver": "latest", "name": "MININI" }, { diff --git a/rtconfig.h b/rtconfig.h index e113a74..49fbab5 100644 --- a/rtconfig.h +++ b/rtconfig.h @@ -49,7 +49,7 @@ #define RT_USING_DEVICE #define RT_USING_CONSOLE #define RT_CONSOLEBUF_SIZE 256 -#define RT_CONSOLE_DEVICE_NAME "uart1" +#define RT_CONSOLE_DEVICE_NAME "uart3" /* end of Kernel Device Object */ #define RT_VER_NUM 0x40101 /* end of RT-Thread Kernel */ @@ -62,14 +62,14 @@ #define RT_USING_COMPONENTS_INIT #define RT_USING_USER_MAIN -#define RT_MAIN_THREAD_STACK_SIZE 2048*2 +#define RT_MAIN_THREAD_STACK_SIZE 2048 #define RT_MAIN_THREAD_PRIORITY 10 #define RT_USING_MSH #define RT_USING_FINSH #define FINSH_USING_MSH #define FINSH_THREAD_NAME "tshell" -#define FINSH_THREAD_PRIORITY 30 -#define FINSH_THREAD_STACK_SIZE 4096*2 +#define FINSH_THREAD_PRIORITY 20 +#define FINSH_THREAD_STACK_SIZE 4096 #define FINSH_USING_HISTORY #define FINSH_HISTORY_LINES 5 #define FINSH_USING_SYMTAB @@ -207,6 +207,7 @@ #define ULOG_OUTPUT_TAG /* end of log format */ #define ULOG_BACKEND_USING_CONSOLE +#define ULOG_BACKEND_USING_FILE /* end of Utilities */ /* end of RT-Thread Components */ @@ -269,12 +270,6 @@ /* tools packages */ -//#define PKG_USING_CMBACKTRACE -//#define PKG_CMBACKTRACE_PLATFORM_M4 -//#define PKG_CMBACKTRACE_DUMP_STACK -//#define PKG_CMBACKTRACE_PRINT_CHINESE_UTF8 -//#define PKG_USING_CMBACKTRACE_V10401 -//#define PKG_CMBACKTRACE_VER_NUM 0x10401 /* end of tools packages */ /* system packages */ @@ -307,7 +302,7 @@ #define SYSWATCH_WDT_TIMEOUT 5 #define PKG_USING_SYSWATCH_LATEST_VERSION #define PKG_USING_MININI -#define PKG_USING_MININI_V120 +#define PKG_USING_MININI_LATEST_VERSION /* end of system packages */ /* peripheral libraries and drivers */ From 40c903ca570aa4e9ae020e25b1c899cda1c9fbfa Mon Sep 17 00:00:00 2001 From: "CSSC-WORK\\murmur" Date: Sun, 18 Jun 2023 09:34:09 +0800 Subject: [PATCH 4/6] =?UTF-8?q?v1.5=20=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=BE=85=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/cfg.c | 2 +- applications/getinfo.c | 55 ++++++++++++++++++++------------------ applications/main.c | 8 ++++++ applications/repeatSend.c | 5 ++-- applications/ttmsg/ttmsg.c | 2 +- applications/w25q.c | 2 +- 6 files changed, 43 insertions(+), 31 deletions(-) diff --git a/applications/cfg.c b/applications/cfg.c index 3d69adf..fd5e7c0 100644 --- a/applications/cfg.c +++ b/applications/cfg.c @@ -271,7 +271,7 @@ void add(int argc, char **argv) } MSH_CMD_EXPORT(gf, 查看待发送文件列表) -MSH_CMD_EXPORT_ALIAS(add, cf,查看待发送文件列表) +//MSH_CMD_EXPORT_ALIAS(add, cf,查看待发送文件列表) //set_if() #endif diff --git a/applications/getinfo.c b/applications/getinfo.c index 038ca79..ca5df56 100644 --- a/applications/getinfo.c +++ b/applications/getinfo.c @@ -49,7 +49,7 @@ typedef struct // char *ele; // 高度 }TT; -TT tmp={.sim="-",.xh="-",.jh="-",.jd=":0.000000",.wd=":0.000000",.ele=":0.000000"}; +TT tmp={.sim="-",.xh="-",.jh="-",.jd="-",.wd="-",.ele="-"}; //memset(&tmp,0x00,sizeof(TT)); TT *TTinfo=&tmp; static rt_tick_t bootstamp=0; @@ -163,7 +163,7 @@ static void rulecheck(void) // rt_event_send(&sw_check, TT_IS_OK); upTTflag(); upTTflagtmp(); - LOG_D("符合规则,TT具备发送状态。"); + LOG_I("符合规则,TT具备发送状态。"); // updateSta(); okCnt = minTTPeriCnt -1; } @@ -298,29 +298,29 @@ void getTTinfo_thread_entry(void* parameter) rt_kprintf("%5s%5s%5s%5s%15s%15s%10s\n", "SIM", "xh", "rw", "jh", "N", "E", "ele"); for (i = 0; i < cfg->cnt; ++i) //按指定次数轮询 { - for (var = 0; var < isize; var++) //轮询每个参数 - { - static char *url = RT_NULL; - url = web_strdup(*(infoH + var)); - if (url == RT_NULL) - { - LOG_E("no memory for create getTT url buffer.\n"); -// return -RT_ENOMEM; - } - if (webclient_get_data(url) != RT_EOK) - { - strcpy(TTinfo->sim,"-"); - strcpy(TTinfo->xh,"-"); - strcpy(TTinfo->jh,"-"); - strcpy(TTinfo->jd,"-"); - strcpy(TTinfo->wd,"-"); - strcpy(TTinfo->ele,"-"); - break; - } - web_free(url); - rt_thread_mdelay(100); - } - rulecheck(); +// for (var = 0; var < isize; var++) //轮询每个参数 +// { +// static char *url = RT_NULL; +// url = web_strdup(*(infoH + var)); +// if (url == RT_NULL) +// { +// LOG_E("no memory for create getTT url buffer.\n"); +//// return -RT_ENOMEM; +// } +// if (webclient_get_data(url) != RT_EOK) +// { +// strcpy(TTinfo->sim,"-"); +// strcpy(TTinfo->xh,"-"); +// strcpy(TTinfo->jh,"-"); +// strcpy(TTinfo->jd,"-"); +// strcpy(TTinfo->wd,"-"); +// strcpy(TTinfo->ele,"-"); +// break; +// } +// web_free(url); +// rt_thread_mdelay(100); +// } +// rulecheck(); rt_kprintf("%5s%5s%5s%5s%15s%15s%10s\n", TTinfo->sim, TTinfo->xh, TTinfo->rw, TTinfo->jh, TTinfo->jd, TTinfo->wd, TTinfo->ele); if (i != cfg->cnt - 1) //最后一次采集不延时 @@ -410,7 +410,10 @@ void repGetTT_thread_entry(void* parameter) } } -void repGetTT() +/** + * 持续更新TT状态信息,数据3s刷新一次。TT断电后退出。 + */ +void repGetTT(void) { /* 创建 serial 线程 */ rt_thread_t thread = rt_thread_create("repGetTT", repGetTT_thread_entry, RT_NULL, 1024 * 3, 25, 10); diff --git a/applications/main.c b/applications/main.c index 5fb49d6..654fc1d 100644 --- a/applications/main.c +++ b/applications/main.c @@ -118,3 +118,11 @@ void pp(int argc, char **argv) MSH_CMD_EXPORT(pp, 打包文件。); extern int rt_hw_stm32_eth_init(void); MSH_CMD_EXPORT(rt_hw_stm32_eth_init, 初始化网络。); + +void show_version(void) +{ + rt_kprintf("SW Version: %s\n","1.5(temp)"); +} + +MSH_CMD_EXPORT(show_version,显示版本号); +INIT_COMPONENT_EXPORT(show_version); diff --git a/applications/repeatSend.c b/applications/repeatSend.c index 11241bf..29a3213 100644 --- a/applications/repeatSend.c +++ b/applications/repeatSend.c @@ -90,7 +90,6 @@ void repeatSend_thread_entry() 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); /* 创建成功则启动线程 */ @@ -107,9 +106,11 @@ void repeatSend_thread_entry() void inievt() { - pwTT_thread_entry("1"); + pwTT_thread_entry("1");//开机 rt_err_t result = rt_event_init(&readyToSend, "repSend", RT_IPC_FLAG_PRIO); rt_hw_stm32_eth_init();//激活网口 + rt_thread_mdelay(10*1000); + repGetTT();//持续更新 } INIT_APP_EXPORT(inievt); INIT_APP_EXPORT(timer_demo); diff --git a/applications/ttmsg/ttmsg.c b/applications/ttmsg/ttmsg.c index f39a2a9..0b1584a 100644 --- a/applications/ttmsg/ttmsg.c +++ b/applications/ttmsg/ttmsg.c @@ -513,7 +513,7 @@ MSH_CMD_EXPORT(pmsg, 打包文件。); /** * 天通上电 - * @param parameter + * @param parameter "0"断电,其它上电 */ void pwTT_thread_entry(void *parameter) { diff --git a/applications/w25q.c b/applications/w25q.c index 691bd68..e60541b 100644 --- a/applications/w25q.c +++ b/applications/w25q.c @@ -23,7 +23,7 @@ int rt_hw_spi_flash_init(void) { - rt_kprintf("SW Version: %s\n","1.3(temp)"); +// rt_kprintf("SW Version: %s\n","1.4(temp)"); __HAL_RCC_GPIOB_CLK_ENABLE(); // __HAL_RCC_GPIOD_CLK_ENABLE(); // rt_kprintf("sfud success.\n"); From 99c8764fe8d4ca42b0502191312aff7241ab57e4 Mon Sep 17 00:00:00 2001 From: "CSSC-WORK\\murmur" Date: Mon, 19 Jun 2023 15:56:45 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90demo=20?= =?UTF-8?q?=E7=89=88=E6=9C=AC1.9(demo)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .config | 16 +++++++---- applications/_main.c | 6 ++-- applications/cfg.c | 3 +- applications/getinfo.c | 46 +++++++++++++++++++++++++++--- applications/log2file.c | 6 ++-- applications/main.c | 54 +++++++++++++++++++----------------- applications/repeatSend.c | 41 +++++++++++++++++++-------- applications/tools.c | 12 ++++++++ applications/ttTR.c | 16 ++++++----- applications/ttmsg/ttmsg.c | 11 ++++---- applications/w25q.c | 26 +++++++++++++++-- drivers/board.c | 49 ++++++++++++++++++++++++++++++++ drivers/board.h | 2 +- drivers/stm32f4xx_hal_conf.h | 2 +- rtconfig.h | 8 +++++- 15 files changed, 227 insertions(+), 71 deletions(-) diff --git a/.config b/.config index 9a5e59d..fa57059 100644 --- a/.config +++ b/.config @@ -81,7 +81,7 @@ CONFIG_RT_USING_DEVICE=y # CONFIG_RT_USING_INTERRUPT_INFO is not set CONFIG_RT_USING_CONSOLE=y CONFIG_RT_CONSOLEBUF_SIZE=256 -CONFIG_RT_CONSOLE_DEVICE_NAME="uart1" +CONFIG_RT_CONSOLE_DEVICE_NAME="uart3" # end of Kernel Device Object CONFIG_RT_VER_NUM=0x40101 @@ -179,7 +179,13 @@ CONFIG_RT_USING_ADC=y CONFIG_RT_USING_RTC=y # CONFIG_RT_USING_ALARM is not set # CONFIG_RT_USING_SOFT_RTC is not set -# CONFIG_RT_USING_SDIO is not set +CONFIG_RT_USING_SDIO=y +CONFIG_RT_SDIO_STACK_SIZE=512 +CONFIG_RT_SDIO_THREAD_PRIORITY=15 +CONFIG_RT_MMCSD_STACK_SIZE=1024 +CONFIG_RT_MMCSD_THREAD_PREORITY=22 +CONFIG_RT_MMCSD_MAX_PARTITION=16 +# CONFIG_RT_SDIO_DEBUG is not set CONFIG_RT_USING_SPI=y # CONFIG_RT_USING_SPI_BITOPS is not set # CONFIG_RT_USING_QSPI is not set @@ -270,8 +276,8 @@ CONFIG_RT_LWIP_DNS=y # # Static IPv4 Address # -CONFIG_RT_LWIP_IPADDR="192.168.0.30" -CONFIG_RT_LWIP_GWADDR="192.168.0.1" +CONFIG_RT_LWIP_IPADDR="10.10.10.10" +CONFIG_RT_LWIP_GWADDR="10.10.10.1" CONFIG_RT_LWIP_MSKADDR="255.255.255.0" # end of Static IPv4 Address @@ -686,7 +692,7 @@ CONFIG_SYSWATCH_EXCEPT_TIMEOUT=60 CONFIG_SYSWATCH_EXCEPT_CONFIRM_TMO=15 CONFIG_SYSWATCH_EXCEPT_RESUME_DLY=15 CONFIG_SYSWATCH_THREAD_PRIO=0 -CONFIG_SYSWATCH_THREAD_STK_SIZE=512 +CONFIG_SYSWATCH_THREAD_STK_SIZE=1024 CONFIG_SYSWATCH_THREAD_NAME="syswatch" CONFIG_SYSWATCH_WDT_NAME="wdt" CONFIG_SYSWATCH_WDT_TIMEOUT=5 diff --git a/applications/_main.c b/applications/_main.c index 8118dbc..629d9df 100644 --- a/applications/_main.c +++ b/applications/_main.c @@ -21,7 +21,7 @@ #include static struct rt_event sw_check;//软件条件 static struct rt_event hw_check;//硬件条件 -struct rt_event tcp_chk;//tcp条件 +//struct rt_event tcp_chk;//tcp条件 //#define FILE_IS_OK 1 //#define TIMER_IS_OUT 1<<1 //#define TT_IS_OK 1<<2 @@ -36,7 +36,7 @@ static void initEvent(void) rt_err_t result = rt_event_init(&sw_check, "SHcheck", RT_IPC_FLAG_PRIO); result = rt_event_init(&hw_check, "HWcheck", RT_IPC_FLAG_PRIO) | result; - result = rt_event_init(&tcp_chk, "tcpTT", RT_IPC_FLAG_PRIO) | result; +// result = rt_event_init(&tcp_chk, "tcpTT", RT_IPC_FLAG_PRIO) | result; if (result != RT_EOK) { @@ -360,5 +360,5 @@ void smsg() return; } } -INIT_COMPONENT_EXPORT(smsg); +//INIT_COMPONENT_EXPORT(smsg); MSH_CMD_EXPORT(smsg,smsg); diff --git a/applications/cfg.c b/applications/cfg.c index fd5e7c0..316a12b 100644 --- a/applications/cfg.c +++ b/applications/cfg.c @@ -81,7 +81,7 @@ int get_cfg(const char *k) } else { // LOG_I("%s = %s",k,buf); - LOG_I("%s = %d",k,rst); +// LOG_I("%s = %d",k,rst); } return rst; } @@ -164,6 +164,7 @@ int set_val(const char *k, long v) int add_val(const char *k) { long ori = get_val(k); + rt_thread_mdelay(100); if (ori != -1) { return set_val(k, ori+1); } diff --git a/applications/getinfo.c b/applications/getinfo.c index ca5df56..8b948a9 100644 --- a/applications/getinfo.c +++ b/applications/getinfo.c @@ -143,7 +143,7 @@ static void rulecheck(void) //满足加1,不满足清零 static rt_uint16_t okCnt=0; if (!okCnt) { - LOG_I("当前规则为:连续%d个采集周期TT信号质量不低于%d",minTTPeriCnt,minTTsinal); + LOG_D("当前规则为:连续%d个采集周期TT信号质量不低于%d",minTTPeriCnt,minTTsinal); } int xh=atoi(TTinfo->xh); if (xh == 99) { @@ -161,7 +161,7 @@ static void rulecheck(void) if (okCnt >= minTTPeriCnt) { //TT具备发送条件 // rt_event_send(&sw_check, TT_IS_OK); - upTTflag(); +// upTTflag(); upTTflagtmp(); LOG_I("符合规则,TT具备发送状态。"); // updateSta(); @@ -269,6 +269,10 @@ static int webclient_get_data(const char *url) if (webclient_request(url, RT_NULL, RT_NULL, 0, (void **) &buffer, &length) < 0) { LOG_E("TT server is not ready."); + if (buffer) + { + web_free(buffer); + } return -RT_ERROR; } @@ -390,10 +394,12 @@ void repGetTT_thread_entry(void* parameter) if (url == RT_NULL) { LOG_E("no memory for create getTT url buffer.\n"); + break; // return -RT_ENOMEM; } if (webclient_get_data(url) != RT_EOK) { + web_free(url); strcpy(TTinfo->sim,"-"); strcpy(TTinfo->xh,"-"); strcpy(TTinfo->jh,"-"); @@ -403,7 +409,7 @@ void repGetTT_thread_entry(void* parameter) break; } web_free(url); - rt_thread_mdelay(100); +// rt_thread_mdelay(100); } rulecheck(); rt_thread_mdelay(3 * 1000);//间隔3s更新一次数据 @@ -416,7 +422,7 @@ void repGetTT_thread_entry(void* parameter) void repGetTT(void) { /* 创建 serial 线程 */ - rt_thread_t thread = rt_thread_create("repGetTT", repGetTT_thread_entry, RT_NULL, 1024 * 3, 25, 10); + rt_thread_t thread = rt_thread_create("repGetTT", repGetTT_thread_entry, RT_NULL, 1024 * 3, 27, 10); /* 创建成功则启动线程 */ if (thread != RT_NULL) { @@ -429,3 +435,35 @@ void repGetTT(void) return RT_ERROR; } } +MSH_CMD_EXPORT(repGetTT,gett); + + + +//由于 + +// +//static rt_timer_t timer1; +///* 定时器1超时函数 */ +//static void timeout1(void *parameter) +//{ +// +//// LOG_D("定时时间到,准备发送数据"); +// if (isTTon()) { +// repGetTT(); +// } +// else { +// rt_timer_stop(timer1); +// } +//// rt_event_send(&readyToSend, TIME_IS_UP); +//} +//void runTT() +//{ +///* 创建定时器1 周期定时器 */ +//timer1 = rt_timer_create("TTinfotimer", timeout1, +// RT_NULL, rt_tick_from_millisecond(3*1000), +// RT_TIMER_FLAG_PERIODIC); +// +///* 启动定时器1 */ +//if (timer1 != RT_NULL && isTTon()) +// rt_timer_start(timer1); +//} diff --git a/applications/log2file.c b/applications/log2file.c index 216afce..761f287 100644 --- a/applications/log2file.c +++ b/applications/log2file.c @@ -34,7 +34,7 @@ typedef enum motion_id, }ulog_file_be_name; -#define ROOT_PATH "/log" //设置保存路径 +#define ROOT_PATH "/sd/syslog" //设置保存路径 #define FILE_SIZE 512 * 1024 //设置单个文件大小 #define BUFF_SIZE 512 //设备缓存区大小 @@ -43,8 +43,8 @@ static struct ulog_file_be sys_log_file; static struct _log_file table[] = { - {"motion" ,ROOT_PATH,5,FILE_SIZE,BUFF_SIZE}, - {"sys" ,&sys_log_backend,&sys_log_file,ROOT_PATH,10,FILE_SIZE,BUFF_SIZE}, + {"motion" ,&sys_log_backend,&sys_log_file,ROOT_PATH,5,FILE_SIZE,BUFF_SIZE}, + {"23-sys" ,&sys_log_backend,&sys_log_file,ROOT_PATH,10,FILE_SIZE,BUFF_SIZE}, }; /* Private function prototypes -----------------------------------------------*/ /** diff --git a/applications/main.c b/applications/main.c index 654fc1d..99d9254 100644 --- a/applications/main.c +++ b/applications/main.c @@ -18,30 +18,6 @@ //#include -void pfdemo(void) -{ -// #define cmb_println(...) rt_kprintf(__VA_ARGS__);rt_kprintf("\r\n"); -// char *f = "1023_05_19_15_29_59_254.txt"; -// char *f = "2023_05_19_15_29_59_255.txt"; - char *f = "2023_06_16_10_28_00_123.bin"; - static rt_uint8_t d[50][200] = { }; - static rt_uint8_t s[50] = { }; - rt_uint8_t len = 0; - LOG_D("%p--%p",d,s); - LOG_I("pack %s ...",f); - len = pack_File(f, 0, d, s); - rt_kprintf("len is %d\n", len); - if (len) - { - for (size_t var = 0; var < len; var++) { - LOG_HEX("d",27,d[var],s[var]); - } -// LOG_HEX("pkdata:",27,d[0],s[0]); -// LOG_D("%p--%p",d,s); -// LOG_D("%d--%d--%02X",len,s[0],d[0][0]); - LOG_I("Done."); - } -} @@ -94,7 +70,31 @@ int main(void) return RT_EOK; } //fastlz_test -c demo.bin f.bin - +#ifdef DEMO +void pfdemo(void) +{ +// #define cmb_println(...) rt_kprintf(__VA_ARGS__);rt_kprintf("\r\n"); +// char *f = "1023_05_19_15_29_59_254.txt"; +// char *f = "2023_05_19_15_29_59_255.txt"; + char *f = "2023_06_16_10_28_00_123.bin"; + static rt_uint8_t d[10][200] = { }; + static rt_uint8_t s[10] = { }; + rt_uint8_t len = 0; + LOG_D("%p--%p",d,s); + LOG_I("pack %s ...",f); + len = pack_File(f, 0, d, s); + rt_kprintf("len is %d\n", len); + if (len) + { + for (size_t var = 0; var < len; var++) { + LOG_HEX("d",27,d[var],s[var]); + } +// LOG_HEX("pkdata:",27,d[0],s[0]); +// LOG_D("%p--%p",d,s); +// LOG_D("%d--%d--%02X",len,s[0],d[0][0]); + LOG_I("Done."); + } +} void pp(int argc, char **argv) { // if (argc == 2) @@ -116,12 +116,14 @@ void pp(int argc, char **argv) } MSH_CMD_EXPORT(pp, 打包文件。); +#endif + extern int rt_hw_stm32_eth_init(void); MSH_CMD_EXPORT(rt_hw_stm32_eth_init, 初始化网络。); void show_version(void) { - rt_kprintf("SW Version: %s\n","1.5(temp)"); + rt_kprintf("SW Version: %s\n","1.9(temp)"); } MSH_CMD_EXPORT(show_version,显示版本号); diff --git a/applications/repeatSend.c b/applications/repeatSend.c index 29a3213..0e49867 100644 --- a/applications/repeatSend.c +++ b/applications/repeatSend.c @@ -20,13 +20,26 @@ /* 定时器的控制块 */ static rt_timer_t timer1; static struct rt_event readyToSend; + +static rt_sem_t ttack= RT_NULL; #define TIME_IS_UP 1<<1 void upTTflagtmp(void) { - rt_event_send(&readyToSend, TT_IS_OK); +// rt_event_send(&readyToSend, TT_IS_OK); + rt_sem_release(ttack); } + + void repeatSend_thread_entry() { + static rt_uint8_t d[10][200] = { }; + static rt_uint8_t s[10] = { }; + while(tcpInit() != RT_EOK) + { + LOG_W("TT server is not ready."); + rt_thread_mdelay(100); + } + LOG_D("TT server is ready."); while (1) { if (rt_event_recv(&readyToSend, TIME_IS_UP, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, @@ -35,25 +48,28 @@ void repeatSend_thread_entry() //记录次数 //此次数为总定时超时次数 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) +// 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)//等待1分钟 + if(rt_sem_take(ttack, rt_tick_from_millisecond(1 * 60 * 1000)) == RT_EOK) { 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)) + LOG_D("Pack done."); + if (len) { for (size_t var = 0; var < len; var++) { sendMsg(d[var], s[var]); + rt_uint8_t rd[30]; + tcpRec(rd); + LOG_HEX("ack",16,rd,30); rt_thread_mdelay(1000); // LOG_HEX("d", 27, d[var], s[var]); } - tcpClose(); +// tcpClose(); LOG_I("send msg Done."); //记录次数 //此次数为发送成功次数 @@ -83,7 +99,7 @@ void repeatSend_thread_entry() { /* 创建定时器1 周期定时器 */ timer1 = rt_timer_create("repeatSendtimer", timeout1, - RT_NULL, rt_tick_from_millisecond(1*60*1000), + RT_NULL, rt_tick_from_millisecond(5*60*1000), RT_TIMER_FLAG_PERIODIC); /* 启动定时器1 */ @@ -91,7 +107,7 @@ void repeatSend_thread_entry() rt_timer_start(timer1); /* 创建 serial 线程 */ - rt_thread_t thread = rt_thread_create("repsendT", repeatSend_thread_entry, RT_NULL, 1024*3, 25+1, 10); + rt_thread_t thread = rt_thread_create("repSendT", repeatSend_thread_entry, RT_NULL, 1024*3, 25+1, 10); /* 创建成功则启动线程 */ if (thread != RT_NULL) { @@ -107,10 +123,13 @@ void inievt() { pwTT_thread_entry("1");//开机 - rt_err_t result = rt_event_init(&readyToSend, "repSend", RT_IPC_FLAG_PRIO); + rt_event_init(&readyToSend, "repSend", RT_IPC_FLAG_PRIO); + ttack = rt_sem_create("ttack", 0, RT_IPC_FLAG_PRIO); + rt_hw_stm32_eth_init();//激活网口 rt_thread_mdelay(10*1000); repGetTT();//持续更新 +// runTT(); } INIT_APP_EXPORT(inievt); INIT_APP_EXPORT(timer_demo); diff --git a/applications/tools.c b/applications/tools.c index ce7d66b..000d4a0 100644 --- a/applications/tools.c +++ b/applications/tools.c @@ -166,6 +166,18 @@ void sDemo() MSH_CMD_EXPORT(sDemo,喂文件数据); +/** + * 关闭网口,去初始化,释放内存 + */ +RT_WEAK void rt_hw_stm32_eth_deinit() +{ + +} +MSH_CMD_EXPORT(rt_hw_stm32_eth_deinit, 去初始化网络。); + + + + static struct rt_thread infoTT_thread; void ttinfoInit() { diff --git a/applications/ttTR.c b/applications/ttTR.c index cadecb4..b86a99b 100644 --- a/applications/ttTR.c +++ b/applications/ttTR.c @@ -85,6 +85,7 @@ static int tcpSend(const rt_uint8_t *send_data, size_t len) if (ret == len) { + LOG_D("send %d Bytes ok.",len); ret = RT_EOK; } else @@ -182,14 +183,15 @@ int sendMsg(const rt_uint8_t *msg, size_t len) tcpClose(); return RT_ERROR; } +//#define CHK_ACK +#ifdef CHK_ACK + if (tcpAck() != RT_EOK) + { + return RT_ERROR; +// break; + }; -// if (tcpRec() != RT_EOK) -// { -// tcpClose(); -// return RT_ERROR; -// }; - -// tcpClose(); +#endif return RT_EOK; } diff --git a/applications/ttmsg/ttmsg.c b/applications/ttmsg/ttmsg.c index 0b1584a..52b618d 100644 --- a/applications/ttmsg/ttmsg.c +++ b/applications/ttmsg/ttmsg.c @@ -372,13 +372,13 @@ rt_uint8_t pack_File(const char *fin, rt_uint8_t flag, const rt_uint8_t (*dout)[ return len; } - static char d[40][200]; - static char s[40]; +#ifdef PF // static rt_uint8_t *buffer = RT_NULL; // static MSG cfg; static int pf_thread_entry(void* parameter) { - + static char d[30][200]; + static char s[30]; char *f = (char *) parameter; // static char d[5][200]; // static char s[5]; @@ -471,7 +471,7 @@ static int pf_thread_entry(void* parameter) { sendMsg(d[var], s[var]); LOG_D("i = %d",var); - LOG_HEX("d", 27, d[var], s[var]); +// LOG_HEX("d", 27, d[var], s[var]); } tcpClose(); LOG_I("Done."); @@ -487,7 +487,7 @@ static int pmsg(int argc, char **argv) strcpy(c, argv[1]); /* 创建线程 */ - rt_thread_t thread = rt_thread_create("pmsg", pf_thread_entry, (void *) c, 1024 * 20, 25, 10); + rt_thread_t thread = rt_thread_create("pmsg", pf_thread_entry, (void *) c, 1024 * 2, 25, 10); /* 创建成功则启动线程 */ if (thread != RT_NULL) { @@ -510,6 +510,7 @@ static int pmsg(int argc, char **argv) #include MSH_CMD_EXPORT(pmsg, 打包文件。); +#endif /** * 天通上电 diff --git a/applications/w25q.c b/applications/w25q.c index e60541b..bba67a4 100644 --- a/applications/w25q.c +++ b/applications/w25q.c @@ -54,9 +54,6 @@ void w25q128_mount(void) rt_kprintf("spi_flash mount to spi failed!\n"); } } - - rt_kprintf("%d ms since boot.\n",rt_tick_get_millisecond()); - add_val("bootCnt"); } @@ -64,3 +61,26 @@ void w25q128_mount(void) INIT_COMPONENT_EXPORT(w25q128_mount); +void sdmnt_init(void) +{ + rt_thread_mdelay(100);//这段延时必须加上,系统上电过程中存在延时,否则会出现先挂载后注册块设备sd0的情况 +// mkfs("elm","sd0");//挂在前需格式化 + if(dfs_mount("sd0","/sd","elm",0,0)==0) //挂载文件系统,参数:块设备名称、挂载目录、文件系统类型、读写标志、私有数据0 + { +// rt_kprintf("dfs mount success\r\n"); + } + else + { + rt_kprintf("dfs mount failed\r\n"); + } +} +/* 导出到自动初始化 */ +INIT_COMPONENT_EXPORT(sdmnt_init); + +void bootinfo() +{ + rt_kprintf("%d ms since boot.\n", rt_tick_get_millisecond()); + add_val("bootCnt"); +} +/* 导出到自动初始化 */ +INIT_COMPONENT_EXPORT(bootinfo); diff --git a/drivers/board.c b/drivers/board.c index 40a8c92..5891af6 100644 --- a/drivers/board.c +++ b/drivers/board.c @@ -179,3 +179,52 @@ void phy_reset(void) } //242.16 KB /51556-64564-70868 add ETH + +/** +* @brief SD MSP Initialization +* This function configures the hardware resources used in this example +* @param hsd: SD handle pointer +* @retval None +*/ +void HAL_SD_MspInit(SD_HandleTypeDef* hsd) +{ + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(hsd->Instance==SDIO) + { + /* USER CODE BEGIN SDIO_MspInit 0 */ + + /* USER CODE END SDIO_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_SDIO_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOD_CLK_ENABLE(); + /**SDIO GPIO Configuration + PC8 ------> SDIO_D0 + PC9 ------> SDIO_D1 + PC10 ------> SDIO_D2 + PC11 ------> SDIO_D3 + PC12 ------> SDIO_CK + PD2 ------> SDIO_CMD + */ + GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11 + |GPIO_PIN_12; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF12_SDIO; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = GPIO_PIN_2; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF12_SDIO; + HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /* USER CODE BEGIN SDIO_MspInit 1 */ + + /* USER CODE END SDIO_MspInit 1 */ + } + +} diff --git a/drivers/board.h b/drivers/board.h index 361236c..f50e1d7 100644 --- a/drivers/board.h +++ b/drivers/board.h @@ -284,7 +284,7 @@ extern "C" * */ -/*#define BSP_USING_SDIO*/ +#define BSP_USING_SDIO /*-------------------------- SDIO CONFIG END --------------------------*/ diff --git a/drivers/stm32f4xx_hal_conf.h b/drivers/stm32f4xx_hal_conf.h index 4590571..14bbc2e 100644 --- a/drivers/stm32f4xx_hal_conf.h +++ b/drivers/stm32f4xx_hal_conf.h @@ -71,7 +71,7 @@ /* #define HAL_RNG_MODULE_ENABLED */ #define HAL_RTC_MODULE_ENABLED /* #define HAL_SAI_MODULE_ENABLED */ -/* #define HAL_SD_MODULE_ENABLED */ + #define HAL_SD_MODULE_ENABLED /* #define HAL_MMC_MODULE_ENABLED */ #define HAL_SPI_MODULE_ENABLED /* #define HAL_TIM_MODULE_ENABLED */ diff --git a/rtconfig.h b/rtconfig.h index 49fbab5..69ca530 100644 --- a/rtconfig.h +++ b/rtconfig.h @@ -111,6 +111,12 @@ #define RT_USING_PIN #define RT_USING_ADC #define RT_USING_RTC +#define RT_USING_SDIO +#define RT_SDIO_STACK_SIZE 512 +#define RT_SDIO_THREAD_PRIORITY 15 +#define RT_MMCSD_STACK_SIZE 1024 +#define RT_MMCSD_THREAD_PREORITY 22 +#define RT_MMCSD_MAX_PARTITION 16 #define RT_USING_SPI #define RT_USING_SFUD #define RT_SFUD_USING_SFDP @@ -296,7 +302,7 @@ #define SYSWATCH_EXCEPT_CONFIRM_TMO 15 #define SYSWATCH_EXCEPT_RESUME_DLY 15 #define SYSWATCH_THREAD_PRIO 0 -#define SYSWATCH_THREAD_STK_SIZE 512*2 +#define SYSWATCH_THREAD_STK_SIZE 1024 #define SYSWATCH_THREAD_NAME "syswatch" #define SYSWATCH_WDT_NAME "wdt" #define SYSWATCH_WDT_TIMEOUT 5 From 62d45ba6a33101c39da9c525898a96d7295332cf Mon Sep 17 00:00:00 2001 From: "CSSC-WORK\\murmur" Date: Mon, 19 Jun 2023 17:17:06 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=AD=90=E5=8C=85?= =?UTF-8?q?=E4=B9=8B=E9=97=B4=E5=8F=91=E9=80=81=E9=97=B4=E9=9A=94=E4=B8=BA?= =?UTF-8?q?3s=E3=80=82=20=E7=89=88=E6=9C=AC=E5=8F=B7=E5=B0=8F=E5=A2=9E?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/main.c | 2 +- applications/repeatSend.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/applications/main.c b/applications/main.c index 99d9254..1cb5aeb 100644 --- a/applications/main.c +++ b/applications/main.c @@ -123,7 +123,7 @@ MSH_CMD_EXPORT(rt_hw_stm32_eth_init, 初始化网络。); void show_version(void) { - rt_kprintf("SW Version: %s\n","1.9(temp)"); + rt_kprintf("SW Version: %s\n","1.91(temp)"); } MSH_CMD_EXPORT(show_version,显示版本号); diff --git a/applications/repeatSend.c b/applications/repeatSend.c index 0e49867..b7be250 100644 --- a/applications/repeatSend.c +++ b/applications/repeatSend.c @@ -66,7 +66,7 @@ void repeatSend_thread_entry() rt_uint8_t rd[30]; tcpRec(rd); LOG_HEX("ack",16,rd,30); - rt_thread_mdelay(1000); + rt_thread_mdelay(3000); // LOG_HEX("d", 27, d[var], s[var]); } // tcpClose();