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