SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00008 // APIs for getting/setting multi-entry/multi-exit detector values via TraCI 00009 /****************************************************************************/ 00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00012 /****************************************************************************/ 00013 // 00014 // This file is part of SUMO. 00015 // SUMO is free software: you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation, either version 3 of the License, or 00018 // (at your option) any later version. 00019 // 00020 /****************************************************************************/ 00021 00022 00023 // =========================================================================== 00024 // included modules 00025 // =========================================================================== 00026 #ifdef _MSC_VER 00027 #include <windows_config.h> 00028 #else 00029 #include <config.h> 00030 #endif 00031 00032 #ifndef NO_TRACI 00033 00034 #include "TraCIConstants.h" 00035 #include <microsim/output/MSDetectorControl.h> 00036 #include <microsim/output/MSE3Collector.h> 00037 #include "TraCIServerAPI_MeMeDetector.h" 00038 00039 #ifdef CHECK_MEMORY_LEAKS 00040 #include <foreign/nvwa/debug_new.h> 00041 #endif // CHECK_MEMORY_LEAKS 00042 00043 00044 // =========================================================================== 00045 // used namespaces 00046 // =========================================================================== 00047 using namespace traci; 00048 00049 00050 // =========================================================================== 00051 // method definitions 00052 // =========================================================================== 00053 bool 00054 TraCIServerAPI_MeMeDetector::processGet(TraCIServer& server, tcpip::Storage& inputStorage, 00055 tcpip::Storage& outputStorage) { 00056 std::string warning = ""; // additional description for response 00057 // variable & id 00058 int variable = inputStorage.readUnsignedByte(); 00059 std::string id = inputStorage.readString(); 00060 // check variable 00061 if (variable != ID_LIST && variable != LAST_STEP_VEHICLE_NUMBER && variable != LAST_STEP_MEAN_SPEED 00062 && variable != LAST_STEP_VEHICLE_ID_LIST && variable != LAST_STEP_VEHICLE_HALTING_NUMBER 00063 && variable != ID_COUNT) { 00064 server.writeStatusCmd(CMD_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE, RTYPE_ERR, "Get MeMeDetector Variable: unsupported variable specified", outputStorage); 00065 return false; 00066 } 00067 // begin response building 00068 tcpip::Storage tempMsg; 00069 // response-code, variableID, objectID 00070 tempMsg.writeUnsignedByte(RESPONSE_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE); 00071 tempMsg.writeUnsignedByte(variable); 00072 tempMsg.writeString(id); 00073 if (variable == ID_LIST) { 00074 std::vector<std::string> ids; 00075 MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_ENTRY_EXIT_DETECTOR).insertIDs(ids); 00076 tempMsg.writeUnsignedByte(TYPE_STRINGLIST); 00077 tempMsg.writeStringList(ids); 00078 } else if (variable == ID_COUNT) { 00079 std::vector<std::string> ids; 00080 MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_ENTRY_EXIT_DETECTOR).insertIDs(ids); 00081 tempMsg.writeUnsignedByte(TYPE_INTEGER); 00082 tempMsg.writeInt((int) ids.size()); 00083 } else { 00084 MSE3Collector* e3 = static_cast<MSE3Collector*>(MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_ENTRY_EXIT_DETECTOR).get(id)); 00085 if (e3 == 0) { 00086 server.writeStatusCmd(CMD_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE, RTYPE_ERR, "Areal detector '" + id + "' is not known", outputStorage); 00087 return false; 00088 } 00089 switch (variable) { 00090 case ID_LIST: 00091 break; 00092 case LAST_STEP_VEHICLE_NUMBER: 00093 tempMsg.writeUnsignedByte(TYPE_INTEGER); 00094 tempMsg.writeInt((int) e3->getVehiclesWithin()); 00095 break; 00096 case LAST_STEP_MEAN_SPEED: 00097 tempMsg.writeUnsignedByte(TYPE_DOUBLE); 00098 tempMsg.writeDouble(e3->getCurrentMeanSpeed()); 00099 break; 00100 case LAST_STEP_VEHICLE_ID_LIST: { 00101 tempMsg.writeUnsignedByte(TYPE_STRINGLIST); 00102 std::vector<std::string> ids = e3->getCurrentVehicleIDs(); 00103 tempMsg.writeStringList(ids); 00104 } 00105 break; 00106 case LAST_STEP_VEHICLE_HALTING_NUMBER: 00107 tempMsg.writeUnsignedByte(TYPE_INTEGER); 00108 tempMsg.writeInt((int) e3->getCurrentHaltingNumber()); 00109 break; 00110 default: 00111 break; 00112 } 00113 } 00114 server.writeStatusCmd(CMD_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE, RTYPE_OK, warning, outputStorage); 00115 server.writeResponseWithLength(outputStorage, tempMsg); 00116 return true; 00117 } 00118 00119 #endif 00120 00121 00122 /****************************************************************************/ 00123