SUMO - Simulation of Urban MObility

TraCIServerAPI_MeMeDetector.cpp

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