rtl433  UNKNOWN
RTL-433 utility
util.h
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_UTIL_H_
13 #define INCLUDE_UTIL_H_
14 
15 #include <stdint.h>
16 
17 // Helper macros, collides with MSVC's stdlib.h unless NOMINMAX is used
18 #ifndef MAX
19 #define MAX(a,b) ((a) > (b) ? (a) : (b))
20 #endif
21 #ifndef MIN
22 #define MIN(a,b) ((a) < (b) ? (a) : (b))
23 #endif
24 
30 
35 void reflect_bytes(uint8_t message[], unsigned num_bytes);
36 
42 
47 void reflect_nibbles(uint8_t message[], unsigned num_bytes);
48 
55 unsigned extract_nibbles_4b1s(uint8_t *message, unsigned offset_bits, unsigned num_bits, uint8_t *dst);
56 
64 uint8_t crc4(uint8_t const message[], unsigned nBytes, uint8_t polynomial, uint8_t init);
65 
73 uint8_t crc7(uint8_t const message[], unsigned nBytes, uint8_t polynomial, uint8_t init);
74 
85 uint8_t crc8(uint8_t const message[], unsigned nBytes, uint8_t polynomial, uint8_t init);
86 
95 uint8_t crc8le(uint8_t const message[], unsigned nBytes, uint8_t polynomial, uint8_t init);
96 
106 uint16_t crc16lsb(uint8_t const message[], unsigned nBytes, uint16_t polynomial, uint16_t init);
107 
115 uint16_t crc16(uint8_t const message[], unsigned nBytes, uint16_t polynomial, uint16_t init);
116 
124 uint8_t lfsr_digest8(uint8_t const message[], unsigned bytes, uint8_t gen, uint8_t key);
125 
133 uint16_t lfsr_digest16(uint32_t data, int bits, uint16_t gen, uint16_t key);
134 
139 int parity8(uint8_t byte);
140 
146 int parity_bytes(uint8_t const message[], unsigned num_bytes);
147 
153 uint8_t xor_bytes(uint8_t const message[], unsigned num_bytes);
154 
160 int add_bytes(uint8_t const message[], unsigned num_bytes);
161 
167 int add_nibbles(uint8_t const message[], unsigned num_bytes);
168 
169 #endif /* INCLUDE_UTIL_H_ */
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 nibble...
Definition: util.c:46
uint8_t crc8(uint8_t const message[], unsigned nBytes, uint8_t polynomial, uint8_t init)
Generic Cyclic Redundancy Check CRC-8.
Definition: util.c:102
uint8_t lfsr_digest8(uint8_t const message[], unsigned bytes, uint8_t gen, uint8_t key)
Digest-8 by "LFSR-based Toeplitz hash".
Definition: util.c:177
int add_nibbles(uint8_t const message[], unsigned num_bytes)
Compute Addition of a number of nibbles (byte wise).
Definition: util.c:283
unsigned short uint16_t
Definition: mongoose.h:271
int parity_bytes(uint8_t const message[], unsigned num_bytes)
Compute bit parity of a number of bytes.
Definition: util.c:256
uint8_t crc4(uint8_t const message[], unsigned nBytes, uint8_t polynomial, uint8_t init)
CRC-4.
Definition: util.c:64
uint16_t crc16(uint8_t const message[], unsigned nBytes, uint16_t polynomial, uint16_t init)
CRC-16.
Definition: util.c:158
int parity8(uint8_t byte)
Compute bit parity of a single byte (8 bits).
Definition: util.c:249
uint16_t lfsr_digest16(uint32_t data, int bits, uint16_t gen, uint16_t key)
Digest-16 by "LFSR-based Toeplitz hash".
Definition: util.c:199
uint8_t crc7(uint8_t const message[], unsigned nBytes, uint8_t polynomial, uint8_t init)
CRC-7.
Definition: util.c:83
uint16_t crc16lsb(uint8_t const message[], unsigned nBytes, uint16_t polynomial, uint16_t init)
CRC-16 LSB.
Definition: util.c:139
unsigned int uint32_t
Definition: mongoose.h:269
uint8_t reverse8(uint8_t x)
Reverse (reflect) the bits in an 8 bit byte.
Definition: util.c:17
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.
Definition: util.c:120
uint8_t reflect4(uint8_t x)
Reflect (reverse LSB to MSB) each nibble in an 8 bit byte, preserves nibble order.
Definition: util.c:32
void reflect_nibbles(uint8_t message[], unsigned num_bytes)
Reflect (reverse LSB to MSB) each nibble in a number of bytes.
Definition: util.c:39
void reflect_bytes(uint8_t message[], unsigned num_bytes)
Reflect (reverse LSB to MSB) each byte of a number of bytes.
Definition: util.c:25
unsigned char uint8_t
Definition: mongoose.h:267
uint8_t xor_bytes(uint8_t const message[], unsigned num_bytes)
Compute XOR (byte-wide parity) of a number of bytes.
Definition: util.c:265
int add_bytes(uint8_t const message[], unsigned num_bytes)
Compute Addition of a number of bytes.
Definition: util.c:274
Definition: data.h:58