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