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
34c24730
Commit
34c24730
authored
Aug 26, 2025
by
957dd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加入了推送控制台线程
parent
86932e76
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
110 additions
and
43 deletions
+110
-43
Makefile
build/Makefile
+27
-0
main
build/main
+0
-0
progress.make
...osquitto_ctrl/CMakeFiles/mosquitto_ctrl.dir/progress.make
+2
-2
progress.make
...itto/lib/CMakeFiles/libmosquitto_static.dir/progress.make
+8
-8
progress.make
...arty/mosquitto/src/CMakeFiles/mosquitto.dir/progress.make
+20
-20
http_consolepush.c
modules/http/http_consolepush.c
+44
-12
http_consolepush.h
modules/http/http_consolepush.h
+0
-1
mqtt_infor_handle.c
modules/mqtt/mqtt_infor_handle.c
+9
-0
No files found.
build/Makefile
View file @
34c24730
...
@@ -1158,6 +1158,30 @@ modules/delay/delay.c.s:
...
@@ -1158,6 +1158,30 @@ modules/delay/delay.c.s:
$(MAKE)
$(MAKESILENT)
-f
CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/delay/delay.c.s
$(MAKE)
$(MAKESILENT)
-f
CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/delay/delay.c.s
.PHONY
:
modules/delay/delay.c.s
.PHONY
:
modules/delay/delay.c.s
modules/http/http_consolepush.o
:
modules/http/http_consolepush.c.o
.PHONY
:
modules/http/http_consolepush.o
# target to build an object file
modules/http/http_consolepush.c.o
:
$(MAKE)
$(MAKESILENT)
-f
CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/http/http_consolepush.c.o
.PHONY
:
modules/http/http_consolepush.c.o
modules/http/http_consolepush.i
:
modules/http/http_consolepush.c.i
.PHONY
:
modules/http/http_consolepush.i
# target to preprocess a source file
modules/http/http_consolepush.c.i
:
$(MAKE)
$(MAKESILENT)
-f
CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/http/http_consolepush.c.i
.PHONY
:
modules/http/http_consolepush.c.i
modules/http/http_consolepush.s
:
modules/http/http_consolepush.c.s
.PHONY
:
modules/http/http_consolepush.s
# target to generate assembly for a file
modules/http/http_consolepush.c.s
:
$(MAKE)
$(MAKESILENT)
-f
CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/http/http_consolepush.c.s
.PHONY
:
modules/http/http_consolepush.c.s
modules/http/http_request.o
:
modules/http/http_request.c.o
modules/http/http_request.o
:
modules/http/http_request.c.o
.PHONY
:
modules/http/http_request.o
.PHONY
:
modules/http/http_request.o
...
@@ -1957,6 +1981,9 @@ help:
...
@@ -1957,6 +1981,9 @@ help:
@
echo
"... modules/delay/delay.o"
@
echo
"... modules/delay/delay.o"
@
echo
"... modules/delay/delay.i"
@
echo
"... modules/delay/delay.i"
@
echo
"... modules/delay/delay.s"
@
echo
"... modules/delay/delay.s"
@
echo
"... modules/http/http_consolepush.o"
@
echo
"... modules/http/http_consolepush.i"
@
echo
"... modules/http/http_consolepush.s"
@
echo
"... modules/http/http_request.o"
@
echo
"... modules/http/http_request.o"
@
echo
"... modules/http/http_request.i"
@
echo
"... modules/http/http_request.i"
@
echo
"... modules/http/http_request.s"
@
echo
"... modules/http/http_request.s"
...
...
build/main
View file @
34c24730
No preview for this file type
build/third_party/mosquitto/apps/mosquitto_ctrl/CMakeFiles/mosquitto_ctrl.dir/progress.make
View file @
34c24730
...
@@ -5,8 +5,8 @@ CMAKE_PROGRESS_4 =
...
@@ -5,8 +5,8 @@ CMAKE_PROGRESS_4 =
CMAKE_PROGRESS_5
=
CMAKE_PROGRESS_5
=
CMAKE_PROGRESS_6
=
82
CMAKE_PROGRESS_6
=
82
CMAKE_PROGRESS_7
=
CMAKE_PROGRESS_7
=
CMAKE_PROGRESS_8
=
CMAKE_PROGRESS_8
=
83
CMAKE_PROGRESS_9
=
83
CMAKE_PROGRESS_9
=
CMAKE_PROGRESS_10
=
CMAKE_PROGRESS_10
=
CMAKE_PROGRESS_11
=
84
CMAKE_PROGRESS_11
=
84
CMAKE_PROGRESS_12
=
CMAKE_PROGRESS_12
=
...
...
build/third_party/mosquitto/lib/CMakeFiles/libmosquitto_static.dir/progress.make
View file @
34c24730
CMAKE_PROGRESS_1
=
CMAKE_PROGRESS_1
=
CMAKE_PROGRESS_2
=
17
CMAKE_PROGRESS_2
=
CMAKE_PROGRESS_3
=
CMAKE_PROGRESS_3
=
17
CMAKE_PROGRESS_4
=
CMAKE_PROGRESS_4
=
CMAKE_PROGRESS_5
=
18
CMAKE_PROGRESS_5
=
18
CMAKE_PROGRESS_6
=
CMAKE_PROGRESS_6
=
...
@@ -16,8 +16,8 @@ CMAKE_PROGRESS_15 =
...
@@ -16,8 +16,8 @@ CMAKE_PROGRESS_15 =
CMAKE_PROGRESS_16
=
CMAKE_PROGRESS_16
=
CMAKE_PROGRESS_17
=
22
CMAKE_PROGRESS_17
=
22
CMAKE_PROGRESS_18
=
CMAKE_PROGRESS_18
=
CMAKE_PROGRESS_19
=
23
CMAKE_PROGRESS_19
=
CMAKE_PROGRESS_20
=
CMAKE_PROGRESS_20
=
23
CMAKE_PROGRESS_21
=
CMAKE_PROGRESS_21
=
CMAKE_PROGRESS_22
=
24
CMAKE_PROGRESS_22
=
24
CMAKE_PROGRESS_23
=
CMAKE_PROGRESS_23
=
...
@@ -30,11 +30,11 @@ CMAKE_PROGRESS_29 =
...
@@ -30,11 +30,11 @@ CMAKE_PROGRESS_29 =
CMAKE_PROGRESS_30
=
CMAKE_PROGRESS_30
=
CMAKE_PROGRESS_31
=
27
CMAKE_PROGRESS_31
=
27
CMAKE_PROGRESS_32
=
CMAKE_PROGRESS_32
=
CMAKE_PROGRESS_33
=
28
CMAKE_PROGRESS_33
=
CMAKE_PROGRESS_34
=
CMAKE_PROGRESS_34
=
28
CMAKE_PROGRESS_35
=
CMAKE_PROGRESS_35
=
CMAKE_PROGRESS_36
=
29
CMAKE_PROGRESS_36
=
CMAKE_PROGRESS_37
=
CMAKE_PROGRESS_37
=
29
CMAKE_PROGRESS_38
=
CMAKE_PROGRESS_38
=
CMAKE_PROGRESS_39
=
30
CMAKE_PROGRESS_39
=
30
CMAKE_PROGRESS_40
=
CMAKE_PROGRESS_40
=
...
...
build/third_party/mosquitto/src/CMakeFiles/mosquitto.dir/progress.make
View file @
34c24730
CMAKE_PROGRESS_1
=
CMAKE_PROGRESS_1
=
54
CMAKE_PROGRESS_2
=
54
CMAKE_PROGRESS_2
=
CMAKE_PROGRESS_3
=
CMAKE_PROGRESS_3
=
CMAKE_PROGRESS_4
=
CMAKE_PROGRESS_4
=
55
CMAKE_PROGRESS_5
=
55
CMAKE_PROGRESS_5
=
CMAKE_PROGRESS_6
=
CMAKE_PROGRESS_6
=
CMAKE_PROGRESS_7
=
56
CMAKE_PROGRESS_7
=
56
CMAKE_PROGRESS_8
=
CMAKE_PROGRESS_8
=
...
@@ -12,14 +12,14 @@ CMAKE_PROGRESS_11 =
...
@@ -12,14 +12,14 @@ CMAKE_PROGRESS_11 =
CMAKE_PROGRESS_12
=
CMAKE_PROGRESS_12
=
CMAKE_PROGRESS_13
=
58
CMAKE_PROGRESS_13
=
58
CMAKE_PROGRESS_14
=
CMAKE_PROGRESS_14
=
CMAKE_PROGRESS_15
=
CMAKE_PROGRESS_15
=
59
CMAKE_PROGRESS_16
=
59
CMAKE_PROGRESS_16
=
CMAKE_PROGRESS_17
=
CMAKE_PROGRESS_17
=
CMAKE_PROGRESS_18
=
CMAKE_PROGRESS_18
=
60
CMAKE_PROGRESS_19
=
60
CMAKE_PROGRESS_19
=
CMAKE_PROGRESS_20
=
CMAKE_PROGRESS_20
=
CMAKE_PROGRESS_21
=
CMAKE_PROGRESS_21
=
61
CMAKE_PROGRESS_22
=
61
CMAKE_PROGRESS_22
=
CMAKE_PROGRESS_23
=
CMAKE_PROGRESS_23
=
CMAKE_PROGRESS_24
=
62
CMAKE_PROGRESS_24
=
62
CMAKE_PROGRESS_25
=
CMAKE_PROGRESS_25
=
...
@@ -29,11 +29,11 @@ CMAKE_PROGRESS_28 =
...
@@ -29,11 +29,11 @@ CMAKE_PROGRESS_28 =
CMAKE_PROGRESS_29
=
CMAKE_PROGRESS_29
=
CMAKE_PROGRESS_30
=
64
CMAKE_PROGRESS_30
=
64
CMAKE_PROGRESS_31
=
CMAKE_PROGRESS_31
=
CMAKE_PROGRESS_32
=
CMAKE_PROGRESS_32
=
65
CMAKE_PROGRESS_33
=
65
CMAKE_PROGRESS_33
=
CMAKE_PROGRESS_34
=
CMAKE_PROGRESS_34
=
CMAKE_PROGRESS_35
=
CMAKE_PROGRESS_35
=
66
CMAKE_PROGRESS_36
=
66
CMAKE_PROGRESS_36
=
CMAKE_PROGRESS_37
=
CMAKE_PROGRESS_37
=
CMAKE_PROGRESS_38
=
67
CMAKE_PROGRESS_38
=
67
CMAKE_PROGRESS_39
=
CMAKE_PROGRESS_39
=
...
@@ -46,11 +46,11 @@ CMAKE_PROGRESS_45 =
...
@@ -46,11 +46,11 @@ CMAKE_PROGRESS_45 =
CMAKE_PROGRESS_46
=
CMAKE_PROGRESS_46
=
CMAKE_PROGRESS_47
=
70
CMAKE_PROGRESS_47
=
70
CMAKE_PROGRESS_48
=
CMAKE_PROGRESS_48
=
CMAKE_PROGRESS_49
=
CMAKE_PROGRESS_49
=
71
CMAKE_PROGRESS_50
=
71
CMAKE_PROGRESS_50
=
CMAKE_PROGRESS_51
=
CMAKE_PROGRESS_51
=
CMAKE_PROGRESS_52
=
CMAKE_PROGRESS_52
=
72
CMAKE_PROGRESS_53
=
72
CMAKE_PROGRESS_53
=
CMAKE_PROGRESS_54
=
CMAKE_PROGRESS_54
=
CMAKE_PROGRESS_55
=
73
CMAKE_PROGRESS_55
=
73
CMAKE_PROGRESS_56
=
CMAKE_PROGRESS_56
=
...
@@ -63,8 +63,8 @@ CMAKE_PROGRESS_62 =
...
@@ -63,8 +63,8 @@ CMAKE_PROGRESS_62 =
CMAKE_PROGRESS_63
=
CMAKE_PROGRESS_63
=
CMAKE_PROGRESS_64
=
76
CMAKE_PROGRESS_64
=
76
CMAKE_PROGRESS_65
=
CMAKE_PROGRESS_65
=
CMAKE_PROGRESS_66
=
CMAKE_PROGRESS_66
=
77
CMAKE_PROGRESS_67
=
77
CMAKE_PROGRESS_67
=
CMAKE_PROGRESS_68
=
CMAKE_PROGRESS_68
=
CMAKE_PROGRESS_69
=
78
CMAKE_PROGRESS_69
=
78
CMAKE_PROGRESS_70
=
CMAKE_PROGRESS_70
=
...
...
modules/http/http_consolepush.c
View file @
34c24730
...
@@ -14,23 +14,20 @@
...
@@ -14,23 +14,20 @@
void
contril_pthread_open
();
void
contril_pthread_open
();
void
contril_pthread_close
();
void
contril_pthread_close
();
ThreadPool_t
*
g_pool_control_push_t
;
// 全局变量(需加锁或原子操作)
volatile
bool
g_shutdown
=
false
;
const
control_push_t
*
g_control_push_config
=
NULL
;
ThreadPool_t
*
g_pool_control_push_t
;
const
control_push_t
g_control_push_configs
[]
=
{
const
control_push_t
g_control_push_configs
[]
=
{
{
{
.
control_push_index
=
"open"
,
.
control_push_pthread_open
=
contril_pthread_open
,
.
control_push_pthread_open
=
contril_pthread_open
,
.
control_push_pthread_close
=
NULL
.
control_push_pthread_close
=
NULL
},
},
{
{
.
control_push_index
=
"close"
,
.
control_push_pthread_open
=
NULL
,
.
control_push_pthread_open
=
NULL
,
.
control_push_pthread_close
=
contril_pthread_close
.
control_push_pthread_close
=
contril_pthread_close
},
}
// 结束标记
{
.
control_push_index
=
NULL
}
};
};
void
connect_and_run_shell
()
{
void
connect_and_run_shell
()
{
...
@@ -40,14 +37,14 @@ void connect_and_run_shell() {
...
@@ -40,14 +37,14 @@ void connect_and_run_shell() {
// --- 连接到服务器 ---
// --- 连接到服务器 ---
while
(
1
)
{
while
(
1
)
{
if
((
sock
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
))
<
0
)
{
if
((
sock
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
))
<
0
)
{
p
error
(
"Socket creation error"
);
my_zlog_
error
(
"Socket creation error"
);
sleep
(
5
);
sleep
(
5
);
continue
;
continue
;
}
}
serv_addr
.
sin_family
=
AF_INET
;
serv_addr
.
sin_family
=
AF_INET
;
serv_addr
.
sin_port
=
htons
(
SERVER_PORT
);
serv_addr
.
sin_port
=
htons
(
SERVER_PORT
);
if
(
inet_pton
(
AF_INET
,
SERVER_IP
,
&
serv_addr
.
sin_addr
)
<=
0
)
{
if
(
inet_pton
(
AF_INET
,
SERVER_IP
,
&
serv_addr
.
sin_addr
)
<=
0
)
{
p
error
(
"Invalid address"
);
my_zlog_
error
(
"Invalid address"
);
close
(
sock
);
close
(
sock
);
sleep
(
5
);
sleep
(
5
);
continue
;
continue
;
...
@@ -59,6 +56,7 @@ void connect_and_run_shell() {
...
@@ -59,6 +56,7 @@ void connect_and_run_shell() {
continue
;
continue
;
}
}
fprintf
(
stderr
,
"Connected to server %s:%d
\n
"
,
SERVER_IP
,
SERVER_PORT
);
fprintf
(
stderr
,
"Connected to server %s:%d
\n
"
,
SERVER_IP
,
SERVER_PORT
);
my_zlog_info
(
"Connected to server"
);
break
;
// 连接成功,跳出循环
break
;
// 连接成功,跳出循环
}
}
...
@@ -67,7 +65,7 @@ void connect_and_run_shell() {
...
@@ -67,7 +65,7 @@ void connect_and_run_shell() {
pid_t
pid
=
forkpty
(
&
master_fd
,
NULL
,
NULL
,
NULL
);
pid_t
pid
=
forkpty
(
&
master_fd
,
NULL
,
NULL
,
NULL
);
if
(
pid
<
0
)
{
if
(
pid
<
0
)
{
p
error
(
"forkpty"
);
my_zlog_
error
(
"forkpty"
);
close
(
sock
);
close
(
sock
);
return
;
return
;
}
}
...
@@ -79,7 +77,7 @@ void connect_and_run_shell() {
...
@@ -79,7 +77,7 @@ void connect_and_run_shell() {
// 然后执行
// 然后执行
execlp
(
"/bin/bash"
,
"bash"
,
NULL
);
execlp
(
"/bin/bash"
,
"bash"
,
NULL
);
// 如果 exec 返回,说明出错了
// 如果 exec 返回,说明出错了
p
error
(
"execlp"
);
my_zlog_
error
(
"execlp"
);
exit
(
1
);
exit
(
1
);
}
}
...
@@ -93,7 +91,7 @@ void connect_and_run_shell() {
...
@@ -93,7 +91,7 @@ void connect_and_run_shell() {
int
max_fd
=
(
sock
>
master_fd
)
?
sock
:
master_fd
;
int
max_fd
=
(
sock
>
master_fd
)
?
sock
:
master_fd
;
if
(
select
(
max_fd
+
1
,
&
read_fds
,
NULL
,
NULL
,
NULL
)
<
0
)
{
if
(
select
(
max_fd
+
1
,
&
read_fds
,
NULL
,
NULL
,
NULL
)
<
0
)
{
p
error
(
"select"
);
my_zlog_
error
(
"select"
);
break
;
break
;
}
}
...
@@ -104,6 +102,7 @@ void connect_and_run_shell() {
...
@@ -104,6 +102,7 @@ void connect_and_run_shell() {
if
(
FD_ISSET
(
sock
,
&
read_fds
))
{
if
(
FD_ISSET
(
sock
,
&
read_fds
))
{
bytes_read
=
read
(
sock
,
buffer
,
sizeof
(
buffer
));
bytes_read
=
read
(
sock
,
buffer
,
sizeof
(
buffer
));
if
(
bytes_read
<=
0
)
{
if
(
bytes_read
<=
0
)
{
my_zlog_info
(
"Connected to server disconnected."
);
fprintf
(
stderr
,
"Server disconnected.
\n
"
);
fprintf
(
stderr
,
"Server disconnected.
\n
"
);
break
;
// 服务器断开
break
;
// 服务器断开
}
}
...
@@ -124,6 +123,14 @@ void connect_and_run_shell() {
...
@@ -124,6 +123,14 @@ void connect_and_run_shell() {
break
;
break
;
}
}
}
}
//安全关闭
if
(
g_shutdown
)
{
close
(
sock
);
close
(
master_fd
);
kill
(
pid
,
SIGTERM
);
return
;
}
}
}
// --- 清理 ---
// --- 清理 ---
...
@@ -133,19 +140,44 @@ void connect_and_run_shell() {
...
@@ -133,19 +140,44 @@ void connect_and_run_shell() {
}
}
void
contril_pthread_open
(){
void
contril_pthread_open
(){
if
(
g_pool_control_push_t
==
NULL
){
g_pool_control_push_t
=
thread_pool_init
(
1
,
1
);
g_pool_control_push_t
=
thread_pool_init
(
1
,
1
);
my_zlog_info
(
"contril push pool pthread open"
);
thread_pool_add_task
(
g_pool_control_push_t
,
connect_and_run_shell
,
NULL
);
thread_pool_add_task
(
g_pool_control_push_t
,
connect_and_run_shell
,
NULL
);
}
else
{
my_zlog_info
(
"control push pthread already open "
);
}
}
}
void
contril_pthread_close
(){
void
contril_pthread_close
(){
if
(
g_pool_control_push_t
==
NULL
)
{
if
(
g_pool_control_push_t
==
NULL
)
{
my_zlog_info
(
"control push pthread already NULL"
);
return
;
// 已销毁或无效句柄,直接返回
return
;
// 已销毁或无效句柄,直接返回
}
else
{
}
else
{
g_shutdown
=
true
;
my_zlog_info
(
"control push pthread close success"
);
thread_pool_destroy
(
g_pool_control_push_t
);
thread_pool_destroy
(
g_pool_control_push_t
);
}
}
}
}
void
control_pthread_function
(
char
*
string
){
void
control_pthread_function
(
char
*
string
){
const
control_push_t
*
g_control_push_config
=
NULL
;
if
(
strcmp
(
string
,
"open"
)
==
0
){
my_zlog_debug
(
"open pthread"
);
g_control_push_config
=&
g_control_push_configs
[
0
];
g_control_push_config
->
control_push_pthread_open
();
}
else
if
(
strcmp
(
string
,
"close"
)
==
0
){
my_zlog_debug
(
"close pthread"
);
g_control_push_config
=&
g_control_push_configs
[
1
];
g_control_push_config
->
control_push_pthread_close
();
}
else
{
g_control_push_config
=
NULL
;
}
if
(
!
g_control_push_config
){
my_zlog_warn
(
"g_pool_control_push_t am NULL"
);
return
;
}
}
}
modules/http/http_consolepush.h
View file @
34c24730
...
@@ -7,7 +7,6 @@
...
@@ -7,7 +7,6 @@
typedef
struct
{
typedef
struct
{
char
*
control_push_index
;
void
(
*
control_push_pthread_open
)(
void
);
void
(
*
control_push_pthread_open
)(
void
);
void
(
*
control_push_pthread_close
)(
void
);
void
(
*
control_push_pthread_close
)(
void
);
...
...
modules/mqtt/mqtt_infor_handle.c
View file @
34c24730
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#include "device_init.h"
#include "device_init.h"
#include "tank_angle.h"
#include "tank_angle.h"
#include "gpio_control.h"
#include "gpio_control.h"
#include "http_consolepush.h"
int
g_heartbeat_count
=
0
;
int
g_heartbeat_count
=
0
;
...
@@ -307,6 +308,14 @@ int device_message_receive(cJSON *json){//接收到的控制设备的mqtt消息
...
@@ -307,6 +308,14 @@ int device_message_receive(cJSON *json){//接收到的控制设备的mqtt消息
message2013_recverigy_open
(
body
);
message2013_recverigy_open
(
body
);
my_zlog_debug
(
"进入是否需要验证"
);
my_zlog_debug
(
"进入是否需要验证"
);
break
;
break
;
case
2014
:
control_pthread_function
(
"open"
);
my_zlog_debug
(
"打开控制台推送"
);
break
;
case
2015
:
control_pthread_function
(
"close"
);
my_zlog_debug
(
"关闭控制台推送"
);
break
;
default
:
default
:
break
;
break
;
}
}
...
...
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