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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
#!/usr/bin/env python3
#
# This code is taken from
# https://sdradventure.wordpress.com/2011/10/15/gnuradio-psk31-decoder-part-1/
# https://sdradventure.wordpress.com/2011/10/15/gnuradio-psk31-decoder-part-2/
import re
import struct
varicode = { # {{{
'1010101011' : '\x00', '1011011011' : '\x01',
'1011101101' : '\x02', '1101110111' : '\x03',
'1011101011' : '\x04', '1101011111' : '\x05',
'1011101111' : '\x06', '1011111101' : '\x07',
'1011111111' : '\x08', '11101111' : '\x09',
'11101' : '\x0A', '1101101111' : '\x0B',
'1011011101' : '\x0C', '11111' : '\x0D',
'1101110101' : '\x0E', '1110101011' : '\x0F',
'1011110111' : '\x10', '1011110101' : '\x11',
'1110101101' : '\x12', '1110101111' : '\x13',
'1101011011' : '\x14', '1101101011' : '\x15',
'1101101101' : '\x16', '1101010111' : '\x17',
'1101111011' : '\x18', '1101111101' : '\x19',
'1110110111' : '\x1A', '1101010101' : '\x1B',
'1101011101' : '\x1C', '1110111011' : '\x1D',
'1011111011' : '\x1E', '1101111111' : '\x1F',
'1' : ' ', '111111111' : '!',
'101011111' : '"', '111110101' : '#',
'111011011' : '$', '1011010101' : '%',
'1010111011' : '&', '101111111' : '\'',
'11111011' : '(', '11110111' : ')',
'101101111' : '*', '111011111' : '+',
'1110101' : ',', '110101' : '-',
'1010111' : '.', '110101111' : '/',
'10110111' : '0', '10111101' : '1',
'11101101' : '2', '11111111' : '3',
'101110111' : '4', '101011011' : '5',
'101101011' : '6', '110101101' : '7',
'110101011' : '8', '110110111' : '9',
'11110101' : ':', '110111101' : ';',
'111101101' : '<', '1010101' : '=',
'111010111' : '>', '1010101111' : '?',
'1010111101' : '@', '1111101' : 'A',
'11101011' : 'B', '10101101' : 'C',
'10110101' : 'D', '1110111' : 'E',
'11011011' : 'F', '11111101' : 'G',
'101010101' : 'H', '1111111' : 'I',
'111111101' : 'J', '101111101' : 'K',
'11010111' : 'L', '10111011' : 'M',
'11011101' : 'N', '10101011' : 'O',
'11010101' : 'P', '111011101' : 'Q',
'10101111' : 'R', '1101111' : 'S',
'1101101' : 'T', '101010111' : 'U',
'110110101' : 'V', '101011101' : 'W',
'101110101' : 'X', '101111011' : 'Y',
'1010101101' : 'Z', '111110111' : '[',
'111101111' : '\\', '111111011' : ']',
'1010111111' : '^', '101101101' : '_',
'1011011111' : '`', '1011' : 'a',
'1011111' : 'b', '101111' : 'c',
'101101' : 'd', '11' : 'e',
'111101' : 'f', '1011011' : 'g',
'101011' : 'h', '1101' : 'i',
'111101011' : 'j', '10111111' : 'k',
'11011' : 'l', '111011' : 'm',
'1111' : 'n', '111' : 'o',
'111111' : 'p', '110111111' : 'q',
'10101' : 'r', '10111' : 's',
'101' : 't', '110111' : 'u',
'1111011' : 'v', '1101011' : 'w',
'11011111' : 'x', '1011101' : 'y',
'111010101' : 'z', '1010110111' : '{',
'110111011' : '|', '1010110101' : '}',
'1011010111' : '~', '1110110101' : '\x7F' }
# }}}
infile = open('./psk125.bit', mode='rb')
# Initialize the loop
bit_stream = ''
# Read 1 byte at a time and add it to the bit stream.
curr_bit = infile.read(1)
while curr_bit != b"":
bit_stream = bit_stream+str(struct.unpack('B', curr_bit)[0])
curr_bit = infile.read(1)
#print("Bit Stream:", bit_stream)
# Use regular expression to separate the characters
# by splitting on two or more 0s
char_list = re.split('00+', bit_stream)
#print("Character List:", char_list)
# Use the dictionary to decode the characters
output_str = ''
for char in char_list:
if char in varicode:
output_str = output_str+varicode[char]
start_ix = output_str.find("HB9G")
if start_ix == -1:
start_ix = 0
output_str = output_str[start_ix:]
end_ix = output_str.rfind("Sat GPS=")
if end_ix != -1:
while end_ix < len(output_str) and output_str[end_ix] != '\n':
end_ix += 1
output_str = output_str[:end_ix]
outfile = open('./psk125.txt', 'w')
outfile.write(output_str)
outfile.write("\n")
|