-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.py
74 lines (56 loc) · 1.95 KB
/
generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import sys
import json
# Usage example: python generator.py C7_E1B.txt 0
if __name__ == '__main__':
file = open(sys.argv[1], "r")
SV_ID = int(sys.argv[2])
PRN_codes = []
for line in file:
code = line.split(";")
code[1] = code[1].rstrip()
PRN_codes.append(code)
# Select the first code
code_id = PRN_codes[SV_ID][0]
prn_sequence = bin(int(PRN_codes[SV_ID][1],16))[2:]
code_lenght = len(prn_sequence)
print("Lenght of the code sequence: " + str(code_lenght))
start_mask = ''
for prn_sequence_bit in prn_sequence:
if(prn_sequence_bit != '1'):
break
start_mask += '0'
prn_sequence_vector = []
prn_sequence_inverse_vector = []
for prn_bit in prn_sequence:
prn_sequence_vector.append(int(prn_bit))
if(prn_bit == '0'):
prn_sequence_inverse_vector.append(1)
else:
prn_sequence_inverse_vector.append(0)
boc_sequence_vector = []
boc_sequence_inverse_vector = []
for prn_bit in prn_sequence_vector:
if(prn_bit == 1):
boc_sequence_vector.append(1)
boc_sequence_vector.append(-1)
else:
boc_sequence_vector.append(-1)
boc_sequence_vector.append(1)
for prn_bit in prn_sequence_inverse_vector:
if(prn_bit == 1):
boc_sequence_inverse_vector.append(1)
boc_sequence_inverse_vector.append(-1)
else:
boc_sequence_inverse_vector.append(-1)
boc_sequence_inverse_vector.append(1)
output = {
'prn_id': code_id,
'prn_lenght': code_lenght,
'prn_sequence': prn_sequence_vector,
'prn_sequence_inverse': prn_sequence_inverse_vector,
'boc_sequence': boc_sequence_vector,
'boc_sequence_inverse': boc_sequence_inverse_vector
}
json_object = json.dumps(output)
with open("codes.json", "w") as outfile:
outfile.write(json_object)