rtl433  UNKNOWN
RTL-433 utility
util.h File Reference

Various utility functions for use by device drivers. More...

Go to the source code of this file.

Functions

uint8_t reverse8 (uint8_t x)
 Reverse (reflect) the bits in an 8 bit byte. More...
 
void reflect_bytes (uint8_t message[], unsigned num_bytes)
 Reflect (reverse LSB to MSB) each byte of a number of bytes. More...
 
uint8_t reflect4 (uint8_t x)
 Reflect (reverse LSB to MSB) each nibble in an 8 bit byte, preserves nibble order. More...
 
void reflect_nibbles (uint8_t message[], unsigned num_bytes)
 Reflect (reverse LSB to MSB) each nibble in a number of bytes. More...
 
unsigned extract_nibbles_4b1s (uint8_t *message, unsigned offset_bits, unsigned num_bits, uint8_t *dst)
 Unstuff nibbles with 1-bit separator (4B1S) to bytes, returns number of successfully unstuffed nibbles. More...
 
uint8_t crc4 (uint8_t const message[], unsigned nBytes, uint8_t polynomial, uint8_t init)
 CRC-4. More...
 
uint8_t crc7 (uint8_t const message[], unsigned nBytes, uint8_t polynomial, uint8_t init)
 CRC-7. More...
 
uint8_t crc8 (uint8_t const message[], unsigned nBytes, uint8_t polynomial, uint8_t init)
 Generic Cyclic Redundancy Check CRC-8. More...
 
uint8_t crc8le (uint8_t const message[], unsigned nBytes, uint8_t polynomial, uint8_t init)
 "Little-endian" Cyclic Redundancy Check CRC-8 LE Input and output are reflected, i.e. More...
 
uint16_t crc16lsb (uint8_t const message[], unsigned nBytes, uint16_t polynomial, uint16_t init)
 CRC-16 LSB. More...
 
uint16_t crc16 (uint8_t const message[], unsigned nBytes, uint16_t polynomial, uint16_t init)
 CRC-16. More...
 
uint8_t lfsr_digest8 (uint8_t const message[], unsigned bytes, uint8_t gen, uint8_t key)
 Digest-8 by "LFSR-based Toeplitz hash". More...
 
uint16_t lfsr_digest16 (uint32_t data, int bits, uint16_t gen, uint16_t key)
 Digest-16 by "LFSR-based Toeplitz hash". More...
 
int parity8 (uint8_t byte)
 Compute bit parity of a single byte (8 bits). More...
 
int parity_bytes (uint8_t const message[], unsigned num_bytes)
 Compute bit parity of a number of bytes. More...
 
uint8_t xor_bytes (uint8_t const message[], unsigned num_bytes)
 Compute XOR (byte-wide parity) of a number of bytes. More...
 
int add_bytes (uint8_t const message[], unsigned num_bytes)
 Compute Addition of a number of bytes. More...
 
int add_nibbles (uint8_t const message[], unsigned num_bytes)
 Compute Addition of a number of nibbles (byte wise). More...
 

Detailed Description

Various utility functions for use by device drivers.

Copyright (C) 2015 Tommy Vestermark

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.

Function Documentation

◆ add_bytes()

int add_bytes ( uint8_t const  message[],
unsigned  num_bytes 
)

Compute Addition of a number of bytes.

Parameters
messagebytes of message data
num_bytesnumber of bytes to sum
Returns
summation value

Referenced by acurite_txr_decode(), alecto_ws1200v2_callback(), alecto_ws1200v2_dcf_callback(), fineoffset_WH0530_callback(), fineoffset_WH25_callback(), lacrosse_ws7000_decode(), and opus_xt300_callback().

◆ add_nibbles()

int add_nibbles ( uint8_t const  message[],
unsigned  num_bytes 
)

Compute Addition of a number of nibbles (byte wise).

