Selaa lähdekoodia

修改不是自己的数据不回ack

wanghechen 8 kuukautta sitten
vanhempi
commit
798c509632

+ 42 - 42
components/Decection/Decection.c

@@ -202,54 +202,54 @@ int decection_state_1(void)
     return 0; // gpio_get_level(38);
 }
 
-#include "freertos/FreeRTOS.h"
-#include "freertos/task.h"
-#include "freertos/queue.h"
-#include "SPIFFS.h"
-extern RTC_FAST_ATTR Machine_info_t Machine_info;
-static void IRAM_ATTR gpio_isr_handler(void *arg)
-{
-    uint32_t gpio_num = (uint32_t)arg;
-    switch (gpio_num)
-    {
+// #include "freertos/FreeRTOS.h"
+// #include "freertos/task.h"
+// #include "freertos/queue.h"
+// #include "SPIFFS.h"
+// extern RTC_FAST_ATTR Machine_info_t Machine_info;
+// static void IRAM_ATTR gpio_isr_handler(void *arg)
+// {
+//     uint32_t gpio_num = (uint32_t)arg;
+//     switch (gpio_num)
+//     {
 
-    case 2:
+//     case 2:
 
-        // beep_blink(100,3);
-        // printf("----------------gpio_num%ld中断------------------------\r\n",gpio_num);
-        break;
+//         // beep_blink(100,3);
+//         // printf("----------------gpio_num%ld中断------------------------\r\n",gpio_num);
+//         break;
 
-    case 38:
+//     case 38:
 
-        // beep_blink(100,4);//rintf("----------------gpio_num%ld中断------------------------\r\n",gpio_num);
-        break;
+//         // beep_blink(100,4);//rintf("----------------gpio_num%ld中断------------------------\r\n",gpio_num);
+//         break;
 
-    default:
-        break;
-    }
-}
+//     default:
+//         break;
+//     }
+// }
 
-void decection_charging_init(void)
-{
-    // zero-initialize the config structure.
-    gpio_config_t io_conf = {};
-    // interrupt of rising edge
-    io_conf.intr_type = GPIO_INTR_NEGEDGE; // 下降沿
-    // bit mask of the pins
-    io_conf.pin_bit_mask = ((1ULL << 2) | (1ULL << 38));
-    // set as input mode
-    io_conf.mode = GPIO_MODE_INPUT;
-    io_conf.pull_up_en = GPIO_PULLUP_DISABLE;     // 禁用上拉电阻
-    io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE; // 禁用下拉电阻
-    // configure GPIO with the given settings
-    gpio_config(&io_conf);
-
-    ESP_LOGW(TAG, "decection_charging_init");
-    // install gpio isr service
-    gpio_install_isr_service(ESP_INTR_FLAG_EDGE);
-    gpio_isr_handler_add(2, gpio_isr_handler, (void *)2);
-    gpio_isr_handler_add(38, gpio_isr_handler, (void *)38);
-}
+// void decection_charging_init(void)
+// {
+//     // zero-initialize the config structure.
+//     gpio_config_t io_conf = {};
+//     // interrupt of rising edge
+//     io_conf.intr_type = GPIO_INTR_NEGEDGE; // 下降沿
+//     // bit mask of the pins
+//     io_conf.pin_bit_mask = ((1ULL << 2) | (1ULL << 38));
+//     // set as input mode
+//     io_conf.mode = GPIO_MODE_INPUT;
+//     io_conf.pull_up_en = GPIO_PULLUP_DISABLE;     // 禁用上拉电阻
+//     io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE; // 禁用下拉电阻
+//     // configure GPIO with the given settings
+//     gpio_config(&io_conf);
+
+//     ESP_LOGW(TAG, "decection_charging_init");
+//     // install gpio isr service
+//     gpio_install_isr_service(ESP_INTR_FLAG_EDGE);
+//     gpio_isr_handler_add(2, gpio_isr_handler, (void *)2);
+//     gpio_isr_handler_add(38, gpio_isr_handler, (void *)38);
+// }
 // void decection_charging_deinit(void)
 // {
 //     gpio_isr_handler_remove(2);

+ 2 - 2
components/Decection/include/Decection.h

@@ -12,8 +12,8 @@ int read_battery_voltage();
 
 int decection_state_0(void);
 int decection_state_1(void);
-void decection_charging_init(void);
-void decection_charging_deinit(void);
+// void decection_charging_init(void);
+// void decection_charging_deinit(void);
 
 int adc_read_left_key_pin(adc_oneshot_unit_handle_t adc_handle);
 #endif/*_DETECTION_H_*/

+ 42 - 26
components/EPD/EPD.c

