Skip to content

Commit e04da9c

Browse files
committed
Add decode_mc flex option
1 parent 649344e commit e04da9c

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ Available options are:
441441
reflect : reflect each byte (MSB first to MSB last)
442442
decode_uart : UART 8n1 (10-to-8) decode
443443
decode_dm : Differential Manchester decode
444+
decode_mc : Manchester decode
444445
match=<bits> : only match if the <bits> are found
445446
preamble=<bits> : match and align at the <bits> preamble
446447
<bits> is a row spec of {<bit count>}<bits as hex number>

man/man1/rtl_433.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ decode_uart : UART 8n1 (10\-to\-8) decode
307307
decode_dm : Differential Manchester decode
308308
.RE
309309
.RS
310+
decode_mc : Manchester decode
311+
.RE
312+
.RS
310313
match=<bits> : only match if the <bits> are found
311314
.RE
312315
.RS

src/devices/flex.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ struct flex_params {
9898
struct flex_get getter[GETTER_SLOTS];
9999
unsigned decode_uart;
100100
unsigned decode_dm;
101+
unsigned decode_mc;
101102
char const *fields[7 + GETTER_SLOTS + 1]; // NOTE: needs to match output_fields
102103
};
103104

@@ -257,6 +258,19 @@ static int flex_callback(r_device *decoder, bitbuffer_t *bitbuffer)
257258
}
258259
}
259260

261+
// IEEE 802.3 MC, may need G.E.Thomas option (bitbuffer_invert_row())
262+
if (params->decode_mc) {
263+
for (i = 0; i < bitbuffer->num_rows; i++) {
264+
// TODO: refactor to bitbuffer_decode_mc_row()
265+
unsigned len = bitbuffer->bits_per_row[i];
266+
bitbuffer_t tmp = {0};
267+
bitbuffer_manchester_decode(bitbuffer, i, 0, &tmp, len);
268+
len = tmp.bits_per_row[0];
269+
memcpy(bitbuffer->bb[i], tmp.bb[0], (len + 7) / 8); // safe to write over: can only be shorter
270+
bitbuffer->bits_per_row[i] = len;
271+
}
272+
}
273+
260274
decoder_log_bitbuffer(decoder, 1, params->name, bitbuffer, "");
261275

262276
// discard duplicates
@@ -406,6 +420,7 @@ static void help(void)
406420
"\treflect : reflect each byte (MSB first to MSB last)\n"
407421
"\tdecode_uart : UART 8n1 (10-to-8) decode\n"
408422
"\tdecode_dm : Differential Manchester decode\n"
423+
"\tdecode_mc : Manchester decode\n"
409424
"\tmatch=<bits> : only match if the <bits> are found\n"
410425
"\tpreamble=<bits> : match and align at the <bits> preamble\n"
411426
"\t\t<bits> is a row spec of {<bit count>}<bits as hex number>\n"
@@ -716,6 +731,8 @@ r_device *flex_create_device(char *spec)
716731
params->decode_uart = parse_atoiv(val, 1, "decode_uart: ");
717732
else if (!strcasecmp(key, "decode_dm"))
718733
params->decode_dm = parse_atoiv(val, 1, "decode_dm: ");
734+
else if (!strcasecmp(key, "decode_mc"))
735+
params->decode_mc = parse_atoiv(val, 1, "decode_mc: ");
719736

720737
else if (!strcasecmp(key, "symbol_zero"))
721738
params->symbol_zero = parse_symbol(val);

0 commit comments

Comments
 (0)