[FL-2529][FL-1628] New LF-RFID subsystem (#1601)
* Makefile: unit tests pack * RFID: pulse joiner and its unit test * Move pulse protocol helpers to appropriate place * Drop pulse_joiner tests * Generic protocol, protocols dictionary, unit test * Protocol dict unit test * iButton: protocols dictionary * Lib: varint * Lib: profiler * Unit test: varint * rfid: worker mockup * LFRFID: em4100 unit test * Storage: file_exist function * rfid: fsk osc * rfid: generic fsk demodulator * rfid: protocol em4100 * rfid: protocol h10301 * rfid: protocol io prox xsf * Unit test: rfid protocols * rfid: new hal * rfid: raw worker * Unit test: fix error output * rfid: worker * rfid: plain c cli * fw: migrate to scons * lfrfid: full io prox support * unit test: io prox protocol * SubGHZ: move bit defines to source * FSK oscillator: level duration compability * libs: bit manipulation library * lfrfid: ioprox protocol, use bit library and new level duration method of FSK ocillator * bit lib: unit tests * Bit lib: parity tests, remove every nth bit, copy bits * Lfrfid: awid protocol * bit lib: uint16 and uint32 getters, unit tests * lfrfid: FDX-B read, draft version * Minunit: better memeq assert * bit lib: reverse, print, print regions * Protocol dict: get protocol features, get protocol validate count * lfrfid worker: improved read * lfrfid raw worker: psk support * Cli: rfid plain C cli * protocol AWID: render * protocol em4100: render * protocol h10301: render * protocol indala26: support every indala 26 scramble * Protocol IO Prox: render * Protocol FDX-B: advanced read * lfrfid: remove unused test function * lfrfid: fix os primitives * bit lib: crc16 and unit tests * FDX-B: save data * lfrfid worker: increase stream size. Alloc raw worker only when needed. * lfrfid: indala26 emulation * lfrfid: prepare to write * lfrfid: fdx-b emulation * lfrfid: awid, ioprox write * lfrfid: write t55xx w\o validation * lfrfid: better t55xx block0 handling * lfrfid: use new t5577 functions in worker * lfrfid: improve protocol description * lfrfid: write and verify * lfrfid: delete cpp cli * lfrfid: improve worker usage * lfrfid-app: step to new worker * lfrfid: old indala (I40134) load fallback * lfrfid: indala26, recover wrong synced data * lfrfid: remove old worker * lfrfid app: dummy read screen * lfrfid app: less dummy read screen * lfrfid: generic 96-bit HID protocol (covers up to HID 37-bit) * rename * lfrfid: improve indala26 read * lfrfid: generic 192-bit HID protocol (covers all HID extended) * lfrfid: TODO about HID render * lfrfid: new protocol FDX-A * lfrfid-app: correct worker stop on exit * misc fixes * lfrfid: FDX-A and HID distinguishability has been fixed. * lfrfid: decode HID size header and render it (#1612) * lfrfid: rename HID96 and HID192 to HIDProx and HIDExt * lfrfid: extra actions scene * lfrfid: decode generic HID Proximity size lazily (#1618) * lib: stream of data buffers concept * lfrfid: raw file helper * lfrfid: changed raw worker api * lfrfid: packed varint pair * lfrfid: read stream speedup * lfrfid app: show read mode * Documentation * lfrfid app: raw read gui * lfrfid app: storage check for raw read * memleak fix * review fixes * lfrfid app: read blink color * lfrfid app: reset key name after read * review fixes * lfrfid app: fix copypasted text * review fixes * lfrfid: disable debug gpio * lfrfid: card detection events * lfrfid: change validation color from magenta to green * Update core_defines. * lfrfid: prefix fdx-b id by zeroes * lfrfid: parse up to 43-bit HID Proximity keys (#1640) * Fbt: downgrade toolchain and fix PS1 * lfrfid: fix unit tests * lfrfid app: remove printf * lfrfid: indala26, use bit 55 as data * lfrfid: indala26, better brief format * lfrfid: indala26, loading fallback * lfrfid: read timing tuning Co-authored-by: James Ide <ide@users.noreply.github.com> Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
473
applications/unit_tests/lfrfid/bit_lib_test.c
Normal file
473
applications/unit_tests/lfrfid/bit_lib_test.c
Normal file
@@ -0,0 +1,473 @@
|
||||
#include <furi.h>
|
||||
#include "../minunit.h"
|
||||
#include <lfrfid/tools/bit_lib.h>
|
||||
|
||||
MU_TEST(test_bit_lib_increment_index) {
|
||||
uint32_t index = 0;
|
||||
|
||||
// test increment
|
||||
for(uint32_t i = 0; i < 31; ++i) {
|
||||
bit_lib_increment_index(index, 32);
|
||||
mu_assert_int_eq(i + 1, index);
|
||||
}
|
||||
|
||||
// test wrap around
|
||||
for(uint32_t i = 0; i < 512; ++i) {
|
||||
bit_lib_increment_index(index, 32);
|
||||
mu_assert_int_less_than(32, index);
|
||||
}
|
||||
}
|
||||
|
||||
MU_TEST(test_bit_lib_is_set) {
|
||||
uint32_t value = 0x0000FFFF;
|
||||
|
||||
for(uint32_t i = 0; i < 16; ++i) {
|
||||
mu_check(bit_lib_bit_is_set(value, i));
|
||||
mu_check(!bit_lib_bit_is_not_set(value, i));
|
||||
}
|
||||
|
||||
for(uint32_t i = 16; i < 32; ++i) {
|
||||
mu_check(!bit_lib_bit_is_set(value, i));
|
||||
mu_check(bit_lib_bit_is_not_set(value, i));
|
||||
}
|
||||
}
|
||||
|
||||
MU_TEST(test_bit_lib_push) {
|
||||
#define TEST_BIT_LIB_PUSH_DATA_SIZE 4
|
||||
uint8_t data[TEST_BIT_LIB_PUSH_DATA_SIZE] = {0};
|
||||
uint8_t expected_data_1[TEST_BIT_LIB_PUSH_DATA_SIZE] = {0x00, 0x00, 0x0F, 0xFF};
|
||||
uint8_t expected_data_2[TEST_BIT_LIB_PUSH_DATA_SIZE] = {0x00, 0xFF, 0xF0, 0x00};
|
||||
uint8_t expected_data_3[TEST_BIT_LIB_PUSH_DATA_SIZE] = {0xFF, 0x00, 0x00, 0xFF};
|
||||
uint8_t expected_data_4[TEST_BIT_LIB_PUSH_DATA_SIZE] = {0xFF, 0xFF, 0xFF, 0xFF};
|
||||
uint8_t expected_data_5[TEST_BIT_LIB_PUSH_DATA_SIZE] = {0x00, 0x00, 0x00, 0x00};
|
||||
uint8_t expected_data_6[TEST_BIT_LIB_PUSH_DATA_SIZE] = {0xCC, 0xCC, 0xCC, 0xCC};
|
||||
|
||||
for(uint32_t i = 0; i < 12; ++i) {
|
||||
bit_lib_push_bit(data, TEST_BIT_LIB_PUSH_DATA_SIZE, true);
|
||||
}
|
||||
mu_assert_mem_eq(expected_data_1, data, TEST_BIT_LIB_PUSH_DATA_SIZE);
|
||||
|
||||
for(uint32_t i = 0; i < 12; ++i) {
|
||||
bit_lib_push_bit(data, TEST_BIT_LIB_PUSH_DATA_SIZE, false);
|
||||
}
|
||||
mu_assert_mem_eq(expected_data_2, data, TEST_BIT_LIB_PUSH_DATA_SIZE);
|
||||
|
||||
for(uint32_t i = 0; i < 4; ++i) {
|
||||
bit_lib_push_bit(data, TEST_BIT_LIB_PUSH_DATA_SIZE, false);
|
||||
}
|
||||
for(uint32_t i = 0; i < 8; ++i) {
|
||||
bit_lib_push_bit(data, TEST_BIT_LIB_PUSH_DATA_SIZE, true);
|
||||
}
|
||||
mu_assert_mem_eq(expected_data_3, data, TEST_BIT_LIB_PUSH_DATA_SIZE);
|
||||
|
||||
for(uint32_t i = 0; i < TEST_BIT_LIB_PUSH_DATA_SIZE * 8; ++i) {
|
||||
bit_lib_push_bit(data, TEST_BIT_LIB_PUSH_DATA_SIZE, true);
|
||||
}
|
||||
mu_assert_mem_eq(expected_data_4, data, TEST_BIT_LIB_PUSH_DATA_SIZE);
|
||||
|
||||
for(uint32_t i = 0; i < TEST_BIT_LIB_PUSH_DATA_SIZE * 8; ++i) {
|
||||
bit_lib_push_bit(data, TEST_BIT_LIB_PUSH_DATA_SIZE, false);
|
||||
}
|
||||
mu_assert_mem_eq(expected_data_5, data, TEST_BIT_LIB_PUSH_DATA_SIZE);
|
||||
|
||||
for(uint32_t i = 0; i < TEST_BIT_LIB_PUSH_DATA_SIZE * 2; ++i) {
|
||||
bit_lib_push_bit(data, TEST_BIT_LIB_PUSH_DATA_SIZE, true);
|
||||
bit_lib_push_bit(data, TEST_BIT_LIB_PUSH_DATA_SIZE, true);
|
||||
bit_lib_push_bit(data, TEST_BIT_LIB_PUSH_DATA_SIZE, false);
|
||||
bit_lib_push_bit(data, TEST_BIT_LIB_PUSH_DATA_SIZE, false);
|
||||
}
|
||||
mu_assert_mem_eq(expected_data_6, data, TEST_BIT_LIB_PUSH_DATA_SIZE);
|
||||
}
|
||||
|
||||
MU_TEST(test_bit_lib_set_bit) {
|
||||
uint8_t value[2] = {0x00, 0xFF};
|
||||
bit_lib_set_bit(value, 15, false);
|
||||
mu_assert_mem_eq(value, ((uint8_t[]){0x00, 0xFE}), 2);
|
||||
bit_lib_set_bit(value, 14, false);
|
||||
mu_assert_mem_eq(value, ((uint8_t[]){0x00, 0xFC}), 2);
|
||||
bit_lib_set_bit(value, 13, false);
|
||||
mu_assert_mem_eq(value, ((uint8_t[]){0x00, 0xF8}), 2);
|
||||
bit_lib_set_bit(value, 12, false);
|
||||
mu_assert_mem_eq(value, ((uint8_t[]){0x00, 0xF0}), 2);
|
||||
bit_lib_set_bit(value, 11, false);
|
||||
mu_assert_mem_eq(value, ((uint8_t[]){0x00, 0xE0}), 2);
|
||||
bit_lib_set_bit(value, 10, false);
|
||||
mu_assert_mem_eq(value, ((uint8_t[]){0x00, 0xC0}), 2);
|
||||
bit_lib_set_bit(value, 9, false);
|
||||
mu_assert_mem_eq(value, ((uint8_t[]){0x00, 0x80}), 2);
|
||||
bit_lib_set_bit(value, 8, false);
|
||||
mu_assert_mem_eq(value, ((uint8_t[]){0x00, 0x00}), 2);
|
||||
|
||||
bit_lib_set_bit(value, 7, true);
|
||||
mu_assert_mem_eq(value, ((uint8_t[]){0x01, 0x00}), 2);
|
||||
bit_lib_set_bit(value, 6, true);
|
||||
mu_assert_mem_eq(value, ((uint8_t[]){0x03, 0x00}), 2);
|
||||
bit_lib_set_bit(value, 5, true);
|
||||
mu_assert_mem_eq(value, ((uint8_t[]){0x07, 0x00}), 2);
|
||||
bit_lib_set_bit(value, 4, true);
|
||||
mu_assert_mem_eq(value, ((uint8_t[]){0x0F, 0x00}), 2);
|
||||
bit_lib_set_bit(value, 3, true);
|
||||
mu_assert_mem_eq(value, ((uint8_t[]){0x1F, 0x00}), 2);
|
||||
bit_lib_set_bit(value, 2, true);
|
||||
mu_assert_mem_eq(value, ((uint8_t[]){0x3F, 0x00}), 2);
|
||||
bit_lib_set_bit(value, 1, true);
|
||||
mu_assert_mem_eq(value, ((uint8_t[]){0x7F, 0x00}), 2);
|
||||
bit_lib_set_bit(value, 0, true);
|
||||
mu_assert_mem_eq(value, ((uint8_t[]){0xFF, 0x00}), 2);
|
||||
}
|
||||
|
||||
MU_TEST(test_bit_lib_set_bits) {
|
||||
uint8_t value[2] = {0b00000000, 0b11111111};
|
||||
// set 4 bits to 0b0100 from 12 index
|
||||
bit_lib_set_bits(value, 12, 0b0100, 4);
|
||||
// [0100]
|
||||
mu_assert_mem_eq(value, ((uint8_t[]){0b00000000, 0b11110100}), 2);
|
||||
|
||||
// set 2 bits to 0b11 from 11 index
|
||||
bit_lib_set_bits(value, 11, 0b11, 2);
|
||||
// [11]
|
||||
mu_assert_mem_eq(value, ((uint8_t[]){0b00000000, 0b11111100}), 2);
|
||||
|
||||
// set 3 bits to 0b111 from 0 index
|
||||
bit_lib_set_bits(value, 0, 0b111, 3);
|
||||
// [111]
|
||||
mu_assert_mem_eq(value, ((uint8_t[]){0b11100000, 0b11111100}), 2);
|
||||
|
||||
// set 8 bits to 0b11111000 from 3 index
|
||||
bit_lib_set_bits(value, 3, 0b11111000, 8);
|
||||
// [11111 000]
|
||||
mu_assert_mem_eq(value, ((uint8_t[]){0b11111111, 0b00011100}), 2);
|
||||
}
|
||||
|
||||
MU_TEST(test_bit_lib_get_bit) {
|
||||
uint8_t value[2] = {0b00000000, 0b11111111};
|
||||
for(uint32_t i = 0; i < 8; ++i) {
|
||||
mu_check(bit_lib_get_bit(value, i) == false);
|
||||
}
|
||||
for(uint32_t i = 8; i < 16; ++i) {
|
||||
mu_check(bit_lib_get_bit(value, i) == true);
|
||||
}
|
||||
}
|
||||
|
||||
MU_TEST(test_bit_lib_get_bits) {
|
||||
uint8_t value[2] = {0b00000000, 0b11111111};
|
||||
mu_assert_int_eq(0b00000000, bit_lib_get_bits(value, 0, 8));
|
||||
mu_assert_int_eq(0b00000001, bit_lib_get_bits(value, 1, 8));
|
||||
mu_assert_int_eq(0b00000011, bit_lib_get_bits(value, 2, 8));
|
||||
mu_assert_int_eq(0b00000111, bit_lib_get_bits(value, 3, 8));
|
||||
mu_assert_int_eq(0b00001111, bit_lib_get_bits(value, 4, 8));
|
||||
mu_assert_int_eq(0b00011111, bit_lib_get_bits(value, 5, 8));
|
||||
mu_assert_int_eq(0b00111111, bit_lib_get_bits(value, 6, 8));
|
||||
mu_assert_int_eq(0b01111111, bit_lib_get_bits(value, 7, 8));
|
||||
mu_assert_int_eq(0b11111111, bit_lib_get_bits(value, 8, 8));
|
||||
}
|
||||
|
||||
MU_TEST(test_bit_lib_get_bits_16) {
|
||||
uint8_t value[2] = {0b00001001, 0b10110001};
|
||||
mu_assert_int_eq(0b0, bit_lib_get_bits_16(value, 0, 1));
|
||||
mu_assert_int_eq(0b00, bit_lib_get_bits_16(value, 0, 2));
|
||||
mu_assert_int_eq(0b000, bit_lib_get_bits_16(value, 0, 3));
|
||||
mu_assert_int_eq(0b0000, bit_lib_get_bits_16(value, 0, 4));
|
||||
mu_assert_int_eq(0b00001, bit_lib_get_bits_16(value, 0, 5));
|
||||
mu_assert_int_eq(0b000010, bit_lib_get_bits_16(value, 0, 6));
|
||||
mu_assert_int_eq(0b0000100, bit_lib_get_bits_16(value, 0, 7));
|
||||
mu_assert_int_eq(0b00001001, bit_lib_get_bits_16(value, 0, 8));
|
||||
mu_assert_int_eq(0b000010011, bit_lib_get_bits_16(value, 0, 9));
|
||||
mu_assert_int_eq(0b0000100110, bit_lib_get_bits_16(value, 0, 10));
|
||||
mu_assert_int_eq(0b00001001101, bit_lib_get_bits_16(value, 0, 11));
|
||||
mu_assert_int_eq(0b000010011011, bit_lib_get_bits_16(value, 0, 12));
|
||||
mu_assert_int_eq(0b0000100110110, bit_lib_get_bits_16(value, 0, 13));
|
||||
mu_assert_int_eq(0b00001001101100, bit_lib_get_bits_16(value, 0, 14));
|
||||
mu_assert_int_eq(0b000010011011000, bit_lib_get_bits_16(value, 0, 15));
|
||||
mu_assert_int_eq(0b0000100110110001, bit_lib_get_bits_16(value, 0, 16));
|
||||
}
|
||||
|
||||
MU_TEST(test_bit_lib_get_bits_32) {
|
||||
uint8_t value[4] = {0b00001001, 0b10110001, 0b10001100, 0b01100010};
|
||||
mu_assert_int_eq(0b0, bit_lib_get_bits_32(value, 0, 1));
|
||||
mu_assert_int_eq(0b00, bit_lib_get_bits_32(value, 0, 2));
|
||||
mu_assert_int_eq(0b000, bit_lib_get_bits_32(value, 0, 3));
|
||||
mu_assert_int_eq(0b0000, bit_lib_get_bits_32(value, 0, 4));
|
||||
mu_assert_int_eq(0b00001, bit_lib_get_bits_32(value, 0, 5));
|
||||
mu_assert_int_eq(0b000010, bit_lib_get_bits_32(value, 0, 6));
|
||||
mu_assert_int_eq(0b0000100, bit_lib_get_bits_32(value, 0, 7));
|
||||
mu_assert_int_eq(0b00001001, bit_lib_get_bits_32(value, 0, 8));
|
||||
mu_assert_int_eq(0b000010011, bit_lib_get_bits_32(value, 0, 9));
|
||||
mu_assert_int_eq(0b0000100110, bit_lib_get_bits_32(value, 0, 10));
|
||||
mu_assert_int_eq(0b00001001101, bit_lib_get_bits_32(value, 0, 11));
|
||||
mu_assert_int_eq(0b000010011011, bit_lib_get_bits_32(value, 0, 12));
|
||||
mu_assert_int_eq(0b0000100110110, bit_lib_get_bits_32(value, 0, 13));
|
||||
mu_assert_int_eq(0b00001001101100, bit_lib_get_bits_32(value, 0, 14));
|
||||
mu_assert_int_eq(0b000010011011000, bit_lib_get_bits_32(value, 0, 15));
|
||||
mu_assert_int_eq(0b0000100110110001, bit_lib_get_bits_32(value, 0, 16));
|
||||
mu_assert_int_eq(0b00001001101100011, bit_lib_get_bits_32(value, 0, 17));
|
||||
mu_assert_int_eq(0b000010011011000110, bit_lib_get_bits_32(value, 0, 18));
|
||||
mu_assert_int_eq(0b0000100110110001100, bit_lib_get_bits_32(value, 0, 19));
|
||||
mu_assert_int_eq(0b00001001101100011000, bit_lib_get_bits_32(value, 0, 20));
|
||||
mu_assert_int_eq(0b000010011011000110001, bit_lib_get_bits_32(value, 0, 21));
|
||||
mu_assert_int_eq(0b0000100110110001100011, bit_lib_get_bits_32(value, 0, 22));
|
||||
mu_assert_int_eq(0b00001001101100011000110, bit_lib_get_bits_32(value, 0, 23));
|
||||
mu_assert_int_eq(0b000010011011000110001100, bit_lib_get_bits_32(value, 0, 24));
|
||||
mu_assert_int_eq(0b0000100110110001100011000, bit_lib_get_bits_32(value, 0, 25));
|
||||
mu_assert_int_eq(0b00001001101100011000110001, bit_lib_get_bits_32(value, 0, 26));
|
||||
mu_assert_int_eq(0b000010011011000110001100011, bit_lib_get_bits_32(value, 0, 27));
|
||||
mu_assert_int_eq(0b0000100110110001100011000110, bit_lib_get_bits_32(value, 0, 28));
|
||||
mu_assert_int_eq(0b00001001101100011000110001100, bit_lib_get_bits_32(value, 0, 29));
|
||||
mu_assert_int_eq(0b000010011011000110001100011000, bit_lib_get_bits_32(value, 0, 30));
|
||||
mu_assert_int_eq(0b0000100110110001100011000110001, bit_lib_get_bits_32(value, 0, 31));
|
||||
mu_assert_int_eq(0b00001001101100011000110001100010, bit_lib_get_bits_32(value, 0, 32));
|
||||
}
|
||||
|
||||
MU_TEST(test_bit_lib_test_parity_u32) {
|
||||
// test even parity
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00000000, BitLibParityEven), 0);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00000001, BitLibParityEven), 1);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00000010, BitLibParityEven), 1);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00000011, BitLibParityEven), 0);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00000100, BitLibParityEven), 1);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00000101, BitLibParityEven), 0);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00000110, BitLibParityEven), 0);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00000111, BitLibParityEven), 1);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00001000, BitLibParityEven), 1);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00001001, BitLibParityEven), 0);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00001010, BitLibParityEven), 0);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00001011, BitLibParityEven), 1);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00001100, BitLibParityEven), 0);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00001101, BitLibParityEven), 1);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00001110, BitLibParityEven), 1);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00001111, BitLibParityEven), 0);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00010000, BitLibParityEven), 1);
|
||||
|
||||
// test odd parity
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00000000, BitLibParityOdd), 1);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00000001, BitLibParityOdd), 0);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00000010, BitLibParityOdd), 0);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00000011, BitLibParityOdd), 1);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00000100, BitLibParityOdd), 0);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00000101, BitLibParityOdd), 1);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00000110, BitLibParityOdd), 1);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00000111, BitLibParityOdd), 0);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00001000, BitLibParityOdd), 0);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00001001, BitLibParityOdd), 1);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00001010, BitLibParityOdd), 1);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00001011, BitLibParityOdd), 0);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00001100, BitLibParityOdd), 1);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00001101, BitLibParityOdd), 0);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00001110, BitLibParityOdd), 0);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00001111, BitLibParityOdd), 1);
|
||||
mu_assert_int_eq(bit_lib_test_parity_32(0b00010000, BitLibParityOdd), 0);
|
||||
}
|
||||
|
||||
MU_TEST(test_bit_lib_test_parity) {
|
||||
// next data contains valid parity for 1-3 nibble and invalid for 4 nibble
|
||||
uint8_t data_always_0_parity[2] = {0b11101110, 0b11101111};
|
||||
uint8_t data_always_1_parity[2] = {0b00010001, 0b00010000};
|
||||
uint8_t data_always_odd_parity[2] = {0b00000011, 0b11110111};
|
||||
uint8_t data_always_even_parity[2] = {0b00010111, 0b10110011};
|
||||
|
||||
// test alawys 0 parity
|
||||
mu_check(bit_lib_test_parity(data_always_0_parity, 0, 12, BitLibParityAlways0, 4));
|
||||
mu_check(bit_lib_test_parity(data_always_0_parity, 4, 8, BitLibParityAlways0, 4));
|
||||
mu_check(bit_lib_test_parity(data_always_0_parity, 8, 4, BitLibParityAlways0, 4));
|
||||
mu_check(bit_lib_test_parity(data_always_1_parity, 12, 4, BitLibParityAlways0, 4));
|
||||
|
||||
mu_check(!bit_lib_test_parity(data_always_0_parity, 0, 16, BitLibParityAlways0, 4));
|
||||
mu_check(!bit_lib_test_parity(data_always_0_parity, 4, 12, BitLibParityAlways0, 4));
|
||||
mu_check(!bit_lib_test_parity(data_always_0_parity, 8, 8, BitLibParityAlways0, 4));
|
||||
mu_check(!bit_lib_test_parity(data_always_0_parity, 12, 4, BitLibParityAlways0, 4));
|
||||
|
||||
// test alawys 1 parity
|
||||
mu_check(bit_lib_test_parity(data_always_1_parity, 0, 12, BitLibParityAlways1, 4));
|
||||
mu_check(bit_lib_test_parity(data_always_1_parity, 4, 8, BitLibParityAlways1, 4));
|
||||
mu_check(bit_lib_test_parity(data_always_1_parity, 8, 4, BitLibParityAlways1, 4));
|
||||
mu_check(bit_lib_test_parity(data_always_0_parity, 12, 4, BitLibParityAlways1, 4));
|
||||
|
||||
mu_check(!bit_lib_test_parity(data_always_1_parity, 0, 16, BitLibParityAlways1, 4));
|
||||
mu_check(!bit_lib_test_parity(data_always_1_parity, 4, 12, BitLibParityAlways1, 4));
|
||||
mu_check(!bit_lib_test_parity(data_always_1_parity, 8, 8, BitLibParityAlways1, 4));
|
||||
mu_check(!bit_lib_test_parity(data_always_1_parity, 12, 4, BitLibParityAlways1, 4));
|
||||
|
||||
// test odd parity
|
||||
mu_check(bit_lib_test_parity(data_always_odd_parity, 0, 12, BitLibParityOdd, 4));
|
||||
mu_check(bit_lib_test_parity(data_always_odd_parity, 4, 8, BitLibParityOdd, 4));
|
||||
mu_check(bit_lib_test_parity(data_always_odd_parity, 8, 4, BitLibParityOdd, 4));
|
||||
mu_check(bit_lib_test_parity(data_always_even_parity, 12, 4, BitLibParityOdd, 4));
|
||||
|
||||
mu_check(!bit_lib_test_parity(data_always_odd_parity, 0, 16, BitLibParityOdd, 4));
|
||||
mu_check(!bit_lib_test_parity(data_always_odd_parity, 4, 12, BitLibParityOdd, 4));
|
||||
mu_check(!bit_lib_test_parity(data_always_odd_parity, 8, 8, BitLibParityOdd, 4));
|
||||
mu_check(!bit_lib_test_parity(data_always_odd_parity, 12, 4, BitLibParityOdd, 4));
|
||||
|
||||
// test even parity
|
||||
mu_check(bit_lib_test_parity(data_always_even_parity, 0, 12, BitLibParityEven, 4));
|
||||
mu_check(bit_lib_test_parity(data_always_even_parity, 4, 8, BitLibParityEven, 4));
|
||||
mu_check(bit_lib_test_parity(data_always_even_parity, 8, 4, BitLibParityEven, 4));
|
||||
mu_check(bit_lib_test_parity(data_always_odd_parity, 12, 4, BitLibParityEven, 4));
|
||||
|
||||
mu_check(!bit_lib_test_parity(data_always_even_parity, 0, 16, BitLibParityEven, 4));
|
||||
mu_check(!bit_lib_test_parity(data_always_even_parity, 4, 12, BitLibParityEven, 4));
|
||||
mu_check(!bit_lib_test_parity(data_always_even_parity, 8, 8, BitLibParityEven, 4));
|
||||
mu_check(!bit_lib_test_parity(data_always_even_parity, 12, 4, BitLibParityEven, 4));
|
||||
}
|
||||
|
||||
MU_TEST(test_bit_lib_remove_bit_every_nth) {
|
||||
// TODO: more tests
|
||||
uint8_t data_i[1] = {0b00001111};
|
||||
uint8_t data_o[1] = {0b00011111};
|
||||
size_t length;
|
||||
|
||||
length = bit_lib_remove_bit_every_nth(data_i, 0, 8, 3);
|
||||
mu_assert_int_eq(6, length);
|
||||
mu_assert_mem_eq(data_o, data_i, 1);
|
||||
}
|
||||
|
||||
MU_TEST(test_bit_lib_reverse_bits) {
|
||||
uint8_t data_1_i[2] = {0b11001010, 0b00011111};
|
||||
uint8_t data_1_o[2] = {0b11111000, 0b01010011};
|
||||
|
||||
// reverse bits [0..15]
|
||||
bit_lib_reverse_bits(data_1_i, 0, 16);
|
||||
mu_assert_mem_eq(data_1_o, data_1_i, 2);
|
||||
|
||||
uint8_t data_2_i[2] = {0b11001010, 0b00011111};
|
||||
uint8_t data_2_o[2] = {0b11001000, 0b01011111};
|
||||
|
||||
// reverse bits [4..11]
|
||||
bit_lib_reverse_bits(data_2_i, 4, 8);
|
||||
mu_assert_mem_eq(data_2_o, data_2_i, 2);
|
||||
}
|
||||
|
||||
MU_TEST(test_bit_lib_copy_bits) {
|
||||
uint8_t data_1_i[2] = {0b11001010, 0b00011111};
|
||||
uint8_t data_1_o[2] = {0};
|
||||
|
||||
// data_1_o[0..15] = data_1_i[0..15]
|
||||
bit_lib_copy_bits(data_1_o, 0, 16, data_1_i, 0);
|
||||
mu_assert_mem_eq(data_1_i, data_1_o, 2);
|
||||
|
||||
memset(data_1_o, 0, 2);
|
||||
// data_1_o[4..11] = data_1_i[0..7]
|
||||
bit_lib_copy_bits(data_1_o, 4, 8, data_1_i, 0);
|
||||
mu_assert_mem_eq(((uint8_t[]){0b00001100, 0b10100000}), data_1_o, 2);
|
||||
}
|
||||
|
||||
MU_TEST(test_bit_lib_get_bit_count) {
|
||||
mu_assert_int_eq(0, bit_lib_get_bit_count(0));
|
||||
mu_assert_int_eq(1, bit_lib_get_bit_count(0b1));
|
||||
mu_assert_int_eq(1, bit_lib_get_bit_count(0b10));
|
||||
mu_assert_int_eq(2, bit_lib_get_bit_count(0b11));
|
||||
mu_assert_int_eq(4, bit_lib_get_bit_count(0b11000011));
|
||||
mu_assert_int_eq(6, bit_lib_get_bit_count(0b11000011000011));
|
||||
mu_assert_int_eq(8, bit_lib_get_bit_count(0b11111111));
|
||||
mu_assert_int_eq(16, bit_lib_get_bit_count(0b11111110000000000000000111111111));
|
||||
mu_assert_int_eq(32, bit_lib_get_bit_count(0b11111111111111111111111111111111));
|
||||
}
|
||||
|
||||
MU_TEST(test_bit_lib_reverse_16_fast) {
|
||||
mu_assert_int_eq(0b0000000000000000, bit_lib_reverse_16_fast(0b0000000000000000));
|
||||
mu_assert_int_eq(0b1000000000000000, bit_lib_reverse_16_fast(0b0000000000000001));
|
||||
mu_assert_int_eq(0b1100000000000000, bit_lib_reverse_16_fast(0b0000000000000011));
|
||||
mu_assert_int_eq(0b0000100000001001, bit_lib_reverse_16_fast(0b1001000000010000));
|
||||
}
|
||||
|
||||
MU_TEST(test_bit_lib_crc16) {
|
||||
uint8_t data[9] = {'1', '2', '3', '4', '5', '6', '7', '8', '9'};
|
||||
uint8_t data_size = 9;
|
||||
|
||||
// Algorithm
|
||||
// Check Poly Init RefIn RefOut XorOut
|
||||
// CRC-16/CCITT-FALSE
|
||||
// 0x29B1 0x1021 0xFFFF false false 0x0000
|
||||
mu_assert_int_eq(0x29B1, bit_lib_crc16(data, data_size, 0x1021, 0xFFFF, false, false, 0x0000));
|
||||
// CRC-16/ARC
|
||||
// 0xBB3D 0x8005 0x0000 true true 0x0000
|
||||
mu_assert_int_eq(0xBB3D, bit_lib_crc16(data, data_size, 0x8005, 0x0000, true, true, 0x0000));
|
||||
// CRC-16/AUG-CCITT
|
||||
// 0xE5CC 0x1021 0x1D0F false false 0x0000
|
||||
mu_assert_int_eq(0xE5CC, bit_lib_crc16(data, data_size, 0x1021, 0x1D0F, false, false, 0x0000));
|
||||
// CRC-16/BUYPASS
|
||||
// 0xFEE8 0x8005 0x0000 false false 0x0000
|
||||
mu_assert_int_eq(0xFEE8, bit_lib_crc16(data, data_size, 0x8005, 0x0000, false, false, 0x0000));
|
||||
// CRC-16/CDMA2000
|
||||
// 0x4C06 0xC867 0xFFFF false false 0x0000
|
||||
mu_assert_int_eq(0x4C06, bit_lib_crc16(data, data_size, 0xC867, 0xFFFF, false, false, 0x0000));
|
||||
// CRC-16/DDS-110
|
||||
// 0x9ECF 0x8005 0x800D false false 0x0000
|
||||
mu_assert_int_eq(0x9ECF, bit_lib_crc16(data, data_size, 0x8005, 0x800D, false, false, 0x0000));
|
||||
// CRC-16/DECT-R
|
||||
// 0x007E 0x0589 0x0000 false false 0x0001
|
||||
mu_assert_int_eq(0x007E, bit_lib_crc16(data, data_size, 0x0589, 0x0000, false, false, 0x0001));
|
||||
// CRC-16/DECT-X
|
||||
// 0x007F 0x0589 0x0000 false false 0x0000
|
||||
mu_assert_int_eq(0x007F, bit_lib_crc16(data, data_size, 0x0589, 0x0000, false, false, 0x0000));
|
||||
// CRC-16/DNP
|
||||
// 0xEA82 0x3D65 0x0000 true true 0xFFFF
|
||||
mu_assert_int_eq(0xEA82, bit_lib_crc16(data, data_size, 0x3D65, 0x0000, true, true, 0xFFFF));
|
||||
// CRC-16/EN-13757
|
||||
// 0xC2B7 0x3D65 0x0000 false false 0xFFFF
|
||||
mu_assert_int_eq(0xC2B7, bit_lib_crc16(data, data_size, 0x3D65, 0x0000, false, false, 0xFFFF));
|
||||
// CRC-16/GENIBUS
|
||||
// 0xD64E 0x1021 0xFFFF false false 0xFFFF
|
||||
mu_assert_int_eq(0xD64E, bit_lib_crc16(data, data_size, 0x1021, 0xFFFF, false, false, 0xFFFF));
|
||||
// CRC-16/MAXIM
|
||||
// 0x44C2 0x8005 0x0000 true true 0xFFFF
|
||||
mu_assert_int_eq(0x44C2, bit_lib_crc16(data, data_size, 0x8005, 0x0000, true, true, 0xFFFF));
|
||||
// CRC-16/MCRF4XX
|
||||
// 0x6F91 0x1021 0xFFFF true true 0x0000
|
||||
mu_assert_int_eq(0x6F91, bit_lib_crc16(data, data_size, 0x1021, 0xFFFF, true, true, 0x0000));
|
||||
// CRC-16/RIELLO
|
||||
// 0x63D0 0x1021 0xB2AA true true 0x0000
|
||||
mu_assert_int_eq(0x63D0, bit_lib_crc16(data, data_size, 0x1021, 0xB2AA, true, true, 0x0000));
|
||||
// CRC-16/T10-DIF
|
||||
// 0xD0DB 0x8BB7 0x0000 false false 0x0000
|
||||
mu_assert_int_eq(0xD0DB, bit_lib_crc16(data, data_size, 0x8BB7, 0x0000, false, false, 0x0000));
|
||||
// CRC-16/TELEDISK
|
||||
// 0x0FB3 0xA097 0x0000 false false 0x0000
|
||||
mu_assert_int_eq(0x0FB3, bit_lib_crc16(data, data_size, 0xA097, 0x0000, false, false, 0x0000));
|
||||
// CRC-16/TMS37157
|
||||
// 0x26B1 0x1021 0x89EC true true 0x0000
|
||||
mu_assert_int_eq(0x26B1, bit_lib_crc16(data, data_size, 0x1021, 0x89EC, true, true, 0x0000));
|
||||
// CRC-16/USB
|
||||
// 0xB4C8 0x8005 0xFFFF true true 0xFFFF
|
||||
mu_assert_int_eq(0xB4C8, bit_lib_crc16(data, data_size, 0x8005, 0xFFFF, true, true, 0xFFFF));
|
||||
// CRC-A
|
||||
// 0xBF05 0x1021 0xC6C6 true true 0x0000
|
||||
mu_assert_int_eq(0xBF05, bit_lib_crc16(data, data_size, 0x1021, 0xC6C6, true, true, 0x0000));
|
||||
// CRC-16/KERMIT
|
||||
// 0x2189 0x1021 0x0000 true true 0x0000
|
||||
mu_assert_int_eq(0x2189, bit_lib_crc16(data, data_size, 0x1021, 0x0000, true, true, 0x0000));
|
||||
// CRC-16/MODBUS
|
||||
// 0x4B37 0x8005 0xFFFF true true 0x0000
|
||||
mu_assert_int_eq(0x4B37, bit_lib_crc16(data, data_size, 0x8005, 0xFFFF, true, true, 0x0000));
|
||||
// CRC-16/X-25
|
||||
// 0x906E 0x1021 0xFFFF true true 0xFFFF
|
||||
mu_assert_int_eq(0x906E, bit_lib_crc16(data, data_size, 0x1021, 0xFFFF, true, true, 0xFFFF));
|
||||
// CRC-16/XMODEM
|
||||
// 0x31C3 0x1021 0x0000 false false 0x0000
|
||||
mu_assert_int_eq(0x31C3, bit_lib_crc16(data, data_size, 0x1021, 0x0000, false, false, 0x0000));
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(test_bit_lib) {
|
||||
MU_RUN_TEST(test_bit_lib_increment_index);
|
||||
MU_RUN_TEST(test_bit_lib_is_set);
|
||||
MU_RUN_TEST(test_bit_lib_push);
|
||||
MU_RUN_TEST(test_bit_lib_set_bit);
|
||||
MU_RUN_TEST(test_bit_lib_set_bits);
|
||||
MU_RUN_TEST(test_bit_lib_get_bit);
|
||||
MU_RUN_TEST(test_bit_lib_get_bits);
|
||||
MU_RUN_TEST(test_bit_lib_get_bits_16);
|
||||
MU_RUN_TEST(test_bit_lib_get_bits_32);
|
||||
MU_RUN_TEST(test_bit_lib_test_parity_u32);
|
||||
MU_RUN_TEST(test_bit_lib_test_parity);
|
||||
MU_RUN_TEST(test_bit_lib_remove_bit_every_nth);
|
||||
MU_RUN_TEST(test_bit_lib_copy_bits);
|
||||
MU_RUN_TEST(test_bit_lib_reverse_bits);
|
||||
MU_RUN_TEST(test_bit_lib_get_bit_count);
|
||||
MU_RUN_TEST(test_bit_lib_reverse_16_fast);
|
||||
MU_RUN_TEST(test_bit_lib_crc16);
|
||||
}
|
||||
|
||||
int run_minunit_test_bit_lib() {
|
||||
MU_RUN_SUITE(test_bit_lib);
|
||||
return MU_EXIT_CODE;
|
||||
}
|
464
applications/unit_tests/lfrfid/lfrfid_protocols.c
Normal file
464
applications/unit_tests/lfrfid/lfrfid_protocols.c
Normal file
@@ -0,0 +1,464 @@
|
||||
#include <furi.h>
|
||||
#include "../minunit.h"
|
||||
#include <toolbox/protocols/protocol_dict.h>
|
||||
#include <lfrfid/protocols/lfrfid_protocols.h>
|
||||
#include <toolbox/pulse_protocols/pulse_glue.h>
|
||||
|
||||
#define LF_RFID_READ_TIMING_MULTIPLIER 8
|
||||
|
||||
#define EM_TEST_DATA \
|
||||
{ 0x58, 0x00, 0x85, 0x64, 0x02 }
|
||||
#define EM_TEST_DATA_SIZE 5
|
||||
#define EM_TEST_EMULATION_TIMINGS_COUNT (64 * 2)
|
||||
|
||||
const int8_t em_test_timings[EM_TEST_EMULATION_TIMINGS_COUNT] = {
|
||||
32, -32, 32, -32, 32, -32, 32, -32, 32, -32, 32, -32, 32, -32, 32, -32, 32, -32, -32,
|
||||
32, 32, -32, -32, 32, 32, -32, -32, 32, 32, -32, -32, 32, -32, 32, -32, 32, 32, -32,
|
||||
-32, 32, -32, 32, -32, 32, -32, 32, -32, 32, -32, 32, -32, 32, -32, 32, -32, 32, -32,
|
||||
32, 32, -32, -32, 32, -32, 32, -32, 32, 32, -32, -32, 32, 32, -32, -32, 32, 32, -32,
|
||||
-32, 32, -32, 32, 32, -32, 32, -32, -32, 32, -32, 32, -32, 32, 32, -32, -32, 32, -32,
|
||||
32, 32, -32, -32, 32, -32, 32, -32, 32, -32, 32, -32, 32, -32, 32, -32, 32, 32, -32,
|
||||
-32, 32, 32, -32, -32, 32, -32, 32, -32, 32, -32, 32, -32, 32,
|
||||
};
|
||||
|
||||
#define HID10301_TEST_DATA \
|
||||
{ 0x8D, 0x48, 0xA8 }
|
||||
#define HID10301_TEST_DATA_SIZE 3
|
||||
#define HID10301_TEST_EMULATION_TIMINGS_COUNT (541 * 2)
|
||||
|
||||
const int8_t hid10301_test_timings[HID10301_TEST_EMULATION_TIMINGS_COUNT] = {
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5,
|
||||
5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5,
|
||||
5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5,
|
||||
5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5,
|
||||
5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5,
|
||||
5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5,
|
||||
5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5,
|
||||
5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5,
|
||||
5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5,
|
||||
5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5,
|
||||
5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5,
|
||||
5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5,
|
||||
5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5,
|
||||
5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5,
|
||||
5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5,
|
||||
5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
};
|
||||
|
||||
#define IOPROX_XSF_TEST_DATA \
|
||||
{ 0x65, 0x01, 0x05, 0x39 }
|
||||
#define IOPROX_XSF_TEST_DATA_SIZE 4
|
||||
#define IOPROX_XSF_TEST_EMULATION_TIMINGS_COUNT (468 * 2)
|
||||
|
||||
const int8_t ioprox_xsf_test_timings[IOPROX_XSF_TEST_EMULATION_TIMINGS_COUNT] = {
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5,
|
||||
5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5,
|
||||
5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5,
|
||||
5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5,
|
||||
5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5,
|
||||
5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5,
|
||||
5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5,
|
||||
5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5,
|
||||
5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5,
|
||||
5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5,
|
||||
5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4,
|
||||
4, -4, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5,
|
||||
5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5,
|
||||
};
|
||||
|
||||
#define INDALA26_EMULATION_TIMINGS_COUNT (1024 * 2)
|
||||
#define INDALA26_TEST_DATA \
|
||||
{ 0x3B, 0x73, 0x64, 0xA8 }
|
||||
#define INDALA26_TEST_DATA_SIZE 4
|
||||
|
||||
const int8_t indala26_test_timings[INDALA26_EMULATION_TIMINGS_COUNT] = {
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
|
||||
1, -1, 1, -1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1,
|
||||
-1, 1, -1, 1, -1, 1, -1, 1,
|
||||
};
|
||||
|
||||
MU_TEST(test_lfrfid_protocol_em_read_simple) {
|
||||
ProtocolDict* dict = protocol_dict_alloc(lfrfid_protocols, LFRFIDProtocolMax);
|
||||
mu_assert_int_eq(EM_TEST_DATA_SIZE, protocol_dict_get_data_size(dict, LFRFIDProtocolEM4100));
|
||||
mu_assert_string_eq("EM4100", protocol_dict_get_name(dict, LFRFIDProtocolEM4100));
|
||||
mu_assert_string_eq("EM-Micro", protocol_dict_get_manufacturer(dict, LFRFIDProtocolEM4100));
|
||||
|
||||
const uint8_t data[EM_TEST_DATA_SIZE] = EM_TEST_DATA;
|
||||
|
||||
protocol_dict_decoders_start(dict);
|
||||
|
||||
ProtocolId protocol = PROTOCOL_NO;
|
||||
PulseGlue* pulse_glue = pulse_glue_alloc();
|
||||
|
||||
for(size_t i = 0; i < EM_TEST_EMULATION_TIMINGS_COUNT * 10; i++) {
|
||||
bool pulse_pop = pulse_glue_push(
|
||||
pulse_glue,
|
||||
em_test_timings[i % EM_TEST_EMULATION_TIMINGS_COUNT] >= 0,
|
||||
abs(em_test_timings[i % EM_TEST_EMULATION_TIMINGS_COUNT]) *
|
||||
LF_RFID_READ_TIMING_MULTIPLIER);
|
||||
|
||||
if(pulse_pop) {
|
||||
uint32_t length, period;
|
||||
pulse_glue_pop(pulse_glue, &length, &period);
|
||||
|
||||
protocol = protocol_dict_decoders_feed(dict, true, period);
|
||||
if(protocol != PROTOCOL_NO) break;
|
||||
|
||||
protocol = protocol_dict_decoders_feed(dict, false, length - period);
|
||||
if(protocol != PROTOCOL_NO) break;
|
||||
}
|
||||
}
|
||||
|
||||
pulse_glue_free(pulse_glue);
|
||||
|
||||
mu_assert_int_eq(LFRFIDProtocolEM4100, protocol);
|
||||
uint8_t received_data[EM_TEST_DATA_SIZE] = {0};
|
||||
protocol_dict_get_data(dict, protocol, received_data, EM_TEST_DATA_SIZE);
|
||||
|
||||
mu_assert_mem_eq(data, received_data, EM_TEST_DATA_SIZE);
|
||||
|
||||
protocol_dict_free(dict);
|
||||
}
|
||||
|
||||
MU_TEST(test_lfrfid_protocol_em_emulate_simple) {
|
||||
ProtocolDict* dict = protocol_dict_alloc(lfrfid_protocols, LFRFIDProtocolMax);
|
||||
mu_assert_int_eq(EM_TEST_DATA_SIZE, protocol_dict_get_data_size(dict, LFRFIDProtocolEM4100));
|
||||
mu_assert_string_eq("EM4100", protocol_dict_get_name(dict, LFRFIDProtocolEM4100));
|
||||
mu_assert_string_eq("EM-Micro", protocol_dict_get_manufacturer(dict, LFRFIDProtocolEM4100));
|
||||
|
||||
const uint8_t data[EM_TEST_DATA_SIZE] = EM_TEST_DATA;
|
||||
|
||||
protocol_dict_set_data(dict, LFRFIDProtocolEM4100, data, EM_TEST_DATA_SIZE);
|
||||
mu_check(protocol_dict_encoder_start(dict, LFRFIDProtocolEM4100));
|
||||
|
||||
for(size_t i = 0; i < EM_TEST_EMULATION_TIMINGS_COUNT; i++) {
|
||||
LevelDuration level_duration = protocol_dict_encoder_yield(dict, LFRFIDProtocolEM4100);
|
||||
|
||||
if(level_duration_get_level(level_duration)) {
|
||||
mu_assert_int_eq(em_test_timings[i], level_duration_get_duration(level_duration));
|
||||
} else {
|
||||
mu_assert_int_eq(em_test_timings[i], -level_duration_get_duration(level_duration));
|
||||
}
|
||||
}
|
||||
|
||||
protocol_dict_free(dict);
|
||||
}
|
||||
|
||||
MU_TEST(test_lfrfid_protocol_h10301_read_simple) {
|
||||
ProtocolDict* dict = protocol_dict_alloc(lfrfid_protocols, LFRFIDProtocolMax);
|
||||
mu_assert_int_eq(
|
||||
HID10301_TEST_DATA_SIZE, protocol_dict_get_data_size(dict, LFRFIDProtocolH10301));
|
||||
mu_assert_string_eq("H10301", protocol_dict_get_name(dict, LFRFIDProtocolH10301));
|
||||
mu_assert_string_eq("HID", protocol_dict_get_manufacturer(dict, LFRFIDProtocolH10301));
|
||||
|
||||
const uint8_t data[HID10301_TEST_DATA_SIZE] = HID10301_TEST_DATA;
|
||||
|
||||
protocol_dict_decoders_start(dict);
|
||||
|
||||
ProtocolId protocol = PROTOCOL_NO;
|
||||
PulseGlue* pulse_glue = pulse_glue_alloc();
|
||||
|
||||
for(size_t i = 0; i < HID10301_TEST_EMULATION_TIMINGS_COUNT * 10; i++) {
|
||||
bool pulse_pop = pulse_glue_push(
|
||||
pulse_glue,
|
||||
hid10301_test_timings[i % HID10301_TEST_EMULATION_TIMINGS_COUNT] >= 0,
|
||||
abs(hid10301_test_timings[i % HID10301_TEST_EMULATION_TIMINGS_COUNT]) *
|
||||
LF_RFID_READ_TIMING_MULTIPLIER);
|
||||
|
||||
if(pulse_pop) {
|
||||
uint32_t length, period;
|
||||
pulse_glue_pop(pulse_glue, &length, &period);
|
||||
|
||||
protocol = protocol_dict_decoders_feed(dict, true, period);
|
||||
if(protocol != PROTOCOL_NO) break;
|
||||
|
||||
protocol = protocol_dict_decoders_feed(dict, false, length - period);
|
||||
if(protocol != PROTOCOL_NO) break;
|
||||
}
|
||||
}
|
||||
|
||||
pulse_glue_free(pulse_glue);
|
||||
|
||||
mu_assert_int_eq(LFRFIDProtocolH10301, protocol);
|
||||
uint8_t received_data[HID10301_TEST_DATA_SIZE] = {0};
|
||||
protocol_dict_get_data(dict, protocol, received_data, HID10301_TEST_DATA_SIZE);
|
||||
|
||||
mu_assert_mem_eq(data, received_data, HID10301_TEST_DATA_SIZE);
|
||||
|
||||
protocol_dict_free(dict);
|
||||
}
|
||||
|
||||
MU_TEST(test_lfrfid_protocol_h10301_emulate_simple) {
|
||||
ProtocolDict* dict = protocol_dict_alloc(lfrfid_protocols, LFRFIDProtocolMax);
|
||||
mu_assert_int_eq(
|
||||
HID10301_TEST_DATA_SIZE, protocol_dict_get_data_size(dict, LFRFIDProtocolH10301));
|
||||
mu_assert_string_eq("H10301", protocol_dict_get_name(dict, LFRFIDProtocolH10301));
|
||||
mu_assert_string_eq("HID", protocol_dict_get_manufacturer(dict, LFRFIDProtocolH10301));
|
||||
|
||||
const uint8_t data[HID10301_TEST_DATA_SIZE] = HID10301_TEST_DATA;
|
||||
|
||||
protocol_dict_set_data(dict, LFRFIDProtocolH10301, data, HID10301_TEST_DATA_SIZE);
|
||||
mu_check(protocol_dict_encoder_start(dict, LFRFIDProtocolH10301));
|
||||
|
||||
for(size_t i = 0; i < HID10301_TEST_EMULATION_TIMINGS_COUNT; i++) {
|
||||
LevelDuration level_duration = protocol_dict_encoder_yield(dict, LFRFIDProtocolH10301);
|
||||
|
||||
if(level_duration_get_level(level_duration)) {
|
||||
mu_assert_int_eq(
|
||||
hid10301_test_timings[i], level_duration_get_duration(level_duration));
|
||||
} else {
|
||||
mu_assert_int_eq(
|
||||
hid10301_test_timings[i], -level_duration_get_duration(level_duration));
|
||||
}
|
||||
}
|
||||
|
||||
protocol_dict_free(dict);
|
||||
}
|
||||
|
||||
MU_TEST(test_lfrfid_protocol_ioprox_xsf_read_simple) {
|
||||
ProtocolDict* dict = protocol_dict_alloc(lfrfid_protocols, LFRFIDProtocolMax);
|
||||
mu_assert_int_eq(
|
||||
IOPROX_XSF_TEST_DATA_SIZE, protocol_dict_get_data_size(dict, LFRFIDProtocolIOProxXSF));
|
||||
mu_assert_string_eq("IoProxXSF", protocol_dict_get_name(dict, LFRFIDProtocolIOProxXSF));
|
||||
mu_assert_string_eq("Kantech", protocol_dict_get_manufacturer(dict, LFRFIDProtocolIOProxXSF));
|
||||
|
||||
const uint8_t data[IOPROX_XSF_TEST_DATA_SIZE] = IOPROX_XSF_TEST_DATA;
|
||||
|
||||
protocol_dict_decoders_start(dict);
|
||||
|
||||
ProtocolId protocol = PROTOCOL_NO;
|
||||
PulseGlue* pulse_glue = pulse_glue_alloc();
|
||||
|
||||
for(size_t i = 0; i < IOPROX_XSF_TEST_EMULATION_TIMINGS_COUNT * 10; i++) {
|
||||
bool pulse_pop = pulse_glue_push(
|
||||
pulse_glue,
|
||||
ioprox_xsf_test_timings[i % IOPROX_XSF_TEST_EMULATION_TIMINGS_COUNT] >= 0,
|
||||
abs(ioprox_xsf_test_timings[i % IOPROX_XSF_TEST_EMULATION_TIMINGS_COUNT]) *
|
||||
LF_RFID_READ_TIMING_MULTIPLIER);
|
||||
|
||||
if(pulse_pop) {
|
||||
uint32_t length, period;
|
||||
pulse_glue_pop(pulse_glue, &length, &period);
|
||||
|
||||
protocol = protocol_dict_decoders_feed(dict, true, period);
|
||||
if(protocol != PROTOCOL_NO) break;
|
||||
|
||||
protocol = protocol_dict_decoders_feed(dict, false, length - period);
|
||||
if(protocol != PROTOCOL_NO) break;
|
||||
}
|
||||
}
|
||||
|
||||
pulse_glue_free(pulse_glue);
|
||||
|
||||
mu_assert_int_eq(LFRFIDProtocolIOProxXSF, protocol);
|
||||
uint8_t received_data[IOPROX_XSF_TEST_DATA_SIZE] = {0};
|
||||
protocol_dict_get_data(dict, protocol, received_data, IOPROX_XSF_TEST_DATA_SIZE);
|
||||
|
||||
mu_assert_mem_eq(data, received_data, IOPROX_XSF_TEST_DATA_SIZE);
|
||||
|
||||
protocol_dict_free(dict);
|
||||
}
|
||||
|
||||
MU_TEST(test_lfrfid_protocol_ioprox_xsf_emulate_simple) {
|
||||
ProtocolDict* dict = protocol_dict_alloc(lfrfid_protocols, LFRFIDProtocolMax);
|
||||
mu_assert_int_eq(
|
||||
IOPROX_XSF_TEST_DATA_SIZE, protocol_dict_get_data_size(dict, LFRFIDProtocolIOProxXSF));
|
||||
mu_assert_string_eq("IoProxXSF", protocol_dict_get_name(dict, LFRFIDProtocolIOProxXSF));
|
||||
mu_assert_string_eq("Kantech", protocol_dict_get_manufacturer(dict, LFRFIDProtocolIOProxXSF));
|
||||
|
||||
const uint8_t data[IOPROX_XSF_TEST_DATA_SIZE] = IOPROX_XSF_TEST_DATA;
|
||||
|
||||
protocol_dict_set_data(dict, LFRFIDProtocolIOProxXSF, data, IOPROX_XSF_TEST_DATA_SIZE);
|
||||
mu_check(protocol_dict_encoder_start(dict, LFRFIDProtocolIOProxXSF));
|
||||
|
||||
for(size_t i = 0; i < IOPROX_XSF_TEST_EMULATION_TIMINGS_COUNT; i++) {
|
||||
LevelDuration level_duration = protocol_dict_encoder_yield(dict, LFRFIDProtocolIOProxXSF);
|
||||
|
||||
if(level_duration_get_level(level_duration)) {
|
||||
mu_assert_int_eq(
|
||||
ioprox_xsf_test_timings[i], level_duration_get_duration(level_duration));
|
||||
} else {
|
||||
mu_assert_int_eq(
|
||||
ioprox_xsf_test_timings[i], -level_duration_get_duration(level_duration));
|
||||
}
|
||||
}
|
||||
|
||||
protocol_dict_free(dict);
|
||||
}
|
||||
|
||||
MU_TEST(test_lfrfid_protocol_inadala26_emulate_simple) {
|
||||
ProtocolDict* dict = protocol_dict_alloc(lfrfid_protocols, LFRFIDProtocolMax);
|
||||
mu_assert_int_eq(
|
||||
INDALA26_TEST_DATA_SIZE, protocol_dict_get_data_size(dict, LFRFIDProtocolIndala26));
|
||||
mu_assert_string_eq("Indala26", protocol_dict_get_name(dict, LFRFIDProtocolIndala26));
|
||||
mu_assert_string_eq("Motorola", protocol_dict_get_manufacturer(dict, LFRFIDProtocolIndala26));
|
||||
|
||||
const uint8_t data[INDALA26_TEST_DATA_SIZE] = INDALA26_TEST_DATA;
|
||||
|
||||
protocol_dict_set_data(dict, LFRFIDProtocolIndala26, data, INDALA26_TEST_DATA_SIZE);
|
||||
mu_check(protocol_dict_encoder_start(dict, LFRFIDProtocolIndala26));
|
||||
|
||||
for(size_t i = 0; i < INDALA26_EMULATION_TIMINGS_COUNT; i++) {
|
||||
LevelDuration level_duration = protocol_dict_encoder_yield(dict, LFRFIDProtocolIndala26);
|
||||
|
||||
if(level_duration_get_level(level_duration)) {
|
||||
mu_assert_int_eq(
|
||||
indala26_test_timings[i], level_duration_get_duration(level_duration));
|
||||
} else {
|
||||
mu_assert_int_eq(
|
||||
indala26_test_timings[i], -level_duration_get_duration(level_duration));
|
||||
}
|
||||
}
|
||||
|
||||
protocol_dict_free(dict);
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(test_lfrfid_protocols_suite) {
|
||||
MU_RUN_TEST(test_lfrfid_protocol_em_read_simple);
|
||||
MU_RUN_TEST(test_lfrfid_protocol_em_emulate_simple);
|
||||
|
||||
MU_RUN_TEST(test_lfrfid_protocol_h10301_read_simple);
|
||||
MU_RUN_TEST(test_lfrfid_protocol_h10301_emulate_simple);
|
||||
|
||||
MU_RUN_TEST(test_lfrfid_protocol_ioprox_xsf_read_simple);
|
||||
MU_RUN_TEST(test_lfrfid_protocol_ioprox_xsf_emulate_simple);
|
||||
|
||||
MU_RUN_TEST(test_lfrfid_protocol_inadala26_emulate_simple);
|
||||
}
|
||||
|
||||
int run_minunit_test_lfrfid_protocols() {
|
||||
MU_RUN_SUITE(test_lfrfid_protocols_suite);
|
||||
return MU_EXIT_CODE;
|
||||
}
|
@@ -151,46 +151,46 @@ void minunit_print_fail(const char* error);
|
||||
#define MU_EXIT_CODE minunit_fail
|
||||
|
||||
/* Assertions */
|
||||
#define mu_check(test) \
|
||||
MU__SAFE_BLOCK( \
|
||||
minunit_assert++; if(!(test)) { \
|
||||
snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\n\t%s:%d: %s", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
#test); \
|
||||
minunit_status = 1; \
|
||||
return; \
|
||||
#define mu_check(test) \
|
||||
MU__SAFE_BLOCK( \
|
||||
minunit_assert++; if(!(test)) { \
|
||||
snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\r\n\t%s:%d: %s", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
#test); \
|
||||
minunit_status = 1; \
|
||||
return; \
|
||||
} else { minunit_print_progress(); })
|
||||
|
||||
#define mu_fail(message) \
|
||||
MU__SAFE_BLOCK(minunit_assert++; snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\n\t%s:%d: %s", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
message); \
|
||||
minunit_status = 1; \
|
||||
#define mu_fail(message) \
|
||||
MU__SAFE_BLOCK(minunit_assert++; snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\r\n\t%s:%d: %s", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
message); \
|
||||
minunit_status = 1; \
|
||||
return;)
|
||||
|
||||
#define mu_assert(test, message) \
|
||||
MU__SAFE_BLOCK( \
|
||||
minunit_assert++; if(!(test)) { \
|
||||
snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\n\t%s:%d: %s", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
message); \
|
||||
minunit_status = 1; \
|
||||
return; \
|
||||
#define mu_assert(test, message) \
|
||||
MU__SAFE_BLOCK( \
|
||||
minunit_assert++; if(!(test)) { \
|
||||
snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\r\n\t%s:%d: %s", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
message); \
|
||||
minunit_status = 1; \
|
||||
return; \
|
||||
} else { minunit_print_progress(); })
|
||||
|
||||
#define mu_assert_int_eq(expected, result) \
|
||||
@@ -201,7 +201,7 @@ void minunit_print_fail(const char* error);
|
||||
snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\n\t%s:%d: %d expected but was %d", \
|
||||
"%s failed:\r\n\t%s:%d: %d expected but was %d", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
@@ -219,7 +219,7 @@ void minunit_print_fail(const char* error);
|
||||
snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\n\t%s:%d: expected different results but both were %d", \
|
||||
"%s failed:\r\n\t%s:%d: expected different results but both were %d", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
@@ -236,7 +236,7 @@ void minunit_print_fail(const char* error);
|
||||
snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\n\t%s:%d: %d <= %d", \
|
||||
"%s failed:\r\n\t%s:%d: %d <= %d", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
@@ -254,7 +254,7 @@ void minunit_print_fail(const char* error);
|
||||
snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\n\t%s:%d: %d >= %d", \
|
||||
"%s failed:\r\n\t%s:%d: %d >= %d", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
@@ -274,7 +274,7 @@ void minunit_print_fail(const char* error);
|
||||
snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\n\t%s:%d: %d was not between (inclusive) %d and %d", \
|
||||
"%s failed:\r\n\t%s:%d: %d was not between (inclusive) %d and %d", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
@@ -302,7 +302,7 @@ void minunit_print_fail(const char* error);
|
||||
snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\n\t%s:%d: expected to be one of %s but was %d", \
|
||||
"%s failed:\r\n\t%s:%d: expected to be one of %s but was %d", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
@@ -321,7 +321,7 @@ void minunit_print_fail(const char* error);
|
||||
snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\n\t%s:%d: %.*g expected but was %.*g", \
|
||||
"%s failed:\r\n\t%s:%d: %.*g expected but was %.*g", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
@@ -341,7 +341,7 @@ void minunit_print_fail(const char* error);
|
||||
snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\n\t%s:%d: %f <= %f", \
|
||||
"%s failed:\r\n\t%s:%d: %f <= %f", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
@@ -359,7 +359,7 @@ void minunit_print_fail(const char* error);
|
||||
snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\n\t%s:%d: %f >= %f", \
|
||||
"%s failed:\r\n\t%s:%d: %f >= %f", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
@@ -379,7 +379,7 @@ void minunit_print_fail(const char* error);
|
||||
snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\n\t%s:%d: %f was not between (inclusive) %f and %f", \
|
||||
"%s failed:\r\n\t%s:%d: %f was not between (inclusive) %f and %f", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
@@ -400,7 +400,7 @@ void minunit_print_fail(const char* error);
|
||||
snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\n\t%s:%d: '%s' expected but was '%s'", \
|
||||
"%s failed:\r\n\t%s:%d: '%s' expected but was '%s'", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
@@ -410,13 +410,41 @@ void minunit_print_fail(const char* error);
|
||||
return; \
|
||||
} else { minunit_print_progress(); })
|
||||
|
||||
#define mu_assert_mem_eq(expected, result, size) \
|
||||
MU__SAFE_BLOCK( \
|
||||
const void* minunit_tmp_e = expected; const void* minunit_tmp_r = result; \
|
||||
minunit_assert++; \
|
||||
if(memcmp(minunit_tmp_e, minunit_tmp_r, size)) { \
|
||||
snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\r\n\t%s:%d: mem not equal\r\n\tEXP RES", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__); \
|
||||
for(size_t __index = 0; __index < size; __index++) { \
|
||||
if(strlen(minunit_last_message) > MINUNIT_MESSAGE_LEN - 20) break; \
|
||||
uint8_t __e = ((uint8_t*)minunit_tmp_e)[__index]; \
|
||||
uint8_t __r = ((uint8_t*)minunit_tmp_r)[__index]; \
|
||||
snprintf( \
|
||||
minunit_last_message + strlen(minunit_last_message), \
|
||||
MINUNIT_MESSAGE_LEN - strlen(minunit_last_message), \
|
||||
"\r\n\t%02X %s %02X", \
|
||||
__e, \
|
||||
((__e == __r) ? ".." : "!="), \
|
||||
__r); \
|
||||
} \
|
||||
minunit_status = 1; \
|
||||
return; \
|
||||
} else { minunit_print_progress(); })
|
||||
|
||||
#define mu_assert_null(result) \
|
||||
MU__SAFE_BLOCK( \
|
||||
minunit_assert++; if(result == NULL) { minunit_print_progress(); } else { \
|
||||
snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\n\t%s:%d: Expected result was not NULL", \
|
||||
"%s failed:\r\n\t%s:%d: Expected result was not NULL", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__); \
|
||||
@@ -430,7 +458,7 @@ void minunit_print_fail(const char* error);
|
||||
snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\n\t%s:%d: Expected result was not NULL", \
|
||||
"%s failed:\r\n\t%s:%d: Expected result was not NULL", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__); \
|
||||
@@ -438,32 +466,32 @@ void minunit_print_fail(const char* error);
|
||||
return; \
|
||||
})
|
||||
|
||||
#define mu_assert_pointers_eq(pointer1, pointer2) \
|
||||
MU__SAFE_BLOCK( \
|
||||
minunit_assert++; if(pointer1 == pointer2) { minunit_print_progress(); } else { \
|
||||
snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\n\t%s:%d: Expected the pointers to point to the same memory location", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__); \
|
||||
minunit_status = 1; \
|
||||
return; \
|
||||
#define mu_assert_pointers_eq(pointer1, pointer2) \
|
||||
MU__SAFE_BLOCK( \
|
||||
minunit_assert++; if(pointer1 == pointer2) { minunit_print_progress(); } else { \
|
||||
snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\r\n\t%s:%d: Expected the pointers to point to the same memory location", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__); \
|
||||
minunit_status = 1; \
|
||||
return; \
|
||||
})
|
||||
|
||||
#define mu_assert_pointers_not_eq(pointer1, pointer2) \
|
||||
MU__SAFE_BLOCK( \
|
||||
minunit_assert++; if(pointer1 != pointer2) { minunit_print_progress(); } else { \
|
||||
snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\n\t%s:%d: Expected the pointers to point to the same memory location", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__); \
|
||||
minunit_status = 1; \
|
||||
return; \
|
||||
#define mu_assert_pointers_not_eq(pointer1, pointer2) \
|
||||
MU__SAFE_BLOCK( \
|
||||
minunit_assert++; if(pointer1 != pointer2) { minunit_print_progress(); } else { \
|
||||
snprintf( \
|
||||
minunit_last_message, \
|
||||
MINUNIT_MESSAGE_LEN, \
|
||||
"%s failed:\r\n\t%s:%d: Expected the pointers to point to the same memory location", \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__); \
|
||||
minunit_status = 1; \
|
||||
return; \
|
||||
})
|
||||
|
||||
/*
|
||||
|
222
applications/unit_tests/protocol_dict/protocol_dict_test.c
Normal file
222
applications/unit_tests/protocol_dict/protocol_dict_test.c
Normal file
@@ -0,0 +1,222 @@
|
||||
#include <furi.h>
|
||||
#include "../minunit.h"
|
||||
#include <toolbox/protocols/protocol_dict.h>
|
||||
|
||||
typedef enum {
|
||||
TestDictProtocol0,
|
||||
TestDictProtocol1,
|
||||
|
||||
TestDictProtocolMax,
|
||||
} TestDictProtocols;
|
||||
|
||||
/*********************** PROTOCOL 0 START ***********************/
|
||||
|
||||
typedef struct {
|
||||
uint32_t data;
|
||||
size_t encoder_counter;
|
||||
} Protocol0Data;
|
||||
|
||||
static const uint32_t protocol_0_decoder_result = 0xDEADBEEF;
|
||||
|
||||
static void* protocol_0_alloc() {
|
||||
void* data = malloc(sizeof(Protocol0Data));
|
||||
return data;
|
||||
}
|
||||
|
||||
static void protocol_0_free(Protocol0Data* data) {
|
||||
free(data);
|
||||
}
|
||||
|
||||
static uint8_t* protocol_0_get_data(Protocol0Data* data) {
|
||||
return (uint8_t*)&data->data;
|
||||
}
|
||||
|
||||
static void protocol_0_decoder_start(Protocol0Data* data) {
|
||||
data->data = 0;
|
||||
}
|
||||
|
||||
static bool protocol_0_decoder_feed(Protocol0Data* data, bool level, uint32_t duration) {
|
||||
if(level && duration == 666) {
|
||||
data->data = protocol_0_decoder_result;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool protocol_0_encoder_start(Protocol0Data* data) {
|
||||
data->encoder_counter = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static LevelDuration protocol_0_encoder_yield(Protocol0Data* data) {
|
||||
data->encoder_counter++;
|
||||
return level_duration_make(data->encoder_counter % 2, data->data);
|
||||
}
|
||||
|
||||
/*********************** PROTOCOL 1 START ***********************/
|
||||
|
||||
typedef struct {
|
||||
uint64_t data;
|
||||
size_t encoder_counter;
|
||||
} Protocol1Data;
|
||||
|
||||
static const uint64_t protocol_1_decoder_result = 0x1234567890ABCDEF;
|
||||
|
||||
static void* protocol_1_alloc() {
|
||||
void* data = malloc(sizeof(Protocol1Data));
|
||||
return data;
|
||||
}
|
||||
|
||||
static void protocol_1_free(Protocol1Data* data) {
|
||||
free(data);
|
||||
}
|
||||
|
||||
static uint8_t* protocol_1_get_data(Protocol1Data* data) {
|
||||
return (uint8_t*)&data->data;
|
||||
}
|
||||
|
||||
static void protocol_1_decoder_start(Protocol1Data* data) {
|
||||
data->data = 0;
|
||||
}
|
||||
|
||||
static bool protocol_1_decoder_feed(Protocol1Data* data, bool level, uint32_t duration) {
|
||||
if(level && duration == 543) {
|
||||
data->data = 0x1234567890ABCDEF;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool protocol_1_encoder_start(Protocol1Data* data) {
|
||||
data->encoder_counter = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static LevelDuration protocol_1_encoder_yield(Protocol1Data* data) {
|
||||
data->encoder_counter++;
|
||||
return level_duration_make(!(data->encoder_counter % 2), 100);
|
||||
}
|
||||
|
||||
/*********************** PROTOCOLS DESCRIPTION ***********************/
|
||||
static const ProtocolBase protocol_0 = {
|
||||
.name = "Protocol 0",
|
||||
.manufacturer = "Manufacturer 0",
|
||||
.data_size = 4,
|
||||
.alloc = (ProtocolAlloc)protocol_0_alloc,
|
||||
.free = (ProtocolFree)protocol_0_free,
|
||||
.get_data = (ProtocolGetData)protocol_0_get_data,
|
||||
.decoder =
|
||||
{
|
||||
.start = (ProtocolDecoderStart)protocol_0_decoder_start,
|
||||
.feed = (ProtocolDecoderFeed)protocol_0_decoder_feed,
|
||||
},
|
||||
.encoder =
|
||||
{
|
||||
.start = (ProtocolEncoderStart)protocol_0_encoder_start,
|
||||
.yield = (ProtocolEncoderYield)protocol_0_encoder_yield,
|
||||
},
|
||||
};
|
||||
|
||||
static const ProtocolBase protocol_1 = {
|
||||
.name = "Protocol 1",
|
||||
.manufacturer = "Manufacturer 1",
|
||||
.data_size = 8,
|
||||
.alloc = (ProtocolAlloc)protocol_1_alloc,
|
||||
.free = (ProtocolFree)protocol_1_free,
|
||||
.get_data = (ProtocolGetData)protocol_1_get_data,
|
||||
.decoder =
|
||||
{
|
||||
.start = (ProtocolDecoderStart)protocol_1_decoder_start,
|
||||
.feed = (ProtocolDecoderFeed)protocol_1_decoder_feed,
|
||||
},
|
||||
.encoder =
|
||||
{
|
||||
.start = (ProtocolEncoderStart)protocol_1_encoder_start,
|
||||
.yield = (ProtocolEncoderYield)protocol_1_encoder_yield,
|
||||
},
|
||||
};
|
||||
|
||||
static const ProtocolBase* test_protocols_base[] = {
|
||||
[TestDictProtocol0] = &protocol_0,
|
||||
[TestDictProtocol1] = &protocol_1,
|
||||
};
|
||||
|
||||
MU_TEST(test_protocol_dict) {
|
||||
ProtocolDict* dict = protocol_dict_alloc(test_protocols_base, TestDictProtocolMax);
|
||||
size_t max_data_size = protocol_dict_get_max_data_size(dict);
|
||||
mu_assert_int_eq(8, max_data_size);
|
||||
uint8_t* data = malloc(max_data_size);
|
||||
|
||||
protocol_dict_decoders_start(dict);
|
||||
ProtocolId protocol_id = PROTOCOL_NO;
|
||||
|
||||
for(size_t i = 0; i < 100; i++) {
|
||||
protocol_id = protocol_dict_decoders_feed(dict, i % 2, 100);
|
||||
mu_assert_int_eq(PROTOCOL_NO, protocol_id);
|
||||
}
|
||||
|
||||
// trigger protocol 1
|
||||
protocol_id = protocol_dict_decoders_feed(dict, true, 543);
|
||||
mu_assert_int_eq(TestDictProtocol1, protocol_id);
|
||||
|
||||
mu_assert_string_eq("Protocol 1", protocol_dict_get_name(dict, protocol_id));
|
||||
mu_assert_string_eq("Manufacturer 1", protocol_dict_get_manufacturer(dict, protocol_id));
|
||||
|
||||
size_t data_size = protocol_dict_get_data_size(dict, protocol_id);
|
||||
mu_assert_int_eq(8, data_size);
|
||||
|
||||
protocol_dict_get_data(dict, protocol_id, data, data_size);
|
||||
mu_assert_mem_eq(&protocol_1_decoder_result, data, data_size);
|
||||
|
||||
// trigger protocol 0
|
||||
protocol_id = protocol_dict_decoders_feed(dict, true, 666);
|
||||
mu_assert_int_eq(TestDictProtocol0, protocol_id);
|
||||
|
||||
mu_assert_string_eq("Protocol 0", protocol_dict_get_name(dict, protocol_id));
|
||||
mu_assert_string_eq("Manufacturer 0", protocol_dict_get_manufacturer(dict, protocol_id));
|
||||
|
||||
data_size = protocol_dict_get_data_size(dict, protocol_id);
|
||||
mu_assert_int_eq(4, data_size);
|
||||
|
||||
protocol_dict_get_data(dict, protocol_id, data, data_size);
|
||||
mu_assert_mem_eq(&protocol_0_decoder_result, data, data_size);
|
||||
|
||||
protocol_dict_decoders_start(dict);
|
||||
|
||||
protocol_id = TestDictProtocol0;
|
||||
|
||||
const uint8_t protocol_0_test_data[4] = {100, 0, 0, 0};
|
||||
protocol_dict_set_data(dict, protocol_id, protocol_0_test_data, 4);
|
||||
|
||||
mu_check(protocol_dict_encoder_start(dict, protocol_id));
|
||||
|
||||
LevelDuration level;
|
||||
level = protocol_dict_encoder_yield(dict, protocol_id);
|
||||
mu_assert_int_eq(true, level_duration_get_level(level));
|
||||
mu_assert_int_eq(100, level_duration_get_duration(level));
|
||||
level = protocol_dict_encoder_yield(dict, protocol_id);
|
||||
mu_assert_int_eq(false, level_duration_get_level(level));
|
||||
mu_assert_int_eq(100, level_duration_get_duration(level));
|
||||
level = protocol_dict_encoder_yield(dict, protocol_id);
|
||||
mu_assert_int_eq(true, level_duration_get_level(level));
|
||||
mu_assert_int_eq(100, level_duration_get_duration(level));
|
||||
|
||||
mu_check(protocol_dict_encoder_start(dict, protocol_id));
|
||||
level = protocol_dict_encoder_yield(dict, protocol_id);
|
||||
mu_assert_int_eq(true, level_duration_get_level(level));
|
||||
mu_assert_int_eq(100, level_duration_get_duration(level));
|
||||
|
||||
protocol_dict_free(dict);
|
||||
free(data);
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(test_protocol_dict_suite) {
|
||||
MU_RUN_TEST(test_protocol_dict);
|
||||
}
|
||||
|
||||
int run_minunit_test_protocol_dict() {
|
||||
MU_RUN_SUITE(test_protocol_dict_suite);
|
||||
return MU_EXIT_CODE;
|
||||
}
|
@@ -19,7 +19,10 @@ int run_minunit_test_stream();
|
||||
int run_minunit_test_storage();
|
||||
int run_minunit_test_subghz();
|
||||
int run_minunit_test_dirwalk();
|
||||
int run_minunit_test_protocol_dict();
|
||||
int run_minunit_test_lfrfid_protocols();
|
||||
int run_minunit_test_nfc();
|
||||
int run_minunit_test_bit_lib();
|
||||
|
||||
typedef int (*UnitTestEntry)();
|
||||
|
||||
@@ -39,6 +42,9 @@ const UnitTest unit_tests[] = {
|
||||
{.name = "subghz", .entry = run_minunit_test_subghz},
|
||||
{.name = "infrared", .entry = run_minunit_test_infrared},
|
||||
{.name = "nfc", .entry = run_minunit_test_nfc},
|
||||
{.name = "protocol_dict", .entry = run_minunit_test_protocol_dict},
|
||||
{.name = "lfrfid", .entry = run_minunit_test_lfrfid_protocols},
|
||||
{.name = "bit_lib", .entry = run_minunit_test_bit_lib},
|
||||
};
|
||||
|
||||
void minunit_print_progress() {
|
||||
|
88
applications/unit_tests/varint/varint_test.c
Normal file
88
applications/unit_tests/varint/varint_test.c
Normal file
@@ -0,0 +1,88 @@
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include "../minunit.h"
|
||||
#include <toolbox/varint.h>
|
||||
#include <toolbox/profiler.h>
|
||||
|
||||
MU_TEST(test_varint_basic_u) {
|
||||
mu_assert_int_eq(1, varint_uint32_length(0));
|
||||
mu_assert_int_eq(5, varint_uint32_length(UINT32_MAX));
|
||||
|
||||
uint8_t data[8] = {};
|
||||
uint32_t out_value;
|
||||
|
||||
mu_assert_int_eq(1, varint_uint32_pack(0, data));
|
||||
mu_assert_int_eq(1, varint_uint32_unpack(&out_value, data, 8));
|
||||
mu_assert_int_eq(0, out_value);
|
||||
|
||||
mu_assert_int_eq(5, varint_uint32_pack(UINT32_MAX, data));
|
||||
mu_assert_int_eq(5, varint_uint32_unpack(&out_value, data, 8));
|
||||
mu_assert_int_eq(UINT32_MAX, out_value);
|
||||
}
|
||||
|
||||
MU_TEST(test_varint_basic_i) {
|
||||
mu_assert_int_eq(5, varint_int32_length(INT32_MIN / 2));
|
||||
mu_assert_int_eq(1, varint_int32_length(0));
|
||||
mu_assert_int_eq(5, varint_int32_length(INT32_MAX / 2));
|
||||
|
||||
mu_assert_int_eq(2, varint_int32_length(127));
|
||||
mu_assert_int_eq(2, varint_int32_length(-127));
|
||||
|
||||
uint8_t data[8] = {};
|
||||
int32_t out_value;
|
||||
mu_assert_int_eq(1, varint_int32_pack(0, data));
|
||||
mu_assert_int_eq(1, varint_int32_unpack(&out_value, data, 8));
|
||||
mu_assert_int_eq(0, out_value);
|
||||
|
||||
mu_assert_int_eq(2, varint_int32_pack(127, data));
|
||||
mu_assert_int_eq(2, varint_int32_unpack(&out_value, data, 8));
|
||||
mu_assert_int_eq(127, out_value);
|
||||
|
||||
mu_assert_int_eq(2, varint_int32_pack(-127, data));
|
||||
mu_assert_int_eq(2, varint_int32_unpack(&out_value, data, 8));
|
||||
mu_assert_int_eq(-127, out_value);
|
||||
|
||||
mu_assert_int_eq(5, varint_int32_pack(INT32_MAX, data));
|
||||
mu_assert_int_eq(5, varint_int32_unpack(&out_value, data, 8));
|
||||
mu_assert_int_eq(INT32_MAX, out_value);
|
||||
|
||||
mu_assert_int_eq(5, varint_int32_pack(INT32_MIN / 2 + 1, data));
|
||||
mu_assert_int_eq(5, varint_int32_unpack(&out_value, data, 8));
|
||||
mu_assert_int_eq(INT32_MIN / 2 + 1, out_value);
|
||||
}
|
||||
|
||||
MU_TEST(test_varint_rand_u) {
|
||||
uint8_t data[8] = {};
|
||||
uint32_t out_value;
|
||||
|
||||
for(size_t i = 0; i < 200000; i++) {
|
||||
uint32_t rand_value = rand();
|
||||
mu_assert_int_eq(
|
||||
varint_uint32_pack(rand_value, data), varint_uint32_unpack(&out_value, data, 8));
|
||||
mu_assert_int_eq(rand_value, out_value);
|
||||
}
|
||||
}
|
||||
|
||||
MU_TEST(test_varint_rand_i) {
|
||||
uint8_t data[8] = {};
|
||||
int32_t out_value;
|
||||
|
||||
for(size_t i = 0; i < 200000; i++) {
|
||||
int32_t rand_value = rand() + (INT32_MIN / 2 + 1);
|
||||
mu_assert_int_eq(
|
||||
varint_int32_pack(rand_value, data), varint_int32_unpack(&out_value, data, 8));
|
||||
mu_assert_int_eq(rand_value, out_value);
|
||||
}
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(test_varint_suite) {
|
||||
MU_RUN_TEST(test_varint_basic_u);
|
||||
MU_RUN_TEST(test_varint_basic_i);
|
||||
MU_RUN_TEST(test_varint_rand_u);
|
||||
MU_RUN_TEST(test_varint_rand_i);
|
||||
}
|
||||
|
||||
int run_minunit_test_varint() {
|
||||
MU_RUN_SUITE(test_varint_suite);
|
||||
return MU_EXIT_CODE;
|
||||
}
|
Reference in New Issue
Block a user