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
059c3110
Commit
059c3110
authored
Oct 15, 2025
by
957dd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加入了自控开启和关闭
parent
555a2968
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
156 additions
and
42 deletions
+156
-42
pthread_open.c
app/main/pthread_open.c
+2
-2
main
build/main
+0
-0
tank0204_control.c
drivers/devicecontrol/tank0204_control.c
+6
-6
self_devicecontrol.c
drivers/selfcontrol/self_devicecontrol.c
+139
-32
self_devicecontrol.h
drivers/selfcontrol/self_devicecontrol.h
+7
-0
mqtt_infor_handle.c
modules/mqtt/mqtt_infor_handle.c
+2
-2
No files found.
app/main/pthread_open.c
View file @
059c3110
...
...
@@ -50,9 +50,9 @@ void *thread_exit_time(void *arg) {
g_devcontrol_exit_count
=
6
;
}
pthread_mutex_unlock
(
&
g_exit_count_mutex
);
}
else
{
set_self_control_time_countfuntion
();
}
else
if
(
get_self_control_index
()
==
true
){
delay_ms
(
20
);
set_self_control_time_countfuntion
();
}
}
...
...
build/main
View file @
059c3110
No preview for this file type
drivers/devicecontrol/tank0204_control.c
View file @
059c3110
...
...
@@ -134,23 +134,23 @@ void tank0204_change(unsigned char *buf) {
tank0204_mode_back
(
tank0204_front_val
+
10
);
tank0204_mode_lift
(
0
);
}
else
if
(
tank0204_front_t
==
0
&&
tank0204_steering_t
==
1
){
tank0204_mode_lift
(
tank0204_steering_val
+
tank0204_count
+
20
);
tank0204_mode_lift
(
tank0204_steering_val
+
tank0204_count
);
tank0204_mode_back
(
0
);
}
else
if
(
tank0204_front_t
==
0
&&
tank0204_steering_t
==
2
){
tank0204_mode_right
(
tank0204_steering_val
+
tank0204_count
+
20
);
tank0204_mode_right
(
tank0204_steering_val
+
tank0204_count
);
tank0204_mode_back
(
0
);
}
else
if
(
tank0204_front_t
==
1
&&
tank0204_steering_t
==
1
){
tank0204_mode_lift
(
tank0204_steering_val
+
4
0
);
tank0204_mode_lift
(
tank0204_steering_val
+
tank0204_count
+
10
0
);
tank0204_mode_flont
(
tank0204_steering_val
+
20
);
}
else
if
(
tank0204_front_t
==
1
&&
tank0204_steering_t
==
2
){
tank0204_mode_right
(
tank0204_steering_val
+
4
0
);
tank0204_mode_right
(
tank0204_steering_val
+
tank0204_count
+
10
0
);
tank0204_mode_flont
(
tank0204_steering_val
+
20
);
}
else
if
(
tank0204_front_t
==
2
&&
tank0204_steering_t
==
1
){
tank0204_mode_lift
(
tank0204_steering_val
+
4
0
);
tank0204_mode_lift
(
tank0204_steering_val
+
tank0204_count
+
10
0
);
tank0204_mode_back
(
tank0204_steering_val
+
20
);
}
else
if
(
tank0204_front_t
==
2
&&
tank0204_steering_t
==
2
){
tank0204_mode_right
(
tank0204_steering_val
+
4
0
);
tank0204_mode_right
(
tank0204_steering_val
+
tank0204_count
+
10
0
);
tank0204_mode_back
(
tank0204_steering_val
+
20
);
}
...
...
drivers/selfcontrol/self_devicecontrol.c
View file @
059c3110
...
...
@@ -5,38 +5,97 @@
#include "drivers_common.h"
static
ThreadPool_t
*
g_self_devicecontrol_task_t
;
static
ThreadPool_t
*
g_self_devicecontrol_task_t
;
//自控任务线程函数
static
bool
g_self_device_control_switch_index
=
false
;
//自控开关。是否打开或者关闭
static
int
self_control_interval
=
0
;
static
int
g_
self_control_interval
=
0
;
static
int
self_control_time_count
=
0
;
static
int
g_self_control_time_count
=
0
;
static
pthread_mutex_t
g_self_control_time_count_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
static
devicecontroltask_t
*
g_self_device_control_date
=
NULL
;
//设备自控全局数据指针
static
pthread_mutex_t
g_self_device_control_date_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
/*
* @brief
设置g_self_devicecontrol_task_t
* @brief
释放内存
*/
void
set_device_tasks
(
devicecontroltask_t
*
new_tasks
)
{
g_self_devicecontrol_task_t
=
new_tasks
;
void
free_device_tasks_memory
()
{
if
(
g_self_device_control_date
!=
NULL
){
pthread_mutex_lock
(
&
g_self_device_control_date_mutex
);
free
(
g_self_device_control_date
);
g_self_device_control_date
=
NULL
;
my_zlog_info
(
"free g_self_device_control_date"
);
pthread_mutex_unlock
(
&
g_self_device_control_date_mutex
);
}
else
return
;
}
/*
* @brief
自控线程中的任务
* @brief
分配内存封装函数
*/
void
self_device_control_task
(){
static
unsigned
char
s_valt
[
4
];
device_walk_control
(
g_device_type
,
s_valt
);
device_gpio_control
(
g_device_type
,
s_valt
[
1
],
s_valt
[
2
]);
void
malloc_device_tasks_memory
()
{
pthread_mutex_lock
(
&
g_self_device_control_date_mutex
);
if
(
g_self_device_control_date
==
NULL
){
g_self_device_control_date
=
(
devicecontroltask_t
*
)
malloc
(
sizeof
(
devicecontroltask_t
));
my_zlog_info
(
"malloc g_self_device_control_date"
);
}
pthread_mutex_unlock
(
&
g_self_device_control_date_mutex
);
}
/*
* @brief 自控线程中的计时函数接口,每20ms加一次
* @param[in] self_control_time_count,计时次数
*/
void
set_self_control_time_countfuntion
(){
self_control_time_count
++
;
pthread_mutex_lock
(
&
g_self_control_time_count_mutex
);
g_self_control_time_count
++
;
if
(
g_self_control_time_count
>
30000
)
g_self_control_time_count
=
30001
;
pthread_mutex_unlock
(
&
g_self_control_time_count_mutex
);
}
/*
* @brief 自控线程中的任务
*/
void
self_device_control_task
(){
static
int
i
=
0
;
static
unsigned
char
s_valt
[
3
];
s_valt
[
1
]
=
1
;
s_valt
[
2
]
=
80
;
long
long
time_now
=
g_self_control_time_count
*
20
;
if
(
i
>=
g_self_device_control_date
->
id_run_count
){
if
(
g_self_control_interval
<
time_now
){
return
;
}
i
=
0
;
}
my_zlog_debug
(
"id_run:%d"
,
g_self_device_control_date
->
id_run
[
i
]);
my_zlog_debug
(
"cool:%d"
,
g_self_device_control_date
->
run_cool
[
g_self_device_control_date
->
id_run
[
i
]]);
my_zlog_debug
(
"run:%d"
,
g_self_device_control_date
->
timed_run
[
g_self_device_control_date
->
id_run
[
i
]]);
if
(
time_now
>
g_self_device_control_date
->
run_cool
[
g_self_device_control_date
->
id_run
[
i
]]
&&
time_now
<=
(
g_self_device_control_date
->
run_cool
[
g_self_device_control_date
->
id_run
[
i
]]
+
g_self_device_control_date
->
timed_run
[
g_self_device_control_date
->
id_run
[
i
]])){
device_walk_control
(
g_device_type
,
s_valt
);
}
else
if
(
time_now
>
(
g_self_device_control_date
->
run_cool
[
g_self_device_control_date
->
id_run
[
i
]]
+
g_self_device_control_date
->
timed_run
[
g_self_device_control_date
->
id_run
[
i
]]))
{
s_valt
[
2
]
=
0
;
device_walk_control
(
g_device_type
,
s_valt
);
pthread_mutex_lock
(
&
g_self_control_time_count_mutex
);
g_self_control_time_count
=
0
;
pthread_mutex_unlock
(
&
g_self_control_time_count_mutex
);
i
=
i
+
1
;
}
}
/*
* @brief 自控线程
*/
...
...
@@ -46,6 +105,7 @@ void self_device_control_task_function(){
if
(
g_self_device_control_switch_index
==
true
){
self_device_control_task
();
}
else
if
(
g_self_device_control_switch_index
==
false
){
delay_ms
(
100
);
}
}
...
...
@@ -63,15 +123,6 @@ void self_device_pthrpoll_task_init(){
my_zlog_info
(
"自控线程池打开"
);
}
/*
* @brief 返回自控是否打开的标识接口
*/
bool
get_self_control_index
(){
return
g_self_device_control_switch_index
;
}
/*
* @brief 自控的线程开启标识设置。
* @param[in] 当index为,true为开,false为关
...
...
@@ -81,6 +132,13 @@ void set_self_control_index(bool index){
}
/*
* @brief 获取自控的线程开启标识。
*/
bool
get_self_control_index
(){
return
g_self_device_control_switch_index
;
}
/*
* @brief 销毁自控的线程
*/
void
self_control_thread_close
(){
...
...
@@ -121,7 +179,6 @@ void send_self_contorl_mqtt(){
cJSON_Delete
(
root
);
// 释放 cJSON 对象
}
/*
* @brief MQTT接收自控消息的函数
*/
...
...
@@ -138,26 +195,75 @@ void receive_self_contorl_mqtt(cJSON *body){
s_switch_status
=
switch_status
->
valueint
;
if
(
s_switch_status
==
DEVICE_SELF_CONTROL_OPEN
){
if
(
s_thread_index
==
0
)
self_device_pthrpoll_task_init
();
g_self_control_time_count
=
0
;
g_self_device_control_switch_index
=
true
;
s_thread_index
=
1
;
}
else
if
(
s_switch_status
==
DEVICE_SELF_CONTROL_CLOSE
)
{
g_self_device_control_switch_index
=
false
;
free_device_tasks_memory
();
send_self_contorl_mqtt
();
return
;
}
cJSON
*
interval
=
cJSON_GetObjectItem
(
body
,
"interval"
);
g_self_control_interval
=
interval
->
valueint
;
malloc_device_tasks_memory
();
//分配内存
// 2️ id_run 数组
//
cJSON *id_run = cJSON_GetObjectItem(body, "id_run");
// g_self_devicecontrol_task_t
->id_run_count = 0;
//
if (cJSON_IsArray(id_run)) {
//
int size = cJSON_GetArraySize(id_run);
//
for (int i = 0; i < size && i < DEVICE_WALK_SIGN_MAX; i++) {
//
cJSON *item = cJSON_GetArrayItem(id_run, i);
// g_self_devicecontrol_task_t->id_run[i] = item->valueint
;
// g_self_devicecontrol_task_t
->id_run_count++;
//
}
//
}
cJSON
*
id_run
=
cJSON_GetObjectItem
(
body
,
"id_run"
);
g_self_device_control_date
->
id_run_count
=
0
;
if
(
cJSON_IsArray
(
id_run
))
{
int
size
=
cJSON_GetArraySize
(
id_run
);
for
(
int
i
=
0
;
i
<
size
&&
i
<
DEVICE_WALK_SIGN_MAX
;
i
++
)
{
cJSON
*
item
=
cJSON_GetArrayItem
(
id_run
,
i
);
g_self_device_control_date
->
id_run
[
i
]
=
item
->
valueint
-
1
;
g_self_device_control_date
->
id_run_count
++
;
}
}
// 3 run_cool 数组
cJSON
*
run_cool
=
cJSON_GetObjectItem
(
body
,
"run_cool"
);
//g_self_device_control_date->id_run_count = 0;
if
(
cJSON_IsArray
(
run_cool
))
{
int
size
=
cJSON_GetArraySize
(
run_cool
);
for
(
int
i
=
0
;
i
<
size
&&
i
<
DEVICE_WALK_SIGN_MAX
;
i
++
)
{
cJSON
*
item
=
cJSON_GetArrayItem
(
run_cool
,
i
);
g_self_device_control_date
->
run_cool
[
g_self_device_control_date
->
id_run
[
i
]]
=
item
->
valueint
;
my_zlog_debug
(
"run_cool:%d"
,
g_self_device_control_date
->
timed_run
[
g_self_device_control_date
->
id_run
[
i
]]);
//g_self_device_control_date->id_run_count++;
}
}
// 4 timed_run 数组
cJSON
*
timed_run
=
cJSON_GetObjectItem
(
body
,
"timed_run"
);
//g_self_device_control_date->id_run_count = 0;
if
(
cJSON_IsArray
(
timed_run
))
{
int
size
=
cJSON_GetArraySize
(
timed_run
);
for
(
int
i
=
0
;
i
<
size
&&
i
<
DEVICE_WALK_SIGN_MAX
;
i
++
)
{
cJSON
*
item
=
cJSON_GetArrayItem
(
timed_run
,
i
);
g_self_device_control_date
->
timed_run
[
g_self_device_control_date
->
id_run
[
i
]]
=
item
->
valueint
;
my_zlog_debug
(
"arry:%d"
,
g_self_device_control_date
->
timed_run
[
g_self_device_control_date
->
id_run
[
i
]]);
//g_self_device_control_date->id_run_count++;
}
}
send_self_contorl_mqtt
();
my_zlog_debug
(
"count:%d"
,
g_self_device_control_date
->
id_run_count
);
return
;
}
/*
* @brief MQTT接收自控的相关的动作控制消息的函数
*/
void
receive_self_contorl_date_mqtt
(
cJSON
*
body
){
if
(
!
body
)
{
my_zlog_error
(
"JSON error!"
);
return
;
}
}
\ No newline at end of file
drivers/selfcontrol/self_devicecontrol.h
View file @
059c3110
...
...
@@ -20,6 +20,13 @@ typedef struct {
int
timed_run
[
DEVICE_WALK_SIGN_MAX
];
}
devicecontroltask_t
;
typedef
struct
{
int
mode
[
DEVICE_WALK_SIGN_MAX
];
int
val
[
DEVICE_WALK_SIGN_MAX
];
int
action_count
;
}
device_automatic_date_t
;
void
set_self_control_time_countfuntion
();
//计时
void
self_control_thread_close
();
...
...
modules/mqtt/mqtt_infor_handle.c
View file @
059c3110
...
...
@@ -5,7 +5,7 @@
#include "drivers_common.h"
#include "modules_common.h"
int
g_heartbeat_count
=
0
;
int
g_heartbeat_count
=
0
;
//心跳计数
/*
*
...
...
@@ -13,7 +13,7 @@ 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
;
int
g_message_type
=
0
;
//接收的mqtt的g_message_type
static
unsigned
char
g_valt
[
4
];
//存放mqtt接收的tpye,mode等
...
...
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