Add support for EnOcean ERP1 decoder ()

This commit is contained in:
Christoph M. Wintersteiger 2021-10-11 07:38:47 +01:00 committed by GitHub
parent d257d6cee8
commit f0224c663d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 122 additions and 0 deletions

View file

@ -281,6 +281,7 @@ See [CONTRIBUTING.md](./docs/CONTRIBUTING.md).
[195] RainPoint soil temperature and moisture sensor
[196] Atech-WS308 temperature sensor
[197] Acurite Grill/Meat Thermometer 01185M
[198] EnOcean ERP1
* Disabled by default, use -R n or -G

View file

@ -418,6 +418,7 @@ stop_after_successful_events false
protocol 195 # RainPoint soil temperature and moisture sensor
protocol 196 # Atech-WS308 temperature sensor
protocol 197 # Acurite Grill/Meat Thermometer 01185M
protocol 198 # EnOcean ERP1
## Flex devices (command line option "-X")

View file

@ -205,6 +205,7 @@
DECL(rainpoint) \
DECL(atech_ws308) \
DECL(acurite_01185m) \
DECL(enocean_erp1) \
/* Add new decoders here. */

View file

@ -80,6 +80,7 @@ add_library(r_433 STATIC
devices/elro_db286a.c
devices/elv.c
devices/emontx.c
devices/enocean_erp1.c
devices/ert_idm.c
devices/ert_scm.c
devices/esa.c

114
src/devices/enocean_erp1.c Normal file
View file

@ -0,0 +1,114 @@
/** @file
EnOcean ERP1
Copyright (C) 2021 Christoph M. Wintersteiger <christoph@winterstiger.at>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
*/
/**
EnOcean Radio Protocol 1
868.3Mhz ASK, 125kbps, inverted, 8/12 coding
Spec: https://www.enocean.com/erp1/
*/
#include "decoder.h"
static int decode_8of12(uint8_t const *b, int pos, int end, bitbuffer_t *out)
{
if (pos + 12 > end)
return DECODE_ABORT_LENGTH;
bitbuffer_add_bit(out, bitrow_get_bit(b, pos + 0));
bitbuffer_add_bit(out, bitrow_get_bit(b, pos + 1));
uint8_t b2 = bitrow_get_bit(b, pos + 2);
bitbuffer_add_bit(out, b2);
if (b2 != !bitrow_get_bit(b, pos + 3))
return DECODE_FAIL_SANITY;
bitbuffer_add_bit(out, bitrow_get_bit(b, pos + 4));
bitbuffer_add_bit(out, bitrow_get_bit(b, pos + 5));
uint8_t b6 = bitrow_get_bit(b, pos + 6);
bitbuffer_add_bit(out, b6);
if (b6 != !bitrow_get_bit(b, pos + 7))
return DECODE_FAIL_SANITY;
bitbuffer_add_bit(out, bitrow_get_bit(b, pos + 8));
bitbuffer_add_bit(out, bitrow_get_bit(b, pos + 9));
return (bitrow_get_bit(b, pos + 10) << 1) | bitrow_get_bit(b, pos + 11);
}
static int enocean_erp1_decode(r_device *decoder, bitbuffer_t *bitbuffer)
{
if (bitbuffer->num_rows != 1)
return DECODE_ABORT_EARLY;
bitbuffer_invert(bitbuffer);
uint8_t preamble[2] = { 0x55, 0x20 };
unsigned start = bitbuffer_search(bitbuffer, 0, 0, preamble, 11);
if (start >= bitbuffer->bits_per_row[0])
return DECODE_FAIL_SANITY;
unsigned pos = start + 11;
unsigned len = bitbuffer->bits_per_row[0] - start;
unsigned end = start + len;
bitbuffer_t bytes = {0};
uint8_t more = 0x01;
do {
more = decode_8of12(bitbuffer->bb[0], pos, end, &bytes);
pos += 12;
} while (pos < end && more == 0x01);
if (bytes.bits_per_row[0] < 16)
return DECODE_ABORT_LENGTH;
uint8_t chk = crc8(bytes.bb[0], (bytes.bits_per_row[0] - 1) / 8, 0x07, 0x00);
if (chk != bitrow_get_byte(bytes.bb[0], bytes.bits_per_row[0] - 8))
return DECODE_FAIL_MIC;
/* clang-format off */
data_t *data = data_make(
"model", "", DATA_STRING, "EnOcean ERP1",
"mic", "Integrity", DATA_STRING, "CRC",
NULL);
/* clang-format on */
uint8_t* buf = bytes.bb[0];
size_t buf_sz = bytes.bits_per_row[0] / 8;
if (buf && buf_sz > 0) {
char tstr[256];
bitrow_snprint(buf, buf_sz * 8, tstr, sizeof (tstr));
data = data_append(data, "telegram", "", DATA_STRING, tstr, NULL);
}
decoder_output_data(decoder, data);
return 1;
}
static char *output_fields[] = {
"model",
"telegram",
"mic",
NULL,
};
r_device enocean_erp1 = {
.name = "EnOcean ERP1",
.modulation = OOK_PULSE_PCM_RZ,
.short_width = 8,
.long_width = 8,
.sync_width = 0,
.tolerance = 1,
.reset_limit = 800,
.decode_fn = &enocean_erp1_decode,
.fields = output_fields,
};

View file

@ -209,6 +209,7 @@ COPY ..\..\libusb\MS64\dll\libusb*.dll $(TargetDir)</Command>
<ClCompile Include="..\src\devices\elro_db286a.c" />
<ClCompile Include="..\src\devices\elv.c" />
<ClCompile Include="..\src\devices\emontx.c" />
<ClCompile Include="..\src\devices\enocean_erp1.c" />
<ClCompile Include="..\src\devices\ert_idm.c" />
<ClCompile Include="..\src\devices\ert_scm.c" />
<ClCompile Include="..\src\devices\esa.c" />

View file

@ -364,6 +364,9 @@
<ClCompile Include="..\src\devices\emontx.c">
<Filter>Source Files\devices</Filter>
</ClCompile>
<ClCompile Include="..\src\devices\enocean_erp1.c">
<Filter>Source Files\devices</Filter>
</ClCompile>
<ClCompile Include="..\src\devices\ert_idm.c">
<Filter>Source Files\devices</Filter>
</ClCompile>