@@ -12,7 +12,7 @@
 #include "esp_timer.h"
 
 bool is_epd_ok = false;
-
+bool is_epd_ok_cplt = false;
 #include "../../main/user_sleep.h"
 #include "esp_sleep.h"
 
@@ -47,8 +47,19 @@ DRAM_ATTR static const epd_init_cmd_t init_cmds[] = {
 static void spi_pre_transfer_callback(spi_transaction_t *t)
 {
     int dc = (int)t->user;
-    gpio_set_level(PIN_L_DC, dc);
-    gpio_set_level(PIN_R_DC, dc);
+    if (dc == 0)
+    {
+        gpio_set_level(PIN_L_DC, 0);
+        gpio_set_level(PIN_R_DC, 0);
+    }
+    else if (dc == 1)
+    {
+        gpio_set_level(PIN_L_DC, 1);
+    }
+    else if (dc == 2)
+    {
+        gpio_set_level(PIN_R_DC, 1);
+    }
 }
 
 #if 0
@@ -287,11 +298,11 @@ void epd_init_cmd(screen_t screen)
         }
     }
 }
-esp_err_t user_spi_get_result(spi_device_handle_t spi)
-{
-    spi_transaction_t *rtrans = NULL;
-    return spi_device_get_trans_result(spi, &rtrans, 10000);
-}
+// esp_err_t user_spi_get_result(spi_device_handle_t spi)
+// {
+//     spi_transaction_t *rtrans = NULL;
+//     return spi_device_get_trans_result(spi, &rtrans, 10000);
+// }
 static void spi_get_result(spi_device_handle_t spi)
 {
     spi_transaction_t *rtrans = NULL;
@@ -304,7 +315,7 @@ static void spi_get_result(spi_device_handle_t spi)
     }
     else
     {
-        printf("->%s\n", esp_err_to_name(ret));
+        printf("err:spi_get_result------->%s\n", esp_err_to_name(ret));
         is_epd_ok = false;
     }
 
@@ -334,41 +345,46 @@ void epd_cmd(spi_device_handle_t spi, const uint8_t cmd, bool keep_cs_active)
 #endif
 }
 
-void epd_data(spi_device_handle_t spi, const uint8_t *data, int len)
+static void epd_data(screen_t screen, spi_device_handle_t spi, const uint8_t *data, int len)
 {
 #if !SOFTWARE_SPI_ENABLE
     esp_err_t ret;
     spi_transaction_t t;
-    int i;
+
     if (len == 0)
         return; // no need to send anything
     if (len > SPI_MAX_LEN)
     {
+        is_epd_ok_cplt = false;
+        int i;
         for (i = 0; i < len; i = i + SPI_MAX_LEN)
         {
-            memset(&t, 0, sizeof(t));                             // Zero out the transaction
-            t.length = SPI_MAX_LEN * 8;                           // Len is in bytes, transaction length is in bits.
-            t.tx_buffer = data + i;                               // Data
-            t.user = (void *)1;                                   // D/C needs to be set to 1
+            memset(&t, 0, sizeof(t));                                  // Zero out the transaction
+            t.length = SPI_MAX_LEN * 8;                                // Len is in bytes, transaction length is in bits.
+            t.tx_buffer = data + i;                                    // Data
+            t.user = (void *)screen;                                   // D/C needs to be set to 1
             ret = user_spi_device_queue_trans(spi, &t, portMAX_DELAY); // Transmit!
             // assert(ret==ESP_OK);            //Should have had no issues.
             spi_get_result(spi);
+            // printf("-next-%d\n",len);
         }
         i -= SPI_MAX_LEN;
-        memset(&t, 0, sizeof(t));                             // Zero out the transaction
-        t.length = (len - i) * 8;                             // Len is in bytes, transaction length is in bits.
-        t.tx_buffer = data + i;                               // Data
-        t.user = (void *)1;                                   // D/C needs to be set to 1
+        memset(&t, 0, sizeof(t));                                  // Zero out the transaction
+        t.length = (len - i) * 8;                                  // Len is in bytes, transaction length is in bits.
+        t.tx_buffer = data + i;                                    // Data
+        t.user = (void *)screen;                                   // D/C needs to be set to 1
         ret = user_spi_device_queue_trans(spi, &t, portMAX_DELAY); // Transmit!
-        assert(ret == ESP_OK);                                // Should have had no issues.
+        assert(ret == ESP_OK);                                     // Should have had no issues.
         spi_get_result(spi);
+        is_epd_ok_cplt = true;
+        // printf("-next2--%d\n", len);
         return;
     }
 
-    memset(&t, 0, sizeof(t));                             // Zero out the transaction
-    t.length = len * 8;                                   // Len is in bytes, transaction length is in bits.
-    t.tx_buffer = data;                                   // Data
-    t.user = (void *)1;                                   // D/C needs to be set to 1
+    memset(&t, 0, sizeof(t));                                  // Zero out the transaction
+    t.length = len * 8;                                        // Len is in bytes, transaction length is in bits.
+    t.tx_buffer = data;                                        // Data
+    t.user = (void *)screen;                                   // D/C needs to be set to 1
     ret = user_spi_device_queue_trans(spi, &t, portMAX_DELAY); // Transmit!
     // assert(ret==ESP_OK);            //Should have had no issues.
     if (ret != ESP_OK)
@@ -424,7 +440,7 @@ void epd_write_data(screen_t screen, const uint8_t *data, int len)
         gpio_set_level(PIN_L_CS, 0);
 
         gpio_set_level(PIN_L_DC, 1);
-        epd_data(epd_spi, data, len);
+        epd_data(screen, epd_spi, data, len);
         gpio_set_level(PIN_L_CS, 1);
     }
     else if (screen == SCREEN_RIGHT)
