Procházet zdrojové kódy

配网恢复不刷屏

wanghechen před 8 měsíci
rodič
revize
6018e08ff2

+ 8 - 9
components/LORA/LORA.c

@@ -36,7 +36,7 @@ uart_status_t lora_uart_status = uart_idle;
 // 声明一个TimerHandle_t类型的变量,用于存储定时器句柄
 TimerHandle_t lora_uart_Timerout;
 
-bool is_change_chanel = false;
+bool is_change_chanel_ok = true;
 
 static const char *LOG_TAG = "LORA";
 
@@ -267,11 +267,6 @@ void lora_init_cmd_handler(unsigned char *data, void *param)
       lora.lora_mode = Lora_UART_Mode;
       gpio_set_level(LORA_SET_PIN, 1);
 
-      // if(is_change_chanel == true)
-      // {
-      //     is_change_chanel = false;
-      // }
-      // uart_set_baudrate(LORA_UART,115200);
       printf("lora at all cmd init ok \r\n");
 
 #if 0
@@ -471,6 +466,7 @@ void lora_set_dst_device_id(uint32_t id)
 
 uint8_t set_lora(uint8_t new_channel, uint8_t eflag)
 {
+  is_change_chanel_ok = false;
   uint8_t ret = 0;
   uint8_t data[50] = {0};
   int user_size = 0;
@@ -589,6 +585,7 @@ uint8_t set_lora(uint8_t new_channel, uint8_t eflag)
   }
   lora.lora_mode = Lora_UART_Mode;
   gpio_set_level(LORA_SET_PIN, 1);
+  is_change_chanel_ok = true;
   return ret;
 }
 
@@ -642,7 +639,7 @@ void print_lora(void)
 }
 void reset_lora(uint8_t new_channel)
 {
-
+  is_change_chanel_ok = false;
   gpio_set_level(LORA_SET_PIN, 0);
   // for(int index = 0;index<sizeof(lora_cmd)/sizeof(lora_cmd[0]);index++)
   {
@@ -774,7 +771,7 @@ void reset_lora(uint8_t new_channel)
 
     lora.lora_mode = Lora_UART_Mode;
     gpio_set_level(LORA_SET_PIN, 1);
-
+    is_change_chanel_ok = true;
     // free(data);
   }
 }
@@ -2137,6 +2134,8 @@ void timer_wake_uart_sleep_out_config()
 
 void lora_init(void)
 {
+  ESP_LOGW(LOG_TAG,"before lora_init");
+  vTaskDelay(1000 / portTICK_PERIOD_MS);
 #if !USER_QIXIN
 // lora_uart_pin_init();
 // //lora_get_cfg();
@@ -2368,7 +2367,7 @@ uint8_t cmd[4]={0};
 
           if ((reson != ESP_SLEEP_WAKEUP_ULP) && (reson != ESP_SLEEP_WAKEUP_TIMER))
           {
-            vTaskDelay(2000 / portTICK_PERIOD_MS);
+            vTaskDelay(1000 / portTICK_PERIOD_MS);
           }
 
 #endif

+ 1 - 1
components/LORA/include/LORA.h

@@ -241,7 +241,7 @@ void uart_sleep_in_config();
 void uart_sleep_out_config();
 void timer_wake_uart_sleep_out_config();
 
-
+extern bool is_change_chanel_ok;
 void lora_factory_config();
 void reset_lora(uint8_t new_channel);
 uint8_t set_lora(uint8_t new_channel,uint8_t eflag);

+ 2 - 2
components/button/user_button.c

@@ -451,11 +451,11 @@ static void power_single_press_cb(void *arg, void *usr_data)
         return;
     }
     is_down = true;
