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
2fdb2575
Commit
2fdb2575
authored
Jul 29, 2025
by
957dd
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/add_pthreadlock' into 'master'
Feature/add pthreadlock See merge request
!50
parents
bfad18a5
09dce424
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
74 additions
and
27 deletions
+74
-27
CMakeLists.txt
CMakeLists.txt
+1
-1
main.c
app/main/main.c
+4
-4
pthread_open.c
app/main/pthread_open.c
+21
-1
version.h
build/include/version.h
+1
-1
main
build/main
+0
-0
tank0203_control.h
drivers/devicecontrol/tank0203_control.h
+0
-3
tank_common.c
drivers/devicecontrol/tank_common.c
+7
-9
tank_common.h
drivers/devicecontrol/tank_common.h
+2
-2
browser_open.c
modules/browser/browser_open.c
+27
-1
mqtt_infor_handle.c
modules/mqtt/mqtt_infor_handle.c
+6
-4
mqtt_infor_handle.h
modules/mqtt/mqtt_infor_handle.h
+3
-0
mqtt_verify.h
modules/mqtt/mqtt_verify.h
+2
-1
No files found.
CMakeLists.txt
View file @
2fdb2575
cmake_minimum_required
(
VERSION 3.10
)
project
(
car
VERSION 1.2.
0
VERSION 1.2.
1
LANGUAGES C
)
...
...
app/main/main.c
View file @
2fdb2575
...
...
@@ -11,6 +11,10 @@ int main(){
return
-
2
;
}
if
(
audio_init
()
!=
0
){
my_zlog_warn
(
"audio初始化有问题"
);
}
if
(
device_id_file_init
()
!=
0
){
my_zlog_error
(
"设备id读取失败"
);
return
-
3
;
...
...
@@ -34,10 +38,6 @@ int main(){
my_zlog_warn
(
"此版本电压没有使用INA226"
);
}
if
(
audio_init
()
!=
0
){
my_zlog_warn
(
"audio初始化有问题"
);
}
int
thread_rc
=
thread_start_init
(
thread_exit_time
,
thread_mqtt_beat
,
thread_open_browser
,
thread_mqtt_reconnect
,
thread_time_calculation
,
thread_play_mp3
);
if
(
thread_rc
!=
0
){
my_zlog_warn
(
"多线程初始化失败"
);
...
...
app/main/pthread_open.c
View file @
2fdb2575
...
...
@@ -46,11 +46,17 @@ int thread_start_init(ThreadFunc thread_exit_time, ThreadFunc thread_mqtt_beat,
void
*
thread_exit_time
(
void
*
arg
)
{
while
(
1
){
delay_ms
(
100
);
pthread_mutex_lock
(
&
g_exit_count_mutex
);
g_devcontrol_exit_count
++
;
if
(
g_devcontrol_exit_count
>=
5
)
{
device_stop
(
g_device_type
);
g_devcontrol_exit_count
=
6
;
}
pthread_mutex_unlock
(
&
g_exit_count_mutex
);
}
return
NULL
;
}
...
...
@@ -89,6 +95,7 @@ void *thread_open_browser(void *arg) {
//mqtt异常处理,断开自动重连,简单粗暴
void
*
thread_mqtt_reconnect
(
void
*
arg
)
{
if
(
mqtt_init
()
!=
0
)
{
my_zlog_fatal
(
"mqtt_init failed"
);
return
NULL
;
...
...
@@ -105,6 +112,7 @@ void *thread_mqtt_reconnect(void *arg) {
g_mqtt_grc
=
mqtt_create
(
mosq
);
if
(
g_mqtt_grc
!=
0
)
{
my_zlog_warn
(
"mqtt fail ..."
);
mqtt_clean
(
mosq
);
mosq
=
NULL
;
continue
;
...
...
@@ -112,6 +120,7 @@ void *thread_mqtt_reconnect(void *arg) {
g_mqtt_grc
=
mqtt_cycle
(
mosq
);
// 阻塞直到断开
if
(
g_mqtt_grc
!=
0
){
my_zlog_warn
(
"mqtt fail ..."
);
mqtt_clean
(
mosq
);
mosq
=
NULL
;
}
...
...
@@ -126,8 +135,18 @@ void *thread_time_calculation(void *arg) {
while
(
1
)
{
delay_ms
(
5
);
g_device_delay_count
++
;
//设备计时,坦克打击倒退逻辑
pthread_mutex_lock
(
&
g_verify_mutex
);
g_verify_count
++
;
//验证计时,每15s一次
if
(
g_verify_count
>=
20000
)
g_verify_count
=
20000
;
pthread_mutex_unlock
(
&
g_verify_mutex
);
if
(
g_verify_count
>=
20000
)
{
pthread_mutex_lock
(
&
g_verify_mutex
);
g_verify_count
=
20000
;
pthread_mutex_unlock
(
&
g_verify_mutex
);
}
if
(
g_device_delay_count
>=
5000
)
g_device_delay_count
=
5000
;
}
return
NULL
;
...
...
@@ -135,6 +154,7 @@ void *thread_time_calculation(void *arg) {
//专门处理MP3播放
void
*
thread_play_mp3
(
void
*
arg
)
{
audio_init
();
audioplay_cycle
();
return
NULL
;
}
...
...
build/include/version.h
View file @
2fdb2575
#define PROJECT_VERSION_MAJOR 1
#define PROJECT_VERSION_MINOR 2
#define PROJECT_VERSION_PATCH
0
#define PROJECT_VERSION_PATCH
1
#define GIT_HASH ""
#define BUILD_TIMESTAMP ""
#define BUILD_USER ""
build/main
View file @
2fdb2575
No preview for this file type
drivers/devicecontrol/tank0203_control.h
View file @
2fdb2575
...
...
@@ -7,8 +7,6 @@ void tank0203_middle();
void
tank0203_change
(
unsigned
char
*
buf
);
int
tank_shot_back_stop
(
int
pin
,
int
val
);
/*销毁坦克使用的线程池,让其正常销毁,只有在tank0202设备号下才有用*/
void
tank0203_thread_close
();
#endif
\ No newline at end of file
drivers/devicecontrol/tank_common.c
View file @
2fdb2575
...
...
@@ -3,14 +3,13 @@
#include "gpio_init.h"
#include "pthrpoll.h"
_Thread_local
const
tank_common_back
*
g_tank_common_config_t
=
NULL
;
int
tank_shot_back_stop
(
unsigned
char
pin
,
unsigned
char
val
);
const
tank_common_back
*
g_tank_common_config_t
=
NULL
;
long
long
shot_device_time_start
=
0
;
long
long
shot_device_time_end
=
0
;
int
tank_shot_back_stop
(
int
pin
,
int
val
);
void
tank_shot_back
(
unsigned
char
gval
)
{
if
(
gval
<
50
)
{
pwmWrite
(
PWM_PIN_CHANGE
,
75
);
...
...
@@ -72,6 +71,7 @@ const tank_common_back tank_common_config_t[]={
};
void
tank_shot_back_stop_task_function
(
void
*
arg
)
{
//多线程处理坦克发射后退线程池
while
(
1
){
long
long
interval
=
shot_device_time_start
-
shot_device_time_end
;
if
(
g_device_delay_count
>
g_tank_common_config_t
->
back_time
&&
g_device_delay_count
<
(
g_tank_common_config_t
->
back_time
+
30
))
...
...
@@ -98,7 +98,7 @@ void tank_shot_pthrpoll_task_init(){
my_zlog_debug
(
"线程池打开"
);
}
int
tank_shot_back_stop
(
int
pin
,
int
val
){
int
tank_shot_back_stop
(
unsigned
char
pin
,
unsigned
char
val
){
static
int
shot_count
=
0
;
shot_device_time_start
=
get_current_time_millis
();
if
(
pin
!=
27
){
...
...
@@ -129,7 +129,8 @@ void tank_thread_close(){
thread_pool_destroy
(
pool_tank_t
);
}
void
tank_shot_stop_control
(
int
device_id
,
int
pin
,
int
val
)
{
void
tank_shot_stop_control
(
int
device_id
,
unsigned
char
pin
,
unsigned
char
val
)
{
if
(
!
g_tank_common_config_t
||
g_tank_common_config_t
->
device_id
!=
device_id
)
{
// 查找设备配置
for
(
int
i
=
0
;
tank_common_config_t
[
i
].
device_id
!=
-
1
;
i
++
)
{
...
...
@@ -144,8 +145,6 @@ void tank_shot_stop_control(int device_id,int pin,int val) {
my_zlog_error
(
"Error: Device stop ID %d not found!
\n
"
,
device_id
);
return
;
}
g_tank_common_config_t
->
shot_back
(
pin
,
val
);
}
\ No newline at end of file
drivers/devicecontrol/tank_common.h
View file @
2fdb2575
...
...
@@ -8,10 +8,10 @@ typedef struct {
int
back_time
;
int
back_interval_back
;
int
shot_back_speed
;
int
(
*
shot_back
)(
int
pin
,
int
val
);
int
(
*
shot_back
)(
unsigned
char
pin
,
unsigned
char
val
);
}
tank_common_back
;
void
tank_shot_stop_control
(
int
device_id
,
int
pin
,
int
val
);
void
tank_shot_stop_control
(
int
device_id
,
unsigned
char
pin
,
unsigned
char
val
);
void
tank_thread_close
();
...
...
modules/browser/browser_open.c
View file @
2fdb2575
...
...
@@ -3,7 +3,7 @@
#include "device_fileopen.h"
#include "device_identity.h"
char
gwebcam
[
2
54
];
//存放启动火狐网站命令
char
gwebcam
[
2
048
];
//存放启动火狐网站命令
int
opencamsh_china
(){
const
char
*
url
=
"https://jywy.yd-ss.com?dev="
;
...
...
@@ -20,6 +20,32 @@ int opencamsh_china(){
}
// int opencamsh_china() {
// const char* url = "https://jywy.yd-ss.com?dev=";
// char urls[50];
// sprintf(urls, "%s%s", url, mqtt_topic_pure_number());
// // 使用nice和taskset提高优先级并绑定CPU核心
// sprintf(gwebcam, "su - orangepi -c \"nice -n -10 taskset -c 1 chromium-browser --use-fake-ui-for-media-stream "
// "--use-gl=egl "
// "--enable-features=WebRTC-H264WithOpenH264FFmpeg "
// "--disable-features=WebRTC-IPv6OnWiFi "
// "--enable-gpu-rasterization "
// "--enable-zero-copy "
// "--disable-quic "
// "--disable-gpu-compositing "
// "--autoplay-policy=no-user-gesture-required "
// "--window-size=800,600 --start-maximized "
// "%s\"", urls);
// system(gwebcam);
// my_zlog_debug("%s", gwebcam);
// my_zlog_debug("open cam");
// return 0;
// }
int
opencamsh_abroad
(){
const
char
*
url
=
"https://video.luckycar.top/?dev="
;
char
urls
[
50
];
...
...
modules/mqtt/mqtt_infor_handle.c
View file @
2fdb2575
...
...
@@ -18,10 +18,9 @@
#include "gpio_init.h"
#include "device_init.h"
int
g_heartbeat_count
=
0
;
pthread_mutex_t
g_exit_count_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
int
g_devcontrol_exit_count
=
0
;
int
g_message_type
=
0
;
...
...
@@ -134,7 +133,6 @@ void message_3(cJSON *body){
g_valt
[
0
]
=
typeTemp
;
g_valt
[
1
]
=
modeTemp
;
g_valt
[
2
]
=
valTemp
;
g_devcontrol_exit_count
=
0
;
my_zlog_debug
(
"typeTemp:%d"
,
g_valt
[
0
]);
my_zlog_debug
(
"modeTemp:%d"
,
g_valt
[
1
]);
...
...
@@ -161,7 +159,6 @@ void message_4(cJSON *body){//message 为4时候
valTemp
=
1
;
}
g_devcontrol_exit_count
=
0
;
g_valt
[
0
]
=
0
;
g_valt
[
1
]
=
pinTemp
;
g_valt
[
2
]
=
valTemp
;
...
...
@@ -171,6 +168,7 @@ void message_4(cJSON *body){//message 为4时候
pin_value
(
g_valt
[
1
],
g_valt
[
2
]);
pwm_value
(
g_valt
[
1
],
g_valt
[
2
]);
tank_shot_stop_control
(
g_device_type
,
g_valt
[
1
],
g_valt
[
2
]);
}
...
...
@@ -249,6 +247,10 @@ int device_message_receive(cJSON *json){//接收到的控制设备的mqtt消息
return
1
;
}
pthread_mutex_lock
(
&
g_exit_count_mutex
);
g_devcontrol_exit_count
=
0
;
pthread_mutex_unlock
(
&
g_exit_count_mutex
);
g_message_type
=
message_type
->
valueint
;
my_zlog_debug
(
"message_type: %d"
,
message_type
->
valueint
);
switch
(
g_message_type
){
...
...
modules/mqtt/mqtt_infor_handle.h
View file @
2fdb2575
...
...
@@ -3,11 +3,14 @@
#include "cjson/cJSON.h"
#include <pthread.h>
extern
int
g_heartbeat_count
;
extern
pthread_mutex_t
g_exit_count_mutex
;
extern
int
g_devcontrol_exit_count
;
void
mqtt_beat_wirte
();
int
device_message_receive
(
cJSON
*
json
);
...
...
modules/mqtt/mqtt_verify.h
View file @
2fdb2575
...
...
@@ -2,12 +2,13 @@
#define MQTT_VERIFY_H__
#include "cjson/cJSON.h"
#include <pthread.h>
/*TRUE为打开验证,FALSE为关闭验证*/
#define VERIFIED_MODE TRUE
#define AES_BLOCK_SIZE 16
extern
pthread_mutex_t
g_verify_mutex
;
extern
int
g_verify_count
;
//验证计时
extern
int
g_verify_index
;
//判断是否验证成功
...
...
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