14
14
#include <stdio.h>
15
15
#include <check.h>
16
16
#include <math.h>
17
+ #include <string.h>
17
18
#include <libswiftnav/nav_msg_glo.h>
18
19
#include <libswiftnav/logging.h>
19
20
@@ -29,7 +30,8 @@ ephemeris_t e;
29
30
* 0aad8090a54019cb035d3f,0,0b3e2240201e97fc34fc39,0,0cae940cdc3c1e2786da9b,0,
30
31
* 0d68bf54a4c697f115320b,0,0eaf8449b38c1e228932d8,0,0f815b653eee981314802a,0*f3837a1c
31
32
*/
32
- u32 strings_in [5 ][3 ] = {
33
+ u32 strings_in [6 ][3 ] = {
34
+ {1 ,1 ,1 }, /* dummy words used in test_nav_msg_update_glo only */
33
35
{0xc3a850b5 , 0x96999b05 , 0x010743 }, /* 01074396999b05c3a850b5 */
34
36
{0xd9c15f66 , 0xa5256204 , 0x021760 }, /* 021760a5256204d9c15f66 */
35
37
{0x6d0e3123 , 0x9d60899a , 0x038026 }, /* 0380269d60899a6d0e3123 */
@@ -60,6 +62,36 @@ double AZ = -2.79396772384643555e-06;
60
62
double GAMMA = 1.81898940354585648e-12 ;
61
63
double TAU = -9.71024855971336365e-05 ;
62
64
65
+ void e_out (void )
66
+ {
67
+ log_debug ("GLO Ephemeris:\n" );
68
+ log_debug ("\tSID: %u (code %u)\n" , e .sid .sat , e .sid .code );
69
+ log_debug ("\tGPS time: TOE %f, WN %d\n" , e .toe .tow , e .toe .wn );
70
+ log_debug ("\tURA: %f\n" , e .ura );
71
+ log_debug ("\tFit interval: %u\n" , e .fit_interval );
72
+ log_debug ("\tValid: %u\n" , e .valid );
73
+ log_debug ("\tHealthy: %u\n" , e .healthy );
74
+ log_debug ("\tgamma: %25.18f\n" , e .glo .gamma );
75
+ log_debug ("\ttau: %25.18f\n" , e .glo .tau );
76
+ log_debug ("\tX, Y, Z: %25.18f, %25.18f, %25.18f\n" ,
77
+ e .glo .pos [0 ], e .glo .pos [1 ], e .glo .pos [2 ]);
78
+ log_debug ("\tVX, VY, VZ: %25.18f, %25.18f, %25.18f\n" ,
79
+ e .glo .vel [0 ], e .glo .vel [1 ], e .glo .vel [2 ]);
80
+ log_debug ("\tAX, AY, AZ: %25.18f, %25.18f, %25.18f\n" ,
81
+ e .glo .acc [0 ], e .glo .acc [1 ], e .glo .acc [2 ]);
82
+ fail_unless (e .glo .pos [0 ]- X == 0 , "dX %25.18f, expected %25.18f" , e .glo .pos [0 ], X );
83
+ fail_unless (e .glo .pos [1 ]- Y == 0 , "dY %25.18f, expected %25.18f" , e .glo .pos [1 ], Y );
84
+ fail_unless (e .glo .pos [2 ]- Z == 0 , "dZ %25.18f, expected %25.18f" , e .glo .pos [2 ], Z );
85
+ fail_unless (e .glo .vel [0 ]- VX == 0 , "dVX %25.18f, expected %25.18f" , e .glo .vel [0 ], VX );
86
+ fail_unless (e .glo .vel [1 ]- VY == 0 , "dVY %25.18f, expected %25.18f" , e .glo .vel [1 ], VY );
87
+ fail_unless (e .glo .vel [2 ]- VZ == 0 , "dVZ %25.18f, expected %25.18f" , e .glo .vel [2 ], VZ );
88
+ fail_unless (e .glo .acc [0 ]- AX == 0 , "dAX %25.18f, expected %25.18f" , e .glo .acc [0 ], AX );
89
+ fail_unless (e .glo .acc [1 ]- AY == 0 , "dAY %25.18f, expected %25.18f" , e .glo .acc [1 ], AY );
90
+ fail_unless (e .glo .acc [2 ]- AZ == 0 , "dAZ %25.18f, expected %25.18f" , e .glo .acc [2 ], AZ );
91
+ fail_unless (e .glo .tau - TAU == 0 , "dTAU %25.18f, expected %25.18f" , e .glo .tau , TAU );
92
+ fail_unless (e .glo .gamma - GAMMA == 0 , "dGAMMA %25.18f, expected %25.18f" , e .glo .gamma , GAMMA );
93
+ }
94
+
63
95
START_TEST (test_extract_glo_word )
64
96
{
65
97
u32 ret = 0 ;
@@ -101,44 +133,66 @@ END_TEST
101
133
START_TEST (test_process_string_glo )
102
134
{
103
135
nav_msg_init_glo (& n );
104
- for (u8 i = 0 ; i < sizeof (strings_in )/sizeof (strings_in [0 ]); i ++ ) {
136
+ memset (& e ,0 ,sizeof (e ));
137
+ for (u8 i = 1 ; i < sizeof (strings_in )/sizeof (strings_in [1 ]); i ++ ) {
105
138
memcpy (n .string_bits , strings_in [i ], sizeof (n .string_bits ));
106
139
process_string_glo (& n , & e );
107
140
}
108
- log_debug ("GLO Ephemeris:\n" );
109
- log_debug ("\tSID: %u (code %u)\n" , e .sid .sat , e .sid .code );
110
- log_debug ("\tGPS time: TOE %f, WN %d\n" , e .toe .tow , e .toe .wn );
111
- log_debug ("\tURA: %f\n" , e .ura );
112
- log_debug ("\tFit interval: %u\n" , e .fit_interval );
113
- log_debug ("\tValid: %u\n" , e .valid );
114
- log_debug ("\tHealthy: %u\n" , e .healthy );
115
- log_debug ("\tgamma: %25.18f\n" , e .glo .gamma );
116
- log_debug ("\ttau: %25.18f\n" , e .glo .tau );
117
- log_debug ("\tX, Y, Z: %25.18f, %25.18f, %25.18f\n" ,
118
- e .glo .pos [0 ], e .glo .pos [1 ], e .glo .pos [2 ]);
119
- log_debug ("\tVX, VY, VZ: %25.18f, %25.18f, %25.18f\n" ,
120
- e .glo .vel [0 ], e .glo .vel [1 ], e .glo .vel [2 ]);
121
- log_debug ("\tAX, AY, AZ: %25.18f, %25.18f, %25.18f\n" ,
122
- e .glo .acc [0 ], e .glo .acc [1 ], e .glo .acc [2 ]);
123
- fail_unless (e .glo .pos [0 ]- X == 0 , "dX %25.18f, expected %25.18f" , e .glo .pos [0 ], X );
124
- fail_unless (e .glo .pos [1 ]- Y == 0 , "dY %25.18f, expected %25.18f" , e .glo .pos [1 ], Y );
125
- fail_unless (e .glo .pos [2 ]- Z == 0 , "dZ %25.18f, expected %25.18f" , e .glo .pos [2 ], Z );
126
- fail_unless (e .glo .vel [0 ]- VX == 0 , "dVX %25.18f, expected %25.18f" , e .glo .vel [0 ], VX );
127
- fail_unless (e .glo .vel [1 ]- VY == 0 , "dVY %25.18f, expected %25.18f" , e .glo .vel [1 ], VY );
128
- fail_unless (e .glo .vel [2 ]- VZ == 0 , "dVZ %25.18f, expected %25.18f" , e .glo .vel [2 ], VZ );
129
- fail_unless (e .glo .acc [0 ]- AX == 0 , "dAX %25.18f, expected %25.18f" , e .glo .acc [0 ], AX );
130
- fail_unless (e .glo .acc [1 ]- AY == 0 , "dAY %25.18f, expected %25.18f" , e .glo .acc [1 ], AY );
131
- fail_unless (e .glo .acc [2 ]- AZ == 0 , "dAZ %25.18f, expected %25.18f" , e .glo .acc [2 ], AZ );
132
- fail_unless (e .glo .tau - TAU == 0 , "dTAU %25.18f, expected %25.18f" , e .glo .tau , TAU );
133
- fail_unless (e .glo .gamma - GAMMA == 0 , "dGAMMA %25.18f, expected %25.18f" , e .glo .gamma , GAMMA );
141
+ e_out ();
142
+ }
143
+ END_TEST
144
+
145
+ START_TEST (test_nav_msg_update_glo )
146
+ {
147
+ /* the unit test encodes strings_in to generate glo bitstream, calls
148
+ * nav_msg_update_glo to receive and finally decodes received string */
149
+ nav_msg_init_glo (& n );
150
+ memset (& e ,0 ,sizeof (e ));
151
+ /* get string one by one */
152
+ for (u8 i = 0 ; i < sizeof (strings_in )/sizeof (strings_in [0 ]); i ++ ) {
153
+ u8 manchester = 0 ;
154
+ nav_msg_glo_t a ;
155
+ s8 ret ;
156
+ u8 j ;
157
+ nav_msg_init_glo (& a );
158
+ /* write test string to temporary buffer */
159
+ memcpy (a .string_bits , strings_in [i ], sizeof (n .string_bits ));
160
+ /* transmit data bits, 85 bit */
161
+ for (j = 85 ; j > 0 ; j -- ) {
162
+ bool one_bit = extract_word_glo (& a ,j ,1 ); /* get bit to be transmitted */
163
+ manchester = (one_bit << 1 | one_bit ) ^ 2 ; /* transform to line code */
164
+ /* now pass it to receiver MSB first, receiver must return -1 */
165
+ ret = nav_msg_update_glo (& n , (manchester >> 1 ) & 1 );
166
+ fail_unless (ret == -1 , "ret = %d, expected -1" , ret );
167
+ /* now LSB, receiver must return -1 */
168
+ ret = nav_msg_update_glo (& n , manchester & 1 );
169
+ }
170
+ /* try to decode the string */
171
+ if (ret == 1 ) {
172
+ fail_unless (memcmp (a .string_bits , n .string_bits , sizeof (a .string_bits )) == 0 ,
173
+ "Received string %x%x%x not equal to trasmitted one %x%x%x" ,
174
+ n .string_bits [2 ],n .string_bits [1 ],n .string_bits [0 ],
175
+ a .string_bits [2 ],a .string_bits [1 ],a .string_bits [0 ]);
176
+
177
+ if (process_string_glo (& n , & e ) == 1 )
178
+ e_out ();
179
+ }
180
+ /* now pass time mark bit by bit to receiver (MSB first), no line code needed */
181
+ for (u8 j = 30 ; j > 0 ; j -- ) {
182
+ ret = nav_msg_update_glo (& n , (GLO_TM >> (j - 1 )) & 1 );
183
+ fail_unless (ret == -1 , "ret = %d, expected -1" , ret );
184
+ }
185
+ }
134
186
}
135
187
END_TEST
188
+
136
189
Suite * glo_decoder_test_suite (void )
137
190
{
138
191
Suite * s = suite_create ("GLO decoder" );
139
192
TCase * tc_core = tcase_create ("Core" );
140
193
tcase_add_test (tc_core , test_extract_glo_word );
141
194
tcase_add_test (tc_core , test_process_string_glo );
195
+ tcase_add_test (tc_core , test_nav_msg_update_glo );
142
196
suite_add_tcase (s , tc_core );
143
197
144
198
return s ;
0 commit comments