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

Commit ca2de18

Browse files
Pasi Miettinenvaleri-atamaniouk
authored andcommitted
Add Glonass CA ranging code generation module and unit test
1 parent c15002f commit ca2de18

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed

peregrine/include/glo_ca_code.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# -*- coding: utf-8 -*-
2+
#!/usr/bin/env python
3+
4+
# Copyright (C) 2016 Swift Navigation Inc.
5+
#
6+
# Contact: Pasi Miettinen <pasi.miettinen@exafore.com>
7+
# This source is subject to the license found in the file 'LICENSE' which must
8+
# be be distributed together with this source. All other rights reserved.
9+
#
10+
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
11+
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
12+
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
13+
14+
import types
15+
import sys
16+
import numpy as np
17+
18+
19+
def generate_glo_ca_code():
20+
"""
21+
Function generates PRN sequence for Glonass.
22+
All GLONASS satellites use the same C/A-code,
23+
generated by a 9-bit shift register.
24+
"""
25+
code = '111111111'
26+
output = np.zeros(511, np.int8)
27+
for i in xrange(len(output)):
28+
if '0' == code[6]:
29+
output[i] = 1
30+
else:
31+
output[i] = -1
32+
if int(code[4]) ^ int(code[8]):
33+
code = '1' + code[:8]
34+
else:
35+
code = '0' + code[:8]
36+
return output
37+
38+
39+
def readonly(value):
40+
return property(lambda self: value)
41+
42+
43+
class glo_ca_code(types.ModuleType):
44+
"""
45+
Implement module level variable as readonly by imitating module with
46+
this class.
47+
"""
48+
49+
value = readonly(generate_glo_ca_code())
50+
51+
def __dir__(self):
52+
return ['__doc__', '__name__', 'value']
53+
54+
tmp = glo_ca_code(__name__)
55+
tmp.__doc__ = """
56+
PR ranging code is a sequence of maximum length of shift register with a
57+
period 1 millisecond and bit rate 511 kbps. PR ranging code is sampled at
58+
the output of 7th stage of the 9-stage shift register. The initialization
59+
vector to generate this sequence is (111111111). The first character of the
60+
PR ranging code is the first character in the group 111111100, and it is
61+
repeated every 1 millisecond. The generating polynomial, which corresponds
62+
to the 9-stage shift register is G(X) = 1 + X^5 + X^9
63+
64+
Function outputs the bitstream as str and time advances from left to right
65+
output[0] ... output[510]
66+
0ms ----------> 1ms
67+
68+
In the sequence '0' is represented as '1', 1 as -1
69+
"""
70+
sys.modules[__name__] = tmp

tests/test_glo_ca_code.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright (C) 2016 Swift Navigation Inc.
4+
#
5+
# Contact: Pasi Miettinen <pasi.miettinen@exafore.com>
6+
# This source is subject to the license found in the file 'LICENSE' which must
7+
# be be distributed together with this source. All other rights reserved.
8+
#
9+
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
10+
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
11+
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
12+
13+
from peregrine.include.glo_ca_code import value
14+
15+
import numpy as np
16+
17+
18+
def test_glo_ca_code():
19+
20+
code = np.array(
21+
[-1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1, 1,
22+
-1, -1, -1, -1, -1, 1, 1, 1, -1, 1, -1, -1, -1, 1, 1, -1, -1,
23+
1, 1, -1, 1, 1, 1, 1, 1, -1, 1, 1, -1, 1, -1, 1, 1, -1,
24+
-1, -1, 1, -1, -1, 1, -1, 1, 1, 1, -1, -1, -1, -1, 1, 1, -1,
25+
-1, -1, -1, -1, 1, 1, -1, -1, 1, -1, -1, 1, 1, 1, -1, 1, -1,
26+
1, -1, 1, 1, -1, 1, 1, 1, -1, -1, -1, 1, 1, 1, -1, -1, 1,
27+
-1, -1, 1, -1, 1, -1, 1, -1, -1, -1, 1, 1, 1, -1, 1, 1, -1,
28+
-1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1,
29+
-1, 1, 1, 1, 1, -1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, 1,
30+
1, -1, -1, -1, 1, 1, -1, 1, -1, 1, -1, 1, -1, -1, 1, 1, 1,
31+
1, -1, -1, 1, -1, -1, -1, -1, 1, -1, 1, 1, -1, -1, 1, -1, -1,
32+
-1, 1, 1, -1, 1, 1, 1, -1, 1, -1, 1, 1, 1, 1, -1, 1, -1,
33+
1, -1, -1, 1, -1, 1, 1, -1, -1, -1, -1, -1, -1, 1, -1, -1, 1,
34+
1, -1, 1, 1, -1, 1, 1, -1, 1, -1, -1, 1, -1, -1, -1, -1, -1,
35+
-1, 1, 1, -1, 1, 1, -1, -1, 1, -1, 1, -1, 1, 1, -1, -1, 1,
36+
1, -1, -1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, -1, -1,
37+
1, 1, -1, 1, -1, 1, 1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1,
38+
-1, -1, -1, -1, -1, -1, 1, -1, 1, 1, 1, -1, 1, -1, -1, 1, 1,
39+
1, -1, -1, -1, 1, -1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, 1,
40+
-1, -1, -1, -1, 1, 1, 1, -1, -1, -1, -1, -1, 1, -1, -1, -1, 1,
41+
-1, 1, 1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, 1, -1, -1, 1,
42+
-1, -1, -1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, -1,
43+
1, -1, -1, -1, -1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 1, 1,
44+
1, 1, 1, -1, 1, -1, 1, 1, -1, 1, -1, 1, -1, -1, -1, -1, 1,
45+
1, -1, 1, -1, -1, -1, 1, -1, -1, -1, 1, 1, 1, 1, 1, 1, -1,
46+
-1, -1, 1, 1, -1, -1, -1, 1, -1, 1, 1, -1, 1, 1, -1, -1, -1,
47+
-1, 1, -1, 1, -1, -1, -1, 1, -1, 1, -1, 1, 1, 1, -1, 1, 1,
48+
-1, 1, 1, 1, 1, -1, -1, 1, 1, -1, -1, -1, 1, 1, 1, 1, -1,
49+
1, -1, -1, -1, -1, 1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1,
50+
1, 1, 1, 1, -1, -1, -1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1,
51+
-1], dtype=np.int8)
52+
53+
assert((code == value).all())

0 commit comments

Comments
 (0)