Parameters
messagebytes (of two nibbles) of message data
num_bytesnumber of bytes to sum
Returns
summation value

Referenced by oregon_scientific_sl109h_callback().

◆ crc16()

uint16_t crc16 ( uint8_t const  message[],
unsigned  nBytes,
uint16_t  polynomial,
uint16_t  init 
)

CRC-16.

Parameters
message[]array of bytes to check
nBytesnumber of bytes in message
polynomialCRC polynomial
initstarting crc value
Returns
CRC value

References bit().

Referenced by danfoss_cfr_callback(), data_output_mqtt_create(), efergy_optical_callback(), honeywell_callback(), ibis_beacon_callback(), ikea_sparsnas_callback(), and m_bus_crc_valid().

◆ crc16lsb()

uint16_t crc16lsb ( uint8_t const  message[],
unsigned  nBytes,
uint16_t  polynomial,
uint16_t  init 
)

CRC-16 LSB.

Input and output are reflected, i.e. least significant bit is shifted in first. Note that poly and init already need to be reflected.

Parameters
message[]array of bytes to check
nBytesnumber of bytes in message
polynomialCRC polynomial
initstarting crc value
Returns
CRC value

References bit().

Referenced by acurite_00275rm_decode(), emontx_callback(), and radiohead_ask_extract().

◆ crc4()

uint8_t crc4 ( uint8_t const  message[],
unsigned  nBytes,
uint8_t  polynomial,
uint8_t  init 
)

CRC-4.

Parameters
message[]array of bytes to check
nBytesnumber of bytes in message
polynomialCRC polynomial
initstarting crc value
Returns
CRC value

References bit().

Referenced by esperanza_ews_callback(), kedsum_callback(), philips_callback(), and s3318p_callback().

◆ crc7()

uint8_t crc7 ( uint8_t const  message[],
unsigned  nBytes,
uint8_t  polynomial,
uint8_t  init 
)

CRC-7.

Parameters
message[]array of bytes to check
nBytesnumber of bytes in message
polynomialCRC polynomial
initstarting crc value
Returns
CRC value

References bit().

◆ crc8()

uint8_t crc8 ( uint8_t const  message[],
unsigned  nBytes,
uint8_t  polynomial,
uint8_t  init 
)

Generic Cyclic Redundancy Check CRC-8.

Example polynomial: 0x31 = x8 + x5 + x4 + 1 (x8 is implicit) Example polynomial: 0x80 = x8 + x7 (a normal bit-by-bit parity XOR)

Parameters
message[]array of bytes to check
nBytesnumber of bytes in message
polynomialbyte is from x^7 to x^0 (x^8 is implicitly one)
initstarting crc value
Returns
CRC value

References bit().

Referenced by alecto_ws1200v1_callback(), alecto_ws1200v2_callback(), alecto_ws1200v2_dcf_callback(), ambientweather_wh31e_callback(), calibeur_rf104_callback(), ecowitt_decode(), fineoffset_WH0290_callback(), fineoffset_WH0530_callback(), fineoffset_wh1050_callback(), fineoffset_wh1080_callback(), fineoffset_WH24_callback(), fineoffset_WH2_callback(), hideki_ts04_callback(), lacrosse_it(), main(), new_template_decode(), rubicson_crc_check(), schraeder_callback(), tpms_pmv107j_decode(), tpms_renault_decode(), tpms_toyota_decode(), and wg_pb12v1_callback().

◆ crc8le()

uint8_t crc8le ( uint8_t const  message[],
unsigned  nBytes,
uint8_t  polynomial,
uint8_t  init 
)

"Little-endian" Cyclic Redundancy Check CRC-8 LE Input and output are reflected, i.e.

least significant bit is shifted in first.

Parameters
message[]array of bytes to check
nBytesnumber of bytes in message
polynomialCRC polynomial
initstarting crc value
Returns
CRC value

References bit(), and reverse8().

