Huyi 1 年之前
父节点
当前提交
a42ddf42b6
共有 4 个文件被更改,包括 26 次插入15 次删除
  1. 10 10
      Drivers/Business/PumpBusiness.c
  2. 1 1
      Drivers/Encrypt/Mbedtls_Util.c
  3. 14 4
      Drivers/Modules/Tuoreniot.c
  4. 1 0
      Drivers/Modules/Tuoreniot.h

+ 10 - 10
Drivers/Business/PumpBusiness.c

@@ -19,13 +19,13 @@
 #include "UDP_Client.h"
 
 // 联网成功标识
-uint8_t Network_Success_Flag = 0;
+uint8_t Network_Success_Flag = 0;			//0表示失败,1表示成功
 
-struct PUMPDICTS_ParamsStruct pump_params; // 泵参数
+struct PUMPDICTS_ParamsStruct pump_params; 	// 泵参数
 
-static uint16_t Data_Number = 0; // 数据编号
-static uint16_t Data_success_Number = 0; // 成功包
-static uint16_t Data_fail_Number = 0; // 失败包
+static uint16_t Data_Number = 0; 			// 数据编号
+static uint16_t Data_success_Number = 0;	// 成功包
+static uint16_t Data_fail_Number = 0; 		// 失败包
 
 int RSRP1=0;
 int RSRQ2=0; 
@@ -84,8 +84,8 @@ void PUMPBUSINESS_ParamsRefresh(void)
 	pump_params.invalidTimes=4;
 	pump_params.patientCode = 2000;
 	pump_params.totalDose=11;
-	pump_params.ward=2; // 编号124,病区。
-	pump_params.bedNo=3; // 编号125,床号。
+	pump_params.ward=2; 	// 编号124,病区。
+	pump_params.bedNo=3; 	// 编号125,床号。
 	pump_params.alarm_LowPower = 1;
 	pump_params.alarm_Total = 1;
 	pump_params.finishDose =20;
@@ -160,11 +160,11 @@ uint8_t send_data_switch = 1; // 
 static void UDPClient_SendDataInterval()
 {
 		// 定时发送数据
-	if(time_get_delay(&timer) > 1000 * Business_wait_time) // // 定时时间,20分钟
+	if(time_get_delay(&timer) > 1000 * Business_wait_time) //定时时间,20分钟
 	{
 		// 20分钟计时完成,处理业务
-		send_data_switch = 1; // 发送数据标志
-		time_clear(&timer); // 重新定时
+		send_data_switch = 1; 	// 发送数据标志
+		time_clear(&timer); 	// 重新定时
 		Log_Printf_Debug("PumpBusines_Handle\r\n");
 	}
 	

+ 1 - 1
Drivers/Encrypt/Mbedtls_Util.c

@@ -68,7 +68,7 @@ static void cutAESPKCS7Data(char* data)
 {
 	int i= 0;
 	int size = strlen(data);
-	for(i=size-1;data[i]>0&&data[i]<AES_BLOCK_SIZE;i--)
+	for(i=size-1;data[i]>0&&data[i]<=AES_BLOCK_SIZE;i--)
 	{
 		data[i]=0;
 	}

+ 14 - 4
Drivers/Modules/Tuoreniot.c

@@ -56,7 +56,7 @@ static void InitClientId(void)
 {
 	// 设置clientid
 	memset(ClientID, 0, sizeof(ClientID));
-	strcat(ClientID, regist_response.productId);
+	strcat(ClientID, regist_response.productKey);
 	strcat(ClientID, "&");
 	strcat(ClientID, regist_response.deviceId);
 }
@@ -113,6 +113,15 @@ uint8_t TUORENIOT_AnalysisRegistData(uint8_t * regist_data, uint16_t regist_data
 		strcpy(regist_response.remoteAddress, cJSON_GetObjectItem(json, "remoteAddress")->valuestring);
 		regist_response.remotePort = cJSON_GetObjectItem(json, "remotePort")->valueint;
 		
+		if(regist_response.platform == 1)
+		{
+			strcpy(regist_response.productKey, cJSON_GetObjectItem(json, "productKey")->valuestring);
+		}
+		else 
+		{
+			strcpy(regist_response.productKey, regist_response.productId);
+		}
+		
 		// 判断是否解析WiFi信息
 		if(regist_response.networkType == 3)
 		{
@@ -217,7 +226,7 @@ void TUORENIOT_PackAuthMessage(uint8_t * coap_message, uint16_t * coap_message_l
 	// 待签名数据
 	// 签名相关
 	memset(StrForSignature, 0, sizeof(StrForSignature));
-	sprintf(StrForSignature, "clientId%sdeviceName%sproductKey%sseq%d", ClientID, regist_response.deviceId,regist_response.productId, SeqOffset);
+	sprintf(StrForSignature, "clientId%sdeviceName%sproductKey%sseq%d", ClientID, regist_response.deviceId,regist_response.productKey, SeqOffset);
 //	Log_Printf_Debug("认证报文StrForSignature:\r\n%s\r\n", StrForSignature);
 	// 签名
 	memset(sign, 0, sizeof(sign));
@@ -227,7 +236,7 @@ void TUORENIOT_PackAuthMessage(uint8_t * coap_message, uint16_t * coap_message_l
 
 	// payload
 	memset(payload, 0, sizeof(payload));
-	sprintf((char * )payload, "{\"clientId\":\"%s\",\"signmethod\":\"hmacsha1\",\"sign\":\"%s\",\"productKey\":\"%s\",\"deviceName\":\"%s\",\"seq\":\"%d\"}", ClientID, sign, regist_response.productId, regist_response.deviceId, SeqOffset);
+	sprintf((char * )payload, "{\"clientId\":\"%s\",\"signmethod\":\"hmacsha1\",\"sign\":\"%s\",\"productKey\":\"%s\",\"deviceName\":\"%s\",\"seq\":\"%d\"}", ClientID, sign, regist_response.productKey, regist_response.deviceId, SeqOffset);
 	// 设置payload
 	CoAP_Set_Payload_Str((char *)payload);
 	
@@ -289,7 +298,7 @@ void TUORENIOT_PackDataMessage(uint8_t * data, uint8_t data_length, uint8_t * co
 	// path
 	CoAP_Set_Option_Str(11, "topic");
 	CoAP_Set_Option_Str(11, "sys");
-	CoAP_Set_Option_Str(11, regist_response.productId);
+	CoAP_Set_Option_Str(11, regist_response.productKey);
 	CoAP_Set_Option_Str(11, regist_response.deviceId);
 	CoAP_Set_Option_Str(11, "thing");
 	CoAP_Set_Option_Str(11, "model");
@@ -425,6 +434,7 @@ void TUORENIOT_PrintfRegistResponseStruct(void)
 	Log_Printf("networkType=%d\r\n", regist_response.networkType);
 	Log_Printf("networkProtocol=%d\r\n", regist_response.networkProtocol);
 	Log_Printf("productId=%s\r\n", regist_response.productId);
+	Log_Printf("productKey=%s\r\n", regist_response.productKey);
 	Log_Printf("deviceId=%s\r\n", regist_response.deviceId);
 	Log_Printf("userId=%s\r\n", regist_response.userId);
 	Log_Printf("deviceSecret=%s\r\n", regist_response.deviceSecret);

+ 1 - 0
Drivers/Modules/Tuoreniot.h

@@ -37,6 +37,7 @@ struct TUORENIOT_RegistResponseStruct
 	uint8_t networkType;
 	uint8_t networkProtocol;
 	char productId[20];
+	char productKey[20];
 	char deviceId[20];
 	char userId[20];
 	char deviceSecret[50];