Commit 62ef36cf authored by 学习的菜鸟's avatar 学习的菜鸟

加入了结构体

parent 4d92d557
No preview for this file type
......@@ -169,7 +169,7 @@ void mode_car0103_right_back(unsigned char gval) {
}
}
int car0103_change(unsigned char *buf) {
void car0103_change(unsigned char *buf) {
unsigned char mode = buf[1];
unsigned char val = buf[2];
if(mode == 1 ) {
......
......@@ -3,6 +3,6 @@
void car0103_middle();
int car0103_change(unsigned char *buf);
void car0103_change(unsigned char *buf);
#endif
\ No newline at end of file
......@@ -168,7 +168,7 @@ void car0104_lift(unsigned char gval) {
}
}
int car0104_change(unsigned char *buf) {
void car0104_change(unsigned char *buf) {
unsigned char mode = buf[1];
unsigned char val = buf[2];
......
......@@ -3,6 +3,6 @@
void car0104_stop();
int car0104_change(unsigned char *buf);
void car0104_change(unsigned char *buf);
#endif
\ No newline at end of file
#include "devcontrol_common.h"
const device_didrive device_didrive_control_config_t[]={
{
.device_id = DEVICE_CAR0101,
.device_didrive_control = car0101_control_change
},
{
.device_id = DEVICE_CAR0102,
.device_didrive_control = car0102_speed_change
},
{
.device_id = DEVICE_CAR0103,
.device_didrive_control = car0103_change
},
{
.device_id = DEVICE_CAR0104,
.device_didrive_control = car0104_change
},
{
.device_id = DEVICE_TANK0202,
.device_didrive_control = tank0202_change
},
{
.device_id = DEVICE_PAO_PTZ0401,
.device_didrive_control = PTZ_pwm_change
},
// 结束标记
{ .device_id = -1 }
};
const device_abnormal_close_t devcontrol_config_t[]= {
{
.device_id = DEVICE_CAR0101,
......@@ -20,7 +49,7 @@ const device_abnormal_close_t devcontrol_config_t[]= {
{
.device_id = DEVICE_TANK0202,
.device_abnormal_stop = tank0202_middle,
.device_close=tank0202_thread_close
.device_close = tank0202_thread_close
},
{
.device_id = DEVICE_PAO_PTZ0401,
......@@ -42,14 +71,12 @@ void device_stop(int device_id) {
}
if(!config) {
my_zlog_error("Error: Device ID %d not found!\n", device_id);
my_zlog_error("Error: Device stop ID %d not found!\n", device_id);
return;
}
config->device_abnormal_stop(); // 速度控制初始化
my_zlog_debug("device stop successfully!,:%d",device_id);
}
void device_end_close(int device_id) {
......@@ -64,7 +91,7 @@ void device_end_close(int device_id) {
}
if(!config) {
my_zlog_error("device close and end successfully!,:%d",device_id);
my_zlog_error("Error: Device close ID %d not found!\n", device_id);
return;
}
......@@ -72,3 +99,23 @@ void device_end_close(int device_id) {
}
void device_walk_control(int device_id,unsigned char *valt) {
const device_didrive *config = NULL;
// 查找设备配置
for(int i = 0; device_didrive_control_config_t[i].device_id != -1; i++) {
if(device_didrive_control_config_t[i].device_id == device_id) {
config = &device_didrive_control_config_t[i];
break;
}
}
if(!config) {
my_zlog_error("Error: Device close ID %d not found!\n", device_id);
return;
}
config->device_didrive_control(valt); // 速度控制初始化
}
......@@ -170,7 +170,7 @@ void mode_right_back(unsigned char gval) {
}
}
int tank0202_change(unsigned char *buf) {
void tank0202_change(unsigned char *buf) {
unsigned char mode = buf[1];
unsigned char val = buf[2];
......
......@@ -7,7 +7,7 @@ void tank0202_middle();
void tank_shot_back_stop_task_end();
int tank0202_change(unsigned char *buf);
void tank0202_change(unsigned char *buf);
int tank_shot_back_stop(int pin,int val);
......
......@@ -16,6 +16,11 @@ typedef struct {
void (*device_close)(void);// 速度控制函数指针
} device_abnormal_close_t;
typedef struct {
int device_id; // 设备ID (101, 102等)
void (*device_didrive_control)(unsigned char *valt); // PWM初始化函数指针
} device_didrive;
#define DEVICE_CAR0101 101
#define DEVICE_CAR0102 102
#define DEVICE_CAR0103 103
......@@ -28,4 +33,6 @@ void device_stop(int device_id);
void device_end_close(int device_id);
void device_walk_control(int device_id,unsigned char *valt);
#endif
\ No newline at end of file
......@@ -80,16 +80,6 @@ void heartbeat_send() {
cJSON_Delete(root); // 释放 cJSON 对象
}
//mqtt设备行走驱动函数
void device_driver(){
if( g_device_type == DEVICE_CAR0101) car0101_control_change(g_valt) ;
if(g_device_type == DEVICE_CAR0102) car0102_speed_change(g_valt) ;
if(g_device_type == DEVICE_CAR0103 ) car0103_change(g_valt) ;
if(g_device_type == DEVICE_CAR0104 ) car0104_change(g_valt) ;
if(g_device_type == DEVICE_TANK0202) tank0202_change(g_valt);
if(g_device_type == DEVICE_PAO_PTZ0401) PTZ_pwm_change(g_valt);
}
//角度发送
void angle_mqtt_send() {
float angle_shot=ads1115_read_channel(2);
......@@ -144,7 +134,7 @@ void message_3(cJSON *body){
my_zlog_debug("modeTemp:%d",g_valt[1]);
my_zlog_debug("valTemp:%d",g_valt[2]);
device_driver();
device_walk_control(g_device_type,g_valt);
}
......@@ -175,7 +165,7 @@ void message_4(cJSON *body){//message 为4时候
pin_value(g_valt[1],g_valt[2]);
pwm_value(g_valt[1],g_valt[2]);
//if(AppExit_pin_pwm == 202 ) tank_shot_back_stop(g_valt[1],g_valt[2]);
if(g_device_type == DEVICE_TANK0202 ) tank_shot_back_stop(g_valt[1],g_valt[2]);
}
//当接收到2时候验证
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment