void TraCIDemo11p::onData(WaveShortMessage* wsm) {
if (mobility->getRoadId()[0] != ':') traciVehicle->changeRoute(wsm->getWsmData(), 9999);
}
The above code is getting called when the vehicle receives a message to change its route when an accident happens.
mobility->getRoadId()
gives the lane ID but what does getRoadId()[0]
mean?
As I know getRoadId()[0]
gives either 1 or :
Note: I am using omnet 5.0, sumo-0.25.0 and veins-4.4. (TraCIDemo11p.cc)
For a string of characters, the [0]
returns the character at index 0
, that is, the first character. In this case, it returns the first character of the road identifier.
In SUMO, the section of roads that is part of an intersection (called “internal edge”) is typically assigned a name starting with :
, so checking if the current road ID starts with :
is a quick hack to make sure we’re not trying to change a vehicle’s route while it is driving on an intersection.