Referenced by acurite_986_decode(), dsc_callback(), and oil_watchman_callback().

◆ extract_nibbles_4b1s()

unsigned extract_nibbles_4b1s ( uint8_t message,
unsigned  offset_bits,
unsigned  num_bits,
uint8_t dst 
)

Unstuff nibbles with 1-bit separator (4B1S) to bytes, returns number of successfully unstuffed nibbles.

Parameters
messagebytes of message data
offset_bitsstart offset of message in bits
num_bitsmessage length in bits
dsttarget buffer for extracted nibbles, at least num_bits/5 size

Referenced by lacrosse_ws7000_decode().

◆ lfsr_digest16()

uint16_t lfsr_digest16 ( uint32_t  data,
int  bits,
uint16_t  gen,
uint16_t  key 
)

Digest-16 by "LFSR-based Toeplitz hash".

Parameters
dataup to 32 bits data, LSB aligned
bitsnumber of bits to digest
genkey stream generator, needs to includes the MSB if the LFSR is rolling
keyinitial key
Returns
digest value

References bit().

Referenced by maverick_et73x_callback(), and tfa_303196_callback().

◆ lfsr_digest8()

uint8_t lfsr_digest8 ( uint8_t const  message[],
unsigned  bytes,
uint8_t  gen,
uint8_t  key 
)

Digest-8 by "LFSR-based Toeplitz hash".

Parameters
messagebytes of message data
bytesnumber of bytes to digest
genkey stream generator, needs to includes the MSB if the LFSR is rolling
keyinitial key
Returns
digest value

Referenced by acurite_606_decode(), and ambient_weather_decode().

◆ parity8()

int parity8 ( uint8_t  byte)

Compute bit parity of a single byte (8 bits).

Parameters
bytesingle byte to check
Returns
1 odd parity, 0 even parity

Referenced by acurite_6045_decode(), acurite_txr_decode(), hideki_ts04_callback(), and parity_bytes().

◆ parity_bytes()

int parity_bytes ( uint8_t const  message[],
unsigned  num_bytes 
)

Compute bit parity of a number of bytes.

Parameters
messagebytes of message data
num_bytesnumber of bytes to sum
Returns
1 odd parity, 0 even parity

References parity8().

Referenced by companion_wtr001_decode(), and honeywell_wdb_callback().

◆ reflect4()

uint8_t reflect4 ( uint8_t  x)

Reflect (reverse LSB to MSB) each nibble in an 8 bit byte, preserves nibble order.

Parameters
xinput byte
Returns
reflected nibbles

Referenced by reflect_nibbles().

◆ reflect_bytes()

void reflect_bytes ( uint8_t  message[],
unsigned  num_bytes 
)

Reflect (reverse LSB to MSB) each byte of a number of bytes.

Parameters
messagebytes of message data
num_bytesnumber of bytes to reflect

References reverse8().

Referenced by hideki_ts04_callback(), and ts_ft002_decoder().

◆ reflect_nibbles()

void reflect_nibbles ( uint8_t  message[],
unsigned  num_bytes 
)

Reflect (reverse LSB to MSB) each nibble in a number of bytes.

Parameters
messagebytes of nibble message data
num_bytesnumber of bytes to reflect

References reflect4().

Referenced by lacrosse_ws7000_decode(), oregon_scientific_v2_1_decode(), and oregon_scientific_v3_decode().

◆ reverse8()

◆ xor_bytes()

uint8_t xor_bytes ( uint8_t const  message[],
unsigned  num_bytes 
)

Compute XOR (byte-wide parity) of a number of bytes.

Parameters
messagebytes of message data
num_bytesnumber of bytes to sum
Returns
summation value, per bit-position 1 odd parity, 0 even parity

Referenced by decode_xc0324_message(), fineoffset_WH25_callback(), hideki_ts04_callback(), lacrosse_ws7000_decode(), springfield_callback(), ts_ft002_decoder(), and wt450_callback().