1
votes

There are n Adhoc nodes that are deployed randomly in field. Because of necessity to a special node I ought to extend new node from AdhocHost and add some parameter like node coordinates.

MySensorNode.ned

import inet.node.inet.AdhocHost;
import inet.node.inet.INetworkNode;

module MySensorNode extends AdhocHost like INetworkNode
{
  parameters:
      @display("bgb=827.48,663.192;bgu=m;i=misc/transmission_anim");
      @class(inet::MySensorNode);
}

MySensorNode.h

#ifndef __INET_MYSENSORNODE_H
#define __INET_MYSENSORNODE_H


namespace inet {

class MySensorNode : public ***????????what should I write here????***
{
   public:
    bool first_init = true;
        MySensorNode();
        virtual ~MySensorNode();
        virtual void initialize(int stage);
        virtual void changecolor();
        virtual void handleMessage(cMessage *msg);
        ?????????others ?????????

};
} // namespace inet
#endif /* __INET_MYSENSORNODE_H */

MySensorNode.cc

#include "MySensorNode.h"
namespace inet {

Define_Module(MySensorNode);


void MySensorNode::initialize(int stage)
{
    if(first_init)
    {
        changecolor();
    }
}

void MySensorNode::changecolor()
{
???????????????????
}


} // namespace inet

as the first part of question, I want to change 5% of nodes' color in initialization. How can I do that?

please mention my mistakes in the codes above. Thx

1
Well, if you have 100 nodes and you want to change the color of 5%, why not taking the first five nodes (based on the node's ID) and change the color? - thardes2
thank you @thardes2. actually it's the first step for clustering. nodes are deployed randomly and IDs aren't in order , the number of nodes are around 1000, and in the next step I want to choose nodes with more energy as Cluster head and change their color. - bob winter
So your question is "how to change a nodes' color"? - thardes2
as the first step yes, It's just a question to learn how to work with ad hoc node. I don't know it. In manual there is just cSimpleModule example but here I extend a module. - bob winter
suppose I add a parameter like xpos to mysensornode module, how can I call it in any method()? - bob winter

1 Answers

0
votes

If it is just about changing the colour, you need to change the Display String.

You could do it like this in the initialize method of the UDPBasicApp module (stage 1):

getParentModule()->getDisplayString().setTagArg("i", 1, "yellow");

The different tags are described in the OMNeT++ Manual

The AdhocHost is a compound module. Although the C++ class for a compound module can be overridden with the @class property, this is a feature that should probably never be used. Encapsulate the code into a simple module, and add it as a submodule. Read this for more information.

To add it as a submodule, you need to change the compound module. This could be done like this:

module SomeName extends AdhocHost 
{
    submodules:
        mySensorNode: MySensorNode;
}

Then your MySensorNode is a cSimpleModule:

namespace inet {

class MySensorNode : public cSimpleModule
{
   public:
....

There are a lot of examples for this on Stack Overflow and in the INET Framework, e.g. the inet.linklayer.common.WirelessNic