I am doing a simulation which when an emergency vehicle is approaching to the intersection the state of traffic light should be changed it phase to green. What I try to do is, EV, will send message to the RSU sending it laneId, then the RSU will trigger traffic light through Traci function. However when the simulation reach the part when it need to trigger the Traci function to change traffic light phase, the simulation said "Simulation has encounter a problem, finished with error". Here is the code for the RSU :-
trafficlightrsu.cc files :
'''
#include "trafficlightrsu.h"
#include "veins/modules/application/traci/MyVeinsApp.h"
#include "veins/modules/application/traci/TraCIDemo11pMessage_m.h"
using namespace veins;
Define_Module(veins::trafficlightrsu);
void trafficlightrsu::onWSA(DemoServiceAdvertisment* wsa)
{
// if this RSU receives a WSA for service 42, it will tune to the channel
if (wsa->getPsid() == 42) {
mac->changeServiceChannel(static_cast<Channel>(wsa->getTargetChannel()));
}
}
void trafficlightrsu::onWSM(BaseFrame1609_4* frame)
{
TraCIDemo11pMessage* wsm = check_and_cast<TraCIDemo11pMessage*>(frame);
std:: string laneId = wsm->getDemoData();
if(laneId == "14617022#0_0"){
manager->getCommandInterface()->trafficlight("cluster_144084639_252529291_255540900_6503456532").setPhaseIndex(2);
}
}
'''
trafficlightrsu.h file :
'''
#pragma once
#include "veins/modules/application/ieee80211p/DemoBaseApplLayer.h"
#include "veins/modules/mobility/traci/TraCIScenarioManager.h"
#include "veins/modules/mobility/traci/TraCICommandInterface.h"
using namespace omnetpp;
namespace veins {
class VEINS_API trafficlightrsu : public DemoBaseApplLayer {
protected:
void onWSM(BaseFrame1609_4* wsm) override;
void onWSA(DemoServiceAdvertisment* wsa) override;
//fix by adding this part
TraCIMobility* mobility;
TraCICommandInterface* traci;
TraCICommandInterface::Vehicle* traciVehicle;
TraCIScenarioManager* manager;
std::string trafficLightId;
private:
void setTraCI();
};
}
'''