void UpdateVehicles() { try { conn.do_timestep(); foreach (GameObject v in vehicles) { // get new position of the car SumoPosition2D newPosition = (SumoPosition2D)conn.do_job_get(de.tudresden.sumo.cmd.Vehicle.getPosition(v.GetComponent <VehicleContainer>().getId())); // convert into vector3 Vector3 newPositonV3 = new Vector3((float)newPosition.x, CarHeight, (float)newPosition.y); // update the position of car v.transform.position = newPositonV3; } } catch (Exception e) { Debug.Log(" Exception updating vehicles - " + e.Message + " " + e.StackTrace); if (conn.isClosed()) { conn.close(); vehiclesCreationSuccess = false; Debug.Log(" Application quit as connection to SUMO was terminated! "); Application.Quit(); return; } } }
//public void Update() //{ // Readcars(); //} void ReadCars() { Debug.Log("LLAMANDO"); carList.Clear(); /*int simtime = (int)*/ int simtime = ((Integer)(conn.do_job_get(Simulation.getCurrentTime()))).intValue(); carIds = (SumoStringList)conn.do_job_get(Vehicle.getIDList()); foreach (string id in carIds) { Debug.Log("id:" + id); position = (SumoPosition2D)conn.do_job_get(Vehicle.getPosition(id)); car = new Auto(position.x, position.y, Convert.ToInt32(id)); speed = ((java.lang.Double)conn.do_job_get(Vehicle.getSpeed(id))).doubleValue(); angle = ((java.lang.Double)conn.do_job_get(Vehicle.getAngle(id))).doubleValue(); car.setSpeed(speed); car.setAngle(angle); carList.Add(car); } //printCars(cars); conn.do_timestep(); }
public virtual SumoPosition2D GetPosition2D(System.Object obj) { SumoPosition2D output = new SumoPosition2D(0, 0); try { if (obj.GetType().Equals(typeof(SumoPosition2D))) { output = (SumoPosition2D)obj; } } catch (Exception ex) { MonoBehaviour.print(ex.GetBaseException()); } return(output); }
bool ReadVehicles() { try { RemoveVehicles(); SumoStringList carIds = (SumoStringList)conn.do_job_get(de.tudresden.sumo.cmd.Vehicle.getIDList()); foreach (string id in carIds) { conn.do_timestep(); // create new car GameObject newVehicle = Instantiate(carPrefab); // assign id newVehicle.GetComponent <VehicleContainer>().setId(id); // get position SumoPosition2D position = (SumoPosition2D)conn.do_job_get(de.tudresden.sumo.cmd.Vehicle.getPosition(id)); // assign position newVehicle.transform.position = new Vector3((float)position.x, CarHeight, (float)position.y); // get speed double speed = double.Parse(conn.do_job_get(de.tudresden.sumo.cmd.Vehicle.getSpeed(id)).ToString()); // assign speed newVehicle.GetComponent <VehicleContainer>().setSpeed(speed); if (id.Contains("ev")) { // assign red color to EV newVehicle.GetComponent <Renderer>().material.color = Color.red; } newVehicle.transform.parent = vehicleParent.transform; // store vehicle vehicles.Add(newVehicle); } } catch (Exception e) { Debug.Log("Read Vehicles Exception : " + e.Message + " -- " + e.StackTrace); return(false); } return(true); }
void ReadCoches() { Debug.Log("LLAMANDO"); coches.Clear(); int simtime = (int)conn.do_job_get(Simulation.getCurrentTime()); carIds = (SumoStringList)conn.do_job_get(Vehicle.getIDList()); foreach (string id in carIds) { Debug.Log(id + " "); position = (SumoPosition2D)conn.do_job_get(Vehicle.getPosition(id)); coche = new Auto(position.x, position.y, Convert.ToInt32(id)); speed = (Double)conn.do_job_get(Vehicle.getSpeed(id)); coche.setSpeed(speed); coches.Add(coche); } pintarCoches(coches); conn.do_timestep(); }
private void Add_variable(Object input) { if (input.GetType().Equals(typeof(int))) { this.cmd.Content().WriteInt((int)input); } else if (input.GetType().Equals(typeof(string))) { this.cmd.Content().WriteStringASCII((string)input); } else if (input.GetType().Equals(typeof(Double))) { this.cmd.Content().WriteDouble((Double)input); } else if (input.GetType().Equals(typeof(Byte))) { this.cmd.Content().WriteByte((Byte)input); } else if (input.GetType().Equals(typeof(bool))) { bool b = (bool)input; cmd.Content().WriteUnsignedByte(b ? 1 : 0); } else if (input.GetType().Equals(typeof(SumoColor))) { SumoColor sc = (SumoColor)input; this.cmd.Content().WriteByte(sc.r); this.cmd.Content().WriteByte(sc.g); this.cmd.Content().WriteByte(sc.b); this.cmd.Content().WriteByte(sc.a); } else if (input.GetType().Equals(typeof(SumoGeometry))) { SumoGeometry sg = (SumoGeometry)input; cmd.Content().WriteUnsignedByte(sg.coords.Count()); foreach (SumoPosition2D pos in sg.coords) { cmd.Content().WriteDouble(pos.x); cmd.Content().WriteDouble(pos.y); } } else if (input.GetType().Equals(typeof(SumoPosition2D))) { SumoPosition2D pos = (SumoPosition2D)input; cmd.Content().WriteDouble(pos.x); cmd.Content().WriteDouble(pos.y); } else if (input.GetType().Equals(typeof(SumoTLSPhase))) { SumoTLSPhase stp = (SumoTLSPhase)input; this.cmd.Content().WriteUnsignedByte(Constants.TYPE_INTEGER); cmd.Content().WriteInt(stp.duration); this.cmd.Content().WriteUnsignedByte(Constants.TYPE_INTEGER); cmd.Content().WriteInt(stp.duration1); this.cmd.Content().WriteUnsignedByte(Constants.TYPE_INTEGER); cmd.Content().WriteInt(stp.duration2); this.cmd.Content().WriteUnsignedByte(Constants.TYPE_STRING); cmd.Content().WriteStringASCII(stp.phasedef); } else if (input.GetType().Equals(typeof(SumoStringList))) { SumoStringList sl = (SumoStringList)input; cmd.Content().WriteInt(sl.getList().Count()); foreach (string s in sl.getList()) { cmd.Content().WriteStringASCII(s); } } }
public /*synchronized*/ Object do_job_get(SumoCommand sc) { Object localObject1 = null; ResponseContainer localResponseContainer = queryAndVerifySingle(sc.cmd); Command localCommand = localResponseContainer.getResponse(); verifyGetVarResponse(localCommand, sc.response, sc.input2, sc.input3); verify("", Convert.ToInt32(sc.output_type), Convert.ToInt32(localCommand.Content().readUnsignedByte())); if (sc.output_type == 9) { localObject1 = Convert.ToInt32(localCommand.Content().readInt()); } else if (sc.output_type == 11) { localObject1 = Convert.ToDouble(localCommand.Content().readDouble()); } else if (sc.output_type == 12) { localObject1 = localCommand.Content().readStringUTF8(); } else { double d1; double d3; if (sc.output_type == 1) { d1 = localCommand.Content().readDouble(); d3 = localCommand.Content().readDouble(); localObject1 = new SumoPosition2D(d1, d3); } else { double d6; if (sc.output_type == 3) { d1 = localCommand.Content().readDouble(); d3 = localCommand.Content().readDouble(); d6 = localCommand.Content().readDouble(); localObject1 = new SumoPosition3D(d1, d3, d6); } else if (sc.output_type == 14) { SumoStringList localSumoStringList = new SumoStringList(); int k = localCommand.Content().readInt(); for (int i1 = 0; i1 < k; i1++) { localSumoStringList.add(localCommand.Content().readStringASCII()); } localObject1 = localSumoStringList; } else if (sc.output_type == 5) { double d2 = localCommand.Content().readDouble(); double d4 = localCommand.Content().readDouble(); d6 = localCommand.Content().readDouble(); double d8 = localCommand.Content().readDouble(); localObject1 = new SumoBoundingBox(d2, d4, d6, d8); } else { Object localObject3; if (sc.input2 == 181) { int i = localCommand.Content().readByte(); localObject3 = new SumoStopFlags((byte)i); localObject1 = localObject3; if (sc.info.Equals("isStopped")) { localObject1 = Convert.ToBoolean(((SumoStopFlags)localObject3).stopped); } if (sc.info.Equals("isStoppedTriggered")) { localObject1 = Convert.ToBoolean(((SumoStopFlags)localObject3).triggered); } if (sc.info.Equals("isAtContainerStop")) { localObject1 = Convert.ToBoolean(((SumoStopFlags)localObject3).isContainerStop); } if (sc.info.Equals("isStoppedParking")) { localObject1 = Convert.ToBoolean(((SumoStopFlags)localObject3).getID() == 12); } if (sc.info.Equals("isAtBusStop")) { localObject1 = Convert.ToBoolean(((SumoStopFlags)localObject3).isBusStop); } } else { int i3; if (sc.output_type == 15) { Object localObject2 = null; int i2; int i7; int i8; Object localObject4; if (sc.input2 == 39) { localObject3 = new SumoLinkList(); localCommand.Content().readUnsignedByte(); localCommand.Content().readInt(); i2 = localCommand.Content().readInt(); localObject2 = new StringList[i2]; for (int i4 = 0; i4 < i2; i4++) { localCommand.Content().readUnsignedByte(); i7 = localCommand.Content().readInt(); for (i8 = 0; i8 < i7; i8++) { localCommand.Content().readUnsignedByte(); localCommand.Content().readInt(); String str4 = localCommand.Content().readStringASCII(); localObject4 = localCommand.Content().readStringASCII(); String str5 = localCommand.Content().readStringASCII(); ((SumoLinkList)localObject3).add(new SumoLink(str4, (String)localObject4, str5)); } } localObject1 = localObject3; } else { int m; int i9; int i10; if (sc.input2 == 43) { localCommand.Content().readUnsignedByte(); localCommand.Content().readInt(); m = localCommand.Content().readInt(); for (i2 = 0; i2 < m; i2++) { localCommand.Content().readUnsignedByte(); String str1 = localCommand.Content().readStringASCII(); localCommand.Content().readUnsignedByte(); i7 = localCommand.Content().readInt(); localCommand.Content().readUnsignedByte(); i8 = localCommand.Content().readInt(); localCommand.Content().readUnsignedByte(); i9 = localCommand.Content().readInt(); localObject4 = new SumoTLSLogic(str1, i7, i8, i9); localCommand.Content().readUnsignedByte(); i10 = localCommand.Content().readInt(); for (int i11 = 0; i11 < i10; i11++) { localCommand.Content().readUnsignedByte(); int i12 = localCommand.Content().readInt(); localCommand.Content().readUnsignedByte(); int i13 = localCommand.Content().readInt(); localCommand.Content().readUnsignedByte(); int i14 = localCommand.Content().readInt(); localCommand.Content().readUnsignedByte(); String str8 = localCommand.Content().readStringASCII(); ((SumoTLSLogic)localObject4).add(new SumoTLSPhase(i12, i13, i14, str8)); } localObject1 = localObject4; } } else { int i5; if (sc.input2 == 51) { localCommand.Content().readUnsignedByte(); localCommand.Content().readInt(); m = localCommand.Content().readInt(); SumoLinkList localSumoLinkList = new SumoLinkList(); for (i5 = 0; i5 < m; i5++) { localCommand.Content().readUnsignedByte(); String str2 = localCommand.Content().readStringASCII(); localCommand.Content().readUnsignedByte(); String str3 = localCommand.Content().readStringASCII(); localCommand.Content().readUnsignedByte(); i9 = (byte)localCommand.Content().readUnsignedByte(); localCommand.Content().readUnsignedByte(); byte b = (byte)localCommand.Content().readUnsignedByte(); localCommand.Content().readUnsignedByte(); i10 = (byte)localCommand.Content().readUnsignedByte(); localCommand.Content().readUnsignedByte(); String str6 = localCommand.Content().readStringASCII(); localCommand.Content().readUnsignedByte(); String str7 = localCommand.Content().readStringASCII(); localCommand.Content().readUnsignedByte(); double d9 = localCommand.Content().readDouble(); localSumoLinkList.add(new SumoLink(str2, str3, (byte)i9, b, (byte)i10, d9, str6, str7)); //CUIDADO } localObject1 = localSumoLinkList; } else { m = localCommand.Content().readInt(); Object[] localObject5 = new Object[m]; for (i3 = 0; i3 < m; i3++) { i5 = localCommand.Content().readUnsignedByte(); localObject5[i3] = get_value(i5, localCommand); } localObject1 = localObject5; } } } } else { int j; if (sc.output_type == 6) { j = localCommand.Content().readUnsignedByte(); SumoGeometry localSumoGeometry = new SumoGeometry(); for (i3 = 0; i3 < j; i3++) { double d5 = Convert.ToDouble((Double)get_value(11, localCommand)); double d7 = Convert.ToDouble((Double)get_value(11, localCommand)); localSumoGeometry.add(new SumoPosition2D(d5, d7)); } localObject1 = localSumoGeometry; } else if (sc.output_type == 17) { j = localCommand.Content().readUnsignedByte(); int n = localCommand.Content().readUnsignedByte(); i3 = localCommand.Content().readUnsignedByte(); int i6 = localCommand.Content().readUnsignedByte(); localObject1 = new SumoColor(j, n, i3, i6); } else if (sc.output_type == 7) { localObject1 = Convert.ToInt16(localCommand.Content().readUnsignedByte()); } } } } } } return(localObject1); }
public virtual Object Do_job_get(SumoCommand sc) { lock (this) { Object output = null; ResponseContainer rc = QueryAndVerifySingle(sc.cmd); Command resp = rc.GetResponse(); VerifyGetVarResponse(resp, sc.response, sc.input2, sc.input3); Verify("", sc.output_type, (int)resp.Content().ReadUnsignedByte()); if (sc.output_type == Constants.TYPE_INTEGER) { output = resp.Content().ReadInt(); } else if (sc.output_type == Constants.TYPE_DOUBLE) { output = resp.Content().ReadDouble(); } else if (sc.output_type == Constants.TYPE_STRING) { output = resp.Content().ReadStringUTF8(); } else if (sc.output_type == Constants.POSITION_2D) { double x = resp.Content().ReadDouble(); double y = resp.Content().ReadDouble(); output = new SumoPosition2D(x, y); } else if (sc.output_type == Constants.POSITION_3D) { double x = resp.Content().ReadDouble(); double y = resp.Content().ReadDouble(); double z = resp.Content().ReadDouble(); output = new SumoPosition3D(x, y, z); } else if (sc.output_type == Constants.TYPE_STRINGLIST) { SumoStringList ssl = new SumoStringList(); int laenge = resp.Content().ReadInt(); for (int i = 0; i < laenge; i++) { ssl.Add(resp.Content().ReadStringASCII()); } output = ssl; } else if (sc.output_type == Constants.TYPE_BOUNDINGBOX) { double min_x = resp.Content().ReadDouble(); double min_y = resp.Content().ReadDouble(); double max_x = resp.Content().ReadDouble(); double max_y = resp.Content().ReadDouble(); output = new SumoBoundingBox(min_x, min_y, max_x, max_y); } else if (sc.output_type == Constants.TYPE_COMPOUND) { Object[] obj = null; if (sc.input2 == Constants.TL_CONTROLLED_LINKS) { SumoLinkList sll = new SumoLinkList(); resp.Content().ReadUnsignedByte(); resp.Content().ReadInt(); int laenge = resp.Content().ReadInt(); obj = new StringList[laenge]; for (int i = 0; i < laenge; i++) { resp.Content().ReadUnsignedByte(); int anzahl = resp.Content().ReadInt(); for (int i1 = 0; i1 < anzahl; i1++) { resp.Content().ReadUnsignedByte(); resp.Content().ReadInt(); string from = resp.Content().ReadStringASCII(); string to = resp.Content().ReadStringASCII(); string over = resp.Content().ReadStringASCII(); sll.Add(new SumoLink(from, to, over)); } } output = sll; } else if (sc.input2 == Constants.TL_COMPLETE_DEFINITION_RYG) { resp.Content().ReadUnsignedByte(); resp.Content().ReadInt(); int length = resp.Content().ReadInt(); for (int i = 0; i < length; i++) { resp.Content().ReadUnsignedByte(); string subID = resp.Content().ReadStringASCII(); resp.Content().ReadUnsignedByte(); int type = resp.Content().ReadInt(); resp.Content().ReadUnsignedByte(); int subParameter = resp.Content().ReadInt(); resp.Content().ReadUnsignedByte(); int currentPhaseIndex = resp.Content().ReadInt(); SumoTLSLogic stl = new SumoTLSLogic(subID, type, subParameter, currentPhaseIndex); resp.Content().ReadUnsignedByte(); int nbPhases = resp.Content().ReadInt(); for (int i1 = 0; i1 < nbPhases; i1++) { resp.Content().ReadUnsignedByte(); int duration = resp.Content().ReadInt(); resp.Content().ReadUnsignedByte(); int duration1 = resp.Content().ReadInt(); resp.Content().ReadUnsignedByte(); int duration2 = resp.Content().ReadInt(); resp.Content().ReadUnsignedByte(); string phaseDef = resp.Content().ReadStringASCII(); stl.Add(new SumoTLSPhase(duration, duration1, duration2, phaseDef)); } output = stl; } } else if (sc.input2 == Constants.LANE_LINKS) { resp.Content().ReadUnsignedByte(); resp.Content().ReadInt(); int length = resp.Content().ReadInt(); SumoLinkList links = new SumoLinkList(); for (int i = 0; i < length; i++) { resp.Content().ReadUnsignedByte(); string notInternalLane = resp.Content().ReadStringASCII(); resp.Content().ReadUnsignedByte(); string internalLane = resp.Content().ReadStringASCII(); resp.Content().ReadUnsignedByte(); byte hasPriority = (byte)resp.Content().ReadUnsignedByte(); resp.Content().ReadUnsignedByte(); byte isOpened = (byte)resp.Content().ReadUnsignedByte(); resp.Content().ReadUnsignedByte(); byte hasFoes = (byte)resp.Content().ReadUnsignedByte(); resp.Content().ReadUnsignedByte(); string state = resp.Content().ReadStringASCII(); resp.Content().ReadUnsignedByte(); string direction = resp.Content().ReadStringASCII(); resp.Content().ReadUnsignedByte(); double laneLength = resp.Content().ReadDouble(); links.Add(new SumoLink(notInternalLane, internalLane, hasPriority, isOpened, hasFoes, laneLength, state, direction)); } output = links; } else { int laenge = resp.Content().ReadInt(); obj = new Object[laenge]; for (int i = 0; i < laenge; i++) { int k = resp.Content().ReadUnsignedByte(); obj[i] = this.Get_value(k, resp); } output = obj; } } else if (sc.output_type == Constants.TYPE_POLYGON) { int laenge = resp.Content().ReadUnsignedByte(); SumoGeometry sg = new SumoGeometry(); for (int i = 0; i < laenge; i++) { double x = (Double)this.Get_value(Constants.TYPE_DOUBLE, resp); double y = (Double)this.Get_value(Constants.TYPE_DOUBLE, resp); sg.Add(new SumoPosition2D(x, y)); } output = sg; } else if (sc.output_type == Constants.TYPE_COLOR) { int r = resp.Content().ReadUnsignedByte(); int g = resp.Content().ReadUnsignedByte(); int b = resp.Content().ReadUnsignedByte(); int a = resp.Content().ReadUnsignedByte(); output = new SumoColor(r, g, b, a); } else if (sc.output_type == Constants.TYPE_UBYTE) { output = resp.Content().ReadUnsignedByte(); } return(output); } }