Merge branch 'demo'

This commit is contained in:
CSSC-WORK\murmur 2023-06-20 09:59:20 +08:00
commit fc9337c8d3
20 changed files with 566 additions and 189 deletions

46
.config
View File

@ -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
@ -344,7 +350,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 +580,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
@ -706,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
@ -719,9 +705,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

View File

@ -21,7 +21,7 @@
#include <ttTR.h>
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)
{
@ -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;
}
@ -359,5 +360,5 @@ void smsg()
return;
}
}
INIT_COMPONENT_EXPORT(smsg);
//INIT_COMPONENT_EXPORT(smsg);
MSH_CMD_EXPORT(smsg,smsg);

View File

@ -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"
@ -80,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;
}
@ -163,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);
}
@ -270,7 +272,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

View File

@ -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

View File

@ -1,7 +1,7 @@
#include <board.h>
#include <rtthread.h>
//#include <../packages/webclient-v2.2.0/inc/webclient.h>
#include <webclient.h>
@ -29,11 +29,7 @@
//#include <string.h>
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="-",.wd="-",.ele="-"};
//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");
@ -146,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) {
@ -164,8 +161,9 @@ static void rulecheck(void)
if (okCnt >= minTTPeriCnt) {
//TT具备发送条件
// rt_event_send(&sw_check, TT_IS_OK);
upTTflag();
LOG_D("符合规则TT具备发送状态。");
// upTTflag();
upTTflagtmp();
LOG_I("符合规则TT具备发送状态。");
// updateSta();
okCnt = minTTPeriCnt -1;
}
@ -271,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;
}
@ -300,23 +302,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)
{
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) //最后一次采集不延时
@ -348,9 +356,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 +370,100 @@ 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");
break;
// return -RT_ENOMEM;
}
if (webclient_get_data(url) != RT_EOK)
{
web_free(url);
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更新一次数据
}
}
/**
* TT状态信息3s刷新一次TT断电后退出
*/
void repGetTT(void)
{
/* 创建 serial 线程 */
rt_thread_t thread = rt_thread_create("repGetTT", repGetTT_thread_entry, RT_NULL, 1024 * 3, 27, 10);
/* 创建成功则启动线程 */
if (thread != RT_NULL)
{
rt_thread_startup(thread);
// rt_kprintf("done");
}
else
{
LOG_E("thread 'repGetTT' create failure.");
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);
//}

72
applications/log2file.c Normal file
View File

@ -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 "/sd/syslog" //设置保存路径
#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" ,&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 -----------------------------------------------*/
/**
* @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);

View File

@ -18,32 +18,6 @@
//#include <cfg.h>
//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");
// 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.");
}
}
@ -62,25 +36,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脚 */
@ -110,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)
@ -132,5 +116,15 @@ 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.91(temp)");
}
MSH_CMD_EXPORT(show_version,);
INIT_COMPONENT_EXPORT(show_version);

141
applications/repeatSend.c Normal file
View File

@ -0,0 +1,141 @@
/*
* 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程序。固定数据包循环重发
#include <rtthread.h>
#define LOG_TAG "repeatSend"
#define LOG_LVL LOG_LVL_DBG
#include <ulog.h>
#include <ttTR.h>
#include <usrcfg.h>
/* 定时器的控制块 */
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_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,
RT_NULL) == 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)//等待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";
rt_uint8_t len = 0;
len = pack_File(f, 0, d, s);
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(3000);
// LOG_HEX("d", 27, d[var], s[var]);
}
// tcpClose();
LOG_I("send msg Done.");
//记录次数
//此次数为发送成功次数
add_val("okCnt");
}
}
else
{
LOG_W("TT is not ready.");
}
}
}
}
/* 定时器1超时函数 */
static void timeout1(void *parameter)
{
LOG_D("定时时间到,准备发送数据");
rt_event_send(&readyToSend, TIME_IS_UP);
}
void timer_demo()
{
/* 创建定时器1 周期定时器 */
timer1 = rt_timer_create("repeatSendtimer", timeout1,
RT_NULL, rt_tick_from_millisecond(5*60*1000),
RT_TIMER_FLAG_PERIODIC);
/* 启动定时器1 */
if (timer1 != RT_NULL)
rt_timer_start(timer1);
/* 创建 serial 线程 */
rt_thread_t thread = rt_thread_create("repSendT", repeatSend_thread_entry, RT_NULL, 1024*3, 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()
{
pwTT_thread_entry("1");//开机
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);
MSH_CMD_EXPORT(upTTflagtmp,);

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);
@ -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()
{
@ -161,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()
{

View File

@ -79,12 +79,13 @@ 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);
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;
}

View File

@ -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,15 +510,16 @@ static int pmsg(int argc, char **argv)
#include <finsh.h>
MSH_CMD_EXPORT(pmsg, );
#endif
/**
*
* @param parameter
* @param parameter "0"
*/
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 +527,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 +537,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 +593,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)

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, rt_tick_from_millisecond(40*1000),
RT_TIMER_FLAG_PERIODIC);

View File

@ -23,6 +23,7 @@ typedef struct
{
rt_uint8_t cnt;
rt_uint8_t s;
rt_uint8_t repeat;
} CFG;

View File

@ -23,6 +23,7 @@
int rt_hw_spi_flash_init(void)
{
// rt_kprintf("SW Version: %s\n","1.4(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,14 +49,11 @@ 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");
}
}
rt_kprintf("%d ms since boot.\n",rt_tick_get_millisecond());
add_val("bootCnt");
}
@ -66,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);

View File

@ -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 */
}
}

View File

@ -284,7 +284,7 @@ extern "C"
*
*/
/*#define BSP_USING_SDIO*/
#define BSP_USING_SDIO
/*-------------------------- SDIO CONFIG END --------------------------*/

View File

@ -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 */

View File

@ -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"
},
{

View File

@ -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
@ -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
@ -207,6 +213,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 +276,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 */
@ -301,13 +302,13 @@
#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
#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 */