Skip to content

Commit

Permalink
Built
Browse files Browse the repository at this point in the history
  • Loading branch information
NorthernMan54 committed Nov 29, 2024
1 parent 08073f6 commit 56aaa01
Show file tree
Hide file tree
Showing 182 changed files with 6,769 additions and 2,089 deletions.
29 changes: 15 additions & 14 deletions include/util.h → include/bit_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,11 @@
(at your option) any later version.
*/

#ifndef INCLUDE_UTIL_H_
#define INCLUDE_UTIL_H_
#ifndef INCLUDE_BIT_UTIL_H_
#define INCLUDE_BIT_UTIL_H_

#include <stdint.h>

// Helper macros, collides with MSVC's stdlib.h unless NOMINMAX is used
#ifndef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif

/// Reverse (reflect) the bits in an 32 bit byte.
///
/// @param x input byte
Expand Down Expand Up @@ -60,7 +52,7 @@ void reflect_nibbles(uint8_t message[], unsigned num_bytes);
/// @param num_bits message length in bits
/// @param dst target buffer for extracted nibbles, at least num_bits/5 size
/// @return number of successfully unstuffed nibbles.
unsigned extract_nibbles_4b1s(uint8_t *message, unsigned offset_bits, unsigned num_bits, uint8_t *dst);
unsigned extract_nibbles_4b1s(uint8_t const *message, unsigned offset_bits, unsigned num_bits, uint8_t *dst);

