From ed4b2fee689f33cd9982c130724c107e96dbb08f Mon Sep 17 00:00:00 2001 From: mer0m Date: Thu, 16 Mar 2017 09:02:35 +0100 Subject: [PATCH] minor fixes --- redpitaya/client/dds_control.grc | 495 +++++++++++++++++++++++ redpitaya/client/gr_add_const_set_offset.xml | 57 +++ redpitaya/client/gr_nco_counter_send_conf.xml | 78 ++++ redpitaya/client/gr_source_test.xml | 30 ++ redpitaya/client/gr_source_test.xml.old | 30 ++ redpitaya/client/redpitaya_gnuradio.py | 71 ++++ redpitaya/client/redpitaya_gnuradio.pyc | Bin 0 -> 1921 bytes redpitaya/client/sourceme.bma | 1 + redpitaya/client/top_block.py | 167 ++++++++ redpitaya/gnuradio_blocks/dds_control.grc | 72 +++- redpitaya/gnuradio_blocks/gr_source_test.xml | 30 ++ redpitaya/gnuradio_blocks/gr_source_test.xml.old | 30 ++ redpitaya/gnuradio_blocks/redpitaya_gnuradio.py | 19 +- redpitaya/gnuradio_blocks/redpitaya_gnuradio.pyc | Bin 0 -> 1921 bytes redpitaya/gnuradio_blocks/top_block.py | 167 ++++++++ redpitaya/server/server.py | 20 +- redpitaya/server/test.py | 6 + redpitaya/server/test_emb.py | 30 ++ 18 files changed, 1284 insertions(+), 19 deletions(-) create mode 100644 redpitaya/client/dds_control.grc create mode 100644 redpitaya/client/gr_add_const_set_offset.xml create mode 100644 redpitaya/client/gr_nco_counter_send_conf.xml create mode 100644 redpitaya/client/gr_source_test.xml create mode 100644 redpitaya/client/gr_source_test.xml.old create mode 100644 redpitaya/client/redpitaya_gnuradio.py create mode 100644 redpitaya/client/redpitaya_gnuradio.pyc create mode 100644 redpitaya/client/sourceme.bma create mode 100755 redpitaya/client/top_block.py create mode 100644 redpitaya/gnuradio_blocks/gr_source_test.xml create mode 100644 redpitaya/gnuradio_blocks/gr_source_test.xml.old create mode 100644 redpitaya/gnuradio_blocks/redpitaya_gnuradio.pyc create mode 100755 redpitaya/gnuradio_blocks/top_block.py create mode 100644 redpitaya/server/test.py create mode 100755 redpitaya/server/test_emb.py diff --git a/redpitaya/client/dds_control.grc b/redpitaya/client/dds_control.grc new file mode 100644 index 0000000..0e5dd0d --- /dev/null +++ b/redpitaya/client/dds_control.grc @@ -0,0 +1,495 @@ + + + + Thu Feb 2 22:54:58 2017 + + options + + author + + + + window_size + + + + category + [GRC Hier Blocks] + + + comment + + + + description + + + + _enabled + True + + + _coordinate + (8, 8) + + + _rotation + 0 + + + generate_options + qt_gui + + + hier_block_src_path + .: + + + id + top_block + + + max_nouts + 0 + + + qt_qss_theme + + + + realtime_scheduling + + + + run_command + {python} -u {filename} + + + run_options + prompt + + + run + True + + + thread_safe_setters + + + + title + + + + + variable_qtgui_range + + comment + + + + value + 0 + + + _enabled + True + + + _coordinate + (704, 24) + + + gui_hint + 1, 0 + + + _rotation + 0 + + + id + a_dds + + + label + DDS amplitude + + + min_len + 200 + + + orient + Qt.Horizontal + + + start + 0 + + + step + 128 + + + stop + 8191 + + + rangeType + int + + + widget + counter_slider + + + + variable + + comment + + + + _enabled + True + + + _coordinate + (0, 248) + + + _rotation + 0 + + + id + addr + + + value + "192.168.0.202" + + + + variable_qtgui_range + + comment + + + + value + 0 + + + _enabled + True + + + _coordinate + (488, 24) + + + gui_hint + 0, 0 + + + _rotation + 0 + + + id + f_dds + + + label + DDS frequency + + + min_len + 200 + + + orient + Qt.Horizontal + + + start + 0 + + + step + 100000 + + + stop + 60000000 + + + rangeType + int + + + widget + counter_slider + + + + variable_qtgui_range + + comment + + + + value + 0 + + + _enabled + True + + + _coordinate + (328, 24) + + + gui_hint + 2, 0 + + + _rotation + 0 + + + id + offset_out1 + + + label + Offset DDS + + + min_len + 200 + + + orient + Qt.Horizontal + + + start + -8192 + + + step + 100 + + + stop + 8191 + + + rangeType + int + + + widget + counter_slider + + + + variable + + comment + + + + _enabled + True + + + _coordinate + (0, 320) + + + _rotation + 0 + + + id + port + + + value + 1001 + + + + variable + + comment + + + + _enabled + True + + + _coordinate + (8, 160) + + + _rotation + 0 + + + id + samp_rate + + + value + 32000 + + + + add_const_set_offset + + addr + addr + + + alias + + + + comment + + + + const + offset_out1 + + + device + /dev/dds_offset + + + _enabled + True + + + _coordinate + (304, 176) + + + _rotation + 0 + + + id + add_const_set_offset_0 + + + port + port + + + + add_const_set_offset + + addr + addr + + + alias + + + + comment + + + + const + a_dds + + + device + /dev/dds_ampl + + + _enabled + True + + + _coordinate + (704, 176) + + + _rotation + 0 + + + id + add_const_set_offset_0_0 + + + port + port + + + + nco_counter_send_conf + + acc_size + 32 + + + addr + addr + + + alias + + + + comment + + + + device + /dev/dds_freq + + + _enabled + True + + + freq_dds + f_dds + + + freq_ref + 125000000 + + + _coordinate + (488, 176) + + + _rotation + 0 + + + id + nco_counter_send_conf_0 + + + offset + 0 + + + port + port + + + diff --git a/redpitaya/client/gr_add_const_set_offset.xml b/redpitaya/client/gr_add_const_set_offset.xml new file mode 100644 index 0000000..26b1a88 --- /dev/null +++ b/redpitaya/client/gr_add_const_set_offset.xml @@ -0,0 +1,57 @@ + + + + add_const_set_offset + add_const_set_offset + Red Pitaya + import redpitaya_gnuradio + redpitaya_gnuradio.add_const_set_offset( + addr=$addr, + port=$port, + device=$device, + const=$const, +) + + set_const(device=$device, const=$const) + + Address + addr + 192.168.0.201 + string + + + Port + port + 1001 + int + + + Device + device + /dev/add_const_0 + string + + + Constant + const + 0 + int + + diff --git a/redpitaya/client/gr_nco_counter_send_conf.xml b/redpitaya/client/gr_nco_counter_send_conf.xml new file mode 100644 index 0000000..f7d6d0c --- /dev/null +++ b/redpitaya/client/gr_nco_counter_send_conf.xml @@ -0,0 +1,78 @@ + + + + nco_counter_send_conf + nco_counter_send_conf + Red Pitaya + import redpitaya_gnuradio + redpitaya_gnuradio.nco_counter_send_conf( + addr=$addr, + port=$port, + device=$device, + freq_ref=$freq_ref, + freq_dds=$freq_dds, + acc_size=$acc_size, + offset=$offset, +) + + set_nco(device=$device, freq_ref=$freq_ref, freq_dds=$freq_dds, acc_size=$acc_size, offset=$offset) + + Address + addr + 192.168.0.201 + string + + + Port + port + 1001 + int + + + Device + device + /dev/dds1 + string + + + Frequency ref + freq_ref + 125000000 + int + + + Frequency DDS + freq_dds + 0 + int + + + Accumulator size + acc_size + 28 + int + + + Offset + offset + 0 + int + + diff --git a/redpitaya/client/gr_source_test.xml b/redpitaya/client/gr_source_test.xml new file mode 100644 index 0000000..bcc8938 --- /dev/null +++ b/redpitaya/client/gr_source_test.xml @@ -0,0 +1,30 @@ + + + + source_test + source_test + Red Pitaya + import redpitaya_gnuradio + redpitaya_gnuradio.source_test() + + out + complex + + diff --git a/redpitaya/client/gr_source_test.xml.old b/redpitaya/client/gr_source_test.xml.old new file mode 100644 index 0000000..bcc8938 --- /dev/null +++ b/redpitaya/client/gr_source_test.xml.old @@ -0,0 +1,30 @@ + + + + source_test + source_test + Red Pitaya + import redpitaya_gnuradio + redpitaya_gnuradio.source_test() + + out + complex + + diff --git a/redpitaya/client/redpitaya_gnuradio.py b/redpitaya/client/redpitaya_gnuradio.py new file mode 100644 index 0000000..650fdcf --- /dev/null +++ b/redpitaya/client/redpitaya_gnuradio.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python + +# GNU Radio blocks for the Red Pitaya transceiver +# Copyright (C) 2015 Renzo Davoli +# +# This program 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 2 +# of the License, or (at your option) any later version. +# +# This program 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 program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +import socket, os +from gnuradio import gr, blocks + +class add_const_set_offset(gr.hier_block2): + def __init__(self, addr, port, device, const): + self.name = "add_const_set_offset" + gr.hier_block2.__init__( + self, + name = self.name, + input_signature = gr.io_signature(0, 0, 0), + output_signature = gr.io_signature(0, 0, 0) + ) + self.ctrl_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.ctrl_sock.connect((addr, port)) + self.set_const(device, const) + + def set_const(self, device, const): + self.ctrl_sock.send('%s;%s;%i\n'%(self.name, device, const)) + + +class nco_counter_send_conf(gr.hier_block2): + def __init__(self, addr, port, device, freq_ref, freq_dds, acc_size, offset): + self.name = "nco_counter_send_conf" + gr.hier_block2.__init__( + self, + name = self.name, + input_signature = gr.io_signature(0, 0, 0), + output_signature = gr.io_signature(0, 0, 0) + ) + self.ctrl_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.ctrl_sock.connect((addr, port)) + self.set_nco(device, freq_ref, freq_dds, acc_size, offset) + + def set_nco(self, device, freq_ref, freq_dds, acc_size, offset): + self.ctrl_sock.send('%s;%s;%i;%i;%i;%i\n'%(self.name, device, freq_ref, freq_dds, acc_size, offset)) + +'''~ +class source_test(gr.hier_block2): + def __init__(self): + self.name = "source_test" + gr.hier_block2.__init__( + self, + name = self.name, + input_signature = gr.io_signature(0, 0, 0), + output_signature = gr.io_signature(1, 1, gr.sizeof_gr_complex) + ) + self.data_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.data_sock.connect((addr, port)) + self.data_sock.send('%s'%self.name) + fd = os.dup(self.data_sock.fileno()) + self.connect(blocks.file_descriptor_source(gr.sizeof_gr_complex, fd), self) +''' diff --git a/redpitaya/client/redpitaya_gnuradio.pyc b/redpitaya/client/redpitaya_gnuradio.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8f6c7b73ecbec66e263c8bae094f8484f7b5802e GIT binary patch literal 1921 zcmd5-%Wl&^6uq{SG%fE}p@75&B(s185-Sj*AdnEENRuugn^EwiI3#xQOprj?l^v1VYqseC6CT0bWw;F6)h%KJ{g7)gh{W_X zf6~Sr+A-K;nEL{USyK^<Z>>L$Mp4bvD*O)UXWo;b z^{4jP#*hEQ3444hGT&@+&%t^l~~avR(rLSsRG>e zlO4ltm~(JP+WkpP=cJ#(yKIXo^1Ii*KjXH>n%E<7L z{307e9X7DDM#J-9NQzN;@hq4VaC-K6-T`c^Gxa!7nC1)}4~9~k*V%hpXZgI5rcN7! zB!L1yWvYheii`2pku-1<^A6JhOQ3OEs)1Vw4%0w$4FR>h^P3o0!@d}xhvv7S3d5Va zQG~)aSHv0zcsrXbbXVbyR2rpy7q%!6!}Dua>8O6gIrC&1{o%qO@0>G}L&Fw%)qg!z r!^Qp`W6&>#dT34p)nxW_EG&EYic0PMM!^pVkn6%-!UeT= StrictVersion("4.5.0"): + style = gr.prefs().get_string('qtgui', 'style', 'raster') + Qt.QApplication.setGraphicsSystem(style) + qapp = Qt.QApplication(sys.argv) + + tb = top_block_cls() + tb.start() + tb.show() + + def quitting(): + tb.stop() + tb.wait() + qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting) + qapp.exec_() + + +if __name__ == '__main__': + main() diff --git a/redpitaya/gnuradio_blocks/dds_control.grc b/redpitaya/gnuradio_blocks/dds_control.grc index 86416cd..0e5dd0d 100644 --- a/redpitaya/gnuradio_blocks/dds_control.grc +++ b/redpitaya/gnuradio_blocks/dds_control.grc @@ -144,6 +144,33 @@ counter_slider + + variable + + comment + + + + _enabled + True + + + _coordinate + (0, 248) + + + _rotation + 0 + + + id + addr + + + value + "192.168.0.202" + + variable_qtgui_range @@ -270,6 +297,33 @@ counter_slider + + variable + + comment + + + + _enabled + True + + + _coordinate + (0, 320) + + + _rotation + 0 + + + id + port + + + value + 1001 + + variable @@ -301,7 +355,7 @@ add_const_set_offset addr - 192.168.0.201 + addr alias @@ -317,7 +371,7 @@ device - /dev/dds1_offset + /dev/dds_offset _enabled @@ -337,14 +391,14 @@ port - 1001 + port add_const_set_offset addr - 192.168.0.201 + addr alias @@ -360,7 +414,7 @@ device - /dev/dds1_ampl + /dev/dds_ampl _enabled @@ -380,7 +434,7 @@ port - 1001 + port @@ -391,7 +445,7 @@ addr - 192.168.0.201 + addr alias @@ -403,7 +457,7 @@ device - /dev/dds1_freq + /dev/dds_freq _enabled @@ -435,7 +489,7 @@ port - 1001 + port diff --git a/redpitaya/gnuradio_blocks/gr_source_test.xml b/redpitaya/gnuradio_blocks/gr_source_test.xml new file mode 100644 index 0000000..bcc8938 --- /dev/null +++ b/redpitaya/gnuradio_blocks/gr_source_test.xml @@ -0,0 +1,30 @@ + + + + source_test + source_test + Red Pitaya + import redpitaya_gnuradio + redpitaya_gnuradio.source_test() + + out + complex + + diff --git a/redpitaya/gnuradio_blocks/gr_source_test.xml.old b/redpitaya/gnuradio_blocks/gr_source_test.xml.old new file mode 100644 index 0000000..bcc8938 --- /dev/null +++ b/redpitaya/gnuradio_blocks/gr_source_test.xml.old @@ -0,0 +1,30 @@ + + + + source_test + source_test + Red Pitaya + import redpitaya_gnuradio + redpitaya_gnuradio.source_test() + + out + complex + + diff --git a/redpitaya/gnuradio_blocks/redpitaya_gnuradio.py b/redpitaya/gnuradio_blocks/redpitaya_gnuradio.py index 1ce3b3a..650fdcf 100644 --- a/redpitaya/gnuradio_blocks/redpitaya_gnuradio.py +++ b/redpitaya/gnuradio_blocks/redpitaya_gnuradio.py @@ -17,7 +17,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -import socket +import socket, os from gnuradio import gr, blocks class add_const_set_offset(gr.hier_block2): @@ -52,3 +52,20 @@ class nco_counter_send_conf(gr.hier_block2): def set_nco(self, device, freq_ref, freq_dds, acc_size, offset): self.ctrl_sock.send('%s;%s;%i;%i;%i;%i\n'%(self.name, device, freq_ref, freq_dds, acc_size, offset)) + +'''~ +class source_test(gr.hier_block2): + def __init__(self): + self.name = "source_test" + gr.hier_block2.__init__( + self, + name = self.name, + input_signature = gr.io_signature(0, 0, 0), + output_signature = gr.io_signature(1, 1, gr.sizeof_gr_complex) + ) + self.data_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.data_sock.connect((addr, port)) + self.data_sock.send('%s'%self.name) + fd = os.dup(self.data_sock.fileno()) + self.connect(blocks.file_descriptor_source(gr.sizeof_gr_complex, fd), self) +''' diff --git a/redpitaya/gnuradio_blocks/redpitaya_gnuradio.pyc b/redpitaya/gnuradio_blocks/redpitaya_gnuradio.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8f6c7b73ecbec66e263c8bae094f8484f7b5802e GIT binary patch literal 1921 zcmd5-%Wl&^6uq{SG%fE}p@75&B(s185-Sj*AdnEENRuugn^EwiI3#xQOprj?l^v1VYqseC6CT0bWw;F6)h%KJ{g7)gh{W_X zf6~Sr+A-K;nEL{USyK^<Z>>L$Mp4bvD*O)UXWo;b z^{4jP#*hEQ3444hGT&@+&%t^l~~avR(rLSsRG>e zlO4ltm~(JP+WkpP=cJ#(yKIXo^1Ii*KjXH>n%E<7L z{307e9X7DDM#J-9NQzN;@hq4VaC-K6-T`c^Gxa!7nC1)}4~9~k*V%hpXZgI5rcN7! zB!L1yWvYheii`2pku-1<^A6JhOQ3OEs)1Vw4%0w$4FR>h^P3o0!@d}xhvv7S3d5Va zQG~)aSHv0zcsrXbbXVbyR2rpy7q%!6!}Dua>8O6gIrC&1{o%qO@0>G}L&Fw%)qg!z r!^Qp`W6&>#dT34p)nxW_EG&EYic0PMM!^pVkn6%-!UeT= StrictVersion("4.5.0"): + style = gr.prefs().get_string('qtgui', 'style', 'raster') + Qt.QApplication.setGraphicsSystem(style) + qapp = Qt.QApplication(sys.argv) + + tb = top_block_cls() + tb.start() + tb.show() + + def quitting(): + tb.stop() + tb.wait() + qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting) + qapp.exec_() + + +if __name__ == '__main__': + main() diff --git a/redpitaya/server/server.py b/redpitaya/server/server.py index 6216e68..7da5c38 100755 --- a/redpitaya/server/server.py +++ b/redpitaya/server/server.py @@ -1,12 +1,9 @@ #!/usr/bin/env python + import socket from thread import start_new_thread import liboscimp_fpga -ctrl_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -ctrl_sock.bind(('', 1001)) -ctrl_sock.listen(10) - def clientThread(conn, addr): print('Open connection from ' + addr[0] + ':' + str(addr[1]) + '\n') while True: @@ -24,10 +21,15 @@ def clientThread(conn, addr): liboscimp_fpga.nco_counter_send_conf(recv[1], int(recv[2]), int(recv[3]), int(recv[4]), int(recv[5])) except: pass - conn.close() + conn.close() -while 1: - conn, addr = ctrl_sock.accept() - start_new_thread(clientThread ,(conn, addr,)) +ctrl_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +ctrl_sock.bind(('', 1001)) +ctrl_sock.listen(10) -ctrl_sock.close() +try: + while True: + conn, addr = ctrl_sock.accept() + start_new_thread(clientThread ,(conn, addr,)) +except KeyboardInterrupt: + ctrl_sock.close() diff --git a/redpitaya/server/test.py b/redpitaya/server/test.py new file mode 100644 index 0000000..2ba73ef --- /dev/null +++ b/redpitaya/server/test.py @@ -0,0 +1,6 @@ +import time + +with open('/dev/data16_adc12', 'r') as f: + for line in f: + print(line.encode('bin')) + time.sleep(0.1) diff --git a/redpitaya/server/test_emb.py b/redpitaya/server/test_emb.py new file mode 100755 index 0000000..837fd52 --- /dev/null +++ b/redpitaya/server/test_emb.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +import ctypes, argparse +import liboscimp_fpga + +def parse(): + parser = argparse.ArgumentParser(description = 'Set offsets to DAC1 and DAC2') + parser.add_argument('-of1', + action='store', + dest='of1', + default=0, + help='DAC1 offset (bits)') + parser.add_argument('-of2', + action='store', + dest='of2', + default=0, + help='DAC2 offset (bits)') + args = parser.parse_args() + return args + +def main(): + args = parse() + of1 = int(args.of1) + of2 = int(args.of2) + liboscimp_fpga.add_const_set_offset("/dev/add_const_0", of1) + liboscimp_fpga.add_const_set_offset("/dev/add_const_1", of2) + print('offset DAC1 : %i'%of1) + print('offset DAC2 : %i'%of2) + +if __name__ == "__main__": + main() -- 2.16.4