/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fuzzytester;
import it.polito.appeal.traci.ChangeLightsStateQuery;
import it.polito.appeal.traci.ChangeObjectVarQuery;
import it.polito.appeal.traci.Lane;
import it.polito.appeal.traci.LightState;
import it.polito.appeal.traci.Repository;
import it.polito.appeal.traci.SumoTraciConnection;
import it.polito.appeal.traci.TLState;
import it.polito.appeal.traci.TrafficLight;
import java.io.IOException;
import java.util.List;
import java.util.Set;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author DLSV3550
*/
public class NextSimStep extends TimerTask {
public SumoTraciConnection connection;
public NextSimStep(SumoTraciConnection con){
this.connection = con;
}
public NextSimStep(){
this.connection = null;
}
@Override
public void run() {
if(this.connection!=null){
try {
System.out.println("NEXT STEP "+connection.getSimulationData().queryCurrentSimTime().get().toString());
} catch (IOException ex) {
Logger.getLogger(NextSimStep.class.getName()).log(Level.SEVERE, null, ex);
}
try {
connection.nextSimStep();
} catch (IOException ex) {
Logger.getLogger(NextSimStep.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalStateException ex) {
Logger.getLogger(NextSimStep.class.getName()).log(Level.SEVERE, null, ex);
}
Repository<TrafficLight> tlr = this.connection.getTrafficLightRepository();
try {
Set<String> listaIDtl = tlr.getIDs();
for(String s:listaIDtl){
System.out.println("Traffic light "+s);
TrafficLight tl = tlr.getByID(s);
List<Lane> list = tl.getReadControlledLanesQuery().get();
LightState[] ls = new LightState[tl.getReadCurrentStateQuery().get().lightStates.length];
for(int i=0; i<tl.getReadCurrentStateQuery().get().lightStates.length; i++){
ls[i]=LightState.RED;
}
TLState tls = new TLState(ls);
ChangeLightsStateQuery q = tl.getChangeLightsStateQuery();
q.setValue(tls);
q.run();
}
} catch (IOException ex) {
Logger.getLogger(FuzzyTesterView.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}