33 #include "gtest/gtest.h"
42 #include "../../PiOS/Common/pios_dsm.c"
46 dsm_dev->resolution = DSM_UNKNOWN;
49 dsm_dev->state.channel_data[
i] = 0;
57 uint8_t resolution = (dsm_dev->resolution == DSM_10BIT) ? 10 : 11;
78 int validate_file(
const char *fn,
int resolution,
int channels,
bool skip);
81 struct pios_dsm_dev
dev;
84 const int idx11[] = {1,5,2,3,0,7,6,1,5,2,3,4,8,9};
85 const int idx10[] = {1,5,4,2,6,0,3,1,5,4,2,6,0,3};
91 uint16_t
j =
idx10[
i + DSM_CHANNELS_PER_FRAME*frame];
92 uint16_t val = channels[
j];
93 uint16_t word = ((frame & (
i == 0)) ? 0x8000 : 0) | ((j & 0x000F) << 10) | (val & 0x03FF);
94 state->received_data[2 + i * 2 + 1] = word & 0x00FF;
95 state->received_data[2 + i * 2] = (word >> 8) & 0x00FF;
103 uint16_t
j =
idx11[
i + DSM_CHANNELS_PER_FRAME*frame];
104 uint16_t val = channels[
j];
105 uint16_t word = ((frame & (
i == 0)) ? 0x8000 : 0) | ((j & 0x000F) << 11) | (val & 0x07FF);
106 state->received_data[2 + i * 2 + 1] = word & 0x00FF;
107 state->received_data[2 + i * 2] = (word >> 8) & 0x00FF;
114 EXPECT_EQ(c1[
i], c2[i]);
120 pack_channels_10bit(channels,
state,
false);
122 state->received_data[
i] = 0;
123 EXPECT_EQ(-2, PIOS_DSM_UnrollChannels(&dev));
127 uint16_t channels[
PIOS_DSM_NUM_INPUTS] = {512, 513, 514, 515, 516, 517, 518, 0, 0, 0, 0, 0};
128 pack_channels_10bit(channels,
state,
false);
129 EXPECT_EQ(0, PIOS_DSM_UnrollChannels(&dev));
130 pack_channels_10bit(channels,
state,
true);
131 EXPECT_EQ(0, PIOS_DSM_UnrollChannels(&dev));
138 uint16_t channels[
PIOS_DSM_NUM_INPUTS] = {512, 513, 514, 515, 516, 517, 518, 0, 0, 0, 0, 0};
139 pack_channels_11bit(channels,
state,
false);
140 EXPECT_EQ(0, PIOS_DSM_UnrollChannels(&dev));
141 pack_channels_11bit(channels,
state,
true);
142 EXPECT_EQ(0, PIOS_DSM_UnrollChannels(&dev));
154 if (fscanf(fid,
"%lf,%hhx,,", &t, &val) == 2) {
165 FILE *fid = fopen(fn,
"r");
170 getline(&line, &len, fid);
172 const int MIN = (resolution == 11) ? 340 : 150;
173 const int MAX = (resolution == 11) ? 2048 : 1024;
174 if (resolution == 11)
185 PIOS_DSM_UnrollChannels(&
dev);
188 EXPECT_EQ(0, PIOS_DSM_UnrollChannels(&
dev));
193 EXPECT_EQ(0, PIOS_DSM_UnrollChannels(&
dev));
199 valid[
i] = ((
i >= channels) &&
dev.state.channel_data[
i] == 0) ||
200 ((
i < channels) && ((
dev.state.channel_data[
i] > MIN) && (
dev.state.channel_data[
i] <=
MAX)));
202 EXPECT_TRUE(valid[
i]);
206 fprintf(stdout,
"%d, ",
dev.state.channel_data[i]);
208 fprintf(stdout,
"\r\n");
227 validate_file(
"DX7_11msDSM2.txt",11,8,
false);
231 validate_file(
"DX7_11msDSM2.txt",11,8,
true);
235 validate_file(
"DX7_22msDSM2.txt",11,8,
false);
238 validate_file(
"DX7_22msDSM2.txt",11,8,
true);
242 validate_file(
"DX7_11msDSMX.txt",11,8,
false);
246 validate_file(
"DX7_11msDSMX.txt",11,8,
true);
250 validate_file(
"DX7_22msDSMX.txt",11,8,
false);
254 validate_file(
"DX7_22msDSMX.txt",11,8,
true);
258 validate_file(
"DX18_11msDSM2_2048res.txt",11,10,
false);
262 validate_file(
"DX18_11msDSM2_2048res.txt",11,10,
true);
269 validate_file(
"DX18_22msDSM2_1024res.txt",11,12,
false);
275 validate_file(
"DX18_22msDSM2_1024res.txt",11,12,
true);
281 validate_file(
"DX18_22msDSM2_XPlus_1024res.txt",11,12,
false);
287 validate_file(
"DX18_22msDSM2_XPlus_1024res.txt",11,12,
true);
291 validate_file(
"DX18_22msDSMX.txt",11,12,
false);
295 validate_file(
"DX18_22msDSMX.txt",11,12,
true);
299 validate_file(
"DX18_11msDSMX.txt",11,10,
false);
303 validate_file(
"DX18_11msDSMX.txt",11,10,
true);
307 validate_file(
"DX18_22msDSMX_XPlus.txt",11,12,
false);
311 validate_file(
"DX18_22msDSMX_XPlus.txt",11,12,
true);
320 FILE *fid = fopen(
"DX7_DSM2_10bit.dat",
"r");
325 while((c = fgetc(fid)) != EOF) {
326 state->received_data[i++] = c;
329 PIOS_DSM_UnrollChannels(&dev);
333 const uint8_t channels = 7;
334 const uint16_t
MIN = 45;
335 const uint16_t
MAX = 1024;
340 valid[
j] = ((
j >= channels) && dev.state.channel_data[
j] == 0) ||
341 ((
j < channels) && ((dev.state.channel_data[
j] > MIN) && (dev.state.channel_data[
j] <=
MAX)));
342 EXPECT_TRUE(valid[
j]);
#define DSM_CHANNELS_PER_FRAME
TEST_F(RneFromLLATest, Equator)
void verify_channels(uint16_t *c1, uint16_t *c2)
int get_packet(FILE *fid, uint8_t *buf)
int PIOS_DSM_Reset(struct pios_dsm_dev *dsm_dev)
Spektrum/JR DSMx satellite receiver private structures.
int validate_file(const char *fn, int resolution, int channels, bool skip)
void pack_channels_10bit(uint16_t channels[DSM_CHANNELS_PER_FRAME], struct pios_dsm_state *state, bool frame)
pack data into DSM2 10 bit packets
int PIOS_DSM_GetResolution(struct pios_dsm_dev *dsm_dev)
void pack_channels_11bit(uint16_t channels[DSM_CHANNELS_PER_FRAME], struct pios_dsm_state *state, bool frame)
pack data into DSM2 11 bit packets
#define PIOS_DSM_NUM_INPUTS
struct pios_dsm_state * state