首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从RSU向静脉中的车辆发送信息

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

Stack Overflow用户
提问于 2021-11-26 08:14:34
回答 1查看 284关注 0票数 2

我试图在静脉中实现一个小例子: RSU广播自己的ID和其他信息,而车辆接收RSU的ID并记录它。我创建了一个名为BeaconRSU.msg的新的msg文件,应用层的RSU和vehicle的cc文件如下所示:

代码语言:javascript
复制
//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;
}

}

代码语言:javascript
复制
//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)中的内容没有打印出来)。日志中有一些错误:在这里输入图像描述

为什么会发生这种情况?有人帮我吗?提前谢谢你!

代码语言:javascript
复制
//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;
}

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-26 12:45:16

您似乎是在“释放”模式下运行模拟,而不是“调试”模式。虽然这将让您的模拟运行得更快,但它忽略了许多正常检查,并且只输出了有关模拟中所发生的事情的最小信息。由于所有这些原因,强烈建议只在“释放”模式下运行完全完成后的模拟。

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

在调试模式下运行模拟时,您应该会看到更多的日志信息,这些信息解释了模拟过程中发生了什么。例如,日志输出可能如下所示:

代码语言:javascript
复制
** 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模块的参数https://github.com/sommer/veins/blob/veins-5.1/src/veins/modules/phy/PhyLayer80211p.ned#L43(参见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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70121308

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档