1.蓝牙连接灯效
authord15521469561 <1731678236@qq.com>
Fri, 22 May 2026 10:47:14 +0000 (18:47 +0800)
committerd15521469561 <1731678236@qq.com>
Fri, 22 May 2026 10:47:14 +0000 (18:47 +0800)
2.按键恢复出厂设置
3.模组升级主控功能

14 files changed:
.gitignore
App/inc/iap.h
App/inc/io.h
App/inc/iot.h
App/inc/led.h
App/inc/uart6.h
App/src/base.c
App/src/flash.c
App/src/iap.c
App/src/io.c
App/src/iot.c
App/src/led.c
App/src/uart6.c
RVMDK/RVMDKN32G45X/project_cfg.h

index a72520c..44fbfa1 100644 (file)
@@ -69,18 +69,18 @@ Thumbs.db
 ehthumbs.db
 Desktop.ini
 
-.ini
-.lst
-.iex
-.axf
-.hex
-.htm
-.lnp
-.dep
-.jscope
-..d
-.crf
-.sct
+*.ini
+*.lst
+*.iex
+*.axf
+*.hex
+*.htm
+*.lnp
+*.dep
+*.jscope
+*.d
+*.crf
+*.sct
 
 # User-specific configuration files
 *.user
index e57f699..45b7d60 100644 (file)
@@ -19,6 +19,7 @@
 #define CMD1_IAP_CHIP5                                 0xB6
 #define CMD1_IAP_IOT                                   0xB7
 
+
 #define CMD2_IAP_FETCH                                 0x00
 #define CMD2_IAP_CERTIFICATE                   0x01
 #define CMD2_IAP_ERASE                         0x02
@@ -226,9 +227,9 @@ typedef union _IAP_UART_CMD
 typedef struct
 {
        uint8_t move_enable;
-       uint8_t type; // 1:App0µ½App1   1:App2µ½App0   1:App1µ½App0
+       uint8_t type; // 1:App0µ½App1   2:App2µ½App0   3:App1µ½App0
        uint32_t crc32;
-       uint8_t move_time;
+       uint8_t move_time; // ÀۼưáÔË´ÎÊý£¬ÓÃÓÚʧ°ÜÖØÊÔ
 }IAP_MOVE_T;
 
 typedef struct
@@ -239,6 +240,79 @@ typedef struct
        uint16_t build_version;
 }IAP_APP_PARTITION_INFO_T;
 
+/***************************************** IAP LITE *****************************************/
+typedef enum
+{
+       IAP_LITE_CMD_READY = 0,
+       IAP_LITE_CMD_ERASE,
+       IAP_LITE_CMD_WRITE,
+       IAP_LITE_CMD_WRITE_DONE,
+       IAP_LITE_CMD_CRC,
+       IAP_LITE_CMD_MOVE,
+       IAP_LITE_CMD_END,
+}IAP_LITE_SUB_CMD_E;
+
+typedef union
+{
+       struct
+       {
+               uint8_t protocol_version;
+               uint8_t reply;
+               uint8_t sub_cmd;
+       }payload;
+       
+       struct
+       {
+               uint8_t protocol_version;
+               uint8_t reply;
+               uint8_t sub_cmd;
+       }ready;
+       
+       struct
+       {
+               uint8_t protocol_version;
+               uint8_t reply;
+               uint8_t sub_cmd;
+       }erase;
+       
+       struct
+       {
+               uint8_t protocol_version;
+               uint8_t reply;
+               uint8_t sub_cmd;
+               
+               uint32_t offset;
+               uint16_t size;
+               uint8_t content;
+       }write;
+       
+       struct
+       {
+               uint8_t protocol_version;
+               uint8_t reply;
+               uint8_t sub_cmd;
+       }write_done;
+       
+       struct
+       {
+               uint8_t protocol_version;
+               uint8_t reply;
+               uint8_t sub_cmd;
+               
+               uint32_t size;
+               uint32_t crc32;
+       }crc;
+       
+       struct
+       {
+               uint8_t protocol_version;
+               uint8_t reply;
+               uint8_t sub_cmd;
+       }end;
+       
+}IAP_LITE_CMD_T;
+
+
 #pragma pack(pop)
 
 extern IAP_CMD_REPLY_T iap_cmd;
@@ -256,5 +330,5 @@ uint32_t Iap_Check(uint32_t start_addr, uint32_t size);
 uint8_t Iap_Verify(uint32_t addr, uint8_t packet_size, uint8_t* data);
 
 void Iap_Process(uint8_t* data, uint8_t len);
-
+void Iap_Lite_Process(uint8_t* data, uint16_t len, uint8_t host_type);
 #endif
index 90f5363..dc72fa5 100644 (file)
@@ -589,6 +589,7 @@ typedef struct
                        uint32_t restore;
                        uint32_t led_switch;
                        uint32_t adc_calibration;
+                       uint32_t iot_factory;
                };
                uint8_t data[4];
        }count;
@@ -600,7 +601,8 @@ typedef struct
                        uint8_t restore:1;
                        uint8_t led_switch:1;
                        uint8_t adc_calibration:1;
-                       uint8_t reserved:5;
+                       uint8_t iot_factory:1;
+                       uint8_t reserved:4;
                };
                uint8_t data[1];
        }trigger;
@@ -951,6 +953,7 @@ typedef enum
 
 #define HOST_TYPE_USB  0
 #define HOST_TYPE_UART 1
+#define HOST_TYPE_UART_IOT 2
 
 #define USB_COMM_READ  0
 #define USB_COMM_WRITE 1
@@ -1225,6 +1228,7 @@ typedef union
 
 extern uint8_t platform_mode, platform_mode_last;
 
+extern uint8_t is_connect_usb;
 #if (ABS_ENC_NUM)
 extern ENCODER_BCD_T encoder_bcd[ABS_ENC_NUM];
 #endif
index 6d43bc2..303e83d 100644 (file)
@@ -18,16 +18,18 @@ typedef struct
 }IOT_UART_TX_QUERY_T;
 #define IOT_UART_QUERY_MAX     20
 
+#define IOT_UART_IAP_CMD   0xE0
 
 typedef struct
 {
+       uint16_t vid;
        uint16_t pid;
        uint16_t fw_version;
        uint16_t build_version;
        uint8_t mac[6];
        uint8_t heartbeat_time;
        
-       char device_id[32];
+       char device_id[2];
 }IOT_INFO_T;
 
 #pragma pack(pop)
@@ -56,8 +58,10 @@ void Iot_Uart_Init(void);
 
 void Iot_Status_Check(void);
 void Iot_Init(void);
-uint8_t Iot_Read_Object(uint16_t dp_id, void* buf, uint8_t* len);
+uint8_t Iot_Read_Object(uint16_t dp_id, void* buf,uint8_t *is_string, uint8_t* len);
 uint8_t Iot_Write_Object(uint16_t dp_id, void* buf, uint8_t len);
 void Iot_OneTimerSecond(void);
+void Iot_Uart_Tx_Query_Add(uint8_t cmd, uint8_t *pbuf, uint8_t len);
+void Iot_Key_Factory_Reset(void);
 
 #endif
index 7f3ab9f..fbb2b88 100644 (file)
@@ -347,6 +347,7 @@ typedef enum
        KEY_TURN_OFF_FOR_A_WHILE,
        KEY_TURN_OFF,
        KEY_COLOR_PREVIEW,
+       KEY_BLE_CONNECT_BLINK,
        KEY_EXHIBITION,
        KEY_POWER_ON,
 }KEY_LED_STATUS_ENUM;
@@ -364,10 +365,12 @@ typedef struct
                        uint16_t turn_off_for_a_while:1;
                        uint16_t turn_off:1;
                        uint16_t color_preview:1;
+                       uint16_t ble_state:1;
                        uint16_t exhibition:1;
                        
+                       
                        uint16_t power_on:1;
-                       uint16_t reserved1:7;
+                       uint16_t reserved1:6;
                };
                uint16_t status;
        };
@@ -434,6 +437,8 @@ void Led_Key_Turn_Off(void);
 void Led_Key_Preview(void);
 // KEY_POWER_ON
 void Led_Key_Power_On(void);
+// KEY_BLE_CONN_BLINK
+void Led_Key_Ble_Connected_Blink(void);
 
 /*********** ENC LED ***********/
 #if (ENC_LED_TOTAL_NUM)