-    ESP_LOGE(LOG_TAG, "is_down true\n");
+    // ESP_LOGE(LOG_TAG, "is_down true\n");
     switch ((int)usr_data)
     {
     case 0:
-        ESP_LOGW(LOG_TAG, "power sigle press\r\n");
+        // ESP_LOGW(LOG_TAG, "power sigle press\r\n");
 
         // if (Machine_info.power_status == 1) // 开机
         // {

+ 32 - 35
main/ulp_riscv_adc_example_main.c

@@ -94,9 +94,9 @@ static void light_sleep_task(void *args)
     int lev_2 = 0;
     while (true)
     {
-        if (is_key_press() || !is_epd_ok || !is_epd_ok_cplt)
+        if (is_key_press() || !is_epd_ok || !is_epd_ok_cplt|| !is_change_chanel_ok)
         {
-            ESP_LOGI(LOG_TAG, "%d %d %d not sleep 1s continue", is_key_press(), !is_epd_ok, !is_epd_ok_cplt);
+            ESP_LOGI(LOG_TAG, "%d %d %d %dnot sleep 1s continue", is_key_press(), !is_epd_ok, !is_epd_ok_cplt,!is_change_chanel_ok);
             vTaskDelay(1000 / portTICK_PERIOD_MS);
             continue;
         }
@@ -176,7 +176,7 @@ static void light_sleep_task(void *args)
                 uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
                 iot_button_stop();
                 adc_oneshot_del_unit(adc1_handle);
-                vTaskDelay(100 / portTICK_PERIOD_MS);
+                // vTaskDelay(100 / portTICK_PERIOD_MS);
                 is_first_run = false;
                 esp_deep_sleep_start();
                 // }
@@ -255,7 +255,7 @@ static void light_sleep_task(void *args)
                     ESP_LOGW(LOG_TAG, "-> sleep\r\n");
                     uart_wait_tx_idle_polling(1);                           // 抛出剩余串口1消息
                     uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM); // 抛出剩余串口0消息
-                    vTaskDelay(100 / portTICK_PERIOD_MS);
+                    // vTaskDelay(100 / portTICK_PERIOD_MS);
                     is_first_run = false;
                     esp_light_sleep_start();
                 }
@@ -302,45 +302,42 @@ static void light_sleep_task(void *args)
                 Machine_info.wait_send_rssi_bat++;
                 printf("weakup: bat %d wait_send_rssi_bat = %d,\r\n", Machine_info.batt_precent, Machine_info.wait_send_rssi_bat);
 
-                // 打印待发数据
-                printList(Send_list);
-
-                // if(Machine_info.wait_send_rssi_bat>(30*60/TIMER_WAKEUP_TIME_S))//30分钟发一次lora
-                if (Machine_info.wait_send_rssi_bat > 60) // 30分钟唤醒一次->(30*60/TIMER_WAKEUP_TIME_S) = 60
-                // if (Machine_info.wait_send_rssi_bat>10)
+                if (Machine_info.paired == 1)
                 {
-                    ESP_LOGE(LOG_TAG, "-> 30minite send lora info");
-                    Machine_info.wait_send_rssi_bat = 0;
-                    // f_send_test();
-                    f_send_get_chart_data();
-                    // f_send_lora_rssi(Machine_info.rssi);
-                    f_send_battary_vaule(Machine_info.batt_precent);
-                    f_send_get_time();
-                }
 
-                if ((Machine_info.last_button.Minute != Machine_info.min) /*||(Machine_info.last_button.Hour != Machine_info.Hour)*/) //
-                {
-                    if (is_sync_time(&Machine_info)) // 同步到时间
+                    printList(Send_list); // 打印待发数据
+
+                    // if(Machine_info.wait_send_rssi_bat>(30*60/TIMER_WAKEUP_TIME_S))//30分钟发一次lora
+                    if (Machine_info.wait_send_rssi_bat > 60) // 30分钟唤醒一次->(30*60/TIMER_WAKEUP_TIME_S) = 60
+                    // if (Machine_info.wait_send_rssi_bat>10)
                     {
-                        ESP_LOGW(LOG_TAG, "update left value min %d,last min %d\r\n", Machine_info.min, Machine_info.last_button.Minute);
-                        Machine_info.last_button.time_min += (Machine_info.min - Machine_info.last_button.Minute);
+                        ESP_LOGE(LOG_TAG, "-> 30minite send lora info");
+                        Machine_info.wait_send_rssi_bat = 0;
+                        // f_send_test();
+                        f_send_get_time();
+                        f_send_get_chart_data();
+                        // f_send_lora_rssi(Machine_info.rssi);
+                        f_send_battary_vaule(Machine_info.batt_precent);
                     }
-                    else
+
+                    if ((Machine_info.last_button.Minute != Machine_info.min) /*||(Machine_info.last_button.Hour != Machine_info.Hour)*/) //
                     {
-                        printf("time not sync\r\n");
+                        if (is_sync_time(&Machine_info)) // 同步到时间
+                        {
+                            ESP_LOGW(LOG_TAG, "update left value min %d,last min %d\r\n", Machine_info.min, Machine_info.last_button.Minute);
+                            Machine_info.last_button.time_min += (Machine_info.min - Machine_info.last_button.Minute);
+                        }
+                        else
+                        {
+                            printf("time not sync\r\n");
+                        }
                     }
-                }
-
-                // printf("wake reason: %s, slept for %lld ms\n",
-                // wakeup_reason,(sleep_afterr_us - sleep_before_us) / 1000);
-                printf("start timer id = %d,%d\r\n", Machine_info.eflagID, Machine_info.eflagID * TIMER_CAN_SEND_TIME);
 
