Fleur Rouge
Fleur Rouge

Reputation: 27

Communication RSU/OBU in veins framework

I need to implement a communication between the RSU and the OBU (the OBU sends a message to the RSU and the RSU does some checks then it will answer the OBU), for that I implemented the handleMessage function in the two . cc files (one for the OBU and the other for the RSU), but when I run it, for the moment, the OBU doesn't send the message to the RSUs, only the OBUs receive the message (same for the RSUs). My question is how to send the message so that the RSU of the same region receives the message? and without the other OBUs receiving the message? I have also implemented the onWSM function in the two files but it does not run, in which case the onWSM function is used?


#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;    
}
    

Upvotes: 1

Views: 338

Answers (1)

Pasha M.
Pasha M.

Reputation: 340

The methods sendDown( ) and sendDelayedDown( ) are used to send the messages to other nodes in omnet++. May be you are calling handleSelfMessage( ). Including code here may help.

update: My Guess went right. There is no handleSelfMessage() definition. scheduleAt() invokes handleSelfMessage() and its not there.

upvote if I am correct

Upvotes: 0

Related Questions