'Cannot use my gain block from the example. How to?

I am trying to make a custom block for my x310 and use it. So far, I'm stuck at the example FPGA image compilation because I can't use the custom block gain.

I've followed step by step the "Building an FPGA Image with OOT Blocks" tutorial and successfully compiled and uploaded the image to my x310. A uhd_usrp_probe returned the expected "0/Block#0" linked back and forth to the SEP4 Block. But a warning from RFNOC:BLOCK_FACTORY states "could not find block with Noc-ID 0xb16, 0xffff"

I proceeded anyway after compiling a custom C++ program based on the rfnoc_radio_loopback example in order to make use of the gain block,

I added this line in the includes:

 #include <rfnoc::gain::gain_block_control.hpp>

And these two lines after the radio_block_control instancing:

uhd::rfnoc::block_id_t gain_id(0, "Block", 0);
rfnoc::example::gain_block_control::sptr gain_ctrl = graph->get_block<rfnoc::example::gain_block_control>(gain_id);

The program compiles fine but running it returns a LookupError stating "This device doesn't have a block of type rfnoc::example::gain_block_control with ID: 0/Block#0" I tend to believe the lookup error is clear but I don't know what to do instead.

I first tried to use the block with gnuradio-companion but was not able to generate the block at all. I am sure I am missing something but I have no idea what (apart from actual brain cells).

  • What is wrong with my C++?
  • Is it possible to generate a gain block in gnuradio-companion and if yes how?
  • Do you know of some tutorial that explains the different procedures on how to use a custom block?


Solution 1:[1]

There is an example application (rfnoc-example/apps/init_gain_block.cpp) that will test the functionality of the block for you. You can compile/run that to see if your block is working.

If you are seeing uhd_usrp_probe return 0/Block#0 instead of 0/Gain#0, then the .so file is not being picked up properly. The easiest way to test this is to LD_PRELOAD the DLL like this:

LD_PRELOAD=/path/to/librfnoc-example.so uhd_usrp_probe

What this will do is force a preload of the DLL containing the block controller (which will make sure it is registered). You should be seing 0/Gain#0 as the block ID now.

Solution 2:[2]

If you want to do something upon setting state then your best bet is to use the useEffect hook from React and adding your state in the dependency array. This will then call the function in your useEffect every time the state changes. See below a rough example:

import { Text } from 'react-native';

const MyComponent = () => {
  const [activeUser, setActiveUser] = useState(null);

  useEffect(() => {
    // This should log every time activeUser changes
    console.log({ activeUser });
  }, [activeUser]);

  const fetchAuthentication = async user => {
    var flag = false;
    await fetch('/api/authUser/', {
      method: 'PUT',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(user),
    })
      .then(res => {
        res.ok && (flag = true);
        return res.json();
      })
      .then(json => {
        if (flag) {
          setActiveUser(json);
        }
      })
      .catch(error => console.error(error));
    return flag;
  };

  return <Text>Hi</Text>;
};

Full documentation: https://reactjs.org/docs/hooks-effect.html

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mbr0wn
Solution 2 P. Brew