pack_File 初步解决报错问题
添加 miniIni 库
This commit is contained in:
parent
15e84bec95
commit
bbea30ec53
10
.config
10
.config
@ -81,7 +81,7 @@ CONFIG_RT_USING_DEVICE=y
|
|||||||
# CONFIG_RT_USING_INTERRUPT_INFO is not set
|
# CONFIG_RT_USING_INTERRUPT_INFO is not set
|
||||||
CONFIG_RT_USING_CONSOLE=y
|
CONFIG_RT_USING_CONSOLE=y
|
||||||
CONFIG_RT_CONSOLEBUF_SIZE=256
|
CONFIG_RT_CONSOLEBUF_SIZE=256
|
||||||
CONFIG_RT_CONSOLE_DEVICE_NAME="uart1"
|
CONFIG_RT_CONSOLE_DEVICE_NAME="uart3"
|
||||||
# end of Kernel Device Object
|
# end of Kernel Device Object
|
||||||
|
|
||||||
CONFIG_RT_VER_NUM=0x40101
|
CONFIG_RT_VER_NUM=0x40101
|
||||||
@ -326,7 +326,7 @@ CONFIG_RT_USING_ULOG=y
|
|||||||
# CONFIG_ULOG_OUTPUT_LVL_I is not set
|
# CONFIG_ULOG_OUTPUT_LVL_I is not set
|
||||||
CONFIG_ULOG_OUTPUT_LVL_D=y
|
CONFIG_ULOG_OUTPUT_LVL_D=y
|
||||||
CONFIG_ULOG_OUTPUT_LVL=7
|
CONFIG_ULOG_OUTPUT_LVL=7
|
||||||
# CONFIG_ULOG_USING_ISR_LOG is not set
|
CONFIG_ULOG_USING_ISR_LOG=y
|
||||||
CONFIG_ULOG_ASSERT_ENABLE=y
|
CONFIG_ULOG_ASSERT_ENABLE=y
|
||||||
CONFIG_ULOG_LINE_BUF_SIZE=256
|
CONFIG_ULOG_LINE_BUF_SIZE=256
|
||||||
# CONFIG_ULOG_USING_ASYNC_OUTPUT is not set
|
# CONFIG_ULOG_USING_ASYNC_OUTPUT is not set
|
||||||
@ -699,7 +699,11 @@ CONFIG_PKG_CMBACKTRACE_VER_NUM=0x10401
|
|||||||
# CONFIG_PKG_USING_SYS_LOAD_MONITOR is not set
|
# CONFIG_PKG_USING_SYS_LOAD_MONITOR is not set
|
||||||
# CONFIG_PKG_USING_PLCCORE is not set
|
# CONFIG_PKG_USING_PLCCORE is not set
|
||||||
# CONFIG_PKG_USING_RAMDISK is not set
|
# CONFIG_PKG_USING_RAMDISK is not set
|
||||||
# CONFIG_PKG_USING_MININI 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_QBOOT is not set
|
# CONFIG_PKG_USING_QBOOT is not set
|
||||||
# CONFIG_PKG_USING_PPOOL is not set
|
# CONFIG_PKG_USING_PPOOL is not set
|
||||||
# CONFIG_PKG_USING_OPENAMP is not set
|
# CONFIG_PKG_USING_OPENAMP is not set
|
||||||
|
60
applications/cfg.c
Normal file
60
applications/cfg.c
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2023-05-29 murmur the first version
|
||||||
|
*/
|
||||||
|
#include "../packages/minIni-v1.2.0/dev/minIni.h"
|
||||||
|
|
||||||
|
#ifdef PKG_USING_MININI
|
||||||
|
#define LJW_CFG_FILE_NAME "/cfg/cfg.ini"
|
||||||
|
|
||||||
|
void ini_test(void)
|
||||||
|
{
|
||||||
|
char buf[16];
|
||||||
|
char ip[16] = {0}, mask[16] = {0}, gw[16] = {0};
|
||||||
|
int len;
|
||||||
|
|
||||||
|
/*
|
||||||
|
** IP地址,保存在config段
|
||||||
|
*/
|
||||||
|
len = ini_gets("config", "IPAddr", "000000", buf, 16, LJW_CFG_FILE_NAME);
|
||||||
|
if(strcmp(buf, "000000") == 0) {
|
||||||
|
// 采用默认值
|
||||||
|
len = ini_puts("config", "IPAddr", "192.168.1.253", LJW_CFG_FILE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** 子网掩码,保存在config段
|
||||||
|
*/
|
||||||
|
len = ini_gets("config", "IPMask", "000000", buf, 16, LJW_CFG_FILE_NAME);
|
||||||
|
if(strcmp(buf, "000000") == 0) {
|
||||||
|
// 采用默认值
|
||||||
|
len = ini_puts("config", "IPMask", "255.255.255.0", LJW_CFG_FILE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** 网关,保存在config段
|
||||||
|
*/
|
||||||
|
len = ini_gets("config", "IPGateWay", "000000", buf, 16, LJW_CFG_FILE_NAME);
|
||||||
|
if(strcmp(buf, "000000") == 0) {
|
||||||
|
// 采用默认值
|
||||||
|
len = ini_puts("config", "IPGateWay", "192.168.1.1", LJW_CFG_FILE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取IP地址
|
||||||
|
ini_gets("config", "IPAddr", "000000", ip, 16, LJW_CFG_FILE_NAME);
|
||||||
|
ini_gets("config", "IPMask", "000000", mask, 16, LJW_CFG_FILE_NAME);
|
||||||
|
ini_gets("config", "IPGateWay", "000000", gw, 16, LJW_CFG_FILE_NAME);
|
||||||
|
// set_if("e0",ip, gw,mask);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef RT_USING_FINSH
|
||||||
|
#include <finsh.h>
|
||||||
|
MSH_CMD_EXPORT(ini_test, "IP address save as ini files, write and read it")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
15
applications/comp.h
Normal file
15
applications/comp.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2023-05-22 murmur the first version
|
||||||
|
*/
|
||||||
|
#ifndef COMP_H_
|
||||||
|
#define COMP_H_
|
||||||
|
|
||||||
|
int fastlz_compress_file(const char *fin, const char *fout);
|
||||||
|
|
||||||
|
#endif /* COMP_H_ */
|
15
applications/cryp.h
Normal file
15
applications/cryp.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2023-05-22 murmur the first version
|
||||||
|
*/
|
||||||
|
#ifndef CRYP_H_
|
||||||
|
#define CRYP_H_
|
||||||
|
|
||||||
|
void aes_file(const char *fin, const char *fout);
|
||||||
|
|
||||||
|
#endif /* CRYP_H_ */
|
19
applications/demo.c
Normal file
19
applications/demo.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2023-05-18 murmur the first version
|
||||||
|
*/
|
||||||
|
#include <rtthread.h>
|
||||||
|
#define LOG_TAG "cfg"
|
||||||
|
#define LOG_LVL LOG_LVL_DBG
|
||||||
|
#include <ulog.h>
|
||||||
|
#include <cJSON.h>
|
||||||
|
#include <dfs_file.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -31,8 +31,8 @@ void pfdemo(void)
|
|||||||
// #define cmb_println(...) rt_kprintf(__VA_ARGS__);rt_kprintf("\r\n");
|
// #define cmb_println(...) rt_kprintf(__VA_ARGS__);rt_kprintf("\r\n");
|
||||||
// char *f = "1023_05_19_15_29_59_254.txt";
|
// char *f = "1023_05_19_15_29_59_254.txt";
|
||||||
char *f = "2023_05_19_15_29_59_255.txt";
|
char *f = "2023_05_19_15_29_59_255.txt";
|
||||||
static rt_uint8_t d[10][200] = { };
|
rt_uint8_t d[10][200] = { };
|
||||||
static rt_uint8_t s[10] = { };
|
rt_uint8_t s[10] = { };
|
||||||
rt_uint8_t len = 0;
|
rt_uint8_t len = 0;
|
||||||
LOG_D("%p--%p",d,s);
|
LOG_D("%p--%p",d,s);
|
||||||
LOG_I("pack %s ...",f);
|
LOG_I("pack %s ...",f);
|
||||||
@ -40,9 +40,12 @@ void pfdemo(void)
|
|||||||
rt_kprintf("len is %d\n", len);
|
rt_kprintf("len is %d\n", len);
|
||||||
if (len)
|
if (len)
|
||||||
{
|
{
|
||||||
LOG_HEX("pkdata:",27,d[0],s[0]);
|
for (size_t var = 0; var < len; ++var) {
|
||||||
LOG_D("%p--%p",d,s);
|
LOG_HEX("d",27,d[var],s[var]);
|
||||||
LOG_D("%d--%d--%02X",len,s[0],d[0][0]);
|
}
|
||||||
|
// 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.");
|
LOG_I("Done.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,36 +60,41 @@ int main(void)
|
|||||||
// #define LED_HEART GET_PIN(E,3)
|
// #define LED_HEART GET_PIN(E,3)
|
||||||
/* 设置PIN脚模式为输出 */
|
/* 设置PIN脚模式为输出 */
|
||||||
rt_pin_mode(LED_HEART, PIN_MODE_OUTPUT);
|
rt_pin_mode(LED_HEART, PIN_MODE_OUTPUT);
|
||||||
|
// rt_pin_mode(LED_HEART_DEBUG, PIN_MODE_OUTPUT);
|
||||||
rt_pin_mode(ETH_RESET_PIN, PIN_MODE_OUTPUT);
|
rt_pin_mode(ETH_RESET_PIN, PIN_MODE_OUTPUT);
|
||||||
|
|
||||||
|
rt_pin_mode(TT_EN, PIN_MODE_OUTPUT);
|
||||||
|
|
||||||
// rt_pin_write(ETH_RESET_PIN, PIN_LOW);//关闭ETH
|
// rt_pin_write(ETH_RESET_PIN, PIN_LOW);//关闭ETH
|
||||||
// rt_thread_mdelay(10000);
|
|
||||||
// pfdemo();
|
rt_err_t ret = RT_EOK;
|
||||||
char *f = "2023_05_19_15_29_59_255.txt";
|
/* 设 置 日 期 */
|
||||||
static rt_uint8_t d[35][200] = { };
|
ret = set_date(2018, 12, 3);
|
||||||
static rt_uint8_t s[35] = { };
|
if (ret != RT_EOK)
|
||||||
size_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)
|
|
||||||
{
|
{
|
||||||
LOG_HEX("pkdata:",27,d[0],s[0]);
|
rt_kprintf("set RTC date failed\n");
|
||||||
LOG_D("%p--%p",d,s);
|
return ret;
|
||||||
LOG_D("%d--%d--%02X",len,s[0],d[0][0]);
|
|
||||||
LOG_I("Done.");
|
|
||||||
}
|
}
|
||||||
|
/* 设 置 时 间 */
|
||||||
|
ret = set_time(11, 15, 50);
|
||||||
|
if (ret != RT_EOK)
|
||||||
|
{
|
||||||
|
rt_kprintf("set RTC time failed\n");
|
||||||
|
// return ret;
|
||||||
|
}
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
/* 拉低PIN脚 */
|
/* 拉低PIN脚 */
|
||||||
rt_pin_write(LED_HEART, PIN_LOW);
|
rt_pin_write(LED_HEART, PIN_LOW);
|
||||||
|
// rt_pin_write(LED_HEART_DEBUG, PIN_LOW);
|
||||||
/* 延时1ms,省电 */
|
/* 延时1ms,省电 */
|
||||||
rt_thread_mdelay(1); //去掉延时,共用print替换
|
rt_thread_mdelay(1); //去掉延时,共用print替换
|
||||||
// rt_kprintf("Heartbeat.\n");
|
// rt_kprintf("Heartbeat.\n");
|
||||||
|
|
||||||
/* 拉高PIN脚 */
|
/* 拉高PIN脚 */
|
||||||
rt_pin_write(LED_HEART, PIN_HIGH);
|
rt_pin_write(LED_HEART, PIN_HIGH);
|
||||||
|
// rt_pin_write(LED_HEART_DEBUG, PIN_HIGH);
|
||||||
rt_thread_mdelay(1000);
|
rt_thread_mdelay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
#include <ulog.h>
|
#include <ulog.h>
|
||||||
|
|
||||||
#include "ttmsg.h"
|
#include "ttmsg.h"
|
||||||
|
#include <board.h>
|
||||||
/**
|
/**
|
||||||
* @brief 按指定分隔符分割字符串
|
* @brief 按指定分隔符分割字符串
|
||||||
*
|
*
|
||||||
@ -67,7 +67,7 @@ static size_t split(const char *str, const char *deli, char (*out)[STR_LEN_MAX])
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// strtok_r版本
|
// strtok_r版本
|
||||||
static size_t split(const char *str, const char *delim, char (*out)[STR_LEN_MAX])
|
static size_t split(const char *str, const char *delim, rt_uint8_t (*out)[STR_LEN_MAX])
|
||||||
{
|
{
|
||||||
char buf[50];
|
char buf[50];
|
||||||
strcpy(buf, str); // strtok会修改字符串
|
strcpy(buf, str); // strtok会修改字符串
|
||||||
@ -105,7 +105,7 @@ static size_t split(const char *str, const char *deli, char (*out)[STR_LEN_MAX])
|
|||||||
* @param out 提取结果
|
* @param out 提取结果
|
||||||
* @return size_t ID长度
|
* @return size_t ID长度
|
||||||
*/
|
*/
|
||||||
static size_t getID(const char *str, unsigned char *out)
|
static size_t getID(const char *str, rt_uint8_t *out)
|
||||||
{
|
{
|
||||||
char id[10][STR_LEN_MAX] = {};
|
char id[10][STR_LEN_MAX] = {};
|
||||||
// 分割路径
|
// 分割路径
|
||||||
@ -144,7 +144,7 @@ static size_t getID(const char *str, unsigned char *out)
|
|||||||
* @param flag 参数配置,如信息类型、压缩方式、加密方式等
|
* @param flag 参数配置,如信息类型、压缩方式、加密方式等
|
||||||
* @return 成功返回0
|
* @return 成功返回0
|
||||||
*/
|
*/
|
||||||
rt_uint8_t packInit(MSG *tpl, const char *fin, rt_uint8_t flag)
|
rt_uint8_t packInit(MSG *tpl, const rt_uint8_t *fin, rt_uint8_t flag)
|
||||||
{
|
{
|
||||||
// memset(tpl, 0, sizeof(MSG)); // 分配空间
|
// memset(tpl, 0, sizeof(MSG)); // 分配空间
|
||||||
// 模板
|
// 模板
|
||||||
@ -214,29 +214,31 @@ rt_uint8_t packMsgs(MSG *cfg, rt_uint8_t *din, size_t len, rt_uint8_t w, rt_uint
|
|||||||
{
|
{
|
||||||
w = len;
|
w = len;
|
||||||
}
|
}
|
||||||
static rt_uint8_t row = 0;
|
rt_uint8_t row = (len / w) + (len % w > 0 ? 1 : 0);
|
||||||
row = (len / w) + (len % w > 0 ? 1 : 0);
|
LOG_I("ROW = %d",row);
|
||||||
// rt_uint8_t packdata[row][200]; // 打包后数据
|
// rt_uint8_t packdata[row][200]; // 打包后数据
|
||||||
rt_uint8_t tlen[row]; // 打包后数据各维长度
|
rt_uint8_t tlen[row]; // 打包后数据各维长度
|
||||||
static rt_uint8_t index = 0;
|
// static rt_uint8_t index = 0;
|
||||||
|
|
||||||
// rt_uint8_t in[len];
|
// rt_uint8_t in[len];
|
||||||
// memcpy(in,din,len);
|
// memcpy(in,din,len);
|
||||||
|
|
||||||
cfg->fallpiece[0]=row;
|
cfg->fallpiece[0]=row;
|
||||||
for (size_t var = 0; var < len;var += w)
|
rt_uint8_t tmplen = 0;
|
||||||
|
size_t var=0;
|
||||||
|
for (rt_uint8_t index = 0; index< row;index++)
|
||||||
{
|
{
|
||||||
size_t tmplen = len - var; // 当前待打包数据的长度
|
// rt_uint8_t tmplen = w; // 当前待打包数据的长度
|
||||||
tmplen = tmplen > w ? w : tmplen; // 判断最后一包数据的长度
|
tmplen = (len - var) > w ? w : (len - var); // 判断最后一包数据的长度
|
||||||
cfg->fcurpiece[0] = index+1;
|
cfg->fcurpiece[0] = index+1;
|
||||||
rt_uint8_t col = packMsg(cfg, din+var, tmplen, dout[index]);
|
rt_uint8_t col = packMsg(cfg, din+var, tmplen, dout[index]);
|
||||||
arrlen[index] = col;
|
arrlen[index] = col;
|
||||||
index++;
|
// index++;
|
||||||
// LOG_D("index/row-var-tmplen");
|
var += w;
|
||||||
// LOG_D("%5d/%3d-%3d-%6d",index,row,var,tmplen);
|
LOG_D("index/row-var-tmplen");
|
||||||
LOG_HEX("per msg",27,dout[index-1],col);
|
LOG_D("%5d/%3d-%3d-%6d",index,row,var,tmplen);
|
||||||
LOG_D("--------");
|
LOG_HEX("per msg",27,dout[index],col);
|
||||||
// LOG_D("addr is %d",din);
|
// LOG_D("--------");
|
||||||
rt_thread_mdelay(100);
|
rt_thread_mdelay(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,7 +288,7 @@ LOG_HEX("buf",16,buf,100);
|
|||||||
*/
|
*/
|
||||||
rt_uint8_t pack_File(const char *fin, rt_uint8_t flag, const rt_uint8_t (*dout)[200], rt_uint8_t *arrLen)
|
rt_uint8_t pack_File(const char *fin, rt_uint8_t flag, const rt_uint8_t (*dout)[200], rt_uint8_t *arrLen)
|
||||||
{
|
{
|
||||||
MSG cfg;
|
static MSG cfg;
|
||||||
rt_memset(&cfg, 0, sizeof(MSG)); // 分配空间
|
rt_memset(&cfg, 0, sizeof(MSG)); // 分配空间
|
||||||
rt_uint8_t rst = packInit(&cfg, fin, flag);
|
rt_uint8_t rst = packInit(&cfg, fin, flag);
|
||||||
if (rst != RT_EOK)
|
if (rst != RT_EOK)
|
||||||
@ -312,7 +314,7 @@ rt_uint8_t pack_File(const char *fin, rt_uint8_t flag, const rt_uint8_t (*dout)[
|
|||||||
file_size = lseek(fd_in, 0, SEEK_END);
|
file_size = lseek(fd_in, 0, SEEK_END);
|
||||||
LOG_I("file size is %d bytes.",file_size);
|
LOG_I("file size is %d bytes.",file_size);
|
||||||
lseek(fd_in, 0, SEEK_SET);
|
lseek(fd_in, 0, SEEK_SET);
|
||||||
static rt_uint8_t *buffer = RT_NULL;
|
rt_uint8_t *buffer=RT_NULL ;
|
||||||
buffer = rt_malloc(file_size);
|
buffer = rt_malloc(file_size);
|
||||||
if (buffer == RT_NULL) {
|
if (buffer == RT_NULL) {
|
||||||
LOG_E("No memory for read %s.",fin);
|
LOG_E("No memory for read %s.",fin);
|
||||||
@ -342,17 +344,7 @@ rt_uint8_t pack_File(const char *fin, rt_uint8_t flag, const rt_uint8_t (*dout)[
|
|||||||
LOG_I("len of data per pack is %d Bytes.",flen);
|
LOG_I("len of data per pack is %d Bytes.",flen);
|
||||||
LOG_I("cnt of packages is %d",(file_size / flen) + (file_size % flen > 0 ? 1 : 0));
|
LOG_I("cnt of packages is %d",(file_size / flen) + (file_size % flen > 0 ? 1 : 0));
|
||||||
|
|
||||||
// len = packMsgs(&cfg, buffer, file_size, flen, dout, arrLen);
|
len = packMsgs(&cfg, buffer, file_size, flen, dout, arrLen);
|
||||||
// arrLen[0]= packMsg(&cfg, buffer, flen, dout[0]);
|
|
||||||
// len=1;
|
|
||||||
|
|
||||||
// len = 10;
|
|
||||||
// rt_memset(arrLen, 100, len);
|
|
||||||
// for (size_t var = 0; var < len; ++var)
|
|
||||||
// {
|
|
||||||
// rt_memset(dout[var], 0xab, arrLen[var]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
if (fd_in >= 0)
|
if (fd_in >= 0)
|
||||||
{
|
{
|
||||||
@ -365,31 +357,30 @@ rt_uint8_t pack_File(const char *fin, rt_uint8_t flag, const rt_uint8_t (*dout)[
|
|||||||
rt_free(buffer);
|
rt_free(buffer);
|
||||||
LOG_D("free buf done.");
|
LOG_D("free buf done.");
|
||||||
}
|
}
|
||||||
LOG_D("%p--%p",dout,arrLen);
|
// LOG_D("%p--%p",dout,arrLen);
|
||||||
|
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void pf_thread_entry(void* parameter)
|
|
||||||
{
|
|
||||||
static char d[40][200];
|
static char d[40][200];
|
||||||
static char s[40];
|
static char s[40];
|
||||||
|
// static rt_uint8_t *buffer = RT_NULL;
|
||||||
|
// static MSG cfg;
|
||||||
|
static int pf_thread_entry(void* parameter)
|
||||||
|
{
|
||||||
|
|
||||||
char *f = (char *) parameter;
|
char *f = (char *) parameter;
|
||||||
// static char d[5][200];
|
// static char d[5][200];
|
||||||
// static char s[5];
|
// static char s[5];
|
||||||
// rt_memset(s, 0xab, 5);
|
rt_uint8_t *buffer = RT_NULL;
|
||||||
// for (size_t var = 0; var < 5; ++var) {
|
static MSG cfg;
|
||||||
// rt_memset(d[var], 0xab, 200);
|
static rt_uint8_t len=0;
|
||||||
// }
|
|
||||||
rt_uint8_t len = 0;
|
|
||||||
// len = pack_File(f, 0, d, s);
|
// len = pack_File(f, 0, d, s);
|
||||||
|
#define DEMO
|
||||||
if (1)
|
#ifdef DEMO
|
||||||
{
|
{
|
||||||
MSG cfg;
|
//
|
||||||
rt_memset(&cfg, 0, sizeof(MSG)); // 分配空间
|
rt_memset(&cfg, 0, sizeof(MSG)); // 分配空间
|
||||||
rt_uint8_t rst = packInit(&cfg, f, 0);
|
rt_uint8_t rst = packInit(&cfg, f, 0);
|
||||||
if (rst != RT_EOK)
|
if (rst != RT_EOK)
|
||||||
@ -401,7 +392,7 @@ void pf_thread_entry(void* parameter)
|
|||||||
|
|
||||||
static size_t file_size = 0;
|
static size_t file_size = 0;
|
||||||
// rt_uint8_t *buffer = RT_NULL;
|
// rt_uint8_t *buffer = RT_NULL;
|
||||||
size_t flen = 150; // 每包数据初始长度,最大不超过 FRAME_DATA_LEN_MAX
|
static size_t flen = 150; // 每包数据初始长度,最大不超过 FRAME_DATA_LEN_MAX
|
||||||
// rt_uint8_t len = 0;
|
// rt_uint8_t len = 0;
|
||||||
|
|
||||||
fd_in = open(f, O_RDONLY, 0);
|
fd_in = open(f, O_RDONLY, 0);
|
||||||
@ -415,7 +406,7 @@ void pf_thread_entry(void* parameter)
|
|||||||
file_size = lseek(fd_in, 0, SEEK_END);
|
file_size = lseek(fd_in, 0, SEEK_END);
|
||||||
LOG_I("file size is %d bytes.", file_size);
|
LOG_I("file size is %d bytes.", file_size);
|
||||||
lseek(fd_in, 0, SEEK_SET);
|
lseek(fd_in, 0, SEEK_SET);
|
||||||
static rt_uint8_t *buffer = RT_NULL;
|
// static rt_uint8_t *buffer = RT_NULL;
|
||||||
buffer = rt_malloc(file_size);
|
buffer = rt_malloc(file_size);
|
||||||
if (buffer == RT_NULL)
|
if (buffer == RT_NULL)
|
||||||
{
|
{
|
||||||
@ -424,9 +415,10 @@ void pf_thread_entry(void* parameter)
|
|||||||
}
|
}
|
||||||
|
|
||||||
read(fd_in, buffer, file_size);
|
read(fd_in, buffer, file_size);
|
||||||
|
// LOG_HEX()
|
||||||
close(fd_in);
|
close(fd_in);
|
||||||
// 粗略调整每包大小
|
// 粗略调整每包大小
|
||||||
if (file_size > FRAME_DATA_LEN_MAX)
|
if (file_size > (size_t)FRAME_DATA_LEN_MAX)
|
||||||
{
|
{
|
||||||
while (file_size % flen < flen / 1.2 && flen < FRAME_DATA_LEN_MAX) // 阈值约83%
|
while (file_size % flen < flen / 1.2 && flen < FRAME_DATA_LEN_MAX) // 阈值约83%
|
||||||
{
|
{
|
||||||
@ -445,6 +437,7 @@ void pf_thread_entry(void* parameter)
|
|||||||
{
|
{
|
||||||
flen = file_size;
|
flen = file_size;
|
||||||
}
|
}
|
||||||
|
LOG_I("flen is %d",flen);
|
||||||
// s[0] = packMsg(&cfg, buffer, flen, d[0]);
|
// s[0] = packMsg(&cfg, buffer, flen, d[0]);
|
||||||
len = packMsgs(&cfg, buffer, file_size, flen, d, s);
|
len = packMsgs(&cfg, buffer, file_size, flen, d, s);
|
||||||
if (fd_in >= 0)
|
if (fd_in >= 0)
|
||||||
@ -459,22 +452,22 @@ void pf_thread_entry(void* parameter)
|
|||||||
LOG_D("free buf done.");
|
LOG_D("free buf done.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
rt_kprintf("len is %d\n", len);
|
rt_kprintf("len is %d\n", len);
|
||||||
if (len)
|
if (len)
|
||||||
{
|
{
|
||||||
// LOG_HEX("pkdata:",27,d[0],s[0]);
|
for (size_t var = 0; var < len; var++)
|
||||||
// LOG_D("%d",s[0]);
|
{
|
||||||
|
LOG_D("i = %d",var);
|
||||||
|
LOG_HEX("d", 27, d[var], s[var]);
|
||||||
|
}
|
||||||
LOG_I("Done.");
|
LOG_I("Done.");
|
||||||
}
|
}
|
||||||
LOG_HEX("s",27,s,len);
|
|
||||||
// for (size_t var = 0; var < len; ++var) {
|
|
||||||
// LOG_HEX("d",27,d[var],s[var]);
|
|
||||||
// }
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pmsg(int argc, char **argv)
|
static int pmsg(int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc == 2)
|
if (argc == 2)
|
||||||
{
|
{
|
||||||
@ -482,7 +475,7 @@ void pmsg(int argc, char **argv)
|
|||||||
strcpy(c, argv[1]);
|
strcpy(c, argv[1]);
|
||||||
|
|
||||||
/* 创建线程 */
|
/* 创建线程 */
|
||||||
rt_thread_t thread = rt_thread_create("pmsg", pf_thread_entry, (void *) c, 1024 * 4, 25, 10);
|
rt_thread_t thread = rt_thread_create("pmsg", pf_thread_entry, (void *) c, 1024 * 20, 25, 10);
|
||||||
/* 创建成功则启动线程 */
|
/* 创建成功则启动线程 */
|
||||||
if (thread != RT_NULL)
|
if (thread != RT_NULL)
|
||||||
{
|
{
|
||||||
@ -500,7 +493,52 @@ void pmsg(int argc, char **argv)
|
|||||||
rt_kprintf("Usage:\n");
|
rt_kprintf("Usage:\n");
|
||||||
rt_kprintf("pmsg [input_file] pack \"input_file\" \n");
|
rt_kprintf("pmsg [input_file] pack \"input_file\" \n");
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#include <finsh.h>
|
#include <finsh.h>
|
||||||
|
|
||||||
MSH_CMD_EXPORT(pmsg, 打包文件。);
|
MSH_CMD_EXPORT(pmsg, 打包文件。);
|
||||||
|
|
||||||
|
|
||||||
|
void pwTT_thread_entry(void *parameter)
|
||||||
|
{
|
||||||
|
// LOG_I("--%s--",parameter);
|
||||||
|
if (parameter == NULL) {
|
||||||
|
int f = rt_pin_read(TT_EN);
|
||||||
|
rt_pin_write(TT_EN, !f);
|
||||||
|
LOG_I("set TT %s",!f?"ON":"OFF");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rt_bool_t flag = (rt_bool_t)parameter;
|
||||||
|
rt_pin_write(TT_EN, flag);
|
||||||
|
LOG_I("set TT %s",flag?"ON":"OFF");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int swTT(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int f = NULL;//不带参数时argv[1]为NULL
|
||||||
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
f = atoi(argv[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 创建线程 */
|
||||||
|
rt_thread_t thread = rt_thread_create("sw_TT", pwTT_thread_entry, (void *) f, 1024 * 1, 25, 10);
|
||||||
|
/* 创建成功则启动线程 */
|
||||||
|
if (thread != RT_NULL)
|
||||||
|
{
|
||||||
|
rt_thread_startup(thread);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG_E("thread 'sw_TT' create failure.");
|
||||||
|
return RT_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MSH_CMD_EXPORT(swTT, 切换TT电源。不带参切换电源状态,支持参数);
|
||||||
|
@ -70,6 +70,7 @@ extern "C"
|
|||||||
#define BSP_USING_UART1
|
#define BSP_USING_UART1
|
||||||
#define BSP_UART1_TX_PIN "PB6"
|
#define BSP_UART1_TX_PIN "PB6"
|
||||||
#define BSP_UART1_RX_PIN "PB7"
|
#define BSP_UART1_RX_PIN "PB7"
|
||||||
|
#define BSP_UART1_RX_USING_DMA
|
||||||
|
|
||||||
#define BSP_USING_UART3
|
#define BSP_USING_UART3
|
||||||
#define BSP_UART3_TX_PIN "PB10"
|
#define BSP_UART3_TX_PIN "PB10"
|
||||||
@ -371,6 +372,8 @@ extern "C"
|
|||||||
|
|
||||||
|
|
||||||
#define LED_HEART GET_PIN(E,3)
|
#define LED_HEART GET_PIN(E,3)
|
||||||
|
#define LED_HEART_DEBUG GET_PIN(B,3)
|
||||||
|
#define TT_EN GET_PIN(B,0)
|
||||||
#ifndef ETH_RESET_PIN
|
#ifndef ETH_RESET_PIN
|
||||||
#define ETH_RESET_PIN GET_PIN(A, 4)//E-7
|
#define ETH_RESET_PIN GET_PIN(A, 4)//E-7
|
||||||
#endif
|
#endif
|
||||||
|
@ -14,6 +14,11 @@
|
|||||||
"ver": "v1.4.1",
|
"ver": "v1.4.1",
|
||||||
"name": "CMBACKTRACE"
|
"name": "CMBACKTRACE"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"path": "/packages/system/minIni",
|
||||||
|
"ver": "v1.2.0",
|
||||||
|
"name": "MININI"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "/packages/misc/fastlz",
|
"path": "/packages/misc/fastlz",
|
||||||
"ver": "v1.0.1",
|
"ver": "v1.0.1",
|
||||||
|
@ -194,6 +194,7 @@
|
|||||||
#define RT_USING_ULOG
|
#define RT_USING_ULOG
|
||||||
#define ULOG_OUTPUT_LVL_D
|
#define ULOG_OUTPUT_LVL_D
|
||||||
#define ULOG_OUTPUT_LVL 7
|
#define ULOG_OUTPUT_LVL 7
|
||||||
|
#define ULOG_USING_ISR_LOG
|
||||||
#define ULOG_ASSERT_ENABLE
|
#define ULOG_ASSERT_ENABLE
|
||||||
#define ULOG_LINE_BUF_SIZE 256
|
#define ULOG_LINE_BUF_SIZE 256
|
||||||
|
|
||||||
@ -293,6 +294,8 @@
|
|||||||
/* Micrium: Micrium software products porting for RT-Thread */
|
/* Micrium: Micrium software products porting for RT-Thread */
|
||||||
|
|
||||||
/* end of Micrium: Micrium software products porting for RT-Thread */
|
/* end of Micrium: Micrium software products porting for RT-Thread */
|
||||||
|
#define PKG_USING_MININI
|
||||||
|
#define PKG_USING_MININI_V120
|
||||||
/* end of system packages */
|
/* end of system packages */
|
||||||
|
|
||||||
/* peripheral libraries and drivers */
|
/* peripheral libraries and drivers */
|
||||||
|
Loading…
Reference in New Issue
Block a user