From 2a2fbc372a71cb643294a66a9a7dde5df4d6ef6e Mon Sep 17 00:00:00 2001 From: Ingo Fischer Date: Wed, 28 Mar 2018 14:26:06 +0200 Subject: [PATCH] make generated timestamps conform to ISO definition --- mbus/mbus-protocol-aux.c | 110 +++++++++++++++++++-------------------- mbus/mbus-protocol.c | 9 ++-- 2 files changed, 60 insertions(+), 59 deletions(-) diff --git a/mbus/mbus-protocol-aux.c b/mbus/mbus-protocol-aux.c index ea21e74..8877d62 100755 --- a/mbus/mbus-protocol-aux.c +++ b/mbus/mbus-protocol-aux.c @@ -154,17 +154,17 @@ mbus_variable_vif vif_table[] = { { 0x56, 1.0e3, "kg/h", "Mass flow" }, { 0x57, 1.0e4, "kg/h", "Mass flow" }, - /* E101 10nn Flow Temperature °C (0.001°C to 1°C) */ - { 0x58, 1.0e-3, "°C", "Flow temperature" }, - { 0x59, 1.0e-2, "°C", "Flow temperature" }, - { 0x5A, 1.0e-1, "°C", "Flow temperature" }, - { 0x5B, 1.0e0, "°C", "Flow temperature" }, + /* E101 10nn Flow Temperature °C (0.001°C to 1°C) */ + { 0x58, 1.0e-3, "°C", "Flow temperature" }, + { 0x59, 1.0e-2, "°C", "Flow temperature" }, + { 0x5A, 1.0e-1, "°C", "Flow temperature" }, + { 0x5B, 1.0e0, "°C", "Flow temperature" }, - /* E101 11nn Return Temperature °C (0.001°C to 1°C) */ - { 0x5C, 1.0e-3, "°C", "Return temperature" }, - { 0x5D, 1.0e-2, "°C", "Return temperature" }, - { 0x5E, 1.0e-1, "°C", "Return temperature" }, - { 0x5F, 1.0e0, "°C", "Return temperature" }, + /* E101 11nn Return Temperature °C (0.001°C to 1°C) */ + { 0x5C, 1.0e-3, "°C", "Return temperature" }, + { 0x5D, 1.0e-2, "°C", "Return temperature" }, + { 0x5E, 1.0e-1, "°C", "Return temperature" }, + { 0x5F, 1.0e0, "°C", "Return temperature" }, /* E110 00nn Temperature Difference K (mK to K) */ { 0x60, 1.0e-3, "K", "Temperature difference" }, @@ -172,11 +172,11 @@ mbus_variable_vif vif_table[] = { { 0x62, 1.0e-1, "K", "Temperature difference" }, { 0x63, 1.0e0, "K", "Temperature difference" }, - /* E110 01nn External Temperature °C (0.001°C to 1°C) */ - { 0x64, 1.0e-3, "°C", "External temperature" }, - { 0x65, 1.0e-2, "°C", "External temperature" }, - { 0x66, 1.0e-1, "°C", "External temperature" }, - { 0x67, 1.0e0, "°C", "External temperature" }, + /* E110 01nn External Temperature °C (0.001°C to 1°C) */ + { 0x64, 1.0e-3, "°C", "External temperature" }, + { 0x65, 1.0e-2, "°C", "External temperature" }, + { 0x66, 1.0e-1, "°C", "External temperature" }, + { 0x67, 1.0e0, "°C", "External temperature" }, /* E110 10nn Pressure bar (1mbar to 1000mbar) */ { 0x68, 1.0e-3, "bar", "Pressure" }, @@ -608,29 +608,29 @@ mbus_variable_vif vif_table[] = { { 0x256, 1.0e0, "Reserved", "Reserved" }, { 0x257, 1.0e0, "Reserved", "Reserved" }, - /* E101 10nn Flow Temperature 10(nn-3) °F 0.001°F to 1°F */ - { 0x258, 1.0e-3, "°F", "Flow temperature" }, - { 0x259, 1.0e-2, "°F", "Flow temperature" }, - { 0x25A, 1.0e-1, "°F", "Flow temperature" }, - { 0x25B, 1.0e0, "°F", "Flow temperature" }, + /* E101 10nn Flow Temperature 10(nn-3) °F 0.001°F to 1°F */ + { 0x258, 1.0e-3, "°F", "Flow temperature" }, + { 0x259, 1.0e-2, "°F", "Flow temperature" }, + { 0x25A, 1.0e-1, "°F", "Flow temperature" }, + { 0x25B, 1.0e0, "°F", "Flow temperature" }, - /* E101 11nn Return Temperature 10(nn-3) °F 0.001°F to 1°F */ - { 0x25C, 1.0e-3, "°F", "Return temperature" }, - { 0x25D, 1.0e-2, "°F", "Return temperature" }, - { 0x25E, 1.0e-1, "°F", "Return temperature" }, - { 0x25F, 1.0e0, "°F", "Return temperature" }, + /* E101 11nn Return Temperature 10(nn-3) °F 0.001°F to 1°F */ + { 0x25C, 1.0e-3, "°F", "Return temperature" }, + { 0x25D, 1.0e-2, "°F", "Return temperature" }, + { 0x25E, 1.0e-1, "°F", "Return temperature" }, + { 0x25F, 1.0e0, "°F", "Return temperature" }, - /* E110 00nn Temperature Difference 10(nn-3) °F 0.001°F to 1°F */ - { 0x260, 1.0e-3, "°F", "Temperature difference" }, - { 0x261, 1.0e-2, "°F", "Temperature difference" }, - { 0x262, 1.0e-1, "°F", "Temperature difference" }, - { 0x263, 1.0e0, "°F", "Temperature difference" }, + /* E110 00nn Temperature Difference 10(nn-3) °F 0.001°F to 1°F */ + { 0x260, 1.0e-3, "°F", "Temperature difference" }, + { 0x261, 1.0e-2, "°F", "Temperature difference" }, + { 0x262, 1.0e-1, "°F", "Temperature difference" }, + { 0x263, 1.0e0, "°F", "Temperature difference" }, - /* E110 01nn External Temperature 10(nn-3) °F 0.001°F to 1°F */ - { 0x264, 1.0e-3, "°F", "External temperature" }, - { 0x265, 1.0e-2, "°F", "External temperature" }, - { 0x266, 1.0e-1, "°F", "External temperature" }, - { 0x267, 1.0e0, "°F", "External temperature" }, + /* E110 01nn External Temperature 10(nn-3) °F 0.001°F to 1°F */ + { 0x264, 1.0e-3, "°F", "External temperature" }, + { 0x265, 1.0e-2, "°F", "External temperature" }, + { 0x266, 1.0e-1, "°F", "External temperature" }, + { 0x267, 1.0e0, "°F", "External temperature" }, /* E110 1nnn Reserved */ { 0x268, 1.0e0, "Reserved", "Reserved" }, @@ -642,19 +642,19 @@ mbus_variable_vif vif_table[] = { { 0x26E, 1.0e0, "Reserved", "Reserved" }, { 0x26F, 1.0e0, "Reserved", "Reserved" }, - /* E111 00nn Cold / Warm Temperature Limit 10(nn-3) °F 0.001°F to 1°F */ - { 0x270, 1.0e-3, "°F", "Cold / Warm Temperature Limit" }, - { 0x271, 1.0e-2, "°F", "Cold / Warm Temperature Limit" }, - { 0x272, 1.0e-1, "°F", "Cold / Warm Temperature Limit" }, - { 0x273, 1.0e0, "°F", "Cold / Warm Temperature Limit" }, + /* E111 00nn Cold / Warm Temperature Limit 10(nn-3) °F 0.001°F to 1°F */ + { 0x270, 1.0e-3, "°F", "Cold / Warm Temperature Limit" }, + { 0x271, 1.0e-2, "°F", "Cold / Warm Temperature Limit" }, + { 0x272, 1.0e-1, "°F", "Cold / Warm Temperature Limit" }, + { 0x273, 1.0e0, "°F", "Cold / Warm Temperature Limit" }, - /* E111 01nn Cold / Warm Temperature Limit 10(nn-3) °C 0.001°C to 1°C */ - { 0x274, 1.0e-3, "°C", "Cold / Warm Temperature Limit" }, - { 0x275, 1.0e-2, "°C", "Cold / Warm Temperature Limit" }, - { 0x276, 1.0e-1, "°C", "Cold / Warm Temperature Limit" }, - { 0x277, 1.0e0, "°C", "Cold / Warm Temperature Limit" }, + /* E111 01nn Cold / Warm Temperature Limit 10(nn-3) °C 0.001°C to 1°C */ + { 0x274, 1.0e-3, "°C", "Cold / Warm Temperature Limit" }, + { 0x275, 1.0e-2, "°C", "Cold / Warm Temperature Limit" }, + { 0x276, 1.0e-1, "°C", "Cold / Warm Temperature Limit" }, + { 0x277, 1.0e0, "°C", "Cold / Warm Temperature Limit" }, - /* E111 1nnn cumul. count max power § 10(nnn-3) W 0.001W to 10000W */ + /* E111 1nnn cumul. count max power § 10(nnn-3) W 0.001W to 10000W */ { 0x278, 1.0e-3, "W", "Cumul count max power" }, { 0x279, 1.0e-3, "W", "Cumul count max power" }, { 0x27A, 1.0e-1, "W", "Cumul count max power" }, @@ -730,7 +730,7 @@ mbus_variable_vif fixed_table[] = { { 0x36, 1.0e1, "m^3/h", "Volume flow" }, { 0x37, 1.0e2, "m^3/h", "Volume flow" }, - { 0x38, 1.0e-3, "°C", "Temperature" }, + { 0x38, 1.0e-3, "°C", "Temperature" }, { 0x39, 1.0e0, "Units for H.C.A.", "H.C.A." }, @@ -886,7 +886,7 @@ int mbus_variable_value_decode(mbus_data_record *record, double *value_out_real, else // normal integer { result = mbus_data_int_decode(record->data, 2, &value_out_int); - *value_out_real = value_out_int; + *value_out_real = value_out_int; } break; @@ -904,12 +904,12 @@ int mbus_variable_value_decode(mbus_data_record *record, double *value_out_real, ((record->drh.vib.vif == 0xFD) && (vife == 0x70))) { mbus_data_tm_decode(&time, record->data, 4); - if ((*value_out_str = (char*) malloc(20)) == NULL) + if ((*value_out_str = (char*) malloc(21)) == NULL) { MBUS_ERROR("Unable to allocate memory"); return -1; } - *value_out_str_size = snprintf(*value_out_str, 20, "%04d-%02d-%02dT%02d:%02d:%02d", + *value_out_str_size = snprintf(*value_out_str, 21, "%04d-%02d-%02dT%02d:%02d:%02dZ", (time.tm_year + 1900), (time.tm_mon + 1), time.tm_mday, @@ -921,7 +921,7 @@ int mbus_variable_value_decode(mbus_data_record *record, double *value_out_real, else // normal integer { result = mbus_data_int_decode(record->data, 4, &value_out_int); - *value_out_real = value_out_int; + *value_out_real = value_out_int; } break; @@ -939,12 +939,12 @@ int mbus_variable_value_decode(mbus_data_record *record, double *value_out_real, ((record->drh.vib.vif == 0xFD) && (vife == 0x70))) { mbus_data_tm_decode(&time, record->data, 6); - if ((*value_out_str = (char*) malloc(20)) == NULL) + if ((*value_out_str = (char*) malloc(21)) == NULL) { MBUS_ERROR("Unable to allocate memory"); return -1; } - *value_out_str_size = snprintf(*value_out_str, 20, "%04d-%02d-%02dT%02d:%02d:%02d", + *value_out_str_size = snprintf(*value_out_str, 21, "%04d-%02d-%02dT%02d:%02d:%02dZ", (time.tm_year + 1900), (time.tm_mon + 1), time.tm_mday, @@ -1286,7 +1286,7 @@ mbus_parse_variable_record(mbus_data_record *data) MBUS_ERROR("%s: memory allocation error\n", __PRETTY_FUNCTION__); return NULL; } - + record->storage_number = mbus_data_record_storage_number(data); record->tariff = mbus_data_record_tariff(data); record->device = mbus_data_record_device(data); @@ -2331,7 +2331,7 @@ mbus_probe_secondary_address(mbus_handle *handle, const char *mask, char *matchi if (addr == NULL) { // show error message, but procede with scan - MBUS_ERROR("Failed to generate secondary address from M-Bus reply frame: %s\n", + MBUS_ERROR("Failed to generate secondary address from M-Bus reply frame: %s\n", mbus_error_str()); return MBUS_PROBE_NOTHING; } diff --git a/mbus/mbus-protocol.c b/mbus/mbus-protocol.c index 03bd5d2..94773cd 100755 --- a/mbus/mbus-protocol.c +++ b/mbus/mbus-protocol.c @@ -3739,7 +3739,7 @@ mbus_hex_dump(const char *label, const char *buff, size_t len) { time_t rawtime; struct tm * timeinfo; - char timestamp[21]; + char timestamp[22]; size_t i; if (label == NULL || buff == NULL) @@ -3748,7 +3748,7 @@ mbus_hex_dump(const char *label, const char *buff, size_t len) time ( &rawtime ); timeinfo = gmtime ( &rawtime ); - strftime(timestamp,20,"%Y-%m-%d %H:%M:%S",timeinfo); + strftime(timestamp,21,"%Y-%m-%d %H:%M:%SZ",timeinfo); fprintf(stderr, "[%s] %s (%03zu):", timestamp, label, len); for (i = 0; i < len; i++) @@ -3767,6 +3767,7 @@ mbus_data_error_print(int error) return -1; } + //------------------------------------------------------------------------------ // // XML RELATED FUNCTIONS @@ -3886,7 +3887,7 @@ mbus_data_variable_record_xml(mbus_data_record *record, int record_cnt, int fram char str_encoded[768]; size_t len = 0; struct tm * timeinfo; - char timestamp[21]; + char timestamp[22]; long tariff; if (record) @@ -3942,7 +3943,7 @@ mbus_data_variable_record_xml(mbus_data_record *record, int record_cnt, int fram if (record->timestamp > 0) { timeinfo = gmtime (&(record->timestamp)); - strftime(timestamp,20,"%Y-%m-%dT%H:%M:%S",timeinfo); + strftime(timestamp,21,"%Y-%m-%dT%H:%M:%SZ",timeinfo); len += snprintf(&buff[len], sizeof(buff) - len, " %s\n", timestamp); }