You can try the FindModlue::findHost()
in DemoBaseApplLayer::initialize(int stage)
in DemoBaseApplLayer.cc
:
EV << FindModule<BaseMobility*>::findHost(getParentModule())->getId() << endl;
It will first return the host module and then use the getId()
function to get its id.
For better understanding:
Firstly, you can run the simulation to see the indexing of the whole simulation and it would be like this:
Simulation information in veins
As read from the figure, each objects are assigned to a number, e.g. node[0]
has the id 7
, besides that, each sub-modules are also assigned with id numbers, e.g.
node[0]
id = 7
appl
id = 8
nic
id = 9
veinsmobility
id = 10
All of this ids (7,8,9,10) point to the node[0]
, which means you can use thoese ids to identify a specific car.
In the default DemoBaseApplLayer.cc
, you can find
mac = FindModule<DemoBaseApplLayerToMac1609_4Interface*>::findSubModule(getParentModule());
and
myId = mac->getMACAddress();
in the initialization function void DemoBaseApplLayer::initialize(int stage)
.
Therefore, you can already use the myId
as the vehicle id.
By the way, the reason that you get the 18
and 20
for vehicle id, is that the returned module might just be the host module and the sub-module, e.g. 18
is for the node[*]
and the 20
is for its nic
sub-module.