【问题标题】:Sending msg from RSU to vehicles in veins从 RSU 向血管中的车辆发送消息
【发布时间】:2021-11-26 08:14:34
【问题描述】:

我正在尝试实现一个小例子:RSU 广播自己的 ID 和其他信息,车辆接收 RSU 的 ID 并记录它。 我新建了一个名为 BeaconRSU.msg 的 msg 文件,RSU 和车辆的应用层 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;
}

部分调试模式日志如下所示:

【问题讨论】:

    标签: c++ omnet++ veins


    【解决方案1】:

    您似乎在“发布”模式下运行模拟,而不是“调试”模式。虽然这将使您的模拟运行得更快,但它省略了许多健全性检查,并且仅打印有关模拟中发生的事情的最少信息。出于所有这些原因,强烈建议仅在完全完成后以“发布”模式运行模拟。

    有关如何在调试模式下运行模拟的信息,请参阅 Veins 常见问题解答条目“如何调试我的 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
    

    在此示例中,调试消息Packet has bit Errors. Lost(请参阅https://github.com/sommer/veins/blob/veins-5.1/src/veins/modules/phy/Decider80211p.cc#L151)将告诉您已尝试解码(即信号强到足以被接收器检测到),但解码失败。您正在使用的 Phy 层模型基于 SINR(信号功率与干扰和噪声功率之比)(请参阅https://github.com/sommer/veins/blob/veins-5.1/src/veins/modules/phy/Decider80211p.cc#L142)决定是否可以正常接收传输,因此这可能有以下两个原因之一:信号可能已经太弱(传输功率低,发送者太远)或干扰信号可能太强(其他人同时发送)。如果您对这两种情况中的哪一种感兴趣,您可以启用 NIC 的phy80211p 模块的参数collectCollisionStatistics(参见https://github.com/sommer/veins/blob/veins-5.1/src/veins/modules/phy/PhyLayer80211p.ned#L43)。然后,您将看到 Packet has bit Errors due to low power 或 Packet has bit Errors due to collision,而不仅仅是 Packet has bit Errors。

    【讨论】:

    • 非常感谢您的回答!我尝试了调试模式,我的情况与您上面的示例完全相同。我检查了源代码,根据日志数据是这种情况: case NOT_DECODED: if (!collectCollisionStats) { EV_TRACE
    • 我对答案进行了修改,以包含有关调试丢失帧原因的更多提示。
    猜你喜欢
    • 1970-01-01
    • 2020-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多