redpitaya_gnuradio.py 2.16 KB
#!/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
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))