0

I am currently working on a GNU Radio project and I have an issue on the xml part.

I need to open a config file and read it to get my variable for GNU Radio.

Now, I just have the build-in files which allow to read the config file, but just once, at the start of the GNU Radio flowgraph. I want to refresh my variable when I change it in the config file while GNU Radio is running.

It's perhaps a specific question since it implies XML and GNU Radio but I think it can be solve even whithout knowing GNU Radio.

SO, there it is :

<block>
    <name>Variable Config1</name>
    <key>variable_config1</key>
    <import>import ConfigParser</import>
    <var_make>self._$(id)_config = ConfigParser.ConfigParser()
self._$(id)_config.read($config_file)
try: $(id) = self._$(id)_config.$(type.get)($section, $option)
except: $(id) = $value
self.$(id) = $(id)</var_make>
    <make></make>
    <callback>self.set_$(id)($value)</callback> 
    <callback>self._$(id)_config = ConfigParser.ConfigParser()
self._$(id)_config.read($config_file)
if not self._$(id)_config.has_section($section):
    self._$(id)_config.add_section($section)
self._$(id)_config.set($section, $option, str($writeback))
self._$(id)_config.write(open($config_file, 'w'))</callback>
    <param>
        <name>Default Value</name>
        <key>value</key>
        <value>0</value>
        <type>$type</type>
    </param>
    <param>
        <name>Type</name>
        <key>type</key>
        <value>real</value>
        <type>enum</type>
        <option>
            <name>Float</name>
            <key>real</key>
            <opt>get:getfloat</opt>
        </option>
        <option>
            <name>Int</name>
            <key>int</key>
            <opt>get:getint</opt>
        </option>
        <option>
            <name>Bool</name>
            <key>bool</key>
            <opt>get:getboolean</opt>
        </option>
        <option>
            <name>String</name>
            <key>string</key>
            <opt>get:get</opt>
        </option>
    </param>
    <param>
        <name>Config File</name>
        <key>config_file</key>
        <value>default</value>
        <type>file_open</type>
    </param>
    <param>
        <name>Section</name>
        <key>section</key>
        <value>main</value>
        <type>string</type>
    </param>
    <param>
        <name>Option</name>
        <key>option</key>
        <value>key</value>
        <type>string</type>
    </param>
    <param>
        <name>WriteBack</name>
        <key>writeback</key>
        <value>None</value>
        <type>raw</type>
    </param>
    <doc>


This block represents a variable that can be read from a config file.

To save the value back into the config file: \
enter the name of another variable into the writeback param. \
When the other variable is changed at runtime, the config file will be re-written.
    </doc>
</block>

To be honest, I don't know XML at all, but I really need to do this.

Even if I don't know XML I did some research before asking and I didn't find anything.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
user
  • 65
  • 1
  • 6

2 Answers2

0

What you're trying to do doesn't make sense. These XML files are really read long before the flow graph even gets converted to python source code, and are completely irrelevant for the further operation. The GNU Radio python application generated from your GRC flow graph has nothing to do with these XML files.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
-1

In fact there is a block to do this in gnuradio. So, if someone wants do change a variable using python while the flowgraph is running, look for the xmlrpc block

user
  • 65
  • 1
  • 6