Commit 90a92785 authored by 957dd's avatar 957dd

优化代码,初优化

parent e2a4d9c1
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include "common.h" #include "common.h"
#include "device_id_change.h" #include "device_id_change.h"
#include "delay.h"
#define BUFFER_SIZE 1024 #define BUFFER_SIZE 1024
......
#include "device_identity.h" #include "device_identity.h"
#include "mqtt_init.h"
#include "common.h"
#include "delay.h"
#include "device_wifi_change.h" #include "device_wifi_change.h"
#include "http_config_mqtt.h" #include "modules_common.h"
char g_current_ssid[SSID_MAX_LEN] = {0};//用于存现在已连接WiFi char g_current_ssid[SSID_MAX_LEN] = {0};//用于存现在已连接WiFi
char wifi_Last_ssid[SSID_MAX_LEN]= {0} ; char wifi_Last_ssid[SSID_MAX_LEN]= {0} ;
......
#ifndef DEVICE_WIFI_CHANGE_H__ #ifndef DEVICE_WIFI_CHANGE_H__
#define DEVICE_WIFI_CHANGE_H__ #define DEVICE_WIFI_CHANGE_H__
#include "cjson/cJSON.h" #include "common.h"
#define SSID_MAX_LEN 128 #define SSID_MAX_LEN 128
#define PASS_MAX_LEN 128 #define PASS_MAX_LEN 128
......
#include "device_identity.h" #include "device_identity.h"
#include "mqtt_init.h"
#include "delay.h"
#include "device_wifi_change.h" #include "device_wifi_change.h"
#include "device_wifi_manager.h" #include "device_wifi_manager.h"
#include "http_config_mqtt.h" #include "modules_common.h"
#define MAX_WIFI_ENTRIES 50 #define MAX_WIFI_ENTRIES 50
#define SSID_MAX_LENGTH 64 #define SSID_MAX_LENGTH 64
......
#include "device_fileopen.h" #include "device_fileopen.h"
#include "device_id_change.h" #include "device_id_change.h"
#include "common.h" #include "common.h"
#include "delay.h"
#define FILENAME "/home/orangepi/car/master/Deviceld.txt" #define FILENAME "/home/orangepi/car/master/Deviceld.txt"
......
#include "common.h"
#include "devcontrol_common.h"
#include "device_identity.h" #include "device_identity.h"
#include "device_fileopen.h" #include "device_fileopen.h"
#include "device_init.h" #include "common.h"
#include "delay.h" #include "drivers_common.h"
char g_app2dev_topic[23]; char g_app2dev_topic[23];
char g_dev2app_topic[23]; char g_dev2app_topic[23];
char g_pure_topic[15]; char g_pure_topic[15];
char g_ser2dev_topic[23]; char g_ser2dev_topic[23];
bool g_device_name_exists=0;//查找设备号状态机,如果id是不属于任何类型 static bool g_device_name_exists_s=0;//查找设备号状态机,如果id是不属于任何类型
/*提早声明*/ /*提早声明*/
int device_mqtt_topic_init(); int device_mqtt_topic_init();
...@@ -139,7 +137,7 @@ int device_judg(CodeEnum_t code,char *sub_str) { ...@@ -139,7 +137,7 @@ int device_judg(CodeEnum_t code,char *sub_str) {
my_zlog_info("使用型号%s",sub_str); my_zlog_info("使用型号%s",sub_str);
}else { }else {
my_zlog_error("没有找到设备号,尝试启用备用mqtt,topic进行改名"); my_zlog_error("没有找到设备号,尝试启用备用mqtt,topic进行改名");
g_device_name_exists=1; g_device_name_exists_s=1;
} }
return 0; return 0;
...@@ -172,7 +170,7 @@ int device_mqtt_topic_init() { ...@@ -172,7 +170,7 @@ int device_mqtt_topic_init() {
free(sub_str); free(sub_str);
delay_s(10); delay_s(10);
if(g_device_name_exists == 0) { if(g_device_name_exists_s == 0) {
sprintf(g_app2dev_topic,"app2dev/%s",readbuf); sprintf(g_app2dev_topic,"app2dev/%s",readbuf);
sprintf(g_dev2app_topic,"dev2app/%s",readbuf); sprintf(g_dev2app_topic,"dev2app/%s",readbuf);
sprintf(g_pure_topic,"%s",readbuf); sprintf(g_pure_topic,"%s",readbuf);
......
...@@ -2,15 +2,10 @@ ...@@ -2,15 +2,10 @@
#define MAIN_H__ #define MAIN_H__
#include "common.h" #include "common.h"
#include "device_fileopen.h" #include "app_device_common.h"
#include "device_identity.h" #include "drivers_common.h"
#include "modules_common.h"
#include "pthread_open.h" #include "pthread_open.h"
#include "http_request.h"
#include "softiic.h"
#include "INA226.h"
#include "devcontrol_common.h"
#include "gpio_init.h"
#include "http_config_mqtt.h"
/*设备id读取初始化*/ /*设备id读取初始化*/
int device_id_file_init(); int device_id_file_init();
......
#include "common.h" #include "common.h"
#include "delay.h" #include "app_device_common.h"
#include "drivers_common.h"
#include "modules_common.h"
#include "pthread_open.h" #include "pthread_open.h"
#include "mqtt_init.h"
#include "mqtt_infor_handle.h"
#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"
#include "gpio_init.h"
#define PTHREAD_MAX 6 #define PTHREAD_MAX 6
......
#define PROJECT_VERSION_MAJOR 1 #define PROJECT_VERSION_MAJOR 1
#define PROJECT_VERSION_MINOR 2 #define PROJECT_VERSION_MINOR 2
#define PROJECT_VERSION_PATCH 14 #define PROJECT_VERSION_PATCH 15
#define GIT_HASH "" #define GIT_HASH ""
#define BUILD_TIMESTAMP "" #define BUILD_TIMESTAMP ""
#define BUILD_USER "" #define BUILD_USER ""
No preview for this file type
#include "common.h" #include "common.h"
#include "car0101_control.h" #include "car0101_control.h"
#include "gpio_init.h" #include "modules_common.h"
#include "gpio_common.h"
/*将角度转化为对应的舵机pwm值*/ /*将角度转化为对应的舵机pwm值*/
void car_calculate_L_R(int angle) { void car_calculate_L_R(int angle) {
......
#include "car0102_control.h" #include "car0102_control.h"
#include "common.h" #include "common.h"
#include "gpio_init.h" #include "modules_common.h"
#include "device_init.h" #include "gpio_common.h"
#include "gpio_control.h"
//将角度转化为对应的舵机pwm值 //将角度转化为对应的舵机pwm值
void car0102_calculate_L_R(int angle) { void car0102_calculate_L_R(int angle) {
......
#include "car0103_control.h" #include "car0103_control.h"
#include "gpio_init.h" #include "modules_common.h"
#include "common.h" #include "common.h"
#include "gpio_common.h"
void car0103_middle() { void car0103_middle() {
pwmWrite(PWM_PIN_SPEED,75); pwmWrite(PWM_PIN_SPEED,75);
......
#include "car0104_control.h" #include "car0104_control.h"
#include "gpio_init.h" #include "modules_common.h"
#include "common.h" #include "common.h"
#include "gpio_common.h"
void car0104_stop() { void car0104_stop() {
pwmWrite(PWM_PIN_SPEED,75); pwmWrite(PWM_PIN_SPEED,75);
......
#include "devcontrol_common.h" #include "devcontrol_common.h"
#include "gpio_init.h" #include "modules_common.h"
#include "gpio_common.h"
const device_didrive device_didrive_control_config_t[]={ const device_didrive device_didrive_control_config_t[]={
{ {
......
#include "common.h" #include "common.h"
#include "gpio_init.h" #include "modules_common.h"
#include "ptz0401_control.h" #include "ptz0401_control.h"
#include "gpio_common.h"
#define PWM_PIN_up 21 #define PWM_PIN_up 21
#define PWM_PIN_down 2 #define PWM_PIN_down 2
......
#include "common.h" #include "common.h"
#include "gpio_init.h" #include "modules_common.h"
#include "ship0301_control.h" #include "ship0301_control.h"
#include "gpio_common.h"
void ship0301_stop() { void ship0301_stop() {
pwmWrite(PWM_PIN_SPEED,75); pwmWrite(PWM_PIN_SPEED,75);
......
#include "common.h" #include "common.h"
#include "gpio_init.h" #include "modules_common.h"
#include "tank0202_control.h" #include "tank0202_control.h"
#include "gpio_common.h"
int g_modecount_tank0202=0; int g_modecount_tank0202=0;
......
#include "common.h" #include "common.h"
#include "gpio_init.h" #include "modules_common.h"
#include "pthrpoll.h"
#include "tank0203_control.h" #include "tank0203_control.h"
#include "gpio_common.h"
#define PWM_MIN 55 // 最小PWM值 #define PWM_MIN 55 // 最小PWM值
#define PWM_MAX 95 // 最大PWM值 #define PWM_MAX 95 // 最大PWM值
......
#ifndef TANK0203_CONTROL_H__ #ifndef TANK0203_CONTROL_H__
#define TANK0203_CONTROL_H__ #define TANK0203_CONTROL_H__
void tank0203_middle(); void tank0203_middle();
void tank0203_change(unsigned char *buf); void tank0203_change(unsigned char *buf);
......
#include "common.h" #include "common.h"
#include "gpio_init.h" #include "modules_common.h"
#include "pthrpoll.h"
#include "tank0204_control.h" #include "tank0204_control.h"
#include "gpio_common.h"
void tank0204_stop() { void tank0204_stop() {
pwmWrite(PWM_PIN_SPEED,75); pwmWrite(PWM_PIN_SPEED,75);
......
#ifndef TANK0204_CONTROL_H__ #ifndef TANK0204_CONTROL_H__
#define TANK0204_CONTROL_H__ #define TANK0204_CONTROL_H__
void tank0204_stop(); void tank0204_stop();
void tank0204_change(unsigned char *buf); void tank0204_change(unsigned char *buf);
......
#include "common.h" #include "common.h"
#include "gpio_init.h" #include "modules_common.h"
#include "pthrpoll.h"
#include "tank0206_control.h" #include "tank0206_control.h"
#include "gpio_common.h"
void tank0206_middle() { void tank0206_middle() {
pwmWrite(PWM_PIN_SPEED,75); pwmWrite(PWM_PIN_SPEED,75);
......
#ifndef TANK0206_CONTROL_H__ #ifndef TANK0206_CONTROL_H__
#define TANK0206_CONTROL_H__ #define TANK0206_CONTROL_H__
void tank0206_middle(); void tank0206_middle();
void tank0206_change(unsigned char *buf); void tank0206_change(unsigned char *buf);
......
#include "tank_common.h" #include "tank_common.h"
#include "devcontrol_common.h" #include "devcontrol_common.h"
#include "gpio_init.h" #include "modules_common.h"
#include "pthrpoll.h" #include "gpio_common.h"
#include "tank_angle.h"
#include "gpio_control.h"
int tank_shot_back_stop(unsigned char pin,unsigned char val); int tank_shot_back_stop(unsigned char pin,unsigned char val);
......
#ifndef GPIO_COMMON_H
#define GPIO_COMMON_H
#include "device_init.h"
#include "gpio_init.h"
#include "gpio_control.h"
#include "softiic.h"
#endif
\ No newline at end of file
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "gpio_init.h" #include "gpio_init.h"
#include "devcontrol_common.h" #include "devcontrol_common.h"
#include "http_request.h" #include "http_request.h"
#include "delay.h"
#define GPIO_ID_THREAD_COUNT 3 #define GPIO_ID_THREAD_COUNT 3
......
#include <math.h>
#include "common.h" #include "common.h"
#include "softiic.h" #include "softiic.h"
......
#include <sys/socket.h>
#include <netinet/in.h>
#include <ifaddrs.h>
#include "common.h" #include "common.h"
#include "ip_reader.h" #include "ip_reader.h"
#include "mylog.h"
struct ifaddrs *ifap, *ifa; struct ifaddrs *ifap, *ifa;
struct sockaddr_in *sa; struct sockaddr_in *sa;
......
#ifndef SERSORS_COMMON_H
#define SERSORS_COMMON_H
#include "ads1115.h"
#include "audioplay.h"
#include "INA226.h"
#include "infrared_gun.h"
#include "tank_angle.h"
#include "temperature.h"
#include "warn.h"
#endif
\ No newline at end of file
#include "common.h" #include "common.h"
#include "warn.h" #include "warn.h"
#include "http_request.h" #include "http_request.h"
#include "mylog.h"
#include "gpio_control.h" #include "gpio_control.h"
#include "device_init.h" #include "device_init.h"
#include "devcontrol_common.h" #include "devcontrol_common.h"
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
- tank0204 M1A2最大为200,更据电池电压具体调速。原电池为7.6v,大概为140左右 - tank0204 M1A2最大为200,更据电池电压具体调速。原电池为7.6v,大概为140左右
- tank0205 M1A2最大为200,更据电池电压具体调速。原电池为7.6v,大概为140左右 - tank0205 M1A2最大为200,更据电池电压具体调速。原电池为7.6v,大概为140左右
- tank0202~0205为眯眼潮玩坦克。 - tank0202~0205为眯眼潮玩坦克。
- 0202 豹2 ,0203 M1A2 ,0204 99A主站坦克
- tank0206 为可以发射水枪的水坦克.原电池为3.3v,大概为80左右 - tank0206 为可以发射水枪的水坦克.原电池为3.3v,大概为80左右
- car0101 最大为150,尽量不能这么大 - car0101 最大为150,尽量不能这么大
- car0102 为小车 最大速度为200 - car0102 为小车 最大速度为200
......
#ifndef APP_DEVICE_COMMON_H
#define APP_DEVICE_COMMON_H
#include "device_id_change.h"
#include "device_wifi_change.h"
#include "device_wifi_manager.h"
#include "device_fileopen.h"
#include "device_identity.h"
#endif
\ No newline at end of file
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <stddef.h>
#include <errno.h>
// ========== 硬件相关 ========== // ========== 硬件相关 ==========
#include <wiringPi.h> // GPIO控制 #include <wiringPi.h> // GPIO控制
...@@ -18,32 +20,31 @@ ...@@ -18,32 +20,31 @@
#include <unistd.h> // POSIX接口 #include <unistd.h> // POSIX接口
#include <sys/stat.h> // 文件状态 #include <sys/stat.h> // 文件状态
#include <dirent.h> // 目录操作 #include <dirent.h> // 目录操作
#include <sys/types.h>
#include <sys/select.h>
#include <pty.h> // for openpty
// ========== 网络通信 ========== // ========== 网络通信 ==========
#include <curl/curl.h> // HTTP客户端 #include <curl/curl.h> // HTTP客户端
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <ifaddrs.h>
// ========== 高级功能 ========== // ========== 高级功能 ==========
#include <termios.h> // 串口通信 #include <termios.h> // 串口通信
#include <pthread.h> // 多线程 #include <pthread.h> // 多线程
#include <math.h> // 数学函数 #include <math.h> // 数学函数
#include <time.h> // 时间处理 #include <time.h> // 时间处理
#include <stddef.h>
#include <uuid/uuid.h> #include <uuid/uuid.h>
#include <signal.h>
// ========== 第三方库 ==========
#include "mosquitto.h" #include "mosquitto.h"
#include "cjson/cJSON.h" #include "cjson/cJSON.h"
// ========== 自己封装的库 ==========
#include "delay.h" #include "delay.h"
#include "mylog.h" #include "mylog.h"
// ========== 香橙派优化宏 ==========
// #define ORANGE_GPIO_SET(pin, val) { \
// pinMode(pin, OUTPUT); \
// digitalWrite(pin, val); \
// }
#endif // COMMON_H #endif // COMMON_H
\ No newline at end of file
#ifndef DRIVERS_COMMON_H
#define DRIVERS_COMMON_H
#include "devcontrol_common.h"
#include "gpio_common.h"
#include "ip_reader.h"
#include "sensors_common.h"
#endif
\ No newline at end of file
#ifndef MODULES_COMMON_H
#define MODULES_COMMON_H
#include "browser_open.h"
#include "http_common.h"
#include "delay.h"
#include "mylog.h"
#include "mqtt_common.h"
#include "pthrpoll.h"
#endif
\ No newline at end of file
#include "common.h"
#include "browser_open.h" #include "browser_open.h"
#include "device_fileopen.h" #include "device_fileopen.h"
#include "device_identity.h" #include "device_identity.h"
......
#ifndef BROWSER_OPEN_H__ #ifndef BROWSER_OPEN_H__
#define BROWSER_OPEN_H__ #define BROWSER_OPEN_H__
#include "common.h"
/*打开摄像头函数,当MODE为1时候为国内网址,2时为泰国网址,3为中东网址*/ /*打开摄像头函数,当MODE为1时候为国内网址,2时为泰国网址,3为中东网址*/
#define BROWSER_MODE 1 #define BROWSER_MODE 1
......
#ifndef HTTP_COMMON_H
#define HTTP_COMMON_H
#include "http_config_mqtt.h"
#include "http_consolepush.h"
#include "http_request.h"
#endif
\ No newline at end of file
#include "device_identity.h" #include "device_identity.h"
#include "http_config_mqtt.h" #include "http_config_mqtt.h"
#include<curl/curl.h> #include "common.h"
#include "cjson/cJSON.h"
#include "http_request.h" #include "http_request.h"
DEVICE_MQTTCONFIG g_mqtt_cam_config; DEVICE_MQTTCONFIG g_mqtt_cam_config;
......
#include "http_consolepush.h" #include "http_consolepush.h"
#include "common.h" #include "common.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <sys/select.h>
#include <pty.h> // for openpty
#include <termios.h>
#include <sys/types.h>
#include <signal.h>
#include "pthrpoll.h" #include "pthrpoll.h"
void contril_pthread_open(); void contril_pthread_open();
......
#include<curl/curl.h>
#include "cjson/cJSON.h"
#include "http_request.h" #include "http_request.h"
#include "device_identity.h" #include "device_identity.h"
#include "common.h" #include "common.h"
......
#ifndef _MQTT_COMMON_H
#define _MQTT_COMMON_H
#include "mqtt_infor_handle.h"
#include "mqtt_verify.h"
#include "mqtt_init.h"
#endif
\ No newline at end of file
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include "mqtt_init.h" #include "mqtt_init.h"
#include "device_identity.h" #include "device_identity.h"
#include "mqtt_infor_handle.h" #include "mqtt_infor_handle.h"
#include "mylog.h"
#include "http_config_mqtt.h" #include "http_config_mqtt.h"
mqttclient g_clients_t[MAX_SERVERS]; mqttclient g_clients_t[MAX_SERVERS];
...@@ -155,7 +154,7 @@ int mqtt_cycle() {//非阻塞型 ...@@ -155,7 +154,7 @@ int mqtt_cycle() {//非阻塞型
mosquitto_reconnect(g_clients_t[i].mosq); mosquitto_reconnect(g_clients_t[i].mosq);
} }
} }
delay_us(50);
} }
return 0; return 0;
......
#include "pthrpoll.h" #include "pthrpoll.h"
#include <stdlib.h> #include "common.h"
#include <pthread.h>
#include <unistd.h>
#include <errno.h>
// 初始化任务队列 // 初始化任务队列
static int task_queue_init(TaskQueue *queue) { static int task_queue_init(TaskQueue *queue) {
......
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