SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00011 /****************************************************************************/ 00012 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00013 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00014 /****************************************************************************/ 00015 // 00016 // This file is part of SUMO. 00017 // SUMO is free software: you can redistribute it and/or modify 00018 // it under the terms of the GNU General Public License as published by 00019 // the Free Software Foundation, either version 3 of the License, or 00020 // (at your option) any later version. 00021 // 00022 /****************************************************************************/ 00023 #ifndef TRACITESTCLIENT_H 00024 #define TRACITESTCLIENT_H 00025 00026 // =========================================================================== 00027 // included modules 00028 // =========================================================================== 00029 #include <string> 00030 #include <sstream> 00031 #include <vector> 00032 00033 #include <foreign/tcpip/socket.h> 00034 #include <utils/common/SUMOTime.h> 00035 00036 namespace testclient { 00037 // =========================================================================== 00038 // Definitions 00039 // =========================================================================== 00040 struct Position { 00041 SUMOReal x; 00042 SUMOReal y; 00043 }; 00044 00045 struct Position3D { 00046 SUMOReal x; 00047 SUMOReal y; 00048 SUMOReal z; 00049 }; 00050 00051 struct PositionRoadMap { 00052 std::string roadId; 00053 SUMOReal pos; 00054 int laneId; 00055 }; 00056 00057 struct BoundingBox { 00058 Position lowerLeft; 00059 Position upperRight; 00060 }; 00061 00062 typedef std::vector<Position> Polygon; 00063 00064 struct TLPhase { 00065 std::string precRoadId; 00066 std::string succRoadId; 00067 int phase; 00068 }; 00069 00070 typedef std::vector<TLPhase> TLPhaseList; 00071 00072 // =========================================================================== 00073 // class definitions 00074 // =========================================================================== 00078 class TraCITestClient { 00079 00080 public: 00081 TraCITestClient(std::string outputFileName = "testclient_result.out"); 00082 00083 ~TraCITestClient(); 00084 00085 bool run(std::string fileName, int port, std::string host = "localhost"); 00086 00087 bool connect(int port, std::string host = "localhost"); 00088 00089 bool close(); 00090 00091 // simulation commands 00092 void commandSimulationStep2(SUMOTime time); 00093 00094 void commandPositionConversion(testclient::Position pos, int posId); 00095 void commandPositionConversion(testclient::Position3D pos, int posId); 00096 void commandPositionConversion(testclient::PositionRoadMap pos, int posId); 00097 00098 void commandDistanceRequest(testclient::Position pos1, testclient::Position pos2, int flag); 00099 void commandDistanceRequest(testclient::Position3D pos1, testclient::Position3D pos2, int flag); 00100 void commandDistanceRequest(testclient::Position pos1, testclient::Position3D pos2, int flag); 00101 void commandDistanceRequest(testclient::Position3D pos1, testclient::Position pos2, int flag); 00102 void commandDistanceRequest(testclient::PositionRoadMap pos1, testclient::PositionRoadMap pos2, int flag); 00103 void commandDistanceRequest(testclient::PositionRoadMap pos1, testclient::Position pos2, int flag); 00104 void commandDistanceRequest(testclient::PositionRoadMap pos1, testclient::Position3D pos2, int flag); 00105 void commandDistanceRequest(testclient::Position pos1, testclient::PositionRoadMap pos2, int flag); 00106 void commandDistanceRequest(testclient::Position3D pos1, testclient::PositionRoadMap pos2, int flag); 00107 00108 void commandGetVariable(int domID, int varID, const std::string& objID); 00109 void commandGetVariablePlus(int domID, int varID, const std::string& objID, std::ifstream& defFile); 00110 void commandSubscribeVariable(int domID, const std::string& objID, int beginTime, int endTime, int varNo, std::ifstream& defFile); 00111 void commandSetValue(int domID, int varID, const std::string& objID, std::ifstream& defFile); 00112 00113 void commandClose(); 00114 00115 private: 00116 void writeResult(); 00117 00118 void errorMsg(std::stringstream& msg); 00119 00120 void commandPositionConversion(testclient::Position* pos2D, 00121 testclient::Position3D* pos3D, 00122 testclient::PositionRoadMap* posRoad, 00123 int posId); 00124 00125 void commandDistanceRequest(testclient::Position* pos1_2D, 00126 testclient::Position3D* pos1_3D, 00127 testclient::PositionRoadMap* pos1_Road, 00128 testclient::Position* pos2_2D, 00129 testclient::Position3D* pos2_3D, 00130 testclient::PositionRoadMap* pos2_Road, 00131 int flag); 00132 00133 // validation of received command responses 00134 bool reportResultState(tcpip::Storage& inMsg, int command, bool ignoreCommandId = false); 00135 00136 bool validateSimulationStep2(tcpip::Storage& inMsg); 00137 bool validateSubscription(tcpip::Storage& inMsg); 00138 00139 bool validatePositionConversion(tcpip::Storage& inMsg); 00140 00141 bool validateDistanceRequest(tcpip::Storage& inMsg); 00142 00143 bool readAndReportTypeDependent(tcpip::Storage& inMsg, int valueDataType); 00144 00145 00153 int setValueTypeDependant(tcpip::Storage& into, std::ifstream& defFile, std::stringstream& msg); 00154 00155 00156 00157 private: 00158 tcpip::Socket* socket; 00159 00160 std::string outputFileName; 00161 00162 std::stringstream answerLog; 00163 }; 00164 00165 } 00166 00167 #endif