SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TraCIAPI.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // C++ TraCI client API implementation
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
10 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include "TraCIAPI.h"
33 #include <utils/common/ToString.h>
34 
35 #ifdef CHECK_MEMORY_LEAKS
36 #include <foreign/nvwa/debug_new.h>
37 #endif // CHECK_MEMORY_LEAKS
38 
39 
40 // ===========================================================================
41 // member definitions
42 // ===========================================================================
43 // ---------------------------------------------------------------------------
44 // TraCIAPI-methods
45 // ---------------------------------------------------------------------------
46 #ifdef _MSC_VER
47 #pragma warning(disable: 4355)
48 #endif
50  : edge(*this), gui(*this), inductionloop(*this),
51  junction(*this), lane(*this), multientryexit(*this), poi(*this),
52  polygon(*this), route(*this), simulation(*this), trafficlights(*this),
53  vehicletype(*this),
54  mySocket(0) {}
55 #ifdef _MSC_VER
56 #pragma warning(default: 4355)
57 #endif
58 
59 
61  delete mySocket;
62 }
63 
64 
65 void
66 TraCIAPI::connect(const std::string& host, int port) {
67  mySocket = new tcpip::Socket(host, port);
68  try {
69  mySocket->connect();
70  } catch (tcpip::SocketException&) {
71  delete mySocket;
72  mySocket = 0;
73  throw;
74  }
75 }
76 
77 
78 void
80  if (mySocket == 0) {
81  return;
82  }
83  mySocket->close();
84  delete mySocket;
85  mySocket = 0;
86 }
87 
88 
89 void
91  tcpip::Storage outMsg;
92  // command length
93  outMsg.writeUnsignedByte(1 + 1 + 4);
94  // command id
96  outMsg.writeInt(time);
97  // send request message
98  mySocket->sendExact(outMsg);
99 }
100 
101 
102 void
104  tcpip::Storage outMsg;
105  // command length
106  outMsg.writeUnsignedByte(1 + 1);
107  // command id
109  mySocket->sendExact(outMsg);
110 }
111 
112 
113 void
114 TraCIAPI::send_commandGetVariable(int domID, int varID, const std::string& objID, tcpip::Storage* add) const {
115  if (mySocket == 0) {
116  throw tcpip::SocketException("Socket is not initialised");
117  }
118  tcpip::Storage outMsg;
119  // command length
120  unsigned int length = 1 + 1 + 1 + 4 + (int) objID.length();
121  if (add != 0) {
122  length += (int)add->size();
123  }
124  outMsg.writeUnsignedByte(length);
125  // command id
126  outMsg.writeUnsignedByte(domID);
127  // variable id
128  outMsg.writeUnsignedByte(varID);
129  // object id
130  outMsg.writeString(objID);
131  // additional values
132  if (add != 0) {
133  outMsg.writeStorage(*add);
134  }
135  // send request message
136  mySocket->sendExact(outMsg);
137 }
138 
139 
140 void
141 TraCIAPI::send_commandSetValue(int domID, int varID, const std::string& objID, tcpip::Storage& content) const {
142  if (mySocket == 0) {
143  throw tcpip::SocketException("Socket is not initialised");
144  }
145  tcpip::Storage outMsg;
146  // command length (domID, varID, objID, dataType, data)
147  outMsg.writeUnsignedByte(1 + 1 + 1 + 4 + (int) objID.length() + (int)content.size());
148  // command id
149  outMsg.writeUnsignedByte(domID);
150  // variable id
151  outMsg.writeUnsignedByte(varID);
152  // object id
153  outMsg.writeString(objID);
154  // data type
155  outMsg.writeStorage(content);
156  // send message
157  mySocket->sendExact(outMsg);
158 }
159 
160 
161 void
162 TraCIAPI::send_commandSubscribeObjectVariable(int domID, const std::string& objID, int beginTime, int endTime,
163  const std::vector<int>& vars) const {
164  if (mySocket == 0) {
165  throw tcpip::SocketException("Socket is not initialised");
166  }
167  tcpip::Storage outMsg;
168  // command length (domID, objID, beginTime, endTime, length, vars)
169  int varNo = (int) vars.size();
170  outMsg.writeUnsignedByte(0);
171  outMsg.writeInt(5 + 1 + 4 + 4 + 4 + (int) objID.length() + 1 + varNo);
172  // command id
173  outMsg.writeUnsignedByte(domID);
174  // time
175  outMsg.writeInt(beginTime);
176  outMsg.writeInt(endTime);
177  // object id
178  outMsg.writeString(objID);
179  // command id
180  outMsg.writeUnsignedByte((int)vars.size());
181  for (int i = 0; i < varNo; ++i) {
182  outMsg.writeUnsignedByte(vars[i]);
183  }
184  // send message
185  mySocket->sendExact(outMsg);
186 }
187 
188 
189 void
190 TraCIAPI::send_commandSubscribeObjectContext(int domID, const std::string& objID, int beginTime, int endTime,
191  int domain, SUMOReal range, const std::vector<int>& vars) const {
192  if (mySocket == 0) {
193  throw tcpip::SocketException("Socket is not initialised");
194  }
195  tcpip::Storage outMsg;
196  // command length (domID, objID, beginTime, endTime, length, vars)
197  int varNo = (int) vars.size();
198  outMsg.writeUnsignedByte(0);
199  outMsg.writeInt(5 + 1 + 4 + 4 + 4 + (int) objID.length() + 1 + 8 + 1 + varNo);
200  // command id
201  outMsg.writeUnsignedByte(domID);
202  // time
203  outMsg.writeInt(beginTime);
204  outMsg.writeInt(endTime);
205  // object id
206  outMsg.writeString(objID);
207  // domain and range
208  outMsg.writeUnsignedByte(domain);
209  outMsg.writeDouble(range);
210  // command id
211  outMsg.writeUnsignedByte((int)vars.size());
212  for (int i = 0; i < varNo; ++i) {
213  outMsg.writeUnsignedByte(vars[i]);
214  }
215  // send message
216  mySocket->sendExact(outMsg);
217 }
218 
219 
220 
221 
222 void
223 TraCIAPI::check_resultState(tcpip::Storage& inMsg, int command, bool ignoreCommandId, std::string* acknowledgement) const {
224  mySocket->receiveExact(inMsg);
225  int cmdLength;
226  int cmdId;
227  int resultType;
228  int cmdStart;
229  std::string msg;
230  try {
231  cmdStart = inMsg.position();
232  cmdLength = inMsg.readUnsignedByte();
233  cmdId = inMsg.readUnsignedByte();
234  if (command != cmdId && !ignoreCommandId) {
235  throw tcpip::SocketException("#Error: received status response to command: " + toString(cmdId) + " but expected: " + toString(command));
236  }
237  resultType = inMsg.readUnsignedByte();
238  msg = inMsg.readString();
239  } catch (std::invalid_argument&) {
240  throw tcpip::SocketException("#Error: an exception was thrown while reading result state message");
241  }
242  switch (resultType) {
243  case RTYPE_ERR:
244  throw tcpip::SocketException(".. Answered with error to command (" + toString(command) + "), [description: " + msg + "]");
246  throw tcpip::SocketException(".. Sent command is not implemented (" + toString(command) + "), [description: " + msg + "]");
247  case RTYPE_OK:
248  if (acknowledgement != 0) {
249  (*acknowledgement) = ".. Command acknowledged (" + toString(command) + "), [description: " + msg + "]";
250  }
251  break;
252  default:
253  throw tcpip::SocketException(".. Answered with unknown result code(" + toString(resultType) + ") to command(" + toString(command) + "), [description: " + msg + "]");
254  }
255  if ((cmdStart + cmdLength) != (int) inMsg.position()) {
256  throw tcpip::SocketException("#Error: command at position " + toString(cmdStart) + " has wrong length");
257  }
258 }
259 
260 
261 void
262 TraCIAPI::check_commandGetResult(tcpip::Storage& inMsg, int command, int expectedType, bool ignoreCommandId) const {
263  inMsg.position(); // respStart
264  int length = inMsg.readUnsignedByte();
265  if (length == 0) {
266  length = inMsg.readInt();
267  }
268  int cmdId = inMsg.readUnsignedByte();
269  if (!ignoreCommandId && cmdId != (command + 0x10)) {
270  throw tcpip::SocketException("#Error: received response with command id: " + toString(cmdId) + "but expected: " + toString(command + 0x10));
271  }
272  if (expectedType >= 0) {
273  int valueDataType = inMsg.readUnsignedByte();
274  if (valueDataType != expectedType) {
275  throw tcpip::SocketException("Expected " + toString(expectedType) + " but got " + toString(valueDataType));
276  }
277  }
278 }
279 
280 
281 void
282 TraCIAPI::processGET(tcpip::Storage& inMsg, int command, int expectedType, bool ignoreCommandId) const {
283  check_resultState(inMsg, command, ignoreCommandId);
284  check_commandGetResult(inMsg, command, expectedType, ignoreCommandId);
285 }
286 
287 
288 
289 
290 SUMOTime
291 TraCIAPI::getSUMOTime(int cmd, int var, const std::string& id, tcpip::Storage* add) {
292  tcpip::Storage inMsg;
293  send_commandGetVariable(cmd, var, id, add);
294  processGET(inMsg, cmd, TYPE_INTEGER);
295  return inMsg.readInt();
296 }
297 
298 
299 int
300 TraCIAPI::getUnsignedByte(int cmd, int var, const std::string& id, tcpip::Storage* add) {
301  tcpip::Storage inMsg;
302  send_commandGetVariable(cmd, var, id, add);
303  processGET(inMsg, cmd, TYPE_UBYTE);
304  return inMsg.readUnsignedByte();
305 }
306 
307 
308 int
309 TraCIAPI::getByte(int cmd, int var, const std::string& id, tcpip::Storage* add) {
310  tcpip::Storage inMsg;
311  send_commandGetVariable(cmd, var, id, add);
312  processGET(inMsg, cmd, TYPE_BYTE);
313  return inMsg.readByte();
314 }
315 
316 
317 int
318 TraCIAPI::getInt(int cmd, int var, const std::string& id, tcpip::Storage* add) {
319  tcpip::Storage inMsg;
320  send_commandGetVariable(cmd, var, id, add);
321  processGET(inMsg, cmd, TYPE_INTEGER);
322  return inMsg.readInt();
323 }
324 
325 
326 SUMOReal
327 TraCIAPI::getFloat(int cmd, int var, const std::string& id, tcpip::Storage* add) {
328  tcpip::Storage inMsg;
329  send_commandGetVariable(cmd, var, id, add);
330  processGET(inMsg, cmd, TYPE_FLOAT);
331  return inMsg.readFloat();
332 }
333 
334 
335 SUMOReal
336 TraCIAPI::getDouble(int cmd, int var, const std::string& id, tcpip::Storage* add) {
337  tcpip::Storage inMsg;
338  send_commandGetVariable(cmd, var, id, add);
339  processGET(inMsg, cmd, TYPE_DOUBLE);
340  return inMsg.readDouble();
341 }
342 
343 
345 TraCIAPI::getBoundingBox(int cmd, int var, const std::string& id, tcpip::Storage* add) {
346  tcpip::Storage inMsg;
347  send_commandGetVariable(cmd, var, id, add);
348  processGET(inMsg, cmd, TYPE_BOUNDINGBOX);
349  TraCIBoundary b;
350  b.xMin = inMsg.readDouble();
351  b.yMin = inMsg.readDouble();
352  b.zMin = 0;
353  b.xMax = inMsg.readDouble();
354  b.yMax = inMsg.readDouble();
355  b.zMax = 0;
356  return b;
357 }
358 
359 
361 TraCIAPI::getPolygon(int cmd, int var, const std::string& id, tcpip::Storage* add) {
362  tcpip::Storage inMsg;
363  send_commandGetVariable(cmd, var, id, add);
364  processGET(inMsg, cmd, TYPE_POLYGON);
365  unsigned int size = inMsg.readInt();
367  for (unsigned int i = 0; i < size; ++i) {
368  TraCIPosition p;
369  p.x = inMsg.readDouble();
370  p.y = inMsg.readDouble();
371  p.z = 0;
372  ret.push_back(p);
373  }
374  return ret;
375 }
376 
377 
379 TraCIAPI::getPosition(int cmd, int var, const std::string& id, tcpip::Storage* add) {
380  tcpip::Storage inMsg;
381  send_commandGetVariable(cmd, var, id, add);
382  processGET(inMsg, cmd, POSITION_2D);
383  TraCIPosition p;
384  p.x = inMsg.readDouble();
385  p.y = inMsg.readDouble();
386  p.z = 0;
387  return p;
388 }
389 
390 
391 std::string
392 TraCIAPI::getString(int cmd, int var, const std::string& id, tcpip::Storage* add) {
393  tcpip::Storage inMsg;
394  send_commandGetVariable(cmd, var, id, add);
395  processGET(inMsg, cmd, TYPE_STRING);
396  return inMsg.readString();
397 }
398 
399 
400 std::vector<std::string>
401 TraCIAPI::getStringVector(int cmd, int var, const std::string& id, tcpip::Storage* add) {
402  tcpip::Storage inMsg;
403  send_commandGetVariable(cmd, var, id, add);
404  processGET(inMsg, cmd, TYPE_STRINGLIST);
405  unsigned int size = inMsg.readInt();
406  std::vector<std::string> r;
407  for (unsigned int i = 0; i < size; ++i) {
408  r.push_back(inMsg.readString());
409  }
410  return r;
411 }
412 
413 
415 TraCIAPI::getColor(int cmd, int var, const std::string& id, tcpip::Storage* add) {
416  tcpip::Storage inMsg;
417  send_commandGetVariable(cmd, var, id, add);
418  processGET(inMsg, cmd, TYPE_COLOR);
419  TraCIColor c;
420  c.r = inMsg.readUnsignedByte();
421  c.g = inMsg.readUnsignedByte();
422  c.b = inMsg.readUnsignedByte();
423  c.a = inMsg.readUnsignedByte();
424  return c;
425 }
426 
427 
428 
429 // ---------------------------------------------------------------------------
430 // TraCIAPI::EdgeScope-methods
431 // ---------------------------------------------------------------------------
432 std::vector<std::string>
435 }
436 
437 unsigned int
439  return myParent.getInt(CMD_GET_EDGE_VARIABLE, ID_COUNT, "");
440 }
441 
442 SUMOReal
443 TraCIAPI::EdgeScope::getAdaptedTraveltime(const std::string& edgeID, SUMOTime time) const {
444  tcpip::Storage content;
445  content.writeInt(time);
446  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, VAR_CO2EMISSION, edgeID, &content);
447 }
448 
449 SUMOReal
450 TraCIAPI::EdgeScope::getEffort(const std::string& edgeID, SUMOTime time) const {
451  tcpip::Storage content;
452  content.writeInt(time);
453  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, VAR_CO2EMISSION, edgeID, &content);
454 }
455 
456 SUMOReal
457 TraCIAPI::EdgeScope::getCO2Emission(const std::string& edgeID) const {
458  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, VAR_CO2EMISSION, edgeID);
459 }
460 
461 SUMOReal
462 TraCIAPI::EdgeScope::getCOEmission(const std::string& edgeID) const {
463  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, VAR_COEMISSION, edgeID);
464 }
465 
466 SUMOReal
467 TraCIAPI::EdgeScope::getHCEmission(const std::string& edgeID) const {
468  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, VAR_HCEMISSION, edgeID);
469 }
470 
471 SUMOReal
472 TraCIAPI::EdgeScope::getPMxEmission(const std::string& edgeID) const {
473  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, VAR_PMXEMISSION, edgeID);
474 }
475 
476 SUMOReal
477 TraCIAPI::EdgeScope::getNOxEmission(const std::string& edgeID) const {
478  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, VAR_NOXEMISSION, edgeID);
479 }
480 
481 SUMOReal
482 TraCIAPI::EdgeScope::getFuelConsumption(const std::string& edgeID) const {
483  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, VAR_FUELCONSUMPTION, edgeID);
484 }
485 
486 SUMOReal
487 TraCIAPI::EdgeScope::getNoiseEmission(const std::string& edgeID) const {
488  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, VAR_NOISEEMISSION, edgeID);
489 }
490 
491 SUMOReal
492 TraCIAPI::EdgeScope::getLastStepMeanSpeed(const std::string& edgeID) const {
493  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, LAST_STEP_MEAN_SPEED, edgeID);
494 }
495 
496 SUMOReal
497 TraCIAPI::EdgeScope::getLastStepOccupancy(const std::string& edgeID) const {
498  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, LAST_STEP_OCCUPANCY, edgeID);
499 }
500 
501 SUMOReal
502 TraCIAPI::EdgeScope::getLastStepLength(const std::string& edgeID) const {
503  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, LAST_STEP_LENGTH, edgeID);
504 }
505 
506 SUMOReal
507 TraCIAPI::EdgeScope::getTraveltime(const std::string& edgeID) const {
508  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, VAR_CURRENT_TRAVELTIME, edgeID);
509 }
510 
511 unsigned int
512 TraCIAPI::EdgeScope::getLastStepVehicleNumber(const std::string& edgeID) const {
513  return myParent.getInt(CMD_GET_EDGE_VARIABLE, LAST_STEP_VEHICLE_NUMBER, edgeID);
514 }
515 
516 SUMOReal
517 TraCIAPI::EdgeScope::getLastStepHaltingNumber(const std::string& edgeID) const {
518  return myParent.getInt(CMD_GET_EDGE_VARIABLE, LAST_STEP_VEHICLE_HALTING_NUMBER, edgeID);
519 }
520 
521 std::vector<std::string>
522 TraCIAPI::EdgeScope::getLastStepVehicleIDs(const std::string& edgeID) const {
523  return myParent.getStringVector(CMD_GET_EDGE_VARIABLE, LAST_STEP_VEHICLE_ID_LIST, edgeID);
524 }
525 
526 
527 
528 void
529 TraCIAPI::EdgeScope::adaptTraveltime(const std::string& edgeID, SUMOReal time) const {
530  tcpip::Storage content;
531  content.writeDouble(time);
532  myParent.send_commandSetValue(CMD_SET_EDGE_VARIABLE, VAR_EDGE_TRAVELTIME, edgeID, content);
533 }
534 
535 void
536 TraCIAPI::EdgeScope::setEffort(const std::string& edgeID, SUMOReal effort) const {
537  tcpip::Storage content;
538  content.writeDouble(effort);
539  myParent.send_commandSetValue(CMD_SET_EDGE_VARIABLE, VAR_EDGE_EFFORT, edgeID, content);
540 }
541 
542 void
543 TraCIAPI::EdgeScope::setMaxSpeed(const std::string& edgeID, SUMOReal speed) const {
544  tcpip::Storage content;
545  content.writeDouble(speed);
546  myParent.send_commandSetValue(CMD_SET_EDGE_VARIABLE, VAR_MAXSPEED, edgeID, content);
547 }
548 
549 
550 
551 
552 // ---------------------------------------------------------------------------
553 // TraCIAPI::GUIScope-methods
554 // ---------------------------------------------------------------------------
555 std::vector<std::string>
557  return myParent.getStringVector(CMD_GET_GUI_VARIABLE, ID_LIST, "");
558 }
559 
560 SUMOReal
561 TraCIAPI::GUIScope::getZoom(const std::string& viewID) const {
562  return myParent.getDouble(CMD_GET_GUI_VARIABLE, VAR_VIEW_ZOOM, viewID);
563 }
564 
566 TraCIAPI::GUIScope::getOffset(const std::string& viewID) const {
567  return myParent.getPosition(CMD_GET_GUI_VARIABLE, VAR_VIEW_OFFSET, viewID);
568 }
569 
570 std::string
571 TraCIAPI::GUIScope::getSchema(const std::string& viewID) const {
572  return myParent.getString(CMD_GET_GUI_VARIABLE, VAR_VIEW_SCHEMA, viewID);
573 }
574 
576 TraCIAPI::GUIScope::getBoundary(const std::string& viewID) const {
577  return myParent.getBoundingBox(CMD_GET_GUI_VARIABLE, VAR_VIEW_BOUNDARY, viewID);
578 }
579 
580 
581 void
582 TraCIAPI::GUIScope::setZoom(const std::string& viewID, SUMOReal zoom) const {
583  tcpip::Storage content;
584  content.writeDouble(zoom);
585  myParent.send_commandSetValue(CMD_SET_GUI_VARIABLE, VAR_VIEW_ZOOM, viewID, content);
586 }
587 
588 void
589 TraCIAPI::GUIScope::setOffset(const std::string& viewID, SUMOReal x, SUMOReal y) const {
590  tcpip::Storage content;
592  content.writeDouble(x);
593  content.writeDouble(y);
594  myParent.send_commandSetValue(CMD_SET_GUI_VARIABLE, VAR_VIEW_OFFSET, viewID, content);
595 }
596 
597 void
598 TraCIAPI::GUIScope::setSchema(const std::string& viewID, const std::string& schemeName) const {
599  tcpip::Storage content;
600  content.writeString(schemeName);
601  myParent.send_commandSetValue(CMD_SET_GUI_VARIABLE, VAR_VIEW_SCHEMA, viewID, content);
602 }
603 
604 void
605 TraCIAPI::GUIScope::setBoundary(const std::string& viewID, SUMOReal xmin, SUMOReal ymin, SUMOReal xmax, SUMOReal ymax) const {
606  tcpip::Storage content;
608  content.writeDouble(xmin);
609  content.writeDouble(ymin);
610  content.writeDouble(xmax);
611  content.writeDouble(ymax);
612  myParent.send_commandSetValue(CMD_SET_GUI_VARIABLE, VAR_VIEW_BOUNDARY, viewID, content);
613 }
614 
615 void
616 TraCIAPI::GUIScope::screenshot(const std::string& viewID, const std::string& filename) const {
617  tcpip::Storage content;
618  content.writeString(filename);
619  myParent.send_commandSetValue(CMD_SET_GUI_VARIABLE, VAR_SCREENSHOT, viewID, content);
620 }
621 
622 void
623 TraCIAPI::GUIScope::trackVehicle(const std::string& viewID, const std::string& vehID) const {
624  tcpip::Storage content;
625  content.writeString(vehID);
626  myParent.send_commandSetValue(CMD_SET_GUI_VARIABLE, VAR_TRACK_VEHICLE, viewID, content);
627 }
628 
629 
630 
631 
632 // ---------------------------------------------------------------------------
633 // TraCIAPI::InductionLoopScope-methods
634 // ---------------------------------------------------------------------------
635 std::vector<std::string>
637  return myParent.getStringVector(CMD_GET_INDUCTIONLOOP_VARIABLE, ID_LIST, "");
638 }
639 
640 SUMOReal
641 TraCIAPI::InductionLoopScope::getPosition(const std::string& loopID) const {
642  return myParent.getDouble(CMD_GET_INDUCTIONLOOP_VARIABLE, VAR_POSITION, loopID);
643 }
644 
645 std::string
646 TraCIAPI::InductionLoopScope::getLaneID(const std::string& loopID) const {
647  return myParent.getString(CMD_GET_INDUCTIONLOOP_VARIABLE, VAR_LANE_ID, loopID);
648 }
649 
650 unsigned int
652  return myParent.getInt(CMD_GET_INDUCTIONLOOP_VARIABLE, LAST_STEP_VEHICLE_NUMBER, loopID);
653 }
654 
655 SUMOReal
656 TraCIAPI::InductionLoopScope::getLastStepMeanSpeed(const std::string& loopID) const {
657  return myParent.getDouble(CMD_GET_INDUCTIONLOOP_VARIABLE, LAST_STEP_MEAN_SPEED, loopID);
658 }
659 
660 std::vector<std::string>
661 TraCIAPI::InductionLoopScope::getLastStepVehicleIDs(const std::string& loopID) const {
662  return myParent.getStringVector(CMD_GET_INDUCTIONLOOP_VARIABLE, LAST_STEP_VEHICLE_ID_LIST, loopID);
663 }
664 
665 SUMOReal
666 TraCIAPI::InductionLoopScope::getLastStepOccupancy(const std::string& loopID) const {
667  return myParent.getDouble(CMD_GET_INDUCTIONLOOP_VARIABLE, LAST_STEP_OCCUPANCY, loopID);
668 }
669 
670 SUMOReal
671 TraCIAPI::InductionLoopScope::getLastStepMeanLength(const std::string& loopID) const {
672  return myParent.getDouble(CMD_GET_INDUCTIONLOOP_VARIABLE, LAST_STEP_LENGTH, loopID);
673 }
674 
675 SUMOReal
676 TraCIAPI::InductionLoopScope::getTimeSinceDetection(const std::string& loopID) const {
677  return myParent.getDouble(CMD_GET_INDUCTIONLOOP_VARIABLE, LAST_STEP_TIME_SINCE_DETECTION, loopID);
678 }
679 
680 unsigned int
681 TraCIAPI::InductionLoopScope::getVehicleData(const std::string& loopID) const {
682  return myParent.getInt(CMD_GET_INDUCTIONLOOP_VARIABLE, LAST_STEP_VEHICLE_DATA, loopID);
683 }
684 
685 
686 
687 
688 // ---------------------------------------------------------------------------
689 // TraCIAPI::JunctionScope-methods
690 // ---------------------------------------------------------------------------
691 std::vector<std::string>
693  return myParent.getStringVector(CMD_GET_JUNCTION_VARIABLE, ID_LIST, "");
694 }
695 
697 TraCIAPI::JunctionScope::getPosition(const std::string& junctionID) const {
698  return myParent.getPosition(CMD_GET_JUNCTION_VARIABLE, VAR_POSITION, junctionID);
699 }
700 
701 
702 
703 
704 // ---------------------------------------------------------------------------
705 // TraCIAPI::LaneScope-methods
706 // ---------------------------------------------------------------------------
707 std::vector<std::string>
709  return myParent.getStringVector(CMD_GET_LANE_VARIABLE, ID_LIST, "");
710 }
711 
712 SUMOReal
713 TraCIAPI::LaneScope::getLength(const std::string& laneID) const {
714  return myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_LENGTH, laneID);
715 }
716 
717 SUMOReal
718 TraCIAPI::LaneScope::getMaxSpeed(const std::string& laneID) const {
719  return myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_MAXSPEED, laneID);
720 }
721 
722 SUMOReal
723 TraCIAPI::LaneScope::getWidth(const std::string& laneID) const {
724  return myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_WIDTH, laneID);
725 }
726 
727 std::vector<std::string>
728 TraCIAPI::LaneScope::getAllowed(const std::string& laneID) const {
729  return myParent.getStringVector(CMD_GET_LANE_VARIABLE, LANE_ALLOWED, laneID);
730 }
731 
732 std::vector<std::string>
733 TraCIAPI::LaneScope::getDisallowed(const std::string& laneID) const {
734  return myParent.getStringVector(CMD_GET_LANE_VARIABLE, LANE_DISALLOWED, laneID);
735 }
736 
737 unsigned int
738 TraCIAPI::LaneScope::getLinkNumber(const std::string& /* laneID */) const {
739  throw tcpip::SocketException("Not implemented!");
740 }
741 
743 TraCIAPI::LaneScope::getShape(const std::string& laneID) const {
744  throw myParent.getPolygon(CMD_GET_LANE_VARIABLE, VAR_SHAPE, laneID);
745 }
746 
747 std::string
748 TraCIAPI::LaneScope::getEdgeID(const std::string& laneID) const {
749  throw myParent.getString(CMD_GET_LANE_VARIABLE, LANE_EDGE_ID, laneID);
750 }
751 
752 SUMOReal
753 TraCIAPI::LaneScope::getCO2Emission(const std::string& laneID) const {
754  throw myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_CO2EMISSION, laneID);
755 }
756 
757 SUMOReal
758 TraCIAPI::LaneScope::getCOEmission(const std::string& laneID) const {
759  throw myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_COEMISSION, laneID);
760 }
761 
762 SUMOReal
763 TraCIAPI::LaneScope::getHCEmission(const std::string& laneID) const {
764  throw myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_HCEMISSION, laneID);
765 }
766 
767 SUMOReal
768 TraCIAPI::LaneScope::getPMxEmission(const std::string& laneID) const {
769  throw myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_PMXEMISSION, laneID);
770 }
771 
772 SUMOReal
773 TraCIAPI::LaneScope::getNOxEmission(const std::string& laneID) const {
774  throw myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_NOXEMISSION, laneID);
775 }
776 
777 SUMOReal
778 TraCIAPI::LaneScope::getFuelConsumption(const std::string& laneID) const {
779  throw myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_FUELCONSUMPTION, laneID);
780 }
781 
782 SUMOReal
783 TraCIAPI::LaneScope::getNoiseEmission(const std::string& laneID) const {
784  throw myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_NOISEEMISSION, laneID);
785 }
786 
787 SUMOReal
788 TraCIAPI::LaneScope::getLastStepMeanSpeed(const std::string& laneID) const {
789  throw myParent.getDouble(CMD_GET_LANE_VARIABLE, LAST_STEP_MEAN_SPEED, laneID);
790 }
791 
792 SUMOReal
793 TraCIAPI::LaneScope::getLastStepOccupancy(const std::string& laneID) const {
794  throw myParent.getDouble(CMD_GET_LANE_VARIABLE, LAST_STEP_OCCUPANCY, laneID);
795 }
796 
797 SUMOReal
798 TraCIAPI::LaneScope::getLastStepLength(const std::string& laneID) const {
799  throw myParent.getDouble(CMD_GET_LANE_VARIABLE, LAST_STEP_LENGTH, laneID);
800 }
801 
802 SUMOReal
803 TraCIAPI::LaneScope::getTraveltime(const std::string& laneID) const {
804  throw myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_CURRENT_TRAVELTIME, laneID);
805 }
806 
807 unsigned int
808 TraCIAPI::LaneScope::getLastStepVehicleNumber(const std::string& laneID) const {
809  throw myParent.getInt(CMD_GET_LANE_VARIABLE, LAST_STEP_VEHICLE_NUMBER, laneID);
810 }
811 
812 unsigned int
813 TraCIAPI::LaneScope::getLastStepHaltingNumber(const std::string& laneID) const {
814  throw myParent.getInt(CMD_GET_LANE_VARIABLE, LAST_STEP_VEHICLE_HALTING_NUMBER, laneID);
815 }
816 
817 std::vector<std::string>
818 TraCIAPI::LaneScope::getLastStepVehicleIDs(const std::string& laneID) const {
819  throw myParent.getStringVector(CMD_GET_LANE_VARIABLE, LAST_STEP_VEHICLE_ID_LIST, laneID);
820 }
821 
822 
823 void
824 TraCIAPI::LaneScope::setAllowed(const std::string& laneID, const std::vector<std::string>& allowedClasses) const {
825  tcpip::Storage content;
827  content.writeInt((int)allowedClasses.size());
828  for (unsigned int i = 0; i < allowedClasses.size(); ++i) {
829  content.writeString(allowedClasses[i]);
830  }
831  myParent.send_commandSetValue(CMD_SET_LANE_VARIABLE, LANE_ALLOWED, laneID, content);
832 }
833 
834 void
835 TraCIAPI::LaneScope::setDisallowed(const std::string& laneID, const std::vector<std::string>& disallowedClasses) const {
836  tcpip::Storage content;
838  content.writeInt((int)disallowedClasses.size());
839  for (unsigned int i = 0; i < disallowedClasses.size(); ++i) {
840  content.writeString(disallowedClasses[i]);
841  }
842  myParent.send_commandSetValue(CMD_SET_LANE_VARIABLE, LANE_DISALLOWED, laneID, content);
843 }
844 
845 void
846 TraCIAPI::LaneScope::setMaxSpeed(const std::string& laneID, SUMOReal speed) const {
847  tcpip::Storage content;
849  content.writeDouble(speed);
850  myParent.send_commandSetValue(CMD_SET_LANE_VARIABLE, VAR_MAXSPEED, laneID, content);
851 }
852 
853 void
854 TraCIAPI::LaneScope::setLength(const std::string& laneID, SUMOReal length) const {
855  tcpip::Storage content;
857  content.writeDouble(length);
858  myParent.send_commandSetValue(CMD_SET_LANE_VARIABLE, VAR_LENGTH, laneID, content);
859 }
860 
861 
862 
863 // ---------------------------------------------------------------------------
864 // TraCIAPI::MeMeScope-methods
865 // ---------------------------------------------------------------------------
866 std::vector<std::string>
868  return myParent.getStringVector(CMD_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE, ID_LIST, "");
869 }
870 
871 unsigned int
872 TraCIAPI::MeMeScope::getLastStepVehicleNumber(const std::string& detID) const {
874 }
875 
876 SUMOReal
877 TraCIAPI::MeMeScope::getLastStepMeanSpeed(const std::string& detID) const {
879 }
880 
881 std::vector<std::string>
882 TraCIAPI::MeMeScope::getLastStepVehicleIDs(const std::string& detID) const {
883  return myParent.getStringVector(CMD_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE, LAST_STEP_VEHICLE_ID_LIST, detID);
884 }
885 
886 unsigned int
887 TraCIAPI::MeMeScope::getLastStepHaltingNumber(const std::string& detID) const {
889 }
890 
891 
892 
893 // ---------------------------------------------------------------------------
894 // TraCIAPI::POIScope-methods
895 // ---------------------------------------------------------------------------
896 std::vector<std::string>
898  return myParent.getStringVector(CMD_GET_POI_VARIABLE, ID_LIST, "");
899 }
900 
901 std::string
902 TraCIAPI::POIScope::getType(const std::string& poiID) const {
903  return myParent.getString(CMD_GET_POI_VARIABLE, VAR_TYPE, poiID);
904 }
905 
907 TraCIAPI::POIScope::getPosition(const std::string& poiID) const {
908  return myParent.getPosition(CMD_GET_POI_VARIABLE, VAR_POSITION, poiID);
909 }
910 
912 TraCIAPI::POIScope::getColor(const std::string& poiID) const {
913  return myParent.getColor(CMD_GET_POI_VARIABLE, VAR_COLOR, poiID);
914 }
915 
916 
917 void
918 TraCIAPI::POIScope::setType(const std::string& poiID, const std::string& setType) const {
919  tcpip::Storage content;
921  content.writeString(setType);
922  myParent.send_commandSetValue(CMD_SET_POI_VARIABLE, VAR_TYPE, poiID, content);
923 }
924 
925 void
926 TraCIAPI::POIScope::setPosition(const std::string& poiID, SUMOReal x, SUMOReal y) const {
927  tcpip::Storage content;
929  content.writeDouble(x);
930  content.writeDouble(y);
931  myParent.send_commandSetValue(CMD_SET_POI_VARIABLE, VAR_POSITION, poiID, content);
932 }
933 
934 void
935 TraCIAPI::POIScope::setColor(const std::string& poiID, const TraCIColor& c) const {
936  tcpip::Storage content;
937  content.writeUnsignedByte(TYPE_COLOR);
938  content.writeUnsignedByte(c.r);
939  content.writeUnsignedByte(c.g);
940  content.writeUnsignedByte(c.b);
941  content.writeUnsignedByte(c.a);
942  myParent.send_commandSetValue(CMD_SET_POI_VARIABLE, VAR_COLOR, poiID, content);
943 }
944 
945 void
946 TraCIAPI::POIScope::add(const std::string& poiID, SUMOReal x, SUMOReal y, const TraCIColor& c, const std::string& type, int layer) const {
947  tcpip::Storage content;
949  content.writeInt(4);
951  content.writeString(type);
952  content.writeUnsignedByte(TYPE_COLOR);
953  content.writeUnsignedByte(c.r);
954  content.writeUnsignedByte(c.g);
955  content.writeUnsignedByte(c.b);
956  content.writeUnsignedByte(c.a);
958  content.writeInt(layer);
960  content.writeDouble(x);
961  content.writeDouble(y);
962  myParent.send_commandSetValue(CMD_SET_POI_VARIABLE, ADD, poiID, content);
963 }
964 
965 void
966 TraCIAPI::POIScope::remove(const std::string& poiID, int layer) const {
967  tcpip::Storage content;
969  content.writeInt(layer);
970  myParent.send_commandSetValue(CMD_SET_POI_VARIABLE, REMOVE, poiID, content);
971 }
972 
973 
974 
975 // ---------------------------------------------------------------------------
976 // TraCIAPI::PolygonScope-methods
977 // ---------------------------------------------------------------------------
978 std::vector<std::string>
980  return myParent.getStringVector(CMD_GET_POLYGON_VARIABLE, ID_LIST, "");
981 }
982 
983 std::string
984 TraCIAPI::PolygonScope::getType(const std::string& polygonID) const {
985  return myParent.getString(CMD_GET_POLYGON_VARIABLE, VAR_TYPE, polygonID);
986 }
987 
989 TraCIAPI::PolygonScope::getShape(const std::string& polygonID) const {
990  return myParent.getPolygon(CMD_GET_POLYGON_VARIABLE, VAR_SHAPE, polygonID);
991 }
992 
994 TraCIAPI::PolygonScope::getColor(const std::string& polygonID) const {
995  return myParent.getColor(CMD_GET_POLYGON_VARIABLE, VAR_COLOR, polygonID);
996 }
997 
998 
999 void
1000 TraCIAPI::PolygonScope::setType(const std::string& polygonID, const std::string& setType) const {
1001  tcpip::Storage content;
1002  content.writeUnsignedByte(TYPE_STRING);
1003  content.writeString(setType);
1004  myParent.send_commandSetValue(CMD_SET_POLYGON_VARIABLE, VAR_TYPE, polygonID, content);
1005 }
1006 
1007 void
1008 TraCIAPI::PolygonScope::setShape(const std::string& polygonID, const TraCIAPI::TraCIPositionVector& shape) const {
1009  tcpip::Storage content;
1011  content.writeInt((int)shape.size());
1012  for (unsigned int i = 0; i < shape.size(); ++i) {
1013  content.writeDouble(shape[i].x);
1014  content.writeDouble(shape[i].y);
1015  }
1016  myParent.send_commandSetValue(CMD_SET_POLYGON_VARIABLE, VAR_POSITION, polygonID, content);
1017 }
1018 
1019 void
1020 TraCIAPI::PolygonScope::setColor(const std::string& polygonID, const TraCIColor& c) const {
1021  tcpip::Storage content;
1022  content.writeUnsignedByte(TYPE_COLOR);
1023  content.writeUnsignedByte(c.r);
1024  content.writeUnsignedByte(c.g);
1025  content.writeUnsignedByte(c.b);
1026  content.writeUnsignedByte(c.a);
1027  myParent.send_commandSetValue(CMD_SET_POLYGON_VARIABLE, VAR_COLOR, polygonID, content);
1028 }
1029 
1030 void
1031 TraCIAPI::PolygonScope::add(const std::string& polygonID, const TraCIAPI::TraCIPositionVector& shape, const TraCIColor& c, bool fill, const std::string& type, int layer) const {
1032  tcpip::Storage content;
1034  content.writeInt(4);
1035  content.writeUnsignedByte(TYPE_STRING);
1036  content.writeString(type);
1037  content.writeUnsignedByte(TYPE_COLOR);
1038  content.writeUnsignedByte(c.r);
1039  content.writeUnsignedByte(c.g);
1040  content.writeUnsignedByte(c.b);
1041  content.writeUnsignedByte(c.a);
1042  content.writeUnsignedByte(TYPE_UBYTE);
1043  int f = fill ? 1 : 0;
1044  content.writeUnsignedByte(f);
1046  content.writeInt(layer);
1048  content.writeInt((int)shape.size());
1049  for (unsigned int i = 0; i < shape.size(); ++i) {
1050  content.writeDouble(shape[i].x);
1051  content.writeDouble(shape[i].y);
1052  }
1053  myParent.send_commandSetValue(CMD_SET_POLYGON_VARIABLE, ADD, polygonID, content);
1054 }
1055 
1056 void
1057 TraCIAPI::PolygonScope::remove(const std::string& polygonID, int layer) const {
1058  tcpip::Storage content;
1060  content.writeInt(layer);
1061  myParent.send_commandSetValue(CMD_SET_POLYGON_VARIABLE, REMOVE, polygonID, content);
1062 }
1063 
1064 
1065 
1066 // ---------------------------------------------------------------------------
1067 // TraCIAPI::RouteScope-methods
1068 // ---------------------------------------------------------------------------
1069 std::vector<std::string>
1071  return myParent.getStringVector(CMD_GET_ROUTE_VARIABLE, ID_LIST, "");
1072 }
1073 
1074 std::vector<std::string>
1075 TraCIAPI::RouteScope::getEdges(const std::string& routeID) const {
1076  return myParent.getStringVector(CMD_GET_ROUTE_VARIABLE, VAR_EDGES, routeID);
1077 }
1078 
1079 
1080 void
1081 TraCIAPI::RouteScope::add(const std::string& routeID, const std::vector<std::string>& edges) const {
1082  tcpip::Storage content;
1084  content.writeStringList(edges);
1085  myParent.send_commandSetValue(CMD_SET_ROUTE_VARIABLE, VAR_POSITION, routeID, content);
1086 }
1087 
1088 
1089 
1090 
1091 
1092 // ---------------------------------------------------------------------------
1093 // TraCIAPI::SimulationScope-methods
1094 // ---------------------------------------------------------------------------
1095 SUMOTime
1097  return myParent.getSUMOTime(CMD_GET_SIM_VARIABLE, VAR_TIME_STEP, "");
1098 }
1099 
1100 unsigned int
1102  return (unsigned int) myParent.getInt(CMD_GET_SIM_VARIABLE, VAR_LOADED_VEHICLES_NUMBER, "");
1103 }
1104 
1105 std::vector<std::string>
1107  return myParent.getStringVector(CMD_GET_SIM_VARIABLE, VAR_LOADED_VEHICLES_IDS, "");
1108 }
1109 
1110 unsigned int
1112  return (unsigned int) myParent.getInt(CMD_GET_SIM_VARIABLE, VAR_DEPARTED_VEHICLES_NUMBER, "");
1113 }
1114 
1115 std::vector<std::string>
1117  return myParent.getStringVector(CMD_GET_SIM_VARIABLE, VAR_DEPARTED_VEHICLES_IDS, "");
1118 }
1119 
1120 unsigned int
1122  return (unsigned int) myParent.getInt(CMD_GET_SIM_VARIABLE, VAR_ARRIVED_VEHICLES_NUMBER, "");
1123 }
1124 
1125 std::vector<std::string>
1127  return myParent.getStringVector(CMD_GET_SIM_VARIABLE, VAR_ARRIVED_VEHICLES_IDS, "");
1128 }
1129 
1130 unsigned int
1132  return (unsigned int) myParent.getInt(CMD_GET_SIM_VARIABLE, VAR_TELEPORT_STARTING_VEHICLES_NUMBER, "");
1133 }
1134 
1135 std::vector<std::string>
1137  return myParent.getStringVector(CMD_GET_SIM_VARIABLE, VAR_TELEPORT_STARTING_VEHICLES_IDS, "");
1138 }
1139 
1140 unsigned int
1142  return (unsigned int) myParent.getInt(CMD_GET_SIM_VARIABLE, VAR_TELEPORT_ENDING_VEHICLES_NUMBER, "");
1143 }
1144 
1145 std::vector<std::string>
1147  return myParent.getStringVector(CMD_GET_SIM_VARIABLE, VAR_TELEPORT_ENDING_VEHICLES_IDS, "");
1148 }
1149 
1150 SUMOTime
1152  return myParent.getSUMOTime(CMD_GET_SIM_VARIABLE, VAR_DELTA_T, "");
1153 }
1154 
1157  return myParent.getBoundingBox(CMD_GET_SIM_VARIABLE, VAR_NET_BOUNDING_BOX, "");
1158 }
1159 
1160 unsigned int
1162  return myParent.getInt(CMD_GET_SIM_VARIABLE, VAR_MIN_EXPECTED_VEHICLES, "");
1163 }
1164 
1165 
1166 
1167 // ---------------------------------------------------------------------------
1168 // TraCIAPI::TrafficLightScope-methods
1169 // ---------------------------------------------------------------------------
1170 std::vector<std::string>
1172  return myParent.getStringVector(CMD_GET_TL_VARIABLE, ID_LIST, "");
1173 }
1174 
1175 std::string
1177  return myParent.getString(CMD_GET_TL_VARIABLE, TL_RED_YELLOW_GREEN_STATE, tlsID);
1178 }
1179 
1180 std::vector<TraCIAPI::TraCILogic>
1182  tcpip::Storage inMsg;
1183  myParent.send_commandGetVariable(CMD_GET_TL_VARIABLE, TL_COMPLETE_DEFINITION_RYG, tlsID);
1184  myParent.processGET(inMsg, CMD_GET_TL_VARIABLE, TYPE_COMPOUND);
1185  std::vector<TraCIAPI::TraCILogic> ret;
1186  int logicNo = inMsg.readInt();
1187  for (int i = 0; i < logicNo; ++i) {
1188  inMsg.readUnsignedByte();
1189  std::string subID = inMsg.readString();
1190  inMsg.readUnsignedByte();
1191  int type = inMsg.readInt();
1192  inMsg.readUnsignedByte();
1193  inMsg.readInt(); // add
1194  inMsg.readUnsignedByte();
1195  int phaseIndex = inMsg.readInt();
1196  inMsg.readUnsignedByte();
1197  int phaseNumber = inMsg.readInt();
1198  std::vector<TraCIAPI::TraCIPhase> phases;
1199  for (int j = 0; j < phaseNumber; ++j) {
1200  inMsg.readUnsignedByte();
1201  int duration = inMsg.readInt();
1202  inMsg.readUnsignedByte();
1203  int duration1 = inMsg.readInt();
1204  inMsg.readUnsignedByte();
1205  int duration2 = inMsg.readInt();
1206  inMsg.readUnsignedByte();
1207  std::string phase = inMsg.readString();
1208  phases.push_back(TraCIAPI::TraCIPhase(duration, phase, duration1, duration2));
1209  }
1210  ret.push_back(TraCIAPI::TraCILogic(subID, type, std::map<std::string, SUMOReal>(), phaseIndex, phases));
1211  }
1212  return ret;
1213 }
1214 
1215 std::vector<std::string>
1216 TraCIAPI::TrafficLightScope::getControlledLanes(const std::string& tlsID) const {
1217  return myParent.getStringVector(CMD_GET_TL_VARIABLE, TL_CONTROLLED_LANES, tlsID);
1218 }
1219 
1220 std::vector<TraCIAPI::TraCILink>
1221 TraCIAPI::TrafficLightScope::getControlledLinks(const std::string& tlsID) const {
1222  tcpip::Storage inMsg;
1223  myParent.send_commandGetVariable(CMD_GET_TL_VARIABLE, TL_CONTROLLED_LINKS, tlsID);
1224  myParent.processGET(inMsg, CMD_GET_TL_VARIABLE, TYPE_COMPOUND);
1225  std::vector<TraCIAPI::TraCILink> ret;
1226  int linkNo = inMsg.readInt();
1227  for (int i = 0; i < linkNo; ++i) {
1228  inMsg.readUnsignedByte();
1229  std::string from = inMsg.readString();
1230  inMsg.readUnsignedByte();
1231  std::string via = inMsg.readString();
1232  inMsg.readUnsignedByte();
1233  std::string to = inMsg.readString();
1234  ret.push_back(TraCIAPI::TraCILink(from, via, to));
1235  }
1236  return ret;
1237 }
1238 
1239 std::string
1240 TraCIAPI::TrafficLightScope::getProgram(const std::string& tlsID) const {
1241  return myParent.getString(CMD_GET_TL_VARIABLE, TL_CURRENT_PROGRAM, tlsID);
1242 }
1243 
1244 unsigned int
1245 TraCIAPI::TrafficLightScope::getPhase(const std::string& tlsID) const {
1246  return myParent.getInt(CMD_GET_TL_VARIABLE, TL_CURRENT_PHASE, tlsID);
1247 }
1248 
1249 unsigned int
1250 TraCIAPI::TrafficLightScope::getNextSwitch(const std::string& tlsID) const {
1251  return myParent.getInt(CMD_GET_TL_VARIABLE, TL_NEXT_SWITCH, tlsID);
1252 }
1253 
1254 
1255 void
1256 TraCIAPI::TrafficLightScope::setRedYellowGreenState(const std::string& tlsID, const std::string& state) const {
1257  tcpip::Storage content;
1258  content.writeUnsignedByte(TYPE_STRING);
1259  content.writeString(state);
1260  myParent.send_commandSetValue(CMD_SET_TL_VARIABLE, TL_RED_YELLOW_GREEN_STATE, tlsID, content);
1261 }
1262 
1263 void
1264 TraCIAPI::TrafficLightScope::setPhase(const std::string& tlsID, unsigned int index) const {
1265  tcpip::Storage content;
1267  content.writeInt(index);
1268  myParent.send_commandSetValue(CMD_SET_TL_VARIABLE, TL_PHASE_INDEX, tlsID, content);
1269 }
1270 
1271 void
1272 TraCIAPI::TrafficLightScope::setProgram(const std::string& tlsID, const std::string& programID) const {
1273  tcpip::Storage content;
1274  content.writeUnsignedByte(TYPE_STRING);
1275  content.writeString(programID);
1276  myParent.send_commandSetValue(CMD_SET_TL_VARIABLE, TL_PROGRAM, tlsID, content);
1277 }
1278 
1279 void
1280 TraCIAPI::TrafficLightScope::setPhaseDuration(const std::string& tlsID, unsigned int phaseDuration) const {
1281  tcpip::Storage content;
1283  content.writeInt(int(1000 * phaseDuration));
1284  myParent.send_commandSetValue(CMD_SET_TL_VARIABLE, TL_PHASE_DURATION, tlsID, content);
1285 }
1286 
1287 void
1289  tcpip::Storage content;
1291  content.writeInt(5 + 4 * (int)logic.phases.size());
1292  content.writeUnsignedByte(TYPE_STRING);
1293  content.writeString(logic.subID);
1295  content.writeInt(logic.type);
1297  content.writeInt(0);
1299  content.writeInt(logic.currentPhaseIndex);
1301  content.writeInt((int)logic.phases.size());
1302  for (int i = 0; i < (int) logic.phases.size(); ++i) {
1304  content.writeInt(logic.phases[i].duration);
1306  content.writeInt(logic.phases[i].duration1);
1308  content.writeInt(logic.phases[i].duration2);
1309  content.writeUnsignedByte(TYPE_STRING);
1310  content.writeString(logic.phases[i].phase);
1311  }
1312  myParent.send_commandSetValue(CMD_SET_TL_VARIABLE, TL_COMPLETE_PROGRAM_RYG, tlsID, content);
1313 }
1314 
1315 
1316 
1317 
1318 
1319 // ---------------------------------------------------------------------------
1320 // TraCIAPI::VehicleTypeScope-methods
1321 // ---------------------------------------------------------------------------
1322 std::vector<std::string>
1324  return myParent.getStringVector(CMD_GET_VEHICLETYPE_VARIABLE, ID_LIST, "");
1325 }
1326 
1327 SUMOReal
1328 TraCIAPI::VehicleTypeScope::getLength(const std::string& typeID) const {
1329  return myParent.getDouble(CMD_GET_TL_VARIABLE, VAR_LENGTH, typeID);
1330 }
1331 
1332 SUMOReal
1333 TraCIAPI::VehicleTypeScope::getMaxSpeed(const std::string& typeID) const {
1334  return myParent.getDouble(CMD_GET_TL_VARIABLE, VAR_MAXSPEED, typeID);
1335 }
1336 
1337 SUMOReal
1338 TraCIAPI::VehicleTypeScope::getSpeedFactor(const std::string& typeID) const {
1339  return myParent.getDouble(CMD_GET_TL_VARIABLE, VAR_SPEED_FACTOR, typeID);
1340 }
1341 
1342 SUMOReal
1343 TraCIAPI::VehicleTypeScope::getSpeedDeviation(const std::string& typeID) const {
1344  return myParent.getDouble(CMD_GET_TL_VARIABLE, VAR_SPEED_DEVIATION, typeID);
1345 }
1346 
1347 SUMOReal
1348 TraCIAPI::VehicleTypeScope::getAccel(const std::string& typeID) const {
1349  return myParent.getDouble(CMD_GET_TL_VARIABLE, VAR_ACCEL, typeID);
1350 }
1351 
1352 SUMOReal
1353 TraCIAPI::VehicleTypeScope::getDecel(const std::string& typeID) const {
1354  return myParent.getDouble(CMD_GET_TL_VARIABLE, VAR_DECEL, typeID);
1355 }
1356 
1357 SUMOReal
1358 TraCIAPI::VehicleTypeScope::getImperfection(const std::string& typeID) const {
1359  return myParent.getDouble(CMD_GET_TL_VARIABLE, VAR_IMPERFECTION, typeID);
1360 }
1361 
1362 SUMOReal
1363 TraCIAPI::VehicleTypeScope::getTau(const std::string& typeID) const {
1364  return myParent.getDouble(CMD_GET_TL_VARIABLE, VAR_TAU, typeID);
1365 }
1366 
1367 std::string
1368 TraCIAPI::VehicleTypeScope::getVehicleClass(const std::string& typeID) const {
1369  return myParent.getString(CMD_GET_TL_VARIABLE, VAR_VEHICLECLASS, typeID);
1370 }
1371 
1372 std::string
1373 TraCIAPI::VehicleTypeScope::getEmissionClass(const std::string& typeID) const {
1374  return myParent.getString(CMD_GET_TL_VARIABLE, VAR_EMISSIONCLASS, typeID);
1375 }
1376 
1377 std::string
1378 TraCIAPI::VehicleTypeScope::getShapeClass(const std::string& typeID) const {
1379  return myParent.getString(CMD_GET_TL_VARIABLE, VAR_SHAPECLASS, typeID);
1380 }
1381 
1382 SUMOReal
1383 TraCIAPI::VehicleTypeScope::getMinGap(const std::string& typeID) const {
1384  return myParent.getDouble(CMD_GET_TL_VARIABLE, VAR_MINGAP, typeID);
1385 }
1386 
1387 SUMOReal
1388 TraCIAPI::VehicleTypeScope::getWidth(const std::string& typeID) const {
1389  return myParent.getDouble(CMD_GET_TL_VARIABLE, VAR_WIDTH, typeID);
1390 }
1391 
1393 TraCIAPI::VehicleTypeScope::getColor(const std::string& typeID) const {
1394  return myParent.getColor(CMD_GET_TL_VARIABLE, VAR_COLOR, typeID);
1395 }
1396 
1397 
1398 
1399 void
1400 TraCIAPI::VehicleTypeScope::setLength(const std::string& typeID, SUMOReal length) const {
1401  tcpip::Storage content;
1402  content.writeUnsignedByte(TYPE_DOUBLE);
1403  content.writeDouble(length);
1404  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_LENGTH, typeID, content);
1405 }
1406 
1407 void
1408 TraCIAPI::VehicleTypeScope::setMaxSpeed(const std::string& typeID, SUMOReal speed) const {
1409  tcpip::Storage content;
1410  content.writeUnsignedByte(TYPE_DOUBLE);
1411  content.writeDouble(speed);
1412  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_MAXSPEED, typeID, content);
1413 }
1414 
1415 void
1416 TraCIAPI::VehicleTypeScope::setVehicleClass(const std::string& typeID, const std::string& clazz) const {
1417  tcpip::Storage content;
1418  content.writeUnsignedByte(TYPE_STRING);
1419  content.writeString(clazz);
1420  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_VEHICLECLASS, typeID, content);
1421 }
1422 
1423 void
1424 TraCIAPI::VehicleTypeScope::setSpeedFactor(const std::string& typeID, SUMOReal factor) const {
1425  tcpip::Storage content;
1426  content.writeUnsignedByte(TYPE_DOUBLE);
1427  content.writeDouble(factor);
1428  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_SPEED_FACTOR, typeID, content);
1429 }
1430 
1431 void
1432 TraCIAPI::VehicleTypeScope::setSpeedDeviation(const std::string& typeID, SUMOReal deviation) const {
1433  tcpip::Storage content;
1434  content.writeUnsignedByte(TYPE_DOUBLE);
1435  content.writeDouble(deviation);
1436  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_SPEED_DEVIATION, typeID, content);
1437 }
1438 
1439 void
1440 TraCIAPI::VehicleTypeScope::setEmissionClass(const std::string& typeID, const std::string& clazz) const {
1441  tcpip::Storage content;
1442  content.writeUnsignedByte(TYPE_STRING);
1443  content.writeString(clazz);
1444  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_EMISSIONCLASS, typeID, content);
1445 }
1446 
1447 void
1448 TraCIAPI::VehicleTypeScope::setWidth(const std::string& typeID, SUMOReal width) const {
1449  tcpip::Storage content;
1450  content.writeUnsignedByte(TYPE_DOUBLE);
1451  content.writeDouble(width);
1452  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_WIDTH, typeID, content);
1453 }
1454 
1455 void
1456 TraCIAPI::VehicleTypeScope::setMinGap(const std::string& typeID, SUMOReal minGap) const {
1457  tcpip::Storage content;
1458  content.writeUnsignedByte(TYPE_DOUBLE);
1459  content.writeDouble(minGap);
1460  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_MINGAP, typeID, content);
1461 }
1462 
1463 void
1464 TraCIAPI::VehicleTypeScope::setShapeClass(const std::string& typeID, const std::string& clazz) const {
1465  tcpip::Storage content;
1466  content.writeUnsignedByte(TYPE_STRING);
1467  content.writeString(clazz);
1468  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_SHAPECLASS, typeID, content);
1469 }
1470 
1471 void
1472 TraCIAPI::VehicleTypeScope::setAccel(const std::string& typeID, SUMOReal accel) const {
1473  tcpip::Storage content;
1474  content.writeUnsignedByte(TYPE_DOUBLE);
1475  content.writeDouble(accel);
1476  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_ACCEL, typeID, content);
1477 }
1478 
1479 void
1480 TraCIAPI::VehicleTypeScope::setDecel(const std::string& typeID, SUMOReal decel) const {
1481  tcpip::Storage content;
1482  content.writeUnsignedByte(TYPE_DOUBLE);
1483  content.writeDouble(decel);
1484  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_DECEL, typeID, content);
1485 }
1486 
1487 void
1488 TraCIAPI::VehicleTypeScope::setImperfection(const std::string& typeID, SUMOReal imperfection) const {
1489  tcpip::Storage content;
1490  content.writeUnsignedByte(TYPE_DOUBLE);
1491  content.writeDouble(imperfection);
1492  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_IMPERFECTION, typeID, content);
1493 }
1494 
1495 void
1496 TraCIAPI::VehicleTypeScope::setTau(const std::string& typeID, SUMOReal tau) const {
1497  tcpip::Storage content;
1498  content.writeUnsignedByte(TYPE_DOUBLE);
1499  content.writeDouble(tau);
1500  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_TAU, typeID, content);
1501 }
1502 
1503 void
1504 TraCIAPI::VehicleTypeScope::setColor(const std::string& typeID, const TraCIColor& c) const {
1505  tcpip::Storage content;
1506  content.writeUnsignedByte(TYPE_COLOR);
1507  content.writeUnsignedByte(c.r);
1508  content.writeUnsignedByte(c.g);
1509  content.writeUnsignedByte(c.b);
1510  content.writeUnsignedByte(c.a);
1511  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_COLOR, typeID, content);
1512 }
1513 
1514 
1515 
1516 /****************************************************************************/
1517