@@ -433,7 +449,7 @@ void epd_write_data(screen_t screen, const uint8_t *data, int len)
         gpio_set_level(PIN_R_CS, 0);
 
         gpio_set_level(PIN_R_DC, 1);
-        epd_data(epd_spi, data, len);
+        epd_data(screen, epd_spi, data, len);
         gpio_set_level(PIN_R_CS, 1);
     }
     else

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

@@ -101,7 +101,7 @@ void deepsleep_epd_powerOn_refresh_sleep(screen_t screen);
 bool epd_cache_quick(screen_t screen,const unsigned char* old,const unsigned char* new);
 void epd_powerOn_refresh_sleep(screen_t screen);
 
-esp_err_t user_spi_get_result(spi_device_handle_t spi);
+// esp_err_t user_spi_get_result(spi_device_handle_t spi);
 
 #else /*HARDWARE_SPI*/
 

+ 1 - 1
components/USER_SPIFFS/include/SPIFFS.h

@@ -81,7 +81,7 @@ typedef struct
     uint8_t power_status;  // 当前系统的状态  开机或者关机
     // uint8_t is_setting;      //设置当前是否为设置模式
 
-    Node *Send_list;
+    // Node *Send_list;
     uint16_t msg_id; // 添加消息发送设备ID 唯一性分配
 
     Button_Time_t last_button;    // 上次按键状态

+ 6 - 5
main/ulp_riscv_adc_example_main.c

@@ -90,12 +90,13 @@ static void light_sleep_task(void *args)
     extern bool is_adv;
     int bat_times = 0;
     extern bool is_epd_ok;
+    extern bool is_epd_ok_cplt;
     int lev_2 = 0;
     while (true)
     {
-        if (is_key_press() || !is_epd_ok)
+        if (is_key_press() || !is_epd_ok|| !is_epd_ok_cplt)
         {
-            ESP_LOGI(LOG_TAG,"is_key_press() || !is_epd_ok");
+            ESP_LOGI(LOG_TAG,"is_key_press() || !is_epd_ok|| !is_epd_ok_cplt");
             vTaskDelay(1000 / portTICK_PERIOD_MS);
             continue; 
         }
@@ -399,8 +400,8 @@ static void light_sleep_task(void *args)
                 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.wait_send_rssi_bat > 60) // 30分钟唤醒一次->(30*60/TIMER_WAKEUP_TIME_S) = 60
+                // if (Machine_info.wait_send_rssi_bat>10)
                 {
                     ESP_LOGE(LOG_TAG, "-> 30minite send lora info");
                     Machine_info.wait_send_rssi_bat = 0;
@@ -408,7 +409,7 @@ static void light_sleep_task(void *args)
                     f_send_get_chart_data();
                     // f_send_lora_rssi(Machine_info.rssi);
                     f_send_battary_vaule(Machine_info.batt_precent);
-                    f_send_get_time();
+                    // f_send_get_time();
                 }
 
                 if ((Machine_info.last_button.Minute != Machine_info.min) /*||(Machine_info.last_button.Hour != Machine_info.Hour)*/) //

+ 3 - 6
main/user_sleep.c

@@ -69,8 +69,7 @@ extern void light_sleep_task(void *args);
 extern void wakeup_sleep_task(void *args);
 
 bool is_sleep = false;
