|
@@ -15,7 +15,7 @@ ring_buffer mqttRecv;
|
|
void processHTTPjson(cJSON *json);
|
|
void processHTTPjson(cJSON *json);
|
|
char *processStringData(cJSON *data_obj, const char *key);
|
|
char *processStringData(cJSON *data_obj, const char *key);
|
|
int processIntData(cJSON *data_obj, const char *key);
|
|
int processIntData(cJSON *data_obj, const char *key);
|
|
-void processHttp(uint8_t *data);
|
|
|
|
|
|
+void processHttp(const uint8_t *data);
|
|
|
|
|
|
static void extract_data_from_buffer(const char *buffer, uint32_t *len_ptr, uint16_t *checkCode_ptr);
|
|
static void extract_data_from_buffer(const char *buffer, uint32_t *len_ptr, uint16_t *checkCode_ptr);
|
|
//static void extract_data_from_buffer232(const char *buffer, uint32_t *len_ptr, uint16_t *checkCode_ptr);
|
|
//static void extract_data_from_buffer232(const char *buffer, uint32_t *len_ptr, uint16_t *checkCode_ptr);
|
|
@@ -60,41 +60,18 @@ int processIntData(cJSON *data_obj, const char *key)
|
|
* 函数作用:等待更新本地flash信息
|
|
* 函数作用:等待更新本地flash信息
|
|
*/
|
|
*/
|
|
|
|
|
|
-bool WaitForUpData(void)
|
|
|
|
|
|
+bool WaitForUpData(char *dmaBuffer)
|
|
{
|
|
{
|
|
if (UART0_RX_STAT > 0)
|
|
if (UART0_RX_STAT > 0)
|
|
{
|
|
{
|
|
UART0_RX_STAT = 0;
|
|
UART0_RX_STAT = 0;
|
|
uint32_t len;
|
|
uint32_t len;
|
|
uint16_t checkCode;
|
|
uint16_t checkCode;
|
|
- extract_data_from_buffer(UART0_RX_BUF, &len, &checkCode);
|
|
|
|
-
|
|
|
|
- uint16_t jsonCheck = checksum(UART0_RX_BUF, len);
|
|
|
|
|
|
+ extract_data_from_buffer(dmaBuffer, &len, &checkCode);
|
|
|
|
+ uint16_t jsonCheck = checksum(dmaBuffer, len);
|
|
if (checkCode == jsonCheck)
|
|
if (checkCode == jsonCheck)
|
|
{
|
|
{
|
|
- memset(UART0_RX_BUF + len, 0, sizeof(UART0_RX_BUF) - len);
|
|
|
|
- if(UART0_RX_NUM<1024)
|
|
|
|
- {
|
|
|
|
- cJSON *json = cJSON_Parse(UART0_RX_BUF);
|
|
|
|
- if (json != NULL)
|
|
|
|
- {
|
|
|
|
- processHTTPjson(json);
|
|
|
|
- cJSON_Delete(json);
|
|
|
|
- Clear_DMA_Buffer();
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- cJSON_Delete(json);
|
|
|
|
- Clear_DMA_Buffer();
|
|
|
|
- LogPrint(LOG_INFO, __func__, __LINE__, "json is to long");
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- processHttp(UART0_RX_BUF);
|
|
|
|
- }
|
|
|
|
|
|
+ processHttp(dmaBuffer);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -103,7 +80,6 @@ bool WaitForUpData(void)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
/*
|
|
/*
|
|
* 函数名:static void extract_data_from_buffer(const char* buffer, uint32_t *len_ptr, uint16_t *checkCode_ptr)
|
|
* 函数名:static void extract_data_from_buffer(const char* buffer, uint32_t *len_ptr, uint16_t *checkCode_ptr)
|
|
* 输入参数:buffer字符串
|
|
* 输入参数:buffer字符串
|
|
@@ -237,43 +213,45 @@ void parseCommandData();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-void processHttp(uint8_t *data)
|
|
|
|
|
|
+void processHttp(const uint8_t *data)
|
|
{
|
|
{
|
|
- CONFIG_PARAMS gateway;
|
|
|
|
- gateway.data_valid_flag = 0xF1;
|
|
|
|
|
|
+ CONFIG_PARAMS *gateway;
|
|
|
|
+ gateway=get_config_params();
|
|
|
|
+ gateway->data_valid_flag = 0xF1;
|
|
char* ptr = (char*)data;
|
|
char* ptr = (char*)data;
|
|
|
|
|
|
|
|
|
|
- gateway.dataSource=parseIntField(ptr,"\"dataSource\":");
|
|
|
|
- gateway.baudrate=parseIntField(ptr,"\"baudrate\":");
|
|
|
|
- gateway.checkBit=parseIntField(ptr,"\"checkBit\":");
|
|
|
|
- parseStringField(ptr,"\"commandTopic\":\"",(char *)&gateway.commandTopic);
|
|
|
|
- gateway.dataBits=parseIntField(ptr,"\"dataBit\":");
|
|
|
|
- parseStringField(ptr,"\"deviceId\":\"",(char *)&gateway.deviceId);
|
|
|
|
- parseStringField(ptr,"\"host\":\"",(char *)&gateway.host);
|
|
|
|
- gateway.inboundTime=parseIntField(ptr,"\"inboundTime\":");
|
|
|
|
- parseStringField(ptr,"\"messageTopic\":\"",(char *)&gateway.messageTopic);
|
|
|
|
- gateway.pollTime=parseIntField(ptr,"\"pollTime\":");
|
|
|
|
- gateway.port=parseIntField(ptr,"\"port\":");
|
|
|
|
- if(gateway.dataSource==2) //为MODBUS
|
|
|
|
|
|
+ gateway->dataSource=parseIntField(ptr,"\"dataSource\":");
|
|
|
|
+ gateway->baudrate=parseIntField(ptr,"\"baudrate\":");
|
|
|
|
+ gateway->checkBit=parseIntField(ptr,"\"checkBit\":");
|
|
|
|
+ gateway->stopBit=parseIntField(ptr,"\"stopBit\":");
|
|
|
|
+ parseStringField(ptr,"\"commandTopic\":\"",(char *)&gateway->commandTopic);
|
|
|
|
+ gateway->dataBits=parseIntField(ptr,"\"dataBit\":");
|
|
|
|
+// parseStringField(ptr,"\"deviceId\":\"",(char *)&gateway->deviceId);
|
|
|
|
+ parseStringField(ptr,"\"host\":\"",(char *)&gateway->host);
|
|
|
|
+ gateway->inboundTime=parseIntField(ptr,"\"inboundTime\":");
|
|
|
|
+ parseStringField(ptr,"\"messageTopic\":\"",(char *)&gateway->messageTopic);
|
|
|
|
+ gateway->pollTime=parseIntField(ptr,"\"pollTime\":");
|
|
|
|
+ gateway->port=parseIntField(ptr,"\"port\":");
|
|
|
|
+ if(gateway->dataSource==2) //为MODBUS
|
|
{
|
|
{
|
|
ptr = strstr(ptr, "\"commandData\":[");
|
|
ptr = strstr(ptr, "\"commandData\":[");
|
|
int i=0;
|
|
int i=0;
|
|
while(1)
|
|
while(1)
|
|
{
|
|
{
|
|
- gateway.device_write_data[i].bigLittleFormat=parseIntField(ptr,"\"bigLittleFormat\":");
|
|
|
|
- parseStringField(ptr,"\"deviceId\":\"",(char *)&gateway.device_write_data[i].deviceId);
|
|
|
|
- parseStringField(ptr,"\"identifier\":\"",(char *)&gateway.device_write_data[i].keyword);
|
|
|
|
- gateway.device_write_data[i].registerLength =parseIntField(ptr,"\"registerByteNum\":\"");
|
|
|
|
- gateway.device_write_data[i].mdbRegister=parseIntField(ptr,"\"registerAddress\":");
|
|
|
|
- gateway.device_write_data[i].mdbSlave =parseIntField(ptr,"\"slaveAddress\":");
|
|
|
|
- gateway.device_write_data[i].mdbFunctionCode=parseIntField(ptr,"\"wFunctionCode\":");
|
|
|
|
|
|
+ gateway->device_write_data[i].bigLittleFormat=parseIntField(ptr,"\"bigLittleFormat\":");
|
|
|
|
+ parseStringField(ptr,"\"deviceId\":\"",(char *)&gateway->device_write_data[i].deviceId);
|
|
|
|
+ parseStringField(ptr,"\"identifier\":\"",(char *)&gateway->device_write_data[i].keyword);
|
|
|
|
+ gateway->device_write_data[i].registerLength =parseIntField(ptr,"\"registerByteNum\":\"");
|
|
|
|
+ gateway->device_write_data[i].mdbRegister=parseIntField(ptr,"\"registerAddress\":");
|
|
|
|
+ gateway->device_write_data[i].mdbSlave =parseIntField(ptr,"\"slaveAddress\":");
|
|
|
|
+ gateway->device_write_data[i].mdbFunctionCode=parseIntField(ptr,"\"wFunctionCode\":");
|
|
ptr=strstr(ptr,"}"); //移动位置到结束
|
|
ptr=strstr(ptr,"}"); //移动位置到结束
|
|
ptr++;
|
|
ptr++;
|
|
if(ptr[0]==']')
|
|
if(ptr[0]==']')
|
|
{
|
|
{
|
|
i++;
|
|
i++;
|
|
- gateway.device_write_data_num=i;
|
|
|
|
|
|
+ gateway->device_write_data_num=i;
|
|
ptr = (char*)data;
|
|
ptr = (char*)data;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -283,7 +261,7 @@ void processHttp(uint8_t *data)
|
|
if (!ptr)
|
|
if (!ptr)
|
|
{
|
|
{
|
|
i++;
|
|
i++;
|
|
- gateway.device_write_data_num=i;
|
|
|
|
|
|
+ gateway->device_write_data_num=i;
|
|
ptr = (char*)data;
|
|
ptr = (char*)data;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -293,20 +271,20 @@ void processHttp(uint8_t *data)
|
|
i=0;
|
|
i=0;
|
|
while(*ptr != ']')
|
|
while(*ptr != ']')
|
|
{
|
|
{
|
|
- gateway.device_read_data[i].bigLittleFormat=parseIntField(ptr,"\"bigLittleFormat\":");
|
|
|
|
- parseStringField(ptr,"\"deviceId\":\"",(char *)&gateway.device_read_data[i].deviceId);
|
|
|
|
- parseStringField(ptr,"\"identifier\":\"",(char *)&gateway.device_read_data[i].keyword);
|
|
|
|
- gateway.device_read_data[i].mdbRegister=parseIntField(ptr,"\"registerAddress\":");
|
|
|
|
- gateway.device_read_data[i].mdbSlave =parseIntField(ptr,"\"slaveAddress\":");
|
|
|
|
- gateway.device_read_data[i].registerLength =parseIntField(ptr,"\"registerByteNum\":");
|
|
|
|
- gateway.device_read_data[i].mdbFunctionCode=parseIntField(ptr,"\"rFunctionCode\":");
|
|
|
|
- gateway.device_read_data[i].decimalPoint=parseIntField(ptr,"\"precise\":");
|
|
|
|
|
|
+ gateway->device_read_data[i].bigLittleFormat=parseIntField(ptr,"\"bigLittleFormat\":");
|
|
|
|
+ parseStringField(ptr,"\"deviceId\":\"",(char *)&gateway->device_read_data[i].deviceId);
|
|
|
|
+ parseStringField(ptr,"\"identifier\":\"",(char *)&gateway->device_read_data[i].keyword);
|
|
|
|
+ gateway->device_read_data[i].mdbRegister=parseIntField(ptr,"\"registerAddress\":");
|
|
|
|
+ gateway->device_read_data[i].mdbSlave =parseIntField(ptr,"\"slaveAddress\":");
|
|
|
|
+ gateway->device_read_data[i].registerLength =parseIntField(ptr,"\"registerByteNum\":");
|
|
|
|
+ gateway->device_read_data[i].mdbFunctionCode=parseIntField(ptr,"\"rFunctionCode\":");
|
|
|
|
+ gateway->device_read_data[i].decimalPoint=parseIntField(ptr,"\"precise\":");
|
|
ptr=strstr(ptr,"}"); //移动位置到结束
|
|
ptr=strstr(ptr,"}"); //移动位置到结束
|
|
ptr++;
|
|
ptr++;
|
|
if(ptr[0]==']')
|
|
if(ptr[0]==']')
|
|
{
|
|
{
|
|
i++;
|
|
i++;
|
|
- gateway.device_read_data_num=i;
|
|
|
|
|
|
+ gateway->device_read_data_num=i;
|
|
ptr = (char*)data;
|
|
ptr = (char*)data;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -316,7 +294,7 @@ void processHttp(uint8_t *data)
|
|
if (!ptr)
|
|
if (!ptr)
|
|
{
|
|
{
|
|
i++;
|
|
i++;
|
|
- gateway.device_read_data_num=i;
|
|
|
|
|
|
+ gateway->device_read_data_num=i;
|
|
ptr = (char*)data;
|
|
ptr = (char*)data;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -324,9 +302,9 @@ void processHttp(uint8_t *data)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- else if(gateway.dataSource==1) //为dlt645协议
|
|
|
|
|
|
+ else if(gateway->dataSource==1) //为dlt645协议
|
|
{
|
|
{
|
|
- gateway.dataType645=parseIntField(ptr,"\"version645\":");
|
|
|
|
|
|
+ gateway->dataType645=parseIntField(ptr,"\"version645\":");
|
|
ptr=strstr(ptr,"\"sensorData\":[");
|
|
ptr=strstr(ptr,"\"sensorData\":[");
|
|
int i=0;
|
|
int i=0;
|
|
while(*ptr != ']')
|
|
while(*ptr != ']')
|
|
@@ -338,19 +316,19 @@ void processHttp(uint8_t *data)
|
|
{
|
|
{
|
|
uint8_t byte;
|
|
uint8_t byte;
|
|
sscanf((const char *)&string[j * 2], "%2hhx", &byte);
|
|
sscanf((const char *)&string[j * 2], "%2hhx", &byte);
|
|
- gateway.device_read_data[i].deviceID645[j] = byte;
|
|
|
|
|
|
+ gateway->device_read_data[i].deviceID645[j] = byte;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
free(string);
|
|
free(string);
|
|
- parseStringField(ptr, "\"deviceId\":\"",(char *)&gateway.device_read_data[i].deviceId);
|
|
|
|
- parseStringField(ptr, "\"identifier\":\"",(char *)&gateway.device_read_data[i].keyword);
|
|
|
|
- gateway.device_read_data[i].dataType645=parseIntField(ptr,"\"identifier645\":");
|
|
|
|
|
|
+ parseStringField(ptr, "\"deviceId\":\"",(char *)&gateway->device_read_data[i].deviceId);
|
|
|
|
+ parseStringField(ptr, "\"identifier\":\"",(char *)&gateway->device_read_data[i].keyword);
|
|
|
|
+ gateway->device_read_data[i].dataType645=parseIntField(ptr,"\"identifier645\":");
|
|
ptr=strstr(ptr,"}");
|
|
ptr=strstr(ptr,"}");
|
|
ptr++;
|
|
ptr++;
|
|
if(ptr[0]==']')
|
|
if(ptr[0]==']')
|
|
{
|
|
{
|
|
i++;
|
|
i++;
|
|
- gateway.device_read_data_num=i;
|
|
|
|
|
|
+ gateway->device_read_data_num=i;
|
|
ptr = (char*)data;
|
|
ptr = (char*)data;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -360,7 +338,7 @@ void processHttp(uint8_t *data)
|
|
if (!ptr)
|
|
if (!ptr)
|
|
{
|
|
{
|
|
i++;
|
|
i++;
|
|
- gateway.device_read_data_num=i;
|
|
|
|
|
|
+ gateway->device_read_data_num=i;
|
|
ptr = (char*)data;
|
|
ptr = (char*)data;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -368,7 +346,6 @@ void processHttp(uint8_t *data)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
ptr=NULL;
|
|
ptr=NULL;
|
|
- save_config_params(&gateway);
|
|
|
|
}
|
|
}
|
|
/*
|
|
/*
|
|
* 函数名: void mmodbusRead(CONFIG_PARAMS * gateway)
|
|
* 函数名: void mmodbusRead(CONFIG_PARAMS * gateway)
|