Skip to content
This repository was archived by the owner on Apr 13, 2021. It is now read-only.

Commit dc9e29e

Browse files
author
Dmitry Tatarinov
committed
Add test for extract_glo_word
1 parent 3286b2c commit dc9e29e

File tree

8 files changed

+297
-0
lines changed

8 files changed

+297
-0
lines changed

include/libswiftnav/nav_msg_glo.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (C) 2016 Swift Navigation Inc.
3+
* Contact: Dmitry Tatarinov <dmitry.tatarinov@exafore.com>
4+
*
5+
* This source is subject to the license found in the file 'LICENSE' which must
6+
* be be distributed together with this source. All other rights reserved.
7+
*
8+
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
9+
* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
10+
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
11+
*/
12+
13+
#ifndef LIBSWIFTNAV_NAV_MSG_GLO_H
14+
#define LIBSWIFTNAV_NAV_MSG_GLO_H
15+
16+
#include <libswiftnav/common.h>
17+
18+
#define NAV_MSG_GLO_STRING_BITS_LEN 3 /* Buffer 96 nav bits. */
19+
20+
typedef struct {
21+
u32 string_bits[NAV_MSG_GLO_STRING_BITS_LEN];
22+
u8 next_string_id;
23+
} nav_msg_glo_t;
24+
25+
void nav_msg_init_glo(nav_msg_glo_t *n);
26+
u32 extract_word_glo(nav_msg_glo_t *n, u16 bit_index, u8 n_bits); //TODO: this will be static so remove after test
27+
28+
#endif /* LIBSWIFTNAV_NAV_MSG_GLO_H */

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ set(libswiftnav_SRCS
4646
ionosphere.c
4747
bit_sync.c
4848
cnav_msg.c
49+
nav_msg_glo.c
4950
${plover_SRCS}
5051

5152
CACHE INTERNAL ""

src/ephemeris.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,23 @@ void decode_ephemeris(u32 frame_words[3][8], ephemeris_t *e)
763763
log_warn_sid(e->sid, "Latest ephemeris had IODC/IODE mismatch. Ignoring ephemeris.");
764764
}
765765
}
766+
#if 0
767+
/** Decode ephemeris from L1 GLO navigation message frames.
768+
*
769+
* \note This function does not check for parity errors. You should check the
770+
* subframes for parity errors before calling this function.
771+
*
772+
* References:
773+
* TODO -# IS-GPS-200D, Section 20.3.2 and Figure 20-1
774+
*
775+
* \param string Array containing 85 bits strings 1 through 3 of any GLO frames
776+
* \param e Pointer to an ephemeris struct to fill in.
777+
*/
778+
void decode_glo_ephemeris(u32 strigs[3][4], ephemeris_t *e)
779+
{
766780

781+
}
782+
#endif
767783
static bool ephemeris_xyz_equal(const ephemeris_xyz_t *a,
768784
const ephemeris_xyz_t *b)
769785
{

src/nav_msg_glo.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (C) 2016 Swift Navigation Inc.
3+
* Contact: Dmitry Tatarinov <dmitry.tatarinov@exafore.com>
4+
*
5+
* This source is subject to the license found in the file 'LICENSE' which must
6+
* be be distributed together with this source. All other rights reserved.
7+
*
8+
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
9+
* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
10+
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
11+
*/
12+
#include <assert.h>
13+
#include <string.h>
14+
#include <stdio.h>
15+
#include <libswiftnav/nav_msg_glo.h>
16+
17+
void nav_msg_init_glo(nav_msg_glo_t *n)
18+
{
19+
/* Initialize the necessary parts of the nav message state structure. */
20+
memset(n, 0, sizeof(nav_msg_glo_t));
21+
n->next_string_id = 1;
22+
}
23+
24+
/** Extract a word of n_bits length (n_bits <= 32) at position bit_index into
25+
* the subframe. Takes account of the offset stored in n, and the circular
26+
* nature of the n->subframe_bits buffer.
27+
* Refer to bit index to Table 4.6 in GLO ICD 5.1 (pg. 34)
28+
* \param n pointer to GLO nav message structure to be parsed
29+
* \param bit_index number of bit to the extract process start with. Range [1..85]
30+
* \param n_bits how many bits should be extract [1..32]
31+
* \return word extracted from navigation string */
32+
u32 extract_word_glo(nav_msg_glo_t *n, u16 bit_index, u8 n_bits)
33+
{
34+
assert(n_bits <= 32 && n_bits > 0);
35+
assert(bit_index <= 85 && bit_index > 0);
36+
37+
/* Extract a word of n_bits length (n_bits <= 32) at position bit_index into
38+
* the GLO string.*/
39+
bit_index--;
40+
u32 word = 0;
41+
u8 bix_hi = bit_index >> 5;
42+
u8 bix_lo = bit_index & 0x1F;
43+
if (bix_lo + n_bits <= 32) {
44+
word = n->string_bits[bix_hi] >> bix_lo;
45+
word &= (0xffffffff << (32-n_bits)) >> (32-n_bits);
46+
} else {
47+
u8 s = 32-bix_lo;
48+
word = extract_word_glo(n, bit_index+1, s) |
49+
extract_word_glo(n, bit_index+1 + s, n_bits - s) << s;
50+
}
51+
52+
return word;
53+
}
54+
#if 0
55+
static s8 process_string_glo(nav_msg_t *n, ephemeris_t *e)
56+
{
57+
/* Extract dummy bit from string */
58+
/* sanity check dummy bit */
59+
/* Extract string number */
60+
61+
/* Extract time stamp from a sting */
62+
u32 ts = extract_word(n, 0, 30, 0);
63+
if (nav_parity(&sf_word2)) {
64+
log_info_sid(e->sid, "subframe parity mismatch (word 2)");
65+
n->gps.subframe_start_index = 0; // Mark the subframe as processed
66+
n->gps.next_subframe_id = 1; // Make sure we start again next time
67+
return -2;
68+
}
69+
70+
return 0;
71+
}
72+
#endif

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ else (CMAKE_CROSSCOMPILING)
4848
check_signal.c
4949
check_track.c
5050
check_cnav.c
51+
check_glo_decoder.c
5152
)
5253

