00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef TRACITESTCLIENT_H
00020 #define TRACITESTCLIENT_H
00021
00022
00023
00024
00025 #include <string>
00026 #include <sstream>
00027 #include <vector>
00028
00029 #include <foreign/tcpip/socket.h>
00030 #include <utils/common/SUMOTime.h>
00031
00032 namespace testclient {
00033
00034
00035
00036 struct Position2D {
00037 float x;
00038 float y;
00039 };
00040
00041 struct Position3D {
00042 float x;
00043 float y;
00044 float z;
00045 };
00046
00047 struct PositionRoadMap {
00048 std::string roadId;
00049 float pos;
00050 int laneId;
00051 };
00052
00053 struct BoundingBox {
00054 Position2D lowerLeft;
00055 Position2D upperRight;
00056 };
00057
00058 typedef std::vector<Position2D> Polygon;
00059
00060 struct TLPhase {
00061 std::string precRoadId;
00062 std::string succRoadId;
00063 int phase;
00064 };
00065
00066 typedef std::vector<TLPhase> TLPhaseList;
00067
00068
00069
00070
00074 class TraCITestClient {
00075
00076 public:
00077 TraCITestClient(std::string outputFileName = "testclient_result.out");
00078
00079 ~TraCITestClient();
00080
00081 bool run(std::string fileName, int port, std::string host = "localhost");
00082
00083 bool connect(int port, std::string host = "localhost");
00084
00085 bool close();
00086
00087
00088 void commandSimulationStep(SUMOTime time, int posFormat);
00089 void commandSimulationStep2(SUMOTime time);
00090
00091 void commandSetMaximumSpeed(int nodeId, float speed);
00092
00093 void commandStopNode(int nodeId, testclient::Position2D pos, float radius, SUMOTime waitTime);
00094 void commandStopNode(int nodeId, testclient::Position3D pos, float radius, SUMOTime waitTime);
00095 void commandStopNode(int nodeId, testclient::PositionRoadMap pos, float radius, SUMOTime waitTime);
00096
00097 void commandChangeLane(int nodeId, int laneId, SUMOTime fixTime);
00098
00099 void commandSlowDown(int nodeId, float minSpeed, SUMOTime timeInterval);
00100
00101 void commandChangeRoute(int nodeId, std::string roadId, double travelTime);
00102
00103 void commandChangeTarget(int nodeId, std::string roadId);
00104
00105 void commandPositionConversion(testclient::Position2D pos, int posId);
00106 void commandPositionConversion(testclient::Position3D pos, int posId);
00107 void commandPositionConversion(testclient::PositionRoadMap pos, int posId);
00108
00109 void commandDistanceRequest(testclient::Position2D pos1, testclient::Position2D pos2, int flag);
00110 void commandDistanceRequest(testclient::Position3D pos1, testclient::Position3D pos2, int flag);
00111 void commandDistanceRequest(testclient::Position2D pos1, testclient::Position3D pos2, int flag);
00112 void commandDistanceRequest(testclient::Position3D pos1, testclient::Position2D pos2, int flag);
00113 void commandDistanceRequest(testclient::PositionRoadMap pos1, testclient::PositionRoadMap pos2, int flag);
00114 void commandDistanceRequest(testclient::PositionRoadMap pos1, testclient::Position2D pos2, int flag);
00115 void commandDistanceRequest(testclient::PositionRoadMap pos1, testclient::Position3D pos2, int flag);
00116 void commandDistanceRequest(testclient::Position2D pos1, testclient::PositionRoadMap pos2, int flag);
00117 void commandDistanceRequest(testclient::Position3D pos1, testclient::PositionRoadMap pos2, int flag);
00118
00119 void commandScenario(int flag, int domain, int domainId, int variable, int valueDataType);
00120 void commandScenario(int flag, int domain, int domainId, int variable, std::string stringVal);
00121 void commandScenario(int flag, int domain, int domainId, int variable, testclient::Position3D pos3dVal);
00122 void commandScenario(int flag, int domain, int domainId, int variable, testclient::PositionRoadMap roadPosVal);
00123
00124 void commandGetTLStatus(int tlId, SUMOTime intervalStart, SUMOTime intervalEnd);
00125 void commandGetVariable(int domID, int varID, const std::string &objID);
00126 void commandGetVariablePlus(int domID, int varID, const std::string &objID, std::ifstream &defFile);
00127 void commandSubscribeVariable(int domID, const std::string &objID, int beginTime, int endTime, int varNo, std::ifstream &defFile);
00128 void commandSetValue(int domID, int varID, const std::string &objID, std::ifstream &defFile);
00129
00130 void commandClose();
00131
00132 private:
00133 void writeResult();
00134
00135 void errorMsg(std::stringstream& msg);
00136
00137 void commandStopNode(int nodeId, testclient::Position2D* pos2D,
00138 testclient::Position3D* pos3D,
00139 testclient::PositionRoadMap* posRoad,
00140 float radius, SUMOTime waitTime);
00141
00142 void commandPositionConversion(testclient::Position2D* pos2D,
00143 testclient::Position3D* pos3D,
00144 testclient::PositionRoadMap* posRoad,
00145 int posId);
00146
00147 void commandDistanceRequest(testclient::Position2D* pos1_2D,
00148 testclient::Position3D* pos1_3D,
00149 testclient::PositionRoadMap* pos1_Road,
00150 testclient::Position2D* pos2_2D,
00151 testclient::Position3D* pos2_3D,
00152 testclient::PositionRoadMap* pos2_Road,
00153 int flag);
00154
00155 void commandScenario(int flag, int domain, int domainId, int variable, int valueDataType,
00156 int* intVal, int* byteVal, int* ubyteVal,
00157 float* floatVal, double* doubleVal, std::string* stringVal,
00158 testclient::Position3D* pos3dVal, testclient::PositionRoadMap* roadPosVal,
00159 testclient::BoundingBox* boxVal, testclient::Polygon* polyVal,
00160 testclient::TLPhaseList* tlphaseVal);
00161
00162
00163 bool reportResultState(tcpip::Storage& inMsg, int command, bool ignoreCommandId=false);
00164
00165 bool validateSimulationStep(tcpip::Storage& inMsg);
00166 bool validateSimulationStep2(tcpip::Storage& inMsg);
00167 bool validateSubscription(tcpip::Storage& inMsg);
00168
00169 bool validateStopNode(tcpip::Storage& inMsg);
00170
00171 bool validatePositionConversion(tcpip::Storage& inMsg);
00172
00173 bool validateDistanceRequest(tcpip::Storage& inMsg);
00174
00175 bool validateScenario(tcpip::Storage& inMsg);
00176
00177 bool validateGetTLStatus(tcpip::Storage& inMsg);
00178
00179 bool readAndReportTypeDependent(tcpip::Storage &inMsg, int valueDataType);
00180
00181
00189 int setValueTypeDependant(tcpip::Storage &into, std::ifstream &defFile, std::stringstream &msg);
00190
00191
00192
00193 private:
00194 tcpip::Socket* socket;
00195
00196 std::string outputFileName;
00197
00198 std::stringstream answerLog;
00199 };
00200
00201 }
00202
00203 #endif