Selaa lähdekoodia

更新 'app/System/source/task.c'

zhaoxia 9 kuukautta sitten
vanhempi
commit
d12097fdeb
1 muutettua tiedostoa jossa 38 lisäystä ja 38 poistoa
  1. 38 38
      app/System/source/task.c

+ 38 - 38
app/System/source/task.c

@@ -24,10 +24,10 @@
 char string[512];
 /*
 *********************************************************************************************************
-*	º¯ Êý Ãû: void data_task(void *pdata)
-*	¹¦ÄÜ˵Ã÷: Ö÷ÒªÊÇdata_task´¦ÀíỊ̈߳¬ÓÅÏȼ¶¸ß¡£ÆäÔËÐÐÂß¼­Êǽ«nandflashÖеÄÊý¾Ý½âÎö³öÀ´ÂÖѯ·¢ËÍÊý¾Ý
-*	ÐÎ    ²Î£ºÎÞ
-*	·µ »Ø Öµ: ÎÞ
+*	函 数 �: void data_task(void *pdata)
+*	功能说明: 主�是data_task处�线程,优先级高。其�行逻辑是将nandflash中的数�解�出�轮询��数�
+*	形    �:无
+*	返 回 值: 无
 *********************************************************************************************************
 */
 void data_task(void *pdata)
@@ -47,12 +47,12 @@ 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);
-		char *buf = mymalloc(SRAMEX, 9 * 1024);	// ½ÓÊÕ¶ÁÈ¡µÄÊý¾Ý
+		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);								//·¢ËÍÊý¾Ý
+				read_device_data(current_device, buf);	//读�数�	
+				send_mqtt(buf, jsonCunt);								//��数�
 				jsonCunt = 0;		
 				memset(buf,0,strlen(buf));	
 				current_device=get->device_params;		
@@ -62,10 +62,10 @@ void data_task(void *pdata)
 }	
 /*
 *********************************************************************************************************
-*	º¯ Êý Ãû: void mqtt_to_device()
-*	¹¦ÄÜ˵Ã÷: ½«½ÓÊÕµ½µÄÊý¾Ý·¢ËÍÖÁÉ豸
-*	ÐÎ    ²Î:
-*	·µ »Ø Öµ:  
+*	函 数 �: void mqtt_to_device()
+*	功能说明: 将接收到的数���至设备
+*	形    �:
+*	返 回 值:  
 *********************************************************************************************************
 */
 void mqtt_to_device(){
@@ -73,20 +73,20 @@ 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);
 		}	
 }
 
 /*
 *********************************************************************************************************
-*	º¯ Êý Ãû: 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_data(DEVICE_PARAMS *device, char* buf)
@@ -100,7 +100,7 @@ int read_device_data(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)
 						{
@@ -140,7 +140,7 @@ int read_device_data(DEVICE_PARAMS *device, char* buf)
 										return 0;
 								}
 								
-								/* ÿ¶ÁÍêÒ»¸ö¼Ä´æÆ÷£¬½øÐÐmessageÅÐ¶Ï */
+								/* �读完一个寄存器,进行message判断 */
 								mqtt_to_device();
 								
 								currentModbusParams = currentModbusParams->nextParams;
@@ -156,7 +156,7 @@ int read_device_data(DEVICE_PARAMS *device, char* buf)
 								}												
 						}					
 				}
-				 if (current_device->protocol == DLT645_2007 || current_device->protocol == DLT645_97)
+				else if (current_device->protocol == DLT645_2007 || current_device->protocol == DLT645_97)
 				{
 						protocol_485=2;
 						uint8_t read_buf[10];
@@ -205,7 +205,7 @@ int read_device_data(DEVICE_PARAMS *device, char* buf)
 //								currentDLT645Params->rxLen = 0;
 //								printf("read DLT current data fail\n");
 //						}
-								/* ÿ¶ÁÍêÒ»¸ö¼Ä´æÆ÷£¬½øÐÐmessageÅÐ¶Ï */
+								/* �读完一个寄存器,进行message判断 */
 								mqtt_to_device();
 					
 								currentDLT645Params = currentDLT645Params->nextParams;		
@@ -226,10 +226,10 @@ int read_device_data(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)
@@ -294,10 +294,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) 
@@ -310,7 +310,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);
 
@@ -324,7 +324,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);
@@ -340,10 +340,10 @@ 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, int jsonCunt){
@@ -351,10 +351,10 @@ void send_mqtt(char*buf, int jsonCunt){
 		get= get_gateway_config_params();
 		time1 = GetCurrentTime();
 		
-		if(jsonCunt || time2  <= time1 - (3 * 1000)) // 20s½øÐÐÒ»´Î
+		if(jsonCunt || time2  <= time1 - (3 * 1000)) // 20s进行一次
 		{
 				memset(pubJsonStringCopy,0, strlen(pubJsonStringCopy));
-				memcpy(pubJsonStringCopy + strlen(pubJsonStringCopy), buf, strlen(buf));//±¸·ÝÉÏÒ»´ÎµÄÊý¾Ý
+				memcpy(pubJsonStringCopy + strlen(pubJsonStringCopy), buf, strlen(buf));//备份上一次的数�
 				sprintf(pubJsonString,"{\"DEVICEID\":\"%s\",\"data\":[%s]",get->deviceId, buf);									
 				
 				int msg = MBOX_USER_PUBLISHQOS0;