TODO: Reorganize as sections and add links to Questions to enhance readability
palId.h, then you can use
palId_id() to get the node id. This only works, when called from a module.
There are four debugging output levels.
LOG_DEBUG("Message: " << somevariable);
you can print out a Message, if the debugging output for that module in that mode is turned on. For setting the debugging output, use the log.conf in your simulation folder. Every line contains the module name (as specified in the NED File), the debugging level (debug, info, warn, error), the output (
stdout for terminal or a filename) and the node id or
* for every node.
To start a Method after a certain time you can use the method
void schedule(Msg *msg, void(Mod::*handler)(Msg *), timeOffset_t ms = 0)
If you want to wait more than 65536 ms, your module needs to inherit from
LongScheduleModule. Then you are able to use the method
LongScheduleMsg* msg = new LongScheduleMsg(createCallback(&ModuleName::Handler)); longSchedule(msg, longTimeOffset_t delay);
LongScheduleMsg contains the Method (
ModuleName::Handler) to be called.
getModule(Moduelname) you get a pointer to the module. The caller needs to be also a module. Also remember to cast the pointer to the right type. If no module by that name exists, the method returns
ATTENTION: As soon as a module obtains a direct pointer from another module, the danger of producing an initialization race exists. Such a race can lead to arbitrarily mean symptoms, which can be random between builds or on the meaner side different behavior between nodes, depending on some initialization data. As long as there is no support for multiple initialization stages, one can and shall use the schedule method to schedule the critical operation. Thereby it is guaranteed, that all Modules are properly initialized.
Example Bug: StaticRouting used to call a loadRoutes() method, which retrieved static IPv6 routes from the EEPROM and added those to the routing table. RoutingTable, however, uses a pointer to the IPv6InterfaceTable module to check if an added address is a local address of this node for all routes with a prefix of 128 bit length. This pointer is set in RoutingTable's initialize() method, which was in this case called after StaticRouting's initialize method. This caused some nodes to reset directly after startup (those which actually had 128 bit prefix routes in their table) and some to work flawlessly. Changing flags to enable logging somehow caused the initialization order to be changed and let the problem “disappear”…
The parameters need to be specified in the module, then you can set a variable by the same name as in the NED file with
ASSERT(condition) you can check a condition. If the condition is not true, the simulation stops. On real hardware the node will get into a state where it just blinks all its leds and needs to be reset.
If you write your code only for simulation this is possible. However, the std Types are not available on the real hardware. Please use the templates in
cometos/src/templates. They offer some types similar to those of the std, for e.g.
In the simulation the module names can be as long as you want, but on hardware they are restricted to four characters. For consistency it is therefore recommended to use only four characters.