Search code examples
veins

How to write a traffic light "get program" and "get phase" functions in traci interface?


Checking in the TraCICommandInterface there are only two function for the traffic lights. The first one is setProgram and the other one is setPhaseIndex how can I write the get functions for them?


Solution

  • In TraCICommandInterface.h: insert the following functions definitions under traffic light methods:

    // Trafficlight methods
    std::string getProgram();
    int getPhaseIndex();
    

    In TraCICommandInterface.cc: insert the following functions declarations:

    std::string TraCICommandInterface::Trafficlight::getProgram() {
        return traci->genericGetString(CMD_GET_TL_VARIABLE, trafficLightId, TL_CURRENT_PROGRAM,RESPONSE_GET_TL_VARIABLE);
    }
    

    and

    int TraCICommandInterface::Trafficlight::getPhaseIndex() {
        return traci->genericGetInt(CMD_GET_TL_VARIABLE, trafficLightId, TL_CURRENT_PHASE,RESPONSE_GET_TL_VARIABLE);
    }