diff --git a/mbus/mbus-protocol.c b/mbus/mbus-protocol.c index 210e008..81b30f2 100644 --- a/mbus/mbus-protocol.c +++ b/mbus/mbus-protocol.c @@ -560,6 +560,33 @@ mbus_data_str_decode(u_char *dst, const u_char *src, size_t len) } } +//------------------------------------------------------------------------------ +/// +/// Decode binary data. +/// +//------------------------------------------------------------------------------ +void +mbus_data_bin_decode(u_char *dst, const u_char *src, size_t len, size_t max_len) +{ + size_t i, pos; + + i = 0; + pos = 0; + + while((i < len) && ((pos+3) < max_len)) { + pos += snprintf(&dst[pos], max_len - pos, "%.2X ", src[i]); + i++; + } + + if (pos > 0) + { + // remove last space + pos--; + } + + dst[pos] = '\0'; +} + //------------------------------------------------------------------------------ /// /// Decode time data (usable for type f = 4 bytes or type g = 2 bytes) @@ -1720,7 +1747,7 @@ mbus_vib_unit_lookup(mbus_value_information_block *vib) const char * mbus_data_record_decode(mbus_data_record *record) { - static char buff[256]; + static char buff[768]; u_char vif, vife; // ignore extension bit @@ -1902,8 +1929,8 @@ mbus_data_record_decode(mbus_data_record *record) break; case 0x0F: // special functions - - snprintf(buff, sizeof(buff), "Special functions"); + + mbus_data_bin_decode(buff, record->data, record->data_len, sizeof(buff)); break; case 0x0D: // variable length @@ -1949,7 +1976,7 @@ mbus_data_record_unit(mbus_data_record *record) const char * mbus_data_record_value(mbus_data_record *record) { - static char buff[128]; + static char buff[768]; if (record) { @@ -2790,7 +2817,7 @@ char * mbus_data_variable_header_xml(mbus_data_variable_header *header) { static char buff[8192]; - char str_encoded[256]; + char str_encoded[768]; size_t len = 0; int val; @@ -2828,7 +2855,7 @@ mbus_data_variable_xml(mbus_data_variable *data) { mbus_data_record *record; static char buff[8192]; - char str_encoded[256]; + char str_encoded[768]; size_t len = 0; size_t i; @@ -2840,32 +2867,28 @@ mbus_data_variable_xml(mbus_data_variable *data) for (record = data->record, i = 0; record; record = record->next, i++) { + len += snprintf(&buff[len], sizeof(buff) - len, " \n", i); + if (record->drh.dib.dif == 0x0F) //MBUS_DIB_DIF_VENDOR_SPECIFIC) { - len += snprintf(&buff[len], sizeof(buff) - len, " \n", i); - len += snprintf(&buff[len], sizeof(buff) - len, " Manufacturer specific\n"); - len += snprintf(&buff[len], sizeof(buff) - len, " \n\n"); + len += snprintf(&buff[len], sizeof(buff) - len, " Manufacturer specific\n"); } else if (record->drh.dib.dif == 0x1F) { - len += snprintf(&buff[len], sizeof(buff) - len, " \n", i); len += snprintf(&buff[len], sizeof(buff) - len, " More records follow\n"); - len += snprintf(&buff[len], sizeof(buff) - len, " \n\n"); } else - { - len += snprintf(&buff[len], sizeof(buff) - len, " \n", i); - + { mbus_str_xml_encode(str_encoded, mbus_data_record_function(record), sizeof(str_encoded)); len += snprintf(&buff[len], sizeof(buff) - len, " %s\n", str_encoded); mbus_str_xml_encode(str_encoded, mbus_data_record_unit(record), sizeof(str_encoded)); len += snprintf(&buff[len], sizeof(buff) - len, " %s\n", str_encoded); - - mbus_str_xml_encode(str_encoded, mbus_data_record_value(record), sizeof(str_encoded)); - len += snprintf(&buff[len], sizeof(buff) - len, " %s\n", str_encoded); - len += snprintf(&buff[len], sizeof(buff) - len, " \n\n"); } + + mbus_str_xml_encode(str_encoded, mbus_data_record_value(record), sizeof(str_encoded)); + len += snprintf(&buff[len], sizeof(buff) - len, " %s\n", str_encoded); + len += snprintf(&buff[len], sizeof(buff) - len, " \n\n"); } len += snprintf(&buff[len], sizeof(buff) - len, "\n"); diff --git a/mbus/mbus-protocol.h b/mbus/mbus-protocol.h index 9f2aaeb..6f1dc13 100644 --- a/mbus/mbus-protocol.h +++ b/mbus/mbus-protocol.h @@ -519,6 +519,8 @@ void mbus_data_tm_decode(struct tm *t, u_char *t_data, size_t t_data_size); void mbus_data_str_decode(u_char *dst, const u_char *src, size_t len); +void mbus_data_bin_decode(u_char *dst, const u_char *src, size_t len, size_t max_len); + const char *mbus_data_fixed_medium(mbus_data_fixed *data); const char *mbus_data_fixed_unit(int medium_unit_byte); const char *mbus_data_variable_medium_lookup(u_char medium);