我在使用 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;
}
}
提前致谢。