Search code examples
omnet++veinssumo

The external ID of wsm message sender


I am using OMNET 5.0, SUMO-0.25.0 and VEINS-4.4. When a vehicle receive a message; onData() is called. I can get external ID of the current vehicle using mobility->getExternalId(); but how I know the the external ID of wsm message sender

The code for initialize():

void TraCIDemo11p::initialize(int stage) {
    BaseWaveApplLayer::initialize(stage);
    if (stage == 0) {
        mobility = TraCIMobilityAccess().get(getParentModule());
        traci = mobility->getCommandInterface();
        traciVehicle = mobility->getVehicleCommandInterface();
        annotations = AnnotationManagerAccess().getIfExists();
        ASSERT(annotations);
        getExternalID =  mobility->getExternalId();
        sentMessage = false;
        lastDroveAt = simTime();

        findHost()->subscribe(parkingStateChangedSignal, this);
        isParking = false;
        sendWhileParking = par("sendWhileParking").boolValue();
    }
}

The code for onData():

void TraCIDemo11p::onData(WaveShortMessage* wsm) {
    std::cout << " I am "<< getExternalID  <<"and I received a message from ???? "<<endl;
    findHost()->getDisplayString().updateWith("r=16,green");
    annotations->scheduleErase(1, annotations->drawLine(wsm->getSenderPos(), mobility->getPositionAt(simTime()), "blue"));

    if (mobility->getRoadId()[0] != ':') 
          traciVehicle->changeRoute(wsm->getWsmData(), 9999);
    if (!sentMessage) 
          sendMessage(wsm->getWsmData());

}

Solution

  • A vehicle can be represented by two identifiers, either that one gotten from SUMO (i.e., calling getExternalId()) or that one of veins (myId normally), the one used in WaveShortMessage after calling getSenderAddress() is myId so I suggest that you focus on that last one.

    Take a look on these two files to get a better idea on the used identifier and the existing methods: "BaseWaveApplLayer.h/.cc" & "WaveShortMessage_m.h/.cc"

    I hope this helps.