解决 log2file.c 报错的问题,由cacheDataToFile引起
This commit is contained in:
parent
eaa05a9add
commit
3ee597180c
@ -20,8 +20,8 @@
|
||||
#include <usrcfg.h>
|
||||
#include <board.h>
|
||||
|
||||
#define LOG_TAG "RS232"
|
||||
#define LOG_LVL LOG_LVL_INFO
|
||||
#define LOG_TAG "RS485"
|
||||
#define LOG_LVL LOG_LVL_DBG
|
||||
#include <ulog.h>
|
||||
|
||||
#define TR485
|
||||
@ -128,7 +128,7 @@ uint8_t getPowerLevel(void)
|
||||
return batt.level[1];
|
||||
}
|
||||
|
||||
static void serial_thread_entry(void *parameter)
|
||||
static void serial485_thread_entry(void *parameter)
|
||||
{
|
||||
struct rx_msg msg;
|
||||
rt_err_t result;
|
||||
@ -139,7 +139,6 @@ static void serial_thread_entry(void *parameter)
|
||||
{
|
||||
//发送指令
|
||||
// if (rt_mutex_take(sendcmd, RT_WAITING_FOREVER) == RT_EOK)
|
||||
rt_thread_mdelay(10*1000);
|
||||
{
|
||||
uint8_t cmd[] = { 0x01, 0x03, 0x00, 0x00, 0x00, 0x1d, 0x85, 0xc3 };
|
||||
|
||||
@ -148,8 +147,7 @@ static void serial_thread_entry(void *parameter)
|
||||
rt_device_write(serial485, 0, cmd, sizeof(cmd));
|
||||
rt_pin_write(TR485_RE, PIN_LOW);
|
||||
}
|
||||
|
||||
|
||||
rt_thread_mdelay(10*1000);
|
||||
|
||||
rt_memset(&msg, 0, sizeof(msg));
|
||||
/* 从消息队列中读取消息*/
|
||||
@ -224,7 +222,7 @@ static int uart485_dma_sample(int argc, char *argv[])
|
||||
/* 发送字符串 */
|
||||
|
||||
/* 创建 serial 线程 */
|
||||
rt_thread_t thread = rt_thread_create("RS485", serial_thread_entry, RT_NULL, 1024*5, 30-2, 10);
|
||||
rt_thread_t thread = rt_thread_create("RS485", serial485_thread_entry, RT_NULL, 1024*5, 30, 10);
|
||||
/* 创建成功则启动线程 */
|
||||
if (thread != RT_NULL)
|
||||
{
|
||||
@ -250,7 +248,7 @@ static int uart485_dma_sample(int argc, char *argv[])
|
||||
|
||||
|
||||
/* 导出到 msh 命令列表中 */
|
||||
MSH_CMD_EXPORT(uart485_dma_sample,uart485_dma_sample);
|
||||
//INIT_APP_EXPORT(uart485_dma_sample);
|
||||
//MSH_CMD_EXPORT(uart485_dma_sample,uart485_dma_sample);
|
||||
INIT_APP_EXPORT(uart485_dma_sample);
|
||||
MSH_CMD_EXPORT(dumpBattInfo,解析电池信息);
|
||||
|
||||
|
@ -306,6 +306,8 @@ MSH_CMD_EXPORT_ALIAS(clear_sta,clsSta, 重置系统统计数据)
|
||||
volatile size_t nislock=0;
|
||||
static void nsetLock()
|
||||
{
|
||||
rt_mutex_take(isTosendOk, RT_WAITING_FOREVER);
|
||||
return;
|
||||
// LOG_D("--%d--",nislock);
|
||||
size_t cnt=10;
|
||||
while(nislock)
|
||||
@ -321,6 +323,8 @@ static void nsetLock()
|
||||
}
|
||||
static void nclearLock()
|
||||
{
|
||||
rt_mutex_release(isTosendOk);
|
||||
return;
|
||||
nislock=0;
|
||||
LOG_W("file is unlocked.");
|
||||
}
|
||||
@ -440,14 +444,14 @@ static void add(int argc, char **argv)
|
||||
* @param k
|
||||
* @return
|
||||
*/
|
||||
int updateLstFile(const char *fin)
|
||||
int setLstFile(const char *fin)
|
||||
{
|
||||
nsetLock();
|
||||
|
||||
int rst = ini_puts(SECTION_LST_FILE, "lst", fin, FILE_TO_SEND);
|
||||
nclearLock();
|
||||
if (!rst) {
|
||||
LOG_E("update lst file error.");
|
||||
LOG_E("set lst file error.");
|
||||
return RT_ERROR;
|
||||
}
|
||||
return RT_EOK;
|
||||
|
@ -71,7 +71,7 @@ static void initCfg(void)
|
||||
close(fd);
|
||||
const char *cfgstr =
|
||||
"[config]\n"
|
||||
"# V1.83\n"
|
||||
"# V1.84\n"
|
||||
"#定时(默认每小时)上报时刻,\n"
|
||||
"sendInterval=15\n"
|
||||
"# 最大文件大小,超过此大小则进入发送流程\n"
|
||||
@ -103,7 +103,7 @@ static void initCfg(void)
|
||||
"# 位置告警功能开关,1-开启,0-关闭\n"
|
||||
"locAlert=1;\n"
|
||||
"# 定时上报位置信息间隔(M)\n"
|
||||
"locRepInterval=5\n"
|
||||
"locRepInterval=1\n"
|
||||
"[stats]\n"
|
||||
"# 继电器开关次数,影响继电器寿命(<10W次)\n"
|
||||
"swCnt=12\n"
|
||||
@ -344,7 +344,7 @@ void d_remain(void)
|
||||
static void timeoutFunc(void *parameter)
|
||||
{
|
||||
stopTM();
|
||||
if (!deinitThread) {
|
||||
if (deinitThread) {
|
||||
LOG_W("timeout leads to shunt down TT");
|
||||
// rt_thread_mdelay(3000);// no delay
|
||||
deInitTT();//Function[rt_mutex_take] shall not be used in ISR
|
||||
@ -577,29 +577,27 @@ void initTT_thread_entry()
|
||||
RT_TIMER_FLAG_ONE_SHOT);//|RT_TIMER_FLAG_SOFT_TIMER);
|
||||
}
|
||||
|
||||
if (!isEthUP())
|
||||
{ //只初始化一次
|
||||
if (!isEthUP())//只初始化一次
|
||||
{
|
||||
LOG_D("init eth...");
|
||||
rt_pin_write(ETH_RESET_PIN, PIN_HIGH);
|
||||
if (rt_hw_stm32_eth_init() == RT_EOK)
|
||||
if (rt_hw_stm32_eth_init() == RT_EOK)//激活网口
|
||||
{
|
||||
LOG_D("eth inited DONE.");
|
||||
// lwip_sys_init();
|
||||
}; //激活网口
|
||||
};
|
||||
}
|
||||
else if (!isTCPok()) //判断TCP连接是否正常,异常自动重连
|
||||
{
|
||||
// tcpInit();
|
||||
if (tcpInit() != RT_EOK) {
|
||||
// cmd_free();
|
||||
if (isEthUP()) {
|
||||
if (tcpInit() != RT_EOK)
|
||||
{
|
||||
if (isEthUP())
|
||||
{
|
||||
LOG_D("retry.");
|
||||
rt_hw_stm32_eth_deinit();
|
||||
// rt_hw_stm32_eth_init();
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
LOG_D("TCP is ready.");
|
||||
tcpRecMQ(); //开启tcp接收线程
|
||||
@ -648,7 +646,7 @@ void initTT()
|
||||
{
|
||||
/* 创建 serial 线程 */
|
||||
if (initThread != RT_NULL) {
|
||||
LOG_W("initThread 未退出");
|
||||
LOG_W("TT is already running.");
|
||||
return;
|
||||
}
|
||||
initThread = rt_thread_create("initTT", initTT_thread_entry, RT_NULL, 1024 * 5, 20, 10);
|
||||
|
@ -146,7 +146,7 @@ void d_getFreeSpace()
|
||||
*/
|
||||
RT_WEAK int getPowerLevel(void)
|
||||
{
|
||||
return 0;
|
||||
return 0x63;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
@ -631,7 +631,7 @@ void reportSysCfg()
|
||||
//单次最多可上报15条位置信息
|
||||
|
||||
/**
|
||||
* 按15条经纬度打包位置信息。由[是否越界]+[时戳]+[15组数据]组成。
|
||||
* 按15条经纬度打包位置信息。由[是否越界,电池电量]+[时戳]+[15组数据]组成。
|
||||
* 是否越界为预留,不在此判断。
|
||||
* 15组数据采集顺序为MOB(most oldest bit),越新的数据离时戳越近
|
||||
* 由于加密后数据最大会增加16字节,后位置数据条数改为10
|
||||
@ -645,7 +645,7 @@ static int packLocMsg(uint8_t *dout)
|
||||
{ 0x5A, 0xA5, ADDR_ANJI, ADDR_TT, _CFG_LOCATION_ALERT >> 8, _CFG_LOCATION_ALERT & 0xFF, 0, 0 };
|
||||
|
||||
|
||||
alertMsg[8] = 0; //首字节00为定时发送,未检测围栏;其它为在围栏外
|
||||
alertMsg[8] = getPowerLevel(); //首字节最高bit为1时为在围栏外
|
||||
int len = time2Byte(alertMsg+9);//添加时间戳
|
||||
len += getAndCheckLoc(alertMsg + 9 + len, _LOC_CNT) + 1; //p指向第2个数据
|
||||
if (len == 0x08) {//无有效位置数据
|
||||
@ -751,7 +751,7 @@ void reportLoc_thread_entry(void *parameter)
|
||||
//检测是否在围栏内
|
||||
if (len && !isInFence(rst+len-11))//不在围栏内
|
||||
{
|
||||
rst[8]=1;
|
||||
rst[8] |= 1<<7;
|
||||
isReadyToSendLoc = 1;
|
||||
}
|
||||
itime += 1 ;
|
||||
@ -1330,13 +1330,14 @@ int cacheDataToFile(uint8_t *din, size_t len)
|
||||
LOG_I("FUNC = cache to upsend");
|
||||
int rst = -RT_ERROR;
|
||||
//return RT_EOK;
|
||||
char f[60]="";
|
||||
getLstCacheFileName(f);
|
||||
|
||||
|
||||
//lock file
|
||||
while (iscdlock) {
|
||||
rt_thread_mdelay(1000);
|
||||
}
|
||||
static char f[60]="";//必须是static,否则log2file报错
|
||||
getLstCacheFileName(f);
|
||||
|
||||
int fd = open(f, O_WRONLY | O_CREAT | O_APPEND);
|
||||
if (fd < 0)
|
||||
|
@ -35,7 +35,7 @@ typedef enum
|
||||
}ulog_file_be_name;
|
||||
|
||||
#define ROOT_PATH ROOT_PATH_DEBUG //设置保存路径
|
||||
#define FILE_SIZE 100*1024 //设置单个文件大小
|
||||
#define FILE_SIZE 10*1024 //设置单个文件大小
|
||||
#define BUFF_SIZE 1*1024 //设备缓存区大小
|
||||
|
||||
static struct ulog_backend sys_log_backend;
|
||||
|
@ -91,3 +91,13 @@ void show_version(void)
|
||||
|
||||
MSH_CMD_EXPORT(show_version,显示版本号);
|
||||
INIT_COMPONENT_EXPORT(show_version);
|
||||
static void clock_information(void)
|
||||
{
|
||||
LOG_D("System Clock information");
|
||||
LOG_D("SYSCLK_Frequency = %d", HAL_RCC_GetSysClockFreq());
|
||||
LOG_D("HCLK_Frequency = %d", HAL_RCC_GetHCLKFreq());
|
||||
LOG_D("PCLK1_Frequency = %d", HAL_RCC_GetPCLK1Freq());
|
||||
LOG_D("PCLK2_Frequency = %d", HAL_RCC_GetPCLK2Freq());
|
||||
|
||||
}
|
||||
MSH_CMD_EXPORT(clock_information,始终信息);
|
||||
|
@ -396,7 +396,7 @@ void updateCacheFileName()
|
||||
strncpy(f + strlen(rootDir), ts, strlen(ts));
|
||||
|
||||
// strcpy(cfname,f);
|
||||
updateLstFile(f);
|
||||
setLstFile(f);
|
||||
// strcpy(fin,f);
|
||||
// return fin;
|
||||
}
|
||||
@ -421,6 +421,7 @@ char *getLstCacheFileName(char *fin)
|
||||
if (!getLstFile(f)) {
|
||||
updateCacheFileName();
|
||||
}
|
||||
getLstFile(f);
|
||||
strcpy(fin,f);
|
||||
return fin;
|
||||
|
||||
|
@ -63,7 +63,7 @@ typedef struct
|
||||
|
||||
#define ROOT_PATH_LOG "/sd/log/" //收发数据
|
||||
#define ROOT_PATH_DATA "/sd/cdata/" //缓存数据
|
||||
#define ROOT_PATH_DEBUG "/sd/debug/" //调试日志
|
||||
#define ROOT_PATH_DEBUG "/sd/debug" //调试日志
|
||||
#define CRYPT_BEFRE_PACK
|
||||
|
||||
#define UPDATE_INTERVAL 10
|
||||
|
@ -204,7 +204,7 @@
|
||||
#define ULOG_ASSERT_ENABLE
|
||||
#define ULOG_LINE_BUF_SIZE 256
|
||||
#define ULOG_USING_ASYNC_OUTPUT
|
||||
#define ULOG_ASYNC_OUTPUT_BUF_SIZE 10240
|
||||
#define ULOG_ASYNC_OUTPUT_BUF_SIZE 1024*10
|
||||
#define ULOG_ASYNC_OUTPUT_BY_THREAD
|
||||
#define ULOG_ASYNC_OUTPUT_THREAD_STACK 10240
|
||||
#define ULOG_ASYNC_OUTPUT_THREAD_PRIORITY 29
|
||||
|
Loading…
Reference in New Issue
Block a user