Added receive timestamp for each data record in XML output
This commit is contained in:
parent
9fd35b781b
commit
0cb23161e7
@ -1367,6 +1367,8 @@ mbus_disconnect(mbus_handle * handle)
|
|||||||
int
|
int
|
||||||
mbus_recv_frame(mbus_handle * handle, mbus_frame *frame)
|
mbus_recv_frame(mbus_handle * handle, mbus_frame *frame)
|
||||||
{
|
{
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
if (handle == NULL)
|
if (handle == NULL)
|
||||||
{
|
{
|
||||||
MBUS_ERROR("%s: Invalid M-Bus handle for receive.\n", __PRETTY_FUNCTION__);
|
MBUS_ERROR("%s: Invalid M-Bus handle for receive.\n", __PRETTY_FUNCTION__);
|
||||||
@ -1375,13 +1377,20 @@ mbus_recv_frame(mbus_handle * handle, mbus_frame *frame)
|
|||||||
|
|
||||||
if (handle->is_serial)
|
if (handle->is_serial)
|
||||||
{
|
{
|
||||||
return mbus_serial_recv_frame(handle->m_serial_handle, frame);
|
result = mbus_serial_recv_frame(handle->m_serial_handle, frame);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return mbus_tcp_recv_frame(handle->m_tcp_handle, frame);
|
result = mbus_tcp_recv_frame(handle->m_tcp_handle, frame);
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
|
if (frame != NULL)
|
||||||
|
{
|
||||||
|
/* set timestamp to receive time */
|
||||||
|
time(&(frame->timestamp));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -2563,6 +2563,9 @@ mbus_data_variable_parse(mbus_frame *frame, mbus_data_variable *data)
|
|||||||
// clean up...
|
// clean up...
|
||||||
return (-2);
|
return (-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// copy timestamp
|
||||||
|
memcpy((void *)&(record->timestamp), (void *)&(frame->timestamp), sizeof(time_t));
|
||||||
|
|
||||||
// read and parse DIB (= DIF + DIFE)
|
// read and parse DIB (= DIF + DIFE)
|
||||||
|
|
||||||
@ -3275,6 +3278,8 @@ mbus_data_variable_record_xml(mbus_data_record *record, int record_cnt, int fram
|
|||||||
static char buff[8192];
|
static char buff[8192];
|
||||||
char str_encoded[768];
|
char str_encoded[768];
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
struct tm * timeinfo;
|
||||||
|
char timestamp[21];
|
||||||
int val;
|
int val;
|
||||||
|
|
||||||
if (record)
|
if (record)
|
||||||
@ -3314,6 +3319,11 @@ mbus_data_variable_record_xml(mbus_data_record *record, int record_cnt, int fram
|
|||||||
|
|
||||||
mbus_str_xml_encode(str_encoded, mbus_data_record_value(record), sizeof(str_encoded));
|
mbus_str_xml_encode(str_encoded, mbus_data_record_value(record), sizeof(str_encoded));
|
||||||
len += snprintf(&buff[len], sizeof(buff) - len, " <Value>%s</Value>\n", str_encoded);
|
len += snprintf(&buff[len], sizeof(buff) - len, " <Value>%s</Value>\n", str_encoded);
|
||||||
|
|
||||||
|
timeinfo = gmtime ( &(record->timestamp) );
|
||||||
|
strftime(timestamp,20,"%Y-%m-%dT%H:%M:%S",timeinfo);
|
||||||
|
len += snprintf(&buff[len], sizeof(buff) - len, " <Timestamp>%s</Timestamp>\n", timestamp);
|
||||||
|
|
||||||
len += snprintf(&buff[len], sizeof(buff) - len, " </DataRecord>\n\n");
|
len += snprintf(&buff[len], sizeof(buff) - len, " </DataRecord>\n\n");
|
||||||
|
|
||||||
return buff;
|
return buff;
|
||||||
|
@ -83,6 +83,7 @@ typedef struct _mbus_frame {
|
|||||||
size_t data_size;
|
size_t data_size;
|
||||||
|
|
||||||
int type;
|
int type;
|
||||||
|
time_t timestamp;
|
||||||
|
|
||||||
//mbus_frame_data frame_data;
|
//mbus_frame_data frame_data;
|
||||||
|
|
||||||
@ -145,6 +146,8 @@ typedef struct _mbus_data_record {
|
|||||||
u_char data[234];
|
u_char data[234];
|
||||||
size_t data_len;
|
size_t data_len;
|
||||||
|
|
||||||
|
time_t timestamp;
|
||||||
|
|
||||||
void *next;
|
void *next;
|
||||||
|
|
||||||
} mbus_data_record;
|
} mbus_data_record;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user