如何解决RSU 和车辆之间的重复通信
我在使用 VEINS 时遇到了一些麻烦。我想模拟 RSU 和 Vehicle 之间的通信。
在模拟开始时,RSU 向所有车辆广播 Msginit
消息,之后车辆也向 RSU 广播 Metrics
消息。
但是 RSU 收不到 Metrics
消息,我不知道原因,有人可以帮助我吗?这是我的代码(我使用的是 omnet 5.6.2、相扑 1.8.0 和静脉 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;
}
}
提前致谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。