Commit 4d92d557 authored by 学习的菜鸟's avatar 学习的菜鸟

代码重构初步完成,差测试,cmake和头文件管理还需后续优化

parent 073c8e3f
......@@ -37,7 +37,7 @@ int main(){
int thread_rc=thread_start_init( thread_exit_time,thread_mqtt_beat,thread_open_browser,thread_mqtt_reconnect,thread_time_calculation,thread_play_mp3);
thread_end_close();
device_close();
device_end_close(g_device_type);
my_log_close();//关闭日志
my_zlog_info("程序关闭成功");
return 0;
......
......@@ -9,6 +9,7 @@
#include "softiic.h"
#include "INA226.h"
#include "devcontrol_common.h"
#include "gpio_init.h"
/*设备id读取初始化*/
int device_id_file_init();
......@@ -39,7 +40,7 @@ int request_date();
void thread_end_close() ;
/*相关设备线程等关闭函数*/
void device_close();
void device_end_close(int device_id);
/*关闭log日志记录*/
void my_log_close();
......
......@@ -6,6 +6,7 @@
#include "browser_open.h"
#include "mqtt_verify.h"
#include "device_wifi_change.h"
#include "devcontrol_common.h"
#include "browser_open.h"
#include "device_init.h"
#include "audioplay.h"
......@@ -47,7 +48,7 @@ void *thread_exit_time(void *arg) {
delay_ms(100);
g_devcontrol_exit_count++;
if(g_devcontrol_exit_count>=5) {
//device_warn_exit();
device_stop(g_device_type);
g_devcontrol_exit_count=6;
}
}
......
......@@ -606,6 +606,30 @@ drivers/devicecontrol/car0104_control.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/devicecontrol/car0104_control.c.s
.PHONY : drivers/devicecontrol/car0104_control.c.s
drivers/devicecontrol/devcontrol_common.o: drivers/devicecontrol/devcontrol_common.c.o
.PHONY : drivers/devicecontrol/devcontrol_common.o
# target to build an object file
drivers/devicecontrol/devcontrol_common.c.o:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/devicecontrol/devcontrol_common.c.o
.PHONY : drivers/devicecontrol/devcontrol_common.c.o
drivers/devicecontrol/devcontrol_common.i: drivers/devicecontrol/devcontrol_common.c.i
.PHONY : drivers/devicecontrol/devcontrol_common.i
# target to preprocess a source file
drivers/devicecontrol/devcontrol_common.c.i:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/devicecontrol/devcontrol_common.c.i
.PHONY : drivers/devicecontrol/devcontrol_common.c.i
drivers/devicecontrol/devcontrol_common.s: drivers/devicecontrol/devcontrol_common.c.s
.PHONY : drivers/devicecontrol/devcontrol_common.s
# target to generate assembly for a file
drivers/devicecontrol/devcontrol_common.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/devicecontrol/devcontrol_common.c.s
.PHONY : drivers/devicecontrol/devcontrol_common.c.s
drivers/devicecontrol/ptz0401_control.o: drivers/devicecontrol/ptz0401_control.c.o
.PHONY : drivers/devicecontrol/ptz0401_control.o
......@@ -1696,6 +1720,9 @@ help:
@echo "... drivers/devicecontrol/car0104_control.o"
@echo "... drivers/devicecontrol/car0104_control.i"
@echo "... drivers/devicecontrol/car0104_control.s"
@echo "... drivers/devicecontrol/devcontrol_common.o"
@echo "... drivers/devicecontrol/devcontrol_common.i"
@echo "... drivers/devicecontrol/devcontrol_common.s"
@echo "... drivers/devicecontrol/ptz0401_control.o"
@echo "... drivers/devicecontrol/ptz0401_control.i"
@echo "... drivers/devicecontrol/ptz0401_control.s"
......
No preview for this file type
CMAKE_PROGRESS_1 =
CMAKE_PROGRESS_2 = 80
CMAKE_PROGRESS_1 = 80
CMAKE_PROGRESS_2 =
CMAKE_PROGRESS_3 =
CMAKE_PROGRESS_4 = 81
CMAKE_PROGRESS_5 =
......@@ -9,6 +9,6 @@ CMAKE_PROGRESS_8 =
CMAKE_PROGRESS_9 =
CMAKE_PROGRESS_10 = 83
CMAKE_PROGRESS_11 =
CMAKE_PROGRESS_12 =
CMAKE_PROGRESS_13 = 84
CMAKE_PROGRESS_12 = 84
CMAKE_PROGRESS_13 =
......@@ -4,5 +4,5 @@ CMAKE_PROGRESS_3 =
CMAKE_PROGRESS_4 =
CMAKE_PROGRESS_5 = 91
CMAKE_PROGRESS_6 =
CMAKE_PROGRESS_7 =
CMAKE_PROGRESS_7 = 92
CMAKE_PROGRESS_1 =
CMAKE_PROGRESS_2 = 95
CMAKE_PROGRESS_3 =
CMAKE_PROGRESS_4 =
CMAKE_PROGRESS_5 = 96
CMAKE_PROGRESS_4 = 96
CMAKE_PROGRESS_5 =
CMAKE_PROGRESS_6 =
......@@ -25,8 +25,8 @@ CMAKE_PROGRESS_24 =
CMAKE_PROGRESS_25 =
CMAKE_PROGRESS_26 = 26
CMAKE_PROGRESS_27 =
CMAKE_PROGRESS_28 = 27
CMAKE_PROGRESS_29 =
CMAKE_PROGRESS_28 =
CMAKE_PROGRESS_29 = 27
CMAKE_PROGRESS_30 =
CMAKE_PROGRESS_31 = 28
CMAKE_PROGRESS_32 =
......@@ -36,8 +36,8 @@ CMAKE_PROGRESS_35 =
CMAKE_PROGRESS_36 =
CMAKE_PROGRESS_37 = 30
CMAKE_PROGRESS_38 =
CMAKE_PROGRESS_39 = 31
CMAKE_PROGRESS_40 =
CMAKE_PROGRESS_39 =
CMAKE_PROGRESS_40 = 31
CMAKE_PROGRESS_41 =
CMAKE_PROGRESS_42 = 32
CMAKE_PROGRESS_43 =
......
......@@ -7,7 +7,7 @@ CMAKE_PROGRESS_6 =
CMAKE_PROGRESS_7 =
CMAKE_PROGRESS_8 = 87
CMAKE_PROGRESS_9 =
CMAKE_PROGRESS_10 =
CMAKE_PROGRESS_11 = 88
CMAKE_PROGRESS_10 = 88
CMAKE_PROGRESS_11 =
CMAKE_PROGRESS_12 =
CMAKE_PROGRESS_1 =
CMAKE_PROGRESS_2 =
CMAKE_PROGRESS_3 = 53
CMAKE_PROGRESS_2 = 53
CMAKE_PROGRESS_3 =
CMAKE_PROGRESS_4 =
CMAKE_PROGRESS_5 = 54
CMAKE_PROGRESS_6 =
CMAKE_PROGRESS_7 =
CMAKE_PROGRESS_8 = 55
CMAKE_PROGRESS_9 =
CMAKE_PROGRESS_10 =
CMAKE_PROGRESS_11 = 56
CMAKE_PROGRESS_10 = 56
CMAKE_PROGRESS_11 =
CMAKE_PROGRESS_12 =
CMAKE_PROGRESS_13 =
CMAKE_PROGRESS_14 = 57
CMAKE_PROGRESS_13 = 57
CMAKE_PROGRESS_14 =
CMAKE_PROGRESS_15 =
CMAKE_PROGRESS_16 = 58
CMAKE_PROGRESS_17 =
CMAKE_PROGRESS_18 =
CMAKE_PROGRESS_19 = 59
CMAKE_PROGRESS_20 =
CMAKE_PROGRESS_21 =
CMAKE_PROGRESS_22 = 60
CMAKE_PROGRESS_21 = 60
CMAKE_PROGRESS_22 =
CMAKE_PROGRESS_23 =
CMAKE_PROGRESS_24 =
CMAKE_PROGRESS_25 = 61
CMAKE_PROGRESS_24 = 61
CMAKE_PROGRESS_25 =
CMAKE_PROGRESS_26 =
CMAKE_PROGRESS_27 = 62
CMAKE_PROGRESS_28 =
CMAKE_PROGRESS_29 =
CMAKE_PROGRESS_30 = 63
CMAKE_PROGRESS_31 =
CMAKE_PROGRESS_32 =
CMAKE_PROGRESS_33 = 64
CMAKE_PROGRESS_32 = 64
CMAKE_PROGRESS_33 =
CMAKE_PROGRESS_34 =
CMAKE_PROGRESS_35 =
CMAKE_PROGRESS_36 = 65
CMAKE_PROGRESS_35 = 65
CMAKE_PROGRESS_36 =
CMAKE_PROGRESS_37 =
CMAKE_PROGRESS_38 = 66
CMAKE_PROGRESS_39 =
CMAKE_PROGRESS_40 =
CMAKE_PROGRESS_41 = 67
CMAKE_PROGRESS_42 =
CMAKE_PROGRESS_43 =
CMAKE_PROGRESS_44 = 68
CMAKE_PROGRESS_43 = 68
CMAKE_PROGRESS_44 =
CMAKE_PROGRESS_45 =
CMAKE_PROGRESS_46 =
CMAKE_PROGRESS_47 = 69
CMAKE_PROGRESS_46 = 69
CMAKE_PROGRESS_47 =
CMAKE_PROGRESS_48 =
CMAKE_PROGRESS_49 = 70
CMAKE_PROGRESS_50 =
CMAKE_PROGRESS_51 =
CMAKE_PROGRESS_52 = 71
CMAKE_PROGRESS_53 =
CMAKE_PROGRESS_54 =
CMAKE_PROGRESS_55 = 72
CMAKE_PROGRESS_54 = 72
CMAKE_PROGRESS_55 =
CMAKE_PROGRESS_56 =
CMAKE_PROGRESS_57 =
CMAKE_PROGRESS_58 = 73
CMAKE_PROGRESS_57 = 73
CMAKE_PROGRESS_58 =
CMAKE_PROGRESS_59 =
CMAKE_PROGRESS_60 = 74
CMAKE_PROGRESS_61 =
CMAKE_PROGRESS_62 =
CMAKE_PROGRESS_63 = 75
CMAKE_PROGRESS_64 =
CMAKE_PROGRESS_65 =
CMAKE_PROGRESS_66 = 76
CMAKE_PROGRESS_65 = 76
CMAKE_PROGRESS_66 =
CMAKE_PROGRESS_67 =
CMAKE_PROGRESS_68 = 77
CMAKE_PROGRESS_69 =
......
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
#ifndef CAR0103_CONTROL_H__
#define CAR0104_CONTROL_H__
#define CAR0103_CONTROL_H__
void car0103_middle();
int car0103_change(unsigned char *buf);
#endif
\ No newline at end of file
#include "common.h"
#include "gpio_init.h"
#include "car0104_control.h"
#include "gpio_init.h"
#include "common.h"
void car0104_middle() {
void car0104_stop() {
pwmWrite(PWM_PIN_SPEED,75);
pwmWrite(PWM_PIN_CHANGE,75);
}
......
#ifndef CAR0104_CONTROL_H__
#define CAR0104_CONTROL_H__
void car0104_middle();
void car0104_stop();
int car0104_change(unsigned char *buf);
......
#include "devcontrol_common.h"
const device_abnormal_close_t devcontrol_config_t[]= {
{
.device_id = DEVICE_CAR0101,
.device_abnormal_stop = car0101_middle_pwm
},
{
.device_id = DEVICE_CAR0102,
.device_abnormal_stop = car0102_speed_stop
},
{
.device_id = DEVICE_CAR0103,
.device_abnormal_stop = car0103_middle
},
{
.device_id = DEVICE_CAR0104,
.device_abnormal_stop = car0104_stop
},
{
.device_id = DEVICE_TANK0202,
.device_abnormal_stop = tank0202_middle,
.device_close=tank0202_thread_close
},
{
.device_id = DEVICE_PAO_PTZ0401,
.device_abnormal_stop = PTZ_pwm_init
},
// 结束标记
{ .device_id = -1 }
};
void device_stop(int device_id) {
const device_abnormal_close_t *config = NULL;
// 查找设备配置
for(int i = 0; devcontrol_config_t[i].device_id != -1; i++) {
if(devcontrol_config_t[i].device_id == device_id) {
config = &devcontrol_config_t[i];
break;
}
}
if(!config) {
my_zlog_error("Error: Device 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) {
const device_abnormal_close_t *config = NULL;
// 查找设备配置
for(int i = 0; devcontrol_config_t[i].device_id != -1; i++) {
if(devcontrol_config_t[i].device_id == device_id) {
config = &devcontrol_config_t[i];
break;
}
}
if(!config) {
my_zlog_error("device close and end successfully!,:%d",device_id);
return;
}
config->device_close(); // 速度控制初始化
}
......@@ -8,7 +8,6 @@ int g_modecount_tank0202=0;
void tank0202_middle() {
pwmWrite(PWM_PIN_SPEED,75);
pwmWrite(PWM_PIN_CHANGE,75);
return 0;
}
void mode_lift_flont(unsigned char gval) {
......
File mode changed from 100644 to 100755
......@@ -10,7 +10,7 @@ int g_device_type =0;
const deviceconfig_t device_configs[] = {
// car0101配置
{
.device_id = 101,
.device_id = DEVICE_CAR0101,
.device_name = "car0101",
.gpio_pins = {5, 6, 7, 10, 16, 20, 22, 23, 24, 25, 26, -1},
.gpio_pwms = {27,-1},
......@@ -20,7 +20,7 @@ const deviceconfig_t device_configs[] = {
},
// car0102配置
{
.device_id = 102,
.device_id = DEVICE_CAR0102,
.device_name = "car0102",
.gpio_pins = {5, 6, 7, 10, 16, 20, 22, 23, 24, 25, 26, 27, -1},
.gpio_pwms = {-1},
......@@ -30,27 +30,27 @@ const deviceconfig_t device_configs[] = {
},
// car0103配置(根据您的需求补充)
{
.device_id = 103,
.device_id = DEVICE_CAR0103,
.device_name = "car0103",
.gpio_pins = {5, 6, 7, 10, 16, 20, 22, 23, 24, 25, 26, 27,-1},/* 补充GPIO引脚 */
.gpio_pwms = {-1},
.device_pwm_init = physics_pwm_init,
.device_control_stop = car0103_middle,/* 补充速度控制函数 */
.device_control_stop = car0103_middle,/* 补充速度控制函数 */
.emergency_code = 103
},
// car0104配置(根据您的需求补充)
{
.device_id = 104,
.device_id = DEVICE_CAR0104,
.device_name = "car0104",
.gpio_pins = {5, 6, 7, 10, 16, 20, 22, 23, 24, 25, 26, 27,-1},/* 补充GPIO引脚 */
.gpio_pwms = {-1},
.device_pwm_init = physics_pwm_init,
.device_control_stop = car0104_middle,/* 补充速度控制函数 */
.device_control_stop = car0104_stop,/* 补充速度控制函数 */
.emergency_code = 104
},
// tank0202配置(根据您的需求补充)
{
.device_id = 202,
.device_id = DEVICE_TANK0202,
.device_name = "tank0202",
.gpio_pins = {6, 16, 20, 22, 23,-1},/* 补充GPIO引脚 */
.gpio_pwms = {5 , 7 ,24,26, 27,-1},
......@@ -60,7 +60,7 @@ const deviceconfig_t device_configs[] = {
},
{
.device_id = 401,
.device_id = DEVICE_PAO_PTZ0401,
.device_name = "ptz0401",
.gpio_pins = {5, 6, 7, 10, 16, 20, 22, 23, 24, 25, 26,-1},/* 补充GPIO引脚 */
.gpio_pwms = { 27,-1},
......@@ -91,7 +91,7 @@ void device_init(int device_id) {
}
if(!config) {
printf("Error: Device ID %d not found!\n", device_id);
my_zlog_error("Error: Device ID %d not found!", device_id);
return;
}
......@@ -103,5 +103,5 @@ void device_init(int device_id) {
g_device_type =config->emergency_code;
printf("%s initialized successfully!\n", config->device_name);
my_zlog_debug("%s initialized successfully!", config->device_name);
}
\ No newline at end of file
......@@ -28,6 +28,7 @@
#include <pthread.h> // 多线程
#include <math.h> // 数学函数
#include <time.h> // 时间处理
#include <stddef.h>
#include "mosquitto.h"
#include "cjson/cJSON.h"
......
......@@ -8,7 +8,13 @@
#include "car0104_control.h"
#include "ptz0401_control.h"
#include "tank02002_control.h"
#include "common.h"
typedef struct {
int device_id; // 设备ID (101, 102等)
void (*device_abnormal_stop)(void); // PWM初始化函数指针
void (*device_close)(void);// 速度控制函数指针
} device_abnormal_close_t;
#define DEVICE_CAR0101 101
#define DEVICE_CAR0102 102
......@@ -18,10 +24,8 @@
#define DEVICE_TANK0202 202
#define DEVICE_PAO_PTZ0401 401
void device_stop(int device_id);
/*关闭相关的设备需要关闭的,比如线程池等*/
void device_close(){
if(g_device_type == DEVICE_TANK0202) tank0202_thread_close();
}
void device_end_close(int device_id);
#endif
\ No newline at end of file
......@@ -2,7 +2,7 @@
#define BROWSER_OPEN_H__
/*打开摄像头函数,当MODE为1时候为国内网址,2时为国外网址*/
#define BROWSER_MODE 2
#define BROWSER_MODE 1
int opencamsh();
......
......@@ -79,20 +79,15 @@ void heartbeat_send() {
cJSON_Delete(root); // 释放 cJSON 对象
}
#define DEVICE_CAR0102 102
#define DEVICE_CAR0103 103
#define DEVICE_CAR0104 104
#define DEVICE_TANK0201 201
#define DEVICE_TANK0202 101
#define DEVICE_PAO_PTZ0401 401
//mqtt设备行走驱动函数
void device_driver(){
if( device_type == DEVICE_CAR0101) car0101_control_change(g_valt) ;
if(device_type == DEVICE_CAR0102) car0102_speed_change(g_valt) ;
if(device_type == DEVICE_CAR0103 ) car0103_change(g_valt) ;
if(device_type == DEVICE_CAR0104 ) car0104_change(g_valt) ;
if(device_type == DEVICE_TANK0202) tank0202_change(g_valt);
if(device_type == DEVICE_PAO_PTZ0401) PTZ_pwm_change(g_valt);
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);
}
//角度发送
......@@ -121,7 +116,7 @@ void mqtt_wirte(){
heartbeat_send();
g_heartbeat_count=0;
}
if( device_type == 202) angle_mqtt_send();
if( g_device_type == 202) angle_mqtt_send();
}
......
......@@ -3,8 +3,6 @@
#include "cjson/cJSON.h"
/*1为打开验证0为关闭验证*/
#define VERIFIED_MODE 1
extern int g_heartbeat_count;
......
......@@ -6,7 +6,7 @@
//extern ThreadPool *pool;
#define MQTT_IPMODE 2 // 或通过编译选项 -DMODE=1 指定
#define MQTT_IPMODE 1 // 或通过编译选项 -DMODE=1 指定
#if MQTT_IPMODE == 1
#define BROKER_ADDRESS "119.45.167.177"
......
......@@ -3,6 +3,9 @@
#include "cjson/cJSON.h"
/*1为打开验证0为关闭验证*/
#define VERIFIED_MODE 1
#define AES_BLOCK_SIZE 16
extern int g_verify_count;//验证计时
......
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