|
@@ -27,10 +27,10 @@ uint8_t count = 0;
|
|
uint8_t jsonCunt = 1;
|
|
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)
|
|
void data_task(void *pdata)
|
|
@@ -52,7 +52,6 @@ void data_task(void *pdata)
|
|
get= get_gateway_config_params();
|
|
get= get_gateway_config_params();
|
|
DEVICE_PARAMS *current_device=get->device_params;
|
|
DEVICE_PARAMS *current_device=get->device_params;
|
|
// Config_485_Port(get->baudrate, get->dataBits, get->stopBit, get->parity, get->flowControl);
|
|
// Config_485_Port(get->baudrate, get->dataBits, get->stopBit, get->parity, get->flowControl);
|
|
-<<<<<<< HEAD
|
|
|
|
char *buf = mymalloc(SRAMEX, 9 * 1024); // ½ÓÊÕ¶ÁÈ¡µÄÊý¾Ý
|
|
char *buf = mymalloc(SRAMEX, 9 * 1024); // ½ÓÊÕ¶ÁÈ¡µÄÊý¾Ý
|
|
memset(buf, 0, 9 * 1024);
|
|
memset(buf, 0, 9 * 1024);
|
|
while (current_device!=NULL)
|
|
while (current_device!=NULL)
|
|
@@ -84,27 +83,15 @@ void data_task(void *pdata)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
OSTimeDly(100);
|
|
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);
|
|
myfree(SRAMEX, buf);
|
|
}
|
|
}
|
|
/*
|
|
/*
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
-* 函 数 �: void mqtt_to_device()
|
|
|
|
-* 功能说明: 将接收到的数���至设备
|
|
|
|
-* 形 �:
|
|
|
|
-* 返 回 值:
|
|
|
|
|
|
+* º¯ Êý Ãû: void mqtt_to_device()
|
|
|
|
+* ¹¦ÄÜ˵Ã÷: ½«½ÓÊÕµ½µÄÊý¾Ý·¢ËÍÖÁÉ豸
|
|
|
|
+* ÐÎ ²Î:
|
|
|
|
+* ·µ »Ø Öµ:
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
*/
|
|
*/
|
|
void mqtt_to_device(){
|
|
void mqtt_to_device(){
|
|
@@ -112,10 +99,10 @@ void mqtt_to_device(){
|
|
StringInfo *message;
|
|
StringInfo *message;
|
|
message = (StringInfo*)OSMboxPend(mqtt_recvMseeageMbox, 1000, &err);
|
|
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);
|
|
//OSTimeDly(1000);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -126,10 +113,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)
|
|
int read_device_data1(DEVICE_PARAMS *device, char* buf)
|
|
@@ -144,7 +131,7 @@ int read_device_data1(DEVICE_PARAMS *device, char* buf)
|
|
if (current_device->protocol == MODBUS_READ)
|
|
if (current_device->protocol == MODBUS_READ)
|
|
{
|
|
{
|
|
protocol_485=1;
|
|
protocol_485=1;
|
|
- uint16_t data[currentModbusParams->registerByteNum /2]; // modbus寄å˜å™¨é•¿åº¦
|
|
|
|
|
|
+ uint16_t data[currentModbusParams->registerByteNum /2]; // modbus¼Ä´æÆ÷³¤¶È
|
|
mmodbus_set16bitOrder(current_device->MDBbigLittleFormat);
|
|
mmodbus_set16bitOrder(current_device->MDBbigLittleFormat);
|
|
if (currentModbusParams->functionCode == 0x03 | currentModbusParams->functionCode == 0x01)
|
|
if (currentModbusParams->functionCode == 0x03 | currentModbusParams->functionCode == 0x01)
|
|
{
|
|
{
|
|
@@ -183,7 +170,7 @@ int read_device_data1(DEVICE_PARAMS *device, char* buf)
|
|
// return 0;
|
|
// return 0;
|
|
// }
|
|
// }
|
|
|
|
|
|
- /* æ¯�读完一个寄å˜å™¨ï¼Œè¿›è¡Œmessageåˆ¤æ– */
|
|
|
|
|
|
+ /* ÿ¶ÁÍêÒ»¸ö¼Ä´æÆ÷£¬½øÐÐmessageÅÐ¶Ï */
|
|
mqtt_to_device();
|
|
mqtt_to_device();
|
|
|
|
|
|
currentModbusParams = currentModbusParams->nextParams;
|
|
currentModbusParams = currentModbusParams->nextParams;
|
|
@@ -252,14 +239,7 @@ int read_device_data1(DEVICE_PARAMS *device, char* buf)
|
|
// {
|
|
// {
|
|
// currentDLT645Params->rxLen = 0;
|
|
// currentDLT645Params->rxLen = 0;
|
|
// printf("read DLT current data fail\n");
|
|
// printf("read DLT current data fail\n");
|
|
-<<<<<<< HEAD
|
|
|
|
// }
|
|
// }
|
|
-=======
|
|
|
|
-// }
|
|
|
|
- /* æ¯�读完一个寄å˜å™¨ï¼Œè¿›è¡Œmessageåˆ¤æ– */
|
|
|
|
- mqtt_to_device();
|
|
|
|
-
|
|
|
|
->>>>>>> d12097fdeb13131a2d24b22a2181d1fbd191264d
|
|
|
|
currentDLT645Params = currentDLT645Params->nextParams;
|
|
currentDLT645Params = currentDLT645Params->nextParams;
|
|
if (currentDLT645Params == NULL)
|
|
if (currentDLT645Params == NULL)
|
|
{
|
|
{
|
|
@@ -409,10 +389,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)
|
|
void write_modbus_data(char* cJSONstring)
|
|
@@ -474,10 +454,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)
|
|
void find_difference(char* buf, char* pubJsonStringCopy, char* string)
|
|
@@ -490,7 +470,7 @@ void find_difference(char* buf, char* pubJsonStringCopy, char* string)
|
|
|
|
|
|
memcpy(data1, buf, strlen(buf));
|
|
memcpy(data1, buf, strlen(buf));
|
|
memcpy(data2, pubJsonStringCopy, strlen(pubJsonStringCopy));
|
|
memcpy(data2, pubJsonStringCopy, strlen(pubJsonStringCopy));
|
|
- // 利用strtok_r函数分割å—符串,并é€�一比较
|
|
|
|
|
|
+ // ÀûÓÃstrtok_rº¯Êý·Ö¸î×Ö·û´®£¬²¢ÖðÒ»±È½Ï
|
|
char* token1 = strtok_r((char*)data1, delimiter, &saveptr1);
|
|
char* token1 = strtok_r((char*)data1, delimiter, &saveptr1);
|
|
char* token2 = strtok_r((char*)data2, delimiter, &saveptr2);
|
|
char* token2 = strtok_r((char*)data2, delimiter, &saveptr2);
|
|
|
|
|
|
@@ -504,7 +484,7 @@ void find_difference(char* buf, char* pubJsonStringCopy, char* string)
|
|
token2 = strtok_r(NULL, delimiter, &saveptr2);
|
|
token2 = strtok_r(NULL, delimiter, &saveptr2);
|
|
}
|
|
}
|
|
|
|
|
|
-// // 如果有剩余å—符串未比较,则打å�°å‰©ä½™å—符串
|
|
|
|
|
|
+// // Èç¹ûÓÐÊ£Óà×Ö·û´®Î´±È½Ï£¬Ôò´òÓ¡Ê£Óà×Ö·û´®
|
|
// while (token1 != NULL) {
|
|
// while (token1 != NULL) {
|
|
// sprintf(string + strlen(string),"%s,", token1);
|
|
// sprintf(string + strlen(string),"%s,", token1);
|
|
// token1 = strtok_r(NULL, delimiter, &saveptr1);
|
|
// token1 = strtok_r(NULL, delimiter, &saveptr1);
|
|
@@ -522,49 +502,19 @@ 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){
|
|
void send_mqtt(char*buf){
|
|
GATEWAY_PARAMS *get;
|
|
GATEWAY_PARAMS *get;
|
|
get= get_gateway_config_params();
|
|
get= get_gateway_config_params();
|
|
-<<<<<<< HEAD
|
|
|
|
|
|
|
|
sprintf(pubJsonString,"{\"DEVICEID\":\"%s\",\"data\":[%s]}",get->deviceId, buf); // ×é³ÉÒª·¢Ë͵ÄjsonÓï¾ä
|
|
sprintf(pubJsonString,"{\"DEVICEID\":\"%s\",\"data\":[%s]}",get->deviceId, buf); // ×é³ÉÒª·¢Ë͵ÄjsonÓï¾ä
|
|
|
|
|
|
int msg = MBOX_USER_PUBLISHQOS0;
|
|
int msg = MBOX_USER_PUBLISHQOS0;
|
|
if(mqtt_connectFlag==1) OSMboxPost(mqtt_sendMseeageMbox, &msg);
|
|
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
|
|
|
|
}
|
|
}
|