index 4f962c9..fe3a2a2 100644 (file)
@@ -19,7 +19,7 @@ void dma_uart6_rx_deal(void);
 
 void dma_uart6_rx_init(void);
 
-
+uint8_t uart_is_send_finish(void);
 
 extern volatile bool uart6_rx_flag;
 extern uint8_t uart6_rx_data[UART6_MAX_LEN];
index 64c52f6..65bb96d 100644 (file)
@@ -165,6 +165,7 @@ void Base_Uart_Rx_Handle(uint8_t *data ,uint8_t len)
                        
                }
                base_connection.uart_conn = 1;
+               is_connect_usb=1;
                base_connection.uart_disconn_cnt = 0;
        }
 }
@@ -177,7 +178,7 @@ void Base_Disconnect_Count(void)
                {
                        base_connection.uart_conn = 0;
                        base_connection.uart_conn_success = 0;
-                       
+                       is_connect_usb=0;
                        base_connection.vid = 0x0000;
                        base_connection.pid = 0x0000;
                        base_connection.fw_version = 0x0000;
index 1f2c113..26f692c 100644 (file)
@@ -4,7 +4,7 @@
 #include "crc.h"
 #include "hw_config.h"
 #include "base.h"
-
+#include "iot.h"
 uint8_t flash_wrote_finish_system_reset = 0;
 
 uint32_t flash_data_write[FLASH_PAGE_SIZE/4] = {0xFFFFFFFF};
@@ -1032,6 +1032,16 @@ void Flash_Move_Check(void)
                                        }
                                        DUG_PRINTF("\n");
                                }
+                               else if(flash_move_query[0].reply_type == HOST_TYPE_UART_IOT)
+                               {
+                                       Iot_Uart_Tx_Query_Add(flash_move_query[0].uart_cmd, flash_move_query[0].reply_fail, flash_move_query[0].size_fail);
+                                       DUG_PRINTF("HOST_TYPE_UART_IOT 1 ok %02x: ", flash_move_query[0].uart_cmd);
+                                       for(uint8_t i=0;i<flash_move_query[0].size_fail;i++)
+                                       {
+                                               DUG_PRINTF("%02x ", flash_move_query[0].reply_fail[i]);
+                                       }
+                                       DUG_PRINTF("\n");
+                               }
                                
                        }
                        else
@@ -1050,6 +1060,16 @@ void Flash_Move_Check(void)
                                        }
                                        DUG_PRINTF("\n");
                                }
+                               else if(flash_move_query[0].reply_type == HOST_TYPE_UART_IOT)
+                               {
+                                       Iot_Uart_Tx_Query_Add(flash_move_query[0].uart_cmd, flash_move_query[0].reply_success, flash_move_query[0].size_success);
+                                       DUG_PRINTF("HOST_TYPE_UART_IOT 0 er %02x: ", flash_move_query[0].uart_cmd);
+                                       for(uint8_t i=0;i<flash_move_query[0].size_success;i++)
+                                       {
+                                               DUG_PRINTF("%02x ", flash_move_query[0].reply_success[i]);
+                                       }
+                                       DUG_PRINTF("\n");
+                               }
                                
                        }
                        
index e35712f..31c2bd8 100644 (file)
@@ -2,6 +2,7 @@
 #include "iap.h"
 #include "flash.h"
 #include "base.h"
+#include "iot.h"
 #include "usb_regs.h"
 #include "hw_config.h"
 #include "crc.h"
@@ -58,7 +59,7 @@ uint8_t Iap_Write(uint32_t addr, uint8_t packet_size, uint8_t* data)
                wdata |= data[j+1]<<8;
                wdata |= data[j+2]<<16;
                wdata |= data[j+3]<<24;
-               
+               DUG_PRINTF("addr:%08x\n",waddr+4*i);
                FLASH_ProgramWord(waddr+4*i, wdata);
                j+=4;
        }
@@ -128,7 +129,6 @@ void Iap_Process(uint8_t* data, uint8_t len)
        memcpy(iap_cmd.other.buf, data, len);
        memcpy(iap_reply.other.buf, iap_cmd.other.buf, 3);
        iap_reply.cmd.status = REPLY_STATUS_NO_CMD;
-       
        if(iap_cmd.cmd.cmd1 != CMD1_IAP_PANEL)
        {
                return;
@@ -227,6 +227,7 @@ void Iap_Process(uint8_t* data, uint8_t len)
                        // Ð´Èë
                        case CMD2_IAP_WRITE:
                        {
+                               
                                iap_reply.write.status = Iap_Write(FLASH_START_ADDR + iap_cmd.write.start_addr, iap_cmd.write.packet_size, iap_cmd.write.data);
                        }
                        break;
@@ -371,3 +372,225 @@ void Iap_Process(uint8_t* data, uint8_t len)
                Base_Uart_Tx_Query_Add(iap_reply.cmd.cmd1, iap_reply.other.buf, sizeof(IAP_CMD_REPLY_T));
        }
 }
