diff --git a/mbus/mbus-protocol.c b/mbus/mbus-protocol.c index 968ace1..93ec8b1 100755 --- a/mbus/mbus-protocol.c +++ b/mbus/mbus-protocol.c @@ -2448,6 +2448,78 @@ mbus_data_record_value(mbus_data_record *record) return NULL; } +//------------------------------------------------------------------------------ +/// Return the storage number for a variable-length data record +//------------------------------------------------------------------------------ +long mbus_data_record_storage_number(mbus_data_record *record) +{ + int bit_index; + long result = 0; + int i; + + if (record) + { + result |= (record->drh.dib.dif & MBUS_DATA_RECORD_DIF_MASK_STORAGE_NO) >> 6; + bit_index++; + + for (i=0; idrh.dib.ndife; i++) + { + result |= (record->drh.dib.dife[i] & MBUS_DATA_RECORD_DIFE_MASK_STORAGE_NO) << bit_index; + bit_index += 4; + } + + return result; + } + + return 0; +} + +//------------------------------------------------------------------------------ +/// Return the tariff for a variable-length data record +//------------------------------------------------------------------------------ +long mbus_data_record_tariff(mbus_data_record *record) +{ + int bit_index; + long result = 0; + int i; + + if (record && (record->drh.dib.ndife > 0)) + { + for (i=0; idrh.dib.ndife; i++) + { + result |= ((record->drh.dib.dife[i] & MBUS_DATA_RECORD_DIFE_MASK_TARIFF) >> 4) << bit_index; + bit_index += 2; + } + + return result; + } + + return -1; +} + +//------------------------------------------------------------------------------ +/// Return device unit for a variable-length data record +//------------------------------------------------------------------------------ +int mbus_data_record_device(mbus_data_record *record) +{ + int bit_index; + int result = 0; + int i; + + if (record && (record->drh.dib.ndife > 0)) + { + for (i=0; idrh.dib.ndife; i++) + { + result |= ((record->drh.dib.dife[i] & MBUS_DATA_RECORD_DIFE_MASK_DEVICE) >> 6) << bit_index; + bit_index++; + } + + return result; + } + + return -1; +} + //------------------------------------------------------------------------------ /// Return a string containing the function description //------------------------------------------------------------------------------ diff --git a/mbus/mbus-protocol.h b/mbus/mbus-protocol.h index 290bf54..c63e089 100755 --- a/mbus/mbus-protocol.h +++ b/mbus/mbus-protocol.h @@ -566,6 +566,9 @@ int mbus_frame_internal_pack(mbus_frame *frame, mbus_frame_data *frame_data); // const char *mbus_data_record_function(mbus_data_record *record); const char *mbus_data_fixed_function(int status); +long mbus_data_record_storage_number(mbus_data_record *record); +long mbus_data_record_tariff(mbus_data_record *record); +int mbus_data_record_device(mbus_data_record *record); // // M-Bus frame data struct access/write functions