From 28a5597a05f787194e65ddce7b3604dfcf470992 Mon Sep 17 00:00:00 2001 From: d15521469561 <1731678236@qq.com> Date: Tue, 2 Jun 2026 09:25:28 +0800 Subject: [PATCH] =?utf8?q?1.=E4=B8=B2=E5=8F=A3=E8=BF=98=E6=98=AF5ms=202.?= =?utf8?q?=E7=BC=96=E7=A0=81=E5=99=A8=E6=8C=89=E9=94=AE=E6=98=A0=E5=B0=84d?= =?utf8?q?pid=E5=8A=9F=E8=83=BD=E5=AE=9E=E7=8E=B0=203.=E8=93=9D=E7=89=99?= =?utf8?q?=E9=97=AA=E7=83=81=E7=81=AF=E5=8A=9F=E8=83=BD=E5=AE=9E=E7=8E=B0?= =?utf8?q?=204.dpid=E6=95=B0=E6=8D=AE=E6=8E=A5=E6=94=B6=E5=A4=84=E7=90=86?= =?utf8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- App/src/iot.c | 554 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 468 insertions(+), 86 deletions(-) diff --git a/App/src/iot.c b/App/src/iot.c index 0b5fead..72dd086 100644 --- a/App/src/iot.c +++ b/App/src/iot.c @@ -18,16 +18,16 @@ IOT_INFO_T iot_info = {.heartbeat_time = 5}; void Iot_Send_Mcu_Info(void) { - uint8_t product_reply[9+FW_HEADER_CODE_SIZE] = {0}; + uint8_t product_reply[9+BLE_ADV_NAME_LEN] = {0}; *(uint16_t*)&product_reply[0] = USB_VID; *(uint16_t*)&product_reply[2] = USB_PID_APP; *(uint16_t*)&product_reply[4] = FW_VERSION; *(uint16_t*)&product_reply[6] = BUILD_VERSION; - product_reply[8] = FW_HEADER_CODE_SIZE; + product_reply[8] = BLE_ADV_NAME_LEN; - memcpy(&product_reply[9], FW_HEADER_CODE, FW_HEADER_CODE_SIZE); + memcpy(&product_reply[9], BLE_ADV_NAME, BLE_ADV_NAME_LEN); Iot_Uart_Tx_Query_Add(0x01, product_reply, sizeof(product_reply)); } @@ -55,20 +55,19 @@ void uart_parse_set_dpid_frame(uint8_t cmd, uint8_t *data, uint16_t len) break; } // 1. È¡ DPID (2¸ö×Ö½Ú) - uint16_t dpid = data[offset + 0] | (data[offset + 1] << 8); - - + uint16_t dpid = 0; + memcpy(&dpid,&data[offset+0],sizeof(uint16_t)); + + // 2. È¡Êý¾Ý³¤¶È(2¸ö×Ö½Ú) - uint16_t data_len = data[offset + 3] | (data[offset + 4] << 8); + uint16_t data_len = 0; + memcpy(&data_len,&data[offset+3],sizeof(uint16_t)); // 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; } - - // 4.Êý¾ÝÖ¸Õë -// uint8_t *p_value = &data[offset + 5]; // ============================== // ¸ù¾ÝÀàÐͽâÎöÊý¾Ý @@ -106,8 +105,9 @@ void uart_parse_get_dpid_frame(uint8_t cmd, uint8_t *data, uint8_t len) { break; } - uint16_t dpid = (data[i*sizeof(uint16_t) + 0] << 8) | data[i*sizeof(uint16_t) + 1];//ԭʼÊý¾ÝÊÇС¶ËÐò - DUG_PRINTF("dpid =%d\n",dpid); + uint16_t dpid = 0; + memcpy(&dpid,&data[i*sizeof(uint16_t) + 0],sizeof(uint16_t)); +// DUG_PRINTF("dpid =%d\n",dpid); // ============================== // ¸ù¾ÝdpidÉϱ¨ÊôÐÔÊý¾Ý // ============================== @@ -118,8 +118,6 @@ void uart_parse_get_dpid_frame(uint8_t cmd, uint8_t *data, uint8_t len) //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)) @@ -130,11 +128,10 @@ void uart_parse_get_dpid_frame(uint8_t cmd, uint8_t *data, uint8_t 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+0],&dpid,2); + memcpy(&send_dpid_data[total_len+2],&string_type,1); + memcpy(&send_dpid_data[total_len+3],&data_len,2); memcpy(&send_dpid_data[total_len+5],tmp_buff,data_len); total_len+=item_len; @@ -153,6 +150,8 @@ void uart_parse_get_dpid_frame(uint8_t cmd, uint8_t *data, uint8_t len) static uint8_t iot_factroy_flag = 0; static uint8_t factory_retry_count=0; +static int64_t time_stamp = 0; // ʱ¼ä´Á ÊÀ½çʱ¼ä +static int8_t time_zone = 8;//Ê±Çøµ¥Î» -24~+24 //°´¼üʹÄÜiot»Ö¸´³ö³§ÉèÖà void Iot_Key_Factory_Reset(void) { @@ -170,7 +169,7 @@ void Iot_Uart_Rx_Handle(uint8_t *data ,uint8_t len) if(data[1] != 0xE0) { DUG_PRINTF("IOT: "); - for(uint8_t i=0;i= 4 && len <= IOT_UART_BUFFER_MAX && data[0] == FRAMEHEAD_IOT_TO_PANEL && Crc8_ROHC_Cal(&data[1], len-2) == data[len-1]) { + DUG_PRINTF("recv:%02x\n", data[1]); switch (data[1]) { case 0x00: @@ -219,10 +219,16 @@ void Iot_Uart_Rx_Handle(uint8_t *data ,uint8_t len) switch (data[3]) { case 0x00: - + { + DUG_PRINTF("mqtt:disconnect\n"); + } break; - case 0x01: break; + case 0x01: + { + DUG_PRINTF("mqtt:connect\n"); + } + break; default: break; } } @@ -303,6 +309,13 @@ void Iot_Uart_Rx_Handle(uint8_t *data ,uint8_t len) // iot_send_process(0,(uint8_t *)&led_key_profile[0],5); } + break; + + case 0x12: + { + memcpy(&time_zone,&data[4],1); + memcpy(&time_stamp,&data[5],8); + } break; case 0x13: @@ -316,6 +329,7 @@ void Iot_Uart_Rx_Handle(uint8_t *data ,uint8_t len) { //°´¼üµÆÉÁ˸ key_led_status.ble_state = 1; + Iot_Uart_Tx_Query_Add(0x14, NULL, 0); } break; @@ -455,11 +469,11 @@ void Iot_Uart_Tx_Query_Process(void) // 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;iaddr, ((IOT_WRITE_OBJECT_T*)dp_object[747].write_object)->flag, ((IOT_WRITE_OBJECT_T*)dp_object[747].write_object)->var, ((IOT_WRITE_OBJECT_T*)dp_object[747].write_object)->size, 1); + + + } Flash_Write_Query_Add(((IOT_WRITE_OBJECT_T*)dp_object[dp_id].write_object)->addr, ((IOT_WRITE_OBJECT_T*)dp_object[dp_id].write_object)->flag, ((IOT_WRITE_OBJECT_T*)dp_object[dp_id].write_object)->var, ((IOT_WRITE_OBJECT_T*)dp_object[dp_id].write_object)->size, 1); + //ÊÇ·ñÐèҪˢРif(((IOT_WRITE_OBJECT_T*)dp_object[dp_id].write_object)->iot_refresh_cb != NULL) { -- 2.17.1