-extern void set_screen_dis_info_and_send_queue(bool is_into_sleep,bool is_left,bool is_change_power,bool is_dont_dis,bool sleep_ms);
-
+extern void set_screen_dis_info_and_send_queue(bool is_into_sleep, bool is_left, bool is_change_power, bool is_dont_dis, bool sleep_ms);
 
 /*********************************************************************************
  * function   :   sleep_timer_callback
@@ -122,7 +121,7 @@ void sleep_timer_start(int ms)
 
     xTimerStart(sleep_timer, 0); // 开始定时器
     // xTimerStart(sleep_Timerout, 0);
-    ESP_LOGI(LOG_TAG, "#############%s##############reset   sleep_timer [%d]",is_sleep?"true":"false" ,ms);
+    ESP_LOGI(LOG_TAG, "#############%s##############reset   sleep_timer [%d]", is_sleep ? "true" : "false", ms);
 #else
 
 #if 0
@@ -194,7 +193,7 @@ void Already_send_timer_callback(void *arg)
     // printf("sleep time = %d\r\n",(TIMER_WAKEUP_TIME_US*Machine_info.eflagID)/1000);
 
 #if 1
-    set_screen_dis_info_and_send_queue(true,false,false,true,100);
+    set_screen_dis_info_and_send_queue(true, false, false, true, 100);
 #endif
 
 #else
@@ -398,7 +397,6 @@ void user_sleep_into()
     ESP_ERROR_CHECK(esp_timer_create(&send_timer_args, &already_send_timer));
 #else
 
-
     // 创建
     sleep_timer = xTimerCreate(
         "sleep_timer",       // 定时器名称(可以为NULL)
@@ -417,7 +415,6 @@ void user_sleep_into()
         Already_send_timer_callback // 定时器回调函数
     );
 
-
 #endif
 
 #endif

+ 2 - 2
main/yc_paint.c

@@ -771,9 +771,9 @@ static uint8_t *partial_right2_quick(void)
     memset((uint8_t *)tmp_paint_buf, 0, DISPLAY_BUFFER_SIZE /*sizeof(tmp_paint_buf)*/);
     Paint_NewImage((UBYTE *)tmp_paint_buf, 480, RIGHT2_HIGHT, ROTATE_0, WHITE);
 
