zhao006 9 ay önce
ebeveyn
işleme
d2b00294f6
1 değiştirilmiş dosya ile 81 ekleme ve 31 silme
  1. 81 31
      app/System/source/task.c

+ 81 - 31
app/System/source/task.c

@@ -27,10 +27,10 @@ uint8_t count = 0;
 uint8_t jsonCunt = 1;	
 /*
 *********************************************************************************************************
-*	º¯ Êý Ãû: void data_task(void *pdata)
-*	¹¦ÄÜ˵Ã÷: Ö÷ÒªÊÇdata_task´¦ÀíỊ̈߳¬ÓÅÏȼ¶¸ß¡£ÆäÔËÐÐÂß¼­Êǽ«nandflashÖеÄÊý¾Ý½âÎö³öÀ´ÂÖѯ·¢ËÍÊý¾Ý
-*	ÐÎ    ²Î£ºÎÞ
-*	·µ »Ø Öµ: ÎÞ
+*	函 数 �: void data_task(void *pdata)
+*	功能说明: 主�是data_task处�线程,优先级高。其�行逻辑是将nandflash中的数�解�出�轮询��数�
+*	形    �:无
+*	返 回 值: 无
 *********************************************************************************************************
 */
 void data_task(void *pdata)
@@ -52,6 +52,7 @@ void data_task(void *pdata)
 		get= get_gateway_config_params();
 		DEVICE_PARAMS *current_device=get->device_params;
 //		Config_485_Port(get->baudrate, get->dataBits, get->stopBit, get->parity, get->flowControl);
+<<<<<<< HEAD
 		char *buf = mymalloc(SRAMEX, 9 * 1024);	// ½ÓÊÕ¶ÁÈ¡µÄÊý¾Ý
 		memset(buf, 0, 9 * 1024);		
 		while (current_device!=NULL)
@@ -83,15 +84,27 @@ void data_task(void *pdata)
 					}	
 			}		
 		OSTimeDly(100);