/// UART "8n1" (10-to-8) decoder with 1 start bit (0), no parity, 1 stop bit (1), LSB-first bit-order.
///
Expand All @@ -69,7 +61,16 @@ unsigned extract_nibbles_4b1s(uint8_t *message, unsigned offset_bits, unsigned n
/// @param num_bits message length in bits
/// @param dst target buffer for extracted bytes, at least num_bits/10 size
/// @return number of successful decoded bytes
unsigned extract_bytes_uart(uint8_t *message, unsigned offset_bits, unsigned num_bits, uint8_t *dst);
unsigned extract_bytes_uart(uint8_t const *message, unsigned offset_bits, unsigned num_bits, uint8_t *dst);

/// UART "8o1" (11-to-8) decoder with 1 start bit (1), odd parity, 1 stop bit (0), MSB-first bit-order.
///
/// @param message bytes of message data
/// @param offset_bits start offset of message in bits
/// @param num_bits message length in bits
/// @param dst target buffer for extracted bytes, at least num_bits/11 size
/// @return number of successful decoded bytes
unsigned extract_bytes_uart_parity(uint8_t const *message, unsigned offset_bits, unsigned num_bits, uint8_t *dst);

/// Decode symbols to bits.
///
Expand All @@ -81,7 +82,7 @@ unsigned extract_bytes_uart(uint8_t *message, unsigned offset_bits, unsigned num
/// @param sync symbol for sync bit, ignored at start, terminates at end
/// @param dst target buffer for extracted bits, at least num_bits/symbol_x_len size
/// @return number of successful decoded bits
unsigned extract_bits_symbols(uint8_t *message, unsigned offset_bits, unsigned num_bits, uint32_t zero, uint32_t one, uint32_t sync, uint8_t *dst);
unsigned extract_bits_symbols(uint8_t const *message, unsigned offset_bits, unsigned num_bits, uint32_t zero, uint32_t one, uint32_t sync, uint8_t *dst);

/// CRC-4.
///
Expand Down Expand Up @@ -204,4 +205,4 @@ int add_bytes(uint8_t const message[], unsigned num_bytes);
/// @return summation value
int add_nibbles(uint8_t const message[], unsigned num_bytes);

#endif /* INCLUDE_UTIL_H_ */
#endif /* INCLUDE_BIT_UTIL_H_ */
23 changes: 23 additions & 0 deletions include/c_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/** @file
General C language utility macro.
Copyright (C) 2018 Christian W. Zuckschwerdt <[email protected]>
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.
*/

#ifndef INCLUDE_C_UTIL_H_
#define INCLUDE_C_UTIL_H_

// Helper macros, collides with MSVC's stdlib.h unless NOMINMAX is used
#ifndef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif

#endif /* INCLUDE_C_UTIL_H_ */
39 changes: 39 additions & 0 deletions include/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,46 @@ R_API data_t *data_append(data_t *first, const char *key,
*/
R_API data_t *data_prepend(data_t *first, const char *key,
const char *pretty_key, ...);
/** Adds to a structured data object, by appending `int` data.
Type-safe alternative to `data_make()` and `data_append()`.
*/
R_API data_t *data_int(data_t *first, char const *key, char const *pretty_key, char const *format, int val);

/** Adds to a structured data object, by appending `double` data.
Type-safe alternative to `data_make()` and `data_append()`.
*/
R_API data_t *data_dbl(data_t *first, char const *key, char const *pretty_key, char const *format, double val);

/** Adds to a structured data object, by appending string data.
Type-safe alternative to `data_make()` and `data_append()`.
*/
R_API data_t *data_str(data_t *first, char const *key, char const *pretty_key, char const *format, char const *val);

/** Adds to a structured data object, by appending `data_array_t` data.
Type-safe alternative to `data_make()` and `data_append()`.
*/
R_API data_t *data_ary(data_t *first, char const *key, char const *pretty_key, char const *format, data_array_t *val);

/** Adds to a structured data object, by appending `data_t` data.
Type-safe alternative to `data_make()` and `data_append()`.
*/
R_API data_t *data_dat(data_t *first, char const *key, char const *pretty_key, char const *format, data_t *val);

/** Adds to a structured data object, by appending hex string data.
Type-safe alternative to `data_make()` and `data_append()`.
If `format` is NULL or empty then a default of "%02x" is used.
Caller needs to provide a sufficiently sized buffer.
*/
typedef unsigned char uint8_t;
R_API data_t *data_hex(data_t *first, char const *key, char const *pretty_key, char const *format, uint8_t const *val, unsigned len, char *buf);
/** Constructs an array from given data of the given uniform type.
@param num_values The number of values to be copied.
Expand Down
3 changes: 2 additions & 1 deletion include/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#include "r_device.h"
#include "bitbuffer.h"
#include "data.h"
#include "util.h"
#include "c_util.h"
#include "bit_util.h"
#include "decoder_util.h"

#endif /* INCLUDE_DECODER_H_ */
2 changes: 1 addition & 1 deletion include/decoder_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void decoder_logf(r_device *decoder, int level, char const *func, _Printf_format

/// Output a log message with the content of the bitbuffer.
void decoder_log_bitbuffer(r_device *decoder, int level, char const *func, const bitbuffer_t *bitbuffer, char const *msg);

int decoder_verbose(r_device *decoder);
/// Output a formatted log message with the content of the bitbuffer.
void decoder_logf_bitbuffer(r_device *decoder, int level, char const *func, const bitbuffer_t *bitbuffer, _Printf_format_string_ const char *format, ...)
#if defined(__GNUC__) || defined(__clang__)
Expand Down
2 changes: 1 addition & 1 deletion include/r_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
The line code is a coding of the bitstream data and referred to as the Coding of the data.
We however use the well known terms to refer to the combinations of this.
E.g. the term PWM is well known as anlog or discrete range modulation, but here used
E.g. the term PWM is well known as analog or discrete range modulation, but here used
to refer to a binary Coding of bits to on and off states (or mark and space) of the carrier.
It should be thought of as Pulse-Width-Coding, then modulated on OOK or FSK.
I.e. it is not truly Pulse-Width-Modulation but Pulse-Width-Coding then OOK or FSK modulation.
Expand Down
37 changes: 32 additions & 5 deletions include/rtl_433_devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
DECL(ambientweather_tx8300) \
DECL(ambientweather_wh31e) \
DECL(ant_antplus) \
DECL(arad_ms_meter) \
DECL(archos_tbh) \
DECL(arexx_ml) \
DECL(atech_ws308) \
DECL(auriol_4ld5661) \
DECL(auriol_aft77b2) \
Expand All @@ -39,13 +41,16 @@
DECL(bresser_5in1) \
DECL(bresser_6in1) \
DECL(bresser_7in1) \
DECL(bresser_leakage) \
DECL(bresser_lightning) \
DECL(bt_rain) \
DECL(burnhardbbq) \
DECL(calibeur_RF104) \
DECL(cardin) \
DECL(cavius) \
DECL(ced7000) \
DECL(celsia_czc1) \
DECL(chamberlain_cwpirc) \
DECL(chuango) \
DECL(cmr113) \
DECL(companion_wtr001) \
Expand Down Expand Up @@ -82,19 +87,24 @@
DECL(fineoffset_WH51) \
DECL(fineoffset_WH0530) \
DECL(fineoffset_wh1050) \
DECL(tfa_303151) \
DECL(fineoffset_wh1080) \
DECL(fineoffset_wh1080_fsk) \
DECL(fineoffset_wh31l) \
DECL(fineoffset_wh45) \
DECL(fineoffset_wh46) \
DECL(fineoffset_wh55) \
DECL(fineoffset_wn34) \
DECL(fineoffset_ws80) \
DECL(fineoffset_ws90) \
DECL(flowis) \
DECL(fordremote) \
DECL(fs20) \
DECL(ft004b) \
DECL(funkbus_remote) \
DECL(gasmate_ba1008) \
DECL(ge_coloreffects) \
DECL(geevon) \
DECL(generic_motion) \
DECL(generic_remote) \
DECL(generic_temperature_sensor) \
Expand Down Expand Up @@ -153,6 +163,7 @@
DECL(mebus433) \
DECL(megacode) \
DECL(missil_ml0757) \
DECL(mueller_hotrod) \
DECL(neptune_r900) \
DECL(new_template) \
DECL(newkaku) \
Expand Down Expand Up @@ -181,11 +192,14 @@
DECL(regency_fan) \
DECL(revolt_nc5462) \
DECL(rftech) \
DECL(risco_agility) \
DECL(rojaflex) \
DECL(rosstech_dcu706) \
DECL(rubicson) \
DECL(rubicson_48659) \
DECL(rubicson_pool_48942) \
DECL(s3318p) \
DECL(schou_72543_rain) \
DECL(schraeder) \
DECL(schrader_EG53MA4) \
DECL(schrader_SMD3MA4) \
Expand Down Expand Up @@ -213,9 +227,16 @@
DECL(tfa_twin_plus_303049) \
DECL(thermopro_tp11) \
DECL(thermopro_tp12) \
DECL(thermopro_tp28b) \
DECL(thermopro_tp828b) \
DECL(thermopro_tp829b) \
DECL(thermopro_tx2) \
DECL(thermopro_tx2c) \
DECL(thermor) \
DECL(tpms_abarth124) \
DECL(tpms_ave) \
DECL(tpms_bmw) \
DECL(tpms_bmwg3) \
DECL(tpms_citroen) \
DECL(tpms_eezrv) \
DECL(tpms_elantra2012) \
Expand All @@ -224,6 +245,7 @@
DECL(tpms_jansite) \
DECL(tpms_jansite_solar) \
DECL(tpms_kia) \
DECL(tpms_nissan) \
DECL(tpms_pmv107j) \
DECL(tpms_porsche) \
DECL(tpms_renault) \
Expand All @@ -235,7 +257,9 @@
DECL(ttx201) \
DECL(vaillant_vrt340f) \
DECL(vauno_en8822c) \
DECL(vevor_7in1) \
DECL(visonic_powercode) \
DECL(watts_thermostat) \
DECL(waveman) \
DECL(wec2103) \
DECL(wg_pb12v1) \
Expand All @@ -247,18 +271,21 @@
DECL(x10_sec) \
DECL(yale_hsa) \
/* Add new decoders here. */
# define NUMOF_OOK_DEVICES 157
# define NUMOF_FSK_DEVICES 80
# define NUMOF_OOK_DEVICES 164
# define NUMOF_FSK_DEVICES 97
/* Add new decoders here. */
#else
/**
* Subset of devices that I have access to and have tested with
*/
# define DEVICES \
DECL(lacrosse_tx141x) \
DECL(acurite_986) \
DECL(skylink_motion) \
DECL(prologue) \
DECL(philips_aj3650) \
DECL(fineoffset_WH51) \
/* Add new personal decoders here. */
# define NUMOF_OOK_DEVICES 1
# define NUMOF_FSK_DEVICES 0
# define NUMOFDEVICES 5
#endif

#define DECL(name) extern r_device name;
Expand Down
45 changes: 39 additions & 6 deletions src/rtl_433/util.c → src/rtl_433/bit_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
(at your option) any later version.
*/

#include "util.h"
#include "bit_util.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Expand All @@ -25,7 +26,7 @@ uint8_t reverse8(uint8_t x)
uint32_t reverse32(uint32_t x)
{
uint32_t ret;
uint8_t* xp = (uint8_t*)&x;
uint8_t const* xp = (uint8_t*)&x;
ret = (uint32_t) reverse8(xp[0]) << 24 | reverse8(xp[1]) << 16 | reverse8(xp[2]) << 8 | reverse8(xp[3]);
return ret;
}
Expand All @@ -51,7 +52,7 @@ void reflect_nibbles(uint8_t message[], unsigned num_bytes)
}
}

unsigned extract_nibbles_4b1s(uint8_t *message, unsigned offset_bits, unsigned num_bits, uint8_t *dst)
unsigned extract_nibbles_4b1s(uint8_t const *message, unsigned offset_bits, unsigned num_bits, uint8_t *dst)
{
unsigned ret = 0;

Expand All @@ -69,7 +70,7 @@ unsigned extract_nibbles_4b1s(uint8_t *message, unsigned offset_bits, unsigned n
return ret;
}

unsigned extract_bytes_uart(uint8_t *message, unsigned offset_bits, unsigned num_bits, uint8_t *dst)
unsigned extract_bytes_uart(uint8_t const *message, unsigned offset_bits, unsigned num_bits, uint8_t *dst)
{
unsigned ret = 0;

Expand All @@ -96,7 +97,39 @@ unsigned extract_bytes_uart(uint8_t *message, unsigned offset_bits, unsigned num
return ret;
}

static unsigned symbol_match(uint8_t *message, unsigned offset_bits, unsigned num_bits, uint32_t symbol)
unsigned extract_bytes_uart_parity(uint8_t const *message, unsigned offset_bits, unsigned num_bits, uint8_t *dst)
{
unsigned ret = 0;

while (num_bits >= 11) {
int startb = message[offset_bits / 8] >> (7 - (offset_bits % 8));
offset_bits += 1;
int datab = message[offset_bits / 8];
if (offset_bits % 8) {
datab = (message[offset_bits / 8] << 8) | message[offset_bits / 8 + 1];
datab >>= 8 - (offset_bits % 8);
}
offset_bits += 8;
int parityb = message[offset_bits / 8] >> (7 - (offset_bits % 8));
offset_bits += 1;
int stopb = message[offset_bits / 8] >> (7 - (offset_bits % 8));
offset_bits += 1;
int data_parity = parity8(datab);
if ((startb & 1) != 1)
break; // start-bit error
if ((parityb & 1) != data_parity)
break; // parity-bit error
if ((stopb & 1) != 0)
break; // stop-bit error
*dst++ = (datab & 0xff);
ret += 1;
num_bits -= 11;
}

return ret;
}

static unsigned symbol_match(uint8_t const *message, unsigned offset_bits, unsigned num_bits, uint32_t symbol)
{
unsigned symbol_len = symbol & 0x1f;

Expand All @@ -118,7 +151,7 @@ static unsigned symbol_match(uint8_t *message, unsigned offset_bits, unsigned nu
return symbol_len;
}

unsigned extract_bits_symbols(uint8_t *message, unsigned offset_bits, unsigned num_bits, uint32_t zero, uint32_t one, uint32_t sync, uint8_t *dst)
unsigned extract_bits_symbols(uint8_t const *message, unsigned offset_bits, unsigned num_bits, uint32_t zero, uint32_t one, uint32_t sync, uint8_t *dst)
{
unsigned zero_len = zero & 0x1f;
unsigned one_len = one & 0x1f;
Expand Down
Loading

0 comments on commit 56aaa01

Please sign in to comment.