|
@@ -34,10 +34,10 @@ int commd = 1;
|
|
|
|
|
|
/*
|
|
|
*********************************************************************************************************
|
|
|
-* 函 数 名: void data_task(void *pdata)
|
|
|
-* 功能说明: 主要是data_task处理线程,优先级高。其运行逻辑是将nandflash中的数据解析出来轮询发送数据
|
|
|
-* 形 参:无
|
|
|
-* 返 回 值: 无
|
|
|
+* �� �� ��: void data_task(void *pdata)
|
|
|
+* ����˵��: ��Ҫ��data_task�����̣߳����ȼ��ߡ����������ǽ�nandflash�е����ݽ���������ѯ��������
|
|
|
+* �� ����
|
|
|
+* �� �� ֵ: ��
|
|
|
*********************************************************************************************************
|
|
|
*/
|
|
|
|
|
@@ -46,7 +46,7 @@ void data_task(void *pdata)
|
|
|
OS_CPU_SR cpu_sr;
|
|
|
pdata = pdata;
|
|
|
mmodbus_init(1);
|
|
|
- char buf[1000]; // ����modbus��ȡ������
|
|
|
+ char buf[1000]; // ����modbus��ȡ������
|
|
|
|
|
|
char *device_config_json = mymalloc(SRAMEX, 9 * 1024);
|
|
|
read_file("device.txt", device_config_json);
|
|
@@ -61,10 +61,9 @@ void data_task(void *pdata)
|
|
|
// Config_485_Port(get->baudrate, get->dataBits, get->stopBit, get->parity, get->flowControl);
|
|
|
|
|
|
while (current_device!=NULL)
|
|
|
-<<<<<<< HEAD
|
|
|
{
|
|
|
uint8_t err;
|
|
|
- StringInfo *message=NULL; //���ն�����Ϣ�ṹ��
|
|
|
+ StringInfo *message=NULL; //���ն�����Ϣ�ṹ��
|
|
|
message=(StringInfo *)OSQPend(JsonQ,1000,&err);
|
|
|
if(commd)
|
|
|
{
|
|
@@ -80,14 +79,14 @@ void data_task(void *pdata)
|
|
|
if( jsoncunt || time2 <= time1 - 20000)
|
|
|
{
|
|
|
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_PUBLISHQOS2;
|
|
|
if(mqtt_connectFlag==1) OSMboxPost(mqtt_sendMseeageMbox, &msg);
|
|
|
current_device=get->device_params;
|
|
|
jsoncunt = 0;
|
|
|
time2 = OSTimeGet();
|
|
|
- }//20s����һ��
|
|
|
+ }//20s����һ��
|
|
|
|
|
|
else
|
|
|
{
|
|
@@ -116,56 +115,14 @@ void data_task(void *pdata)
|
|
|
}
|
|
|
printf("sx1278_task_recv : %s",message->p);
|
|
|
myfree(SRAMIN ,message->p);
|
|
|
- commd = 1;
|
|
|
+
|
|
|
+ commd = 1;
|
|
|
}
|
|
|
- OSTimeDly(1000);
|
|
|
-=======
|
|
|
- {
|
|
|
- char buf[1000]; // 接收modbus读取的数据
|
|
|
- READ_MODBUS_DATA(current_device, buf);
|
|
|
- if(current_device->nextDevice!=NULL)
|
|
|
- {
|
|
|
- current_device=current_device->nextDevice;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- sprintf(buf + strlen(buf) - 1, "}");
|
|
|
- time1 = OSTimeGet();
|
|
|
- if( jsoncunt || time2 <= time1 - 10000)
|
|
|
- {
|
|
|
- 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_PUBLISHQOS2;
|
|
|
- if(mqtt_connectFlag==1) OSMboxPost(mqtt_sendMseeageMbox, &msg);
|
|
|
- current_device=get->device_params;
|
|
|
- jsoncunt = 0;
|
|
|
- time2 = OSTimeGet();
|
|
|
- }//10s进行一次
|
|
|
-
|
|
|
- else
|
|
|
- {
|
|
|
- if(strcmp(buf,pubJsonStringCopy))
|
|
|
- {
|
|
|
- memset(string, 0 , strlen(string));
|
|
|
- findDifference(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_PUBLISHQOS2;
|
|
|
- if(mqtt_connectFlag==1) OSMboxPost(mqtt_sendMseeageMbox, &msg);
|
|
|
- }
|
|
|
- }
|
|
|
- memset(buf,0,strlen(buf));
|
|
|
- current_device=get->device_params;
|
|
|
- }
|
|
|
->>>>>>> a918534a9b4aa4cabe8f4f2913d8348b30404274
|
|
|
+ OSTimeDly(1000);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- #if 0 //测试代码不经过转发直接进行相应的解析
|
|
|
+ #if 0 //���Դ��벻����ת��ֱ�ӽ�����Ӧ�Ľ���
|
|
|
SlaveProtocolAnalysis(string,bufferLength);
|
|
|
data_acquisition();
|
|
|
uint8_t node_string[256];
|
|
@@ -176,10 +133,10 @@ void data_task(void *pdata)
|
|
|
|
|
|
/*
|
|
|
*********************************************************************************************************
|
|
|
-* 函 数 名: 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��ʧ��
|
|
|
*********************************************************************************************************
|
|
|
*/
|
|
|
|
|
@@ -195,7 +152,7 @@ int READ_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)
|
|
|
{
|
|
@@ -243,10 +200,10 @@ int READ_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)
|
|
@@ -317,12 +274,7 @@ void WRITE_MODBUS_DATA(char* cJSONstring)
|
|
|
}
|
|
|
|
|
|
|
|
|
-<<<<<<< HEAD
|
|
|
-// Ƚ JSONItem 飬ҵ仯IJ
|
|
|
-=======
|
|
|
-
|
|
|
-// 比较两个 JSONItem 数组,找到变化的部分
|
|
|
->>>>>>> a918534a9b4aa4cabe8f4f2913d8348b30404274
|
|
|
+// �Ƚ����� JSONItem ���飬�ҵ��仯�IJ���
|
|
|
void findDifference(char* buf, char* pubJsonStringCopy, char* string)
|
|
|
{
|
|
|
const char* delimiter = "{}";
|
|
@@ -332,7 +284,7 @@ void findDifference(char* buf, char* pubJsonStringCopy, char* string)
|
|
|
char* data2 = malloc(strlen(pubJsonStringCopy) + 1); ;
|
|
|
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);
|
|
|
|
|
@@ -344,7 +296,7 @@ void findDifference(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);
|