From 5e396626c974ae7775551f994779f6ea71df9482 Mon Sep 17 00:00:00 2001 From: Anton Date: Tue, 23 Mar 2021 13:01:00 +0200 Subject: [PATCH] Adding work ptt scripts for svxlink --- giga_echo_link.py | 198 +++++++++++++++ giga_echo_link_tx.grc | 544 +++++++++++++++++++++++++++++++++++++++--- read_pts.sh | 21 ++ start_gnuradio_ptt.py | 6 + stop_gnuradio_ptt.py | 6 + 5 files changed, 747 insertions(+), 28 deletions(-) create mode 100644 giga_echo_link.py create mode 100644 read_pts.sh create mode 100644 start_gnuradio_ptt.py create mode 100644 stop_gnuradio_ptt.py diff --git a/giga_echo_link.py b/giga_echo_link.py new file mode 100644 index 0000000..82a3b7c --- /dev/null +++ b/giga_echo_link.py @@ -0,0 +1,198 @@ +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- +################################################## +# GNU Radio Python Flow Graph +# Title: Giga svxlink +# Author: Anton Janovsky +# Description: svxlink echolink to rpitx block +# Generated: Mon Mar 22 17:54:47 2021 +################################################## + +from distutils.version import StrictVersion + +if __name__ == '__main__': + import ctypes + import sys + if sys.platform.startswith('linux'): + try: + x11 = ctypes.cdll.LoadLibrary('libX11.so') + x11.XInitThreads() + except: + print "Warning: failed to XInitThreads()" + +from PyQt5 import Qt +from PyQt5 import Qt, QtCore +from gnuradio import analog +from gnuradio import audio +from gnuradio import blocks +from gnuradio import eng_notation +from gnuradio import filter +from gnuradio import gr +from gnuradio import qtgui +from gnuradio.eng_option import eng_option +from gnuradio.filter import firdes +from grc_gnuradio import blks2 as grc_blks2 +from optparse import OptionParser +import SimpleXMLRPCServer +import sip +import sys +import threading +from gnuradio import qtgui + + +class giga_echo_link(gr.top_block, Qt.QWidget): + + def __init__(self): + gr.top_block.__init__(self, "Giga svxlink") + Qt.QWidget.__init__(self) + self.setWindowTitle("Giga svxlink") + qtgui.util.check_set_qss() + try: + self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) + except: + pass + self.top_scroll_layout = Qt.QVBoxLayout() + self.setLayout(self.top_scroll_layout) + self.top_scroll = Qt.QScrollArea() + self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) + self.top_scroll_layout.addWidget(self.top_scroll) + self.top_scroll.setWidgetResizable(True) + self.top_widget = Qt.QWidget() + self.top_scroll.setWidget(self.top_widget) + self.top_layout = Qt.QVBoxLayout(self.top_widget) + self.top_grid_layout = Qt.QGridLayout() + self.top_layout.addLayout(self.top_grid_layout) + + self.settings = Qt.QSettings("GNU Radio", "giga_echo_link") + self.restoreGeometry(self.settings.value("geometry", type=QtCore.QByteArray)) + + + ################################################## + # Variables + ################################################## + self.samp_rate = samp_rate = 32000 + self.ptt = ptt = 1 + + ################################################## + # Blocks + ################################################## + self.xmlrpc_server_0 = SimpleXMLRPCServer.SimpleXMLRPCServer(('localhost', 8008), allow_none=True) + self.xmlrpc_server_0.register_instance(self) + self.xmlrpc_server_0_thread = threading.Thread(target=self.xmlrpc_server_0.serve_forever) + self.xmlrpc_server_0_thread.daemon = True + self.xmlrpc_server_0_thread.start() + self.tx_power = blocks.multiply_const_vcc((ptt, )) + self.qtgui_time_sink_x_1 = qtgui.time_sink_f( + 1024, #size + 48000, #samp_rate + "", #name + 1 #number of inputs + ) + self.qtgui_time_sink_x_1.set_update_time(0.10) + self.qtgui_time_sink_x_1.set_y_axis(-1, 1) + + self.qtgui_time_sink_x_1.set_y_label('Amplitude', "") + + self.qtgui_time_sink_x_1.enable_tags(-1, True) + self.qtgui_time_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") + self.qtgui_time_sink_x_1.enable_autoscale(False) + self.qtgui_time_sink_x_1.enable_grid(False) + self.qtgui_time_sink_x_1.enable_axis_labels(True) + self.qtgui_time_sink_x_1.enable_control_panel(False) + self.qtgui_time_sink_x_1.enable_stem_plot(False) + + if not True: + self.qtgui_time_sink_x_1.disable_legend() + + labels = ['', '', '', '', '', + '', '', '', '', ''] + widths = [1, 1, 1, 1, 1, + 1, 1, 1, 1, 1] + colors = ["blue", "red", "green", "black", "cyan", + "magenta", "yellow", "dark red", "dark green", "blue"] + styles = [1, 1, 1, 1, 1, + 1, 1, 1, 1, 1] + markers = [-1, -1, -1, -1, -1, + -1, -1, -1, -1, -1] + alphas = [1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0] + + for i in xrange(1): + if len(labels[i]) == 0: + self.qtgui_time_sink_x_1.set_line_label(i, "Data {0}".format(i)) + else: + self.qtgui_time_sink_x_1.set_line_label(i, labels[i]) + self.qtgui_time_sink_x_1.set_line_width(i, widths[i]) + self.qtgui_time_sink_x_1.set_line_color(i, colors[i]) + self.qtgui_time_sink_x_1.set_line_style(i, styles[i]) + self.qtgui_time_sink_x_1.set_line_marker(i, markers[i]) + self.qtgui_time_sink_x_1.set_line_alpha(i, alphas[i]) + + self._qtgui_time_sink_x_1_win = sip.wrapinstance(self.qtgui_time_sink_x_1.pyqwidget(), Qt.QWidget) + self.top_grid_layout.addWidget(self._qtgui_time_sink_x_1_win) + self.low_pass_filter_0 = filter.fir_filter_fff(1, firdes.low_pass( + 1, 48000, 6000, 250, firdes.WIN_HAMMING, 6.76)) + self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_gr_complex*1) + self.blks2_tcp_sink_0 = grc_blks2.tcp_sink( + itemsize=gr.sizeof_gr_complex*1, + addr='127.0.0.1', + port=8011, + server=False, + ) + self.audio_source_0 = audio.source(48000, 'hw:2,1', True) + self.analog_nbfm_tx_0 = analog.nbfm_tx( + audio_rate=48000, + quad_rate=96000, + tau=75e-6, + max_dev=10000, + fh=-1.0, + ) + + + + ################################################## + # Connections + ################################################## + self.connect((self.analog_nbfm_tx_0, 0), (self.tx_power, 0)) + self.connect((self.audio_source_0, 0), (self.low_pass_filter_0, 0)) + self.connect((self.audio_source_0, 0), (self.qtgui_time_sink_x_1, 0)) + self.connect((self.low_pass_filter_0, 0), (self.analog_nbfm_tx_0, 0)) + self.connect((self.tx_power, 0), (self.blks2_tcp_sink_0, 0)) + self.connect((self.tx_power, 0), (self.blocks_null_sink_0, 0)) + + def closeEvent(self, event): + self.settings = Qt.QSettings("GNU Radio", "giga_echo_link") + self.settings.setValue("geometry", self.saveGeometry()) + event.accept() + + def get_samp_rate(self): + return self.samp_rate + + def set_samp_rate(self, samp_rate): + self.samp_rate = samp_rate + + def get_ptt(self): + return self.ptt + + def set_ptt(self, ptt): + self.ptt = ptt + self.tx_power.set_k((self.ptt, )) + + +def main(top_block_cls=giga_echo_link, options=None): + + qapp = Qt.QApplication(sys.argv) + + tb = top_block_cls() + tb.start() + tb.show() + + def quitting(): + tb.stop() + tb.wait() + qapp.aboutToQuit.connect(quitting) + qapp.exec_() + + +if __name__ == '__main__': + main() diff --git a/giga_echo_link_tx.grc b/giga_echo_link_tx.grc index 1da52be..c14546a 100644 --- a/giga_echo_link_tx.grc +++ b/giga_echo_link_tx.grc @@ -38,7 +38,7 @@ generate_options - no_gui + qt_gui hier_block_src_path @@ -89,6 +89,33 @@ (0,0) + + variable + + comment + + + + _enabled + True + + + _coordinate + (64, 276) + + + _rotation + 0 + + + id + ptt + + + value + 1 + + variable @@ -191,7 +218,7 @@ device_name - hw:1,1,0 + hw:2,1 _enabled @@ -199,7 +226,7 @@ _coordinate - (200, 44) + (208, 36) _rotation @@ -250,11 +277,11 @@ _enabled - True + 1 _coordinate - (416, 188) + (416, 228) _rotation @@ -282,18 +309,18 @@ - blocks_multiply_const_vxx + blocks_null_sink alias - comment - + bus_conns + [[0,],] - const - 1 + comment + affinity @@ -301,11 +328,11 @@ _enabled - True + 1 _coordinate - (192, 204) + (408, 320) _rotation @@ -313,19 +340,15 @@ id - blocks_multiply_const_vxx_1 + blocks_null_sink_0 type complex - maxoutbuf - 0 - - - minoutbuf - 0 + num_inputs + 1 vlen @@ -873,9 +896,462 @@ -1 + + qtgui_time_sink_x + + autoscale + False + + + axislabels + True + + + alias + + + + comment + + + + ctrlpanel + False + + + affinity + + + + entags + True + + + _enabled + True + + + _coordinate + (424, 136) + + + gui_hint + + + + _rotation + 0 + + + grid + False + + + id + qtgui_time_sink_x_1 + + + legend + True + + + alpha1 + 1.0 + + + color1 + "blue" + + + label1 + + + + marker1 + -1 + + + style1 + 1 + + + width1 + 1 + + + alpha10 + 1.0 + + + color10 + "blue" + + + label10 + + + + marker10 + -1 + + + style10 + 1 + + + width10 + 1 + + + alpha2 + 1.0 + + + color2 + "red" + + + label2 + + + + marker2 + -1 + + + style2 + 1 + + + width2 + 1 + + + alpha3 + 1.0 + + + color3 + "green" + + + label3 + + + + marker3 + -1 + + + style3 + 1 + + + width3 + 1 + + + alpha4 + 1.0 + + + color4 + "black" + + + label4 + + + + marker4 + -1 + + + style4 + 1 + + + width4 + 1 + + + alpha5 + 1.0 + + + color5 + "cyan" + + + label5 + + + + marker5 + -1 + + + style5 + 1 + + + width5 + 1 + + + alpha6 + 1.0 + + + color6 + "magenta" + + + label6 + + + + marker6 + -1 + + + style6 + 1 + + + width6 + 1 + + + alpha7 + 1.0 + + + color7 + "yellow" + + + label7 + + + + marker7 + -1 + + + style7 + 1 + + + width7 + 1 + + + alpha8 + 1.0 + + + color8 + "dark red" + + + label8 + + + + marker8 + -1 + + + style8 + 1 + + + width8 + 1 + + + alpha9 + 1.0 + + + color9 + "dark green" + + + label9 + + + + marker9 + -1 + + + style9 + 1 + + + width9 + 1 + + + name + "" + + + nconnections + 1 + + + size + 1024 + + + srate + 48000 + + + stemplot + False + + + tr_chan + 0 + + + tr_delay + 0 + + + tr_level + 0.0 + + + tr_mode + qtgui.TRIG_MODE_FREE + + + tr_slope + qtgui.TRIG_SLOPE_POS + + + tr_tag + "" + + + type + float + + + update_time + 0.10 + + + ylabel + Amplitude + + + yunit + "" + + + ymax + 1 + + + ymin + -1 + + + + blocks_multiply_const_vxx + + alias + + + + comment + + + + const + ptt + + + affinity + + + + _enabled + True + + + _coordinate + (224, 244) + + + _rotation + 0 + + + id + tx_power + + + type + complex + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + vlen + 1 + + + + xmlrpc_server + + addr + localhost + + + alias + + + + comment + + + + _enabled + True + + + _coordinate + (192, 316) + + + _rotation + 0 + + + id + xmlrpc_server_0 + + + port + 8008 + + analog_nbfm_tx_0 - blocks_multiply_const_vxx_1 + tx_power 0 0 @@ -886,14 +1362,8 @@ 0 - blocks_multiply_const_vxx_1 - blks2_tcp_sink_0 - 0 - 0 - - - blocks_multiply_const_vxx_1 - qtgui_sink_x_0 + audio_source_0 + qtgui_time_sink_x_1 0 0 @@ -909,4 +1379,22 @@ 0 0 + + tx_power + blks2_tcp_sink_0 + 0 + 0 + + + tx_power + blocks_null_sink_0 + 0 + 0 + + + tx_power + qtgui_sink_x_0 + 0 + 0 + diff --git a/read_pts.sh b/read_pts.sh new file mode 100644 index 0000000..5b9fd21 --- /dev/null +++ b/read_pts.sh @@ -0,0 +1,21 @@ +#!/bin/bash +#read X < /dev/pts/0 +#$ echo $X + +while IFS= read -r -n1 char +do +if [ $char == "T" ] + then +# `rigctl -m 370 -r /dev/ttyUSB0 -s 19200 T 1` +echo " ptt is tx" +python /home/pi/start_gnuradio_ptt.py +fi +if [ $char == "R" ] + then +# `rigctl -m 370 -r /dev/ttyUSB0 -s 19200 T 0` +echo " ptt is rx" +python /home/pi/stop_gnuradio_ptt.py +fi + +done < "${1:-/home/pi/ptt}" + diff --git a/start_gnuradio_ptt.py b/start_gnuradio_ptt.py new file mode 100644 index 0000000..95d6d31 --- /dev/null +++ b/start_gnuradio_ptt.py @@ -0,0 +1,6 @@ +import xmlrpclib +import time + +s = xmlrpclib.Server('http://localhost:8008') +#s.set_freq(1000) +s.set_ptt(1) diff --git a/stop_gnuradio_ptt.py b/stop_gnuradio_ptt.py new file mode 100644 index 0000000..567f976 --- /dev/null +++ b/stop_gnuradio_ptt.py @@ -0,0 +1,6 @@ +import xmlrpclib +import time + +s = xmlrpclib.Server('http://localhost:8008') +#s.set_freq(1000) +s.set_ptt(0)