Skip to content

Commit

Permalink
minor: Cleanup AradMsMeter-Dialog3G code style
Browse files Browse the repository at this point in the history
  • Loading branch information
zuckschwerdt committed Jun 28, 2024
1 parent 5d35ca4 commit 7e4cef2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 47 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ See [CONTRIBUTING.md](./docs/CONTRIBUTING.md).
[257] BMW Gen3 TPMS
[258] Chamberlain CWPIRC PIR Sensor
[259] ThermoPro TP829b Meat Thermometer 4 coated probes
[260]* Arad/Master Meter Dialog3G water utility meter
* Disabled by default, use -R n or a conf file to enable
Expand Down
3 changes: 3 additions & 0 deletions conf/rtl_433.example.conf
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,9 @@ convert si
protocol 255 # Mueller Hot Rod water meter
protocol 256 # ThermoPro TP28b Super Long Range Wireless Meat Thermometer for Smoker BBQ Grill
protocol 257 # BMW Gen3 TPMS
protocol 258 # Chamberlain CWPIRC PIR Sensor
protocol 259 # ThermoPro TP829b Meat Thermometer 4 coated probes
# protocol 260 # Arad/Master Meter Dialog3G water utility meter

## Flex devices (command line option "-X")

Expand Down
87 changes: 40 additions & 47 deletions src/devices/arad_ms_meter.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/** @file
Arad/Master Meter Dialog3G water utility meter.
Copyright (C) 2022 avicarmeli
Expand All @@ -10,78 +9,72 @@
(at your option) any later version.
*/

/**
#include "decoder.h"

/**
Arad/Master Meter Dialog3G water utility meter.
FCC-Id: TKCET-733
Massage is being sent once every 30 second.
The massage look like that:
00000000FFFFFFFFFFFFFFSSSSSSSSXXCCCCCCXXXF?????????XFF
Message is being sent once every 30 seconds.
The message looks like:
00000000FFFFFFFFFFFFFFSSSSSSSSXXCCCCCCXXXF?????????XFF
where:
00000000 is preamble.
FFFFFFFFFFFFFF is fixed in time and the same for other meters in the neighborhood. Probably gearing ratio. The payload is 3e690aec7ac84b.
SSSSSSSS is Meter serial number. for instance fa1c9073 => fa1c90 = 09444602, little endian 73= 'S'
XX no idea.
CCCCCC is the counter reading little endian for instance a80600= 1704
XXX no idea.
F is fixed in time and the same for other meters in the neighborhood. With payload of 5.
????????? probably some kind of CRC or checksum - here is where I need help.
X is getting either 8 or 0 same for other meters in the neighborhood.
FF is fixed in time and the same for other meters in the neighborhood.With payload f8.
- 00000000 is preamble.
- FFFFFFFFFFFFFF is fixed in time and the same for other meters in the neighborhood. Probably gearing ratio. The payload is 3e690aec7ac84b.
- SSSSSSSS is Meter serial number. for instance fa1c9073 => fa1c90 = 09444602, little endian 73= 'S'
- XX no idea.
- CCCCCC is the counter reading little endian for instance a80600= 1704
- XXX no idea.
- F is fixed in time and the same for other meters in the neighborhood. With payload of 5.
- ????????? probably some kind of CRC or checksum - here is where I need help.
- X is getting either 8 or 0 same for other meters in the neighborhood.
- FF is fixed in time and the same for other meters in the neighborhood.With payload f8.
Format string:
56x SERIAL: <24dc 8x COUNTER: <24d hhhhhhhhhhhhhh SUFFIX:hh
*/
56x SERIAL: <24dc 8x COUNTER: <24d hhhhhhhhhhhhhh SUFFIX:hh
#include "decoder.h"
*/

static int arad_mm_dialog3g_decode(r_device *decoder, bitbuffer_t *bitbuffer)
{
uint8_t const preamble_pattern[] = {0x96, 0xf5, 0x13, 0x85, 0x37, 0xb4}; // 48 bit preamble
int row;
data_t *data;
uint8_t mdata[15];
bitbuffer_t databits = {0};

// fprintf(stderr,"arad_mm_dialog3g callback was triggered :-) \n");
// bitbuffer_print(bitbuffer);

row = bitbuffer_find_repeated_row(bitbuffer, 1, 168); // expected 1 row with minimum of 48+120= 168 bits.
if (row < 0)
int row = bitbuffer_find_repeated_row(bitbuffer, 1, 168); // expected 1 row with minimum of 48+120= 168 bits.
if (row < 0) {
return DECODE_ABORT_EARLY;
}

unsigned start_pos = bitbuffer_search(bitbuffer, row, 0, preamble_pattern, 48);
start_pos += 48; // skip preamble

if ((bitbuffer->bits_per_row[row] - start_pos) < 120)
if ((bitbuffer->bits_per_row[row] - start_pos) < 120) {
return DECODE_ABORT_LENGTH; // short buffer or preamble not found
}

bitbuffer_invert(bitbuffer);

// bitbuffer_print(bitbuffer);
uint8_t b[15];
bitbuffer_extract_bytes(bitbuffer, row, start_pos, b, 120);

bitbuffer_extract_bytes(bitbuffer, row, start_pos, mdata, 120);

uint32_t serno = mdata[0] | (mdata[1] << 8) | (mdata[2] << 16) | (0 << 24); // 24 bit little endian Meter Serial number
uint32_t wreadraw = mdata[5] | (mdata[6] << 8) | (mdata[7] << 16) | (0 << 24); // 24 bit little endian Meter water consumption reading
int serno = b[0] | (b[1] << 8) | (b[2] << 16); // 24 bit little endian Meter Serial number
int wreadraw = b[5] | (b[6] << 8) | (b[7] << 16); // 24 bit little endian Meter water consumption reading
float wread = wreadraw * 0.1f;

char sernoout[10];

sprintf(sernoout, "%08u%c", serno, mdata[3] - 32);

float wread = wreadraw;

wread = wread / 10;
sprintf(sernoout, "%08u%c", serno, b[3] - 32);

/* clang-format off */
data = data_make(
"model", "", DATA_STRING, "AradMsMeter-Dialog3G",
"id", "Serial No", DATA_STRING, sernoout,
"volume_m3", "Volume", DATA_FORMAT, "%.1f m3", DATA_DOUBLE, wread,
//"mic", "Integrity", DATA_STRING, "CHECKSUM",
NULL);
data_t *data = data_make(
"model", "", DATA_STRING, "AradMsMeter-Dialog3G",
"id", "Serial No", DATA_STRING, sernoout,
"volume_m3", "Volume", DATA_FORMAT, "%.1f m3", DATA_DOUBLE, wread,
//"mic", "Integrity", DATA_STRING, "CHECKSUM",
NULL);
/* clang-format on */

decoder_output_data(decoder, data);
Expand All @@ -100,9 +93,9 @@ r_device const arad_ms_meter = {
.name = "Arad/Master Meter Dialog3G water utility meter",
.modulation = FSK_PULSE_MANCHESTER_ZEROBIT,
.short_width = 8.4,
.long_width = 0, // not used
.long_width = 8.4, // not used
.reset_limit = 30,
.decode_fn = &arad_mm_dialog3g_decode,
.disabled = 1, // stop debug output from spamming unsuspecting users
.disabled = 1, // checksum not implemented
.fields = output_fields,
};

0 comments on commit 7e4cef2

Please sign in to comment.