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