5354
target_link_libraries(test_libswiftnav ${TEST_LIBS})

tests/check_glo_decoder.c

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/*
2+
* Copyright (C) 2016 Swift Navigation Inc.
3+
* Contact: Dmitry Tatarinov <dmitry.tatarinov@exafore.com>
4+
*
5+
* This source is subject to the license found in the file 'LICENSE' which must
6+
* be be distributed together with this source. All other rights reserved.
7+
*
8+
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
9+
* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
10+
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
11+
*/
12+
13+
#include <stdio.h>
14+
#include <check.h>
15+
#include <math.h>
16+
#include <libswiftnav/nav_msg_glo.h>
17+
18+
nav_msg_glo_t n;
19+
20+
21+
START_TEST(test_extract_glo_word)
22+
{
23+
u32 ret = 0;
24+
nav_msg_init_glo(&n);
25+
n.string_bits[0] = 5;
26+
n.string_bits[1] = 5;
27+
n.string_bits[2] = 5;
28+
ret = extract_word_glo(&n,1,32);
29+
fail_unless(ret == 5, "1. %x, expected %x", ret, 5);
30+
ret = extract_word_glo(&n,33,3);
31+
fail_unless(ret == 5, "2. %x, expected %x", ret, 5);
32+
ret = extract_word_glo(&n,65,3);
33+
fail_unless(ret == 5, "3. %x, expected %x", ret, 5);
34+
35+
n.string_bits[0] = 0x12345678;
36+
n.string_bits[1] = 0xdeadbeef;
37+
n.string_bits[2] = 0x87654321;
38+
ret = extract_word_glo(&n,1,32);
39+
fail_unless(ret == 0x12345678, "4. %x, expected %x", ret, 0x12345678);
40+
ret = extract_word_glo(&n,33,32);
41+
fail_unless(ret == 0xdeadbeef, "5. %x, expected %x", ret, 0xdeadbeef);
42+
ret = extract_word_glo(&n,65,32);
43+
fail_unless(ret == 0x87654321, "6. %x, expected %x", ret, 0x87654321);
44+
ret = extract_word_glo(&n,49,4);
45+
fail_unless(ret == 0xd, "7. %x, expected %x", ret, 0xd);
46+
47+
n.string_bits[0] = 0xbeef0000;
48+
n.string_bits[1] = 0x4321dead;
49+
n.string_bits[2] = 0x00008765;
50+
ret = extract_word_glo(&n,17,32);
51+
fail_unless(ret == 0xdeadbeef, "8. %x, expected %x", ret, 0xdeadbeef);
52+
ret = extract_word_glo(&n,49,32);
53+
fail_unless(ret == 0x87654321, "9. %x, expected %x", ret, 0x87654321);
54+
ret = extract_word_glo(&n,49,16);
55+
fail_unless(ret == 0x4321, "10. %x, expected %x", ret, 0x4321);
56+
}
57+
END_TEST
58+
59+
START_TEST(test_extract_real_glo_word)
60+
{
61+
u32 ret = 0;
62+
u8 sign = 0;
63+
double f_ret;
64+
nav_msg_init_glo(&n);
65+
//parse string 1
66+
n.string_bits[0] = 0xc3a850b5;
67+
n.string_bits[1] = 0x96999b05;
68+
n.string_bits[2] = 0x010743;
69+
ret = extract_word_glo(&n,85,1);
70+
fail_unless(ret == 0, "1. %x, expected %x", ret, 0);
71+
ret = extract_word_glo(&n,81,4);
72+
fail_unless(ret == 1, "2. %x, expected %x", ret, 1);
73+
printf("STRING %u\n",ret);
74+
ret = extract_word_glo(&n,9,26);
75+
sign = extract_word_glo(&n,9+26,1);
76+
f_ret = sign ? -1.0*ret*pow(2,-11)*1000.0 : ret*pow(2,-11)*1000.0;
77+
printf("x = %f(%x, %u)\n",f_ret,ret,sign);
78+
ret = extract_word_glo(&n,41,23);
79+
sign = extract_word_glo(&n,41+23,1);
80+
f_ret = sign ? -1.0*ret*pow(2,-20)*1000.0 : ret*pow(2,-20)*1000.0;
81+
printf("Vx = %f(%x, %u)\n",f_ret,ret,sign);
82+
ret = extract_word_glo(&n,36,4);
83+
sign = extract_word_glo(&n,36+4,1);
84+
f_ret = sign ? -1.0*ret*pow(2,-30)*1000.0 : ret*pow(2,-30)*1000.0;
85+
printf("Ax = %f(%x, %u)\n",f_ret,ret,sign);
86+
ret = extract_word_glo(&n,65,12);
87+
printf("row Tk = %x\n",ret);
88+
ret = extract_word_glo(&n,65,5);
89+
printf("Tk(hours) = %u\n",ret);
90+
ret = extract_word_glo(&n,70,6);
91+
printf("Tk(mins) = %u\n",ret);
92+
ret = extract_word_glo(&n,76,1);
93+
printf("Tk(sec) = %u\n",ret);
94+
//parse string 2
95+
n.string_bits[0] = 0xd9c15f66;
96+
n.string_bits[1] = 0xa5256204;
97+
n.string_bits[2] = 0x021760;
98+
ret = extract_word_glo(&n,85,1);
99+
fail_unless(ret == 0, "1. %x, expected %x", ret, 0);
100+
ret = extract_word_glo(&n,81,4);
101+
fail_unless(ret == 2, "2. %x, expected %x", ret, 2);
102+
printf("STRING %u\n",ret);
103+
ret = extract_word_glo(&n,9,26);
104+
sign = extract_word_glo(&n,9+26,1);
105+
f_ret = sign ? -1.0*ret*pow(2,-11)*1000.0 : ret*pow(2,-11)*1000.0;
106+
printf("y = %f(%x, %u)\n",f_ret,ret,sign);
107+
ret = extract_word_glo(&n,41,23);
108+
sign = extract_word_glo(&n,41+23,1);
109+
f_ret = sign ? -1.0*ret*pow(2,-20)*1000.0 : ret*pow(2,-20)*1000.0;
110+
printf("Vy = %f(%x, %u)\n",f_ret,ret,sign);
111+
ret = extract_word_glo(&n,36,4);
112+
sign = extract_word_glo(&n,36+4,1);
113+
f_ret = sign ? -1.0*ret*pow(2,-30)*1000.0 : ret*pow(2,-30)*1000.0;
114+
printf("Ay = %f(%x, %u)\n",f_ret,ret,sign);
115+
//parse string 3
116+
n.string_bits[0] = 0x6d0e3123;
117+
n.string_bits[1] = 0x9d60899a;
118+
n.string_bits[2] = 0x038026;
119+
ret = extract_word_glo(&n,85,1);
120+
fail_unless(ret == 0, "1. %x, expected %x", ret, 0);
121+
ret = extract_word_glo(&n,81,4);
122+
fail_unless(ret == 3, "2. %x, expected %x", ret, 3);
123+
printf("STRING %u\n",ret);
124+
ret = extract_word_glo(&n,9,26);
125+
sign = extract_word_glo(&n,9+26,1);
126+
f_ret = sign ? -1.0*ret*pow(2,-11)*1000.0 : ret*pow(2,-11)*1000.0;
127+
printf("z = %f(%x, %u)\n",f_ret,ret,sign);
128+
ret = extract_word_glo(&n,41,23);
129+
sign = extract_word_glo(&n,41+23,1);
130+
f_ret = sign ? -1.0*ret*pow(2,-20)*1000.0 : ret*pow(2,-20)*1000.0;
131+
printf("Vz = %f(%x, %u)\n",f_ret,ret,sign);
132+
ret = extract_word_glo(&n,36,4);
133+
sign = extract_word_glo(&n,36+4,1);
134+
f_ret = sign ? -1.0*ret*pow(2,-30)*1000.0 : ret*pow(2,-30)*1000.0;
135+
printf("Az = %f(%x, %u)\n",f_ret,ret,sign);
136+
ret = extract_word_glo(&n,66,2);
137+
printf("P = %u\n",ret);
138+
//parse string 4
139+
n.string_bits[0] = 0x00344918;
140+
n.string_bits[1] = 0x1cc00000;
141+
n.string_bits[2] = 0x04865d;
142+
ret = extract_word_glo(&n,85,1);
143+
fail_unless(ret == 0, "1. %x, expected %x", ret, 0);
144+
ret = extract_word_glo(&n,81,4);
145+
fail_unless(ret == 4, "2. %x, expected %x", ret, 4);
146+
printf("STRING %u\n",ret);
147+
ret = extract_word_glo(&n,16,11);
148+
printf("Nt = %u\n",ret);
149+
//parse string 5
150+
n.string_bits[0] = 0x40000895;
151+
n.string_bits[1] = 0x3;
152+
n.string_bits[2] = 0x050d10;
153+
ret = extract_word_glo(&n,85,1);
154+
fail_unless(ret == 0, "1. %x, expected %x", ret, 0);
155+
ret = extract_word_glo(&n,81,4);
156+
fail_unless(ret == 5, "2. %x, expected %x", ret, 5);
157+
printf("STRING %u\n",ret);
158+
ret = extract_word_glo(&n,38,32);
159+
printf("Tau c = %u\n",ret);
160+
ret = extract_word_glo(&n,32,5);
161+
printf("N4 = %u\n",ret);
162+
ret = extract_word_glo(&n,10,22);
163+
printf("Tau GPS = %u\n",ret);
164+
ret = extract_word_glo(&n,70,11);
165+
printf("Na = %u\n",ret);
166+
}
167+
END_TEST
168+
Suite* glo_decoder_test_suite(void)
169+
{
170+
Suite *s = suite_create("GLO decoder");
171+
TCase *tc_core = tcase_create("Core");
172+
tcase_add_test(tc_core, test_extract_glo_word);
173+
tcase_add_test(tc_core, test_extract_real_glo_word);
174+
suite_add_tcase(s, tc_core);
175+
176+
return s;
177+
}

tests/check_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ int main(void)
3434
srunner_add_suite(sr, signal_test_suite());
3535
srunner_add_suite(sr, track_test_suite());
3636
srunner_add_suite(sr, cnav_test_suite());
37+
srunner_add_suite(sr, glo_decoder_test_suite());
3738

3839
srunner_set_fork_status(sr, CK_NOFORK);
3940
srunner_run_all(sr, CK_NORMAL);

tests/check_suites.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ Suite* ionosphere_suite(void);
2424
Suite* signal_test_suite(void);
2525
Suite* track_test_suite(void);
2626
Suite* cnav_test_suite(void);
27+
Suite* glo_decoder_test_suite(void);
2728

2829
#endif /* CHECK_SUITES_H */

0 commit comments

Comments
 (0)