SUMO - Simulation of Urban MObility
TraCITestClient.cpp
Go to the documentation of this file.
1 /****************************************************************************/
13 /****************************************************************************/
14 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
15 // Copyright (C) 2008-2014 DLR (http://www.dlr.de/) and contributors
16 /****************************************************************************/
17 //
18 // This file is part of SUMO.
19 // SUMO is free software: you can redistribute it and/or modify
20 // it under the terms of the GNU General Public License as published by
21 // the Free Software Foundation, either version 3 of the License, or
22 // (at your option) any later version.
23 //
24 /****************************************************************************/
25 /* =========================================================================
26  * included modules
27  * ======================================================================= */
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <vector>
35 #include <iostream>
36 #include <iomanip>
37 #include <fstream>
38 #include <sstream>
39 #include <ctime>
40 #include <cstdlib>
41 
42 #define BUILD_TCPIP
43 #include <foreign/tcpip/storage.h>
44 #include <foreign/tcpip/socket.h>
45 
47 #include <utils/common/SUMOTime.h>
48 #include "TraCITestClient.h"
49 
50 #ifdef CHECK_MEMORY_LEAKS
51 #include <foreign/nvwa/debug_new.h>
52 #endif // CHECK_MEMORY_LEAKS
53 
54 
55 // ===========================================================================
56 // method definitions
57 // ===========================================================================
58 TraCITestClient::TraCITestClient(std::string outputFileName)
59  : outputFileName(outputFileName), answerLog("") {
60  answerLog.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
61  answerLog.setf(std::ios::showpoint); // print decimal point
62  answerLog << std::setprecision(2);
63 }
64 
65 
67  writeResult();
68 }
69 
70 
71 bool
72 TraCITestClient::run(std::string fileName, int port, std::string host) {
73  std::ifstream defFile;
74  std::string fileContentStr;
75  std::stringstream fileContent;
76  std::string lineCommand;
77  std::stringstream msg;
78  int repNo = 1;
79  bool commentRead = false;
80 
81  // try to connect
82  try {
83  TraCIAPI::connect(host, port);
84  } catch (tcpip::SocketException& e) {
85  std::stringstream msg;
86  msg << "#Error while connecting: " << e.what();
87  errorMsg(msg);
88  return false;
89  }
90 
91  // read definition file and trigger commands according to it
92  defFile.open(fileName.c_str());
93  if (!defFile) {
94  msg << "Can not open definition file " << fileName << std::endl;
95  errorMsg(msg);
96  return false;
97  }
98  defFile.unsetf(std::ios::dec);
99 
100  while (defFile >> lineCommand) {
101  repNo = 1;
102  if (lineCommand.compare("%") == 0) {
103  // a comment was read
104  commentRead = !commentRead;
105  continue;
106  }
107  if (commentRead) {
108  // wait until end of comment is reached
109  continue;
110  }
111  if (lineCommand.compare("repeat") == 0) {
112  defFile >> repNo;
113  defFile >> lineCommand;
114  }
115  if (lineCommand.compare("simstep2") == 0) {
116  // read parameter for command simulation step and trigger command
117  std::string time;
118  defFile >> time;
119  for (int i = 0; i < repNo; i++) {
121  }
122  } else if (lineCommand.compare("getvariable") == 0) {
123  // trigger command GetXXXVariable
124  int domID, varID;
125  std::string objID;
126  defFile >> domID >> varID >> objID;
127  commandGetVariable(domID, varID, objID);
128  } else if (lineCommand.compare("getvariable_plus") == 0) {
129  // trigger command GetXXXVariable with one parameter
130  int domID, varID;
131  std::string objID;
132  defFile >> domID >> varID >> objID;
133  std::stringstream msg;
134  tcpip::Storage tmp;
135  setValueTypeDependant(tmp, defFile, msg);
136  std::string msgS = msg.str();
137  if (msgS != "") {
138  errorMsg(msg);
139  }
140  commandGetVariable(domID, varID, objID, &tmp);
141  } else if (lineCommand.compare("subscribevariable") == 0) {
142  // trigger command SubscribeXXXVariable
143  int domID, varNo;
144  std::string beginTime, endTime;
145  std::string objID;
146  defFile >> domID >> objID >> beginTime >> endTime >> varNo;
147  commandSubscribeObjectVariable(domID, objID, string2time(beginTime), string2time(endTime), varNo, defFile);
148  } else if (lineCommand.compare("subscribecontext") == 0) {
149  // trigger command SubscribeXXXVariable
150  int domID, varNo, domain;
151  SUMOReal range;
152  std::string beginTime, endTime;
153  std::string objID;
154  defFile >> domID >> objID >> beginTime >> endTime >> domain >> range >> varNo;
155  commandSubscribeContextVariable(domID, objID, string2time(beginTime), string2time(endTime), domain, range, varNo, defFile);
156  } else if (lineCommand.compare("setvalue") == 0) {
157  // trigger command SetXXXValue
158  int domID, varID;
159  std::string objID;
160  defFile >> domID >> varID >> objID;
161  commandSetValue(domID, varID, objID, defFile);
162  } else {
163  msg << "Error in definition file: " << lineCommand << " is not a valid command";
164  errorMsg(msg);
165  commandClose();
166  close();
167  return false;
168  }
169  }
170  defFile.close();
171  commandClose();
172  close();
173  return true;
174 }
175 
176 
177 // ---------- Commands handling
178 void
181  answerLog << std::endl << "-> Command sent: <SimulationStep2>:" << std::endl;
182  tcpip::Storage inMsg;
183  try {
184  std::string acknowledgement;
185  check_resultState(inMsg, CMD_SIMSTEP2, false, &acknowledgement);
186  answerLog << acknowledgement << std::endl;
188  } catch (tcpip::SocketException& e) {
189  answerLog << e.what() << std::endl;
190  }
191 }
192 
193 
194 void
197  answerLog << std::endl << "-> Command sent: <Close>:" << std::endl;
198  try {
199  tcpip::Storage inMsg;
200  std::string acknowledgement;
201  check_resultState(inMsg, CMD_CLOSE, false, &acknowledgement);
202  answerLog << acknowledgement << std::endl;
203  } catch (tcpip::SocketException& e) {
204  answerLog << e.what() << std::endl;
205  }
206 }
207 
208 
209 void
210 TraCITestClient::commandGetVariable(int domID, int varID, const std::string& objID, tcpip::Storage* addData) {
211  send_commandGetVariable(domID, varID, objID, addData);
212  answerLog << std::endl << "-> Command sent: <GetVariable>:" << std::endl
213  << " domID=" << domID << " varID=" << varID
214  << " objID=" << objID << std::endl;
215  tcpip::Storage inMsg;
216  try {
217  std::string acknowledgement;
218  check_resultState(inMsg, domID, false, &acknowledgement);
219  answerLog << acknowledgement << std::endl;
220  } catch (tcpip::SocketException& e) {
221  answerLog << e.what() << std::endl;
222  return;
223  }
224  check_commandGetResult(inMsg, domID, -1, false);
225  // report result state
226  try {
227  int variableID = inMsg.readUnsignedByte();
228  std::string objectID = inMsg.readString();
229  answerLog << " CommandID=" << (domID + 0x10) << " VariableID=" << variableID << " ObjectID=" << objectID;
230  int valueDataType = inMsg.readUnsignedByte();
231  answerLog << " valueDataType=" << valueDataType;
232  readAndReportTypeDependent(inMsg, valueDataType);
233  } catch (tcpip::SocketException& e) {
234  std::stringstream msg;
235  msg << "Error while receiving command: " << e.what();
236  errorMsg(msg);
237  return;
238  }
239 }
240 
241 
242 void
243 TraCITestClient::commandSetValue(int domID, int varID, const std::string& objID, std::ifstream& defFile) {
244  std::stringstream msg;
245  tcpip::Storage inMsg, tmp;
246  setValueTypeDependant(tmp, defFile, msg);
247  std::string msgS = msg.str();
248  if (msgS != "") {
249  errorMsg(msg);
250  }
251  send_commandSetValue(domID, varID, objID, tmp);
252  answerLog << std::endl << "-> Command sent: <SetValue>:" << std::endl
253  << " domID=" << domID << " varID=" << varID
254  << " objID=" << objID << std::endl;
255  try {
256  std::string acknowledgement;
257  check_resultState(inMsg, domID, false, &acknowledgement);
258  answerLog << acknowledgement << std::endl;
259  } catch (tcpip::SocketException& e) {
260  answerLog << e.what() << std::endl;
261  }
262 }
263 
264 
265 void
266 TraCITestClient::commandSubscribeObjectVariable(int domID, const std::string& objID, int beginTime, int endTime, int varNo, std::ifstream& defFile) {
267  std::vector<int> vars;
268  for (int i = 0; i < varNo; ++i) {
269  int var;
270  defFile >> var;
271  // variable id
272  vars.push_back(var);
273  }
274  send_commandSubscribeObjectVariable(domID, objID, beginTime, endTime, vars);
275  answerLog << std::endl << "-> Command sent: <SubscribeVariable>:" << std::endl
276  << " domID=" << domID << " objID=" << objID << " with " << varNo << " variables" << std::endl;
277  tcpip::Storage inMsg;
278  try {
279  std::string acknowledgement;
280  check_resultState(inMsg, domID, false, &acknowledgement);
281  answerLog << acknowledgement << std::endl;
282  validateSubscription(inMsg);
283  } catch (tcpip::SocketException& e) {
284  answerLog << e.what() << std::endl;
285  }
286 }
287 
288 
289 void
290 TraCITestClient::commandSubscribeContextVariable(int domID, const std::string& objID, int beginTime, int endTime,
291  int domain, SUMOReal range, int varNo, std::ifstream& defFile) {
292  std::vector<int> vars;
293  for (int i = 0; i < varNo; ++i) {
294  int var;
295  defFile >> var;
296  // variable id
297  vars.push_back(var);
298  }
299  send_commandSubscribeObjectContext(domID, objID, beginTime, endTime, domain, range, vars);
300  answerLog << std::endl << "-> Command sent: <SubscribeContext>:" << std::endl
301  << " domID=" << domID << " objID=" << objID << " domain=" << domain << " range=" << range
302  << " with " << varNo << " variables" << std::endl;
303  tcpip::Storage inMsg;
304  try {
305  std::string acknowledgement;
306  check_resultState(inMsg, domID, false, &acknowledgement);
307  answerLog << acknowledgement << std::endl;
308  validateSubscription(inMsg);
309  } catch (tcpip::SocketException& e) {
310  answerLog << e.what() << std::endl;
311  }
312 }
313 
314 
315 // ---------- Report helper
316 void
318  time_t seconds;
319  tm* locTime;
320  std::ofstream outFile(outputFileName.c_str());
321  if (!outFile) {
322  std::cerr << "Unable to write result file" << std::endl;
323  }
324  time(&seconds);
325  locTime = localtime(&seconds);
326  outFile << "TraCITestClient output file. Date: " << asctime(locTime) << std::endl;
327  outFile << answerLog.str();
328  outFile.close();
329 }
330 
331 
332 void
333 TraCITestClient::errorMsg(std::stringstream& msg) {
334  std::cerr << msg.str() << std::endl;
335  answerLog << "----" << std::endl << msg.str() << std::endl;
336 }
337 
338 
339 
340 
341 
342 
343 bool
345  try {
346  int noSubscriptions = inMsg.readInt();
347  for (int s = 0; s < noSubscriptions; ++s) {
348  if (!validateSubscription(inMsg)) {
349  return false;
350  }
351  }
352  } catch (std::invalid_argument& e) {
353  answerLog << "#Error while reading message:" << e.what() << std::endl;
354  return false;
355  }
356  return true;
357 }
358 
359 
360 bool
362  try {
363  int length = inMsg.readUnsignedByte();
364  if (length == 0) {
365  length = inMsg.readInt();
366  }
367  int cmdId = inMsg.readUnsignedByte();
369  answerLog << " CommandID=" << cmdId;
370  answerLog << " ObjectID=" << inMsg.readString();
371  unsigned int varNo = inMsg.readUnsignedByte();
372  answerLog << " #variables=" << varNo << std::endl;
373  for (unsigned int i = 0; i < varNo; ++i) {
374  answerLog << " VariableID=" << inMsg.readUnsignedByte();
375  bool ok = inMsg.readUnsignedByte() == RTYPE_OK;
376  answerLog << " ok=" << ok;
377  int valueDataType = inMsg.readUnsignedByte();
378  answerLog << " valueDataType=" << valueDataType;
379  readAndReportTypeDependent(inMsg, valueDataType);
380  }
382  answerLog << " CommandID=" << cmdId;
383  answerLog << " ObjectID=" << inMsg.readString();
384  answerLog << " Domain=" << inMsg.readUnsignedByte();
385  unsigned int varNo = inMsg.readUnsignedByte();
386  answerLog << " #variables=" << varNo << std::endl;
387  unsigned int objNo = inMsg.readInt();
388  answerLog << " #objects=" << objNo << std::endl;
389  for (unsigned int j = 0; j < objNo; ++j) {
390  answerLog << " ObjectID=" << inMsg.readString() << std::endl;
391  for (unsigned int i = 0; i < varNo; ++i) {
392  answerLog << " VariableID=" << inMsg.readUnsignedByte();
393  bool ok = inMsg.readUnsignedByte() == RTYPE_OK;
394  answerLog << " ok=" << ok;
395  int valueDataType = inMsg.readUnsignedByte();
396  answerLog << " valueDataType=" << valueDataType;
397  readAndReportTypeDependent(inMsg, valueDataType);
398  }
399  }
400  } else {
401  answerLog << "#Error: received response with command id: " << cmdId << " but expected a subscription response (0xe0-0xef / 0x90-0x9f)" << std::endl;
402  return false;
403  }
404  } catch (std::invalid_argument& e) {
405  answerLog << "#Error while reading message:" << e.what() << std::endl;
406  return false;
407  }
408  return true;
409 }
410 
411 
412 
413 
414 
415 
416 
417 // ---------- Conversion helper
418 int
419 TraCITestClient::setValueTypeDependant(tcpip::Storage& into, std::ifstream& defFile, std::stringstream& msg) {
420  std::string dataTypeS;
421  defFile >> dataTypeS;
422  if (dataTypeS == "<airDist>") {
424  return 1;
425  } else if (dataTypeS == "<drivingDist>") {
427  return 1;
428  } else if (dataTypeS == "<objSubscription>") {
429  int beginTime, endTime, numVars;
430  defFile >> beginTime >> endTime >> numVars;
431  into.writeInt(beginTime);
432  into.writeInt(endTime);
433  into.writeInt(numVars);
434  for (int i = 0; i < numVars; ++i) {
435  int var;
436  defFile >> var;
437  into.writeUnsignedByte(var);
438  }
439  return 4 + 4 + 4 + numVars;
440  }
441  int valI;
442  double valF;
443  if (dataTypeS == "<int>") {
444  defFile >> valI;
446  into.writeInt(valI);
447  return 4 + 1;
448  } else if (dataTypeS == "<byte>") {
449  defFile >> valI;
451  into.writeByte(valI);
452  return 1 + 1;
453  } else if (dataTypeS == "<ubyte>") {
454  defFile >> valI;
456  into.writeUnsignedByte(valI);
457  return 1 + 1;
458  } else if (dataTypeS == "<float>") {
459  defFile >> valF;
461  into.writeFloat(float(valF));
462  return 4 + 1;
463  } else if (dataTypeS == "<double>") {
464  defFile >> valF;
466  into.writeDouble(valF);
467  return 8 + 1;
468  } else if (dataTypeS == "<string>") {
469  std::string valueS;
470  defFile >> valueS;
471  if (valueS == "\"\"") {
472  valueS = "";
473  }
475  into.writeString(valueS);
476  return 4 + 1 + (int) valueS.length();
477  } else if (dataTypeS == "<string*>") {
478  std::vector<std::string> slValue;
479  defFile >> valI;
480  int length = 1 + 4;
481  for (int i = 0; i < valI; ++i) {
482  std::string tmp;
483  defFile >> tmp;
484  slValue.push_back(tmp);
485  length += 4 + int(tmp.length());
486  }
488  into.writeStringList(slValue);
489  return length;
490  } else if (dataTypeS == "<compound>") {
491  defFile >> valI;
493  into.writeInt(valI);
494  int length = 1 + 4;
495  for (int i = 0; i < valI; ++i) {
496  length += setValueTypeDependant(into, defFile, msg);
497  }
498  return length;
499  } else if (dataTypeS == "<color>") {
500  defFile >> valI;
502  into.writeUnsignedByte(valI);
503  for (int i = 0; i < 3; ++i) {
504  defFile >> valI;
505  into.writeUnsignedByte(valI);
506  }
507  return 1 + 4;
508  } else if (dataTypeS == "<position2D>") {
509  defFile >> valF;
511  into.writeDouble(valF);
512  defFile >> valF;
513  into.writeDouble(valF);
514  return 1 + 8 + 8;
515  } else if (dataTypeS == "<position3D>") {
516  defFile >> valF;
518  into.writeDouble(valF);
519  defFile >> valF;
520  into.writeDouble(valF);
521  defFile >> valF;
522  into.writeDouble(valF);
523  return 1 + 8 + 8 + 8;
524  } else if (dataTypeS == "<positionRoadmap>") {
525  std::string valueS;
526  defFile >> valueS;
528  into.writeString(valueS);
529  int length = 1 + 8 + (int) valueS.length();
530  defFile >> valF;
531  into.writeDouble(valF);
532  defFile >> valI;
533  into.writeUnsignedByte(valI);
534  return length + 4 + 1;
535  } else if (dataTypeS == "<shape>") {
536  defFile >> valI;
538  into.writeUnsignedByte(valI);
539  int length = 1 + 1;
540  for (int i = 0; i < valI; ++i) {
541  double x, y;
542  defFile >> x >> y;
543  into.writeDouble(x);
544  into.writeDouble(y);
545  length += 8 + 8;
546  }
547  return length;
548  }
549  msg << "## Unknown data type: " << dataTypeS;
550  return 0;
551 }
552 
553 
554 void
556  if (valueDataType == TYPE_UBYTE) {
557  int ubyte = inMsg.readUnsignedByte();
558  answerLog << " Unsigned Byte Value: " << ubyte << std::endl;
559  } else if (valueDataType == TYPE_BYTE) {
560  int byte = inMsg.readByte();
561  answerLog << " Byte value: " << byte << std::endl;
562  } else if (valueDataType == TYPE_INTEGER) {
563  int integer = inMsg.readInt();
564  answerLog << " Int value: " << integer << std::endl;
565  } else if (valueDataType == TYPE_FLOAT) {
566  float floatv = inMsg.readFloat();
567  if (floatv < 0.1 && floatv > 0) {
568  answerLog.setf(std::ios::scientific, std::ios::floatfield);
569  }
570  answerLog << " float value: " << floatv << std::endl;
571  answerLog.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
572  answerLog.setf(std::ios::showpoint); // print decimal point
573  answerLog << std::setprecision(2);
574  } else if (valueDataType == TYPE_DOUBLE) {
575  double doublev = inMsg.readDouble();
576  answerLog << " Double value: " << doublev << std::endl;
577  } else if (valueDataType == TYPE_BOUNDINGBOX) {
578  SUMOReal lowerLeftX = inMsg.readDouble();
579  SUMOReal lowerLeftY = inMsg.readDouble();
580  SUMOReal upperRightX = inMsg.readDouble();
581  SUMOReal upperRightY = inMsg.readDouble();
582  answerLog << " BoundaryBoxValue: lowerLeft x=" << lowerLeftX
583  << " y=" << lowerLeftY << " upperRight x=" << upperRightX
584  << " y=" << upperRightY << std::endl;
585  } else if (valueDataType == TYPE_POLYGON) {
586  int length = inMsg.readUnsignedByte();
587  answerLog << " PolygonValue: ";
588  for (int i = 0; i < length; i++) {
589  SUMOReal x = inMsg.readDouble();
590  SUMOReal y = inMsg.readDouble();
591  answerLog << "(" << x << "," << y << ") ";
592  }
593  answerLog << std::endl;
594  } else if (valueDataType == POSITION_3D) {
595  SUMOReal x = inMsg.readDouble();
596  SUMOReal y = inMsg.readDouble();
597  SUMOReal z = inMsg.readDouble();
598  answerLog << " Position3DValue: " << std::endl;
599  answerLog << " x: " << x << " y: " << y
600  << " z: " << z << std::endl;
601  } else if (valueDataType == POSITION_ROADMAP) {
602  std::string roadId = inMsg.readString();
603  SUMOReal pos = inMsg.readDouble();
604  int laneId = inMsg.readUnsignedByte();
605  answerLog << " RoadMapPositionValue: roadId=" << roadId
606  << " pos=" << pos
607  << " laneId=" << laneId << std::endl;
608  } else if (valueDataType == TYPE_TLPHASELIST) {
609  int length = inMsg.readUnsignedByte();
610  answerLog << " TLPhaseListValue: length=" << length << std::endl;
611  for (int i = 0; i < length; i++) {
612  std::string pred = inMsg.readString();
613  std::string succ = inMsg.readString();
614  int phase = inMsg.readUnsignedByte();
615  answerLog << " precRoad=" << pred << " succRoad=" << succ
616  << " phase=";
617  switch (phase) {
618  case TLPHASE_RED:
619  answerLog << "red" << std::endl;
620  break;
621  case TLPHASE_YELLOW:
622  answerLog << "yellow" << std::endl;
623  break;
624  case TLPHASE_GREEN:
625  answerLog << "green" << std::endl;
626  break;
627  default:
628  answerLog << "#Error: unknown phase value" << (int)phase << std::endl;
629  return;
630  }
631  }
632  } else if (valueDataType == TYPE_STRING) {
633  std::string s = inMsg.readString();
634  answerLog << " string value: " << s << std::endl;
635  } else if (valueDataType == TYPE_STRINGLIST) {
636  std::vector<std::string> s = inMsg.readStringList();
637  answerLog << " string list value: [ " << std::endl;
638  for (std::vector<std::string>::iterator i = s.begin(); i != s.end(); ++i) {
639  if (i != s.begin()) {
640  answerLog << ", ";
641  }
642  answerLog << '"' << *i << '"';
643  }
644  answerLog << " ]" << std::endl;
645  } else if (valueDataType == TYPE_COMPOUND) {
646  int no = inMsg.readInt();
647  answerLog << " compound value with " << no << " members: [ " << std::endl;
648  for (int i = 0; i < no; ++i) {
649  int currentValueDataType = inMsg.readUnsignedByte();
650  answerLog << " valueDataType=" << currentValueDataType;
651  readAndReportTypeDependent(inMsg, currentValueDataType);
652  }
653  answerLog << " ]" << std::endl;
654  } else if (valueDataType == POSITION_2D) {
655  SUMOReal xv = inMsg.readDouble();
656  SUMOReal yv = inMsg.readDouble();
657  answerLog << " position value: (" << xv << "," << yv << ")" << std::endl;
658  } else if (valueDataType == TYPE_COLOR) {
659  int r = inMsg.readUnsignedByte();
660  int g = inMsg.readUnsignedByte();
661  int b = inMsg.readUnsignedByte();
662  int a = inMsg.readUnsignedByte();
663  answerLog << " color value: (" << r << "," << g << "," << b << "," << a << ")" << std::endl;
664  } else {
665  answerLog << "#Error: unknown valueDataType!" << std::endl;
666  }
667 }
668 
669 
#define RESPONSE_SUBSCRIBE_INDUCTIONLOOP_CONTEXT
void readAndReportTypeDependent(tcpip::Storage &inMsg, int valueDataType)
Reads a value of the given type from the given storage and reports it.
#define REQUEST_DRIVINGDIST
void close()
Closes the connection.
Definition: TraCIAPI.cpp:82
void connect(const std::string &host, int port)
Connects to the specified SUMO server.
Definition: TraCIAPI.cpp:69
#define TYPE_COMPOUND
std::stringstream answerLog
Stream containing the log.
#define CMD_CLOSE
virtual std::vector< std::string > readStringList()
#define RESPONSE_SUBSCRIBE_GUI_VARIABLE
#define POSITION_2D
void commandSubscribeContextVariable(int domID, const std::string &objID, int beginTime, int endTime, int domain, SUMOReal range, int varNo, std::ifstream &defFile)
Sends and validates a SubscribeContext command.
int setValueTypeDependant(tcpip::Storage &into, std::ifstream &defFile, std::stringstream &msg)
Parses the next value type / value pair from the stream and inserts it into the storage.
void send_commandClose() const
Sends a Close command.
Definition: TraCIAPI.cpp:106
void send_commandSubscribeObjectContext(int domID, const std::string &objID, int beginTime, int endTime, int domain, SUMOReal range, const std::vector< int > &vars) const
Sends a SubscribeContext request.
Definition: TraCIAPI.cpp:193
#define TYPE_UBYTE
#define RTYPE_OK
#define POSITION_ROADMAP
virtual double readDouble()
#define TYPE_POLYGON
bool validateSubscription(tcpip::Storage &inMsg)
Validates whether the given message is a valid subscription return message.
#define TYPE_COLOR
#define TYPE_STRINGLIST
#define POSITION_3D
std::string outputFileName
The name of the file to write the results log into.
virtual void writeUnsignedByte(int)
virtual void writeInt(int)
#define TLPHASE_RED
#define TYPE_STRING
virtual int readUnsignedByte()
#define RESPONSE_SUBSCRIBE_INDUCTIONLOOP_VARIABLE
bool validateSimulationStep2(tcpip::Storage &inMsg)
Validates whether the given message is a valid answer to CMD_SIMSTEP2.
void commandSetValue(int domID, int varID, const std::string &objID, std::ifstream &defFile)
Sends and validates a SetVariable command.
void send_commandSimulationStep(SUMOTime time) const
Sends a SimulationStep command.
Definition: TraCIAPI.cpp:93
#define TLPHASE_YELLOW
#define TYPE_FLOAT
#define TYPE_TLPHASELIST
virtual int readInt()
void send_commandGetVariable(int domID, int varID, const std::string &objID, tcpip::Storage *add=0) const
Sends a GetVariable request.
Definition: TraCIAPI.cpp:117
void writeResult()
Writes the results file.
virtual void writeByte(int)
#define TYPE_BOUNDINGBOX
bool run(std::string fileName, int port, std::string host="localhost")
Runs a test.
virtual void writeStringList(const std::vector< std::string > &s)
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:48
virtual std::string readString()
void commandSubscribeObjectVariable(int domID, const std::string &objID, int beginTime, int endTime, int varNo, std::ifstream &defFile)
Sends and validates a SubscribeVariable command.
TraCITestClient(std::string outputFileName="testclient_result.out")
Constructor.
virtual void writeFloat(float)
void errorMsg(std::stringstream &msg)
Writes an error message.
#define TLPHASE_GREEN
#define RESPONSE_SUBSCRIBE_GUI_CONTEXT
void send_commandSubscribeObjectVariable(int domID, const std::string &objID, int beginTime, int endTime, const std::vector< int > &vars) const
Sends a SubscribeVariable request.
Definition: TraCIAPI.cpp:165
virtual void writeString(const std::string &s)
virtual const char * what() const
Definition: socket.h:70
#define REQUEST_AIRDIST
#define TYPE_DOUBLE
virtual float readFloat()
#define TYPE_BYTE
void check_resultState(tcpip::Storage &inMsg, int command, bool ignoreCommandId=false, std::string *acknowledgement=0) const
Validates the result state of a command.
Definition: TraCIAPI.cpp:226
void commandClose()
Sends and validates a Close command.
virtual void writeDouble(double)
void send_commandSetValue(int domID, int varID, const std::string &objID, tcpip::Storage &content) const
Sends a SetVariable request.
Definition: TraCIAPI.cpp:144
#define SUMOReal
Definition: config.h:215
void check_commandGetResult(tcpip::Storage &inMsg, int command, int expectedType=-1, bool ignoreCommandId=false) const
Definition: TraCIAPI.cpp:265
void commandGetVariable(int domID, int varID, const std::string &objID, tcpip::Storage *addData=0)
Sends and validates a GetVariable command.
void commandSimulationStep(SUMOTime time)
Sends and validates a simulation step command.
#define TYPE_INTEGER
#define CMD_SIMSTEP2
virtual int readByte()
~TraCITestClient()
Destructor.