pluto - gnuradio - update attb block string only

Hi

My goal is to be able to call fast lock profiles from gnuradio - no problem if you want the profile number to be static, but if you try to swap the profile number via a variable it's almost impossible as none of the gnuradio variables or parameters allow strings, the update attribute block only allows strings.

For 3 days i tried via windows python to connect to the ad9361 but get a swig error every time.

So if anyone can suggest a windows method to write the attributes, the perfect solution would be python so i can write my own block that modulate from profile 0-7 

Parents
  • 99% of the way there, i just need a final push in the right direction to finish:

    Working -

    •  message structure and port out to attrb sink
    • taking complex64 variable (qt range) as "value" ie profile number and passing it successfully to sink (0 recall errors from backend so i'm guessing profile is applied)

    not working

    something with the lock, it takes the first value of the variable at initialisation and continues to use said value until killed, i know enough python to get by but some things i'm not so familiar with so a little nudge in the right direction would be appreciated. how do i get around the lock / while 1 loop so that i get the updated/refreshed 'Value' at each 'interval'

    """
    Embedded Python Blocks:
    
    Each time this file is saved, GRC will instantiate the first class it finds
    to get ports and parameters of your block. The arguments to __init__  will
    be the parameters. All of them are required to have default values!
    """
    
    import numpy
    from gnuradio import gr
    import threading
    import pmt
    import random
    from time import sleep
    
    
    class msg_block(gr.basic_block):  # other base classes are basic_block, decim_block, interp_block
        """This block converts strings from the QT GUI Message Edit Box to uint8 vectors"""
    
        def __init__(self,  value=7):  # only default arguments here
            """arguments to this function show up as parameters in GRC"""
            gr.basic_block.__init__(
                self,
                name='AD9361 Fastlock Strobe',   # will show up in GRC
                in_sig=None,
                out_sig=None
            )
    	self.attribute = "fastlock_recall"
            self.value = value
            self.interval = 10
    	
           	self.port = pmt.intern("out")
            self.message_port_register_out(self.port)
            self.lock = threading.Lock()
            self.run = True
            self.thread = threading.Thread(target=self.sender, args=())
            self.thread.start()
    	 
    
        def __del__(self):
            self.lock.acquire()
            self.run = False
            self.lock.release()
            self.thread.join()
    
        def update_value(self, value):
    	
           	self.value = value
    
        def sender(self):
            while 1:
                self.lock.acquire()
                if not self.run:
                    self.lock.release()
                    return
                self.lock.release()
    
                key0 = pmt.intern(str(self.attribute))
                val0 = pmt.intern(str(self.value))
                msg_dic = pmt.make_dict()
                msg_dic = pmt.dict_add(msg_dic, key0, val0)
                try:
                    self.message_port_pub(self.port, msg_dic)
                except:
                    print "Error: Failed to publish message"
                    return
    
                sleep(self.interval/1000)
      

Reply
  • 99% of the way there, i just need a final push in the right direction to finish:

    Working -

    •  message structure and port out to attrb sink
    • taking complex64 variable (qt range) as "value" ie profile number and passing it successfully to sink (0 recall errors from backend so i'm guessing profile is applied)

    not working

    something with the lock, it takes the first value of the variable at initialisation and continues to use said value until killed, i know enough python to get by but some things i'm not so familiar with so a little nudge in the right direction would be appreciated. how do i get around the lock / while 1 loop so that i get the updated/refreshed 'Value' at each 'interval'

    """
    Embedded Python Blocks:
    
    Each time this file is saved, GRC will instantiate the first class it finds
    to get ports and parameters of your block. The arguments to __init__  will
    be the parameters. All of them are required to have default values!
    """
    
    import numpy
    from gnuradio import gr
    import threading
    import pmt
    import random
    from time import sleep
    
    
    class msg_block(gr.basic_block):  # other base classes are basic_block, decim_block, interp_block
        """This block converts strings from the QT GUI Message Edit Box to uint8 vectors"""
    
        def __init__(self,  value=7):  # only default arguments here
            """arguments to this function show up as parameters in GRC"""
            gr.basic_block.__init__(
                self,
                name='AD9361 Fastlock Strobe',   # will show up in GRC
                in_sig=None,
                out_sig=None
            )
    	self.attribute = "fastlock_recall"
            self.value = value
            self.interval = 10
    	
           	self.port = pmt.intern("out")
            self.message_port_register_out(self.port)
            self.lock = threading.Lock()
            self.run = True
            self.thread = threading.Thread(target=self.sender, args=())
            self.thread.start()
    	 
    
        def __del__(self):
            self.lock.acquire()
            self.run = False
            self.lock.release()
            self.thread.join()
    
        def update_value(self, value):
    	
           	self.value = value
    
        def sender(self):
            while 1:
                self.lock.acquire()
                if not self.run:
                    self.lock.release()
                    return
                self.lock.release()
    
                key0 = pmt.intern(str(self.attribute))
                val0 = pmt.intern(str(self.value))
                msg_dic = pmt.make_dict()
                msg_dic = pmt.dict_add(msg_dic, key0, val0)
                try:
                    self.message_port_pub(self.port, msg_dic)
                except:
                    print "Error: Failed to publish message"
                    return
    
                sleep(self.interval/1000)
      

Children