Commit e7d0d7ff authored by 957dd's avatar 957dd

Merge branch 'feature/add_control_push' into 'master'

Feature/add control push See merge request !61
parents 92086282 4fe2e2b3
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
#define MAX_WIFI_ENTRIES 50 #define MAX_WIFI_ENTRIES 50
#define SSID_MAX_LENGTH 64 #define SSID_MAX_LENGTH 64
void device_wifi_public_sendmqtt(int wifi_status) { //成功发送3010 /*成功发送3010,保存wifi和删除WiFi都会发送,wifi_status未0为成功*/
void device_wifi_public_sendmqtt(int wifi_status) {
get_current_wifi(); get_current_wifi();
cJSON *root = cJSON_CreateObject(); cJSON *root = cJSON_CreateObject();
...@@ -28,6 +29,8 @@ void device_wifi_public_sendmqtt(int wifi_status) { //成功发送3010 ...@@ -28,6 +29,8 @@ void device_wifi_public_sendmqtt(int wifi_status) { //成功发送3010
cJSON_Delete(root); // 释放 cJSON 对象 cJSON_Delete(root); // 释放 cJSON 对象
} }
/*接收到删除的mqtt消息*/
void device_wifi_rec_delete(cJSON *body){ void device_wifi_rec_delete(cJSON *body){
cJSON *wifi_ssid = cJSON_GetObjectItem(body, "wifi_ssid"); cJSON *wifi_ssid = cJSON_GetObjectItem(body, "wifi_ssid");
cJSON *wifi_password = cJSON_GetObjectItem(body, "wifi_password"); cJSON *wifi_password = cJSON_GetObjectItem(body, "wifi_password");
...@@ -44,6 +47,7 @@ void device_wifi_rec_delete(cJSON *body){ ...@@ -44,6 +47,7 @@ void device_wifi_rec_delete(cJSON *body){
} }
} }
/*进行保存wifi*/
int orange_pi_save_wifi(const char* ssid, const char* password) { int orange_pi_save_wifi(const char* ssid, const char* password) {
// 参数检查 // 参数检查
if (!ssid || !password || strlen(ssid) == 0 || strlen(password) == 0) { if (!ssid || !password || strlen(ssid) == 0 || strlen(password) == 0) {
...@@ -75,6 +79,7 @@ int orange_pi_save_wifi(const char* ssid, const char* password) { ...@@ -75,6 +79,7 @@ int orange_pi_save_wifi(const char* ssid, const char* password) {
} }
/*保存WiFi接口,接收到mqtt消息进行保存*/
void device_wifi_rec_sava(cJSON *body){ void device_wifi_rec_sava(cJSON *body){
cJSON *wifi_ssid = cJSON_GetObjectItem(body, "wifi_ssid"); cJSON *wifi_ssid = cJSON_GetObjectItem(body, "wifi_ssid");
cJSON *wifi_password = cJSON_GetObjectItem(body, "wifi_password"); cJSON *wifi_password = cJSON_GetObjectItem(body, "wifi_password");
...@@ -131,10 +136,10 @@ int get_saved_wifi_list(char ssid_list[][SSID_MAX_LENGTH], int max_count) { ...@@ -131,10 +136,10 @@ int get_saved_wifi_list(char ssid_list[][SSID_MAX_LENGTH], int max_count) {
return count; return count;
} }
/** /**
* @brief 打印所有已保存的WiFi配置 * @brief 打印所有已保存的WiFi配置
*/ */
void device_send_saved_wifi(){ void device_send_saved_wifi(){
get_current_wifi(); get_current_wifi();
......
...@@ -3,10 +3,13 @@ ...@@ -3,10 +3,13 @@
#include "common.h" #include "common.h"
//发送已经保存的WiFi给上层
void device_send_saved_wifi(); void device_send_saved_wifi();
//删除wifi
void device_wifi_rec_delete(cJSON *body); void device_wifi_rec_delete(cJSON *body);
//接收到保存wifi消息
void device_wifi_rec_sava(cJSON *body); void device_wifi_rec_sava(cJSON *body);
#endif #endif
\ No newline at end of file
...@@ -8,7 +8,5 @@ int device_id_file_init(); ...@@ -8,7 +8,5 @@ int device_id_file_init();
/*打开版本文件,版本文件是go语言进行创建,只需要读取就行了*/ /*打开版本文件,版本文件是go语言进行创建,只需要读取就行了*/
char *program_version() ; char *program_version() ;
//extern char *g_device_id ;
char *device_id_function(); char *device_id_function();
#endif #endif
\ No newline at end of file
...@@ -51,12 +51,11 @@ void *thread_exit_time(void *arg) { ...@@ -51,12 +51,11 @@ void *thread_exit_time(void *arg) {
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) {
device_stop(g_device_type); device_stop(g_device_type);
g_devcontrol_exit_count=6; g_devcontrol_exit_count=6;
} }
pthread_mutex_unlock(&g_exit_count_mutex); pthread_mutex_unlock(&g_exit_count_mutex);
...@@ -64,6 +63,7 @@ void *thread_exit_time(void *arg) { ...@@ -64,6 +63,7 @@ void *thread_exit_time(void *arg) {
return NULL; return NULL;
} }
/*心跳线程处理函数,心跳发送前会像上层请求是否需要验证*/
void *thread_mqtt_beat(void *arg) { void *thread_mqtt_beat(void *arg) {
my_zlog_info("thread_mqtt_beat start"); my_zlog_info("thread_mqtt_beat start");
g_webrtc_index=1; g_webrtc_index=1;
...@@ -95,6 +95,7 @@ void *thread_mqtt_beat(void *arg) { ...@@ -95,6 +95,7 @@ void *thread_mqtt_beat(void *arg) {
return NULL; return NULL;
} }
//打开游览器线程,让游览器一直在一个线程中打开并运行
void *thread_open_browser(void *arg) { void *thread_open_browser(void *arg) {
//如果为相关的不需要心跳或者游览器设备,提早结束线程 //如果为相关的不需要心跳或者游览器设备,提早结束线程
...@@ -138,7 +139,7 @@ void *thread_mqtt_reconnect(void *arg) { ...@@ -138,7 +139,7 @@ void *thread_mqtt_reconnect(void *arg) {
} }
} }
g_mqtt_grc = mqtt_create(mosq); g_mqtt_grc = mqtt_create(mosq);//创建mqtt
if (g_mqtt_grc != 0) { if (g_mqtt_grc != 0) {
my_zlog_warn("mqtt fail ..."); my_zlog_warn("mqtt fail ...");
mqtt_clean(mosq); mqtt_clean(mosq);
...@@ -161,21 +162,19 @@ void *thread_mqtt_reconnect(void *arg) { ...@@ -161,21 +162,19 @@ void *thread_mqtt_reconnect(void *arg) {
//专门用于计时的线程 //专门用于计时的线程
void *thread_time_calculation(void *arg) { void *thread_time_calculation(void *arg) {
while (1) { while (1) {
delay_ms(5); delay_ms(5);
g_device_delay_count++;//设备计时,坦克打击倒退逻辑 g_device_delay_back_count ++;//设备计时,坦克打击倒退逻辑
pthread_mutex_lock(&g_verify_mutex); pthread_mutex_lock(&g_verify_mutex);
g_verify_count++;//验证计时,每15s一次 g_verify_count++;//验证计时,每15s一次
pthread_mutex_unlock(&g_verify_mutex); pthread_mutex_unlock(&g_verify_mutex);
if(g_verify_count >= 20000) { if(g_verify_count >= 20000) {//防止溢出
pthread_mutex_lock(&g_verify_mutex); pthread_mutex_lock(&g_verify_mutex);
g_verify_count = 20000; g_verify_count = 20000;
pthread_mutex_unlock(&g_verify_mutex); pthread_mutex_unlock(&g_verify_mutex);
} }
if(g_device_delay_count >= 5000) g_device_delay_count = 5000; if(g_device_delay_back_count >= 5000) g_device_delay_back_count = 5000;//防止溢出
} }
return NULL; return NULL;
} }
......
...@@ -1158,6 +1158,30 @@ modules/delay/delay.c.s: ...@@ -1158,6 +1158,30 @@ modules/delay/delay.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/delay/delay.c.s $(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/delay/delay.c.s
.PHONY : modules/delay/delay.c.s .PHONY : modules/delay/delay.c.s
modules/http/http_consolepush.o: modules/http/http_consolepush.c.o
.PHONY : modules/http/http_consolepush.o
# target to build an object file
modules/http/http_consolepush.c.o:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/http/http_consolepush.c.o
.PHONY : modules/http/http_consolepush.c.o
modules/http/http_consolepush.i: modules/http/http_consolepush.c.i
.PHONY : modules/http/http_consolepush.i
# target to preprocess a source file
modules/http/http_consolepush.c.i:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/http/http_consolepush.c.i
.PHONY : modules/http/http_consolepush.c.i
modules/http/http_consolepush.s: modules/http/http_consolepush.c.s
.PHONY : modules/http/http_consolepush.s
# target to generate assembly for a file
modules/http/http_consolepush.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/http/http_consolepush.c.s
.PHONY : modules/http/http_consolepush.c.s
modules/http/http_request.o: modules/http/http_request.c.o modules/http/http_request.o: modules/http/http_request.c.o
.PHONY : modules/http/http_request.o .PHONY : modules/http/http_request.o
...@@ -1957,6 +1981,9 @@ help: ...@@ -1957,6 +1981,9 @@ help:
@echo "... modules/delay/delay.o" @echo "... modules/delay/delay.o"
@echo "... modules/delay/delay.i" @echo "... modules/delay/delay.i"
@echo "... modules/delay/delay.s" @echo "... modules/delay/delay.s"
@echo "... modules/http/http_consolepush.o"
@echo "... modules/http/http_consolepush.i"
@echo "... modules/http/http_consolepush.s"
@echo "... modules/http/http_request.o" @echo "... modules/http/http_request.o"
@echo "... modules/http/http_request.i" @echo "... modules/http/http_request.i"
@echo "... modules/http/http_request.s" @echo "... modules/http/http_request.s"
......
No preview for this file type
...@@ -5,8 +5,8 @@ CMAKE_PROGRESS_4 = ...@@ -5,8 +5,8 @@ CMAKE_PROGRESS_4 =
CMAKE_PROGRESS_5 = CMAKE_PROGRESS_5 =
CMAKE_PROGRESS_6 = 82 CMAKE_PROGRESS_6 = 82
CMAKE_PROGRESS_7 = CMAKE_PROGRESS_7 =
CMAKE_PROGRESS_8 = CMAKE_PROGRESS_8 = 83
CMAKE_PROGRESS_9 = 83 CMAKE_PROGRESS_9 =
CMAKE_PROGRESS_10 = CMAKE_PROGRESS_10 =
CMAKE_PROGRESS_11 = 84 CMAKE_PROGRESS_11 = 84
CMAKE_PROGRESS_12 = CMAKE_PROGRESS_12 =
......
CMAKE_PROGRESS_1 = CMAKE_PROGRESS_1 =
CMAKE_PROGRESS_2 = 17 CMAKE_PROGRESS_2 =
CMAKE_PROGRESS_3 = CMAKE_PROGRESS_3 = 17
CMAKE_PROGRESS_4 = CMAKE_PROGRESS_4 =
CMAKE_PROGRESS_5 = 18 CMAKE_PROGRESS_5 = 18
CMAKE_PROGRESS_6 = CMAKE_PROGRESS_6 =
...@@ -16,8 +16,8 @@ CMAKE_PROGRESS_15 = ...@@ -16,8 +16,8 @@ CMAKE_PROGRESS_15 =
CMAKE_PROGRESS_16 = CMAKE_PROGRESS_16 =
CMAKE_PROGRESS_17 = 22 CMAKE_PROGRESS_17 = 22
CMAKE_PROGRESS_18 = CMAKE_PROGRESS_18 =
CMAKE_PROGRESS_19 = 23 CMAKE_PROGRESS_19 =
CMAKE_PROGRESS_20 = CMAKE_PROGRESS_20 = 23
CMAKE_PROGRESS_21 = CMAKE_PROGRESS_21 =
CMAKE_PROGRESS_22 = 24 CMAKE_PROGRESS_22 = 24
CMAKE_PROGRESS_23 = CMAKE_PROGRESS_23 =
...@@ -30,11 +30,11 @@ CMAKE_PROGRESS_29 = ...@@ -30,11 +30,11 @@ CMAKE_PROGRESS_29 =
CMAKE_PROGRESS_30 = CMAKE_PROGRESS_30 =
CMAKE_PROGRESS_31 = 27 CMAKE_PROGRESS_31 = 27
CMAKE_PROGRESS_32 = CMAKE_PROGRESS_32 =
CMAKE_PROGRESS_33 = 28 CMAKE_PROGRESS_33 =
CMAKE_PROGRESS_34 = CMAKE_PROGRESS_34 = 28
CMAKE_PROGRESS_35 = CMAKE_PROGRESS_35 =
CMAKE_PROGRESS_36 = 29 CMAKE_PROGRESS_36 =
CMAKE_PROGRESS_37 = CMAKE_PROGRESS_37 = 29
CMAKE_PROGRESS_38 = CMAKE_PROGRESS_38 =
CMAKE_PROGRESS_39 = 30 CMAKE_PROGRESS_39 = 30
CMAKE_PROGRESS_40 = CMAKE_PROGRESS_40 =
......
CMAKE_PROGRESS_1 = CMAKE_PROGRESS_1 = 54
CMAKE_PROGRESS_2 = 54 CMAKE_PROGRESS_2 =
CMAKE_PROGRESS_3 = CMAKE_PROGRESS_3 =
CMAKE_PROGRESS_4 = CMAKE_PROGRESS_4 = 55
CMAKE_PROGRESS_5 = 55 CMAKE_PROGRESS_5 =
CMAKE_PROGRESS_6 = CMAKE_PROGRESS_6 =
CMAKE_PROGRESS_7 = 56 CMAKE_PROGRESS_7 = 56
CMAKE_PROGRESS_8 = CMAKE_PROGRESS_8 =
...@@ -12,14 +12,14 @@ CMAKE_PROGRESS_11 = ...@@ -12,14 +12,14 @@ CMAKE_PROGRESS_11 =
CMAKE_PROGRESS_12 = CMAKE_PROGRESS_12 =
CMAKE_PROGRESS_13 = 58 CMAKE_PROGRESS_13 = 58
CMAKE_PROGRESS_14 = CMAKE_PROGRESS_14 =
CMAKE_PROGRESS_15 = CMAKE_PROGRESS_15 = 59
CMAKE_PROGRESS_16 = 59 CMAKE_PROGRESS_16 =
CMAKE_PROGRESS_17 = CMAKE_PROGRESS_17 =
CMAKE_PROGRESS_18 = CMAKE_PROGRESS_18 = 60
CMAKE_PROGRESS_19 = 60 CMAKE_PROGRESS_19 =
CMAKE_PROGRESS_20 = CMAKE_PROGRESS_20 =
CMAKE_PROGRESS_21 = CMAKE_PROGRESS_21 = 61
CMAKE_PROGRESS_22 = 61 CMAKE_PROGRESS_22 =
CMAKE_PROGRESS_23 = CMAKE_PROGRESS_23 =
CMAKE_PROGRESS_24 = 62 CMAKE_PROGRESS_24 = 62
CMAKE_PROGRESS_25 = CMAKE_PROGRESS_25 =
...@@ -29,11 +29,11 @@ CMAKE_PROGRESS_28 = ...@@ -29,11 +29,11 @@ CMAKE_PROGRESS_28 =
CMAKE_PROGRESS_29 = CMAKE_PROGRESS_29 =
CMAKE_PROGRESS_30 = 64 CMAKE_PROGRESS_30 = 64
CMAKE_PROGRESS_31 = CMAKE_PROGRESS_31 =
CMAKE_PROGRESS_32 = CMAKE_PROGRESS_32 = 65
CMAKE_PROGRESS_33 = 65 CMAKE_PROGRESS_33 =
CMAKE_PROGRESS_34 = CMAKE_PROGRESS_34 =
CMAKE_PROGRESS_35 = CMAKE_PROGRESS_35 = 66
CMAKE_PROGRESS_36 = 66 CMAKE_PROGRESS_36 =
CMAKE_PROGRESS_37 = CMAKE_PROGRESS_37 =
CMAKE_PROGRESS_38 = 67 CMAKE_PROGRESS_38 = 67
CMAKE_PROGRESS_39 = CMAKE_PROGRESS_39 =
...@@ -46,11 +46,11 @@ CMAKE_PROGRESS_45 = ...@@ -46,11 +46,11 @@ CMAKE_PROGRESS_45 =
CMAKE_PROGRESS_46 = CMAKE_PROGRESS_46 =
CMAKE_PROGRESS_47 = 70 CMAKE_PROGRESS_47 = 70
CMAKE_PROGRESS_48 = CMAKE_PROGRESS_48 =
CMAKE_PROGRESS_49 = CMAKE_PROGRESS_49 = 71
CMAKE_PROGRESS_50 = 71 CMAKE_PROGRESS_50 =
CMAKE_PROGRESS_51 = CMAKE_PROGRESS_51 =
CMAKE_PROGRESS_52 = CMAKE_PROGRESS_52 = 72
CMAKE_PROGRESS_53 = 72 CMAKE_PROGRESS_53 =
CMAKE_PROGRESS_54 = CMAKE_PROGRESS_54 =
CMAKE_PROGRESS_55 = 73 CMAKE_PROGRESS_55 = 73
CMAKE_PROGRESS_56 = CMAKE_PROGRESS_56 =
...@@ -63,8 +63,8 @@ CMAKE_PROGRESS_62 = ...@@ -63,8 +63,8 @@ CMAKE_PROGRESS_62 =
CMAKE_PROGRESS_63 = CMAKE_PROGRESS_63 =
CMAKE_PROGRESS_64 = 76 CMAKE_PROGRESS_64 = 76
CMAKE_PROGRESS_65 = CMAKE_PROGRESS_65 =
CMAKE_PROGRESS_66 = CMAKE_PROGRESS_66 = 77
CMAKE_PROGRESS_67 = 77 CMAKE_PROGRESS_67 =
CMAKE_PROGRESS_68 = CMAKE_PROGRESS_68 =
CMAKE_PROGRESS_69 = 78 CMAKE_PROGRESS_69 = 78
CMAKE_PROGRESS_70 = CMAKE_PROGRESS_70 =
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
#include "device_init.h" #include "device_init.h"
#include "gpio_control.h" #include "gpio_control.h"
//将角度转化为对应的舵机pwm值
void car0102_calculate_L_R(int angle) {//将角度转化为对应的舵机pwm值 void car0102_calculate_L_R(int angle) {
if (angle < 0) { if (angle < 0) {
angle = 0; angle = 0;
} else if (angle > 180) { } else if (angle > 180) {
...@@ -17,8 +17,8 @@ void car0102_calculate_L_R(int angle) {//将角度转化为对应的舵机pwm值 ...@@ -17,8 +17,8 @@ void car0102_calculate_L_R(int angle) {//将角度转化为对应的舵机pwm值
int val = (int)((pulse_width / period) * 1000); int val = (int)((pulse_width / period) * 1000);
pwmWrite(PWM_PIN_CHANGE,val); pwmWrite(PWM_PIN_CHANGE,val);
} }
void car0102_speed_stop() { void car0102_speed_stop() {
//device_gpio_control(g_device_type,26,0);
pwmWrite(PWM_PIN_SPEED,0); pwmWrite(PWM_PIN_SPEED,0);
car0102_calculate_L_R(90); car0102_calculate_L_R(90);
} }
...@@ -166,7 +166,8 @@ void car0102_mode_4_right(unsigned char gval) { ...@@ -166,7 +166,8 @@ void car0102_mode_4_right(unsigned char gval) {
} }
} }
void car0102_speed_change(unsigned char *buf) {//车速度和转向引脚数值处理函数 //车速度和转向引脚数值处理函数
void car0102_speed_change(unsigned char *buf) {
unsigned char mode=buf[1]; unsigned char mode=buf[1];
unsigned char val=buf[2]; unsigned char val=buf[2];
switch(mode){ switch(mode){
......
...@@ -37,13 +37,13 @@ void mode_car0103_lift_back(unsigned char gval) { ...@@ -37,13 +37,13 @@ void mode_car0103_lift_back(unsigned char gval) {
} }
void mode_car0103_right_flont(unsigned char gval) { void mode_car0103_right_flont(unsigned char gval) {
int b=0; int b=1;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_CHANGE, 75); pwmWrite(PWM_PIN_CHANGE, 75);
}else if (gval <= 60) { }else if (gval <= 60) {
pwmWrite(PWM_PIN_CHANGE, 79); pwmWrite(PWM_PIN_CHANGE, 79+b);
}else if (gval <= 70) { }else if (gval <= 70) {
pwmWrite(PWM_PIN_CHANGE, 80); pwmWrite(PWM_PIN_CHANGE, 80+b);
}else if(gval >70){ }else if(gval >70){
int flont_speed = 80+(gval-70)/10+b; int flont_speed = 80+(gval-70)/10+b;
pwmWrite(PWM_PIN_CHANGE, flont_speed); pwmWrite(PWM_PIN_CHANGE, flont_speed);
...@@ -51,20 +51,21 @@ void mode_car0103_right_flont(unsigned char gval) { ...@@ -51,20 +51,21 @@ void mode_car0103_right_flont(unsigned char gval) {
} }
void mode_car0103_right_back(unsigned char gval) { void mode_car0103_right_back(unsigned char gval) {
int b=0; int b=1;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_CHANGE, 75); pwmWrite(PWM_PIN_CHANGE, 75);
}else if (gval <= 60) { }else if (gval <= 60) {
pwmWrite(PWM_PIN_CHANGE, 71); pwmWrite(PWM_PIN_CHANGE, 71-b);
} else if (gval <= 70) { } else if (gval <= 70) {
pwmWrite(PWM_PIN_CHANGE, 70); pwmWrite(PWM_PIN_CHANGE, 70-b);
} else if(gval >70){ } else if(gval >70){
int back_speed = 70 - (gval-70)/10-b; int back_speed = 70 - (gval-70)/10-b;
pwmWrite(PWM_PIN_CHANGE, back_speed); pwmWrite(PWM_PIN_CHANGE, back_speed);
} }
} }
void car0103_change(unsigned char *buf) { /*挖机的速度处理接口*/
void car0103_change(unsigned char *buf) {
unsigned char mode = buf[1]; unsigned char mode = buf[1];
unsigned char val = buf[2]; unsigned char val = buf[2];
static int modecount_car0103=0; static int modecount_car0103=0;
......
#ifndef CAR0103_CONTROL_H__ #ifndef CAR0103_CONTROL_H__
#define CAR0103_CONTROL_H__ #define CAR0103_CONTROL_H__
//停止接口
void car0103_middle(); void car0103_middle();
void car0103_change(unsigned char *buf); /*挖机的速度处理接口*/
void car0103_change(unsigned char *buf);
#endif #endif
\ No newline at end of file
...@@ -8,6 +8,7 @@ void car0104_stop() { ...@@ -8,6 +8,7 @@ void car0104_stop() {
pwmWrite(PWM_PIN_CHANGE,75); pwmWrite(PWM_PIN_CHANGE,75);
} }
//铲车后退
void car0104_back(unsigned char gval) { void car0104_back(unsigned char gval) {
int b=7; int b=7;
int c=2; int c=2;
...@@ -25,6 +26,7 @@ void car0104_back(unsigned char gval) { ...@@ -25,6 +26,7 @@ void car0104_back(unsigned char gval) {
} }
} }
//铲车前进
void car0104_flont(unsigned char gval) { void car0104_flont(unsigned char gval) {
int b=7; int b=7;
int c=2; int c=2;
...@@ -41,6 +43,7 @@ void car0104_flont(unsigned char gval) { ...@@ -41,6 +43,7 @@ void car0104_flont(unsigned char gval) {
} }
} }
//铲车右
void car0104_right(unsigned char gval) { void car0104_right(unsigned char gval) {
int b=5; int b=5;
if (gval < 50) { if (gval < 50) {
...@@ -57,6 +60,7 @@ void car0104_right(unsigned char gval) { ...@@ -57,6 +60,7 @@ void car0104_right(unsigned char gval) {
} }
} }
//铲车左
void car0104_lift(unsigned char gval) { void car0104_lift(unsigned char gval) {
int b=5; int b=5;
if (gval < 50) { if (gval < 50) {
......
...@@ -18,9 +18,9 @@ void tank0203_mode_lift_flont(unsigned char gval) { ...@@ -18,9 +18,9 @@ void tank0203_mode_lift_flont(unsigned char gval) {
pwmWrite(PWM_PIN_SPEED, 75); pwmWrite(PWM_PIN_SPEED, 75);
} }
else if (gval <= 60) { else if (gval <= 60) {
pwmWrite(PWM_PIN_SPEED, 79); pwmWrite(PWM_PIN_SPEED, 79+b);
}else if (gval <= 70) { }else if (gval <= 70) {
pwmWrite(PWM_PIN_SPEED, 80); pwmWrite(PWM_PIN_SPEED, 80+b);
}else if(gval >70){ }else if(gval >70){
int flont_speed = 80+(gval-70)/10+b; int flont_speed = 80+(gval-70)/10+b;
if(flont_speed>95) flont_speed = 95; if(flont_speed>95) flont_speed = 95;
...@@ -33,9 +33,9 @@ void tank0203_mode_lift_back(unsigned char gval) { ...@@ -33,9 +33,9 @@ void tank0203_mode_lift_back(unsigned char gval) {
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_SPEED, 75); pwmWrite(PWM_PIN_SPEED, 75);
} else if (gval <= 60) { } else if (gval <= 60) {
pwmWrite(PWM_PIN_SPEED, 71); pwmWrite(PWM_PIN_SPEED, 71-b);
}else if (gval <= 70) { }else if (gval <= 70) {
pwmWrite(PWM_PIN_SPEED, 70); pwmWrite(PWM_PIN_SPEED, 70-b);
} else if(gval >70){ } else if(gval >70){
int back_speed = 70 - (gval-70)/10-b; int back_speed = 70 - (gval-70)/10-b;
if(back_speed<55) back_speed =55; if(back_speed<55) back_speed =55;
...@@ -48,9 +48,9 @@ void tank0203_mode_right_back(unsigned char gval) { ...@@ -48,9 +48,9 @@ void tank0203_mode_right_back(unsigned char gval) {
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_CHANGE, 75); pwmWrite(PWM_PIN_CHANGE, 75);
}else if (gval <= 60) { }else if (gval <= 60) {
pwmWrite(PWM_PIN_CHANGE, 79); pwmWrite(PWM_PIN_CHANGE, 79+b);
}else if (gval <= 70) { }else if (gval <= 70) {
pwmWrite(PWM_PIN_CHANGE, 80); pwmWrite(PWM_PIN_CHANGE, 80+b);
}else if(gval >70){ }else if(gval >70){
int flont_speed = 80+(gval-70)/10+b; int flont_speed = 80+(gval-70)/10+b;
if(flont_speed>95) flont_speed = 95; if(flont_speed>95) flont_speed = 95;
...@@ -63,9 +63,9 @@ void tank0203_mode_right_flont(unsigned char gval) { ...@@ -63,9 +63,9 @@ void tank0203_mode_right_flont(unsigned char gval) {
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_CHANGE, 75); pwmWrite(PWM_PIN_CHANGE, 75);
}else if (gval <= 60) { }else if (gval <= 60) {
pwmWrite(PWM_PIN_CHANGE, 71); pwmWrite(PWM_PIN_CHANGE, 71-b);
} else if (gval <= 70) { } else if (gval <= 70) {
pwmWrite(PWM_PIN_CHANGE, 70); pwmWrite(PWM_PIN_CHANGE, 70-b);
} else if(gval >70){ } else if(gval >70){
int back_speed = 70 - (gval-70)/10-b; int back_speed = 70 - (gval-70)/10-b;
if(back_speed<55) back_speed =55; if(back_speed<55) back_speed =55;
...@@ -73,36 +73,34 @@ void tank0203_mode_right_flont(unsigned char gval) { ...@@ -73,36 +73,34 @@ void tank0203_mode_right_flont(unsigned char gval) {
} }
} }
void tank0203_change(unsigned char *buf) {
//tank0203控制函数
void tank0203_change(unsigned char *buf) {
unsigned char mode = buf[1]; unsigned char mode = buf[1];
unsigned char val = buf[2]; unsigned char val = buf[2];
static int modecount_tank0203=0; static int modecount_tank0203=0;
static int tank0203_index =0; static int tank0203_index =0;
// static int s_val_1=0;
// static int s_val_2=0;
if(mode == 1 ) { if(mode == 1 ) {
tank0203_mode_lift_flont(val); tank0203_mode_lift_flont(val);
tank0203_mode_right_flont(val); tank0203_mode_right_flont(val);
modecount_tank0203=0; modecount_tank0203=0;
//s_val_1 = val;
}else if(mode == 2 ) { }else if(mode == 2 ) {
tank0203_mode_lift_back(val); tank0203_mode_lift_back(val);
tank0203_mode_right_back(val); tank0203_mode_right_back(val);
modecount_tank0203=1; modecount_tank0203=1;
//s_val_2 = val;
} }
if((mode == 1||mode == 2)&&val == 0) { if((mode == 1||mode == 2)&&val == 0) {
modecount_tank0203 = 0; modecount_tank0203 = 0;
tank0203_index = 0; tank0203_index = 0;
} }
if((mode == 1||mode == 2)&&val != 0) tank0203_index = 1; if((mode == 1||mode == 2)&&val != 0) tank0203_index = 1;
if(mode == 3) { if(mode == 3) {
if(modecount_tank0203 == 0){ if(modecount_tank0203 == 0){
if(tank0203_index == 1) { if(tank0203_index == 1) {
tank0203_mode_lift_flont(0); tank0203_mode_lift_flont(0);
//tank0203_mode_right_flont(s_val_1-20);
} }
else { else {
tank0203_mode_lift_back(val+30); tank0203_mode_lift_back(val+30);
...@@ -112,29 +110,24 @@ void tank0203_change(unsigned char *buf) { ...@@ -112,29 +110,24 @@ void tank0203_change(unsigned char *buf) {
if(modecount_tank0203 == 1) { if(modecount_tank0203 == 1) {
if(tank0203_index == 1) { if(tank0203_index == 1) {
tank0203_mode_lift_back(0); tank0203_mode_lift_back(0);
//tank0203_mode_lift_back(s_val_2-20);
}else { }else {
tank0203_mode_lift_back(val+30); tank0203_mode_lift_back(val+30);
tank0203_mode_right_flont(val+30); tank0203_mode_right_flont(val+30);
} }
} }
}else if(mode == 4) { }else if(mode == 4) {
if(modecount_tank0203 == 1){ if(modecount_tank0203 == 1){
if(tank0203_index == 1) { if(tank0203_index == 1) {
//tank0203_mode_right_back(s_val_1);
tank0203_mode_right_back(0); tank0203_mode_right_back(0);
} }
else { else {
tank0203_mode_lift_flont(val+30); tank0203_mode_lift_flont(val+30);
tank0203_mode_right_back(val+30); tank0203_mode_right_back(val+30);
} }
} }
if(modecount_tank0203 == 0) { if(modecount_tank0203 == 0) {
if(tank0203_index == 1) { if(tank0203_index == 1) {
//tank0203_mode_lift_flont(s_val_1-20);
tank0203_mode_right_flont(0); tank0203_mode_right_flont(0);
} }
else { else {
......
...@@ -12,6 +12,7 @@ const tank_common_back *g_tank_common_config_t = NULL; ...@@ -12,6 +12,7 @@ const tank_common_back *g_tank_common_config_t = NULL;
long long shot_device_time_start =0 ; long long shot_device_time_start =0 ;
long long shot_device_time_end = 0; long long shot_device_time_end = 0;
/*击打后退速度设置,混空模式下为单路,单独模式下为双路控制,后续需要优化*/
void tank_shot_back(unsigned char gval) { void tank_shot_back(unsigned char gval) {
int b=0; int b=0;
...@@ -39,7 +40,6 @@ void tank_shot_back(unsigned char gval) { ...@@ -39,7 +40,6 @@ void tank_shot_back(unsigned char gval) {
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_SPEED, speed_2);
if(g_tank_common_config_t->device_id ==DEVICE_TANK0204) pwmWrite(PWM_PIN_CHANGE, change_1); if(g_tank_common_config_t->device_id ==DEVICE_TANK0204) pwmWrite(PWM_PIN_CHANGE, change_1);
} }
} }
...@@ -71,18 +71,35 @@ const tank_common_back tank_common_config_t[]={ ...@@ -71,18 +71,35 @@ const tank_common_back tank_common_config_t[]={
{ .device_id = -1 } { .device_id = -1 }
}; };
void tank_shot_back_stop_task_function(void *arg) {//多线程处理坦克发射后退线程池 //多线程处理坦克发射后退线程池
void tank_shot_back_stop_task_function(void *arg) {
if(arg!= NULL){ if(arg!= NULL){
free(arg); free(arg);
} }
// 设置 GPIO 23 为输入模式,启用内部上拉电阻
// pinMode(23, INPUT);
// pullUpDnControl(23, PUD_UP);
// my_zlog_debug("开始监测 GPIO 23 状态...\n");
while(1){ while(1){
//下面一部分为检测射击后后退
// if(digitalRead(27)==LOW){
// if(g_device_delay_back_count <= g_tank_common_config_t->back_time) {
// tank_shot_back(g_tank_common_config_t->shot_back_speed);
// my_zlog_debug("操作耗时: %lld 毫秒", interval);
// }
// }else tank_shot_back(0);
//下面一部分为射击后按时间后退
long long interval=shot_device_time_start-shot_device_time_end; long long interval=shot_device_time_start-shot_device_time_end;
if(g_device_delay_count > g_tank_common_config_t->back_time&&g_device_delay_count < (g_tank_common_config_t->back_time+30)) if(g_device_delay_back_count > g_tank_common_config_t->back_time&&g_device_delay_back_count < (g_tank_common_config_t->back_time+30))
tank_shot_back(0); tank_shot_back(0);
if(interval > g_tank_common_config_t->back_interval_back){ if(interval > g_tank_common_config_t->back_interval_back){
if(g_device_delay_count <= g_tank_common_config_t->back_time) { if(g_device_delay_back_count <= g_tank_common_config_t->back_time) {
tank_shot_back(g_tank_common_config_t->shot_back_speed); tank_shot_back(g_tank_common_config_t->shot_back_speed);
my_zlog_debug("操作耗时: %lld 毫秒", interval); my_zlog_debug("操作耗时: %lld 毫秒", interval);
} }
...@@ -92,8 +109,9 @@ void tank_shot_back_stop_task_function(void *arg) {//多线程处理坦克发射 ...@@ -92,8 +109,9 @@ void tank_shot_back_stop_task_function(void *arg) {//多线程处理坦克发射
} }
ThreadPool_t *pool_tank_t; ThreadPool_t *pool_tank_t;//坦克后退线程函数
/*坦克后退线程池打开*/
void tank_shot_pthrpoll_task_init(){ void tank_shot_pthrpoll_task_init(){
int *arg = malloc(sizeof(int)); int *arg = malloc(sizeof(int));
*arg = 1; *arg = 1;
...@@ -102,6 +120,7 @@ void tank_shot_pthrpoll_task_init(){ ...@@ -102,6 +120,7 @@ void tank_shot_pthrpoll_task_init(){
my_zlog_debug("线程池打开"); my_zlog_debug("线程池打开");
} }
/*坦克后退射击*/
int tank_shot_back_stop(unsigned char pin,unsigned char val){ int tank_shot_back_stop(unsigned char pin,unsigned char val){
static int shot_count=0; static int shot_count=0;
shot_device_time_start=get_current_time_millis(); shot_device_time_start=get_current_time_millis();
...@@ -121,7 +140,7 @@ int tank_shot_back_stop(unsigned char pin,unsigned char val){ ...@@ -121,7 +140,7 @@ int tank_shot_back_stop(unsigned char pin,unsigned char val){
} }
shot_count=1; shot_count=1;
if(shot_count == 1){ if(shot_count == 1){
g_device_delay_count=0; g_device_delay_back_count =0;
} }
} }
...@@ -134,6 +153,7 @@ void tank_thread_close(){ ...@@ -134,6 +153,7 @@ void tank_thread_close(){
thread_pool_destroy(g_pool_device_gpio_control_t); thread_pool_destroy(g_pool_device_gpio_control_t);
} }
/*坦克射击接口,只有在特定设备号下使用*/
void tank_shot_stop_control(int device_id,unsigned char pin,unsigned char val) { void tank_shot_stop_control(int device_id,unsigned char pin,unsigned char val) {
if (!g_tank_common_config_t || g_tank_common_config_t->device_id != device_id) { if (!g_tank_common_config_t || g_tank_common_config_t->device_id != device_id) {
......
...@@ -11,10 +11,10 @@ typedef struct { ...@@ -11,10 +11,10 @@ typedef struct {
int(*shot_back)(unsigned char pin,unsigned char val); int(*shot_back)(unsigned char pin,unsigned char val);
} tank_common_back; } tank_common_back;
/*坦克射击接口,只有在特定设备号下使用*/
void tank_shot_stop_control(int device_id,unsigned char pin,unsigned char val); void tank_shot_stop_control(int device_id,unsigned char pin,unsigned char val);
/*关闭线程*/
void tank_thread_close(); void tank_thread_close();
int angele_limit();
#endif #endif
\ No newline at end of file
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
#include "common.h" #include "common.h"
#include "gpio_init.h" #include "gpio_init.h"
int g_device_delay_count =0; int g_device_delay_back_count =0;//设备计时,比如坦克打击倒退逻辑
int abnormal_pin_pwm_stop=0; int abnormal_pin_pwm_stop=0;
int g_device_type =0; //设备类型,比如tank0202、car0101 int g_device_type =0; //设备详细类型,比如tank0202、car0101
const deviceconfig_t device_configs[] = { const deviceconfig_t device_configs[] = {
// car0101配置 // car0101配置
...@@ -54,7 +54,7 @@ const deviceconfig_t device_configs[] = { ...@@ -54,7 +54,7 @@ const deviceconfig_t device_configs[] = {
{ {
.device_id = DEVICE_TANK0202, .device_id = DEVICE_TANK0202,
.device_name = "tank0202", .device_name = "tank0202",
.gpio_pins = {6, 16, 20, 22, 23,-1},/* 补充GPIO引脚 */ .gpio_pins = {6, 16, 20, 22,-1},/* 补充GPIO引脚 */
.gpio_pwms = {5 , 7 ,24,26, 27,-1}, .gpio_pwms = {5 , 7 ,24,26, 27,-1},
.device_pwm_init = physics_pwm_init, .device_pwm_init = physics_pwm_init,
.device_control_stop = tank0202_middle,/* 补充速度控制函数 */ .device_control_stop = tank0202_middle,/* 补充速度控制函数 */
...@@ -63,7 +63,7 @@ const deviceconfig_t device_configs[] = { ...@@ -63,7 +63,7 @@ const deviceconfig_t device_configs[] = {
{ {
.device_id = DEVICE_TANK0203, .device_id = DEVICE_TANK0203,
.device_name = "tank0203", .device_name = "tank0203",
.gpio_pins = {6, 16, 20, 22, 23,-1},/* 补充GPIO引脚 */ .gpio_pins = {6, 16, 20, 22,-1},/* 补充GPIO引脚 */
.gpio_pwms = {5 , 7 ,24, 26, 27,-1}, .gpio_pwms = {5 , 7 ,24, 26, 27,-1},
.device_pwm_init = physics_pwm_init, .device_pwm_init = physics_pwm_init,
.device_control_stop = tank0203_middle,/* 补充速度控制函数 */ .device_control_stop = tank0203_middle,/* 补充速度控制函数 */
...@@ -72,7 +72,7 @@ const deviceconfig_t device_configs[] = { ...@@ -72,7 +72,7 @@ const deviceconfig_t device_configs[] = {
{ {
.device_id = DEVICE_TANK0204, .device_id = DEVICE_TANK0204,
.device_name = "tank0204", .device_name = "tank0204",
.gpio_pins = {6, 16, 20, 22, 23,-1},/* 补充GPIO引脚 */ .gpio_pins = {6, 16, 20, 22,-1},/* 补充GPIO引脚 */
.gpio_pwms = {5 , 7 ,24, 26, 27,-1}, .gpio_pwms = {5 , 7 ,24, 26, 27,-1},
.device_pwm_init = physics_pwm_init, .device_pwm_init = physics_pwm_init,
.device_control_stop = tank0204_stop,/* 补充速度控制函数 */ .device_control_stop = tank0204_stop,/* 补充速度控制函数 */
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
extern int g_device_type;//设备类型,比如tank0202、car0101 extern int g_device_type;//设备类型,比如tank0202、car0101
extern int g_device_delay_count ; //设备延时函数 extern int g_device_delay_back_count ; //设备延时函数,坦克倒退逻辑
typedef struct { typedef struct {
int device_id; // 设备ID (101, 102等) int device_id; // 设备ID (101, 102等)
......
...@@ -9,14 +9,11 @@ ...@@ -9,14 +9,11 @@
#define GPIO_ID_THREAD_COUNT 3 #define GPIO_ID_THREAD_COUNT 3
int gpio_device_id[GPIO_ID_THREAD_COUNT]={DEVICE_TANK0202,DEVICE_TANK0203,DEVICE_TANK0204}; int gpio_device_id[GPIO_ID_THREAD_COUNT]={DEVICE_TANK0202,DEVICE_TANK0203,DEVICE_TANK0204};//需要打开线程池设备号
const gpiocontrol_t *gpio_control_config_t = NULL ; const gpiocontrol_t *gpio_control_config_t = NULL ;//gpio结构体标识
ThreadPool_t *g_pool_device_gpio_control_t;
static bool s_poll_tank_index =0;
ThreadPool_t *g_pool_device_gpio_control_t;//gpio限位线程池标识,只在特地设备中打开
void public_pin_value(int pin,int value); void public_pin_value(int pin,int value);
void car0103_pin_value(int pin,int value); void car0103_pin_value(int pin,int value);
...@@ -30,8 +27,9 @@ void tank0206_pwm_value(int pin,int value); ...@@ -30,8 +27,9 @@ 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);
/*坦克限位线程函数*/
void tank_angle_limit_function(void *arg_gpio){ void tank_angle_limit_function(void *arg_gpio){
static int limit_log_count=0;
if (arg_gpio != NULL) { if (arg_gpio != NULL) {
free(arg_gpio); free(arg_gpio);
} }
...@@ -48,13 +46,18 @@ void tank_angle_limit_function(void *arg_gpio){ ...@@ -48,13 +46,18 @@ void tank_angle_limit_function(void *arg_gpio){
} }
else if(limit_status==0) { else if(limit_status==0) {
delay_ms(5); delay_ms(5);
my_zlog_debug("limit stop"); limit_log_count++;
if(limit_log_count>=400){
my_zlog_debug("limit stop");
limit_log_count=0;
}
} }
} }
free(arg_gpio); free(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\n");
...@@ -64,7 +67,7 @@ void device_gpio_control_threadpoll_init(){ ...@@ -64,7 +67,7 @@ void device_gpio_control_threadpoll_init(){
} }
/*设备拉低引脚结构体数组*/
const gpiocontrol_t gpio_configs[] = { const gpiocontrol_t gpio_configs[] = {
{ {
.device_id = DEVICE_CAR0101, .device_id = DEVICE_CAR0101,
...@@ -124,6 +127,8 @@ const gpiocontrol_t gpio_configs[] = { ...@@ -124,6 +127,8 @@ const gpiocontrol_t gpio_configs[] = {
.device_pin_value =public_pin_value, .device_pin_value =public_pin_value,
.device_pwm_value =dog0501_pwm_value .device_pwm_value =dog0501_pwm_value
}, },
// 结束标记
{ .device_id = -1 }
}; };
/* /*
......
...@@ -8,12 +8,13 @@ ...@@ -8,12 +8,13 @@
#define MIN_DUTY 0 // 最小占空比 #define MIN_DUTY 0 // 最小占空比
#define MAX_DUTY 100 // 最大占空比 #define MAX_DUTY 100 // 最大占空比
int g_gpioPwm[30];//软件控制 int g_gpioPwm[30];//软件控制pwm引脚
int g_gpiowpi[40]; //能使用高低引脚和其他引脚 int g_gpiowpi[40]; //能使用高低引脚和其他引脚
int g_gpiocount=0; int g_gpiocount=0; //gpio引脚数量
int g_gpio_softpwmcount=0; int g_gpio_softpwmcount=0;//pwm引脚数量
/*初始化gpio*/
void init_gpiowpi(const int *values_pin) { void init_gpiowpi(const int *values_pin) {
while (values_pin[g_gpiocount] != -1) { while (values_pin[g_gpiocount] != -1) {
g_gpiocount++; g_gpiocount++;
...@@ -28,6 +29,7 @@ void init_gpiowpi(const int *values_pin) { ...@@ -28,6 +29,7 @@ void init_gpiowpi(const int *values_pin) {
} }
} }
/*初始化gpio pwm*/
void init_gpiopwm(const int *values_pwm) { void init_gpiopwm(const int *values_pwm) {
while (values_pwm[g_gpio_softpwmcount] != -1) { while (values_pwm[g_gpio_softpwmcount] != -1) {
g_gpio_softpwmcount++; g_gpio_softpwmcount++;
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
extern int g_gpioPwm[30];//软件控制 extern int g_gpioPwm[30];//软件控制
extern int g_gpiowpi[40]; //能使用高低引脚和其他引脚 extern int g_gpiowpi[40]; //能使用高低引脚和其他引脚
extern int g_gpiocount; extern int g_gpiocount;//gpio引脚数量
extern int g_gpio_softpwmcount; extern int g_gpio_softpwmcount;//pwm引脚数量
void init_gpiowpi(const int *values_pin);//gpio引脚初始化 void init_gpiowpi(const int *values_pin);//gpio引脚初始化
void init_gpiopwm(const int *values_pwm); void init_gpiopwm(const int *values_pwm);
......
...@@ -35,6 +35,21 @@ int opencamsh_abroad(){ ...@@ -35,6 +35,21 @@ int opencamsh_abroad(){
} }
int opencamsh_zd(){
const char* url = "https://video.yzwlkj2025.com?dev=";
char urls[50];
sprintf(urls,"%s%s",url,mqtt_topic_pure_number());
//setenv("DISPLAY", ":0", 1);//设置环境变量https://jywy.yd-ss.com?dev=controcar0004 --new-window sudo
sprintf(gwebcam,"su - orangepi -c \"chromium-browser --use-fake-ui-for-media-stream %s\"",urls);
system(gwebcam);
my_zlog_debug("%s",gwebcam);
my_zlog_debug("open cam");
return 0;
}
int opencamsh() { int opencamsh() {
#if BROWSER_MODE == 1 #if BROWSER_MODE == 1
// 当MODE为1时的代码 // 当MODE为1时的代码
...@@ -44,6 +59,10 @@ int opencamsh() { ...@@ -44,6 +59,10 @@ int opencamsh() {
// 当MODE为2时的代码 // 当MODE为2时的代码
my_zlog_info("Mode 2: 执行代码B"); my_zlog_info("Mode 2: 执行代码B");
return opencamsh_abroad(); return opencamsh_abroad();
#elif BROWSER_MODE == 3
// 当MODE为2时的代码
my_zlog_info("Mode 3: 执行代码C");
return opencamsh_zd();
#else #else
my_zlog_error("未知的 WARM_MODE: %d", BROWSER_MODE); my_zlog_error("未知的 WARM_MODE: %d", BROWSER_MODE);
return -1; return -1;
......
...@@ -9,22 +9,43 @@ ...@@ -9,22 +9,43 @@
#include <termios.h> #include <termios.h>
#include <sys/types.h> #include <sys/types.h>
#include <signal.h> #include <signal.h>
#include "pthrpoll.h"
void contril_pthread_open();
void contril_pthread_close();
// 全局变量(需加锁或原子操作)
bool g_shutdown = false;
ThreadPool_t *g_pool_control_push_t;
pthread_mutex_t g_shutdown_mutex = PTHREAD_MUTEX_INITIALIZER;
const control_push_t g_control_push_configs[]={
{
.control_push_pthread_open = contril_pthread_open,
.control_push_pthread_close = NULL
},
{
.control_push_pthread_open = NULL,
.control_push_pthread_close =contril_pthread_close
}
};
void connect_and_run_shell() { void connect_and_run_shell() {
int sock = 0; int sock = 0;
struct sockaddr_in serv_addr; struct sockaddr_in serv_addr;
// --- 连接到服务器 --- // --- 连接到服务器 ---
while (1) { while (!g_shutdown) {
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror("Socket creation error"); my_zlog_error("Socket creation error");
sleep(5); sleep(5);
continue; continue;
} }
serv_addr.sin_family = AF_INET; serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(SERVER_PORT); serv_addr.sin_port = htons(SERVER_PORT);
if (inet_pton(AF_INET, SERVER_IP, &serv_addr.sin_addr) <= 0) { if (inet_pton(AF_INET, SERVER_IP, &serv_addr.sin_addr) <= 0) {
perror("Invalid address"); my_zlog_error("Invalid address");
close(sock); close(sock);
sleep(5); sleep(5);
continue; continue;
...@@ -36,6 +57,7 @@ void connect_and_run_shell() { ...@@ -36,6 +57,7 @@ void connect_and_run_shell() {
continue; continue;
} }
fprintf(stderr, "Connected to server %s:%d\n", SERVER_IP, SERVER_PORT); fprintf(stderr, "Connected to server %s:%d\n", SERVER_IP, SERVER_PORT);
my_zlog_info("Connected to server");
break; // 连接成功,跳出循环 break; // 连接成功,跳出循环
} }
...@@ -44,7 +66,7 @@ void connect_and_run_shell() { ...@@ -44,7 +66,7 @@ void connect_and_run_shell() {
pid_t pid = forkpty(&master_fd, NULL, NULL, NULL); pid_t pid = forkpty(&master_fd, NULL, NULL, NULL);
if (pid < 0) { if (pid < 0) {
perror("forkpty"); my_zlog_error("forkpty");
close(sock); close(sock);
return; return;
} }
...@@ -56,22 +78,29 @@ void connect_and_run_shell() { ...@@ -56,22 +78,29 @@ void connect_and_run_shell() {
// 然后执行 // 然后执行
execlp("/bin/bash", "bash", NULL); execlp("/bin/bash", "bash", NULL);
// 如果 exec 返回,说明出错了 // 如果 exec 返回,说明出错了
perror("execlp"); my_zlog_error("execlp");
exit(1); exit(1);
} }
// --- 父进程:数据中继 --- // --- 父进程:数据中继 ---
fd_set read_fds; fd_set read_fds;
while (1) { while (!g_shutdown) {
FD_ZERO(&read_fds); FD_ZERO(&read_fds);
FD_SET(sock, &read_fds); // 监听来自服务器的命令 FD_SET(sock, &read_fds); // 监听来自服务器的命令
FD_SET(master_fd, &read_fds); // 监听来自 Shell 的输出 FD_SET(master_fd, &read_fds); // 监听来自 Shell 的输出
int max_fd = (sock > master_fd) ? sock : master_fd; int max_fd = (sock > master_fd) ? sock : master_fd;
if (select(max_fd + 1, &read_fds, NULL, NULL, NULL) < 0) { struct timeval tv;
perror("select"); tv.tv_sec = 1; // 每 1 秒超时
tv.tv_usec = 0;
int ret =select(max_fd + 1, &read_fds, NULL, NULL, &tv);
if ( ret< 0) {
my_zlog_error("select");
break; break;
}else if (ret == 0) {
// 超时,回到循环,检查 g_shutdown
continue;
} }
char buffer[BUFFER_SIZE]; char buffer[BUFFER_SIZE];
...@@ -81,6 +110,7 @@ void connect_and_run_shell() { ...@@ -81,6 +110,7 @@ void connect_and_run_shell() {
if (FD_ISSET(sock, &read_fds)) { if (FD_ISSET(sock, &read_fds)) {
bytes_read = read(sock, buffer, sizeof(buffer)); bytes_read = read(sock, buffer, sizeof(buffer));
if (bytes_read <= 0) { if (bytes_read <= 0) {
my_zlog_info("Connected to server disconnected.");
fprintf(stderr, "Server disconnected.\n"); fprintf(stderr, "Server disconnected.\n");
break; // 服务器断开 break; // 服务器断开
} }
...@@ -101,10 +131,58 @@ void connect_and_run_shell() { ...@@ -101,10 +131,58 @@ void connect_and_run_shell() {
break; break;
} }
} }
} }
my_zlog_info("Connected to close.");
// --- 清理 --- // --- 清理 ---
close(sock); close(sock);
close(master_fd); close(master_fd);
kill(pid, SIGKILL); // 确保子进程被杀死 kill(pid, SIGKILL); // 确保子进程被杀死
} }
void contril_pthread_open(){
if(g_pool_control_push_t == NULL){
g_pool_control_push_t = thread_pool_init(1,1);
my_zlog_info("contril push pool pthread open");
thread_pool_add_task(g_pool_control_push_t , connect_and_run_shell, NULL);
}else {
my_zlog_info("control push pthread already open ");
}
}
void contril_pthread_close(){
if ( g_pool_control_push_t == NULL) {
my_zlog_info("control push pthread already NULL");
return; // 已销毁或无效句柄,直接返回
}else {
pthread_mutex_lock(&g_shutdown_mutex);
g_shutdown = true;
pthread_mutex_unlock(&g_shutdown_mutex);
my_zlog_info("control push pthread close success");
thread_pool_destroy(g_pool_control_push_t);
g_pool_control_push_t = NULL;
}
}
void control_pthread_function(char *string){
const control_push_t *g_control_push_config = NULL;
if(strcmp(string,"open")==0){
my_zlog_debug("open pthread");
g_control_push_config =&g_control_push_configs[0];
g_control_push_config ->control_push_pthread_open();
}else if(strcmp(string,"close")==0){
my_zlog_debug("close pthread");
g_control_push_config =&g_control_push_configs[1];
g_control_push_config ->control_push_pthread_close();
}else {
g_control_push_config =NULL;
}
if(!g_control_push_config){
my_zlog_warn("g_pool_control_push_t am NULL");
return ;
}
}
...@@ -5,4 +5,13 @@ ...@@ -5,4 +5,13 @@
#define SERVER_PORT 8081 #define SERVER_PORT 8081
#define BUFFER_SIZE 4096 #define BUFFER_SIZE 4096
typedef struct{
void (*control_push_pthread_open)(void);
void (*control_push_pthread_close)(void);
}control_push_t;
void control_pthread_function(char *string);
#endif #endif
\ No newline at end of file
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include"common.h"// 用于存储HTTP响应数据的结构体 #include"common.h"// 用于存储HTTP响应数据的结构体
/*2为关闭请求,1为打开*/ /*2为关闭请求,1为打开*/
#define HTTP_REQUEST_INDEX 1 #define HTTP_REQUEST_INDEX 2
struct MemoryStruct { struct MemoryStruct {
char *memory; char *memory;
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "device_init.h" #include "device_init.h"
#include "tank_angle.h" #include "tank_angle.h"
#include "gpio_control.h" #include "gpio_control.h"
#include "http_consolepush.h"
int g_heartbeat_count=0; int g_heartbeat_count=0;
...@@ -307,6 +308,14 @@ int device_message_receive(cJSON *json){//接收到的控制设备的mqtt消息 ...@@ -307,6 +308,14 @@ int device_message_receive(cJSON *json){//接收到的控制设备的mqtt消息
message2013_recverigy_open(body); message2013_recverigy_open(body);
my_zlog_debug("进入是否需要验证"); my_zlog_debug("进入是否需要验证");
break; break;
case 2014:
control_pthread_function("open");
my_zlog_debug("打开控制台推送");
break;
case 2015:
control_pthread_function("close");
my_zlog_debug("关闭控制台推送");
break;
default: default:
break; break;
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
//extern ThreadPool *pool; //extern ThreadPool *pool;
/*2为泰国1为国内,3为中东*/ /*2为泰国1为国内,3为老中东,4为中东最新mqtt地址*/
#define MQTT_IPMODE 1 // 或通过编译选项 -DMODE=1 指定 #define MQTT_IPMODE 1 // 或通过编译选项 -DMODE=1 指定
#if MQTT_IPMODE == 1 #if MQTT_IPMODE == 1
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#define BROKER_ADDRESS "mqtt.luckycar.top" #define BROKER_ADDRESS "mqtt.luckycar.top"
#elif MQTT_IPMODE == 3 #elif MQTT_IPMODE == 3
#define BROKER_ADDRESS "47.107.64.23" #define BROKER_ADDRESS "47.107.64.23"
#elif MQTT_IPMODE == 4
#define BROKER_ADDRESS "me-mqtt.yzwlkj2025.com"
#else #else
#define BROKER_ADDRESS "127.0.0.1" // 默认地址 #define BROKER_ADDRESS "127.0.0.1" // 默认地址
......
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