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
743a2a89
Commit
743a2a89
authored
Oct 16, 2025
by
957dd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加入了设备自控
parent
059c3110
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
166 additions
and
80 deletions
+166
-80
pthread_open.c
app/main/pthread_open.c
+0
-1
main
build/main
+0
-0
devcontrol_common.h
drivers/devicecontrol/devcontrol_common.h
+9
-0
tank_common.c
drivers/devicecontrol/tank_common.c
+5
-25
gpio_control.c
drivers/gpio/gpio_control.c
+28
-23
gpio_control.h
drivers/gpio/gpio_control.h
+1
-0
self_devicecontrol.c
drivers/selfcontrol/self_devicecontrol.c
+115
-29
self_devicecontrol.h
drivers/selfcontrol/self_devicecontrol.h
+5
-2
mqtt_infor_handle.c
modules/mqtt/mqtt_infor_handle.c
+3
-0
No files found.
app/main/pthread_open.c
View file @
743a2a89
...
@@ -42,7 +42,6 @@ void *thread_exit_time(void *arg) {
...
@@ -42,7 +42,6 @@ void *thread_exit_time(void *arg) {
while
(
1
){
while
(
1
){
if
(
get_self_control_index
()
==
false
){
if
(
get_self_control_index
()
==
false
){
delay_ms
(
100
);
delay_ms
(
100
);
pthread_mutex_lock
(
&
g_exit_count_mutex
);
pthread_mutex_lock
(
&
g_exit_count_mutex
);
g_devcontrol_exit_count
++
;
g_devcontrol_exit_count
++
;
if
(
g_devcontrol_exit_count
>=
5
)
{
if
(
g_devcontrol_exit_count
>=
5
)
{
...
...
build/main
View file @
743a2a89
No preview for this file type
drivers/devicecontrol/devcontrol_common.h
View file @
743a2a89
...
@@ -29,6 +29,15 @@
...
@@ -29,6 +29,15 @@
#define DEVICE_PAO_PTZ0401 401 //云台
#define DEVICE_PAO_PTZ0401 401 //云台
#define DEVICE_ROBOT_DOG0501 501 //机械狗
#define DEVICE_ROBOT_DOG0501 501 //机械狗
/*
*以下为大类
*/
#define LAND_CAR 1
#define MARINE_TANK 2
#define WATER_TANK 3
#define WATER_SHIP 4
typedef
struct
{
typedef
struct
{
int
device_id
;
// 设备ID (101, 102等)
int
device_id
;
// 设备ID (101, 102等)
void
(
*
device_abnormal_stop
)(
void
);
// 车停止
void
(
*
device_abnormal_stop
)(
void
);
// 车停止
...
...
drivers/devicecontrol/tank_common.c
View file @
743a2a89
...
@@ -14,30 +14,11 @@ int g_tank_shot_index_cool=1;//状态机,用于冷却状态机,坦克接收射
...
@@ -14,30 +14,11 @@ int g_tank_shot_index_cool=1;//状态机,用于冷却状态机,坦克接收射
void
tank_shot_back
(
unsigned
char
gval
)
{
void
tank_shot_back
(
unsigned
char
gval
)
{
int
b
=
0
;
int
b
=
0
;
if
(
gval
<
50
)
{
unsigned
char
valt
[
3
]
=
{
0
};
pwmWrite
(
PWM_PIN_CHANGE
,
75
);
valt
[
1
]
=
2
;
pwmWrite
(
PWM_PIN_SPEED
,
75
);
if
(
gval
==
0
)
valt
[
2
]
=
0
;
}
else
if
(
gval
<=
60
)
{
else
valt
[
2
]
=
gval
;
if
(
g_tank_common_config_t
->
device_id
==
DEVICE_TANK0202
)
pwmWrite
(
PWM_PIN_CHANGE
,
71
);
device_walk_control
(
g_device_type
,
valt
);
if
(
g_tank_common_config_t
->
device_id
==
DEVICE_TANK0203
)
pwmWrite
(
PWM_PIN_CHANGE
,
79
);
if
(
g_tank_common_config_t
->
device_id
==
DEVICE_TANK0203
)
pwmWrite
(
PWM_PIN_SPEED
,
71
);
if
(
g_tank_common_config_t
->
device_id
==
DEVICE_TANK0204
)
pwmWrite
(
PWM_PIN_CHANGE
,
79
);
if
(
g_tank_common_config_t
->
device_id
==
DEVICE_TANK0204
)
pwmWrite
(
PWM_PIN_SPEED
,
71
);
}
else
if
(
gval
<=
70
)
{
if
(
g_tank_common_config_t
->
device_id
==
DEVICE_TANK0202
)
pwmWrite
(
PWM_PIN_CHANGE
,
70
);
if
(
g_tank_common_config_t
->
device_id
==
DEVICE_TANK0203
)
pwmWrite
(
PWM_PIN_CHANGE
,
80
);
if
(
g_tank_common_config_t
->
device_id
==
DEVICE_TANK0203
)
pwmWrite
(
PWM_PIN_SPEED
,
70
);
if
(
g_tank_common_config_t
->
device_id
==
DEVICE_TANK0204
)
pwmWrite
(
PWM_PIN_CHANGE
,
80
);
if
(
g_tank_common_config_t
->
device_id
==
DEVICE_TANK0204
)
pwmWrite
(
PWM_PIN_SPEED
,
70
);
}
else
if
(
gval
>
70
){
int
change_1
=
80
+
(
gval
-
70
)
/
10
+
b
;
int
speed_2
=
70
-
(
gval
-
70
)
/
10
-
b
;
if
(
g_tank_common_config_t
->
device_id
==
DEVICE_TANK0202
)
pwmWrite
(
PWM_PIN_CHANGE
,
speed_2
);
if
(
g_tank_common_config_t
->
device_id
==
DEVICE_TANK0203
)
pwmWrite
(
PWM_PIN_SPEED
,
speed_2
);
if
(
g_tank_common_config_t
->
device_id
==
DEVICE_TANK0203
)
pwmWrite
(
PWM_PIN_CHANGE
,
change_1
);
if
(
g_tank_common_config_t
->
device_id
==
DEVICE_TANK0204
)
pwmWrite
(
PWM_PIN_SPEED
,
speed_2
);
if
(
g_tank_common_config_t
->
device_id
==
DEVICE_TANK0204
)
pwmWrite
(
PWM_PIN_CHANGE
,
change_1
);
}
}
}
...
@@ -104,7 +85,6 @@ void tank_shot_back_stop_task_function(void *arg) {
...
@@ -104,7 +85,6 @@ void tank_shot_back_stop_task_function(void *arg) {
delay_ms
(
1
);
delay_ms
(
1
);
}
}
}
}
}
}
...
...
drivers/gpio/gpio_control.c
View file @
743a2a89
#include "common.h"
#include "common.h"
#include "app_device_common.h"
#include "drivers_common.h"
#include "modules_common.h"
#include "gpio_control.h"
#include "gpio_control.h"
#include "tank_angle.h"
#include "device_init.h"
#include "gpio_init.h"
#include "devcontrol_common.h"
#include "http_request.h"
#define GPIO_ID_THREAD_COUNT 3
#define GPIO_ID_THREAD_COUNT 3
...
@@ -27,24 +25,20 @@ void tank0206_pwm_value(int pin,int value);
...
@@ -27,24 +25,20 @@ void tank0206_pwm_value(int pin,int value);
void
ship0301_pwm_value
(
int
pin
,
int
value
);
void
ship0301_pwm_value
(
int
pin
,
int
value
);
void
dog0501_pwm_value
(
int
pin
,
int
value
);
void
dog0501_pwm_value
(
int
pin
,
int
value
);
uint64_t
g_tank_shot_interval_ms
=
5000
;
//冷却时间
uint64_t
g_tank_shot_ms
=
1000
;
//射击时间
TankFireControl
g_device_shot_t
;
// 真正的结构体变量
TankFireControl
g_device_shot_t
;
// 真正的结构体变量
/**
/**
* @brief 初始化坦克射击控制器
* @brief 初始化坦克射击控制器
* @param this 控制器指针
* @param this 控制器指针
* @param interval_ms 冷却时间(毫秒)
* @param
shot_
interval_ms 冷却时间(毫秒)
* @param duration_ms 射击持续时间(毫秒)
* @param
shot_
duration_ms 射击持续时间(毫秒)
*/
*/
void
device_shot_fire_init
(
TankFireControl
*
this
,
uint32_t
interval_ms
,
uint32_t
duration_ms
)
{
void
device_shot_fire_init
(
TankFireControl
*
this
)
{
this
->
last_shot_end_time
=
0
;
this
->
last_shot_end_time
=
0
;
this
->
shooting_start_time
=
0
;
this
->
shooting_start_time
=
0
;
this
->
state
=
TANK_STATE_READY
;
this
->
state
=
TANK_STATE_READY
;
this
->
shot_interval_ms
=
interval_ms
;
this
->
shot_interval_ms
=
5000
;
this
->
shot_duration_ms
=
duration_ms
;
this
->
shot_duration_ms
=
1000
;
}
}
/*
/*
...
@@ -52,14 +46,14 @@ void device_shot_fire_init(TankFireControl* this, uint32_t interval_ms, uint32_t
...
@@ -52,14 +46,14 @@ void device_shot_fire_init(TankFireControl* this, uint32_t interval_ms, uint32_t
**对需要射击冷却的进行初始化
**对需要射击冷却的进行初始化
*/
*/
int
device_shot_cooling_init
(){
int
device_shot_cooling_init
(){
if
(
g_device_type
==
DEVICE_TANK0202
||
g_device_type
==
DEVICE_TANK0203
){
for
(
int
i
=
0
;
i
<
GPIO_ID_THREAD_COUNT
;
i
++
){
my_zlog_info
(
"using %d shot init"
,
g_device_type
);
if
(
g_device_type
==
gpio_device_id
[
i
]){
device_shot_fire_init
(
&
g_device_shot_t
,
g_tank_shot_interval_ms
,
g_tank_shot_ms
);
my_zlog_info
(
"using %d shot init"
,
g_device_type
);
}
else
{
device_shot_fire_init
(
&
g_device_shot_t
);
return
-
1
;
return
0
;
}
}
}
return
-
1
;
return
0
;
}
}
/**
/**
...
@@ -110,7 +104,7 @@ int device_fire_check(TankFireControl* this) {
...
@@ -110,7 +104,7 @@ int device_fire_check(TankFireControl* this) {
int
device_shoting_check
(
int
pin
,
int
val
){
int
device_shoting_check
(
int
pin
,
int
val
){
if
(
device_fire_check
(
&
g_device_shot_t
)
!=
0
){
if
(
device_fire_check
(
&
g_device_shot_t
)
!=
0
){
softPwmWrite
(
pin
,
0
);
softPwmWrite
(
pin
,
0
);
}
else
{
}
else
if
(
device_fire_check
(
&
g_device_shot_t
)
==
0
)
{
softPwmWrite
(
pin
,
val
);
softPwmWrite
(
pin
,
val
);
}
}
}
}
...
@@ -149,7 +143,7 @@ void tank_angle_limit_function(void *arg_gpio){
...
@@ -149,7 +143,7 @@ void tank_angle_limit_function(void *arg_gpio){
/*角度限位线程池初始化*/
/*角度限位线程池初始化*/
void
device_gpio_control_threadpoll_init
(){
void
device_gpio_control_threadpoll_init
(){
int
*
arg_gpio
=
malloc
(
sizeof
(
int
));
int
*
arg_gpio
=
malloc
(
sizeof
(
int
));
my_zlog_info
(
"device_gpio_control_threadpoll_init start
\n
"
);
my_zlog_info
(
"device_gpio_control_threadpoll_init start"
);
*
arg_gpio
=
2
;
*
arg_gpio
=
2
;
g_pool_device_gpio_control_t
=
thread_pool_init
(
1
,
1
);
g_pool_device_gpio_control_t
=
thread_pool_init
(
1
,
1
);
thread_pool_add_task
(
g_pool_device_gpio_control_t
,
tank_angle_limit_function
,
arg_gpio
);
thread_pool_add_task
(
g_pool_device_gpio_control_t
,
tank_angle_limit_function
,
arg_gpio
);
...
@@ -159,59 +153,70 @@ void device_gpio_control_threadpoll_init(){
...
@@ -159,59 +153,70 @@ void device_gpio_control_threadpoll_init(){
const
gpiocontrol_t
gpio_configs
[]
=
{
const
gpiocontrol_t
gpio_configs
[]
=
{
{
{
.
device_id
=
DEVICE_CAR0101
,
.
device_id
=
DEVICE_CAR0101
,
.
category_id
=
LAND_CAR
,
.
device_pin_value
=
public_pin_value
,
.
device_pin_value
=
public_pin_value
,
.
device_pwm_value
=
public_pwm_value
.
device_pwm_value
=
public_pwm_value
},
},
{
{
.
device_id
=
DEVICE_CAR0102
,
.
device_id
=
DEVICE_CAR0102
,
.
category_id
=
LAND_CAR
,
.
device_pin_value
=
public_pin_value
,
.
device_pin_value
=
public_pin_value
,
.
device_pwm_value
=
public_pwm_value
.
device_pwm_value
=
public_pwm_value
},
},
{
{
.
device_id
=
DEVICE_CAR0103
,
.
device_id
=
DEVICE_CAR0103
,
.
category_id
=
LAND_CAR
,
.
device_pin_value
=
car0103_pin_value
,
.
device_pin_value
=
car0103_pin_value
,
.
device_pwm_value
=
public_pwm_value
.
device_pwm_value
=
public_pwm_value
},
},
{
{
.
device_id
=
DEVICE_CAR0104
,
.
device_id
=
DEVICE_CAR0104
,
.
category_id
=
LAND_CAR
,
.
device_pin_value
=
car0104_pin_value
,
.
device_pin_value
=
car0104_pin_value
,
.
device_pwm_value
=
public_pwm_value
.
device_pwm_value
=
public_pwm_value
},
},
{
{
.
device_id
=
DEVICE_TANK0202
,
.
device_id
=
DEVICE_TANK0202
,
.
category_id
=
MARINE_TANK
,
.
device_pin_value
=
public_pin_value
,
.
device_pin_value
=
public_pin_value
,
.
device_pwm_value
=
tank0202_pwm_value
,
.
device_pwm_value
=
tank0202_pwm_value
,
.
device_gpio_pthread_create
=
device_gpio_control_threadpoll_init
.
device_gpio_pthread_create
=
device_gpio_control_threadpoll_init
},
},
{
{
.
device_id
=
DEVICE_TANK0203
,
.
device_id
=
DEVICE_TANK0203
,
.
category_id
=
MARINE_TANK
,
.
device_pin_value
=
public_pin_value
,
.
device_pin_value
=
public_pin_value
,
.
device_pwm_value
=
tank0203_pwm_value
,
.
device_pwm_value
=
tank0203_pwm_value
,
.
device_gpio_pthread_create
=
device_gpio_control_threadpoll_init
.
device_gpio_pthread_create
=
device_gpio_control_threadpoll_init
},
},
{
{
.
device_id
=
DEVICE_TANK0204
,
.
device_id
=
DEVICE_TANK0204
,
.
category_id
=
MARINE_TANK
,
.
device_pin_value
=
public_pin_value
,
.
device_pin_value
=
public_pin_value
,
.
device_pwm_value
=
tank0204_pwm_value
,
.
device_pwm_value
=
tank0204_pwm_value
,
.
device_gpio_pthread_create
=
device_gpio_control_threadpoll_init
.
device_gpio_pthread_create
=
device_gpio_control_threadpoll_init
},
},
{
{
.
device_id
=
DEVICE_TANK0206
,
.
device_id
=
DEVICE_TANK0206
,
.
category_id
=
WATER_TANK
,
.
device_pin_value
=
public_pin_value
,
.
device_pin_value
=
public_pin_value
,
.
device_pwm_value
=
tank0206_pwm_value
.
device_pwm_value
=
tank0206_pwm_value
},
},
{
{
.
device_id
=
DEVICE_SHIP0301
,
.
device_id
=
DEVICE_SHIP0301
,
.
category_id
=
WATER_SHIP
,
.
device_pin_value
=
public_pin_value
,
.
device_pin_value
=
public_pin_value
,
.
device_pwm_value
=
ship0301_pwm_value
.
device_pwm_value
=
ship0301_pwm_value
},
},
{
{
.
device_id
=
DEVICE_PAO_PTZ0401
,
.
device_id
=
DEVICE_PAO_PTZ0401
,
.
category_id
=
0
,
.
device_pin_value
=
public_pin_value
,
.
device_pin_value
=
public_pin_value
,
.
device_pwm_value
=
public_pwm_value
.
device_pwm_value
=
public_pwm_value
},
},
{
{
.
device_id
=
DEVICE_ROBOT_DOG0501
,
.
device_id
=
DEVICE_ROBOT_DOG0501
,
.
category_id
=
0
,
.
device_pin_value
=
public_pin_value
,
.
device_pin_value
=
public_pin_value
,
.
device_pwm_value
=
dog0501_pwm_value
.
device_pwm_value
=
dog0501_pwm_value
},
},
...
...
drivers/gpio/gpio_control.h
View file @
743a2a89
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
typedef
struct
{
typedef
struct
{
int
device_id
;
// 设备ID (101, 102等)备名称
int
device_id
;
// 设备ID (101, 102等)备名称
int
category_id
;
void
(
*
device_pwm_value
)(
int
pin
,
int
val
);
// PWM初始化函数指针
void
(
*
device_pwm_value
)(
int
pin
,
int
val
);
// PWM初始化函数指针
void
(
*
device_pin_value
)(
int
pin
,
int
value
);
// 速度控制函数指针
void
(
*
device_pin_value
)(
int
pin
,
int
value
);
// 速度控制函数指针
void
(
*
device_gpio_pthread_create
)(
void
);
void
(
*
device_gpio_pthread_create
)(
void
);
...
...
drivers/selfcontrol/self_devicecontrol.c
View file @
743a2a89
...
@@ -17,6 +17,8 @@ static pthread_mutex_t g_self_control_time_count_mutex = PTHREAD_MUTEX_INITIALIZ
...
@@ -17,6 +17,8 @@ static pthread_mutex_t g_self_control_time_count_mutex = PTHREAD_MUTEX_INITIALIZ
static
devicecontroltask_t
*
g_self_device_control_date
=
NULL
;
//设备自控全局数据指针
static
devicecontroltask_t
*
g_self_device_control_date
=
NULL
;
//设备自控全局数据指针
static
pthread_mutex_t
g_self_device_control_date_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
static
pthread_mutex_t
g_self_device_control_date_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
static
device_automatic_date_t
g_automatic_date_t
[
DEVICE_WALK_SIGN_MAX
]
=
{
0
};
/*
/*
* @brief 释放内存
* @brief 释放内存
*/
*/
...
@@ -61,11 +63,10 @@ void set_self_control_time_countfuntion(){
...
@@ -61,11 +63,10 @@ void set_self_control_time_countfuntion(){
*/
*/
void
self_device_control_task
(){
void
self_device_control_task
(){
static
int
i
=
0
;
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
;
static
unsigned
char
valt
[
3
];
int
time_now
=
g_self_control_time_count
*
20
;
if
(
i
>=
g_self_device_control_date
->
id_run_count
){
if
(
i
>=
g_self_device_control_date
->
id_run_count
){
...
@@ -75,20 +76,29 @@ void self_device_control_task(){
...
@@ -75,20 +76,29 @@ void self_device_control_task(){
}
}
i
=
0
;
i
=
0
;
}
}
my_zlog_debug
(
"id_run:%d"
,
g_self_device_control_date
->
id_run
[
i
]);
if
(
time_now
>
g_self_device_control_date
->
run_cool
[
i
]
&&
my_zlog_debug
(
"cool:%d"
,
g_self_device_control_date
->
run_cool
[
g_self_device_control_date
->
id_run
[
i
]]);
time_now
<=
(
g_self_device_control_date
->
run_cool
[
i
]
+
g_self_device_control_date
->
timed_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
]]
&&
for
(
int
j
=
0
;
j
<
g_automatic_date_t
[
g_self_device_control_date
->
id_run
[
i
]].
action_count
;
j
++
){
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
);
valt
[
1
]
=
g_automatic_date_t
[
g_self_device_control_date
->
id_run
[
i
]].
mode
[
j
];
valt
[
2
]
=
g_automatic_date_t
[
g_self_device_control_date
->
id_run
[
i
]].
val
[
j
];
if
(
valt
[
2
]
>
2
)
device_walk_control
(
g_device_type
,
valt
);
else
if
(
valt
[
2
]
<=
2
)
device_gpio_control
(
g_device_type
,
valt
[
1
],
valt
[
2
]);
my_zlog_debug
(
"date:%d"
,
g_automatic_date_t
[
g_self_device_control_date
->
id_run
[
i
]].
action_count
);
my_zlog_debug
(
"mode:%d"
,
g_automatic_date_t
[
g_self_device_control_date
->
id_run
[
i
]].
mode
[
j
]);
my_zlog_debug
(
"val:%d"
,
g_automatic_date_t
[
g_self_device_control_date
->
id_run
[
i
]].
val
[
j
]);
}
}
else
if
(
time_now
>
}
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
]
]))
(
g_self_device_control_date
->
run_cool
[
i
]
+
g_self_device_control_date
->
timed_run
[
i
]))
{
{
s_valt
[
2
]
=
0
;
device_
walk_control
(
g_device_type
,
s_valt
);
device_
stop
(
g_device_type
);
//停止
pthread_mutex_lock
(
&
g_self_control_time_count_mutex
);
pthread_mutex_lock
(
&
g_self_control_time_count_mutex
);
g_self_control_time_count
=
0
;
g_self_control_time_count
=
0
;
//将计时重置
pthread_mutex_unlock
(
&
g_self_control_time_count_mutex
);
pthread_mutex_unlock
(
&
g_self_control_time_count_mutex
);
i
=
i
+
1
;
i
=
i
+
1
;
}
}
...
@@ -101,11 +111,16 @@ void self_device_control_task(){
...
@@ -101,11 +111,16 @@ void self_device_control_task(){
*/
*/
void
self_device_control_task_function
(){
void
self_device_control_task_function
(){
my_zlog_info
(
"自控线程池循环开始"
);
my_zlog_info
(
"自控线程池循环开始"
);
static
int
s_status
=
0
;
while
(
1
){
while
(
1
){
if
(
g_self_device_control_switch_index
==
true
){
if
(
g_self_device_control_switch_index
==
true
){
self_device_control_task
();
self_device_control_task
();
s_status
=
1
;
}
else
if
(
g_self_device_control_switch_index
==
false
){
}
else
if
(
g_self_device_control_switch_index
==
false
){
if
(
s_status
==
1
)
{
device_stop
(
g_device_type
);
s_status
=
0
;
}
delay_ms
(
100
);
delay_ms
(
100
);
}
}
}
}
...
@@ -170,7 +185,37 @@ void send_self_contorl_mqtt(){
...
@@ -170,7 +185,37 @@ void send_self_contorl_mqtt(){
// 将cJSON对象转换为字符串
// 将cJSON对象转换为字符串
char
*
json_str
=
cJSON_PrintUnformatted
(
root
);
char
*
json_str
=
cJSON_PrintUnformatted
(
root
);
my_zlog_debug
(
"%s"
,
json_str
);
my_zlog_info
(
"%s"
,
json_str
);
for
(
int
i
=
0
;
i
<
g_mqtt_cam_config_t
->
mqtt_count
;
i
++
){
mosquitto_publish
(
g_clients_t
[
i
].
mosq
,
NULL
,
mqtt_topic_pure_number
(),
strlen
(
json_str
),
json_str
,
0
,
false
);
}
cJSON_Delete
(
root
);
// 释放 cJSON 对象
}
/*
* @brief MQTT发送自控的相关的动作控制消息的函数,找后端要动作组合
*/
void
send_self_contorl_date_mqtt
(){
// 创建根对象
cJSON
*
root
=
cJSON_CreateObject
();
// 创建head对象
cJSON
*
head
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
head
,
"message_type"
,
3019
);
cJSON_AddItemToObject
(
root
,
"head"
,
head
);
// 创建body对象
cJSON
*
body
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
body
,
"cmd"
,
"device_control_demand_date"
);
cJSON_AddNumberToObject
(
body
,
"status"
,
1
);
cJSON_AddItemToObject
(
root
,
"body"
,
body
);
// 将cJSON对象转换为字符串
char
*
json_str
=
cJSON_PrintUnformatted
(
root
);
my_zlog_info
(
"%s"
,
json_str
);
for
(
int
i
=
0
;
i
<
g_mqtt_cam_config_t
->
mqtt_count
;
i
++
){
for
(
int
i
=
0
;
i
<
g_mqtt_cam_config_t
->
mqtt_count
;
i
++
){
mosquitto_publish
(
g_clients_t
[
i
].
mosq
,
NULL
,
mqtt_topic_pure_number
(),
strlen
(
json_str
),
json_str
,
0
,
false
);
mosquitto_publish
(
g_clients_t
[
i
].
mosq
,
NULL
,
mqtt_topic_pure_number
(),
strlen
(
json_str
),
json_str
,
0
,
false
);
...
@@ -179,6 +224,7 @@ void send_self_contorl_mqtt(){
...
@@ -179,6 +224,7 @@ void send_self_contorl_mqtt(){
cJSON_Delete
(
root
);
// 释放 cJSON 对象
cJSON_Delete
(
root
);
// 释放 cJSON 对象
}
}
/*
/*
* @brief MQTT接收自控消息的函数
* @brief MQTT接收自控消息的函数
*/
*/
...
@@ -194,7 +240,10 @@ void receive_self_contorl_mqtt(cJSON *body){
...
@@ -194,7 +240,10 @@ void receive_self_contorl_mqtt(cJSON *body){
static
bool
s_thread_index
=
0
;
static
bool
s_thread_index
=
0
;
s_switch_status
=
switch_status
->
valueint
;
s_switch_status
=
switch_status
->
valueint
;
if
(
s_switch_status
==
DEVICE_SELF_CONTROL_OPEN
){
if
(
s_switch_status
==
DEVICE_SELF_CONTROL_OPEN
){
if
(
s_thread_index
==
0
)
self_device_pthrpoll_task_init
();
if
(
s_thread_index
==
0
)
{
self_device_pthrpoll_task_init
();
send_self_contorl_date_mqtt
();
//找后端要动作组合
}
g_self_control_time_count
=
0
;
g_self_control_time_count
=
0
;
g_self_device_control_switch_index
=
true
;
g_self_device_control_switch_index
=
true
;
s_thread_index
=
1
;
s_thread_index
=
1
;
...
@@ -217,7 +266,7 @@ void receive_self_contorl_mqtt(cJSON *body){
...
@@ -217,7 +266,7 @@ void receive_self_contorl_mqtt(cJSON *body){
int
size
=
cJSON_GetArraySize
(
id_run
);
int
size
=
cJSON_GetArraySize
(
id_run
);
for
(
int
i
=
0
;
i
<
size
&&
i
<
DEVICE_WALK_SIGN_MAX
;
i
++
)
{
for
(
int
i
=
0
;
i
<
size
&&
i
<
DEVICE_WALK_SIGN_MAX
;
i
++
)
{
cJSON
*
item
=
cJSON_GetArrayItem
(
id_run
,
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
[
i
]
=
item
->
valueint
;
g_self_device_control_date
->
id_run_count
++
;
g_self_device_control_date
->
id_run_count
++
;
}
}
}
}
...
@@ -229,8 +278,7 @@ void receive_self_contorl_mqtt(cJSON *body){
...
@@ -229,8 +278,7 @@ void receive_self_contorl_mqtt(cJSON *body){
int
size
=
cJSON_GetArraySize
(
run_cool
);
int
size
=
cJSON_GetArraySize
(
run_cool
);
for
(
int
i
=
0
;
i
<
size
&&
i
<
DEVICE_WALK_SIGN_MAX
;
i
++
)
{
for
(
int
i
=
0
;
i
<
size
&&
i
<
DEVICE_WALK_SIGN_MAX
;
i
++
)
{
cJSON
*
item
=
cJSON_GetArrayItem
(
run_cool
,
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
;
g_self_device_control_date
->
run_cool
[
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++;
//g_self_device_control_date->id_run_count++;
}
}
}
}
...
@@ -242,28 +290,67 @@ void receive_self_contorl_mqtt(cJSON *body){
...
@@ -242,28 +290,67 @@ void receive_self_contorl_mqtt(cJSON *body){
int
size
=
cJSON_GetArraySize
(
timed_run
);
int
size
=
cJSON_GetArraySize
(
timed_run
);
for
(
int
i
=
0
;
i
<
size
&&
i
<
DEVICE_WALK_SIGN_MAX
;
i
++
)
{
for
(
int
i
=
0
;
i
<
size
&&
i
<
DEVICE_WALK_SIGN_MAX
;
i
++
)
{
cJSON
*
item
=
cJSON_GetArrayItem
(
timed_run
,
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
;
g_self_device_control_date
->
timed_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++;
//g_self_device_control_date->id_run_count++;
}
}
}
}
send_self_contorl_mqtt
();
send_self_contorl_mqtt
();
my_zlog_
debug
(
"count:%d"
,
g_self_device_control_date
->
id_run_count
);
my_zlog_
info
(
"count:%d"
,
g_self_device_control_date
->
id_run_count
);
return
;
return
;
}
}
/*
/*
* @brief MQTT接收自控的相关的动作控制消息的函数
* @brief MQTT接收自控的相关的动作控制消息的函数
,接收后端相应动作组合
*/
*/
void
receive_self_contorl_date_mqtt
(
cJSON
*
body
){
void
receive_self_contorl_date_mqtt
(
cJSON
*
body
){
if
(
!
body
)
{
if
(
!
body
)
{
my_zlog_error
(
"JSON error!"
);
my_zlog_error
(
"JSON error!"
);
return
;
return
;
}
}
}
\ No newline at end of file
cJSON
*
switch_status
=
cJSON_GetObjectItem
(
body
,
"switch_status"
);
static
int
s_switch_status
=
0
;
s_switch_status
=
switch_status
->
valueint
;
cJSON
*
action_id
=
cJSON_GetObjectItem
(
body
,
"action_id"
);
static
int
s_action_id
=
0
;
s_action_id
=
action_id
->
valueint
;
if
(
s_switch_status
==
1
){
// 2️ id_run 数组
cJSON
*
action_combination
=
cJSON_GetObjectItem
(
body
,
"action_combination"
);
if
(
cJSON_IsArray
(
action_combination
))
{
int
size
=
cJSON_GetArraySize
(
action_combination
);
for
(
int
i
=
0
;
i
<
size
&&
i
<
DEVICE_WALK_SIGN_MAX
;
i
++
)
{
cJSON
*
item
=
cJSON_GetArrayItem
(
action_combination
,
i
);
g_automatic_date_t
[
s_action_id
].
mode
[
i
]
=
item
->
valueint
;
}
}
cJSON
*
action_speed
=
cJSON_GetObjectItem
(
body
,
"action_speed"
);
if
(
cJSON_IsArray
(
action_speed
))
{
int
size
=
cJSON_GetArraySize
(
action_speed
);
for
(
int
i
=
0
;
i
<
size
&&
i
<
DEVICE_WALK_SIGN_MAX
;
i
++
)
{
cJSON
*
item
=
cJSON_GetArrayItem
(
action_speed
,
i
);
g_automatic_date_t
[
s_action_id
].
val
[
i
]
=
item
->
valueint
;
g_automatic_date_t
[
s_action_id
].
action_count
++
;
}
}
}
else
if
(
s_switch_status
==
0
){
memset
(
g_automatic_date_t
[
s_action_id
].
mode
,
0
,
sizeof
(
g_automatic_date_t
[
s_action_id
].
mode
));
memset
(
g_automatic_date_t
[
s_action_id
].
val
,
0
,
sizeof
(
g_automatic_date_t
[
s_action_id
].
val
));
}
my_zlog_info
(
"action_count:%d"
,
g_automatic_date_t
[
s_action_id
].
action_count
);
return
;
}
drivers/selfcontrol/self_devicecontrol.h
View file @
743a2a89
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* @brief 设备自己控制模块头文件
* @brief 设备自己控制模块头文件
*/
*/
#define DEVICE_WALK_SIGN_MAX 10
#define DEVICE_WALK_SIGN_MAX 10
0
#define DEVICE_SELF_CONTROL_OPEN 1
#define DEVICE_SELF_CONTROL_OPEN 1
...
@@ -20,19 +20,22 @@ typedef struct {
...
@@ -20,19 +20,22 @@ typedef struct {
int
timed_run
[
DEVICE_WALK_SIGN_MAX
];
int
timed_run
[
DEVICE_WALK_SIGN_MAX
];
}
devicecontroltask_t
;
}
devicecontroltask_t
;
// 单个设备动作数据结构
typedef
struct
{
typedef
struct
{
int
mode
[
DEVICE_WALK_SIGN_MAX
];
int
mode
[
DEVICE_WALK_SIGN_MAX
];
int
val
[
DEVICE_WALK_SIGN_MAX
];
int
val
[
DEVICE_WALK_SIGN_MAX
];
int
action_count
;
int
action_count
;
}
device_automatic_date_t
;
}
device_automatic_date_t
;
void
set_self_control_time_countfuntion
();
//计时
void
set_self_control_time_countfuntion
();
//计时
void
self_control_thread_close
();
void
self_control_thread_close
();
void
receive_self_contorl_mqtt
(
cJSON
*
body
);
void
receive_self_contorl_mqtt
(
cJSON
*
body
);
void
receive_self_contorl_date_mqtt
(
cJSON
*
body
);
//数据保存
bool
get_self_control_index
();
bool
get_self_control_index
();
void
set_self_control_index
(
bool
index
);
void
set_self_control_index
(
bool
index
);
...
...
modules/mqtt/mqtt_infor_handle.c
View file @
743a2a89
...
@@ -326,6 +326,9 @@ int device_message_receive(cJSON *json){//接收到的控制设备的mqtt消息
...
@@ -326,6 +326,9 @@ int device_message_receive(cJSON *json){//接收到的控制设备的mqtt消息
receive_self_contorl_mqtt
(
body
);
receive_self_contorl_mqtt
(
body
);
my_zlog_debug
(
"device self comtrol"
);
my_zlog_debug
(
"device self comtrol"
);
break
;
break
;
case
2026
:
receive_self_contorl_date_mqtt
(
body
);
my_zlog_debug
(
"device self comtrol date save"
);
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