|
@@ -24,15 +24,14 @@
|
|
char string[512];
|
|
char string[512];
|
|
/*
|
|
/*
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
-* 锟斤拷 锟斤拷 锟斤拷: void data_task(void *pdata)
|
|
|
|
-* 锟斤拷锟斤拷说锟斤拷: 锟斤拷要锟斤拷data_task锟斤拷锟斤拷锟竭程o拷锟斤拷锟饺硷拷锟竭★拷锟斤拷锟斤拷锟斤拷锟竭硷拷锟角斤拷nandflash锟叫碉拷锟斤拷锟捷斤拷锟斤拷锟斤拷锟斤拷锟斤拷询锟斤拷锟斤拷锟斤拷锟斤拷
|
|
|
|
-* 锟斤拷 锟轿o拷锟斤拷
|
|
|
|
-* 锟斤拷 锟斤拷 值: 锟斤拷
|
|
|
|
|
|
+* 函 数 名: void data_task(void *pdata)
|
|
|
|
+* 功能说明: 主要是data_task处理线程,优先级高。其运行逻辑是将nandflash中的数据解析出来轮询发送数据
|
|
|
|
+* 形 参:无
|
|
|
|
+* 返 回 值: 无
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
*/
|
|
*/
|
|
void data_task(void *pdata)
|
|
void data_task(void *pdata)
|
|
{
|
|
{
|
|
-<<<<<<< HEAD
|
|
|
|
OS_CPU_SR cpu_sr;
|
|
OS_CPU_SR cpu_sr;
|
|
pdata = pdata;
|
|
pdata = pdata;
|
|
dlt645_init(100);
|
|
dlt645_init(100);
|
|
@@ -48,12 +47,12 @@ 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);
|
|
- 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)
|
|
{
|
|
{
|
|
- read_device_data(current_device, buf); //锟斤拷取锟斤拷锟斤拷
|
|
|
|
- send_mqtt(buf, jsonCunt); //锟斤拷锟斤拷锟斤拷锟斤拷
|
|
|
|
|
|
+ read_device_data(current_device, buf); //读取数据
|
|
|
|
+ send_mqtt(buf, jsonCunt); //发送数据
|
|
jsonCunt = 0;
|
|
jsonCunt = 0;
|
|
memset(buf,0,strlen(buf));
|
|
memset(buf,0,strlen(buf));
|
|
current_device=get->device_params;
|
|
current_device=get->device_params;
|
|
@@ -63,10 +62,10 @@ void data_task(void *pdata)
|
|
}
|
|
}
|
|
/*
|
|
/*
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
-* 锟斤拷 锟斤拷 锟斤拷: void mqtt_to_device()
|
|
|
|
-* 锟斤拷锟斤拷说锟斤拷: 锟斤拷锟斤拷锟秸碉拷锟斤拷锟斤拷锟捷凤拷锟斤拷锟斤拷锟借备
|
|
|
|
-* 锟斤拷 锟斤拷:
|
|
|
|
-* 锟斤拷 锟斤拷 值:
|
|
|
|
|
|
+* 函 数 名: void mqtt_to_device()
|
|
|
|
+* 功能说明: 将接收到的数据发送至设备
|
|
|
|
+* 形 参:
|
|
|
|
+* 返 回 值:
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
*/
|
|
*/
|
|
void mqtt_to_device(){
|
|
void mqtt_to_device(){
|
|
@@ -74,109 +73,20 @@ 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);
|
|
}
|
|
}
|
|
-=======
|
|
|
|
- OS_CPU_SR cpu_sr;
|
|
|
|
- pdata = pdata;
|
|
|
|
- mmodbus_init(1);
|
|
|
|
- char buf[1000]; // 锟斤拷锟斤拷modbus锟斤拷取锟斤拷锟斤拷锟斤拷
|
|
|
|
-
|
|
|
|
- char *device_config_json = mymalloc(SRAMEX, 9 * 1024);
|
|
|
|
- read_file("device.txt", device_config_json);
|
|
|
|
- addGatewayParams(device_config_json);
|
|
|
|
- myfree(SRAMEX, device_config_json);
|
|
|
|
-
|
|
|
|
- GATEWAY_PARAMS *get;
|
|
|
|
- get= get_gateway_config_params();
|
|
|
|
- int deviceIndex=0;
|
|
|
|
- DEVICE_PARAMS *current_device=get->device_params;
|
|
|
|
-// Config_485_Port(get->baudrate, get->dataBits, get->stopBit, get->parity, get->flowControl);
|
|
|
|
- while (current_device!=NULL)
|
|
|
|
- {
|
|
|
|
- uint8_t err;
|
|
|
|
- StringInfo *message=NULL;
|
|
|
|
- message=OSQPend(JsonQ,1000,&err);
|
|
|
|
- if(message==NULL)//娌℃湁娑堟伅
|
|
|
|
- {
|
|
|
|
- OSTimeDly(1000);
|
|
|
|
- }
|
|
|
|
- else //鍖呭惈娑堟伅
|
|
|
|
- {
|
|
|
|
- myfree(SRAMIN ,message->p);//閲婃斁鍐呴儴鏁版嵁
|
|
|
|
- myfree(SRAMIN,message);
|
|
|
|
- OSTimeDly(1000);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-// uint8_t err;
|
|
|
|
-// StringInfo *message=NULL; //锟斤拷锟秸讹拷锟斤拷锟斤拷息锟结构锟斤拷
|
|
|
|
-// message=OSQPend(JsonQ,1000,&err);
|
|
|
|
-// if(message==NULL)
|
|
|
|
-// {
|
|
|
|
-// READ_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 - 20000)
|
|
|
|
-// {
|
|
|
|
-// 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();
|
|
|
|
-// }//20s锟斤拷锟斤拷一锟斤拷
|
|
|
|
-//
|
|
|
|
-// 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;
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// else
|
|
|
|
-// {
|
|
|
|
-// WRITE_MODBUS_DATA(message->p);
|
|
|
|
-// printf("sx1278_task_recv : %s",message->p);
|
|
|
|
-// myfree(SRAMIN ,message->p);
|
|
|
|
-// myfree(SRAMIN,message);
|
|
|
|
-//
|
|
|
|
-// commd = 1;
|
|
|
|
-// }
|
|
|
|
-// OSTimeDly(1000);
|
|
|
|
- }
|
|
|
|
->>>>>>> 841e7987800910a57cf5275c331a8acbfec24198
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
-* 锟斤拷 锟斤拷 锟斤拷: 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)
|
|
int read_device_data(DEVICE_PARAMS *device, char* buf)
|
|
@@ -190,7 +100,7 @@ int read_device_data(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)
|
|
{
|
|
{
|
|
@@ -230,7 +140,7 @@ int read_device_data(DEVICE_PARAMS *device, char* buf)
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
- /* 每锟斤拷锟斤拷一锟斤拷锟侥达拷锟斤拷锟斤拷锟斤拷锟斤拷message锟叫讹拷 */
|
|
|
|
|
|
+ /* 每读完一个寄存器,进行message判断 */
|
|
mqtt_to_device();
|
|
mqtt_to_device();
|
|
|
|
|
|
currentModbusParams = currentModbusParams->nextParams;
|
|
currentModbusParams = currentModbusParams->nextParams;
|
|
@@ -246,7 +156,7 @@ int read_device_data(DEVICE_PARAMS *device, char* buf)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else if (current_device->protocol == DLT645_2007 || current_device->protocol == DLT645_97)
|
|
|
|
|
|
+ if (current_device->protocol == DLT645_2007 || current_device->protocol == DLT645_97)
|
|
{
|
|
{
|
|
protocol_485=2;
|
|
protocol_485=2;
|
|
uint8_t read_buf[10];
|
|
uint8_t read_buf[10];
|
|
@@ -295,7 +205,7 @@ int read_device_data(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");
|
|
// }
|
|
// }
|
|
- /* 每锟斤拷锟斤拷一锟斤拷锟侥达拷锟斤拷锟斤拷锟斤拷锟斤拷message锟叫讹拷 */
|
|
|
|
|
|
+ /* 每读完一个寄存器,进行message判断 */
|
|
mqtt_to_device();
|
|
mqtt_to_device();
|
|
|
|
|
|
currentDLT645Params = currentDLT645Params->nextParams;
|
|
currentDLT645Params = currentDLT645Params->nextParams;
|
|
@@ -316,10 +226,10 @@ int read_device_data(DEVICE_PARAMS *device, char* buf)
|
|
}
|
|
}
|
|
/*
|
|
/*
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
-* 锟斤拷 锟斤拷 锟斤拷:void WRITE_MODBUS_DATA(char* cJSONstring)
|
|
|
|
-* 锟斤拷锟斤拷说锟斤拷: 锟斤拷锟斤拷mqtt锟斤拷锟捷诧拷写锟斤拷modbus锟侥达拷锟斤拷
|
|
|
|
-* 锟斤拷 锟轿o拷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)
|
|
@@ -384,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)
|
|
void find_difference(char* buf, char* pubJsonStringCopy, char* string)
|
|
@@ -400,7 +310,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);
|
|
|
|
|
|
@@ -414,7 +324,7 @@ void find_difference(char* buf, char* pubJsonStringCopy, char* string)
|
|
token2 = strtok_r(NULL, delimiter, &saveptr2);
|
|
token2 = strtok_r(NULL, delimiter, &saveptr2);
|
|
}
|
|
}
|
|
|
|
|
|
-// // 锟斤拷锟斤拷锟绞o拷锟斤拷址锟斤拷锟轿达拷冉希锟斤拷锟斤拷印剩锟斤拷锟街凤拷锟斤拷
|
|
|
|
|
|
+// // 如果有剩余字符串未比较,则打印剩余字符串
|
|
// 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);
|
|
@@ -430,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){
|
|
void send_mqtt(char*buf, int jsonCunt){
|
|
@@ -441,10 +351,10 @@ void send_mqtt(char*buf, int jsonCunt){
|
|
get= get_gateway_config_params();
|
|
get= get_gateway_config_params();
|
|
time1 = GetCurrentTime();
|
|
time1 = GetCurrentTime();
|
|
|
|
|
|
- if(jsonCunt || time2 <= time1 - (3 * 1000)) // 20s锟斤拷锟斤拷一锟斤拷
|
|
|
|
|
|
+ if(jsonCunt || time2 <= time1 - (3 * 1000)) // 20s进行一次
|
|
{
|
|
{
|
|
memset(pubJsonStringCopy,0, strlen(pubJsonStringCopy));
|
|
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);
|
|
sprintf(pubJsonString,"{\"DEVICEID\":\"%s\",\"data\":[%s]",get->deviceId, buf);
|
|
|
|
|
|
int msg = MBOX_USER_PUBLISHQOS0;
|
|
int msg = MBOX_USER_PUBLISHQOS0;
|