op25/op25/gr-op25_repeater/apps/p25_decoder.py

145 lines
4.6 KiB
Python
Raw Normal View History

2014-11-30 16:32:58 +00:00
#
# Copyright 2005,2006,2007 Free Software Foundation, Inc.
#
# OP25 Decoder Block
# Copyright 2009, 2014 Max H. Parke KA1RBI
#
# This file is part of GNU Radio and part of OP25
#
# This is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# It is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
"""
P25 decoding block.
"""
import time
2022-05-20 00:21:21 +00:00
from gnuradio import gr, eng_notation
2014-12-06 00:01:04 +00:00
from gnuradio import blocks, audio
2014-11-30 16:32:58 +00:00
from gnuradio.eng_option import eng_option
import op25
import op25_repeater
# default values (used in __init__ and add_options)
_def_debug = 0
_def_num_ambe = False
2014-11-30 16:32:58 +00:00
_def_do_imbe = True
2014-12-06 00:01:04 +00:00
_def_wireshark_host = ''
_def_udp_port = 0
_def_dest = 'wav'
_def_audio_rate = 8000
_def_audio_output = 'plughw:0,0'
_def_max_tdma_timeslots = 2
2014-11-30 16:32:58 +00:00
# /////////////////////////////////////////////////////////////////////////////
# decoder
# /////////////////////////////////////////////////////////////////////////////
class p25_decoder_sink_b(gr.hier_block2):
2014-11-30 16:32:58 +00:00
def __init__(self,
2014-12-06 00:01:04 +00:00
dest = _def_dest,
2014-11-30 16:32:58 +00:00
do_imbe = _def_do_imbe,
num_ambe = _def_num_ambe,
2014-12-06 00:01:04 +00:00
wireshark_host = _def_wireshark_host,
udp_port = _def_udp_port,
do_msgq = False,
msgq = None,
audio_output = _def_audio_output,
2021-07-26 00:46:14 +00:00
debug = _def_debug,
msgq_id = 0):
2014-11-30 16:32:58 +00:00
"""
Hierarchical block for P25 decoding.
@param debug: debug level
@type debug: int
"""
gr.hier_block2.__init__(self, "p25_demod_c",
2014-11-30 16:32:58 +00:00
gr.io_signature(1, 1, gr.sizeof_char), # Input signature
gr.io_signature(0, 0, 0)) # Output signature
assert 0 <= num_ambe <= _def_max_tdma_timeslots
assert not (num_ambe > 1 and dest != 'wav')
2014-11-30 16:32:58 +00:00
self.debug = debug
2014-12-06 00:01:04 +00:00
self.dest = dest
2017-04-29 16:32:47 +00:00
do_output = False
2018-12-26 02:10:06 +00:00
do_audio_output = False
do_phase2_tdma = False
2017-04-29 16:32:47 +00:00
if dest == 'wav':
do_output = True
2018-12-26 02:10:06 +00:00
if do_imbe:
do_audio_output = True
if num_ambe > 0:
do_phase2_tdma = True
2014-12-06 00:01:04 +00:00
if msgq is None:
msgq = gr.msg_queue(1)
2014-11-30 16:32:58 +00:00
self.p25_decoders = []
self.audio_s2f = []
self.scaler = []
self.audio_sink = []
self.xorhash = []
num_decoders = 1
if num_ambe > 1:
num_decoders += num_ambe - 1
for slot in range(num_decoders):
2021-07-26 00:46:14 +00:00
self.p25_decoders.append(op25_repeater.p25_frame_assembler(wireshark_host, udp_port, debug, do_imbe, do_output, do_msgq, msgq, do_audio_output, do_phase2_tdma, msgq_id+slot))
self.p25_decoders[slot].set_slotid(slot)
self.xorhash.append('')
2014-11-30 16:32:58 +00:00
if dest == 'wav':
filename = 'default-%f-%d.wav' % (time.time(), slot)
n_channels = 1
sample_rate = 8000
bits_per_sample = 16
2017-04-29 16:32:47 +00:00
self.audio_s2f.append(blocks.short_to_float()) # another ridiculous conversion
self.scaler.append(blocks.multiply_const_ff(1 / 32768.0))
self.audio_sink.append(blocks.wavfile_sink(filename, n_channels, sample_rate, bits_per_sample))
2017-04-29 16:32:47 +00:00
self.connect(self, self.p25_decoders[slot], self.audio_s2f[slot], self.scaler[slot], self.audio_sink[slot])
elif dest == 'audio':
2017-04-29 16:32:47 +00:00
self.connect(self, self.p25_decoders[slot])
2014-11-30 16:32:58 +00:00
def close_file(self, index=0):
2014-12-06 00:01:04 +00:00
if self.dest != 'wav':
return
self.audio_sink[index].close()
def set_slotid(self, slot, index=0):
self.p25_decoders[index].set_slotid(slot)
2014-11-30 16:32:58 +00:00
def set_output(self, filename, index=0):
2014-12-06 00:01:04 +00:00
if self.dest != 'wav':
return
self.audio_sink[index].open(filename)
2018-12-26 02:10:06 +00:00
def set_nac(self, nac, index=0):
self.p25_decoders[index].set_nac(nac)
def set_xormask(self, xormask, xorhash, index=0):
if self.xorhash[index] == xorhash:
return
self.xorhash[index] = xorhash
self.p25_decoders[index].set_xormask(xormask)
def set_scaler_k(self, k, index=0):
self.scaler[index].set_k(k)