I tried responding to this before but I'm not sure if it actually posted so
I'm using a different email address.

Thanks for your response Baskshi. I looked at the code you implemented,  in
addition to looking at the information on message passing on doxygen.

I've tried creating my own code that would adjust the gain by a certain
amount(0.5 dB) after receiving a certain number of samples. However, after
the block receives the required number of input samples, I want it to send
out 12 0's in addition to sending the sink block a command to adjust the
gain. I believe sending out the 12 0's should be handled in the forecast
function but I'm not sure if I'm going about doing this correctly.

I've attached my flow graph and the code for this "gain setter" block. Any
feedback would be great.

Tellrell

On Mon, Jul 17, 2017 at 1:07 PM, Tellrell White <[email protected]> wrote:

> Thanks for your response Baskshi. I looked at the code you implemented,
> in addition to looking at the information on message passing on doxygen.
>
> I've tried creating my own code that would adjust the gain by a certain
> amount(0.5 dB) after receiving a certain number of samples. However, after
> the block receives the required number of input samples, I want it to send
> out 12 0's in addition to sending the sink block a command to adjust the
> gain. I believe sending out the 12 0's should be handled in the forecast
> function but I'm not sure if I'm going about doing this correctly.
>
> I've attached my flow graph and the code for this "gain setter" block. Any
> feedback would be great.
>
> Tellrell
>
>
> On Thursday, July 13, 2017 2:48 PM, "Bakshi, Arjun"
> <[email protected]> wrote:
>
>
> Couldn't figure out how to reply from the digest, so I'm making a new
> post. New to this.
>
> Original message/context:
> ==============================
> *From*: Tellrell White
>
> I'm currently in the process of creating a block in python that does two
> things; takes in? a certain number of input items, and once it reaches a
> certain number of input items 2) it sends a command to the UHD USRP sink
> block to adjust its gain by a certain amount.
>
> I have a few questions. 1) Is it even possible to create a single block
> that can accomplish both these tasks? 2) How exactly do I make this block
> issue the command to adjust the gain after it receives a certain number of
> values??Below is some code that I currently have constructed for this
> purpose. I'm pretty new to python so I'm sure this code is probably not the
> most efficient way but any suggestions are welcome.
>
> ===============================
>
> Hey Tellrell,
>
> 1) I think it can be achieved using 1 block. The block will need to output
> a * message* with "gain" and the gain value whenever the input matches
> your condition. Connect the output *message* port to the USRP sink's
> command port. Message should be a pmt that looks something like ("gain",
> value).
>
> More info on the command port: https://gnuradio.org/doc/
> doxygen/page_uhd.html#uhd_command_syntax
>
>
> 2) I went ahead and implemented something as an example. Increases gain
> upto a limit and then starts over again. See attached code, xml for block,
> rxed signal plot, and flowgraph pic.
>
> I'm new to this too, so hopefully other will correct my mistakes.
>
> Regards,
>
> AB
>
>
>
> _______________________________________________
> Discuss-gnuradio mailing list
> [email protected]
> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
>
>
"""
Embedded Python Blocks:

Each 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 as np
from gnuradio import gr
import pmt
from random import uniform
import pdb

class blk(gr.basic_block):
    def __init__(self, initial_gain=5, stop_gain=15, step=0.5):# only default arguments here
        gr.basic_block.__init__(
            self,
            name='Gain Sweeper',
            in_sig=[np.complex64],
            out_sig=[np.complex64]
        )
       
        self.message_port_register_out(pmt.intern('msg_out'))
        self.gain = initial_gain
        self.step = step
        self.stop = stop_gain
        self.count = 0
        self.a = 000000000000
        

    #def forecast(self, noutput_items, ninput_items_required):
     #   #setup size of input_items[i] for work call
      #  for i in range(len(ninput_items_required)):
       #     ninput_items_required[i] = noutput_items + a


    def general_work(self, input_items, output_items):
     #creating variables equal to the number of input & output items 
        in0 = input_items[0]
        out = output_items[0]
     # loop that will count the number of input items. Once 10^7 input items is reached
     # a command will be sent to increase the gain.
        for x in len(in0):
             pdb.set_trace()
             self.count = count + len(in0)
             if self.count == 100000000:
                self.count = 0
                self.message_port_pub(pmt.intern('msg_out'),pmt.cons(pmt.intern("gain"),pmt.to_pmt(self.gain)))
                self.gain+=self.step

        return len(output_items[0])



Attachment: gain_test.grc
Description: application/gnuradio-grc

_______________________________________________
Discuss-gnuradio mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Reply via email to