0

I encounter some trouble when using VEINS. I want to simulate a comunication between RSU and Vehicle. in the begining of simulation, RSU broadcasts a MsgInit message to all vehicles, after that, the vehicles also broadcasts a Metrics message to RSU. But RSU cannot received the Metrics message, I dont know the reason, can someone help me? Here is my code (I'm using omnet 5.6.2, sumo 1.8.0 and veins 5.1)

// MyVeinsAppRSU.cc
void MyVeinsAppRSU::initialize(int stage)
{
    ...
    // send message "sendMsgInit" at 70 second of simulation
    scheduleAt(simTime()+70,sendMsgInit);
}
void MyVeinsAppRSU::handleSelfMsg(cMessage* msg)
{
    MsgInit* msg_init = new MsgInit();
    BaseFrame1609_4* WSM = new BaseFrame1609_4();
    WSM->encapsulate(msg_init);
    populateWSM(WSM);
    // send out WSM from lowerLayer of Application of RSU
    send(WSM,lowerLayerOut);
}
void MyVeinsAppRSU::handleLowerMsg(cMessage* msg)
{
    BaseFrame1609_4* WSM = check_and_cast<BaseFrame1609_4*>(msg);
    //Decapsulation packet from WSM
    cPacket* pkt = WSM->getEncapsulatedPacket();
    // translate packet to Metrics
    Metrics* MT = dynamic_cast<Metrics*>(pkt);
    EV << "send message Vehicle id: " << MT->getVehicleId() << "Receive successfully !!!!!!!!!!!" << endl;
}
// MyVeinsAppCar.cc
void MyVeinsAppCar::handleLowerMsg(cMessage* msg)
{
    BaseFrame1609_4* WSM = check_and_cast<BaseFrame1609_4*>(msg);
    cPacket* enc = WSM->getEncapsulatedPacket();
    MsgInit* MI = dynamic_cast<MsgInit*>(enc);
    // initialize as follower
    findHost()->getDisplayString().setTagArg("i", 1, "black");

    //after receive MsgInit, send Metrics out(next step: handleSelfMsg)
    if (sendMetrics->isScheduled()) {
        cancelEvent(sendMetrics);
    }
    scheduleAt(simTime() + 1,sendMetrics);
}
void MyVeinsAppCar::handleSelfMsg(cMessage* msg)
{
    cModule* vehicle = getParentModule();
    TraCIMobility* traci = dynamic_cast<TraCIMobility*>(vehicle->getSubmodule("veinsmobility", 0));
    TraCICommandInterface::Vehicle* traciVehicle = traci->getVehicleCommandInterface();

    if(msg == sendMetrics){

        Metrics* msg_metrics = new Metrics();
        msg_metrics->setVehicleId(this->getParentModule()->getIndex());
        msg_metrics->setSpeed(traci->getSpeed());

        BaseFrame1609_4* WSM = new BaseFrame1609_4();
        WSM->encapsulate(msg_metrics);
        populateWSM(WSM, -1);
        send(WSM,lowerLayerOut);

        EV << "send Metrics!!"<< endl;
    }
}

Thank you in advance.

  • When you run your simulation in debug mode, you should be able to see a lot of debug information in the event stream (visible in the log window at the bottom of your simulation's GUI). What is the last event relevant to your message exchange that you are able to witness in there? – Christoph Sommer May 07 '21 at 17:56
  • it can see the transmission of the message in the GUI screen, but the log information below seems does not receipt (I set to print the information after receiving the message). There are some error messages in the log. I don't know if it is related? (error does not affect simulation) I don’t quite understand the meaning of those error messages – georgeGu May 10 '21 at 07:53
  • log as below: `** Event #396 t=71.000473698518 RSUExampleScenario.node[3].nic.mac1609_4 (Mac1609_4, id=37) on Error (omnetpp::cMessage, id=684) ** Event #397 t=71.00047369893 RSUExampleScenario.node[1].nic.phy80211p (PhyLayer80211p, id=24) on selfmsg (veins::AirFrame11p, id=536) ** Event #398 t=71.00047369893 RSUExampleScenario.node[1].nic.mac1609_4 (Mac1609_4, id=25) on Error (omnetpp::cMessage, id=685) ** Event #399 t=71.000473699371 RSUExampleScenario.node[3].nic.phy80211p (PhyLayer80211p, id=36) on selfmsg transmission over (omnetpp::cMessage, id=66)` – georgeGu May 10 '21 at 07:54
  • Are you really sure you are running a debug build? I am seeing way fewer messages starting with “TRACE” or “DEBUG” than I would expect… – Christoph Sommer May 10 '21 at 20:44
  • I guess I had solved this problem by let vehicle broadcast one by one instead of at the same time. It may be due to the collision caused by the simultaneous broadcast, which caused some vehicles can receive, while others could not. Thanks for your advice. – georgeGu May 11 '21 at 11:53
  • Glad to hear you managed to find an answer to your question. If you can, I would encourage you to post the answer here (and mark it as accepted). This way, other people who have the same question will be able to easily find it - and the answer to it. – Christoph Sommer May 11 '21 at 15:12

0 Answers0