从 RSU 向静脉中的车辆发送消息

Sending msg from RSU to vehicles in veins

我在尝试实现一个小例子:RSU广播自己的ID等信息,车辆接收RSU的ID并记录下来。 我新建了一个msg文件,命名为BeaconRSU.msg,RSU和vehicle的应用层cc文件如下:

//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;    }

当我运行仿真时,可以看到RSU发送的msg成功,但是节点收不到msg(MyVeinsAppCar::handleLowerMsg(cMessage* msg)里面的内容没有打印出来) . 日志中有一些错误: enter image description here

为什么会这样?有人帮帮我吗?提前致谢!

//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;
}

部分debug模式日志如下:

您似乎 运行在“发布”模式而非“调试”模式下模拟您的模拟。虽然这会让您的模拟 运行 更快,但它会省略大量完整性检查并仅打印有关模拟中发生的事情的最少信息。出于所有这些原因,强烈建议在完全完成后仅 运行 在“发布”模式下进行模拟。

有关如何在调试模式下运行模拟的信息,请参阅 Veins FAQ 条目“如何调试我的 OMNeT++ 模拟模型?如何创建堆栈跟踪?" 在 http://veins.car2x.org/documentation/faq/

当 运行在调试模式下运行您的模拟时,您应该会看到更多解释模拟中发生的事情的日志信息。例如,日志输出可能如下所示:

** 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

在此示例中,NIC 的 phy80211p 模块的调试消息 Packet has bit Errors. Lost(参见 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)。而不是 Packet has bit Errors 然后你会看到 Packet has bit Errors due to low powerPacket has bit Errors due to collision.