|
@@ -25,15 +25,17 @@ char string[512];
|
|
uint8_t read_cnt = 0;
|
|
uint8_t read_cnt = 0;
|
|
uint8_t count = 0;
|
|
uint8_t count = 0;
|
|
uint8_t jsonCunt = 1;
|
|
uint8_t jsonCunt = 1;
|
|
|
|
+int ID = 0;
|
|
/*
|
|
/*
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
-* 函 数 �: 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)
|
|
|
|
+<<<<<<< HEAD
|
|
{
|
|
{
|
|
<<<<<<< HEAD
|
|
<<<<<<< HEAD
|
|
OS_CPU_SR cpu_sr;
|
|
OS_CPU_SR cpu_sr;
|
|
@@ -72,13 +74,15 @@ void data_task(void *pdata)
|
|
while(Qnum.OSNMsgs!=0)
|
|
while(Qnum.OSNMsgs!=0)
|
|
=======
|
|
=======
|
|
|
|
|
|
|
|
+=======
|
|
|
|
+{
|
|
|
|
+>>>>>>> 59516250cca2e8da62941a123b11f78ecf895415
|
|
OS_CPU_SR cpu_sr;
|
|
OS_CPU_SR cpu_sr;
|
|
pdata = pdata;
|
|
pdata = pdata;
|
|
|
|
|
|
dlt645_init(100);
|
|
dlt645_init(100);
|
|
mmodbus_init(1);
|
|
mmodbus_init(1);
|
|
|
|
|
|
-
|
|
|
|
char *device_config_json = mymalloc(SRAMEX, 9 * 1024);
|
|
char *device_config_json = mymalloc(SRAMEX, 9 * 1024);
|
|
read_file("device.txt", device_config_json);
|
|
read_file("device.txt", device_config_json);
|
|
addGatewayParams(device_config_json);
|
|
addGatewayParams(device_config_json);
|
|
@@ -87,8 +91,7 @@ void data_task(void *pdata)
|
|
GATEWAY_PARAMS *get;
|
|
GATEWAY_PARAMS *get;
|
|
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);
|
|
|
|
-<<<<<<< HEAD
|
|
|
|
|
|
+// Config_485_Port(get->baudrate, get->dataBits, get->stopBit, get->checkBit, 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)
|
|
@@ -97,51 +100,42 @@ void data_task(void *pdata)
|
|
if(mqtt_connectFlag)
|
|
if(mqtt_connectFlag)
|
|
>>>>>>> d2b00294f64b161364915ae9082f104a2f26e39c
|
|
>>>>>>> d2b00294f64b161364915ae9082f104a2f26e39c
|
|
{
|
|
{
|
|
- if(jsonCunt || time2 <= time1 - (10 * 1000))// 10s½øÐÐÒ»´ÎÈ«Êý¾Ý·¢ËÍ
|
|
|
|
|
|
+ if(jsonCunt || time2 <= time1 - ( 60 * 1000))// 60s½øÐÐÒ»´ÎÈ«Êý¾Ý·¢ËÍ
|
|
{
|
|
{
|
|
- read_device_data1(current_device, buf);
|
|
|
|
- send_mqtt(buf);
|
|
|
|
- jsonCunt = 0;
|
|
|
|
- memset(buf,0,strlen(buf));
|
|
|
|
|
|
+ read_device_data(current_device, buf);
|
|
|
|
+ send_mqtt(buf);
|
|
current_device=get->device_params;
|
|
current_device=get->device_params;
|
|
time2 = GetCurrentTime();
|
|
time2 = GetCurrentTime();
|
|
-// LogPrint(LOG_INFO,__FILE__, __FUNCTION__, __LINE__, "data for all");
|
|
|
|
|
|
+ jsonCunt = 0;
|
|
|
|
+ count = 0;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- read_device_data2(current_device, buf);
|
|
|
|
- if(count > 0)// count¼ì²âbufÄÚÊÇ·ñº¬ÓÐÊý¾Ý
|
|
|
|
- {
|
|
|
|
- send_mqtt(buf);
|
|
|
|
- memset(buf,0,strlen(buf));
|
|
|
|
|
|
+ read_device_data(current_device, buf);
|
|
|
|
+ if(count > 0)// count¼ì²âÊÇ·ñº¬ÓÐÊý¾Ý
|
|
|
|
+ {
|
|
|
|
+ send_mqtt(string);
|
|
|
|
+ memset(string,0,strlen(string));
|
|
current_device=get->device_params;
|
|
current_device=get->device_params;
|
|
count = 0;
|
|
count = 0;
|
|
-// LogPrint(LOG_INFO,__FILE__, __FUNCTION__, __LINE__, "different data");
|
|
|
|
|
|
+ }else
|
|
|
|
+ {
|
|
|
|
+// LogPrint(LOG_INFO,__FILE__, __FUNCTION__, __LINE__, "no data");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ mqtt_to_device();
|
|
|
|
+ memset(buf,0,strlen(buf));
|
|
}
|
|
}
|
|
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(){
|
|
@@ -149,10 +143,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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -163,67 +157,47 @@ 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_data(DEVICE_PARAMS *device, char* buf)
|
|
{
|
|
{
|
|
-
|
|
|
|
DEVICE_PARAMS *current_device=device;
|
|
DEVICE_PARAMS *current_device=device;
|
|
GATEWAY_READ_MODBUS_COMMAND *currentModbusParams = current_device->params->gateway_read_modbus_command;
|
|
GATEWAY_READ_MODBUS_COMMAND *currentModbusParams = current_device->params->gateway_read_modbus_command;
|
|
GATEWAY_READ_DLT645_COMMAND *currentDLT645Params = current_device->params->gateway_read_dlt645_command;
|
|
GATEWAY_READ_DLT645_COMMAND *currentDLT645Params = current_device->params->gateway_read_dlt645_command;
|
|
-
|
|
|
|
|
|
+
|
|
while(current_device->params != NULL)
|
|
while(current_device->params != NULL)
|
|
{
|
|
{
|
|
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寄å˜å™¨é•¿åº¦
|
|
|
|
|
|
+ uint8_t state;
|
|
|
|
+ uint16_t data[currentModbusParams->registerByteNum /2]; // modbus¼Ä´æÆ÷³¤¶È
|
|
|
|
+ uint8_t data1[currentModbusParams->registerByteNum /2];
|
|
mmodbus_set16bitOrder(current_device->MDBbigLittleFormat);
|
|
mmodbus_set16bitOrder(current_device->MDBbigLittleFormat);
|
|
- if (currentModbusParams->functionCode == 0x03 | currentModbusParams->functionCode == 0x01)
|
|
|
|
|
|
+ // ¶ÁË®·§×´Ì¬
|
|
|
|
+ if(currentModbusParams->functionCode == 0x01)
|
|
{
|
|
{
|
|
- bool success = mmodbus_readHoldingRegisters16i(currentModbusParams->slaveAddress,
|
|
|
|
- currentModbusParams->registerAddress,
|
|
|
|
|
|
+ bool success = mmodbus_readCoil(currentModbusParams->slaveAddress,
|
|
currentModbusParams->registerByteNum /2,
|
|
currentModbusParams->registerByteNum /2,
|
|
- data);
|
|
|
|
-
|
|
|
|
- if (success)
|
|
|
|
|
|
+ data1);
|
|
|
|
+ if(success)
|
|
|
|
+ {
|
|
|
|
+ uint8_t value;
|
|
|
|
+ value = data1[0];
|
|
|
|
+ if(value == 0)
|
|
{
|
|
{
|
|
- uint32_t value;
|
|
|
|
- if (currentModbusParams->registerByteNum == 4)
|
|
|
|
- {
|
|
|
|
- value = (uint32_t)data[0] | data[1];
|
|
|
|
- }
|
|
|
|
- else if (currentModbusParams->registerByteNum == 2)
|
|
|
|
- {
|
|
|
|
- value = data[0];
|
|
|
|
- }
|
|
|
|
- if (currentModbusParams->decimalPoint == 0)
|
|
|
|
- {
|
|
|
|
- currentModbusParams->value = value;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- float convertedValue = (float)value / pow(10, currentModbusParams->decimalPoint);
|
|
|
|
- currentModbusParams->value=convertedValue;
|
|
|
|
- }
|
|
|
|
- sprintf(buf + strlen(buf), "{\"deviceId\":\"%s\",\"%s\":%d},",
|
|
|
|
- current_device->deviceID, currentModbusParams->keyword, value);
|
|
|
|
|
|
+ sprintf(buf + strlen(buf), "{\"deviceId\":\"%s\",\"%s\":close},",
|
|
|
|
+ current_device->deviceID, currentModbusParams->keyword);
|
|
|
|
+ }else{
|
|
|
|
+ sprintf(buf + strlen(buf), "{\"deviceId\":\"%s\",\"%s\":open},",
|
|
|
|
+ current_device->deviceID, currentModbusParams->keyword);
|
|
}
|
|
}
|
|
-// else
|
|
|
|
-// {
|
|
|
|
-// printf("read modbus register fail\n");
|
|
|
|
-// return 0;
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
- /* æ¯�读完一个寄å˜å™¨ï¼Œè¿›è¡Œmessageåˆ¤æ– */
|
|
|
|
- mqtt_to_device();
|
|
|
|
-
|
|
|
|
- currentModbusParams = currentModbusParams->nextParams;
|
|
|
|
|
|
+ }
|
|
|
|
+ currentModbusParams = currentModbusParams->nextParams;
|
|
if (currentModbusParams == NULL)
|
|
if (currentModbusParams == NULL)
|
|
{
|
|
{
|
|
current_device = current_device->nextDevice;
|
|
current_device = current_device->nextDevice;
|
|
@@ -233,107 +207,16 @@ int read_device_data1(DEVICE_PARAMS *device, char* buf)
|
|
sprintf(buf + strlen(buf) - 1, "");
|
|
sprintf(buf + strlen(buf) - 1, "");
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else if (current_device->protocol == DLT645_2007 || current_device->protocol == DLT645_97)
|
|
|
|
- {
|
|
|
|
- protocol_485=2;
|
|
|
|
- uint8_t read_buf[10];
|
|
|
|
- uint32_t dltValue;
|
|
|
|
-
|
|
|
|
- currentDLT645Params->rxLen = 0;
|
|
|
|
- memset(read_buf, 0, 10);
|
|
|
|
- memset(currentDLT645Params->data, 0, 10);
|
|
|
|
-
|
|
|
|
- dlt645_set_addr(&dlt645, currentDLT645Params->deviceID645);
|
|
|
|
- int8_t rs;
|
|
|
|
- if (current_device->protocol == DLT645_2007)
|
|
|
|
- {
|
|
|
|
- rs = dlt645_read_data(&dlt645, currentDLT645Params->Identification, read_buf, DLT645_2007);
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- else if (current_device->protocol == DLT645_1997)
|
|
|
|
- {
|
|
|
|
- rs = dlt645_read_data(&dlt645, currentDLT645Params->Identification, read_buf, DLT645_1997);
|
|
|
|
- }
|
|
|
|
- if (rs != -1)
|
|
|
|
- {
|
|
|
|
- if (rs <= 4)
|
|
|
|
- {
|
|
|
|
- memcpy(currentDLT645Params->data, read_buf, 4);
|
|
|
|
- currentDLT645Params->rxLen = 4;
|
|
|
|
- }
|
|
|
|
- else if (rs == 5)
|
|
|
|
- {
|
|
|
|
- memcpy(currentDLT645Params->data, read_buf, 5);
|
|
|
|
- currentDLT645Params->rxLen = 5;
|
|
|
|
- }
|
|
|
|
- else if (rs > 5)
|
|
|
|
- {
|
|
|
|
- memcpy(currentDLT645Params->data, read_buf, 9);
|
|
|
|
- currentDLT645Params->rxLen = 9;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- dltValue = currentDLT645Params->data[0] << 24 | currentDLT645Params->data[1] << 16|
|
|
|
|
- currentDLT645Params->data[2] << 8 | currentDLT645Params->data[3];
|
|
|
|
-
|
|
|
|
- sprintf(buf + strlen(buf), "{\"identifier\":\"%s\",\"deviceID645\":\"%02x%02x%02x%02x%02x%02x\",\"identifier645\":%d,\"value\":%X}",
|
|
|
|
- currentDLT645Params->keyword, currentDLT645Params->deviceID645[0],
|
|
|
|
- currentDLT645Params->deviceID645[1],currentDLT645Params->deviceID645[2],
|
|
|
|
- currentDLT645Params->deviceID645[3],currentDLT645Params->deviceID645[4],
|
|
|
|
- currentDLT645Params->deviceID645[5],currentDLT645Params->Identification,dltValue);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-// else
|
|
|
|
-// {
|
|
|
|
-// currentDLT645Params->rxLen = 0;
|
|
|
|
-// printf("read DLT current data fail\n");
|
|
|
|
-<<<<<<< HEAD
|
|
|
|
-// }
|
|
|
|
-=======
|
|
|
|
-// }
|
|
|
|
- /* æ¯�读完一个寄å˜å™¨ï¼Œè¿›è¡Œmessageåˆ¤æ– */
|
|
|
|
- mqtt_to_device();
|
|
|
|
-
|
|
|
|
->>>>>>> d12097fdeb13131a2d24b22a2181d1fbd191264d
|
|
|
|
- currentDLT645Params = currentDLT645Params->nextParams;
|
|
|
|
- if (currentDLT645Params == NULL)
|
|
|
|
- {
|
|
|
|
- current_device = current_device->nextDevice;
|
|
|
|
- currentDLT645Params = current_device->params->gateway_read_dlt645_command;
|
|
|
|
- if(current_device == NULL)
|
|
|
|
- {
|
|
|
|
- sprintf(buf + strlen(buf) - 1, "");
|
|
|
|
- return 1;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- return 1;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-int read_device_data2(DEVICE_PARAMS *device, char* buf)
|
|
|
|
-{
|
|
|
|
- DEVICE_PARAMS *current_device=device;
|
|
|
|
- GATEWAY_READ_MODBUS_COMMAND *currentModbusParams = current_device->params->gateway_read_modbus_command;
|
|
|
|
- GATEWAY_READ_DLT645_COMMAND *currentDLT645Params = current_device->params->gateway_read_dlt645_command;
|
|
|
|
-
|
|
|
|
- while(current_device->params != NULL)
|
|
|
|
- {
|
|
|
|
- if (current_device->protocol == MODBUS_READ)
|
|
|
|
- {
|
|
|
|
- protocol_485=1;
|
|
|
|
- uint16_t data[currentModbusParams->registerByteNum /2]; // modbus¼Ä´æÆ÷³¤¶È
|
|
|
|
- mmodbus_set16bitOrder(current_device->MDBbigLittleFormat);
|
|
|
|
- if (currentModbusParams->functionCode == 0x03 | currentModbusParams->functionCode == 0x01)
|
|
|
|
|
|
+ // ¶Áµ¥¸ö¼Ä´æÆ÷
|
|
|
|
+ if (currentModbusParams->functionCode == 0x03)
|
|
{
|
|
{
|
|
|
|
+// bool success = mmodbus_readHoldingRegisters16i(0x17,0x00,0x02,data);
|
|
bool success = mmodbus_readHoldingRegisters16i(currentModbusParams->slaveAddress,
|
|
bool success = mmodbus_readHoldingRegisters16i(currentModbusParams->slaveAddress,
|
|
- currentModbusParams->registerAddress,
|
|
|
|
- currentModbusParams->registerByteNum /2,
|
|
|
|
- data);
|
|
|
|
|
|
+ currentModbusParams->registerAddress,
|
|
|
|
+ currentModbusParams->registerByteNum /2,
|
|
|
|
+ data);
|
|
|
|
|
|
if (success)
|
|
if (success)
|
|
{
|
|
{
|
|
@@ -348,11 +231,16 @@ int read_device_data2(DEVICE_PARAMS *device, char* buf)
|
|
}
|
|
}
|
|
if((value - currentModbusParams->value) != 0)
|
|
if((value - currentModbusParams->value) != 0)
|
|
{
|
|
{
|
|
|
|
+ count++;
|
|
|
|
+ sprintf(string + strlen(string), "{\"deviceId\":\"%s\",\"%s\":%d},",
|
|
|
|
+ current_device->deviceID, currentModbusParams->keyword, value);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
sprintf(buf + strlen(buf), "{\"deviceId\":\"%s\",\"%s\":%d},",
|
|
sprintf(buf + strlen(buf), "{\"deviceId\":\"%s\",\"%s\":%d},",
|
|
current_device->deviceID, currentModbusParams->keyword, value);
|
|
current_device->deviceID, currentModbusParams->keyword, value);
|
|
- count++;
|
|
|
|
}
|
|
}
|
|
- if (currentModbusParams->decimalPoint == 0)
|
|
|
|
|
|
+ if (currentModbusParams->decimalPoint == 0)
|
|
{
|
|
{
|
|
currentModbusParams->value = value;
|
|
currentModbusParams->value = value;
|
|
|
|
|
|
@@ -375,7 +263,61 @@ int read_device_data2(DEVICE_PARAMS *device, char* buf)
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ // ¿ª¹ØË®·§
|
|
|
|
+ if(currentModbusParams->functionCode == 0x05)
|
|
|
|
+ {
|
|
|
|
+ bool success = mmodbus_writeCoil(currentModbusParams->slaveAddress,
|
|
|
|
+ currentModbusParams->registerByteNum /2,
|
|
|
|
+ state);
|
|
|
|
+ if(success)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ sprintf(buf + strlen(buf), "{\"deviceId\":\"%s\",\"%s\": success},",
|
|
|
|
+ current_device->deviceID, currentModbusParams->keyword);
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ sprintf(buf + strlen(buf), "{\"deviceId\":\"%s\",\"%s\": fail},",
|
|
|
|
+ current_device->deviceID, currentModbusParams->keyword);
|
|
|
|
+ }
|
|
|
|
+ currentModbusParams = currentModbusParams->nextParams;
|
|
|
|
+ if (currentModbusParams == NULL)
|
|
|
|
+ {
|
|
|
|
+ current_device = current_device->nextDevice;
|
|
|
|
+ currentModbusParams = current_device->params->gateway_read_modbus_command;
|
|
|
|
+ if(current_device == NULL)
|
|
|
|
+ {
|
|
|
|
+ sprintf(buf + strlen(buf) - 1, "");
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // дµ¥¸ö¼Ä´æÆ÷
|
|
|
|
+ if(currentModbusParams->functionCode == 0x06)
|
|
|
|
+ {
|
|
|
|
+ bool success = mmodbus_writeHoldingRegisters16i(currentModbusParams->slaveAddress,
|
|
|
|
+ currentModbusParams->registerAddress,
|
|
|
|
+ currentModbusParams->registerByteNum /2,
|
|
|
|
+ data);
|
|
|
|
+ if(success)
|
|
|
|
+ {
|
|
|
|
+ sprintf(buf + strlen(buf), "{\"deviceId\":\"%s\",\"%s\":write success},",
|
|
|
|
+ current_device->deviceID, currentModbusParams->keyword);
|
|
|
|
+ }
|
|
|
|
+ currentModbusParams = currentModbusParams->nextParams;
|
|
|
|
+ if (currentModbusParams == NULL)
|
|
|
|
+ {
|
|
|
|
+ current_device = current_device->nextDevice;
|
|
|
|
+ currentModbusParams = current_device->params->gateway_read_modbus_command;
|
|
|
|
+ if(current_device == NULL)
|
|
|
|
+ {
|
|
|
|
+ sprintf(buf + strlen(buf) - 1, "");
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
else if (current_device->protocol == DLT645_2007 || current_device->protocol == DLT645_97)
|
|
else if (current_device->protocol == DLT645_2007 || current_device->protocol == DLT645_97)
|
|
{
|
|
{
|
|
@@ -417,13 +359,13 @@ int read_device_data2(DEVICE_PARAMS *device, char* buf)
|
|
|
|
|
|
dltValue = currentDLT645Params->data[0] << 24 | currentDLT645Params->data[1] << 16|
|
|
dltValue = currentDLT645Params->data[0] << 24 | currentDLT645Params->data[1] << 16|
|
|
currentDLT645Params->data[2] << 8 | currentDLT645Params->data[3];
|
|
currentDLT645Params->data[2] << 8 | currentDLT645Params->data[3];
|
|
-
|
|
|
|
|
|
+
|
|
sprintf(buf + strlen(buf), "{\"identifier\":\"%s\",\"deviceID645\":\"%02x%02x%02x%02x%02x%02x\",\"identifier645\":%d,\"value\":%X}",
|
|
sprintf(buf + strlen(buf), "{\"identifier\":\"%s\",\"deviceID645\":\"%02x%02x%02x%02x%02x%02x\",\"identifier645\":%d,\"value\":%X}",
|
|
currentDLT645Params->keyword, currentDLT645Params->deviceID645[0],
|
|
currentDLT645Params->keyword, currentDLT645Params->deviceID645[0],
|
|
currentDLT645Params->deviceID645[1],currentDLT645Params->deviceID645[2],
|
|
currentDLT645Params->deviceID645[1],currentDLT645Params->deviceID645[2],
|
|
currentDLT645Params->deviceID645[3],currentDLT645Params->deviceID645[4],
|
|
currentDLT645Params->deviceID645[3],currentDLT645Params->deviceID645[4],
|
|
currentDLT645Params->deviceID645[5],currentDLT645Params->Identification,dltValue);
|
|
currentDLT645Params->deviceID645[5],currentDLT645Params->Identification,dltValue);
|
|
-
|
|
|
|
|
|
+ count++;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -446,10 +388,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)
|
|
@@ -459,12 +401,16 @@ void write_modbus_data(char* cJSONstring)
|
|
DEVICE_PARAMS* current_device = get->device_params;
|
|
DEVICE_PARAMS* current_device = get->device_params;
|
|
/* ÀûÓÃcJSOn_Parse½âÎöÊý¾Ý£¬»ñÈ¡¸÷ÀàÐÍÊý¾Ý */
|
|
/* ÀûÓÃcJSOn_Parse½âÎöÊý¾Ý£¬»ñÈ¡¸÷ÀàÐÍÊý¾Ý */
|
|
cJSON *root = cJSON_Parse(cJSONstring);
|
|
cJSON *root = cJSON_Parse(cJSONstring);
|
|
- const char *deviceId = cJSON_GetStringValue(cJSON_GetObjectItem(root, "deviceId"));
|
|
|
|
|
|
+ const char *deviceId = cJSON_GetStringValue(cJSON_GetObjectItem(root, "deviceId"));
|
|
|
|
+ const cJSON *func = cJSON_GetObjectItemCaseSensitive(root, "function");
|
|
const cJSON *power = cJSON_GetObjectItemCaseSensitive(root, "power");
|
|
const cJSON *power = cJSON_GetObjectItemCaseSensitive(root, "power");
|
|
const cJSON *temp = cJSON_GetObjectItemCaseSensitive(root, "temp");
|
|
const cJSON *temp = cJSON_GetObjectItemCaseSensitive(root, "temp");
|
|
const cJSON *mode = cJSON_GetObjectItemCaseSensitive(root, "mode");
|
|
const cJSON *mode = cJSON_GetObjectItemCaseSensitive(root, "mode");
|
|
const cJSON *fan = cJSON_GetObjectItemCaseSensitive(root, "fan");
|
|
const cJSON *fan = cJSON_GetObjectItemCaseSensitive(root, "fan");
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ const cJSON *slaveAddress = cJSON_GetObjectItemCaseSensitive(root, "slaveAddress");
|
|
|
|
+ const cJSON *registerAddress = cJSON_GetObjectItemCaseSensitive(root, "registerAddress");
|
|
|
|
+ const cJSON *cmd = cJSON_GetObjectItemCaseSensitive(root, "cmd");
|
|
while(current_device)
|
|
while(current_device)
|
|
{
|
|
{
|
|
char* device_ID = (char*)current_device->deviceID;
|
|
char* device_ID = (char*)current_device->deviceID;
|
|
@@ -472,6 +418,13 @@ void write_modbus_data(char* cJSONstring)
|
|
if(!strcmp(device_ID,deviceId)) //Æ¥ÅäID
|
|
if(!strcmp(device_ID,deviceId)) //Æ¥ÅäID
|
|
{
|
|
{
|
|
OSTimeDly(100);
|
|
OSTimeDly(100);
|
|
|
|
+ if(func->valueint == 5)
|
|
|
|
+ // ¿ª¹Ø·§ÃÅ
|
|
|
|
+ {
|
|
|
|
+ bool success = mmodbus_writeCoil(slaveAddress->valueint,registerAddress->valueint,cmd->valueint);
|
|
|
|
+ }
|
|
|
|
+ if(func->valueint == 6)
|
|
|
|
+ {
|
|
/* дÈë¼Ä´æÆ÷²Ù×÷ */
|
|
/* дÈë¼Ä´æÆ÷²Ù×÷ */
|
|
if(power)
|
|
if(power)
|
|
{
|
|
{
|
|
@@ -503,6 +456,8 @@ void write_modbus_data(char* cJSONstring)
|
|
currentModbusParams->registerAddress,
|
|
currentModbusParams->registerAddress,
|
|
fan->valueint);
|
|
fan->valueint);
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
current_device = current_device->nextDevice;
|
|
current_device = current_device->nextDevice;
|
|
}
|
|
}
|
|
@@ -511,10 +466,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)
|
|
@@ -527,10 +482,10 @@ 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);
|
|
-
|
|
|
|
|
|
+ memset(string,0,strlen(string));
|
|
while (token1 != NULL && token2 != NULL)
|
|
while (token1 != NULL && token2 != NULL)
|
|
{
|
|
{
|
|
if (strcmp(token1, token2) != 0)
|
|
if (strcmp(token1, token2) != 0)
|
|
@@ -541,7 +496,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);
|
|
@@ -559,49 +514,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,"ID: %d, {\"DEVICEID\":\"%s\",\"data\":[%s]}",ID++,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
|
|
|
|
}
|
|
}
|