Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
krvmk authored Jun 15, 2024
2 parents 59a6a66 + 321f231 commit 9523319
Show file tree
Hide file tree
Showing 22 changed files with 358 additions and 253 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ See [CONTRIBUTING.md](./docs/CONTRIBUTING.md).
[45] emonTx OpenEnergyMonitor
[46] HT680 Remote control
[47] Conrad S3318P, FreeTec NC-5849-913 temperature humidity sensor, ORIA WA50 ST389 temperature sensor
[48] Akhan 100F14 remote keyless entry
[48]* Akhan 100F14 remote keyless entry
[49] Quhwa
[50] OSv1 Temperature Sensor
[51] Proove / Nexa / KlikAanKlikUit Wireless Switch
Expand Down Expand Up @@ -171,7 +171,7 @@ See [CONTRIBUTING.md](./docs/CONTRIBUTING.md).
[83] Oil Ultrasonic STANDARD ASK
[84] Thermopro TP11 Thermometer
[85] Solight TE44/TE66, EMOS E0107T, NX-6876-917
[86] Wireless Smoke and Heat Detector GS 558
[86]* Wireless Smoke and Heat Detector GS 558
[87] Generic wireless motion sensor
[88] Toyota TPMS
[89] Ford TPMS
Expand Down Expand Up @@ -343,9 +343,10 @@ See [CONTRIBUTING.md](./docs/CONTRIBUTING.md).
[255] Mueller Hot Rod water meter
[256] ThermoPro TP28b Super Long Range Wireless Meat Thermometer for Smoker BBQ Grill
[257] BMW Gen3 TPMS
[258] Landis & Gyr Gridstream Power Meters 9.6k
[259] Landis & Gyr Gridstream Power Meters 19.2k
[260] Landis & Gyr Gridstream Power Meters 38.4k
[258] Chamberlain CWPIRC PIR Sensor
[259] Landis & Gyr Gridstream Power Meters 9.6k
[260] Landis & Gyr Gridstream Power Meters 19.2k
[261] Landis & Gyr Gridstream Power Meters 38.4k
* Disabled by default, use -R n or a conf file to enable
Expand Down
6 changes: 3 additions & 3 deletions conf/rtl_433.example.conf
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ convert si
protocol 45 # emonTx OpenEnergyMonitor
protocol 46 # HT680 Remote control
protocol 47 # Conrad S3318P, FreeTec NC-5849-913 temperature humidity sensor, ORIA WA50 ST389 temperature sensor
protocol 48 # Akhan 100F14 remote keyless entry
# protocol 48 # Akhan 100F14 remote keyless entry
protocol 49 # Quhwa
protocol 50 # OSv1 Temperature Sensor
protocol 51 # Proove / Nexa / KlikAanKlikUit Wireless Switch
Expand Down Expand Up @@ -312,7 +312,7 @@ convert si
protocol 83 # Oil Ultrasonic STANDARD ASK
protocol 84 # Thermopro TP11 Thermometer
protocol 85 # Solight TE44/TE66, EMOS E0107T, NX-6876-917
protocol 86 # Wireless Smoke and Heat Detector GS 558
# protocol 86 # Wireless Smoke and Heat Detector GS 558
protocol 87 # Generic wireless motion sensor
protocol 88 # Toyota TPMS
protocol 89 # Ford TPMS
Expand Down Expand Up @@ -447,7 +447,7 @@ convert si
protocol 218 # Microchip HCS200/HCS300 KeeLoq Hopping Encoder based remotes (FSK)
protocol 219 # Fine Offset Electronics WH45 air quality sensor
protocol 220 # Maverick XR-30 BBQ Sensor
protocol 221 # Fine Offset Electronics WN34 temperature sensor
protocol 221 # Fine Offset Electronics WN34S/L/D and Froggit DP150/D35 temperature sensor
protocol 222 # Rubicson Pool Thermometer 48942
protocol 223 # Badger ORION water meter, 100kbps (-f 916.45M -s 1200k)
protocol 224 # GEO minim+ energy monitor
Expand Down
43 changes: 38 additions & 5 deletions include/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#endif

