discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] using shared variables in GNU Radio


From: Martin Braun
Subject: Re: [Discuss-gnuradio] using shared variables in GNU Radio
Date: Thu, 5 Nov 2015 13:33:42 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

There's different ways to address this:

- The channel-power-calculator can send the calculated power downstream.
This can either happen as a message, or as a stream.
- You could query the value from the other block, e.g. by having a
reference to the block and accessing a getter (that's sometimes
necessary, but not really clean), or sending a message to trigger a
response message.

M


On 05.11.2015 13:22, Subrata Sarkar wrote:
> Hi, 
> Is it possible to share a variable between two blocks in GNU Radio such
> that block A modifies its value and block B reads it. Block A that
> modifies the value is a downstream block. I have a block called CSMA and
> it has a msg input port. Whenever it receives a msg, its corresponding
> msg handler "in( )" is executed. In my function "in( )", I need the
> channel power that is calculated by another downstream block
> "channel_power".  
> 
> void csma_impl::in(pmt::pmt_t msg)
>     {
> ..
>  bool okay_to_send = false;
> while(k < 10){
>                 //check channel state
> okay_to_send = channel_state(d_threshold, power);  if (okay_to_send) break;
> wait_time(1000); // waits 1000 micro-seconds
> k++;
> }
> }
> bool csma_impl::channel_state(float threshold, double * power)
> {
> //assuming power is the pointer to the shared variable between the blocks
> // extracts the value pointed to by power
> if (*power >= threshold) {return true;} return false;
> }
> void csma_impl::wait_time(double wait_duration)
> {
> time_t start_time;
> time_t stop_time;
> time(&start_time);
> time(&stop_time);
> while((stop_time - start_time)/1000000 <= wait_duration)
> {
> time(&stop_time);
> }
> }
> 
> I can't pass the value modified by the downstream block "channel_power"
> to "CSMA" block as a feedback (as a message) because I want to get
> access to the current value of the shared value multiple times in the
> while loop in a single execution of the csma block. 
> 
> Subrata
>  
> 
> 
> 
> 
> _______________________________________________
> Discuss-gnuradio mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]