99 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
1010 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
1111 */
12- #define DEBUG 1
12+ // #define DEBUG 1
1313
1414#include <stdio.h>
1515#include <check.h>
@@ -168,7 +168,7 @@ START_TEST(test_nav_msg_update_glo)
168168 nav_msg_init_glo (& a );
169169 /* write test string to temporary buffer */
170170 memcpy (a .string_bits , strings_in [i ], sizeof (n .string_bits ));
171- /* transmit data bits, 85 bit */
171+ /* transmit data bits, 85 bits */
172172 for (j = 85 ; j > 0 ; j -- ) {
173173 bool one_bit = extract_word_glo (& a , j , 1 ); /* get bit to be transmitted */
174174 manchester = (one_bit << 1 | one_bit ) ^ 2 ; /* transform to line code */
@@ -188,6 +188,7 @@ START_TEST(test_nav_msg_update_glo)
188188
189189 if (process_string_glo (& n , & e ) == 1 )
190190 e_out ();
191+
191192 }
192193 /* now pass time mark bit by bit to receiver (MSB first),
193194 * no line code needed */
@@ -199,13 +200,65 @@ START_TEST(test_nav_msg_update_glo)
199200}
200201END_TEST
201202
203+ START_TEST (test_error_correction_glo )
204+ {
205+ const struct {
206+ u32 str_in [3 ]; /**< input string for test */
207+ s8 ret ; /** result of the test */
208+ } test_case [] = {
209+ /* First, simply test one GLO nav message received from Novatel,
210+ * we trust Novatel, so no errors must be */
211+ { {0xc90cfb3e , 0x9743a301 , 0x010749 }, 0 }, /* case 0 */
212+ { {0xdd39f5fc , 0x24542d0c , 0x021760 }, 0 },
213+ { {0x653bc7e9 , 0x1e8ead92 , 0x038006 }, 0 },
214+ { {0x60342dfc , 0x41000002 , 0x0481c7 }, 0 },
215+ { {0x40000895 , 0x00000003 , 0x050d10 }, 0 },
216+ { {0x530a7ecf , 0x059c4415 , 0x06b082 }, 0 },
217+ { {0xfd94beb6 , 0x7a577e97 , 0x070f46 }, 0 },
218+ { {0xba02de6f , 0x988e6814 , 0x08b101 }, 0 },
219+ { {0x12064831 , 0x87767698 , 0x09e1a6 }, 0 },
220+ { {0xaf870be5 , 0x54ef2617 , 0x0ab286 }, 0 },
221+ { {0x0f06ba41 , 0x9a3f2698 , 0x0b8f7c }, 0 },
222+ { {0x2f012204 , 0xf0c3c81a , 0x0cb309 }, 0 },
223+ { {0x1c858601 , 0x10c47e98 , 0x0da065 }, 0 },
224+ { {0x5205980b , 0xf49abc1a , 0x0eb40e }, 0 },
225+ { {0x15454437 , 0x2504e698 , 0x0f8c09 }, 0 },
226+ /* Second, take 1st string from other GLO nav message and introduce an error
227+ * in data bits */
228+ { {0xc90cfb81 , 0x9743a301 , 0x010748 }, 0 }, /* case 15, no errors */
229+ { {0xc90cfb81 , 0x9743a301 , 0x110748 }, 85 },
230+ { {0xc90cfb81 , 0x1743a301 , 0x010748 }, 64 },
231+ { {0x490cfb81 , 0x9743a301 , 0x010748 }, 32 },
232+ { {0xc90cfb81 , 0x9743a300 , 0x010748 }, 33 },
233+ { {0xc90cfb81 , 0x9743a301 , 0x010749 }, 65 },
234+ { {0xc90cfb81 , 0x9743a301 , 0x000748 }, 81 },
235+ { {0xc90c3b81 , 0x9743a301 , 0x010748 }, -1 },
236+ { {0xc90cfb81 , 0x974fa301 , 0x010748 }, -1 },
237+ { {0xc90cfb81 , 0x9743a301 , 0x01074b }, -1 },
238+ { {0xc90cfb81 , 0x9743a301 , 0x010744 }, -1 },
239+ { {0xc90cfb81 , 0x9aaaa301 , 0x010748 }, -1 },
240+ { {0xc90cfb81 , 0x9743a301 , 0x010748 }, 0 }, /* no errors here */
241+ };
242+
243+ nav_msg_glo_t n ;
244+
245+ for (u8 i = 0 ; i < sizeof (test_case ) / sizeof (test_case [0 ]); i ++ ) {
246+ memcpy (n .string_bits , test_case [i ].str_in , sizeof (n .string_bits ));
247+ s8 ret = error_detection_glo (& n );
248+ fail_unless (test_case [i ].ret == ret , "Case %u: ret = %d, expected %d" ,
249+ i , ret , test_case [i ].ret );
250+ }
251+ }
252+ END_TEST
253+
202254Suite * glo_decoder_test_suite (void )
203255{
204256 Suite * s = suite_create ("GLO decoder" );
205257 TCase * tc_core = tcase_create ("Core" );
206258 tcase_add_test (tc_core , test_extract_glo_word );
207259 tcase_add_test (tc_core , test_process_string_glo );
208260 tcase_add_test (tc_core , test_nav_msg_update_glo );
261+ tcase_add_test (tc_core , test_error_correction_glo );
209262 suite_add_tcase (s , tc_core );
210263
211264 return s ;
0 commit comments