#include <stddef.h>
#include <stdint.h>

typedef enum {
DATA_DATA, /**< pointer to data is stored */
Expand Down Expand Up @@ -109,17 +110,49 @@ typedef struct data {
*/
R_API data_t *data_make(const char *key, const char *pretty_key, ...);

/** Adds to a structured data object, by appending data.
/** Adds to a structured data object, by prepending data.
@see data_make()
*/
R_API data_t *data_append(data_t *first, const char *key, const char *pretty_key, ...);
R_API data_t *data_prepend(data_t *first, const char *key, const char *pretty_key, ...);

/** Adds to a structured data object, by prepending data.
/** Adds to a structured data object, by appending `int` data.
@see data_make()
Type-safe alternative to `data_make()` and `data_append()`.
*/
R_API data_t *data_prepend(data_t *first, const char *key, const char *pretty_key, ...);
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()`.
Caller needs to provide a sufficiently sized buffer.
*/
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.
Expand Down
1 change: 1 addition & 0 deletions include/rtl_433_devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
DECL(mueller_hotrod) \
DECL(thermopro_tp28b) \
DECL(tpms_bmwg3) \
DECL(chamberlain_cwpirc) \
DECL(gridstream96) \
DECL(gridstream192) \
DECL(gridstream384) \
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ add_library(r_433 STATIC
devices/cavius.c
devices/ced7000.c
devices/celsia_czc1.c
devices/chamberlain_cwpirc.c
devices/chuango.c
devices/cmr113.c
devices/companion_wtr001.c
Expand Down
51 changes: 45 additions & 6 deletions src/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,13 @@ static data_t *vdata_make(data_t *first, const char *key, const char *pretty_key
fprintf(stderr, "vdata_make() format type used twice\n");
goto alloc_error;
}
format = strdup(va_arg(ap, char *));
if (!format) {
WARN_STRDUP("vdata_make()");
goto alloc_error;
format = va_arg(ap, char *);
if (format) {
format = strdup(format);
if (!format) {
WARN_STRDUP("vdata_make()");
goto alloc_error;
}
}
type = va_arg(ap, data_type_t);
continue;
Expand All @@ -203,7 +206,7 @@ static data_t *vdata_make(data_t *first, const char *key, const char *pretty_key
break;
case DATA_STRING:
value_release = (value_release_fn)free; // appease CSA checker
value.v_ptr = strdup(va_arg(ap, char *));
value.v_ptr = strdup(va_arg(ap, char const *));
if (!value.v_ptr)
WARN_STRDUP("vdata_make()");
break;
Expand Down Expand Up @@ -284,7 +287,7 @@ R_API data_t *data_make(const char *key, const char *pretty_key, ...)
return result;
}

R_API data_t *data_append(data_t *first, const char *key, const char *pretty_key, ...)
static data_t *data_append(data_t *first, const char *key, const char *pretty_key, ...)
{
va_list ap;
va_start(ap, pretty_key);
Expand All @@ -311,6 +314,42 @@ R_API data_t *data_prepend(data_t *first, const char *key, const char *pretty_ke
return result;
}

// Wrappers for now, should be refactored.
R_API data_t *data_int(data_t *first, char const *key, char const *pretty_key, char const *format, int val)
{
return data_append(first, key, pretty_key, DATA_FORMAT, format, DATA_INT, val, NULL);
}
R_API data_t *data_dbl(data_t *first, char const *key, char const *pretty_key, char const *format, double val)
{
return data_append(first, key, pretty_key, DATA_FORMAT, format, DATA_DOUBLE, val, NULL);
}
R_API data_t *data_str(data_t *first, char const *key, char const *pretty_key, char const *format, char const *val)
{
return data_append(first, key, pretty_key, DATA_FORMAT, format, DATA_STRING, val, NULL);
}
R_API data_t *data_ary(data_t *first, char const *key, char const *pretty_key, char const *format, data_array_t *val)
{
return data_append(first, key, pretty_key, DATA_FORMAT, format, DATA_ARRAY, val, NULL);
}
R_API data_t *data_dat(data_t *first, char const *key, char const *pretty_key, char const *format, data_t *val)
{
return data_append(first, key, pretty_key, DATA_FORMAT, format, DATA_DATA, val, NULL);
}
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)
{
if (!format || !*format) {
format = "%02x";
}

char *p = buf;
for (unsigned i = 0; i < len; i += 1) {
p += sprintf(p, format, val[i]);
}
*p = '\0';

return data_append(first, key, pretty_key, DATA_FORMAT, format, DATA_STRING, val, NULL);
}

R_API void data_array_free(data_array_t *array)
{
array_element_release_fn release = dmt[array->type].array_element_release;
Expand Down
12 changes: 3 additions & 9 deletions src/data_tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,7 @@ static data_t *append_filtered_json(data_t *data, char const *json, char const *
int len = MIN(v->end - v->start, (int)sizeof(buf) - 1);
memcpy(buf, json + v->start, len);
buf[len] = '\0';
data = data_append(data,
key, "", DATA_STRING, buf,
NULL);
data = data_str(data, key, "", NULL, buf);
}
}

Expand All @@ -299,9 +297,7 @@ data_t *data_tag_apply(data_tag_t *tag, data_t *data, char const *filename)
// wrap tag includes
data_t *obj = append_filtered_json(NULL, val, tag->includes);
// append tag wrapper
data = data_append(data,
tag->key, "", DATA_DATA, obj,
NULL);
data = data_dat(data, tag->key, "", NULL, obj);
}
else {
// append tag includes
Expand All @@ -310,9 +306,7 @@ data_t *data_tag_apply(data_tag_t *tag, data_t *data, char const *filename)
}
else {
// append tag string
data = data_append(data,
tag->key, "", DATA_STRING, val,
NULL);
data = data_str(data, tag->key, "", NULL, val);
}
return data;
}
Expand Down
8 changes: 2 additions & 6 deletions src/decoder_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ void decoder_log_bitbuffer(r_device *decoder, int level, char const *func, const
/* clang-format on */

if (decoder->verbose_bits) {
data_append(data,
"bits", "", DATA_ARRAY, data_array(num_rows, DATA_STRING, row_bits),
NULL);
data = data_ary(data, "bits", "", NULL, data_array(num_rows, DATA_STRING, row_bits));
}

decoder_output_log(decoder, level, data);
Expand Down Expand Up @@ -229,9 +227,7 @@ void decoder_log_bitrow(r_device *decoder, int level, char const *func, uint8_t

if (decoder->verbose_bits) {
row_bits = bitrow_asprint_bits(bitrow, bit_len);
data_append(data,
"bits", "", DATA_STRING, row_bits,
NULL);
data = data_str(data, "bits", "", NULL, row_bits);
}

decoder_output_log(decoder, level, data);
Expand Down
70 changes: 24 additions & 46 deletions src/devices/acurite.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,30 +139,6 @@ static char const *acurite_getChannel(uint8_t byte)
return channel_strs[channel];
}

// Add exception and raw message bytes to message to enable
// later analysis of unexpected/possibly undecoded data
static data_t *data_append_exception(data_t *data, int exception, uint8_t const *bb, int browlen)
{
char raw_str[31], *rawp;

rawp = (char *)raw_str;
for (int i = 0; i < browlen && (size_t)i < sizeof(raw_str) / 2; i++) {
sprintf(rawp,"%02x",bb[i]);
rawp += 2;
}
*rawp = '\0';

/* clang-format off */
data = data_append(data,
"exception", "Data Exception", DATA_INT, exception,
"raw_msg", "Raw Message", DATA_STRING, raw_str,
NULL);
/* clang-format on */

return data;
}


/**
Acurite 896 rain gauge
Expand Down Expand Up @@ -873,10 +849,8 @@ static int acurite_atlas_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsig


/* clang-format off */
data = data_append(data,
"temperature_F", "Temperature", DATA_FORMAT, "%.1f F", DATA_DOUBLE, tempf,
"humidity", NULL, DATA_FORMAT, "%u %%", DATA_INT, humidity,
NULL);
data = data_dbl(data, "temperature_F", "Temperature", "%.1f F", tempf);
data = data_int(data, "humidity", NULL, "%u %%", humidity);
/* clang-format on */
}

Expand Down Expand Up @@ -905,10 +879,8 @@ static int acurite_atlas_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsig
int raincounter = ((bb[5] & 0x03) << 7) | (bb[6] & 0x7F);

/* clang-format off */
data = data_append(data,
"wind_dir_deg", NULL, DATA_FORMAT, "%.1f", DATA_DOUBLE, wind_dir,
"rain_in", "Rainfall Accumulation", DATA_FORMAT, "%.2f in", DATA_DOUBLE, raincounter * 0.01f,
NULL);
data = data_dbl(data, "wind_dir_deg", NULL, "%.1f", wind_dir);
data = data_dbl(data, "rain_in", "Rainfall Accumulation", "%.2f in", raincounter * 0.01f);
/* clang-format on */
}

Expand All @@ -929,10 +901,8 @@ static int acurite_atlas_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsig
}

/* clang-format off */
data = data_append(data,
"uv", NULL, DATA_INT, uv,
"lux", NULL, DATA_INT, lux * 10,
NULL);
data = data_int(data, "uv", NULL, NULL, uv);
data = data_int(data, "lux", NULL, NULL, lux * 10);
/* clang-format on */
}

Expand All @@ -945,18 +915,14 @@ static int acurite_atlas_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsig
int strike_distance = bb[8] & 0x1f;

/* clang-format off */
data = data_append(data,
"strike_count", NULL, DATA_INT, strike_count,
"strike_distance", NULL, DATA_INT, strike_distance,
NULL);
data = data_int(data, "strike_count", NULL, NULL, strike_count);
data = data_int(data, "strike_distance", NULL, NULL, strike_distance);
/* clang-format on */
}

// @todo only do this if exception != 0, but would be somewhat incompatible
data = data_append(data,
"exception", "Data Exception", DATA_INT, exception,
"raw_msg", "Raw Message", DATA_STRING, raw_str,
NULL);
data = data_int(data, "exception", "Data Exception", NULL, exception);
data = data_str(data, "raw_msg", "Raw Message", NULL, raw_str);

decoder_output_data(decoder, data);

Expand Down Expand Up @@ -1045,7 +1011,13 @@ static int acurite_tower_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8
/* clang-format on */

if (exception) {
data = data_append_exception(data, exception, bb, ACURITE_TXR_BYTELEN);
// Add exception and raw message bytes to message to enable
// later analysis of unexpected/possibly undecoded data
/* clang-format off */
data = data_int(data, "exception", "Data Exception", NULL, exception);
char buf_str[31];
data = data_hex(data, "raw_msg", "Raw Message", NULL, bb, ACURITE_TXR_BYTELEN, buf_str);
/* clang-format on */
}

decoder_output_data(decoder, data);
Expand Down Expand Up @@ -1173,7 +1145,13 @@ static int acurite_515_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t
/* clang-format on */

if (exception) {
data = data_append_exception(data, exception, bb, ACURITE_515_BYTELEN);
// Add exception and raw message bytes to message to enable
// later analysis of unexpected/possibly undecoded data
/* clang-format off */
data = data_int(data, "exception", "Data Exception", NULL, exception);
char buf_str[31];
data = data_hex(data, "raw_msg", "Raw Message", NULL, bb, ACURITE_515_BYTELEN, buf_str);
/* clang-format on */
}

decoder_output_data(decoder, data);
Expand Down
Loading

0 comments on commit 9523319

Please sign in to comment.