-    ESP_LOGI(LOG_TAG, "paint Charge_close %d %d %d %d %d", Machine_info.person[0].Charge_close, Machine_info.person[1].Charge_close, Machine_info.person[2].Charge_close,
+    ESP_LOGD(LOG_TAG, "paint Charge_close %d %d %d %d %d", Machine_info.person[0].Charge_close, Machine_info.person[1].Charge_close, Machine_info.person[2].Charge_close,
              Machine_info.person[3].Charge_close, Machine_info.person[4].Charge_close);
-    ESP_LOGI(LOG_TAG, "责任人人数 [%d][%d][%d][%d][%d]", person_get_num(0), person_get_num(1), person_get_num(2), person_get_num(3), person_get_num(4)); // 获取当前类型人员数量
+    ESP_LOGD(LOG_TAG, "责任人人数 [%d][%d][%d][%d][%d]", person_get_num(0), person_get_num(1), person_get_num(2), person_get_num(3), person_get_num(4)); // 获取当前类型人员数量
 
     // 管理员不会关闭
     memset((uint8_t *)buffer, 0, sizeof(buffer));

+ 30 - 146
main/yc_protocol.c

@@ -21,7 +21,7 @@
 #include "SPIFFS.h"
 // #include "user_config.h"
 
-Screen_dis_t screen_dis_info;
+RTC_NOINIT_ATTR Screen_dis_t screen_dis_info;
 // 声明一个TimerHandle_t类型的变量,用于存储定时器句柄
 
 extern EventGroupHandle_t screen_event;
@@ -160,6 +160,7 @@ void f_send_status_duration(void);
 
 void set_screen_dis_info_and_send_queue(bool is_into_sleep, bool is_left, bool is_change_power, bool is_dont_dis, int ms)
 {
+    ESP_LOGE(LOG_TAG, "%d %d %d %d %d ",is_into_sleep,is_left,is_change_power,is_dont_dis,ms);
     screen_dis_info.is_into_sleep = is_into_sleep;
     screen_dis_info.is_left = is_left;
     screen_dis_info.is_change_power = is_change_power;
@@ -226,7 +227,7 @@ void screen_display(void)
     if (bits == 3)
     {
         // xQueueReset(screen_queue);
-        Machine_info.left_current_Quick_refresh_time = 5; // 刷两个屏最好为慢刷
+        Machine_info.left_current_Quick_refresh_time = 4; // 刷两个屏最好不同时慢刷
         set_screen_dis_info_and_send_queue(false, true, false, false, 100);
         set_screen_dis_info_and_send_queue(true, false, false, false, 100);
     }
@@ -414,8 +415,8 @@ static int terminal_number_func(const LORA_DATA_T *buf)
     //     printf("%02x ",Machine_info.terminal_number[i]);
     // }
 
-    printf("setting num %s", Machine_info.terminal_number);
-    printf("\n");
+    // printf("setting num %s", Machine_info.terminal_number);
+    // printf("\n");
 
     // display_flag = RIGHT_FLAG;
     xEventGroupSetBits(screen_event, RIGHT_SCREEN_BIT);
@@ -617,7 +618,7 @@ static int production_punch_func(const LORA_DATA_T *buf)
         Machine_info.checkIn_set[terminal_info.production_punch[0]].checkIn_close = false; // 开启该类型打卡
     }
 
-    ESP_LOGW(LOG_TAG, "打卡设置: 类型[%d]  %s", terminal_info.production_punch[0], terminal_info.production_punch[1] ? "开启" : "关闭");
+    ESP_LOGD(LOG_TAG, "打卡设置: 类型[%d]  %s", terminal_info.production_punch[0], terminal_info.production_punch[1] ? "开启" : "关闭");
 
     if (len > 2) // 数据长度大于2 ,说明设置了别名
     {
@@ -647,7 +648,7 @@ static int personnel_check_in_func(const LORA_DATA_T *buf)
     xEventGroupSetBits(screen_event, LEFT_SCREEN_BIT);
     ESP_LOG_BUFFER_HEX(LOG_TAG, terminal_info.personnel_check_in, len);
     int ID_crc = crc8(&terminal_info.personnel_check_in[2], len - 2, 0x5a, 0x51); // lora_crc8( , ,0x5a,0x51);暂定对人员id求crc
-    ESP_LOGW(LOG_TAG, "打卡类型[%d] %s ,ID_crc = %d", terminal_info.personnel_check_in[0], Machine_info.checkIn_set[terminal_info.personnel_check_in[0]].checkIn_close ? "关闭" : "开启", ID_crc);
+    ESP_LOGD(LOG_TAG, "打卡类型[%d] %s ,ID_crc = %d", terminal_info.personnel_check_in[0], Machine_info.checkIn_set[terminal_info.personnel_check_in[0]].checkIn_close ? "关闭" : "开启", ID_crc);
     if (!(Machine_info.checkIn_set[terminal_info.personnel_check_in[0]].checkIn_close)) // 开启打卡
     {
         if (terminal_info.personnel_check_in[1] == 0x00) // 打卡签入
@@ -1118,7 +1119,7 @@ int reply_ack_func(int cmd, int msg_id, bool is_send, uint8_t *result)
 
     if (is_send)
     {
-
+        ESP_LOG_BUFFER_HEX("send ack to gateway", strlorabuf, 15);
         lora_send_data((char *)strlorabuf, 15);
         uart_wait_tx_idle_polling(UART_NUM_1);
     }
@@ -1352,10 +1353,12 @@ static void hardware_gwpair_func(const LORA_DATA_T *buf)
     f_send_get_chart_data();
 #endif
 
-#if USER_LIGHT_SLEEP_ENABLE || USER_DEEP_SLEEP_ENABLE
-    set_screen_dis_info_and_send_queue(false, true, false, true, 100);
-#endif
-
+    // xQueueReset(screen_queue);
+    // 重置快刷
+    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);
+    set_screen_dis_info_and_send_queue(true, false, false, false, 100);
     // printf("start timer id = %d,%d\r\n",Machine_info.eflagID,Machine_info.eflagID * TIMER_CAN_SEND_TIME);
     // Already_send_timer_start(Machine_info.eflagID * TIMER_CAN_SEND_TIME);
 }
@@ -1468,7 +1471,7 @@ static void hardware_ack_delete_msg_id(const LORA_DATA_T *buf)
 
     if (find != NULL)
     {
-        ESP_LOGE(LOG_TAG, "find  %d", msg_id);
+        ESP_LOGE(LOG_TAG, "find  msg_id : %d", msg_id);
         // printList(Send_list);
 
         for (int i = 0; i < LORA_INFO_END; i++)
@@ -1619,12 +1622,7 @@ void business_logic_func(const LORA_DATA_T *buf, uint8_t cmd_index, int msg)
         hardware_gwpair_func(buf);
         // Paint_leftScreen_main_quick(&Machine_info);
         // Paint_rightScreen_main_quick(&Machine_info);
-        // xQueueReset(screen_queue);
-        // 重置快刷
-        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);
-        set_screen_dis_info_and_send_queue(false, false, false, false, 100);
+
         break;
 
     case PROTOCOL_HARDWARE_UNGWPAIRED: // 取消配网
@@ -1958,7 +1956,6 @@ bool subcontract(YC_DATA_T *data)
     USE_DATA_T use_data;
 
     bool refresh_flag = false;
-#if 1
 
     u8 targetSequence[] = {0x5A, 0x51};
     int sequenceSize = sizeof(targetSequence);
@@ -1966,13 +1963,6 @@ bool subcontract(YC_DATA_T *data)
     int *positions = NULL;
     int result = findByteSequence(buf, all_len, targetSequence, sequenceSize, &positions);
 
-    if (result > 1)
-    {
-        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);
-    }
-
     if (result == 1)
     {
         printf("cmd 5A 51 find times %d,data len = %d\r\n", result, data->len);
@@ -2016,33 +2006,32 @@ bool subcontract(YC_DATA_T *data)
                     // 多条指令处理逻辑
 
                     bool is = mac_is_true(&buf[positions[index] + 3]);
-                    if (is)
+                    if (is) // 验证为本机,处理数据 回复ack
                     {
                         use_data.data_len = (((buf[positions[index] - 2]) << 8) | ((buf[positions[index] - 1]))) + 2;
                         memcpy(use_data.data_buf, data->data + (positions[index] - 2), use_data.data_len);
                         // print_yc_data(&use_data);
                         business_logic_func(&use_data, USE_CMD_LEN_INDEX, rsp_msgid);
                         refresh_flag = true;
+
+                        reply_ack_func(0x00, rsp_msgid, true, NULL); // 回复ack
+                        spiffs_write(&Machine_info);
+                        ESP_LOGE(LOG_TAG, "1times  cmd = %02X  msg = %X start reply ack\r\n", 0x00, rsp_msgid);
                     }
                     else
                     {
                         printf("mac is fail not deal\r\n");
                     }
                 }