+
+
+
+
+#define IAP_UART_FW_LEN   (64)
+uint8_t Iap_Lite_Erase(uint32_t addr, uint32_t size)
+{
+       if(addr < FLASH_APP_BACKUP_PARTITION)
+       {
+               return REPLY_STATUS_FAIL;
+       }
+       
+       if((size % FLASH_PAGE_SIZE) != 0 || (addr % FLASH_PAGE_SIZE) != 0)
+       {
+               return REPLY_STATUS_FAIL;
+       }
+       
+       uint32_t u32Addr = 0;
+       
+       for (u32Addr = addr; u32Addr < addr+size; u32Addr += FLASH_PAGE_SIZE)
+       {
+               FLASH_EraseOnePage(u32Addr);
+       }
+       return REPLY_STATUS_OK;
+}
+
+uint8_t Iap_Lite_Write(uint32_t addr, uint8_t packet_size, uint8_t* data)
+{
+       if(addr < FLASH_APP_BACKUP_PARTITION)
+       {
+               return REPLY_STATUS_FAIL;
+       }
+       
+       if((addr % 4) != 0 || packet_size > IAP_UART_FW_LEN)
+       {
+               return REPLY_STATUS_FAIL;
+       }
+       uint32_t wdata;
+       uint32_t waddr = addr;
+       packet_size = (packet_size/4 + ((packet_size % 4) != 0)) * 4;
+       uint8_t i, j;
+//     DUG_PRINTF("packet_size:%08x %d\n",addr,packet_size);
+       for (i=0,j=0;i<(packet_size/4);i++)
+       {
+               wdata = data[j];
+               wdata |= data[j+1]<<8;
+               wdata |= data[j+2]<<16;
+               wdata |= data[j+3]<<24;
+//             DUG_PRINTF("addr:%08x wdata:%08x\n",waddr+4*i,wdata);
+               FLASH_ProgramWord(waddr+4*i, wdata);
+               j+=4;
+       }
+//     DUG_PRINTF(":end\n");
+       return REPLY_STATUS_OK;
+}
+
+uint8_t Iap_Lite_Read(uint32_t addr, uint8_t packet_size, uint8_t* data)
+{
+       Flash_Read(addr, data, packet_size);
+       
+       return REPLY_STATUS_OK;
+}
+
+uint32_t Iap_Lite_Check(uint32_t start_addr, uint32_t size)
+{
+       CRC32_CTX_T ctx = {0};
+       CRC32_Init(&ctx);
+       
+       uint8_t temp[FLASH_PAGE_SIZE];
+       uint32_t read_num = size/FLASH_PAGE_SIZE + ((size%FLASH_PAGE_SIZE) != 0);
+       uint32_t read_cnt = 0;
+       uint32_t remain = 0;
+       
+       for(read_cnt = 0;read_cnt<read_num;read_cnt++)
+       {
+               if(read_cnt+1 >= read_num)
+               {
+                       remain = size - (read_num-1)*FLASH_PAGE_SIZE;
+               }
+               else
+               {
+                       remain = FLASH_PAGE_SIZE;
+               }
+               
+               Flash_Read(start_addr+read_cnt*FLASH_PAGE_SIZE, temp, remain);
+               
+               CRC32_Update(&ctx, temp, remain);
+//#if (IWDG_ENABLE)
+//             IWDG_ReloadKey();
+//#endif
+//             DUG_PRINTF("CRC32_Update:%x\n", CRC32_Final(&ctx));
+       }
+       
+       uint32_t crc_result = CRC32_Final(&ctx);
+       DUG_PRINTF("iap check_crc32:%08X \n", crc_result);
+       return crc_result;
+}
+
+uint8_t Iap_Lite_Verify(uint32_t addr, uint8_t packet_size, uint8_t* data)
+{
+       uint8_t temp[64];
+       Flash_Read(addr, temp, packet_size);
+       
+       if(memcmp(temp, data, packet_size) == 0)
+       {
+               return REPLY_STATUS_OK;
+       }
+       else
+       {
+               return REPLY_STATUS_FAIL;
+       }
+}
+
+void Iap_Lite_Process(uint8_t* data, uint16_t len, uint8_t host_type)
+{
+       IAP_LITE_CMD_T* iap_lite_cmd = (IAP_LITE_CMD_T*)data;
+       IAP_LITE_CMD_T iap_lite_reply;
+       iap_lite_reply.payload.protocol_version = iap_lite_cmd->payload.protocol_version;
+       iap_lite_reply.payload.reply = REPLY_STATUS_NONE;
+       iap_lite_reply.payload.sub_cmd = iap_lite_cmd->payload.sub_cmd;
+       
+       // ¼ì²éЭÒé°æ±¾
+       if(iap_lite_cmd->payload.protocol_version == 0x01)
+       {
+               // ·ÖÎöÃüÁîÂë
+               switch(iap_lite_cmd->payload.sub_cmd)
+               {
+                       // ×¼±¸Éý¼¶
+                       case IAP_LITE_CMD_READY:
+                       {
+                               // ½«APP0°áÔ˵½APP1±¸·Ý
+                               uint32_t crc32 = Iap_Check(FLASH_APP_PARTITION, FLASH_APP_PARTITION_SIZE);
+                               
+                               IAP_LITE_CMD_T reply_ok = {.payload.protocol_version = 0x01, .payload.reply = REPLY_STATUS_OK, .payload.sub_cmd = IAP_LITE_CMD_READY};
+                               IAP_LITE_CMD_T reply_fail = {.payload.protocol_version = 0x01, .payload.reply = REPLY_STATUS_FAIL, .payload.sub_cmd = IAP_LITE_CMD_READY};
+                               Flash_Move_Query_Add(FLASH_APP_PARTITION, FLASH_APP_BACKUP_PARTITION, FLASH_APP_PARTITION_SIZE, crc32, HOST_TYPE_UART_IOT, IOT_UART_IAP_CMD, &reply_ok, sizeof(reply_ok.payload), &reply_fail, sizeof(reply_fail.payload));
+                               return;
+                       }
+                       break;
+                       
+                       // ²Á³ý
+                       case IAP_LITE_CMD_ERASE:
+                       {
+                               iap_lite_reply.payload.reply = Iap_Lite_Erase(FLASH_APP_DOWNLOAD_PARTITION, FLASH_APP_PARTITION_SIZE);
+                       }
+                       break;
+                       
+                       // Ð´Èë
+                       case IAP_LITE_CMD_WRITE:
+                       {
+                               if(iap_lite_cmd->write.offset > FLASH_APP_PARTITION_SIZE)
+                               {
+                                       break;
+                               }
+//                             DUG_PRINTF("Iap_Lite_Write:start:%d\n",systicks);
+                               iap_lite_reply.payload.reply = Iap_Lite_Write(FLASH_APP_DOWNLOAD_PARTITION + iap_lite_cmd->write.offset, iap_lite_cmd->write.size, &iap_lite_cmd->write.content);
+//                             DUG_PRINTF("Iap_Lite_Write:ens:%d\n",systicks);
+                       }
+                       break;
+                       
+                       // Ð´ÈëÍê±Ï
+                       case IAP_LITE_CMD_WRITE_DONE:
+                       {
+                               iap_lite_reply.payload.reply = REPLY_STATUS_OK;
+                       }
+                       break;
+                       
+                       // Ð£Ñé
+                       case IAP_LITE_CMD_CRC:
+                       {
+                               DUG_PRINTF("IAP_LITE_CMD_CRC :%08x %08x %08x\n",FLASH_APP_DOWNLOAD_PARTITION,iap_lite_cmd->crc.size,iap_lite_cmd->crc.crc32);
+                               if( iap_lite_cmd->crc.size > FLASH_APP_PARTITION_SIZE)
+                               {
+                                       iap_lite_reply.payload.reply = REPLY_STATUS_FAIL;
+                                       break;
+                               }
+                               if(Iap_Lite_Check(FLASH_APP_DOWNLOAD_PARTITION, iap_lite_cmd->crc.size) == iap_lite_cmd->crc.crc32)
+                               {
+                                       iap_lite_reply.payload.reply = REPLY_STATUS_OK;
+                               }
+                               else
+                               {
+                                       iap_lite_reply.payload.reply = REPLY_STATUS_FAIL;
+                               }
+                       }
+                       break;
+                       
+                       // °áÔË
+                       case IAP_LITE_CMD_MOVE:
+                       {
+                               
+                               iap_move.move_enable = 1;
+                               iap_move.type = MOVE_APP2_TO_APP0;
+                               iap_move.crc32 = Iap_Lite_Check(FLASH_APP_DOWNLOAD_PARTITION, FLASH_APP_PARTITION_SIZE);
+                               iap_move.move_time = 0;
+                               Flash_Write_With_Flag(FLASH_MOVE_PARTITION_ADDR, FLASH_MOVE_PARTITION_FLAG, &iap_move, sizeof(IAP_MOVE_T));
+                               
+                               iap_lite_reply.payload.reply = REPLY_STATUS_OK;
+                       }
+                       break;
+                       //½áÊø¸´Î»
+                       case IAP_LITE_CMD_END :
+                       {
+                               iap_end_flag = 1;
+                               iap_lite_reply.payload.reply = REPLY_STATUS_OK;
+                       }
+                       break;
+                       
+                       default:
+                       {
+                               iap_lite_reply.payload.reply = REPLY_STATUS_NO_CMD;
+                       }
+                       break;
+               }
+       }
+       
+       // »Ø¸´
+       if(host_type == HOST_TYPE_UART_IOT)
+       {
+               Iot_Uart_Tx_Query_Add(IOT_UART_IAP_CMD, (uint8_t*)&iap_lite_reply, sizeof(iap_lite_reply.payload));
+       }
+}
index f31b91a..73ae933 100644 (file)
@@ -12,7 +12,7 @@
 #include "simhub.h"
 
 uint8_t platform_mode = DINPUT_MODE, platform_mode_last = DINPUT_MODE;
-
+uint8_t is_connect_usb = 0;
 /************************** ADC **************************/
 #if (ADC_TOTAL_NUM)
 __IO uint16_t adc_value[ADC_TOTAL_NUM]; // HALL_L2 HALL_R2
@@ -487,6 +487,7 @@ void Io_Init(void)
 //     Led_Key_Switch_Profile(0);
 //     Led_Tele_Switch_Profile(0);
 //     Led_Enc_Switch_Profile(0);
+       Led_Key_Ble_Connected_Blink();
        
        Base_Uart_Init();
 #if (IOT_ENABLE)
@@ -1503,7 +1504,23 @@ void Combine_Key_Handle(void)
                combine_key.trigger.led_switch = 0;
        }
 #endif
-       
+       //IOTÖØÖÃ
+       if(physic_key_value == COMBINE_KEY_IOT_FACTORY)
+       {
+               if(combine_key.trigger.iot_factory == 0 && ++combine_key.count.iot_factory > 5000)
+               {
+                       combine_key.trigger.iot_factory = 1;
+                       
+                       DUG_PRINTF("iot_factory\n");
+                       Iot_Key_Factory_Reset();
+                       
+               }
+       }
+       else
+       {
+               combine_key.count.iot_factory = 0;
+               combine_key.trigger.iot_factory = 0;
+       }
        // ÖØÖÃ
        if(physic_key_value == COMBINE_KEY_RESTORE)
        {
index 22123e3..0b5fead 100644 (file)
@@ -31,11 +31,11 @@ void Iot_Send_Mcu_Info(void)
     Iot_Uart_Tx_Query_Add(0x01, product_reply, sizeof(product_reply));
    
 }
-// ´®¿Ú½âÎö´¦ÀíÍêÒ»Ö¡Êý¾Ý È¥µôheader crc
+// ´®¿Ú½âÎöÊôÐÔÉ豸ÉèÖàȥµôheader crc
 // cmd: ÃüÁîÂë
 // data: ´¿Êý¾Ý¶ÎÖ¸Õë
 // len: Êý¾Ý¶Î×ܳ¤¶È
