Commit 279aa042 authored by 957dd's avatar 957dd

修改了不发bug,找后端要验证失败会重复要验证

parent e3206a35
......@@ -58,7 +58,7 @@ target_compile_definitions(main PRIVATE
PROJECT_ROOT_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
)
# Release模式下定义LOG_PRODUCTION宏,编译时剔除debug和info日志
# Release模式下定义LOG_PRODUCTION宏,编译时剔除debug日志(info及以上保留)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
target_compile_definitions(main PRIVATE LOG_PRODUCTION)
endif()
......
......@@ -184,7 +184,7 @@ int connect_wifi_with_fallback(const char* ssid, const char* password, const cha
int change_wifi_connect(const char *wifi_ssid,const char *wifi_password) {
get_current_wifi();
int ret = connect_wifi_with_fallback(wifi_ssid, wifi_password, g_current_ssid);
my_zlog_notice("返回代码:%d", ret);
my_zlog_info("WiFi连接返回代码:%d", ret);
return ret;
}
......
......@@ -94,7 +94,7 @@ void *thread_mqtt_beat(void *arg)
// }
if (verify_open_index_init() != 0)
{
my_zlog_info("mqtt send verify is NULL");
my_zlog_warn("mqtt send verify is NULL");
}
// 如果为相关的不需要心跳或者游览器设备,提早结束线程
......@@ -108,6 +108,8 @@ void *thread_mqtt_beat(void *arg)
{
delay_ms(100);
verify_open_query_poll();
g_heartbeat_count++;
set_tank_angle_count(); // 角度发布计时,1开始计时,0清0
if (s_mqtt_grc == 0)
......@@ -116,7 +118,7 @@ void *thread_mqtt_beat(void *arg)
if (get_device_self_control_configuration_initialization() == 0)
{
my_zlog_warn("自控配置初始化成功");
my_zlog_info("自控配置初始化成功");
}
}
}
......@@ -241,7 +243,7 @@ void *thread_mqtt_reconnect(void *arg)
remqtt_index = mqtt_init();
if (remqtt_index == 0)
{
my_zlog_warn("mqtt success", remqtt_index);
my_zlog_info("mqtt success");
break;
}
else
......
No preview for this file type
......@@ -301,7 +301,7 @@ void ptz_driver_change(int *buf)
return;
}
my_zlog_info("PTZ(%d) CMD: %d", s_cfg->device_id, buf[1]);
my_zlog_debug("PTZ(%d) CMD: %d", s_cfg->device_id, buf[1]);
switch (buf[1]) {
case 1:
......
......@@ -108,7 +108,7 @@ int tankshot_detection_backcount(int *cool_time,int flag){
pthread_mutex_lock(&s_tankshot_detection_mutex);
if(flag==0){
cool_count_init=*cool_time;
my_zlog_info("cool_count_init的值:%d",cool_count_init);
my_zlog_debug("cool_count_init的值:%d",cool_count_init);
}
else if(flag==1){
cool_count++;
......@@ -121,7 +121,7 @@ int tankshot_detection_backcount(int *cool_time,int flag){
}else if(flag==3){
cool_count=0;
s_tankshot_detectionback_count=0;
my_zlog_info("冷却计时重置");
my_zlog_debug("冷却计时重置");
}else if(flag==4){
s_tankshot_detectionback_count=0;
}
......@@ -139,7 +139,7 @@ static void tankshot_detectionback(){
g_device_delay_back_count=0;
softPwmWrite(27, 0);
set_backshotstatus(false);
my_zlog_info("检测引脚12拉低");
my_zlog_debug("检测引脚12拉低");
}
}
......
This diff is collapsed.
......@@ -318,7 +318,7 @@ void receive_self_contorl_mqtt(cJSON *body){
send_self_contorl_mqtt();
my_zlog_info("count:%d",s_self_device_control_data->id_run_count);
my_zlog_debug("count:%d",s_self_device_control_data->id_run_count);
return;
}
......@@ -369,8 +369,8 @@ void receive_self_contorl_date_mqtt(cJSON *body){
s_automatic_data[s_action_id].action_count++;
my_zlog_info("combination:%d",s_automatic_data[s_action_id].mode[j]);
my_zlog_info("speed:%d",s_automatic_data[s_action_id].val[j]);
my_zlog_debug("combination:%d",s_automatic_data[s_action_id].mode[j]);
my_zlog_debug("speed:%d",s_automatic_data[s_action_id].val[j]);
}
}
......@@ -383,7 +383,7 @@ void receive_self_contorl_date_mqtt(cJSON *body){
memset(s_automatic_data[s_action_id].val, 0, sizeof(s_automatic_data[s_action_id].val));
}
my_zlog_info("action_count:%d",s_automatic_data[s_action_id].action_count);
my_zlog_debug("action_count:%d",s_automatic_data[s_action_id].action_count);
return;
......
......@@ -154,7 +154,7 @@ void refresh_cam(void)
if (now < s_refresh_next_allowed) {
long left = (long)(s_refresh_next_allowed - now);
pthread_mutex_unlock(&s_refresh_cool_mutex);
my_zlog_notice("refresh_cam skipped: cooldown %lds remaining (max once per %ds)",
my_zlog_debug("refresh_cam skipped: cooldown %lds remaining (max once per %ds)",
left, REFRESH_CAM_COOLDOWN_SEC);
return;
}
......
......@@ -229,6 +229,7 @@ void my_zlog_debug(const char *format, ...) {
va_end(args);
}
}
#endif
void my_zlog_info(const char *format, ...) {
if (s_zlog_c) {
......@@ -238,7 +239,6 @@ void my_zlog_info(const char *format, ...) {
va_end(args);
}
}
#endif
void my_zlog_notice(const char *format, ...) {
if (s_zlog_c) {
......
......@@ -6,12 +6,12 @@ int mylog_init();
#ifdef LOG_PRODUCTION
#define my_zlog_debug(...) ((void)0)
#define my_zlog_info(...) ((void)0)
#else
void my_zlog_debug(const char *format, ...) ;
void my_zlog_info(const char *format, ...) ;
#endif
void my_zlog_info(const char *format, ...) ;
void my_zlog_notice(const char *format, ...) ;
void my_zlog_warn(const char *format, ...) ;
void my_zlog_error(const char *format, ...) ;
......
......@@ -253,7 +253,7 @@ void message_4_judyverify(cJSON *body)
if (VERIFIED_MODE == FALSE)
{
message_4(body);
my_zlog_info("不使用验证");
my_zlog_warn("不使用验证");
return;
}
......@@ -274,7 +274,7 @@ void message_6_steering_judyverify(cJSON *body)
if (VERIFIED_MODE == FALSE)
{
steering_mqtt_recv(body);
my_zlog_info("不使用验证");
my_zlog_warn("不使用验证");
return;
}
......@@ -301,7 +301,7 @@ void message_7_joystick_judyverify(cJSON *body)
if (VERIFIED_MODE == FALSE)
{
ptz_driver_set_joystick_json(joystick_ctrl);
my_zlog_info("不使用验证");
my_zlog_warn("不使用验证");
return;
}
......@@ -325,8 +325,8 @@ int device_mqttchange_name(cJSON *device_id)
char *device_change_date = date->valuestring;
device_changename_back(device_change_date, device_change_id);
// 输出提取的数据
my_zlog_debug("设备ID: %s", device_change_id);
my_zlog_debug("日期: %s", device_change_date);
my_zlog_info("设备ID: %s", device_change_id);
my_zlog_info("日期: %s", device_change_date);
return 0;
}
......@@ -371,7 +371,7 @@ int device_message_receive(cJSON *json)
case 5:
audio_wheat_init();
audio_speaker_init();
my_zlog_debug("执行麦和喇叭命令");
my_zlog_info("执行麦和喇叭命令");
break;
case 6:
message_6_steering_judyverify(body);
......@@ -383,64 +383,64 @@ int device_message_receive(cJSON *json)
break;
case 2001:
audioplay_mqtt_receive(body);
my_zlog_debug("进入音频播放");
my_zlog_info("进入音频播放");
break;
case 2002:
device_mqttchange_name(body);
my_zlog_debug("进入修改设备号");
my_zlog_info("进入修改设备号");
break;
case 2003:
scan_wifi_json();
my_zlog_debug("进入查询WiFi");
my_zlog_info("进入查询WiFi");
break;
case 2004:
// wifi_change_recmqtt(body);
my_zlog_debug("进入修改WiFi");
my_zlog_info("进入修改WiFi");
break;
case 2006:
message2006_verify(body);
my_zlog_debug("进入消息为2006验证");
my_zlog_info("进入消息为2006验证");
break;
case 2007:
device_send_saved_wifi();
my_zlog_debug("查询已保存wifi和现在已连接WiFi");
my_zlog_info("查询已保存wifi和现在已连接WiFi");
break;
case 2008:
device_wifi_rec_sava(body);
my_zlog_debug("保存wifi");
my_zlog_info("保存wifi");
break;
case 2009:
device_wifi_rec_delete(body);
my_zlog_debug("删除已保存wifi");
my_zlog_info("删除已保存wifi");
break;
case 2011:
int res = system("sudo reboot"); // 重启香橙派
if (res == 0)
my_zlog_debug("重启成功");
my_zlog_info("重启成功");
break;
case 2012:
refresh_cam();
my_zlog_debug("刷新成功");
my_zlog_info("刷新成功");
break;
case 2013:
message2013_recverigy_open(body);
my_zlog_debug("进入是否需要验证");
my_zlog_info("进入是否需要验证");
break;
case 2014:
control_pthread_function("open");
my_zlog_debug("打开控制台推送");
my_zlog_info("打开控制台推送");
break;
case 2015:
control_pthread_function("close");
my_zlog_debug("关闭控制台推送");
my_zlog_info("关闭控制台推送");
break;
case 2016:
mqtt_verify_data_clear(body);
my_zlog_debug("清除验证数据");
my_zlog_info("清除验证数据");
break;
case 2025:
receive_self_contorl_mqtt(body);
my_zlog_debug("device self comtrol");
my_zlog_info("device self comtrol");
break;
case 2026:
receive_self_contorl_date_mqtt(body);
......
......@@ -137,7 +137,7 @@ void on_message(struct mosquitto *mosq, void *obj, const struct mosquitto_messag
// 解析 JSON
cJSON *json = cJSON_Parse(payload_str);
if(json != NULL){
if(device_message_receive(json)==0) my_zlog_info("进入设备接收mqtt");
if(device_message_receive(json)==0) my_zlog_debug("进入设备接收mqtt");
}
// 释放 payload 字符串
......@@ -239,7 +239,7 @@ void mqtt_clean(){
}
mosquitto_lib_cleanup();
my_zlog_notice("清理成功");
my_zlog_info("清理成功");
}
int mqtt_cycle() {//非阻塞型
......
......@@ -33,6 +33,15 @@ static time_t s_verify_retry_after_time = 0; /* 允许发起重试的时间戳
#define VERIFY_RETRY_MAX 3
#define VERIFY_RETRY_INTERVAL_SEC 1
/* 启动时向后端查询是否开启验证(3013/2013) */
#define VERIFY_OPEN_QUERY_MAX 3
#define VERIFY_OPEN_QUERY_INTERVAL_SEC 3
static bool s_verify_open_got_reply = false; /* 已收到后端2013 */
static bool s_verify_open_query_gave_up = false; /* 3次未收到,已放弃 */
static int s_verify_open_send_count = 0; /* 已发送3013次数 */
static time_t s_verify_open_last_send_time = 0;
int g_verify_index =0;//判断是否验证成功
pthread_mutex_t g_verify_mutex = PTHREAD_MUTEX_INITIALIZER;//线程锁
......@@ -120,7 +129,7 @@ int receive_jwt(cJSON *body) {
&& s_verify_retry_after_time > 0 && time(NULL) >= s_verify_retry_after_time) {
s_verify_retry_after_time = 0;
send_jwtser(s_pending_verify_token);
my_zlog_notice("距上次失败已过%d秒,发起第%d次重试验证, token=%s",
my_zlog_info("距上次失败已过%d秒,发起第%d次重试验证, token=%s",
VERIFY_RETRY_INTERVAL_SEC, s_verify_retry_count + 1, s_pending_verify_token);
}
......@@ -141,7 +150,7 @@ int receive_jwt(cJSON *body) {
pthread_mutex_lock(&g_verify_mutex);
g_verify_count = 0;
pthread_mutex_unlock(&g_verify_mutex);
my_zlog_notice("首次token,发起验证, token=%s", token);
my_zlog_info("首次token,发起验证, token=%s", token);
} else if (strcmp(token, s_last_seen_token) != 0) {
strncpy(s_last_seen_token, token, sizeof(s_last_seen_token) - 1);
s_last_seen_token[sizeof(s_last_seen_token) - 1] = '\0';
......@@ -154,9 +163,9 @@ int receive_jwt(cJSON *body) {
pthread_mutex_lock(&g_verify_mutex);
g_verify_count = 0;
pthread_mutex_unlock(&g_verify_mutex);
my_zlog_notice("token变化,发起验证, token=%s", token);
my_zlog_info("token变化,发起验证, token=%s", token);
} else {
my_zlog_info("token未变化");
my_zlog_debug("token未变化");
}
......@@ -175,7 +184,7 @@ int receive_jwt(cJSON *body) {
my_zlog_debug("g_verify_index= %d ",g_verify_index);
if(g_verify_count>12000){
send_jwtser(token);
my_zlog_notice("JWT超过1分钟触发重新验证, token=%s", token);
my_zlog_debug("JWT超过1分钟触发重新验证, token=%s", token);
pthread_mutex_lock(&g_verify_mutex);
g_verify_count=0;
pthread_mutex_unlock(&g_verify_mutex);
......@@ -187,8 +196,8 @@ int receive_jwt(cJSON *body) {
my_zlog_debug("g_verify_index= %d ",g_verify_index);
}
my_zlog_info("token: %s", token);
my_zlog_info("token_time: %s", token_time);
my_zlog_debug("token: %s", token);
my_zlog_debug("token_time: %s", token_time);
return 0;
}
......@@ -203,7 +212,7 @@ int message2006_verify(cJSON *body){
if(json_status == NULL || json_onlyid==NULL) {
my_zlog_debug("验证为空");
my_zlog_warn("验证为空");
s_service_verify = FALSE;
g_verify_index=1;
my_zlog_debug("g_verify_index= %d ",g_verify_index);
......@@ -215,7 +224,7 @@ int message2006_verify(cJSON *body){
my_zlog_debug("data: %s", status);
my_zlog_debug("onlyid: %s", onlyid);
if(strcmp(onlyid,s_only_id_middle) == 0 && strcmp(status, "1") == 0){
my_zlog_debug("获得验证正确");
my_zlog_info("获得验证正确, onlyid=%s", onlyid);
s_service_verify = TRUE;
g_verify_index = 0; /* 后端通过后必须清除失败标志,否则正确 token 仍会提示验证不通过 */
strcpy(s_secret_key, s_pending_verify_token);
......@@ -237,7 +246,7 @@ int message2006_verify(cJSON *body){
return 2;
}
} else {
my_zlog_debug("获得验证错误,禁止使用");
my_zlog_warn("获得验证错误,禁止使用, onlyid=%s status=%s", onlyid, status);
g_verify_index = 1;
s_service_verify = FALSE;
return 2;
......@@ -251,17 +260,20 @@ int message2006_verify(cJSON *body){
int message2013_recverigy_open(cJSON *body){
cJSON *verifty_open_index = cJSON_GetObjectItem(body, "verify_status");
if(verifty_open_index == NULL){
my_zlog_debug("接收验证是否打开为空");
my_zlog_warn("接收验证是否打开为空");
return -1;
}
int verifty_open = verifty_open_index->valueint;
my_zlog_debug("verifty:%d",verifty_open);
s_verify_open_got_reply = true;
s_verify_open_query_gave_up = false;
if(verifty_open == 0){
VERIFIED_MODE=FALSE;
my_zlog_debug("verify close");
my_zlog_info("关闭验证, verify_status=%d", verifty_open);
}else {
VERIFIED_MODE=TRUE;
my_zlog_debug("verify open");
my_zlog_info("开启验证, verify_status=%d", verifty_open);
}
return 0;
}
......@@ -287,7 +299,7 @@ int message_sendopen_verify(){
return -1;
}
my_zlog_debug("%s",payload);
my_zlog_debug("发送验证查询: %s", payload);
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(payload), payload, 0, false);
......@@ -300,13 +312,46 @@ int message_sendopen_verify(){
}
static int verify_open_query_send_once(void) {
if (message_sendopen_verify() != 0) {
return -1;
}
s_verify_open_send_count++;
s_verify_open_last_send_time = time(NULL);
my_zlog_info("发送验证开关查询(3013), 第%d/%d次", s_verify_open_send_count, VERIFY_OPEN_QUERY_MAX);
return 0;
}
/*发送是否打开验证的mqtt给后端验证初始化*/
int verify_open_index_init(){
if(message_sendopen_verify()!=0){
return -1;
s_verify_open_got_reply = false;
s_verify_open_query_gave_up = false;
s_verify_open_send_count = 0;
s_verify_open_last_send_time = 0;
return verify_open_query_send_once();
}
void verify_open_query_poll(void) {
if (s_verify_open_got_reply || s_verify_open_query_gave_up) {
return;
}
if (s_verify_open_last_send_time == 0) {
return;
}
return 0;
time_t now = time(NULL);
if (now - s_verify_open_last_send_time < VERIFY_OPEN_QUERY_INTERVAL_SEC) {
return;
}
if (s_verify_open_send_count >= VERIFY_OPEN_QUERY_MAX) {
my_zlog_warn("验证开关查询(3013)已发送%d次仍未收到后端2013回复,停止重试", VERIFY_OPEN_QUERY_MAX);
s_verify_open_query_gave_up = true;
return;
}
verify_open_query_send_once();
}
int mqtt_verify_clear_send(char *status){
......@@ -366,7 +411,7 @@ void mqtt_verify_data_clear(cJSON *body){
mqtt_verify_clear_send("0");
}
} else {
my_zlog_info("verify_clear_item 字段不存在或不是字符串类型");
my_zlog_warn("verify_clear_item 字段不存在或不是字符串类型");
mqtt_verify_clear_send("2");
}
}
......
......@@ -21,8 +21,11 @@ int message2006_verify(cJSON *body);
/*接收到是否打开验证的函数*/
int message2013_recverigy_open(cJSON *body);
/*发送是否打开验证的mqtt给后端验证初始化*/
/*发送是否打开验证的mqtt给后端验证初始化(首次发送3013)*/
int verify_open_index_init();
/* 心跳线程轮询:未收到2013则按间隔重试,最多3次 */
void verify_open_query_poll(void);
void mqtt_verify_data_clear(cJSON *body);
#endif
\ No newline at end of file
......@@ -9,4 +9,4 @@ file perms = 600
millisecond = "%d(%Y-%m-%d %H:%M:%S).%ms [%V] %m%n"
[rules]
my_log.* "/home/orangepi/car/master/log/log_2026-05-08.log"; millisecond
my_log.* "/home/orangepi/car/master/log/log_2026-05-22.log"; millisecond
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