-
-                // if(is_rsp_ack)
-                {
-                    reply_ack_func(0x00, rsp_msgid, true, NULL); // 回复ack
-                    spiffs_write(&Machine_info);
-                    ESP_LOGE(LOG_TAG, "1times  cmd = %02X  msg = %X start reply ack\r\n", 0x00, rsp_msgid);
-                }
             }
         }
     }
 
     if (result > 1)
     {
-
+        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);
         printf("not single cmd len =%d\r\n", use_data.data_len);
 
         rsp_msgid = (buf[13] << 8) | buf[14]; // 获取当前消息id 用于删除;
@@ -2072,97 +2061,18 @@ bool subcontract(YC_DATA_T *data)
                 //  print_yc_data(&use_data);
                 business_logic_func(&use_data, USE_CMD_LEN_INDEX, rsp_msgid);
                 refresh_flag = true;
+
+                reply_ack_func(0x00, rsp_msgid, true, NULL); // 回复ack
+                spiffs_write(&Machine_info);
+                ESP_LOGE(LOG_TAG, "cmd = %02X  msg = %X start reply ack\r\n", 0x00, rsp_msgid);
             }
             else
             {
                 printf("mac is fail not deal\r\n");
             }
         }
-        // if(is_rsp_ack)
-        {
-            reply_ack_func(0x00, rsp_msgid, true, NULL); // 回复ack
-            spiffs_write(&Machine_info);
-            ESP_LOGE(LOG_TAG, "cmd = %02X  msg = %X start reply ack\r\n", 0x00, rsp_msgid);
-        }
-    }
-
-#if 0
-    u8 targetSequence1[] = {0x55, 0x51};
-    int sequenceSize1 = sizeof(targetSequence);
-
-    int* positions1 = NULL;
-     result = findByteSequence(buf, all_len, targetSequence1, sequenceSize1, &positions1);
-
-    if(result!=0)
-    {
-        printf("ack 55 51 find time %d\r\n", result);
     }
-
-      for(int index = 0;index<result;index++)
-    {
-        //use_data.data_len =(((buf[positions[index] - 2])<<8) | ((buf[positions[index] - 1])))+2;
-        //memcpy(use_data.data_buf,data->data + (positions[index] -2) ,use_data.data_len);
-        //print_yc_data(&use_data);
-        use_data.data_len = all_len;
-        memcpy(use_data.data_buf,data->data + (positions1[index]) ,use_data.data_len);
-        business_ack_func(&use_data);
-        //refresh_flag =true;
-    }
-#endif
-
-    // #if 1
-
-    //       for (int i = 0; i < all_len; i++)
-    //         {
-    //             printf("%02x",buf[i]);
-    //         }
-
-    // #endif
-
     free(positions);
