Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
car-controlserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenzhongjian
car-controlserver
Commits
8629878c
Commit
8629878c
authored
Aug 13, 2025
by
957dd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加入了日志文件当设备启动时候日志文件启动时候删除并重启重新创建日志文件
parent
550c1523
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
70 additions
and
9 deletions
+70
-9
pthread_open.c
app/main/pthread_open.c
+0
-1
main
build/main
+0
-0
audioplay.c
drivers/sensors/audioplay.c
+26
-6
audioplay.h
drivers/sensors/audioplay.h
+4
-0
mylog.c
modules/logger/mylog.c
+39
-1
mqtt_verify.h
modules/mqtt/mqtt_verify.h
+1
-1
No files found.
app/main/pthread_open.c
View file @
8629878c
...
@@ -164,7 +164,6 @@ void *thread_time_calculation(void *arg) {
...
@@ -164,7 +164,6 @@ void *thread_time_calculation(void *arg) {
//专门处理MP3播放
//专门处理MP3播放
void
*
thread_play_mp3
(
void
*
arg
)
{
void
*
thread_play_mp3
(
void
*
arg
)
{
audio_init
();
audioplay_cycle
();
audioplay_cycle
();
return
NULL
;
return
NULL
;
}
}
...
...
build/main
View file @
8629878c
No preview for this file type
drivers/sensors/audioplay.c
View file @
8629878c
...
@@ -8,6 +8,8 @@ char urlbuf[512];
...
@@ -8,6 +8,8 @@ char urlbuf[512];
char
keybuf
[
256
];
char
keybuf
[
256
];
double
audio_volume
=
0
.
8
;
double
audio_volume
=
0
.
8
;
int
audio_wheat_init
();
//接收音频播放
//接收音频播放
void
audioplay_mqtt_receive
(
cJSON
*
json
)
{
void
audioplay_mqtt_receive
(
cJSON
*
json
)
{
// 解析"audioLink"字段(修正了原始JSON中的拼写错误)
// 解析"audioLink"字段(修正了原始JSON中的拼写错误)
...
@@ -80,6 +82,9 @@ void audioplay_cycle(){
...
@@ -80,6 +82,9 @@ void audioplay_cycle(){
int
ret
;
int
ret
;
while
(
1
){
while
(
1
){
if
(
audio_status
==
0
){
if
(
audio_status
==
0
){
audio_wheat_init
();
char
*
urlmoddle
=
urlbuf
;
char
*
urlmoddle
=
urlbuf
;
snprintf
(
command
,
sizeof
(
command
),
snprintf
(
command
,
sizeof
(
command
),
"sudo ffplay -nodisp -autoexit -loglevel quiet -af
\"
volume=%1f
\"
\"
%s
\"
"
,
"sudo ffplay -nodisp -autoexit -loglevel quiet -af
\"
volume=%1f
\"
\"
%s
\"
"
,
...
@@ -105,18 +110,32 @@ void audioplay_cycle(){
...
@@ -105,18 +110,32 @@ void audioplay_cycle(){
}
}
}
}
int
audio_init
()
{
int
audio_wheat_init
(){
int
adino_jude
=
system
(
"pactl load-module module-alsa-sink device=hw:2,0"
);
int
adino_jude
=
system
(
"pactl load-module module-alsa-sink device=hw:2,0"
);
delay_s
(
3
);
if
(
adino_jude
==
0
){
my_zlog_debug
(
"命令执行成功!"
);
return
0
;
}
else
{
if
(
adino_jude
!=
0
)
my_zlog_warn
(
"喇叭命令执行失败,返回状态码: %d"
,
adino_jude
);
return
-
1
;
}
}
int
audio_speaker_init
()
{
int
adino_play_jude
=
system
(
"pactl load-module module-alsa-source device=hw:2,0"
);
int
adino_play_jude
=
system
(
"pactl load-module module-alsa-source device=hw:2,0"
);
if
(
adino_jude
==
0
&&
adino_play_jude
==
0
)
{
if
(
adino_play_jude
==
0
)
{
my_zlog_debug
(
"命令执行成功!"
);
my_zlog_debug
(
"命令执行成功!"
);
return
0
;
return
0
;
}
else
{
}
else
{
if
(
adino_jude
!=
0
)
my_zlog_warn
(
"麦命令执行失败,返回状态码: %d"
,
adino_jude
);
if
(
adino_play_jude
!=
0
)
my_zlog_warn
(
"麦命令执行失败,返回状态码: %d"
,
adino_play_jude
);
if
(
adino_play_jude
!=
0
)
my_zlog_warn
(
"喇叭命令执行失败,返回状态码: %d"
,
adino_play_jude
);
return
-
1
;
return
-
1
;
}
}
}
int
audio_init
(){
// audio_wheat_init();
// delay_s(3);
audio_speaker_init
();
}
}
\ No newline at end of file
drivers/sensors/audioplay.h
View file @
8629878c
...
@@ -7,5 +7,8 @@
...
@@ -7,5 +7,8 @@
void
audioplay_mqtt_receive
(
cJSON
*
body
);
//接收音频mqtt播放函数
void
audioplay_mqtt_receive
(
cJSON
*
body
);
//接收音频mqtt播放函数
void
audioplay_cycle
();
//音频播放线程中函数
void
audioplay_cycle
();
//音频播放线程中函数
int
audio_wheat_init
();
int
audio_speaker_init
();
int
audio_init
();
int
audio_init
();
#endif
#endif
\ No newline at end of file
modules/logger/mylog.c
View file @
8629878c
...
@@ -15,15 +15,19 @@ const char *c_config_content = "[global]\n"
...
@@ -15,15 +15,19 @@ const char *c_config_content = "[global]\n"
"[rules]
\n
"
"[rules]
\n
"
"# 日志文件路径,30天轮询,自动创建目录
\n
"
"# 日志文件路径,30天轮询,自动创建目录
\n
"
"my_log.*
\"
/home/orangepi/car/master/log/log.log
\"
, 30D; millisecond
\n
"
;
"my_log.*
\"
/home/orangepi/car/master/log/log.log
\"
, 30D; millisecond
\n
"
;
//
const char *LOG_FILE = "/home/orangepi/car/master/log/log.log";//日志文件
//
最后一行也可以写成"my_log.* \"/home/orangepi/car/master/log/log.log\",100M; millisecond{rotate 5}\n";
#define LOG_FILE "/home/orangepi/car/master/log/log.log" //日志文件
#define LOG_FILE "/home/orangepi/car/master/log/log.log" //日志文件
#define MAX_SIZE_MB 100 // 最大文件大小(MB)
static
zlog_category_t
*
s_zlog_c
=
NULL
;
static
zlog_category_t
*
s_zlog_c
=
NULL
;
int
logprject_Init
();
int
logprject_Init
();
int
logconf_create
();
int
logconf_create
();
void
check_and_delete_log
();
int
mylog_init
(){
int
mylog_init
(){
if
(
logconf_create
()
!=
0
)
{
if
(
logconf_create
()
!=
0
)
{
...
@@ -31,10 +35,15 @@ int mylog_init(){
...
@@ -31,10 +35,15 @@ int mylog_init(){
return
1
;
return
1
;
}
}
check_and_delete_log
();
if
(
logprject_Init
()
!=
0
)
{
if
(
logprject_Init
()
!=
0
)
{
my_zlog_fatal
(
"日志初始化失败"
);
my_zlog_fatal
(
"日志初始化失败"
);
return
2
;
return
2
;
}
}
my_zlog_info
(
"LOG_FILE权限成功"
);
my_zlog_info
(
"日志初始化成功"
);
my_zlog_info
(
"日志初始化成功"
);
return
0
;
return
0
;
}
}
...
@@ -53,6 +62,9 @@ int logconf_create() {
...
@@ -53,6 +62,9 @@ int logconf_create() {
// 写入配置内容
// 写入配置内容
fwrite
(
c_config_content
,
strlen
(
c_config_content
),
1
,
fp
);
fwrite
(
c_config_content
,
strlen
(
c_config_content
),
1
,
fp
);
fclose
(
fp
);
fclose
(
fp
);
system
(
"sudo chmod +666 /home/orangepi/car/master/zlog.conf"
);
printf
(
"zlog.conf has been created.
\n
"
);
printf
(
"zlog.conf has been created.
\n
"
);
}
else
{
}
else
{
printf
(
"zlog.conf already exists.
\n
"
);
printf
(
"zlog.conf already exists.
\n
"
);
...
@@ -108,10 +120,36 @@ int logprject_Init() {
...
@@ -108,10 +120,36 @@ int logprject_Init() {
zlog_fini
();
zlog_fini
();
return
-
3
;
return
-
3
;
}
}
system
(
"sudo chmod +666 /home/orangepi/car/master/log/log.log"
);
return
0
;
return
0
;
}
}
//日志文件过大则重新删除
void
check_and_delete_log
()
{
struct
stat
st
;
// 获取文件状态
if
(
stat
(
LOG_FILE
,
&
st
)
!=
0
)
{
perror
(
"stat"
);
return
;
}
// 判断文件大小是否大于 MAX_SIZE_MB
double
size_mb
=
st
.
st_size
/
(
1024
.
0
*
1024
.
0
);
if
(
size_mb
>
MAX_SIZE_MB
)
{
printf
(
"日志文件大小 %.2f MB 超过 %d MB,删除中...
\n
"
,
size_mb
,
MAX_SIZE_MB
);
if
(
remove
(
LOG_FILE
)
!=
0
)
{
perror
(
"删除文件失败"
);
}
else
{
printf
(
"日志文件已删除。
\n
"
);
system
(
"sudo reboot"
);
//重启香橙派
}
}
else
{
printf
(
"日志文件大小 %.2f MB,未超过 %d MB,无需删除。
\n
"
,
size_mb
,
MAX_SIZE_MB
);
}
}
// 封装 zlog_debug
// 封装 zlog_debug
void
my_zlog_debug
(
const
char
*
format
,
...)
{
void
my_zlog_debug
(
const
char
*
format
,
...)
{
...
...
modules/mqtt/mqtt_verify.h
View file @
8629878c
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
#include "cjson/cJSON.h"
#include "cjson/cJSON.h"
#include <pthread.h>
#include <pthread.h>
/*TRUE为打开验证,FALSE为关闭验证*/
/*TRUE为打开验证,FALSE为关闭验证*/
#define VERIFIED_MODE
TRU
E
#define VERIFIED_MODE
FALS
E
#define AES_BLOCK_SIZE 16
#define AES_BLOCK_SIZE 16
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment