Tiffany
Tiffany

Reputation: 43

Sending msg from RSU to vehicles in veins

I'm trying to implement a small example in veins: the RSU broadcasts its own ID and other information, and the vehicle receives the RSU'S ID and records it. I have created a new msg file named BeaconRSU.msg, and the application layer's cc files of RSU and vehicle are shown below:

//MyVeinsAppRSU.cc
#include "veins/modules/application/traci/MyVeinsAppRSU.h"
#include "veins/modules/application/traci/BeaconRSU_m.h"

using namespace veins;

Define_Module(veins::MyVeinsAppRSU);

void MyVeinsAppRSU::initialize(int stage)
{
  DemoBaseApplLayer::initialize(stage);
    if (stage == 0) {
        sendBeacon= new cMessage("send Beacon");
        EV << "Initializing " << par("appName").stringValue() << std::endl;
    }
    else if (stage == 1) {
        // Initializing members that require initialized other modules goes here
        if (sendBeacon->isScheduled())
        {
            cancelEvent(sendBeacon);
        }
        scheduleAt(simTime()+5,sendBeacon);
    }
}

void MyVeinsAppRSU::handleSelfMsg(cMessage* msg)
{
if (msg == sendBeacon){

    BeaconRSU* rsuBeacon = new BeaconRSU();
    rsuBeacon->setRSUId(this->getParentModule()->getIndex());
    rsuBeacon->setMyDemoData("RSU message!!");
    BaseFrame1609_4* WSM = new BaseFrame1609_4();
    WSM->encapsulate(rsuBeacon);
    populateWSM(WSM);
    send(WSM,lowerLayerOut);
    EV << "rsu send success" <<endl;
    if (simTime() < 2000) {
    scheduleAt(simTime()+1,sendBeacon);
    }
    return;
}

}

//MyVeinsAppCar.cc
#include "veins/modules/application/traci/MyVeinsAppCar.h"
#include "veins/modules/application/traci/BeaconRSU_m.h"
#include "veins/modules/application/traci/MyVeinsAppRSU.h"

using namespace veins;

Define_Module(veins::MyVeinsAppCar);

void MyVeinsAppCar::initialize(int stage)
{
    DemoBaseApplLayer::initialize(stage);
    if (stage == 0) {
        // Initializing members and pointers of your application goes here
        EV << "Initializing " << par("appName").stringValue() << std::endl;
        int a = INT_MIN;
    }
    else if (stage == 1) {
        // Initializing members that require initialized other modules goes here
        RSUIndex.setName("test");
        int a= INT_MIN;
        EV << "MyVeinsAppCar is initializing" << std::endl;
    }
}

void MyVeinsAppCar::handleLowerMsg(cMessage* msg)
{
    BaseFrame1609_4* WSM = check_and_cast<BaseFrame1609_4*>(msg);
    cPacket* enc = WSM->getEncapsulatedPacket();
    BeaconRSU* bc = dynamic_cast<BeaconRSU*>(enc);
    EV << "receive message  !!!" << endl;
    if(a!=bc->getRSUId())
    {
       RSUIndex.record(bc->getRSUId());
       a=bc->getRSUId();
    }
    EV << "my message = " <<bc->getMyDemoData()<<endl;
    EV <<"send message RSU id:" <<bc->getRSUId() << "  Receive successfully !!!!!!!!!!!" << endl;    }

When I run the simulation, I can see the msg sent from RSU successfully, but nodes cannot receive the msg (The contents in MyVeinsAppCar::handleLowerMsg(cMessage* msg) are not printed out). And there some error in log: enter image description here

Why did this happen? Is someone help me? Thank you in advance!

//BeaconRSU.msg

cplusplus{{
#import "veins/base/utils/Coord.h"
#import "veins/modules/utility/Consts80211p.h"
#include "veins/modules/messages/BaseFrame1609_4_m.h"
#include "veins/base/utils/SimpleAddress.h"
}};

namespace veins;

// TODO generated message class

class noncobject Coord;
class BaseFrame1609_4;

packet BeaconRSU extends BaseFrame1609_4
{
    //id of the originator
    int RSUId = 0;
    Coord position[100];
    double beaconrate[100];
    string myDemoData;
    Coord slotpos;
    simtime_t timestamp=0;
}

Part of the debug mode log is shown below:

enter image description here

enter image description here

Upvotes: 2

Views: 741

Answers (1)

Christoph Sommer
Christoph Sommer

Reputation: 6943

You seem to be running your simulation in "release" mode, not "debug" mode. While this will let your simulation run much faster, it omits a lot of sanity checks and prints only minimal information about what is happening in your simulation. For all of these reasons, it is highly recommended to only run a simulation in "release" mode after it is completely finished.

For information on how to run a simulation in debug mode, see the Veins FAQ entry "How can I debug my OMNeT++ simulation models? How do I create a stack trace?" at http://veins.car2x.org/documentation/faq/

When running your simulation in debug mode, you should see a lot more log information that explains what is going on in the simulation. For example, the log output might look like this:

** Event #100 t=1 ...nic.phy80211p (PhyLayer80211p, id=1)  on selfmsg  (veins::AirFrame11p, id=1)
TRACE (PhyLayer80211p)...nic.phy80211p: Processing AirFrame...
TRACE (PhyLayer80211p)...nic.phy80211p: Packet has bit Errors. Lost
TRACE (PhyLayer80211p)...nic.phy80211p: packet was not received correctly, sending it as control message to upper layer
TRACE (PhyLayer80211p)...nic.phy80211p: Channel idle now!
TRACE (PhyLayer80211p)...nic.phy80211p: End of Airframe with ID 6.

** Event #101 t=2 ...nic.mac1609_4 (Mac1609_4, id=2)  on Error (omnetpp::cMessage, id=1)
TRACE (Mac1609_4)RSUExampleScenario.node[27].nic.mac1609_4: A packet was not received due to biterrors

In this example, the debug message Packet has bit Errors. Lost (see https://github.com/sommer/veins/blob/veins-5.1/src/veins/modules/phy/Decider80211p.cc#L151) will tell you that decoding was attempted (that is, the signal was strong enough to be detected by the receiver), but decoding failed. The Phy layer model you are employing bases the decision whether a transmission is received okay on the SINR (the ratio of signal power to interference and noise power) (see https://github.com/sommer/veins/blob/veins-5.1/src/veins/modules/phy/Decider80211p.cc#L142) so this can have any one of two reasons: the signal might have been to weak (low transmission power, sender too far away) or interfering signals might have been too strong (somebody else was sending at the same time). If you are interested in which of the two was the case you can enable the parameter collectCollisionStatistics (see https://github.com/sommer/veins/blob/veins-5.1/src/veins/modules/phy/PhyLayer80211p.ned#L43) of the phy80211p module of a NIC. Instead of just Packet has bit Errors you will then see either Packet has bit Errors due to low power or Packet has bit Errors due to collision.

Upvotes: 1

Related Questions