静脉框架中的通信 RSU/OBU
Communication RSU/OBU in veins framework
我需要在 RSU 和 OBU 之间实现通信(OBU 向 RSU 发送消息,RSU 进行一些检查然后它会回答 OBU),为此我在两个中实现了 handleMessage 函数。 cc 文件(一个用于 OBU,另一个用于 RSU),但是当我 运行 它时,目前 OBU 不向 RSU 发送消息,只有 OBU 接收消息(与 RSU 相同)。我的问题是如何发送消息让同区域的RSU收到消息?并且没有其他 OBU 收到消息?我在这两个文件中也实现了onWSM函数,但是没有运行,那么使用onWSM函数呢?
#include <veins/modules/application/traci/OBU.h>
#include "veins/modules/application/traci/ReqObu_m.h"
#include "veins/modules/application/traci/TraCIDemo11pMessage_m.h"
#include "veins/modules/application/traci/MyVeinsApp.h"
using namespace OBU;
using namespace omnetpp;
Define_Module(OBU::OBUMessage);
using namespace veins;
Define_Module(veins::MyVeinsApp);
void OBU::OBUMessage::initialize(int stage)
{
DemoBaseApplLayer::initialize(stage);
EV << "on est dans la fonction initilize_obu:\n";
char msgName[30];
sprintf(msgName, "Req_depuis_lOBU_index_%d", findHost()->getIndex());
ReqObu * req= new ReqObu(msgName);
findHost()->getDisplayString().setTagArg("i", 1, "green");
EV << "message forme :"<< req->getName()<< "\n";
if(findHost()->getIndex()==0)
{
req->setDestination(1);
} else req->setDestination(0);
scheduleAt(25.2, req);
}
void MyVeinsApp::onWSM(BaseFrame1609_4* frame)
{
// Your application has received a data message from another car or RSU
// code for handling the message goes here, see TraciDemo11p.cc for examples
veins::ReqObu* wsm = check_and_cast<veins::ReqObu*>(frame);
findHost()->getDisplayString().setTagArg("i", 1, "red");
EV << "we are in onWSM____OBU\n";
scheduleAt(simTime() + 2 + uniform(0.01, 0.2), wsm);
}
void OBU::OBUMessage::handleMessage(cMessage *msg )
{
EV << "we are in handleMessage_OBU:\n";
ReqObu *ttmsg =dynamic_cast<ReqObu*>(msg);
if(ttmsg->getDestination()!=findHost()->getIndex())
{ EV << "I am : " << findHost()->getIndex()<< " destination : "<< ttmsg->getDestination()<<" and the msg :"<< ttmsg->getName()<<"\n";
}
}
RSU.cc :
#include <veins/modules/application/traci/FN.h>
#include "veins/modules/application/traci/ReqObu_m.h"
#include "veins/modules/application/traci/TraCIDemo11pMessage_m.h"
using namespace FN;
using namespace omnetpp;
Define_Module(FN::FogMessage);
void FN::FogMessage::initialize(int stage)
{
DemoBaseApplLayer::initialize(stage);
EV << "on est dans la fonction initilize_fn:\n";
char msgName[30];
sprintf(msgName, "Req_depuis_RSU_index_%d", findHost()->getIndex());
veins::ReqObu * req= new veins::ReqObu(msgName);
EV << "RSU____ :"<< req->getName()<< "\n";
if(findHost()->getIndex()==0)
{
req->setDestination(1);
} else req->setDestination(0);
scheduleAt(35.2, req);
}
void FN::FogMessage::handleMessage(cMessage *msg)
{
EV << "on est dans la fonction handleMessage_RSU:\n";
veins::ReqObu *ttmsg =check_and_cast<veins::ReqObu*>(msg);
EV << "RSU : destination : " << ttmsg->getDestination()<< " and le msg :"<< ttmsg->getName()<<"\n";
}
void FN::FogMessage::onWSM(veins::BaseFrame1609_4* msg)
{
veins::ReqObu *ttmsg =check_and_cast<veins::ReqObu*>(msg);
EV << "on est dans la fonction onWSM____RSU:\n";
}
ReqOBU.msg :
cplusplus {{
#include "veins/modules/messages/BaseFrame1609_4_m.h"
}}
namespace veins;
class BaseFrame1609_4;
message Cert
{
int pIDfN=-1;
long tmpFN =-1;
int pIDOBU=-1;
}
message BlockchainMsg
{
int pFN;
long tmpFN;
int pOBU;
long tmpOBU;
}
message ReqObu extends BaseFrame1609_4
{
int pID=-1;
long tMP=-1 ;
int destination=-1;
}
方法sendDown( ) 和sendDelayedDown( ) 用于将消息发送到omnet++ 中的其他节点。可能是您正在调用 handleSelfMessage()。在此处包含代码可能会有所帮助。
更新:
我猜对了。没有 handleSelfMessage() 定义。 scheduleAt() 调用 handleSelfMessage() 但它不存在。
如果我是正确的请点赞
我需要在 RSU 和 OBU 之间实现通信(OBU 向 RSU 发送消息,RSU 进行一些检查然后它会回答 OBU),为此我在两个中实现了 handleMessage 函数。 cc 文件(一个用于 OBU,另一个用于 RSU),但是当我 运行 它时,目前 OBU 不向 RSU 发送消息,只有 OBU 接收消息(与 RSU 相同)。我的问题是如何发送消息让同区域的RSU收到消息?并且没有其他 OBU 收到消息?我在这两个文件中也实现了onWSM函数,但是没有运行,那么使用onWSM函数呢?
#include <veins/modules/application/traci/OBU.h>
#include "veins/modules/application/traci/ReqObu_m.h"
#include "veins/modules/application/traci/TraCIDemo11pMessage_m.h"
#include "veins/modules/application/traci/MyVeinsApp.h"
using namespace OBU;
using namespace omnetpp;
Define_Module(OBU::OBUMessage);
using namespace veins;
Define_Module(veins::MyVeinsApp);
void OBU::OBUMessage::initialize(int stage)
{
DemoBaseApplLayer::initialize(stage);
EV << "on est dans la fonction initilize_obu:\n";
char msgName[30];
sprintf(msgName, "Req_depuis_lOBU_index_%d", findHost()->getIndex());
ReqObu * req= new ReqObu(msgName);
findHost()->getDisplayString().setTagArg("i", 1, "green");
EV << "message forme :"<< req->getName()<< "\n";
if(findHost()->getIndex()==0)
{
req->setDestination(1);
} else req->setDestination(0);
scheduleAt(25.2, req);
}
void MyVeinsApp::onWSM(BaseFrame1609_4* frame)
{
// Your application has received a data message from another car or RSU
// code for handling the message goes here, see TraciDemo11p.cc for examples
veins::ReqObu* wsm = check_and_cast<veins::ReqObu*>(frame);
findHost()->getDisplayString().setTagArg("i", 1, "red");
EV << "we are in onWSM____OBU\n";
scheduleAt(simTime() + 2 + uniform(0.01, 0.2), wsm);
}
void OBU::OBUMessage::handleMessage(cMessage *msg )
{
EV << "we are in handleMessage_OBU:\n";
ReqObu *ttmsg =dynamic_cast<ReqObu*>(msg);
if(ttmsg->getDestination()!=findHost()->getIndex())
{ EV << "I am : " << findHost()->getIndex()<< " destination : "<< ttmsg->getDestination()<<" and the msg :"<< ttmsg->getName()<<"\n";
}
}
RSU.cc :
#include <veins/modules/application/traci/FN.h>
#include "veins/modules/application/traci/ReqObu_m.h"
#include "veins/modules/application/traci/TraCIDemo11pMessage_m.h"
using namespace FN;
using namespace omnetpp;
Define_Module(FN::FogMessage);
void FN::FogMessage::initialize(int stage)
{
DemoBaseApplLayer::initialize(stage);
EV << "on est dans la fonction initilize_fn:\n";
char msgName[30];
sprintf(msgName, "Req_depuis_RSU_index_%d", findHost()->getIndex());
veins::ReqObu * req= new veins::ReqObu(msgName);
EV << "RSU____ :"<< req->getName()<< "\n";
if(findHost()->getIndex()==0)
{
req->setDestination(1);
} else req->setDestination(0);
scheduleAt(35.2, req);
}
void FN::FogMessage::handleMessage(cMessage *msg)
{
EV << "on est dans la fonction handleMessage_RSU:\n";
veins::ReqObu *ttmsg =check_and_cast<veins::ReqObu*>(msg);
EV << "RSU : destination : " << ttmsg->getDestination()<< " and le msg :"<< ttmsg->getName()<<"\n";
}
void FN::FogMessage::onWSM(veins::BaseFrame1609_4* msg)
{
veins::ReqObu *ttmsg =check_and_cast<veins::ReqObu*>(msg);
EV << "on est dans la fonction onWSM____RSU:\n";
}
ReqOBU.msg :
cplusplus {{
#include "veins/modules/messages/BaseFrame1609_4_m.h"
}}
namespace veins;
class BaseFrame1609_4;
message Cert
{
int pIDfN=-1;
long tmpFN =-1;
int pIDOBU=-1;
}
message BlockchainMsg
{
int pFN;
long tmpFN;
int pOBU;
long tmpOBU;
}
message ReqObu extends BaseFrame1609_4
{
int pID=-1;
long tMP=-1 ;
int destination=-1;
}
方法sendDown( ) 和sendDelayedDown( ) 用于将消息发送到omnet++ 中的其他节点。可能是您正在调用 handleSelfMessage()。在此处包含代码可能会有所帮助。
更新: 我猜对了。没有 handleSelfMessage() 定义。 scheduleAt() 调用 handleSelfMessage() 但它不存在。
如果我是正确的请点赞