1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2017-2018 German Aerospace Center (DLR) and others.
4 // TraaS module
5 // Copyright (C) 2016-2017 Dresden University of Technology
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 // SPDX-License-Identifier: EPL-2.0
11 /****************************************************************************/
12 /// @file    Trafficlight.java
13 /// @author  Mario Krumnow
14 /// @author  Evamarie Wiessner
15 /// @date    2016
16 /// @version $Id$
17 ///
18 //
19 /****************************************************************************/
20 package de.tudresden.sumo.cmd;
21 import de.tudresden.sumo.config.Constants;
22 import de.tudresden.sumo.util.SumoCommand;
23 import de.tudresden.ws.container.SumoTLSProgram;
24 
25 /**
26  *
27  * @author Mario Krumnow
28  * @author Evamarie Wiessner
29  *
30  */
31 
32 
33 public class Trafficlight {
34 
35 	//getter methods
36 
37 	/**
38 	 * Returns the complete traffic light program.
39 	 *
40 	 * @param tlsID a string identifying the traffic light
41 	 * @return program definition
42 	 */
43 
getCompleteRedYellowGreenDefinition(String tlsID)44 	public static SumoCommand getCompleteRedYellowGreenDefinition(String tlsID){
45 		return new SumoCommand(Constants.CMD_GET_TL_VARIABLE, Constants.TL_COMPLETE_DEFINITION_RYG, tlsID, Constants.RESPONSE_GET_TL_VARIABLE, Constants.TYPE_COMPOUND);
46 	}
47 
48 
49 	/**
50 	 * Returns the number of all traffic lights in the network.
51 	 * @return number of traffic lights
52 	 */
53 
getIDCount()54 	public static SumoCommand getIDCount(){
55 		return new SumoCommand(Constants.CMD_GET_TL_VARIABLE, Constants.ID_COUNT, "", Constants.RESPONSE_GET_TL_VARIABLE, Constants.TYPE_INTEGER);
56 	}
57 
58 	/**
59 	 * getPhaseDuration
60 	 * @param tlsID a string identifying the traffic light
61 	 * @return phase duration
62 	 */
63 
getPhaseDuration(String tlsID)64 	public static SumoCommand getPhaseDuration(String tlsID){
65 		return new SumoCommand(Constants.CMD_GET_TL_VARIABLE, Constants.TL_PHASE_DURATION, tlsID, Constants.RESPONSE_GET_TL_VARIABLE, Constants.TYPE_DOUBLE);
66 	}
67 
68 	/**
69 	 * Returns the list of lanes which are controlled by the named traffic light.
70 	 *
71 	 * @param tlsID a string identifying the traffic light
72 	 * @return list of controlled lanes
73 	 */
74 
75 
getControlledLanes(String tlsID)76 	public static SumoCommand getControlledLanes(String tlsID){
77 		return new SumoCommand(Constants.CMD_GET_TL_VARIABLE, Constants.TL_CONTROLLED_LANES, tlsID, Constants.RESPONSE_GET_TL_VARIABLE, Constants.TYPE_STRINGLIST);
78 	}
79 
80 	/**
81 	 * Returns the links controlled by the traffic light, sorted by the signal index and described by giving the incoming, outgoing, and via lane.
82 	 *
83 	 * @param tlsID a string identifying the traffic light
84 	 * @return list of controlled links
85 	 */
86 
getControlledLinks(String tlsID)87 	public static SumoCommand getControlledLinks(String tlsID){
88 		return new SumoCommand(Constants.CMD_GET_TL_VARIABLE, Constants.TL_CONTROLLED_LINKS, tlsID, Constants.RESPONSE_GET_TL_VARIABLE, Constants.TYPE_COMPOUND);
89 	}
90 
91 	/**
92 	 * Returns the junctions controlled by the traffic light
93 	 *
94 	 * @param tlsID a string identifying the traffic light
95 	 * @return list of controlled junctions
96 	 */
97 
getControlledJunctions(String tlsID)98 	public static SumoCommand getControlledJunctions(String tlsID){
99 		return new SumoCommand(Constants.CMD_GET_TL_VARIABLE, Constants.TL_CONTROLLED_JUNCTIONS, tlsID, Constants.RESPONSE_GET_TL_VARIABLE, Constants.TYPE_COMPOUND);
100 	}
101 
102 	/**
103 	 * Returns the external state
104 	 *
105 	 * @param tlsID a string identifying the traffic light
106 	 * @return compound of the external state
107 	 */
108 
getExternalState(String tlsID)109 	public static SumoCommand getExternalState(String tlsID){
110 		return new SumoCommand(Constants.CMD_GET_TL_VARIABLE, Constants.TL_EXTERNAL_STATE, tlsID, Constants.RESPONSE_GET_TL_VARIABLE, Constants.TYPE_COMPOUND);
111 	}
112 
113 	/**
114 	 * Returns a list of IDs of all traffic lights within the scenario.
115 	 *
116 	 * @return a list of IDs of all TLS
117 	 */
118 
getIDList()119 	public static SumoCommand getIDList(){
120 		return new SumoCommand(Constants.CMD_GET_TL_VARIABLE, Constants.TRACI_ID_LIST, "", Constants.RESPONSE_GET_TL_VARIABLE, Constants.TYPE_STRINGLIST);
121 	}
122 
123 	/**
124 	 * Returns the assumed time (in ms) at which the TLS changes the phase.
125 	 *
126 	 * @param tlsID a string identifying the traffic light
127 	 * @return absolute time, counting from simulation start, at which TLS may change
128 	 */
129 
getNextSwitch(String tlsID)130 	public static SumoCommand getNextSwitch(String tlsID){
131 		return new SumoCommand(Constants.CMD_GET_TL_VARIABLE, Constants.TL_NEXT_SWITCH, tlsID, Constants.RESPONSE_GET_TL_VARIABLE, Constants.TYPE_DOUBLE);
132 	}
133 
134 	/**
135 	 * Returns the chosen parameter
136 	 *
137 	 *  @param tlsID a string identifying the traffic light
138 	 *  @param param a string identifying the parameter
139 	 *
140 	 * @return the specific parameter
141 	 */
142 
getParameter(String tlsID, String param)143 	public static SumoCommand getParameter(String tlsID, String param){
144 		Object[] array = new Object[]{param};
145 		return new SumoCommand(Constants.CMD_GET_TL_VARIABLE, Constants.VAR_PARAMETER, tlsID, array, Constants.RESPONSE_GET_TL_VARIABLE, Constants.TYPE_STRING);
146 	}
147 
148 
149 	/**
150 	 * Sets the chosen parameter
151 	 *
152 	 *  @param vehID a string identifying the vehicle
153 	 *  @param param a string identifying the parameter
154 	 *  @param value a string identifying the new value
155 	 *
156 	 * @return SumoCommand
157 	 */
158 
setParameter(String tlsID, String param, String value)159 	public static SumoCommand setParameter(String tlsID, String param, String value){
160 		Object[] array = new Object[]{param, value};
161 		return new SumoCommand(Constants.CMD_SET_TL_VARIABLE, Constants.VAR_PARAMETER, tlsID, array);
162 	}
163 
164 	/**
165 	 * Returns the index of the current phase in the current program.
166 	 *
167 	 * @param tlsID a string identifying the traffic light
168 	 * @return index of the current phase
169 	 */
170 
getPhase(String tlsID)171 	public static SumoCommand getPhase(String tlsID){
172 		return new SumoCommand(Constants.CMD_GET_TL_VARIABLE, Constants.TL_CURRENT_PHASE, tlsID, Constants.RESPONSE_GET_TL_VARIABLE, Constants.TYPE_INTEGER);
173 	}
174 
175 	/**
176 	 * Returns the name of the current phase in the current program.
177 	 *
178 	 * @param tlsID a string identifying the traffic light
179 	 * @return name of the current phase
180 	 */
181 
getPhaseName(String tlsID)182 	public static SumoCommand getPhaseName(String tlsID){
183 		return new SumoCommand(Constants.CMD_GET_TL_VARIABLE, Constants.VAR_NAME, tlsID, Constants.RESPONSE_GET_TL_VARIABLE, Constants.TYPE_STRING);
184 	}
185 
186 	/**
187 	 * Returns the id of the current program.
188 	 *
189 	 * @param tlsID a string identifying the traffic light
190 	 * @return index of the current program
191 	 */
192 
getProgram(String tlsID)193 	public static SumoCommand getProgram(String tlsID){
194 		return new SumoCommand(Constants.CMD_GET_TL_VARIABLE, Constants.TL_CURRENT_PROGRAM, tlsID, Constants.RESPONSE_GET_TL_VARIABLE, Constants.TYPE_STRING);
195 	}
196 
197 	/**
198 	 * Returns the named tl's state as a tuple of light definitions from rRgGyYoO, for red, green, yellow, off, where lower case letters mean that the stream has to decelerate.
199 	 *
200 	 * @param tlsID a string identifying the traffic light
201 	 * @return SumoCommand
202 	 */
203 
getRedYellowGreenState(String tlsID)204 	public static SumoCommand getRedYellowGreenState(String tlsID){
205 		return new SumoCommand(Constants.CMD_GET_TL_VARIABLE, Constants.TL_RED_YELLOW_GREEN_STATE, tlsID, Constants.RESPONSE_GET_TL_VARIABLE, Constants.TYPE_STRING);
206 	}
207 
208 	//setter methods
209 
210 	/**
211 	 * Set the complete traffic light program.
212 	 *
213 	 * @param tlsID a string identifying the traffic light
214 	 * @param tls complete program definition
215 	 * @return SumoCommand
216 	 */
217 
setCompleteRedYellowGreenDefinition(String tlsID, SumoTLSProgram tls)218 	public static SumoCommand setCompleteRedYellowGreenDefinition(String tlsID, SumoTLSProgram tls){
219 		return new SumoCommand(Constants.CMD_SET_TL_VARIABLE, Constants.TL_COMPLETE_PROGRAM_RYG, tlsID, tls);
220 	}
221 
222 	/**
223 	 * Set the index of the current phase in the current program.
224 	 *
225 	 * @param tlsID a string identifying the traffic light
226 	 * @param index an integer identifying the phase (it must be between 0 and the number of phases known to the current program of the tls - 1)
227 	 * @return SumoCommand
228 	 */
229 
setPhase(String tlsID, int index)230 	public static SumoCommand setPhase(String tlsID, int index){
231 
232 		return new SumoCommand(Constants.CMD_SET_TL_VARIABLE, Constants.TL_PHASE_INDEX, tlsID, index);
233 	}
234 
235 	/**
236 	 * Set the name of the current phase in the current program.
237 	 *
238 	 * @param tlsID a string identifying the traffic light
239 	 * @param name a string with the phase name
240 	 * @return SumoCommand
241 	 */
242 
setPhaseName(String tlsID, String name)243 	public static SumoCommand setPhaseName(String tlsID, String name){
244 
245 		return new SumoCommand(Constants.CMD_SET_TL_VARIABLE, Constants.VAR_NAME, tlsID, name);
246 	}
247 
248 	/**
249 	 * Set the duration of the currently active phase (in s?).
250 	 *
251 	 * @param tlsID a string identifying the traffic light
252 	 * @param phaseDuration remaining duration of the current phase
253 	 * @return SumoCommand
254 	 */
255 
setPhaseDuration(String tlsID, double phaseDuration)256 	public static SumoCommand setPhaseDuration(String tlsID, double phaseDuration){
257 
258 		return new SumoCommand(Constants.CMD_SET_TL_VARIABLE, Constants.TL_PHASE_DURATION, tlsID, phaseDuration);
259 	}
260 
261 	/**
262 	 * Set the id of the current program.
263 	 *
264 	 * @param tlsID a string identifying the traffic light
265 	 * @param programID a string identifying the program
266 	 * @return SumoCommand
267 	 */
268 
setProgram(String tlsID, String programID)269 	public static SumoCommand setProgram(String tlsID, String programID){
270 		return new SumoCommand(Constants.CMD_SET_TL_VARIABLE, Constants.TL_PROGRAM, tlsID, programID);
271 	}
272 
273 	/**
274 	 * Set the named tl's state as a tuple of light definitions.
275 	 *
276 	 * @param tlsID a string identifying the traffic light
277 	 * @param state as a tuple of light definitions from rRgGyYoO, for red, green, yellow, off, where lower case letters mean that the stream has to decelerate
278 	 * @return SumoCommand
279 	 */
280 
setRedYellowGreenState(String tlsID, String state)281 	public static SumoCommand setRedYellowGreenState(String tlsID, String state){
282 		return new SumoCommand(Constants.CMD_SET_TL_VARIABLE, Constants.TL_RED_YELLOW_GREEN_STATE, tlsID, state);
283 	}
284 
285 }
286