|
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 #include "TraCIConstants.h" 00033 #include <microsim/output/MSDetectorControl.h> 00034 #include <microsim/output/MSE3Collector.h> 00035 #include "TraCIServerAPI_MeMeDetector.h" 00036 00037 #ifdef CHECK_MEMORY_LEAKS 00038 #include <foreign/nvwa/debug_new.h> 00039 #endif // CHECK_MEMORY_LEAKS 00040 00041 00042 // =========================================================================== 00043 // used namespaces 00044 // =========================================================================== 00045 using namespace traci; 00046 00047 00048 // =========================================================================== 00049 // method definitions 00050 // =========================================================================== 00051 bool 00052 TraCIServerAPI_MeMeDetector::processGet(TraCIServer& server, tcpip::Storage& inputStorage, 00053 tcpip::Storage& outputStorage) { 00054 std::string warning = ""; // additional description for response 00055 // variable & id 00056 int variable = inputStorage.readUnsignedByte(); 00057 std::string id = inputStorage.readString(); 00058 // check variable 00059 if (variable != ID_LIST && variable != LAST_STEP_VEHICLE_NUMBER && variable != LAST_STEP_MEAN_SPEED 00060 && variable != LAST_STEP_VEHICLE_ID_LIST && variable != LAST_STEP_VEHICLE_HALTING_NUMBER 00061 && variable != ID_COUNT) { 00062 server.writeStatusCmd(CMD_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE, RTYPE_ERR, "Get MeMeDetector Variable: unsupported variable specified", outputStorage); 00063 return false; 00064 } 00065 // begin response building 00066 tcpip::Storage tempMsg; 00067 // response-code, variableID, objectID 00068 tempMsg.writeUnsignedByte(RESPONSE_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE); 00069 tempMsg.writeUnsignedByte(variable); 00070 tempMsg.writeString(id); 00071 if (variable == ID_LIST) { 00072 std::vector<std::string> ids; 00073 MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_ENTRY_EXIT_DETECTOR).insertIDs(ids); 00074 tempMsg.writeUnsignedByte(TYPE_STRINGLIST); 00075 tempMsg.writeStringList(ids); 00076 } else if (variable == ID_COUNT) { 00077 std::vector<std::string> ids; 00078 MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_ENTRY_EXIT_DETECTOR).insertIDs(ids); 00079 tempMsg.writeUnsignedByte(TYPE_INTEGER); 00080 tempMsg.writeInt((int) ids.size()); 00081 } else { 00082 MSE3Collector* e3 = static_cast<MSE3Collector*>(MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_ENTRY_EXIT_DETECTOR).get(id)); 00083 if (e3 == 0) { 00084 server.writeStatusCmd(CMD_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE, RTYPE_ERR, "Areal detector '" + id + "' is not known", outputStorage); 00085 return false; 00086 } 00087 switch (variable) { 00088 case ID_LIST: 00089 break; 00090 case LAST_STEP_VEHICLE_NUMBER: 00091 tempMsg.writeUnsignedByte(TYPE_INTEGER); 00092 tempMsg.writeInt((int) e3->getVehiclesWithin()); 00093 break; 00094 case LAST_STEP_MEAN_SPEED: 00095 tempMsg.writeUnsignedByte(TYPE_DOUBLE); 00096 tempMsg.writeDouble(e3->getCurrentMeanSpeed()); 00097 break; 00098 case LAST_STEP_VEHICLE_ID_LIST: { 00099 tempMsg.writeUnsignedByte(TYPE_STRINGLIST); 00100 std::vector<std::string> ids = e3->getCurrentVehicleIDs(); 00101 tempMsg.writeStringList(ids); 00102 } 00103 break; 00104 case LAST_STEP_VEHICLE_HALTING_NUMBER: 00105 tempMsg.writeUnsignedByte(TYPE_INTEGER); 00106 tempMsg.writeInt((int) e3->getCurrentHaltingNumber()); 00107 break; 00108 default: 00109 break; 00110 } 00111 } 00112 server.writeStatusCmd(CMD_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE, RTYPE_OK, warning, outputStorage); 00113 server.writeResponseWithLength(outputStorage, tempMsg); 00114 return true; 00115 } 00116 00117 00118 /****************************************************************************/ 00119