-
-// free(positions1);
-#if 0
-    printf("index:");
-    if (result > 0) {
-        //printf("出现的位置索引:");
-        for (int i = 0; i < result; i++) {
-            printf("%d,", positions[i]);
-        }
-        printf("\n");
-       
-    }
-#endif
-
-#else
-    while (all_len > 0)
-    {
-        // ESP_LOGW(LOG_TAG,"-->[%d]",all_len);
-        // for(int i=0;i<all_len;i++)
-        // {
-        //     printf("%02x ",data->data[i]);
-        // }
-        // printf("\n");
-        if (((buf[index + 2]) == 0x5A) && ((buf[index + 3]) == 0x51))
-        {
-            use_data.data_len = (((buf[index]) << 8) | ((buf[index + 1]))) + 2;
-            memcpy(use_data.data_buf, data->data + index, use_data.data_len);
-            all_len -= (use_data.data_len);
-            index += (use_data.data_len);
-            // print_yc_data(&use_data);
-            business_logic_func(&use_data);
-            refresh_flag = true;
-        }
-        else
-        {
-            all_len--;
-            index++;
-            // ESP_LOGE(LOG_TAG,"err:data");
-            // break;
-        }
-    }
-#endif
-
     return refresh_flag;
 }
 
@@ -2841,7 +2751,7 @@ void f_send_status_duration(void)
     for (i = 3; i < 27; i++)
         crc16 = crc16 + strlorabuf[i];
     strlorabuf[2] = crc16 & 0xff;
-    // ESP_LOGE(LOG_TAG,"{cmd:0e}send_status_duration btn -->[%d] -->Duration_time = %ld -->time :%d %d %d %d %d %d %d",strlorabuf[15],Machine_info.Duration_time,strlorabuf[16],strlorabuf[17],strlorabuf[18],strlorabuf[19],strlorabuf[20],strlorabuf[21],strlorabuf[22]);
+    ESP_LOGE(LOG_TAG,"{cmd:0e}send_status_duration btn -->[%d] -->Duration_time = %ld -->time :%d %d %d %d %d %d %d",strlorabuf[15],Machine_info.Duration_time,strlorabuf[16],strlorabuf[17],strlorabuf[18],strlorabuf[19],strlorabuf[20],strlorabuf[21],strlorabuf[22]);
 
     changebintotxt(strlorabuf, 27);
 
@@ -2873,30 +2783,6 @@ void f_send_update_status(void)
     {
         return;
     }
-#if 0
-    uint8_t* update = (uint8_t*)malloc(sizeof(uint8_t)*(12));
-    memset(&new_button_info,0,sizeof(Button_Time_t));
-    new_button_info.Year = Machine_info.year;
-    new_button_info.Month = Machine_info.month;
-    new_button_info.Day = Machine_info.day;
-    new_button_info.Hour = Machine_info.hour;
-    new_button_info.Minute = Machine_info.min;
-    new_button_info.Second = Machine_info.sec;
-    new_button_info.time_min = 0;
-
-
-    memcpy(update,&last_button_info.button_info,1);
-    memcpy(update+1,&new_button_info.Year,2);
-    memcpy(update+3,&new_button_info.Month,1);
-    memcpy(update+4,&new_button_info.Day,1);
-    memcpy(update+5,&new_button_info.Hour,1);
-    memcpy(update+6,&new_button_info.Minute,1);
-    memcpy(update+7,&new_button_info.Second,1);
-    memcpy(update+8,&new_button_info.time_min,4);
-
-    protocol_package(0x0F,update,12);
-    free(update);
-#else
 
     // memset(&Machine_info.current_button,0,sizeof(Button_Time_t));
 
@@ -2969,7 +2855,7 @@ void f_send_update_status(void)
     strlorabuf[25] = (Machine_info.current_button.time_min >> 8) & 0xff;
     strlorabuf[26] = Machine_info.current_button.time_min & 0xff;
     strlorabuf[27] = 0;
-    // ESP_LOGE(LOG_TAG,"@@send_update_status -->btn = [%d] -->time :%d %d %d %d %d %d %d",strlorabuf[15],strlorabuf[16],strlorabuf[17],strlorabuf[18],strlorabuf[19],strlorabuf[20],strlorabuf[21],strlorabuf[22]);
+    ESP_LOGE(LOG_TAG,"@@send_update_status -->btn = [%d] -->time :%d %d %d %d %d %d %d",strlorabuf[15],strlorabuf[16],strlorabuf[17],strlorabuf[18],strlorabuf[19],strlorabuf[20],strlorabuf[21],strlorabuf[22]);
 
     crc16 = strlorabuf[0] + strlorabuf[1];
     for (i = 3; i < 27; i++)
@@ -2993,8 +2879,6 @@ void f_send_update_status(void)
 #endif
 
     Machine_info.last_button.time_min = 0;