-void uart_parse_dpid_frame(uint8_t cmd, uint8_t *data, uint16_t len)
+void uart_parse_set_dpid_frame(uint8_t cmd, uint8_t *data, uint16_t len)
 {
     // ±ØÐëÖÁÉÙ1¸ödpidµÄ×îС³¤¶È 2+1+2 =5
     if (len < 5 || data == NULL) {
@@ -46,7 +46,7 @@ void uart_parse_dpid_frame(uint8_t cmd, uint8_t *data, uint16_t len)
 
     // Ñ­»·½âÎöËùÓеÄDPID£¨×Ô¶¯´¦Àí¿É±äµÄ³¤¶È£©
 //             DF 02 01 01 00 64 E0 02 01 01 00 64 E1 02 01 01 00 64 00 
-       DUG_PRINTF("uart_parse_dpid_frame len=%d\n",len);
+       DUG_PRINTF("uart_parse_set_dpid_frame len=%d\n",len);
     while (1)
     {
                if(offset+5 > len)
@@ -57,50 +57,117 @@ void uart_parse_dpid_frame(uint8_t cmd, uint8_t *data, uint16_t len)
         // 1. È¡ DPID (2¸ö×Ö½Ú)
         uint16_t dpid = data[offset + 0] | (data[offset + 1] << 8);
 
-        // 2. È¡ÀàÐÍ(1¸ö×Ö½Ú)
-        uint8_t type = data[offset + 2];
 
-        // 3. È¡Êý¾Ý³¤¶È(2¸ö×Ö½Ú)
+        // 2. È¡Êý¾Ý³¤¶È(2¸ö×Ö½Ú)
         uint16_t data_len = data[offset + 3] | (data[offset + 4] << 8);
 
-        // 4. ¼ì²éÊ£ÓàµÄ³¤¶È¹»²»¹»
-        if (offset + 5 + data_len > len || data_len  > 32 || data_len == 0) {
+        // 3. ¼ì²éÊ£ÓàµÄ³¤¶È¹»²»¹»
+        if (offset + 5 + data_len > len || data_len  > 63 || data_len == 0) {
                        DUG_PRINTF("offset + 5 + data_len=%d, len=%d\n",offset + 5 + data_len,data_len);
             break;
         }
                                
-        // 5.Êý¾ÝÖ¸Õë
-        uint8_t *p_value = &data[offset + 5];
+        // 4.Êý¾ÝÖ¸Õë
+//        uint8_t *p_value = &data[offset + 5];
 
         // ==============================
         // ¸ù¾ÝÀàÐͽâÎöÊý¾Ý
         // ==============================
-        uint32_t value = 0;
-        char str_value[64] = {0};
-                               
-        if (type == 1) { // u8
-            value = p_value[0];
-        }
-        else if (type == 2) { // u16
-            value = (p_value[0]) | (p_value[1] << 8);
-        }
-        else if (type == 4) { // u32
-            value = (p_value[0]) | (p_value[1] << 8) | (p_value[2] << 16) | (p_value[3] << 24);
-        }
-        else if (type == 5) { // string
-                       uint8_t copy_len = (data_len < 63) ? data_len : 63;
-                       memcpy(str_value, p_value, copy_len);
-                       str_value[copy_len] = 0;
-        }
 //             DUG_PRINTF("DPID=%d, type=%d, data_len=%d\n", dpid, type, data_len);
-               Iot_Write_Object(dpid,&data[offset + 5],data_len);
-               offset += 5 + data_len;
+               if(Iot_Write_Object(dpid,&data[offset + 5],data_len))
+               {
+                       offset += 5 + data_len;
+               }
+               
+    }
+}
+
+
+// ´®¿Ú½âÎöÊôÐÔÉϱ¨dpidÊý¾Ýµã È¥µôheader crc
+// cmd: ÃüÁîÂë
+// data: ´¿Êý¾Ý¶ÎÖ¸Õë
+// len: Êý¾Ý¶Î×ܳ¤¶È
+// 
+//IOT: F1 09 08 01 4F 01 50 01 50 01 51 C1 
+void uart_parse_get_dpid_frame(uint8_t cmd, uint8_t *data, uint8_t len)
+{
+    // ±ØÐëÖÁÉÙ1¸ödpidµÄ×îС³¤¶È 2+1+2 =5
+    if (len <= 0 || data == NULL || (len %2) != 0) {
+        return;
     }
+       DUG_PRINTF("uart_parse_get_dpid_frame len=%d\n",len);
+       uint8_t total_len = 0;
+       uint16_t dpid_num = len/sizeof(uint16_t); //×ܹ²ÊǶà¸öÐèÒªÉϱ¨dpidÊôÐÔÊý¾Ý
+       uint8_t send_dpid_data[IOT_UART_BUFFER_MAX-8]={0};
+       uint8_t tmp_buff[64]={0};
+       for(uint16_t i = 0;i < dpid_num;i++)
+       {
+               if(((i*sizeof(uint16_t))+1) > len) //·ÀÖ¹Òç³ö
+               {
+                       break;
+               }
+               uint16_t dpid = (data[i*sizeof(uint16_t) + 0] << 8) | data[i*sizeof(uint16_t) + 1];//ԭʼÊý¾ÝÊÇС¶ËÐò
+               DUG_PRINTF("dpid =%d\n",dpid);
+        // ==============================
+        // ¸ù¾ÝdpidÉϱ¨ÊôÐÔÊý¾Ý
+        // ==============================
+               memset(tmp_buff,0,sizeof(tmp_buff));
+               
+               uint8_t data_len = 0;
+               uint8_t string_type = 0;
+               //send_dpid_dataΪ¶Á³öµÄÄÚÈÝ£¬¸ñʽΪ£º dpid ³¤¶È ÄÚÈÝ dpid ³¤¶È ÄÚÈÝ......
+               if(Iot_Read_Object(dpid,tmp_buff,&string_type,&data_len))
+               {
+                       //22*5 = 110 dpid 
+                       // 108 
+                       uint16_t item_len = 5+data_len;
+//                     DUG_PRINTF("total_len =%d %d\n",total_len,item_len);
+                       if(total_len + item_len >= sizeof(send_dpid_data))
+                       {       
+                               //Âú255ÐèÒª·¢ËÍ
+//                             DUG_PRINTF("total_len =%d %d %d %d %d\n",total_len,total_len + item_len,item_len,data_len,sizeof(send_dpid_data));
+                               Iot_Uart_Tx_Query_Add(0x07, send_dpid_data,total_len);
+                               total_len=0;
+                               memset(send_dpid_data,0,sizeof(send_dpid_data));
+                       }
+                       send_dpid_data[total_len+0] = dpid & 0xff;
+                       send_dpid_data[total_len+1] = (dpid >> 8)&0xff;
+                       send_dpid_data[total_len+2] = string_type;
+                       send_dpid_data[total_len+3] = data_len & 0xff;
+                       send_dpid_data[total_len+4] = (data_len >> 8)&0xff;
+                       
+                       memcpy(&send_dpid_data[total_len+5],tmp_buff,data_len);
+                       total_len+=item_len;
+                       
+               }
+       }
+   
+       if(total_len > 0)
+       {
+               //×îºóÒ»°ü»òÕß²»Âú255ÐèÒª·¢ËÍ
+               DUG_PRINTF("total_len end =%d\n",total_len);
+               Iot_Uart_Tx_Query_Add(0x07, send_dpid_data,total_len);
+               total_len=0;
+       }
+}
+
+static uint8_t iot_factroy_flag = 0;
+static uint8_t factory_retry_count=0;
+//°´¼üʹÄÜiot»Ö¸´³ö³§ÉèÖÃ
+void Iot_Key_Factory_Reset(void)
+{
+       factory_retry_count=0;
+       //0x13Ö¸Áî
+       iot_factroy_flag = 1;
+       Iot_Uart_Tx_Query_Add(0x13, NULL,0);
 }
+
+
 uint8_t got_heartbeat_flag = 0;
+
 void Iot_Uart_Rx_Handle(uint8_t *data ,uint8_t len)
 {
-       if(data[1] != 0xb7)
+       if(data[1] != 0xE0)
        {
                DUG_PRINTF("IOT: ");
                for(uint8_t i=0;i<len;i++)
@@ -110,7 +177,10 @@ void Iot_Uart_Rx_Handle(uint8_t *data ,uint8_t len)
                DUG_PRINTF("\n");
        }
     
-
+       if(data == NULL)
+       {
+               return;
+       }
     if(len >= 4 && len <= IOT_UART_BUFFER_MAX && data[0] == FRAMEHEAD_IOT_TO_PANEL && Crc8_ROHC_Cal(&data[1], len-2) == data[len-1])
     {
         switch (data[1])
@@ -125,11 +195,12 @@ void Iot_Uart_Rx_Handle(uint8_t *data ,uint8_t len)
                                        
                                        real_update_data[0] = iot_info.heartbeat_time;
                                        real_update_data[1] = platform_mode;//Á¬½Óƽ̨
-                                       Iot_Uart_Tx_Query_Add(0x00, real_update_data, 2);
+                                       real_update_data[2] = base_connection.uart_conn;//ÊÇ·ñÁ¬½Ó»ù×ù»¹ÊǵçÄÔ
+                                       Iot_Uart_Tx_Query_Add(0x00, real_update_data, 3);
                                }
                                if(data[1] == 0xff)
                                {
-                                       DUG_PRINTF("wifi restart:%d\n", got_heartbeat_flag);
+//                                     DUG_PRINTF("wifi restart:%d\n", got_heartbeat_flag);
                                        if(got_heartbeat_flag >= 3)
                                        {
                                                got_heartbeat_flag=0;
@@ -144,27 +215,10 @@ void Iot_Uart_Rx_Handle(uint8_t *data ,uint8_t len)
                     Iot_Uart_Tx_Query_Add(0x0C, NULL, 0);
                 }
 
-                               DUG_PRINTF("data[2]:%02x\n\n", data[2]);
+//                             DUG_PRINTF("data[2]:%02x\n\n", data[2]);
                 switch (data[3])
                 {
                     case 0x00:
-                        if(data[4] == 1)
-                        {
-                                                       
-//                            iot_send_struct_t *s = &iot_send_type[IOT_SEND_KEY_COLOR];
-//                            DUG_PRINTF("KEY LED: %d, %d\n",s-> is_sending_flag,s-> is_send_finish_flag);
-//                            if(s-> is_sending_flag == 0 && s-> is_send_finish_flag == 0)
-//                            {
-
-//                                                                                                                             iot_start_send(IOT_SEND_KEY_COLOR,0x0d,KEY_LED_NUM,(uint8_t *)&led_key_profile[0],BUTTON_COLOR_DPID_START,3,5);
-//                                // Iot_Start_Send_Key_Color();
-
-//                            }
-//                                                                                             }
-//                                                                                             else
-//                                                                                             {
-//                                                     
-                        }
 
                                        break;
 
@@ -189,7 +243,7 @@ void Iot_Uart_Rx_Handle(uint8_t *data ,uint8_t len)
                                uint16_t data_len = data[2];
 
                                // Í¨ÓÃdpid½âÎöº¯Êý Òª·ûºÏdpidÊý¾ÝЭÒé
-                               uart_parse_dpid_frame(cmd, p_data, data_len);
+                               uart_parse_set_dpid_frame(cmd, p_data, data_len);
                        }
 //                                                             
                        break;
@@ -198,7 +252,25 @@ void Iot_Uart_Rx_Handle(uint8_t *data ,uint8_t len)
                                                
                                                
             case 0x08: break;
-            case 0x09: break;
+            case 0x09:  //7.Ö¸¶¨ÊôÐÔÅúÁ¿²éѯ(0x09)
+                       {
+                               if(len == 0)
+                               {
+                                       
+                                       break;
+                               }
+                               //data[0] //֡ͷ
+                               //data[1] cmd
+                               //data[2] len 1
+                               //data[3+n] dpid 2¸ö×Ö½Ú
+                               uint8_t  cmd = 0x07;
+                               uint8_t *p_data = &data[3];
+                               uint8_t data_len = data[2];
+
+                               // Í¨ÓÃdpid½âÎöº¯Êý Òª·ûºÏdpidÊý¾ÝЭÒé
+                               uart_parse_get_dpid_frame(cmd, p_data, data_len);
+                       }       
+                       break;
 
             case 0x0A:
             {
@@ -232,12 +304,32 @@ void Iot_Uart_Rx_Handle(uint8_t *data ,uint8_t len)
                                
             }
             break;
+                       
+                       case 0x13:
+            {
+                               iot_factroy_flag=0;
+            }
+            break;
+                       
+                       //À¶ÑÀÒÑÁ¬½Ó
+                       case 0x14:
+            {
+                               //°´¼üµÆÉÁ˸
+                               key_led_status.ble_state = 1;
+            }
+            break;
+                       
 
             case 0xB1:
             {
                 Iap_Process(&data[3], data[2]);
             }
             break;
+                       case IOT_UART_IAP_CMD:
+                       {
+                               Iap_Lite_Process(&data[3], data[2],HOST_TYPE_UART_IOT);
+                       }
+                       break;
 
             case 0xB7:
             {
@@ -279,18 +371,18 @@ void Iot_OneTimerSecond(void)
 {
        static uint32_t timerSecond=0;
        static uint32_t powerOn_count=0;
+       
        if(timerSecond == 0)
        {
                timerSecond= systicks;
        }
-       if(timerSecond -systicks >= ONE_TIMER_SECOND)
+       if(systicks - timerSecond >= ONE_TIMER_SECOND)
        {
                timerSecond= systicks;
-               
                if(powerOn_count <= 10)
                {
                        powerOn_count++;
-                       DUG_PRINTF("iot got_heartbeat_flag:%d",got_heartbeat_flag);
+//                     DUG_PRINTF("iot got_heartbeat_flag:%d",got_heartbeat_flag);
                        if(powerOn_count == 10 && got_heartbeat_flag >= 3) //¿ª»ú10¼ì²éÒ»´ÎÊÇ·ñÐèÒª·¢ËÍmcuÐÅÏ¢
                        {
                          Iot_Send_Mcu_Info();
@@ -298,6 +390,14 @@ void Iot_OneTimerSecond(void)
                          Iot_Uart_Tx_Query_Add(0x0C, NULL, 0);
                        }
                }
+               //°´¼üʹÄÜIOT»Ö¸´³ö³§ÉèÖÃ ÖØ·¢´ÎÊý3
+               if(iot_factroy_flag){
+                       if(factory_retry_count < 3)
+                       {
+                               factory_retry_count++;
+                               Iot_Uart_Tx_Query_Add(0x13, NULL, 0);
+                       }
+               }
        }
        
 }
@@ -324,38 +424,57 @@ void Iot_Uart_Tx_Query_Add(uint8_t cmd, uint8_t *pbuf, uint8_t len)
        iot_uart_tx_query_cnt++;
 }
 
-//¶ÓÁж¨Ê±´¦Àí
 void Iot_Uart_Tx_Query_Process(void)
 {
-       static uint32_t iot_send_query_time = 0;
+       
+       static uint32_t systicks_iot_uart = 0;
+       static uint32_t iot_uart_tick = 0;
        
        if(iot_uart_tx_query_cnt == 0)
                return;
        
-       if(systicks - iot_send_query_time >= 20)
-    {
-        iot_send_query_time = systicks;
+       if(systicks - iot_uart_tick >= 50) //
+//     if(systicks - iot_uart_tick >= 100)
+       {
+               iot_uart_tick = systicks;
+       
+//             if(uart_is_send_finish())
+//             {
+//                     systicks_iot_uart++;
+//             }
+//             
                
-               iot_uart_send(iot_uart_tx_query[0].buffer, iot_uart_tx_query[0].size);
+//             if(systicks_iot_uart - iot_send_query_time >= 30)
+               {
+                       
+//                     iot_send_query_time = systicks_iot_uart;
+
+                       iot_uart_send(iot_uart_tx_query[0].buffer, iot_uart_tx_query[0].size);
+//                     DUG_PRINTF("iot_uart_tx_query[0].size %d\n",iot_uart_tx_query[0].size);
 #if (1)
-                       if(iot_uart_tx_query[0].buffer[0] != 0xb7){
-                               DUG_PRINTF("iot send:");
-                               for(uint8_t i=0;i<iot_uart_tx_query[0].size;i++)
-                               {
-                                       DUG_PRINTF("%02x ", iot_uart_tx_query[0].buffer[i]);
+//                             DUG_PRINTF("iot iot_uart_tx_query[0].size£º%d\n",iot_uart_tx_query[0].size);
+                               if(iot_uart_tx_query[0].buffer[0] != 0xb7 || iot_uart_tx_query[0].buffer[0] != 0xe0  ){
+                                       DUG_PRINTF("iot send:\n");
+                                       for(uint8_t i=0;i<iot_uart_tx_query[0].size;i++)
+                                       {
+                                               DUG_PRINTF("%02x ", iot_uart_tx_query[0].buffer[i]);
+                                       }
+                                       DUG_PRINTF("\n");
                                }
-                               DUG_PRINTF("\n");
-                       }
-       
 #endif
-               for(uint8_t i=0;i<iot_uart_tx_query_cnt-1;i++)
-               {
-                       memcpy(&iot_uart_tx_query[i], &iot_uart_tx_query[i+1], sizeof(IOT_UART_TX_QUERY_T));
+                       for(uint8_t i=0;i<iot_uart_tx_query_cnt-1;i++)
+                       {
+                               memcpy(&iot_uart_tx_query[i], &iot_uart_tx_query[i+1], sizeof(IOT_UART_TX_QUERY_T));
+                       }
+                       iot_uart_tx_query_cnt--;
+                       // 5. 
+                       memset(&iot_uart_tx_query[iot_uart_tx_query_cnt], 0, sizeof(IOT_UART_TX_QUERY_T));
+                       
                }
-               iot_uart_tx_query_cnt--;
        }
 }
 
+
 void Iot_Uart_Init(void)
 {
 #if (IOT_UART_SET == 1)
@@ -451,6 +570,7 @@ void refresh_led_enc_color_callback(void *parm)
        enc_led_status.profile_color_changed=enable;
        
 }
+//ÐýÅ¥±àÂëģʽ Ïà¶Ôģʽ ¾ø¶Ôģʽ
 void refresh_abs_encoder_mode_callback(void *parm)
 {
        DUG_PRINTF("refresh_abs_encoder_mode_callback \n");
@@ -471,6 +591,7 @@ void restore_all_refresh(void)
 }
 void Iot_Write_Object_Init(void)
 {
+       memset(iot_write_object, 0, sizeof(iot_write_object));
        // °´¼üÓ³Éä
        iot_write_object[0].addr = FLASH_INPUT_REMAP_ADDR;
        iot_write_object[0].flag = FLASH_INPUT_REMAP_FLAG;
@@ -582,9 +703,10 @@ typedef struct
        uint8_t rw_prop:2; // ¶ÁдÊôÐÔ 0:Ö»¶Á  1:ֻд  2:¿É¶Áд
        uint8_t string_type:2; // ×Ö·û´®ÀàÐÍ  0:·Ç×Ö·û´®  1:ÆÕͨ  2:¿ªÍ·´øÓÐ#ºÅ
        uint8_t mask_bits:3; // Ð´ÈëʱµÄÑÚÂë  0:8λ  1:µÍ1λ  2:µÍ2λ ...  7:µÍ7λ
+       uint8_t reserved:1;
        uint8_t data_max;
        uint8_t data_min;
-       uint8_t reserved:1;
+       
        
        void* write_object; // Ð´Èë±£´æ¶ÔÏó
 }IOT_DP_OBJECT_T;
@@ -603,7 +725,9 @@ uint8_t iot_restore_net_pairing = 0;
 uint8_t iot_backup_fw = 0;
 uint8_t iot_restore_last_fw = 0;
 
-IOT_DP_OBJECT_T dp_object[2304] = {NULL};
+
+#define DP_OBJECT_MAX_NUM  (2304)
+IOT_DP_OBJECT_T dp_object[DP_OBJECT_MAX_NUM] = {NULL};
 
 void Iot_Dp_Object_Init(void)
 {
@@ -639,10 +763,10 @@ void Iot_Dp_Object_Init(void)
        
        // ÅäÍødevice id
        // 6 Ä£×é´¦Àí
-//     dp_object[6].object = (void*)&iot_info.device_id;
-//     dp_object[6].data_len = sizeof(iot_info.device_id);
-//     dp_object[6].rw_prop = IOT_READ_WRITE;
-//     dp_object[6].string_type = 1;
+       dp_object[6].object = (void*)&iot_info.device_id;
+       dp_object[6].data_len = sizeof(iot_info.device_id);
+       dp_object[6].rw_prop = IOT_READ_ONLY;
+       dp_object[6].string_type = 1;
        
        // µ±Ç°Á¬½Óƽ̨
        dp_object[7].object = (void*)&platform_mode;
@@ -659,6 +783,14 @@ void Iot_Dp_Object_Init(void)
        dp_object[8].data_max = 1;
        
        
+       dp_object[9].object = (void*)(uint32_t)base_connection.uart_conn;
+       dp_object[9].data_len =1;
+       dp_object[9].rw_prop = IOT_READ_WRITE;
+       dp_object[9].string_type = 0;
+       dp_object[9].data_min = 0;
+       dp_object[9].data_max = 1;
+       
+       
        // Ô¤Áô 9~16
        
        
@@ -2022,59 +2154,173 @@ uint8_t hex_2_char(uint8_t *src)
         desc = *src + 0x30;
     else if((*src >= 0xA) && (*src <= 0xF))
         desc = *src + 0x37; // Í³Ò»´óд
-    
+
     return desc;
 }
 
-uint8_t Iot_Read_Object(uint16_t dp_id, void* buf, uint8_t* len)
+uint8_t Iot_Read_Object(uint16_t dp_id, void* buf,uint8_t *is_string, uint8_t* len)
 {
        uint8_t err = 0;
+       if(dp_id >= DP_OBJECT_MAX_NUM)
+       {
+               DUG_PRINTF("read dpid >= DP_OBJECT_MAX_NUM %d %d\n",dp_id,DP_OBJECT_MAX_NUM);
+               return 0; // 
+       }
+       
        if(dp_object[dp_id].object != NULL)
        {
+               if(dp_object[dp_id].rw_prop == IOT_WRITE_ONLY)
+               {
+                       return err;
+               }
                err = 1; //  ³É¹¦
                
                if(dp_object[dp_id].string_type > 0) // ÊÇ·ñΪ×Ö·û´®
                {
                        *len = 0;
-                       if(dp_object[dp_id].string_type == 2)
+                       if(dp_object[dp_id].string_type == 2) //´ø#×Ö·û´®´«
                        {
                                // ¿ªÍ·¼ÓÉÏ#ºÅ
                                (((char*)buf)[*len]) = '#';
                                *len += 1;
+                       }else if(dp_object[dp_id].string_type == 1) //ÆÕͨÊý¾ÝÐèҪת³É×Ö·û´®
+                       {
+                               
+                               if(dp_object[dp_id].data_len == 1)
+                               {
+                                       uint8_t value = *(uint8_t *)dp_object[dp_id].object;
+                                       char hex_str[4] = {0};
+                                       snprintf(hex_str, sizeof(hex_str), "%02X",value);
+                                       // ¿½±´µ½Êä³öbuf
+                                        // ¹Ì¶¨¿½±´ 2 ¸ö×Ö·û£¬
+                                       ((char*)buf)[*len + 0] = hex_str[0];
+                                       ((char*)buf)[*len + 1] = hex_str[1];
+
+                                       *len += dp_object[dp_id].data_len;        // 1 ×Ö½Ú ¡ú 2 ¸öÊ®Áù½øÖÆ×Ö·û
+                                       *is_string = 5;
+                                       return err;
+                               }
+                               else if(dp_object[dp_id].data_len == 2) //uint16_t 0XFFAF ÐèҪת»»³É "FFAF"
+                               {
+                                       // È¡³ö uint16_t
+                                       
+                                       uint16_t value = *(uint16_t *)dp_object[dp_id].object;
+                                       // ¸ß8λ¡¢µÍ8λ
+                                       uint8_t h = (value >> 8) & 0xFF;
+                                       uint8_t l = value & 0xFF;
+                                       
+                                       // ×ª³É 4 Î»´óдʮÁù½øÖÆ×Ö·û´®
+                                       char hex_str[6] = {0};
+                                       snprintf(hex_str, sizeof(hex_str), "%02X%02X", h, l);
+                                       // ¿½±´µ½Êä³öbuf
+                                        // ¹Ì¶¨¿½±´ 4 ¸ö×Ö·û£¬²»ÊÜ 00 Ó°Ïì ?
+                                       ((char*)buf)[*len + 0] = hex_str[0];
+                                       ((char*)buf)[*len + 1] = hex_str[1];
+                                       ((char*)buf)[*len + 2] = hex_str[2];
+                                       ((char*)buf)[*len + 3] = hex_str[3];
+
+                                       *len += dp_object[dp_id].data_len*2;        // 2 ×Ö½Ú ¡ú 4 ¸öÊ®Áù½øÖÆ×Ö·û
+                                       *is_string = 5;
+                                       return err;
+                                       
+                               }else if(dp_object[dp_id].data_len == 4) //uint16_t 0XFFAFAEEF ÐèҪת»»³É "FFAFAEEF"
+                               {
+                                       // È¡³ö uint32_t
+                                       
+                                       uint32_t value = *(uint32_t *)dp_object[dp_id].object;
+                                       // ¸ß8λ¡¢µÍ8λ
+                                       uint8_t H1 = (value >> 24) & 0xFF;
+                                       uint8_t H2 = (value >> 16) & 0xFF;
+                                       uint8_t L1 = (value >> 8) & 0xFF;
+                                       uint8_t L2 = value & 0xFF;
+                                       
+                                       // ×ª³É 4 Î»´óдʮÁù½øÖÆ×Ö·û´®
+                                       char hex_str[10] = {0};
+                                       snprintf(hex_str, sizeof(hex_str), "%02X%02X%02X%02X",H1,H2,L1,L2);
+                                       // ¿½±´µ½Êä³öbuf
+                                        // ¹Ì¶¨¿½±´ 6 ¸ö×Ö·û
+                                       ((char*)buf)[*len + 0] = hex_str[0];
+                                       ((char*)buf)[*len + 1] = hex_str[1];
+                                       ((char*)buf)[*len + 2] = hex_str[2];
+                                       ((char*)buf)[*len + 3] = hex_str[3];
+                                       ((char*)buf)[*len + 4] = hex_str[4];
+                                       ((char*)buf)[*len + 5] = hex_str[5];
+                                       ((char*)buf)[*len + 6] = hex_str[6];
+                                       ((char*)buf)[*len + 7] = hex_str[7];
+               
+                                       *len += dp_object[dp_id].data_len*2;        // 4 ×Ö½Ú ¡ú 8 ¸öÊ®Áù½øÖÆ×Ö·û
+                                       *is_string = 5;
+                                       return err;
+                                       
+                               }
                        }
                        
-                       for(uint8_t i=0;i<dp_object[dp_id].data_len;i++)
+                       if(dp_object[dp_id].data_len/sizeof(LED_COLOR_T) > 1)
                        {
-                               uint8_t byte_h = (((uint8_t*)dp_object[dp_id].object)[i] & 0xF0) >> 4;
-                               uint8_t byte_l = (((uint8_t*)dp_object[dp_id].object)[i] & 0x0F);
                                
-                               (((char*)buf)[*len]) = hex_2_char(&byte_h);
-                               *len += 1;
-                               (((char*)buf)[*len]) = hex_2_char(&byte_l);
-                               *len += 1;
+                               for(uint8_t i=0;i<sizeof(LED_COLOR_T);i++)
+                               {
+
+                                       char hex_str[4] = {0};
+                                       uint8_t value = ((uint8_t*)dp_object[dp_id].object)[i];
+                                       
+                                       snprintf(hex_str, sizeof(hex_str)-1, "%02X", value);
+                                       // ¿½±´µ½Êä³öbuf
+                                       ((char*)buf)[*len + 0] = hex_str[0];
+                                       ((char*)buf)[*len + 1] = hex_str[1];
+                                       *len += 2;
+                                       
+                                       
+                               }
+                               
+                                       
                        }
+                       else{
+                               for(uint8_t i=0;i<dp_object[dp_id].data_len;i++)
+                               {
+                                       char hex_str[4] = {0};
+                                       uint8_t value = ((uint8_t*)dp_object[dp_id].object)[i];
+                                       
+                                       snprintf(hex_str, sizeof(hex_str)-1, "%02X", value);
+                                       // ×ª³É 4 Î»´óдʮÁù½øÖÆ×Ö·û´®
+                                       
+                                       
+                                       // ¿½±´µ½Êä³öbuf
+                                       ((char*)buf)[*len + 0] = hex_str[0];
+                                       ((char*)buf)[*len + 1] = hex_str[1];
+                                       *len += 2;
+                                       
+                               }
+                       }
+                       
+                       *is_string=5;
                }
                else
                {
+                       
                        memcpy(buf, dp_object[dp_id].object, dp_object[dp_id].data_len);
                        *len = dp_object[dp_id].data_len;
+                       *is_string=1;
+                       
                }
        }
        else
        {
                err = 0; //ʧ°Ü
                *len = 0;
+               *is_string=0;
        }
        return err;
 }
 
 void Iot_Dpid_Read(uint16_t* dpids, uint16_t num, uint8_t* output, uint8_t* output_offset)
 {
-       for(uint8_t i=0;i<num;i++)
+       for(uint16_t i=0;i<num;i++)
        {
                uint8_t content_len = 0;
                uint8_t content[64] = {0};
-               Iot_Read_Object(dpids[i], &content, &content_len);
+               uint8_t string_type = 0;
+               Iot_Read_Object(dpids[i], &content,&string_type,&content_len);
                
                *((uint16_t*)&output[*output_offset]) = dpids[i]; // DPID×Ö½Ú
                *output_offset += sizeof(uint16_t); // id³¤¶È
@@ -2093,7 +2339,7 @@ void Iot_Dpid_Read(uint16_t* dpids, uint16_t num, uint8_t* output, uint8_t* outp
 uint8_t iot_read_dpid_cmd[] = {0xF1, 0x09, 8, 1, 0, 2, 0, 3, 0, 4, 0, 0xFF};
 void Iot_Dpid_Read_Sample(void)
 {
-       uint8_t dpid_num = iot_read_dpid_cmd[2] / sizeof(uint16_t); //½âÎöºóµÄdpidµãÊýÁ¿
+       uint16_t dpid_num = iot_read_dpid_cmd[2] / sizeof(uint16_t); //½âÎöºóµÄdpidµãÊýÁ¿
        uint16_t dpid_req[128];
        memcpy(dpid_req, &iot_read_dpid_cmd[3], iot_read_dpid_cmd[2]);
        
@@ -2108,9 +2354,18 @@ void Iot_Dpid_Read_Sample(void)
 uint8_t Iot_Write_Object(uint16_t dp_id, void* buf, uint8_t len)
 {
        uint8_t err = 0;
+       if(dp_id >= DP_OBJECT_MAX_NUM)
+       {
+               DUG_PRINTF("write dpid >= DP_OBJECT_MAX_NUM %d %d\n",dp_id,DP_OBJECT_MAX_NUM);
+               return 0;
+       }
        
        if(dp_object[dp_id].object != NULL)
        {
+               if(dp_object[dp_id].rw_prop == IOT_READ_ONLY)
+               {
+                       return err;
+               }
                if(dp_object[dp_id].string_type == 0) // ²»ÊÇ×Ö·û´®
                {
 //                     if(len <= dp_object[dp_id].data_len)
@@ -2181,7 +2436,7 @@ uint8_t Iot_Write_Object(uint16_t dp_id, void* buf, uint8_t len)
                }
                else // ×Ö·û´®
                {
-                       if(dp_object[dp_id].string_type == 2 && len == 7 && ((uint8_t*)buf)[0] == '#') // ×Ö·û´®ÀàÐÍ1 ²¢ÇÒµÚÒ»¸ö×Ö½ÚÊÇ#ºÅ×Ö·û
+                       if(dp_object[dp_id].string_type == 2 && len >= 7 && ((uint8_t*)buf)[0] == '#') // ×Ö·û´®ÀàÐÍ1 ²¢ÇÒµÚÒ»¸ö×Ö½ÚÊÇ#ºÅ×Ö·û
                        {
                                LED_COLOR_T color = {0};
                                uint8_t* ptr = buf;
@@ -2204,7 +2459,11 @@ uint8_t Iot_Write_Object(uint16_t dp_id, void* buf, uint8_t len)
                                        }
                                }else{ //Ö»¸Ä±äµ¥¸öµÆÑÕÉ«
                                        DUG_PRINTF("single color\n");
-                                       memcpy(dp_object[dp_id].object,&color,sizeof(LED_COLOR_T));
+                                       if(dp_object[dp_id].data_len == sizeof(LED_COLOR_T))
+                                       {
+                                               memcpy(dp_object[dp_id].object,&color,sizeof(LED_COLOR_T));
+                                       }
+                                       
                                }
                                
                                
index 720f7d3..15f51ee 100644 (file)
@@ -1997,6 +1997,83 @@ void Led_Key_Preview(void)
     }
 }
 
+void Led_Key_Ble_Connected_Blink(void)
+{
+    // Ó¦ÓÃ
+    for(uint8_t num=0;num<KEY_LED_NUM;num++)
+    {
+        key_led_struct[num].unit[0].startTime = 0;
+               key_led_struct[num].unit[0].axisTime = 40;
+               key_led_struct[num].unit[0].shiftInTime = 10;
+               key_led_struct[num].unit[0].shiftOutTime = 0;
+               key_led_struct[num].unit[0].dstR = 0;
+               key_led_struct[num].unit[0].dstG = 0;
+               key_led_struct[num].unit[0].dstB = 0;
+
+               key_led_struct[num].unit[1].startTime = 40;
+               key_led_struct[num].unit[1].axisTime = 40;
+               key_led_struct[num].unit[1].shiftInTime = 10;
+               key_led_struct[num].unit[1].shiftOutTime = 0;
+               key_led_struct[num].unit[1].dstR = led_key_profile[led_profile_status.key_current_profile][num][0];
+               key_led_struct[num].unit[1].dstG = led_key_profile[led_profile_status.key_current_profile][num][1];
+               key_led_struct[num].unit[1].dstB = led_key_profile[led_profile_status.key_current_profile][num][2];
+               
+               key_led_struct[num].unit[2].startTime = 80;
+               key_led_struct[num].unit[2].axisTime = 40;
+               key_led_struct[num].unit[2].shiftInTime = 10;
+               key_led_struct[num].unit[2].shiftOutTime = 0;
+               key_led_struct[num].unit[2].dstR = 0;
+               key_led_struct[num].unit[2].dstG = 0;
+               key_led_struct[num].unit[2].dstB = 0;
+
+               key_led_struct[num].unit[3].startTime = 120;
+               key_led_struct[num].unit[3].axisTime = 40;
+               key_led_struct[num].unit[3].shiftInTime = 10;
+               key_led_struct[num].unit[3].shiftOutTime = 0;
+               key_led_struct[num].unit[3].dstR = led_key_profile[led_profile_status.key_current_profile][num][0];
+               key_led_struct[num].unit[3].dstG = led_key_profile[led_profile_status.key_current_profile][num][1];
+               key_led_struct[num].unit[3].dstB = led_key_profile[led_profile_status.key_current_profile][num][2];
+               
+               key_led_struct[num].unit[4].startTime = 160;
+               key_led_struct[num].unit[4].axisTime = 40;
+               key_led_struct[num].unit[4].shiftInTime = 10;
+               key_led_struct[num].unit[4].shiftOutTime = 0;
+               key_led_struct[num].unit[4].dstR = 0;
+               key_led_struct[num].unit[4].dstG = 0;
+               key_led_struct[num].unit[4].dstB = 0;
+
+               key_led_struct[num].unit[5].startTime = 200;
+               key_led_struct[num].unit[5].axisTime = 40;
+               key_led_struct[num].unit[5].shiftInTime = 10;
+               key_led_struct[num].unit[5].shiftOutTime = 0;
+               key_led_struct[num].unit[5].dstR = led_key_profile[led_profile_status.key_current_profile][num][0];
+               key_led_struct[num].unit[5].dstG = led_key_profile[led_profile_status.key_current_profile][num][1];
+               key_led_struct[num].unit[5].dstB = led_key_profile[led_profile_status.key_current_profile][num][2];
+               
+               key_led_struct[num].unit[6].startTime = 240;
+               key_led_struct[num].unit[6].axisTime = 40;
+               key_led_struct[num].unit[6].shiftInTime = 10;
+               key_led_struct[num].unit[6].shiftOutTime = 0;
+               key_led_struct[num].unit[6].dstR = 0;
+               key_led_struct[num].unit[6].dstG = 0;
+               key_led_struct[num].unit[6].dstB = 0;
+
+               key_led_struct[num].unit[7].startTime = 280;
+               key_led_struct[num].unit[7].axisTime = 40;
+               key_led_struct[num].unit[7].shiftInTime = 10;
+               key_led_struct[num].unit[7].shiftOutTime = 0;
+               key_led_struct[num].unit[7].dstR = led_key_profile[led_profile_status.key_current_profile][num][0];
+               key_led_struct[num].unit[7].dstG = led_key_profile[led_profile_status.key_current_profile][num][1];
+               key_led_struct[num].unit[7].dstB = led_key_profile[led_profile_status.key_current_profile][num][2];
+               
+               key_led_struct[num].totalTime = 320;
+               key_led_struct[num].unitNum = 8;
+               key_led_struct[num].loop = 0;
+               
+               key_led_struct[num].start = 1;
+    }
+}
+
 void Led_Enc_Recover_Color(uint8_t abs_num, uint8_t led_num)
 {
 #if (ENC_LED_TOTAL_NUM)
@@ -2173,6 +2250,8 @@ void Led_Enc_Preview(void)
 #endif
 }
 
+
+
 uint16_t race_telemetry_total_time_mul[RACE_TELEMETRY_MAX_SPEED] = {20, 50, 100};
 void Led_Race_Telemetry_Check(void)
 {
@@ -2537,6 +2616,13 @@ void Led_Key_Status_Process(void)
                        }
                        break;
                        
+                       case KEY_BLE_CONNECT_BLINK:
+                       {
+                               key_led_status.wait_for_profile_end_enable = 1;
+                               Led_Key_Ble_Connected_Blink();
+                       }
+                       break;
+       
                        case KEY_EXHIBITION:
                        {
                                Led_Key_Exhibition2();
index 618c498..ed0498b 100644 (file)
@@ -122,7 +122,22 @@ void dma_uart6_tx_init(void)
        memset(UART6_TX_DATA,0,UART6_MAX_LEN);
 }
 
-
+uint8_t uart_is_send_finish(void)
+{
+       if(USART_GetFlagStatus(UART6, USART_FLAG_TXC) == SET)
+       {
+               USART_ClrFlag(UART6,USART_FLAG_TXC);
+               return 1;
+       }
+       return 0;
+       if(DMA_GetFlagStatus(DMA2_FLAG_TC2, DMA2) == SET)
+       {
+               DMA_ClearFlag(DMA2_FLAG_TC2, DMA2);
+               return 1;
+       }
+       return 0;
+//     return DMA_GetCurrDataCounter(UART6_TX_DMA_CH) == 0;
+}
 
 //dma usart6 ·¢ËÍÊý¾Ý
 void dma_uart6_send(uint8_t *pbuf,uint8_t len)
index 96edbfd..b94793f 100644 (file)
@@ -16,7 +16,7 @@
 
 #if (W_GTL == 1)
        // USB
-       #define FW_VERSION                      (0x0103)                //¹Ì¼þ°æ±¾
+       #define FW_VERSION                      (0x0104)                //¹Ì¼þ°æ±¾
        #define BUILD_VERSION                   (0x0001)
        #define USB_VID                                         (0x36E6)
        #define USB_PID_APP                                     (0xA00B)
@@ -30,7 +30,7 @@
        #define FW_HEADER_CODE_SIZE                      4
        #define FW_FILE_NAME                            "GT_ONE_Main_Update"
        
-       #define IWDG_ENABLE                                     1
+       #define IWDG_ENABLE                                     0
        
        #define IOT_ENABLE                                      1
        #define SIMHUB_COMPATIBLE                       1
 #define iot_uart_rx_deal               dma_uart6_rx_deal
 #define iot_uart_send                  dma_uart6_send
 
+
 /******************************* Encoder *******************************/
 #define INC_ENC_NUM            4
 #define ABS_ENC_NUM            3
 
 /******************************* Combine Key *******************************/
 #define COMBINE_KEY_RESTORE                                    0x06
+#define COMBINE_KEY_IOT_FACTORY                                0x30
 #define COMBINE_KEY_ADC_CALI                           0x300
 #define COMBINE_KEY_ABS_ENC_MODE_SWITCH                0x10000