Fix typo
[inav.git] / src / test / unit / gps_ublox_unittest.cc
blobbc20b3402511afec3c5b7920fa1b212a1e60dd2d
1 /*
2 * This file is part of INAV.
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/>.
19 #include "gtest/gtest.h"
20 #include "unittest_macros.h"
22 #include <iostream>
23 #include <string>
24 #include <stdio.h>
26 #include "io/gps_ublox_utils.h"
28 void dumpCfg(const ubx_config_data8_t *cfg, int valuesAdded)
30 printf("%02x %02x %02x %02x %04x\n", cfg->header.preamble1, cfg->header.preamble2, cfg->header.msg_class, cfg->header.msg_id, cfg->header.length);
32 printf("%02x %02x %02x %02x\n", cfg->configHeader.version, cfg->configHeader.layers, cfg->configHeader.transaction, cfg->configHeader.reserved);
34 for(int i =0; i < valuesAdded; ++i) {
35 printf("%i: %08x %02x\n", i+1, cfg->data.payload[i].key, cfg->data.payload[i].value);
38 uint8_t *chksums = (uint8_t *)&cfg->data.payload[valuesAdded];
40 printf("%02x %02x\n", chksums[0], chksums[1]);
43 void dumpMemory(uint8_t *mem, int size)
45 for(int i =0; i < size; ++i) {
46 printf("%02x ", mem[i]);
48 printf("\n");
51 TEST(GPSUbloxTest, TestUbloxCfgFillBytes)
53 ubx_config_data8_t cfg = {};
54 ubx_config_data8_payload_t kvPairs[] = {
55 { 0x10310025, 0x1},
56 { 0x42, 0x69},
57 { 0x04, 0x20},
58 { 0x42, 0x69},
59 { 0x04, 0x20},
60 { 0x42, 0x69},
61 { 0x04, 0x20},
62 { 0x42, 0x69},
63 { 0x04, 0x20},
64 { 0x42, 0x69},
65 { 0x04, 0x20},
66 { 0x42, 0x69}
69 int valuesAdded = ubloxCfgFillBytes(&cfg, kvPairs, 12);
71 EXPECT_TRUE(valuesAdded == 12);
73 dumpCfg(&cfg, valuesAdded);
75 valuesAdded = ubloxCfgFillBytes(&cfg, kvPairs, 1);
76 EXPECT_TRUE(1 == valuesAdded);
78 // Set glonass enabled, from u-center 2
79 const uint8_t expected[] = {0xB5, 0x62, 0x06, 0x8A, 0x09, 0x00, 0x01, 0x01, 0x00, 0x00, 0x25, 0x00, 0x31, 0x10, 0x01, 0x02, 0xA7};
80 EXPECT_FALSE(memcmp((void *)expected, (void *)&cfg, 17));
82 printf("Expected:\n");
83 dumpMemory((uint8_t *)expected, 17);
84 printf("Actual:\n");
85 dumpMemory((uint8_t *)&cfg, 17);
87 // osdFormatCentiNumber(buf, 12345, 1, 2, 3, 7);
88 // std::cout << "'" << buf << "'" << std::endl;
89 //EXPECT_FALSE(strcmp(buf, " 123.45"));