作者 王振宇

优化log损坏文件系统的自动修复

/* Includes ------------------------------------------------------------------*/
#include "JZ_TempControl.h"
#include "JZ_lamp.h"
#include "JZ_widget.h"
#include "JZ_speaker.h"
#include "wiringPi.h"
#include <unistd.h>
... ...
... ... @@ -2,9 +2,8 @@
#include "JZ_lamp.h"
#include "JZ_uart.h"
#include "JZ_widget.h"
#include "JZ_TempControl.h"
#include "JZ_speaker.h"
/* Private constants ---------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
... ...
/* Includes----------------------------------------------------*/
#include "JZ_widget.h"
#include "version_choose.h"
#include <stdarg.h>
//道通没有自定义控件
#if SPECIAL_VERSION == SPECIAL_GDU
#include "test_widget.h"
#include "gdu_logger.h"
#endif
/* Private constants-------------------------------------------*/
/* Private types-----------------------------------------------*/
/* Private values----------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
void Jz_set_widget_value(int index,int value)
{
//如不是道通,则设置控件的值
#if SPECIAL_VERSION != SPECIAL_UAV
set_widget_value(index,value);
#endif
}
void JZ_LOG_INFO(const char *format, ...)
{
#if SPECIAL_VERSION == SPECIAL_GDU
va_list args;
va_start(args, format);
USER_LOG_INFO(format, args); // 传递参数给 USER_LOG_INFO
va_end(args);
#endif
}
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef _JZ_WIDGET_H
#define _JZ_WIDGET_H
/* Includes ------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
void Jz_set_widget_value(int index,int value);
void JZ_LOG_INFO(const char *format, ...);
#ifdef __cplusplus
}
#endif
#endif //_JZ_WIDGET_H
... ... @@ -5,6 +5,13 @@
#include "JZ_TempControl.h"
#include <unistd.h>
#include <stdio.h>
#include "version_choose.h"
#include <stdarg.h>
#include <time.h>
#if SPECIAL_VERSION == SPECIAL_GDU
#include "test_widget.h"
#include "gdu_logger.h"
#endif
/* Private constants ---------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
... ... @@ -229,4 +236,57 @@ void JZ_DelayThreadCreate(int delayTime)
printf("线程创建失败\n");
}
}
}
\ No newline at end of file
}
/************************************
*设置UI控件值
*函数名: Jz_set_widget_value
*函数参数:
@index: 控件编号
@value: 控件值
*返回值:
*函数作者:wzy
*************************************/
void Jz_set_widget_value(int index,int value)
{
//如不是道通,则设置控件的值
#if SPECIAL_VERSION != SPECIAL_UAV
set_widget_value(index,value);
#endif
}
/************************************
*输出信息
*函数名: JZ_LOG_INFO
*函数参数:
*返回值:
*函数作者:wzy
*************************************/
void JZ_LOG_INFO(const char *format, ...)
{
#if SPECIAL_VERSION == SPECIAL_GDU
va_list args;
va_start(args, format);
USER_LOG_INFO(format, args); // 传递参数给 USER_LOG_INFO
va_end(args);
#else
FILE *file = fopen("/root/sdcard/debuglog.txt", "a"); // "a" 模式表示追加内容到文件末尾
if (file == NULL) {
perror("无法打开日志文件");
return;
}
// 获取当前时间
time_t now;
time(&now);
struct tm *local = localtime(&now);
// 写入时间戳和消息到文件
fprintf(file, "[%04d-%02d-%02d %02d:%02d:%02d] %s\n",
local->tm_year + 1900, local->tm_mon + 1, local->tm_mday,
local->tm_hour, local->tm_min, local->tm_sec, format);
// 关闭文件
fclose(file);
#endif
}
... ...
... ... @@ -19,6 +19,8 @@ void JZ_LampLumenControlFeature(uint8_t value1,uint8_t value2);//亮度控制功
void Jz_LampGimbalControlFeature(int value);
void JZ_GetBeforeChar(const char *dest,char *src);//提取 . 之前的字符串
void JZ_DelayThreadCreate(int delayTime);//延时执行线程创建
void Jz_set_widget_value(int index,int value);
void JZ_LOG_INFO(const char *format, ...);
#ifdef __cplusplus
}
#endif
... ...
... ... @@ -21,7 +21,6 @@
#include "JZ_lamp.h"
#include "JZ_TempControl.h"
#include "JZ_widget.h"
#include "JZ_uart.h"
#include "JZ_speaker.h"
#include "ircut.h"
... ... @@ -406,10 +405,6 @@ static T_UAVReturnCode SpeakerControl(T_UavWidgetSpeakerControl *speakerControl)
set_paly_state(3);
s_isDecodeFinished = false;//解码标志位
//将不带格式的名字取出来
// len = strrchr(speakerControl->strValue, '.') - speakerControl->strValue;//计算文件名长度
// memcpy(record_file_name, "\0", 256);
// strncpy(record_file_name, speakerControl->strValue, len);//取文件名
// record_file_name[len] = '\0';
JZ_GetBeforeChar(speakerControl->strValue,record_file_name);
sprintf(opus_file_name, "record/%s.opus", record_file_name);
//打开opus文件
... ... @@ -498,7 +493,7 @@ static T_UAVReturnCode SpeakerQuery(T_UavWidgetSpeakerQuery *speakerQuery,T_UavW
{
switch(speakerQuery->query)
{
case 1:
case 1://播放状态
if(play_mode == 1)//开启了循环
{
if(playStatusQueryFlag == 1)//上次播放未完成,关闭播放
... ...
... ... @@ -9,13 +9,13 @@ sync;
# 检查文件是否存在
if [ -f "$file_path" ]; then
# 读取文件的第一行
value=$(head -n 1 "$file_path")
if [ -z "$value" ]; then #判断文件是否为空,文件为空意味着log导致了sd卡文件系统变为只读
#重新挂载sd卡
umount /dev/mmcblk0p3
mount -t vfat -o iocharset=utf8 /dev/mmcblk0p3 /root/sdcard
# 读取文件的第一行
value=$(head -n 1 "$file_path")
if [ -z "$value" ]; then #判断文件是否为空,文件为空意味着log导致了sd卡文件系统变为只读
echo "删除log文件"
rm -rf /root/sdcard/Logs/JZ*.log
... ...
... ... @@ -10,11 +10,10 @@
#include "string.h"
#include <pthread.h>
#include <opus.h>
#include "JZ_widget.h"
#include "JZ_speaker.h"
#include "wiringPi.h"
#include "uav_widget.h"
#include <math.h>
#include <stdbool.h>
int music_sum=0;//歌曲总数
int music_num=0;//当前播放的歌曲编号
char musiclist[128][128];//最多存取128首歌曲
... ...