#include "iap.h"
#include "flash.h"
#include "base.h"
+#include "iot.h"
#include "usb_regs.h"
#include "hw_config.h"
#include "crc.h"
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;
}
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;
// дÈë
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;
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));
+ }
+}
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) {
// Ñ»·½âÎöËùÓеÄ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)
// 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++)
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])
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;
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;
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;
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:
{
}
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:
{
{
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();
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);
+ }
+ }
}
}
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)
enc_led_status.profile_color_changed=enable;
}
+//ÐýÅ¥±àÂëģʽ Ïà¶Ôģʽ ¾ø¶Ôģʽ
void refresh_abs_encoder_mode_callback(void *parm)
{
DUG_PRINTF("refresh_abs_encoder_mode_callback \n");
}
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;
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;
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)
{
// ÅäÍø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;
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
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³¤¶È
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]);
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)
}
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;
}
}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));
+ }
+
}
}
}
+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)
#endif
}
+
+
uint16_t race_telemetry_total_time_mul[RACE_TELEMETRY_MAX_SPEED] = {20, 50, 100};
void Led_Race_Telemetry_Check(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();