forked from daniestevez/gr-satellites
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlilacsat2.py
executable file
·390 lines (324 loc) · 18.3 KB
/
lilacsat2.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
##################################################
# GNU Radio Python Flow Graph
# Title: LilacSat-2 decoder
# Author: Daniel Estevez
# Description: LilacSat-2 decoder
# Generated: Mon Jan 23 17:36:30 2017
##################################################
import os
import sys
sys.path.append(os.environ.get('GRC_HIER_PATH', os.path.expanduser('~/.grc_gnuradio')))
from ccsds_descrambler import ccsds_descrambler # grc-generated hier_block
from ccsds_viterbi import ccsds_viterbi # grc-generated hier_block
from gnuradio import analog
from gnuradio import blocks
from gnuradio import digital
from gnuradio import eng_notation
from gnuradio import filter
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
from sync_to_pdu import sync_to_pdu # grc-generated hier_block
import kiss
import libfec
import sids
class lilacsat2(gr.top_block):
def __init__(self, bfo=12000, callsign='', invert=1, ip='::', latitude=0, longitude=0, port=7355, recstart=''):
gr.top_block.__init__(self, "LilacSat-2 decoder")
##################################################
# Parameters
##################################################
self.bfo = bfo
self.callsign = callsign
self.invert = invert
self.ip = ip
self.latitude = latitude
self.longitude = longitude
self.port = port
self.recstart = recstart
##################################################
# Variables
##################################################
self.sub_sps = sub_sps = 32
self.sub_nfilts = sub_nfilts = 16
self.sub_alpha = sub_alpha = 0.35
self.sps = sps = 5
self.samp_per_sym = samp_per_sym = 5
self.nfilts = nfilts = 16
self.alpha = alpha = 0.35
self.variable_constellation_0_0 = variable_constellation_0_0 = digital.constellation_calcdist(([-1, 1]), ([0, 1]), 2, 1).base()
self.variable_constellation_0 = variable_constellation_0 = digital.constellation_calcdist(([-1, 1]), ([0, 1]), 2, 1).base()
self.threshold = threshold = 4
self.sub_rrc_taps = sub_rrc_taps = firdes.root_raised_cosine(sub_nfilts, sub_nfilts, 1.0/float(sub_sps), sub_alpha, 11*sub_sps*sub_nfilts)
self.samp_rate = samp_rate = 48000
self.rrc_taps_0 = rrc_taps_0 = firdes.root_raised_cosine(nfilts, nfilts, 1.0/float(samp_per_sym), 0.35, 11*samp_per_sym*nfilts)
self.rrc_taps = rrc_taps = firdes.root_raised_cosine(nfilts, nfilts, 1.0/float(sps), alpha, 11*sps*nfilts)
self.nfilts_0 = nfilts_0 = 16
##################################################
# Blocks
##################################################
self.sync_to_pdu_0_1_0 = sync_to_pdu(
packlen=(114+32)*8,
sync="00011010110011111111110000011101",
threshold=threshold,
)
self.sync_to_pdu_0_1 = sync_to_pdu(
packlen=(114+32)*8,
sync="00011010110011111111110000011101",
threshold=threshold,
)
self.sync_to_pdu_0_0_0 = sync_to_pdu(
packlen=(114+32)*8,
sync="00011010110011111111110000011101",
threshold=threshold,
)
self.sync_to_pdu_0_0 = sync_to_pdu(
packlen=(114+32)*8,
sync="00011010110011111111110000011101",
threshold=threshold,
)
self.sync_to_pdu_0 = sync_to_pdu(
packlen=(114+32)*8,
sync="00011010110011111111110000011101",
threshold=threshold,
)
self.sids_submit_0 = sids.submit('http://tlm.pe0sat.nl/tlmdb/frame_db.php', 40908, callsign, longitude, latitude, recstart)
self.sids_print_timestamp_0 = sids.print_timestamp('%Y-%m-%d %H:%M:%S')
self.low_pass_filter_0 = filter.fir_filter_fff(5, firdes.low_pass(
1, samp_rate, 200, 50, firdes.WIN_HAMMING, 6.76))
self.libfec_decode_rs_0_0_0 = libfec.decode_rs(True, 0)
self.libfec_decode_rs_0_0 = libfec.decode_rs(True, 0)
self.libfec_decode_rs_0 = libfec.decode_rs(True, 0)
self.kiss_kiss_to_pdu_0_1 = kiss.kiss_to_pdu(False)
self.kiss_kiss_to_pdu_0_0 = kiss.kiss_to_pdu(False)
self.kiss_kiss_to_pdu_0 = kiss.kiss_to_pdu(False)
self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_fcf(1, (firdes.low_pass(1, samp_rate, 10000, 1000)), bfo, samp_rate)
self.digital_pfb_clock_sync_xxx_0_0 = digital.pfb_clock_sync_fff(sub_sps, 0.0628, (sub_rrc_taps), sub_nfilts, sub_nfilts/2, 0.01, 1)
self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf(sps, 0.100, (rrc_taps), nfilts, nfilts/2, 1.5, 2)
self.digital_lms_dd_equalizer_cc_0_0 = digital.lms_dd_equalizer_cc(2, 0.3, 2, variable_constellation_0)
self.digital_fll_band_edge_cc_0 = digital.fll_band_edge_cc(sps, 0.350, 100, 0.1)
self.digital_diff_decoder_bb_0_0 = digital.diff_decoder_bb(2)
self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(2)
self.digital_costas_loop_cc_0_0 = digital.costas_loop_cc(0.4, 2, False)
self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_ff(10, 0.25*0.175*0.175, 0.5, 0.175, 0.005)
self.digital_binary_slicer_fb_1 = digital.binary_slicer_fb()
self.dc_blocker_xx_0 = filter.dc_blocker_ff(1024, True)
self.ccsds_viterbi_0_1 = ccsds_viterbi()
self.ccsds_viterbi_0_0_0 = ccsds_viterbi()
self.ccsds_viterbi_0_0 = ccsds_viterbi()
self.ccsds_viterbi_0 = ccsds_viterbi()
self.ccsds_descrambler_0_0_0 = ccsds_descrambler()
self.ccsds_descrambler_0_0 = ccsds_descrambler()
self.ccsds_descrambler_0 = ccsds_descrambler()
self.blocks_udp_source_0 = blocks.udp_source(gr.sizeof_short*1, ip, port, 1472, False)
self.blocks_short_to_float_0 = blocks.short_to_float(1, 32767)
self.blocks_pdu_to_tagged_stream_0_1 = blocks.pdu_to_tagged_stream(blocks.byte_t, 'packet_len')
self.blocks_pdu_to_tagged_stream_0_0 = blocks.pdu_to_tagged_stream(blocks.byte_t, 'packet_len')
self.blocks_pdu_to_tagged_stream_0 = blocks.pdu_to_tagged_stream(blocks.byte_t, 'packet_len')
self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vff((invert*10, ))
self.blocks_message_debug_0 = blocks.message_debug()
self.blocks_delay_0_0_0 = blocks.delay(gr.sizeof_float*1, 1)
self.blocks_delay_0_0 = blocks.delay(gr.sizeof_float*1, 1)
self.blocks_complex_to_real_0 = blocks.complex_to_real(1)
self.analog_feedforward_agc_cc_0 = analog.feedforward_agc_cc(1024, 2)
##################################################
# Connections
##################################################
self.msg_connect((self.ccsds_descrambler_0, 'out'), (self.libfec_decode_rs_0, 'in'))
self.msg_connect((self.ccsds_descrambler_0_0, 'out'), (self.libfec_decode_rs_0_0, 'in'))
self.msg_connect((self.ccsds_descrambler_0_0_0, 'out'), (self.libfec_decode_rs_0_0_0, 'in'))
self.msg_connect((self.kiss_kiss_to_pdu_0, 'out'), (self.sids_print_timestamp_0, 'in'))
self.msg_connect((self.kiss_kiss_to_pdu_0, 'out'), (self.sids_submit_0, 'in'))
self.msg_connect((self.kiss_kiss_to_pdu_0_0, 'out'), (self.sids_print_timestamp_0, 'in'))
self.msg_connect((self.kiss_kiss_to_pdu_0_0, 'out'), (self.sids_submit_0, 'in'))
self.msg_connect((self.kiss_kiss_to_pdu_0_1, 'out'), (self.sids_print_timestamp_0, 'in'))
self.msg_connect((self.kiss_kiss_to_pdu_0_1, 'out'), (self.sids_submit_0, 'in'))
self.msg_connect((self.libfec_decode_rs_0, 'out'), (self.blocks_pdu_to_tagged_stream_0, 'pdus'))
self.msg_connect((self.libfec_decode_rs_0_0, 'out'), (self.blocks_pdu_to_tagged_stream_0_0, 'pdus'))
self.msg_connect((self.libfec_decode_rs_0_0_0, 'out'), (self.blocks_pdu_to_tagged_stream_0_1, 'pdus'))
self.msg_connect((self.sids_print_timestamp_0, 'out'), (self.blocks_message_debug_0, 'print_pdu'))
self.msg_connect((self.sync_to_pdu_0, 'out'), (self.ccsds_descrambler_0, 'in'))
self.msg_connect((self.sync_to_pdu_0_0, 'out'), (self.ccsds_descrambler_0_0, 'in'))
self.msg_connect((self.sync_to_pdu_0_0_0, 'out'), (self.ccsds_descrambler_0_0_0, 'in'))
self.msg_connect((self.sync_to_pdu_0_1, 'out'), (self.ccsds_descrambler_0_0, 'in'))
self.msg_connect((self.sync_to_pdu_0_1_0, 'out'), (self.ccsds_descrambler_0_0_0, 'in'))
self.connect((self.analog_feedforward_agc_cc_0, 0), (self.digital_fll_band_edge_cc_0, 0))
self.connect((self.blocks_complex_to_real_0, 0), (self.blocks_delay_0_0, 0))
self.connect((self.blocks_complex_to_real_0, 0), (self.ccsds_viterbi_0_1, 0))
self.connect((self.blocks_delay_0_0, 0), (self.ccsds_viterbi_0_0_0, 0))
self.connect((self.blocks_delay_0_0_0, 0), (self.ccsds_viterbi_0_0, 0))
self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.digital_clock_recovery_mm_xx_0, 0))
self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.low_pass_filter_0, 0))
self.connect((self.blocks_pdu_to_tagged_stream_0, 0), (self.kiss_kiss_to_pdu_0, 0))
self.connect((self.blocks_pdu_to_tagged_stream_0_0, 0), (self.kiss_kiss_to_pdu_0_0, 0))
self.connect((self.blocks_pdu_to_tagged_stream_0_1, 0), (self.kiss_kiss_to_pdu_0_1, 0))
self.connect((self.blocks_short_to_float_0, 0), (self.blocks_multiply_const_vxx_0_0, 0))
self.connect((self.blocks_short_to_float_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0))
self.connect((self.blocks_udp_source_0, 0), (self.blocks_short_to_float_0, 0))
self.connect((self.ccsds_viterbi_0, 0), (self.sync_to_pdu_0_1_0, 0))
self.connect((self.ccsds_viterbi_0_0, 0), (self.sync_to_pdu_0_0_0, 0))
self.connect((self.ccsds_viterbi_0_0_0, 0), (self.digital_diff_decoder_bb_0_0, 0))
self.connect((self.ccsds_viterbi_0_1, 0), (self.digital_diff_decoder_bb_0, 0))
self.connect((self.dc_blocker_xx_0, 0), (self.digital_pfb_clock_sync_xxx_0_0, 0))
self.connect((self.digital_binary_slicer_fb_1, 0), (self.sync_to_pdu_0, 0))
self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.blocks_delay_0_0_0, 0))
self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.ccsds_viterbi_0, 0))
self.connect((self.digital_costas_loop_cc_0_0, 0), (self.digital_lms_dd_equalizer_cc_0_0, 0))
self.connect((self.digital_diff_decoder_bb_0, 0), (self.sync_to_pdu_0_1, 0))
self.connect((self.digital_diff_decoder_bb_0_0, 0), (self.sync_to_pdu_0_0, 0))
self.connect((self.digital_fll_band_edge_cc_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0))
self.connect((self.digital_lms_dd_equalizer_cc_0_0, 0), (self.blocks_complex_to_real_0, 0))
self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_costas_loop_cc_0_0, 0))
self.connect((self.digital_pfb_clock_sync_xxx_0_0, 0), (self.digital_binary_slicer_fb_1, 0))
self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.analog_feedforward_agc_cc_0, 0))
self.connect((self.low_pass_filter_0, 0), (self.dc_blocker_xx_0, 0))
def get_bfo(self):
return self.bfo
def set_bfo(self, bfo):
self.bfo = bfo
self.freq_xlating_fir_filter_xxx_0.set_center_freq(self.bfo)
def get_callsign(self):
return self.callsign
def set_callsign(self, callsign):
self.callsign = callsign
def get_invert(self):
return self.invert
def set_invert(self, invert):
self.invert = invert
self.blocks_multiply_const_vxx_0_0.set_k((self.invert*10, ))
def get_ip(self):
return self.ip
def set_ip(self, ip):
self.ip = ip
def get_latitude(self):
return self.latitude
def set_latitude(self, latitude):
self.latitude = latitude
def get_longitude(self):
return self.longitude
def set_longitude(self, longitude):
self.longitude = longitude
def get_port(self):
return self.port
def set_port(self, port):
self.port = port
def get_recstart(self):
return self.recstart
def set_recstart(self, recstart):
self.recstart = recstart
def get_sub_sps(self):
return self.sub_sps
def set_sub_sps(self, sub_sps):
self.sub_sps = sub_sps
self.set_sub_rrc_taps(firdes.root_raised_cosine(self.sub_nfilts, self.sub_nfilts, 1.0/float(self.sub_sps), self.sub_alpha, 11*self.sub_sps*self.sub_nfilts))
def get_sub_nfilts(self):
return self.sub_nfilts
def set_sub_nfilts(self, sub_nfilts):
self.sub_nfilts = sub_nfilts
self.set_sub_rrc_taps(firdes.root_raised_cosine(self.sub_nfilts, self.sub_nfilts, 1.0/float(self.sub_sps), self.sub_alpha, 11*self.sub_sps*self.sub_nfilts))
def get_sub_alpha(self):
return self.sub_alpha
def set_sub_alpha(self, sub_alpha):
self.sub_alpha = sub_alpha
self.set_sub_rrc_taps(firdes.root_raised_cosine(self.sub_nfilts, self.sub_nfilts, 1.0/float(self.sub_sps), self.sub_alpha, 11*self.sub_sps*self.sub_nfilts))
def get_sps(self):
return self.sps
def set_sps(self, sps):
self.sps = sps
self.set_rrc_taps(firdes.root_raised_cosine(self.nfilts, self.nfilts, 1.0/float(self.sps), self.alpha, 11*self.sps*self.nfilts))
def get_samp_per_sym(self):
return self.samp_per_sym
def set_samp_per_sym(self, samp_per_sym):
self.samp_per_sym = samp_per_sym
self.set_rrc_taps_0(firdes.root_raised_cosine(self.nfilts, self.nfilts, 1.0/float(self.samp_per_sym), 0.35, 11*self.samp_per_sym*self.nfilts))
def get_nfilts(self):
return self.nfilts
def set_nfilts(self, nfilts):
self.nfilts = nfilts
self.set_rrc_taps(firdes.root_raised_cosine(self.nfilts, self.nfilts, 1.0/float(self.sps), self.alpha, 11*self.sps*self.nfilts))
self.set_rrc_taps_0(firdes.root_raised_cosine(self.nfilts, self.nfilts, 1.0/float(self.samp_per_sym), 0.35, 11*self.samp_per_sym*self.nfilts))
def get_alpha(self):
return self.alpha
def set_alpha(self, alpha):
self.alpha = alpha
self.set_rrc_taps(firdes.root_raised_cosine(self.nfilts, self.nfilts, 1.0/float(self.sps), self.alpha, 11*self.sps*self.nfilts))
def get_variable_constellation_0_0(self):
return self.variable_constellation_0_0
def set_variable_constellation_0_0(self, variable_constellation_0_0):
self.variable_constellation_0_0 = variable_constellation_0_0
def get_variable_constellation_0(self):
return self.variable_constellation_0
def set_variable_constellation_0(self, variable_constellation_0):
self.variable_constellation_0 = variable_constellation_0
def get_threshold(self):
return self.threshold
def set_threshold(self, threshold):
self.threshold = threshold
self.sync_to_pdu_0_1_0.set_threshold(self.threshold)
self.sync_to_pdu_0_1.set_threshold(self.threshold)
self.sync_to_pdu_0_0_0.set_threshold(self.threshold)
self.sync_to_pdu_0_0.set_threshold(self.threshold)
self.sync_to_pdu_0.set_threshold(self.threshold)
def get_sub_rrc_taps(self):
return self.sub_rrc_taps
def set_sub_rrc_taps(self, sub_rrc_taps):
self.sub_rrc_taps = sub_rrc_taps
self.digital_pfb_clock_sync_xxx_0_0.update_taps((self.sub_rrc_taps))
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
self.low_pass_filter_0.set_taps(firdes.low_pass(1, self.samp_rate, 200, 50, firdes.WIN_HAMMING, 6.76))
self.freq_xlating_fir_filter_xxx_0.set_taps((firdes.low_pass(1, self.samp_rate, 10000, 1000)))
def get_rrc_taps_0(self):
return self.rrc_taps_0
def set_rrc_taps_0(self, rrc_taps_0):
self.rrc_taps_0 = rrc_taps_0
def get_rrc_taps(self):
return self.rrc_taps
def set_rrc_taps(self, rrc_taps):
self.rrc_taps = rrc_taps
self.digital_pfb_clock_sync_xxx_0.update_taps((self.rrc_taps))
def get_nfilts_0(self):
return self.nfilts_0
def set_nfilts_0(self, nfilts_0):
self.nfilts_0 = nfilts_0
def argument_parser():
description = 'LilacSat-2 decoder'
parser = OptionParser(usage="%prog: [options]", option_class=eng_option, description=description)
parser.add_option(
"", "--bfo", dest="bfo", type="eng_float", default=eng_notation.num_to_str(12000),
help="Set carrier frequency of the BPSK signal [default=%default]")
parser.add_option(
"", "--callsign", dest="callsign", type="string", default='',
help="Set your callsign [default=%default]")
parser.add_option(
"-i", "--invert", dest="invert", type="intx", default=1,
help="Set invert the waveform (-1 to invert) [default=%default]")
parser.add_option(
"", "--ip", dest="ip", type="string", default='::',
help="Set UDP listen IP [default=%default]")
parser.add_option(
"", "--latitude", dest="latitude", type="eng_float", default=eng_notation.num_to_str(0),
help="Set latitude (format 00.000 or -00.000) [default=%default]")
parser.add_option(
"", "--longitude", dest="longitude", type="eng_float", default=eng_notation.num_to_str(0),
help="Set longitude (format 00.000 or -00.000) [default=%default]")
parser.add_option(
"", "--port", dest="port", type="intx", default=7355,
help="Set UDP port [default=%default]")
parser.add_option(
"", "--recstart", dest="recstart", type="string", default='',
help="Set start of recording, if processing a recording (format YYYY-MM-DD HH:MM:SS) [default=%default]")
return parser
def main(top_block_cls=lilacsat2, options=None):
if options is None:
options, _ = argument_parser().parse_args()
tb = top_block_cls(bfo=options.bfo, callsign=options.callsign, invert=options.invert, ip=options.ip, latitude=options.latitude, longitude=options.longitude, port=options.port, recstart=options.recstart)
tb.start()
tb.wait()
if __name__ == '__main__':
main()