Search code examples
c++omnet++veins

Send a periodically message with TraCIDemo11p


With veins in the example TraCIDemo11p I want to add a method that periodically send (each 1s) a wsm Here is what I modify:

I created a method called "sendTrace"that is similar to the one in the example but with the wsm data changed:

void TraCIDemo11p::sendTrace() {


        t_channel channel = dataOnSch ? type_SCH : type_CCH;
        WaveShortMessage* wsm = prepareWSM("data", dataLengthBits, channel, dataPriority, -1,2);
        wsm->setWsmData(traceID.c_str());
        sendWSM(wsm);
         EV << "Received message2 `" << wsm->getSenderModuleId() << "', sending it out again\n";
}

in traCIDemo11p.h const std::string traceID ="trace";

In onData I add a condition on received messages:

void TraCIDemo11p::onData(WaveShortMessage* wsm) {

    if (wsm->getWsmData()== traceID.c_str()){
        infoWsm.push_back(wsm);
        EV << "Received message3 `" << wsm->getSenderModuleId() << "', sending it out again\n";
    }
    else{

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());
EV << "Received message4`" << wsm->getSenderModuleId() << "', sending it out again\n";
    }

}

At the initialization I send the first trace:

void TraCIDemo11p::initialize(int stage) {
BaseWaveApplLayer::initialize(stage);
if (stage == 0) {
    ...
    lastTraceAt = simTime();
    sendTrace();

}

}

And in handleParkingUpdateI control the sending of other traces:

void TraCIDemo11p::handleParkingUpdate(cObject* obj) {
isParking = mobility->getParkingState();
if (sendWhileParking == false) {
    if (isParking == true) {
        (FindModule<BaseConnectionManager*>::findGlobalModule())->unregisterNic(this->getParentModule()->getSubmodule("nic"));
    }
    else {
        Coord pos = mobility->getCurrentPosition();
        (FindModule<BaseConnectionManager*>::findGlobalModule())->registerNic(this->getParentModule()->getSubmodule("nic"), (ChannelAccess*) this->getParentModule()->getSubmodule("nic")->getSubmodule("phy80211p"), &pos);
    }
}

}

Then while running I had this error !!

<!> Error in module (TraCIDemo11p) RSUExampleScenario.node[0].appl (id=14) at event #54, t=3.100413031916: TraCI server reported error executing command 0xc4 ("Referenced edge 'trace' is not known.")..

And I can not identify the source of this problem could you help me!

PS:I know the error says that the edge 'trace' is not recognized which means that the condition set in the ondata method does not work !! So please tell me how to fix it or if there is another problem (s)?


Solution

  • Trying to compare two char* using == means you are comparing memory addresses, not (as you assume) what text is stored there.