@@ -93,29 +93,45 @@ def tick(self):
9393
9494 self .current_tick = res ["TICK" ]
9595
96- def generate_trip (self , vehID , origin , destination ):
97- msg = {
98- "TYPE" : "CTRL_generateTrip" ,
99- "vehID" : vehID ,
100- "origin" : origin ,
101- "destination" : destination ,
102- }
96+ def generate_trip (self , vehID , origin = - 1 , destination = - 1 ):
97+ msg = {"TYPE" : "CTRL_generateTrip" , "DATA" : []}
98+ if not isinstance (vehID , list ):
99+ vehID = [vehID ]
100+ if not isinstance (origin , list ):
101+ origin = [origin ] * len (vehID )
102+ if not isinstance (destination , list ):
103+ destination = [destination ] * len (vehID )
104+
105+ assert (
106+ len (vehID ) == len (origin ) == len (destination )
107+ ), "Length of vehID, origin, and destination must be the same"
108+ for vehID , origin , destination in zip (vehID , origin , destination ):
109+ msg ["DATA" ].append (
110+ {"vehID" : vehID , "vehType" : True , "orig" : origin , "dest" : destination }
111+ )
103112
104113 res = self .send_receive_msg (msg , ignore_heartbeats = True )
105114
106115 assert res ["TYPE" ] == "CTRL_generateTrip" , res ["TYPE" ]
107116 assert res ["CODE" ] == "OK" , res ["CODE" ]
117+ return res
108118
109- def query_vehicle (self , vehID , private_veh = False , transform_coords = False ):
110- msg = {
111- "TYPE" : "QUERY_vehicle" ,
112- "ID" : vehID ,
113- "PRV" : private_veh ,
114- "TRAN" : transform_coords ,
115- }
119+ def query_vehicle (self , id = None , private_veh = False , transform_coords = False ):
120+ msg = {"TYPE" : "QUERY_vehicle" }
121+ if id is not None :
122+ msg ["DATA" ] = []
123+ if not isinstance (id , list ):
124+ id = [id ]
125+ if not isinstance (private_veh , list ):
126+ private_veh = [private_veh ] * len (id )
127+ if not isinstance (transform_coords , list ):
128+ transform_coords = [transform_coords ] * len (id )
129+ for veh_id , prv , tran in zip (id , private_veh , transform_coords ):
130+ msg ["DATA" ].append (
131+ {"vehID" : veh_id , "vehType" : prv , "transformCoord" : tran }
132+ )
116133
117134 res = self .send_receive_msg (msg , ignore_heartbeats = True )
118-
119135 assert res ["TYPE" ] == "ANS_vehicle" , res ["TYPE" ]
120136 return res
121137
0 commit comments