-
-#endif
 }
 
 // void send_ACK(char cmd, bool flag)

+ 15 - 17
main/yc_terminal.c

@@ -829,22 +829,17 @@ if(tmp_paint_buf!=NULL)
 }
 static void screen_task(void *arg)
 {
-    Machine_info.rssi = 100;        // 没有获取到真数据,默认100
+    // Machine_info.rssi = 100;        // 没有获取到真数据,默认100
     int reson = is_wake_up_reson(); // 返回唤醒的原因
     ESP_LOGW(LOG_TAG, "screen_task  %d", reson);
     if ((reson != ESP_SLEEP_WAKEUP_ULP) && (reson != ESP_SLEEP_WAKEUP_TIMER) && (reson != ESP_SLEEP_WAKEUP_EXT0))
     {
-        // Paint_leftScreen_main_powerOn();
-        // Paint_rightScreen_main_powerON();
         Paint_leftScreen(Machine_info.power_status, false);
         Paint_rightScreen(Machine_info.power_status, false);
     }
     else if (reson == ESP_SLEEP_WAKEUP_EXT0)
     {
-        // 按键从深睡唤醒,开机刷新屏慕
         ESP_LOGW(LOG_TAG, "按键从深睡唤醒,开机刷新屏慕");
-        //  Paint_leftScreen_main_slow(&Machine_info);
-        //  Paint_rightScreen_main_slow(&Machine_info);
         Paint_leftScreen(Machine_info.power_status, false);
         Paint_rightScreen(Machine_info.power_status, false);
     }
@@ -868,6 +863,11 @@ static void screen_task(void *arg)
 
             if (screen_rev_info.is_left) // 刷左屏
             {
+                if (screen_rev_info.is_change_power)
+                {
+                    ESP_LOGE(LOG_TAG, "=============power_status %s========  set power off", Machine_info.power_status ? "is power on" : "is power off");
+                    Machine_info.power_status = 0; // 关机
+                }
                 if (Machine_info.left_current_Quick_refresh_time >= Machine_info.left_max_Quick_refresh_time)
                 {
                     Machine_info.left_current_Quick_refresh_time = 0;
@@ -893,15 +893,14 @@ static void screen_task(void *arg)
             }
         dont_dis:
             // ESP_LOGE(LOG_TAG, "%d %d %d", Machine_info.power_status, Machine_info.paired, screen_rev_info.is_into_sleep);
-            if ((Machine_info.power_status == 1) && (Machine_info.paired == 1) && screen_rev_info.is_into_sleep)
+
+            if ((Machine_info.power_status == 1) /*&& (Machine_info.paired == 1) */ && screen_rev_info.is_into_sleep)
             {
-                ESP_LOGD(LOG_TAG, "100ms sleep  %s", screen_rev_info.is_left ? "left" : "right");
-                if (screen_rev_info.is_change_power)
-                {
-                    ESP_LOGE(LOG_TAG, "=============power_status %s========  set power off", Machine_info.power_status ? "is power on" : "is power off");
-                    Machine_info.power_status = 0; // 关机
-                }
-                sleep_timer_start(screen_rev_info.sleep_ms); // 进入睡眠
+                ESP_LOGW(LOG_TAG, "%dms sleep  %s", screen_rev_info.sleep_ms, screen_rev_info.is_left ? "left" : "right");
+                if (screen_rev_info.sleep_ms == 1)
+                    sleep_timer_start(100); // 进入睡眠
+                else
+                    sleep_timer_start(screen_rev_info.sleep_ms); // 进入睡眠
             }
 
             if (Machine_info.power_status == 0) // 展示说明书都是先左后右,等右屏刷完再休眠
@@ -949,7 +948,6 @@ static void button_task(void *arg)
                     if ((Machine_info.power_status == 1) && (Machine_info.paired == 1))
                     {
                         set_screen_dis_info_and_send_queue(false, false, false, true, 100);
-                        // sleep_timer_start(100); // 进入睡眠
                     }
                 }
                 Machine_info.current_button.button_info = button_info;
@@ -1065,8 +1063,8 @@ static void button_task(void *arg)
                         // Machine_info.power_status = 0;
                         // screen_dis_info.is_change_power = true;
                         xQueueReset(screen_queue);
-                        set_screen_dis_info_and_send_queue(false, true, false, false, 100);
-                        set_screen_dis_info_and_send_queue(true, false, true, false, 1000); // 关机
+                        set_screen_dis_info_and_send_queue(false, true, true, false, 100);// 关机
+                        set_screen_dis_info_and_send_queue(true, false, false, false, 1000); 
                         printf("poweron->poweroff\r\n");
                     }
                     else if (Machine_info.power_status == 0)