+=======
+		char *buf = mymalloc(SRAMEX, 9 * 1024);	// 接收读�的数�
+		memset(buf, 0, 9 * 1024);	
+		while (current_device!=NULL)
+		{						
+				read_device_data(current_device, buf);	//读�数�	
+				send_mqtt(buf, jsonCunt);								//��数�
+				jsonCunt = 0;		
+				memset(buf,0,strlen(buf));	
+				current_device=get->device_params;		
+				OSTimeDly(1);
+>>>>>>> d12097fdeb13131a2d24b22a2181d1fbd191264d
 		}
 		myfree(SRAMEX, buf);
 }	
 /*
 *********************************************************************************************************
-*	º¯ Êý Ãû: void mqtt_to_device()
-*	¹¦ÄÜ˵Ã÷: ½«½ÓÊÕµ½µÄÊý¾Ý·¢ËÍÖÁÉ豸
-*	ÐÎ    ²Î:
-*	·µ »Ø Öµ:  
+*	函 数 �: void mqtt_to_device()
+*	功能说明: 将接收到的数���至设备
+*	形    �:
+*	返 回 值:  
 *********************************************************************************************************
 */
 void mqtt_to_device(){
@@ -99,10 +112,10 @@ void mqtt_to_device(){
 		StringInfo *message;
 		message	= (StringInfo*)OSMboxPend(mqtt_recvMseeageMbox, 1000, &err);	
 		
-		if(message != NULL)	//°üº¬ÏûÏ¢
+		if(message != NULL)	//包�消�
 		{
-				write_modbus_data(message->p);	//дÈëÊý¾Ý
-				myfree(SRAMEX ,message->p);//ÊÍ·ÅÄÚ²¿Êý¾Ý
+				write_modbus_data(message->p);	//写入数�
+				myfree(SRAMEX ,message->p);//释放内部数�
 				//OSTimeDly(1000);
 		}	
 }
@@ -113,10 +126,10 @@ void find_diff(char* buf, char* string) {
 }
 /*
 *********************************************************************************************************
-*	º¯ Êý Ãû: int READ_MODBUS_DATA(DEVICE_PARAMS *device)
-*	¹¦ÄÜ˵Ã÷: ¶ÁÈ¡µ±Ç°½ÚµãÉϵÄmodbusÊý¾Ý
-*	ÐÎ    ²Î: DEVICE_PARAMS *device  µ±Ç°É豸
-*	·µ »Ø Öµ: 1: ³É¹¦ 0:ʧ°Ü
+*	函 数 �: int READ_MODBUS_DATA(DEVICE_PARAMS *device)
+*	功能说明: 读�当�节点上的modbus数�
+*	形    �: DEVICE_PARAMS *device  当�设备
+*	返 回 值: 1: �功 0:失败
 *********************************************************************************************************
 */
 int read_device_data1(DEVICE_PARAMS *device, char* buf)
@@ -131,7 +144,7 @@ int read_device_data1(DEVICE_PARAMS *device, char* buf)
 				if (current_device->protocol == MODBUS_READ)
 				{
 						protocol_485=1;
-						uint16_t data[currentModbusParams->registerByteNum /2]; // modbus¼Ä´æÆ÷³¤¶È
+						uint16_t data[currentModbusParams->registerByteNum /2]; // modbus寄存器长度
 						mmodbus_set16bitOrder(current_device->MDBbigLittleFormat);
 						if (currentModbusParams->functionCode == 0x03 | currentModbusParams->functionCode == 0x01)
 						{
@@ -170,7 +183,7 @@ int read_device_data1(DEVICE_PARAMS *device, char* buf)
 //										return 0;
 //								}
 								
-								/* ÿ¶ÁÍêÒ»¸ö¼Ä´æÆ÷£¬½øÐÐmessageÅÐ¶Ï */
+								/* �读完一个寄存器,进行message判断 */
 								mqtt_to_device();
 								
 								currentModbusParams = currentModbusParams->nextParams;
@@ -239,7 +252,14 @@ int read_device_data1(DEVICE_PARAMS *device, char* buf)
 //						{
 //								currentDLT645Params->rxLen = 0;
 //								printf("read DLT current data fail\n");
+<<<<<<< HEAD
 //						}				
+=======
+//						}
+								/* �读完一个寄存器,进行message判断 */
+								mqtt_to_device();
+					
+>>>>>>> d12097fdeb13131a2d24b22a2181d1fbd191264d
 								currentDLT645Params = currentDLT645Params->nextParams;		
 								if (currentDLT645Params == NULL)	
 								{
@@ -389,10 +409,10 @@ int read_device_data2(DEVICE_PARAMS *device, char* buf)
 }
 /*
 *********************************************************************************************************
-*	º¯ Êý Ãû:void WRITE_MODBUS_DATA(char* cJSONstring)
-*	¹¦ÄÜ˵Ã÷: ½ÓÊÕmqttÊý¾Ý²¢Ð´Èëmodbus¼Ä´æÆ÷
-*	ÐÎ    ²Î£ºchar* cJSONstring mqtt½ÓÊÕµ½µÄÊý¾Ý
-*	·µ »Ø Öµ: ÎÞ
+*	函 数 �:void WRITE_MODBUS_DATA(char* cJSONstring)
+*	功能说明: 接收mqtt数�并写入modbus寄存器
+*	形    �:char* cJSONstring mqtt接收到的数�
+*	返 回 值: 无
 *********************************************************************************************************
 */
 void write_modbus_data(char* cJSONstring)
@@ -454,10 +474,10 @@ void write_modbus_data(char* cJSONstring)
 
 /*
 *********************************************************************************************************
-*	º¯ Êý Ãû: void find_difference(char* buf, char* pubJsonStringCopy, char* string)
-*	¹¦ÄÜ˵Ã÷: ±È½Ï³ö²ÎÊý1ºÍ²ÎÊý2µÄ²»Í¬´¦
-*	ÐÎ    ²Î: ²ÎÊý1:ÐÂÊý¾Ý ²ÎÊý2:¾ÉÊý¾Ý ²ÎÊý3£ºÊä³ö²ÎÊý
-*	·µ »Ø Öµ: ÎÞ
+*	函 数 �: void find_difference(char* buf, char* pubJsonStringCopy, char* string)
+*	功能说明: 比较出�数1和�数2的��处
+*	形    �: �数1:新数� �数2:旧数� �数3:输出�数
+*	返 回 值: 无
 *********************************************************************************************************
 */
 void find_difference(char* buf, char* pubJsonStringCopy, char* string) 
@@ -470,7 +490,7 @@ void find_difference(char* buf, char* pubJsonStringCopy, char* string)
 		
 		memcpy(data1, buf, strlen(buf));
 		memcpy(data2, pubJsonStringCopy, strlen(pubJsonStringCopy));
-     // ÀûÓÃstrtok_rº¯Êý·Ö¸î×Ö·û´®£¬²¢ÖðÒ»±È½Ï
+     // 利用strtok_r函数分割字符串,并�一比较
     char* token1 = strtok_r((char*)data1, delimiter, &saveptr1);
     char* token2 = strtok_r((char*)data2, delimiter, &saveptr2);
 
@@ -484,7 +504,7 @@ void find_difference(char* buf, char* pubJsonStringCopy, char* string)
         token2 = strtok_r(NULL, delimiter, &saveptr2);
     }
 
-//     // Èç¹ûÓÐÊ£Óà×Ö·û´®Î´±È½Ï£¬Ôò´òÓ¡Ê£Óà×Ö·û´®
+//     // 如果有剩余字符串未比较,则打�剩余字符串
 //    while (token1 != NULL) {
 //        sprintf(string + strlen(string),"%s,", token1);
 //        token1 = strtok_r(NULL, delimiter, &saveptr1);
@@ -502,19 +522,49 @@ void find_difference(char* buf, char* pubJsonStringCopy, char* string)
 
 /*
 *********************************************************************************************************
-*	º¯ Êý Ãû: void send_mqtt(char*buf, int jsonCunt)
-*	¹¦ÄÜ˵Ã÷: ½«Êý¾Ý·¢Ë͵½mqtt
-*	ÐÎ    ²Î: ²ÎÊý1:¶ÁÈ¡Êý¾Ý ²ÎÊý2:µÚÒ»´Î·¢ËͱêÖ¾
-*	·µ »Ø Öµ: ÎÞ
+*	函 数 �: void send_mqtt(char*buf, int jsonCunt)
+*	功能说明: 将数���到mqtt
+*	形    �: �数1:读�数� �数2:第一次��标志
+*	返 回 值: 无
 *********************************************************************************************************
 */
 void send_mqtt(char*buf){
 		GATEWAY_PARAMS *get;
 		get= get_gateway_config_params();
+<<<<<<< HEAD
 
 		sprintf(pubJsonString,"{\"DEVICEID\":\"%s\",\"data\":[%s]}",get->deviceId, buf);	// ×é³ÉÒª·¢Ë͵ÄjsonÓï¾ä							
 	
 		int msg = MBOX_USER_PUBLISHQOS0;	
 		if(mqtt_connectFlag==1) OSMboxPost(mqtt_sendMseeageMbox, &msg);
 
+=======
+		time1 = GetCurrentTime();
+		
+		if(jsonCunt || time2  <= time1 - (3 * 1000)) // 20s进行一次
+		{
+				memset(pubJsonStringCopy,0, strlen(pubJsonStringCopy));
+				memcpy(pubJsonStringCopy + strlen(pubJsonStringCopy), buf, strlen(buf));//备份上一次的数�
+				sprintf(pubJsonString,"{\"DEVICEID\":\"%s\",\"data\":[%s]",get->deviceId, buf);									
+				
+				int msg = MBOX_USER_PUBLISHQOS0;	
+				if(mqtt_connectFlag==1) OSMboxPost(mqtt_sendMseeageMbox, &msg);
+				time2 = GetCurrentTime();			
+		}
+		else
+		{
+				if(strcmp(buf,pubJsonStringCopy))
+				{
+						memset(string, 0 , strlen(string));
+						find_difference(buf, pubJsonStringCopy, string);	
+						memset(pubJsonString,0, strlen(pubJsonString));
+						sprintf(pubJsonString,"{\"deviceId\":\"%s\",\"data\":[{%s}]}",get->deviceId, string);
+						memset(pubJsonStringCopy,0, strlen(pubJsonStringCopy));
+						sprintf(pubJsonStringCopy, buf, strlen(buf));
+					
+						int msg = MBOX_USER_PUBLISHQOS0;	
+						if(mqtt_connectFlag==1) OSMboxPost(mqtt_sendMseeageMbox, &msg);	
+				}
+		}	
+>>>>>>> d12097fdeb13131a2d24b22a2181d1fbd191264d
 }