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 2001-2010 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 "TraCIServerAPIHelper.h"
00034 #include "TraCIServerAPI_MeMeDetector.h"
00035 
00036 #ifdef CHECK_MEMORY_LEAKS
00037 #include <foreign/nvwa/debug_new.h>
00038 #endif // CHECK_MEMORY_LEAKS
00039 
00040 
00041 // ===========================================================================
00042 // used namespaces
00043 // ===========================================================================
00044 using namespace std;
00045 using namespace traci;
00046 using namespace tcpip;
00047 
00048 
00049 // ===========================================================================
00050 // method definitions
00051 // ===========================================================================
00052 bool
00053 TraCIServerAPI_MeMeDetector::processGet(tcpip::Storage &inputStorage,
00054                                         tcpip::Storage &outputStorage,
00055                                         bool withStatus) throw(TraCIException) {
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         TraCIServerAPIHelper::writeStatusCmd(CMD_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE, RTYPE_ERR, "Get MeMeDetector Variable: unsupported variable specified", outputStorage);
00064         return false;
00065     }
00066     // begin response building
00067     Storage tempMsg;
00068     //  response-code, variableID, objectID
00069     tempMsg.writeUnsignedByte(RESPONSE_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE);
00070     tempMsg.writeUnsignedByte(variable);
00071     tempMsg.writeString(id);
00072     if (variable==ID_LIST) {
00073         std::vector<std::string> ids;
00074         MSNet::getInstance()->getDetectorControl().getE3Detectors().insertIDs(ids);
00075         tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
00076         tempMsg.writeStringList(ids);
00077     } else {
00078         MSE3Collector *e3 = MSNet::getInstance()->getDetectorControl().getE3Detectors().get(id);
00079         if (e3==0) {
00080             TraCIServerAPIHelper::writeStatusCmd(CMD_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE, RTYPE_ERR, "Areal detector '" + id + "' is not known", outputStorage);
00081             return false;
00082         }
00083         switch (variable) {
00084         case ID_LIST:
00085             break;
00086         case LAST_STEP_VEHICLE_NUMBER:
00087             tempMsg.writeUnsignedByte(TYPE_INTEGER);
00088             tempMsg.writeInt((float) e3->getVehiclesWithin());
00089             break;
00090         case LAST_STEP_MEAN_SPEED:
00091             tempMsg.writeUnsignedByte(TYPE_FLOAT);
00092             tempMsg.writeFloat((float) e3->getCurrentMeanSpeed());
00093             break;
00094         case LAST_STEP_VEHICLE_ID_LIST: {
00095             tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
00096             std::vector<std::string> ids = e3->getCurrentVehicleIDs();
00097             tempMsg.writeStringList(ids);
00098         }
00099         break;
00100         case LAST_STEP_VEHICLE_HALTING_NUMBER:
00101             tempMsg.writeUnsignedByte(TYPE_INTEGER);
00102             tempMsg.writeInt((int) e3->getCurrentHaltingNumber());
00103             break;
00104         default:
00105             break;
00106         }
00107     }
00108     if (withStatus) {
00109         TraCIServerAPIHelper::writeStatusCmd(CMD_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE, RTYPE_OK, warning, outputStorage);
00110     }
00111     // send response
00112     outputStorage.writeUnsignedByte(0); // command length -> extended
00113     outputStorage.writeInt(1 + 4 + tempMsg.size());
00114     outputStorage.writeStorage(tempMsg);
00115     return true;
00116 }
00117 
00118 
00119 /****************************************************************************/
00120 

Generated on Wed May 5 00:06:37 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6