-                // Machine_info.eflagID = 0x01;
-                // Already_send_timer_stop();
-                Already_send_timer_start(LORA_POWER_TIME + (Machine_info.eflagID * TIMER_CAN_SEND_TIME));
+                    printf("start timer id = %d,%d\r\n", Machine_info.eflagID, Machine_info.eflagID * TIMER_CAN_SEND_TIME);
 
-                // Already_send_timer_start(LORA_POWER_TIME +2000);
-                // sleep_timer_start(700);  //进入睡眠
+                    // Already_send_timer_stop();
+                    Already_send_timer_start(LORA_POWER_TIME + (Machine_info.eflagID * TIMER_CAN_SEND_TIME));
+                }
                 is_first_run = true;
             }
 

+ 12 - 2
main/yc_protocol.c

@@ -1175,7 +1175,11 @@ int reply_gwpair_ack_func(uint8_t *cid, uint8_t cid_len, uint8_t *result)
 /*硬件配网*/
 static void hardware_gwpair_func(const LORA_DATA_T *buf)
 {
-
+    if (buf->data_len != 35)
+    {
+        ESP_LOGE(LOG_TAG, "err:hardware_gwpair_func");
+        return;
+    }
     uint8_t child_mac[6] = {0};   // 子设备的mac地址
     uint8_t gateway_mac[6] = {0}; // 网关的组内编号
     int child_num = 0;
@@ -1342,6 +1346,7 @@ static void hardware_gwpair_func(const LORA_DATA_T *buf)
 
     vTaskDelay(200 / portTICK_PERIOD_MS);
     Machine_info.rssi = set_lora(Machine_info.lora_new_channel, Machine_info.eflagID);
+    f_send_get_time();
     f_send_version();
     f_send_reply_status(0x01); // 回复在线状态
     f_send_update_status();
@@ -1355,7 +1360,7 @@ static void hardware_gwpair_func(const LORA_DATA_T *buf)
     // 重置快刷
     extern bool is_paired_sleep;
     is_paired_sleep = true;
-     ESP_LOGW(LOG_TAG,"3is_paired_sleep = true");
+    ESP_LOGW(LOG_TAG, "3is_paired_sleep = true");
     Machine_info.left_current_Quick_refresh_time = 0;
     Machine_info.right_current_Quick_refresh_time = 0;
     set_screen_dis_info_and_send_queue(false, true, false, false, 100);
@@ -2032,6 +2037,11 @@ bool subcontract(YC_DATA_T *data)
 
     if (result > 1)
     {
+        if ((buf[0] == 0x5a) && (buf[1] == 0x51))
+        {
+            printf("result = 1,but not real\r\n");
+            goto err;
+        }
         int data_len = 0;
         data_len = (buf[0] << 8) | (buf[1]);
         printf("cmd 5A 51 find times %d,all data len = %d\r\n", result, data_len);

+ 4 - 4
main/yc_terminal.c

@@ -907,7 +907,7 @@ static void screen_task(void *arg)
                 ESP_LOGW(LOG_TAG, "now is power off");
                 sleep_timer_start(1000); // 进入睡眠
             }
-            ESP_LOGW(LOG_TAG, "screen task over");
+            // ESP_LOGW(LOG_TAG, "screen task over");
         }
     }
 }
@@ -1108,13 +1108,14 @@ static void button_task(void *arg)
 
                 if (button_info == POWER_ON_INTO_RESET_VALUE) // 进入配网模式
                 {
-                    beep_blink(2000, 1);
+                    is_change_chanel_ok = false;
+
                     printf("into reset mode\r\n");
 
                     font_exit_sleep();
                     lora_set_power_level(1);
                     uart_sleep_out_config();
-
+                    beep_blink(2000, 1);
                     extern void sleep_timer_stop();
                     extern void Already_send_timer_stop();
 
@@ -1124,7 +1125,6 @@ static void button_task(void *arg)
                     vTaskDelay(300 / portTICK_PERIOD_MS);
                     reset_default(true, 1);
                     reset_lora(LORA_CHANENL);
-                    vTaskDelay(300 / portTICK_PERIOD_MS);
                 }
             }
         }