Merge pull request #11190 from mathiasvr/pr-arraylen
[betaflight.git] / src / test / unit / transponder_ir_unittest.cc
blobb220d06c921446b0ab1f92dac3b61d6821df6dbc
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #include <stdint.h>
19 #include <stdlib.h>
20 #include <limits.h>
22 extern "C" {
23 #include <platform.h>
24 #include "build/build_config.h"
25 #include "drivers/dma.h"
26 #include "drivers/transponder_ir.h"
27 #include "drivers/transponder_ir_arcitimer.h"
28 #include "drivers/transponder_ir_ilap.h"
31 #include "unittest_macros.h"
32 #include "gtest/gtest.h"
34 extern "C" {
35 STATIC_UNIT_TESTED extern uint16_t dmaBufferOffset;
36 STATIC_UNIT_TESTED void updateTransponderDMABufferIlap(transponder_t *transponder, const uint8_t* transponderData);
37 STATIC_UNIT_TESTED void updateTransponderDMABufferArcitimer(transponder_t *transponder, const uint8_t* transponderData);
40 TEST(transponderTest, updateTransponderDMABufferArcitimer)
42 //input
43 uint8_t data[9] = {0x1F, 0xFC, 0x8F, 0x3, 0xF0, 0x1, 0xF8, 0x1F, 0x0};
44 //excepted
45 uint8_t excepted[TRANSPONDER_DMA_BUFFER_SIZE_ARCITIMER] = {
46 78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,78,78,78,78,
47 78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,0,0,
48 0,0,0,0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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
58 0,0,0,0,0,0,0,0,0,0,0,0,0,0
60 uint8_t* transponderData = data;
61 transponder_t transponder;
62 transponder.dma_buffer_size = TRANSPONDER_DMA_BUFFER_SIZE_ARCITIMER;
63 transponder.bitToggleOne = 78;
64 memset(&(transponder.transponderIrDMABuffer.arcitimer), 0, TRANSPONDER_DMA_BUFFER_SIZE_ARCITIMER);
66 updateTransponderDMABufferArcitimer(&transponder, transponderData);
67 uint16_t i;
68 for(i = 0; i < transponder.dma_buffer_size; i++) {
69 EXPECT_EQ(transponder.transponderIrDMABuffer.arcitimer[i], excepted[i]);
73 TEST(transponderTest, updateTransponderDMABufferIlap)
75 uint8_t data[9] = {0x1F, 0xFC, 0x8F, 0x3, 0xF0, 0x1, 0x0, 0x0, 0x0};
77 uint8_t excepted[TRANSPONDER_DMA_BUFFER_SIZE_ILAP] = {
78 78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,78,
79 78,78,78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,0,0,0,
80 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,78,78,78,78,78,78,
81 78,78,78,78,78,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,
82 78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,78,
83 78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,0,0,0,0,0,0,0,0,0,0,0,0,78,78,78,78,78,78,78,78,78,
84 78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,
85 78,0,78,78,78,78,78,78,78,78,78,78,78,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
86 0,0,78,78,78,78,78,78,78,78,78,78,78,0,0,0,0,0,0,0,0,0,0,0,0,0,78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,
87 78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
88 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
89 0,0,0,0,0,0,0,0,78,78,78,78,78,78,78,78,78,78,78,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
90 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,
91 0,78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,0,0,0,0,0,0,0,0,0,0,0,0,78,78,78,78,
92 78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,78,78,78,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
93 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
94 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
97 uint8_t* transponderData = data;
98 transponder_t transponder;
99 transponder.dma_buffer_size = TRANSPONDER_DMA_BUFFER_SIZE_ILAP;
100 transponder.bitToggleOne = 78;
102 updateTransponderDMABufferIlap(&transponder, transponderData);
104 uint16_t i;
105 for(i = 0; i < transponder.dma_buffer_size; i++) {
106 EXPECT_EQ(transponder.transponderIrDMABuffer.ilap[i], excepted[i]);