Guidelines - ThomasRueckert/sensorSim GitHub Wiki

how to use XML support

important functions

  • function -> returns
  • [parameter].xmlValue() -> cXMLElement*
  • cXMLElement::getNodeValue() -> string
  • [any-tag]->getChildren() -> cXMLElementList

example

inside the NED file:

...
parameters:
    xml test = xmldoc("[path]/test.xml");

note: the path for the xml-file must be defined from the project-root, not from the position of the NED-file

inside the c++ code

// get the xml from the parameter, return type cXMLElement
cXMLElement *rootE = par("test").xmlValue(); 

// get the data inside the parent-/root-tag
EV << rootE->getNodeValue() << endl;

// get a vector (of type cXMLElement) with all childs of the root-tag
cXMLElementList nList = rootE->getChildren();

// again access the data from a child
EV << nList[0]->getNodeValue() << endl;

Example for inheritance

Both Sensor and a NIC have C-Code and NED-files, Sensor is a Module of the NIC (here called Node)

Some very important statements:

  • inside the c-code
  • Register_Class([Classname]);
  • Define_Module([Classname]);
  • include the parent class inside the child class
  • inside the NED files
  • import the package to include inside the NED file

Sensor

Sensor.h:

Class Sensor
{
    //some methods and members
}

Register_Class(Sensor);
Define_Module(Sensor);

Sensor.ned:

package sensor;

simple Sensor
{
    //some modules, params etc.
}

Node

Node.h:

#include <Sensor.h>

Class Node
{
    //some methods and members
}

Register_Class(Node);
Define_Module(Node);

Node.ned:

package node;
import sensor;

simple Node
{
    //some modules, params etc.
    submodule:
        Sensor: Sensor {
            @display("p=140,310");
        }
}
⚠️ **GitHub.com Fallback** ⚠️