TraCIServerAPI_InductionLoop Class Reference

#include <TraCIServerAPI_InductionLoop.h>


Detailed Description

APIs for getting/setting induction loop values via TraCI.

Definition at line 43 of file TraCIServerAPI_InductionLoop.h.


Static Public Member Functions

static bool processGet (tcpip::Storage &inputStorage, tcpip::Storage &outputStorage, bool withStatus=true) throw (traci::TraCIException)
 Processes a get value command (Command 0xa0: Get Induction Loop Variable).

Private Member Functions

TraCIServerAPI_InductionLoopoperator= (const TraCIServerAPI_InductionLoop &s)
 invalidated assignment operator
 TraCIServerAPI_InductionLoop (const TraCIServerAPI_InductionLoop &s)
 invalidated copy constructor

Constructor & Destructor Documentation

TraCIServerAPI_InductionLoop::TraCIServerAPI_InductionLoop ( const TraCIServerAPI_InductionLoop s  )  [private]

invalidated copy constructor


Member Function Documentation

TraCIServerAPI_InductionLoop& TraCIServerAPI_InductionLoop::operator= ( const TraCIServerAPI_InductionLoop s  )  [private]

invalidated assignment operator

bool TraCIServerAPI_InductionLoop::processGet ( tcpip::Storage inputStorage,
tcpip::Storage outputStorage,
bool  withStatus = true 
) throw (traci::TraCIException) [static]

Processes a get value command (Command 0xa0: Get Induction Loop Variable).

Parameters:
[in] inputStorage The storage to read the command from
[out] outputStorage The storage to write the result to
[in] withStatus Whether the status message shall be written (not in subscription)

Definition at line 53 of file TraCIServerAPI_InductionLoop.cpp.

References CMD_GET_INDUCTIONLOOP_VARIABLE, MSInductLoop::getCurrentLength(), MSInductLoop::getCurrentOccupancy(), MSInductLoop::getCurrentPassedNumber(), MSInductLoop::getCurrentSpeed(), MSInductLoop::getCurrentVehicleIDs(), MSNet::getDetectorControl(), MSDetectorControl::getInductLoops(), MSNet::getInstance(), MSInductLoop::getTimestepsSinceLastDetection(), ID_LIST, LAST_STEP_LENGTH, LAST_STEP_MEAN_SPEED, LAST_STEP_OCCUPANCY, LAST_STEP_TIME_SINCE_DETECTION, LAST_STEP_VEHICLE_ID_LIST, LAST_STEP_VEHICLE_NUMBER, RESPONSE_GET_INDUCTIONLOOP_VARIABLE, RTYPE_ERR, RTYPE_OK, tcpip::Storage::size(), TYPE_FLOAT, TYPE_INTEGER, TYPE_STRINGLIST, tcpip::Storage::writeFloat(), tcpip::Storage::writeInt(), TraCIServerAPIHelper::writeStatusCmd(), tcpip::Storage::writeString(), tcpip::Storage::writeStringList(), and tcpip::Storage::writeUnsignedByte().

Referenced by traci::TraCIServer::dispatchCommand(), and traci::TraCIServer::processSingleSubscription().

00055                                                {
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_OCCUPANCY
00063             &&variable!=LAST_STEP_LENGTH&&variable!=LAST_STEP_TIME_SINCE_DETECTION) {
00064         TraCIServerAPIHelper::writeStatusCmd(CMD_GET_INDUCTIONLOOP_VARIABLE, RTYPE_ERR, "Get Induction Loop Variable: unsupported variable specified", outputStorage);
00065         return false;
00066     }
00067     // begin response building
00068     Storage tempMsg;
00069     //  response-code, variableID, objectID
00070     tempMsg.writeUnsignedByte(RESPONSE_GET_INDUCTIONLOOP_VARIABLE);
00071     tempMsg.writeUnsignedByte(variable);
00072     tempMsg.writeString(id);
00073     // process request
00074     if (variable==ID_LIST) {
00075         std::vector<std::string> ids;
00076         MSNet::getInstance()->getDetectorControl().getInductLoops().insertIDs(ids);
00077         tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
00078         tempMsg.writeStringList(ids);
00079     } else {
00080         MSInductLoop *il = MSNet::getInstance()->getDetectorControl().getInductLoops().get(id);
00081         if (il==0) {
00082             TraCIServerAPIHelper::writeStatusCmd(CMD_GET_INDUCTIONLOOP_VARIABLE, RTYPE_ERR, "Induction loop '" + 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(il->getCurrentPassedNumber());
00091             break;
00092         case LAST_STEP_MEAN_SPEED:
00093             tempMsg.writeUnsignedByte(TYPE_FLOAT);
00094             tempMsg.writeFloat((float) il->getCurrentSpeed());
00095             break;
00096         case LAST_STEP_VEHICLE_ID_LIST: {
00097             tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
00098             std::vector<std::string> ids = il->getCurrentVehicleIDs();
00099             tempMsg.writeStringList(ids);
00100         }
00101         break;
00102         case LAST_STEP_OCCUPANCY:
00103             tempMsg.writeUnsignedByte(TYPE_FLOAT);
00104             tempMsg.writeFloat((float) il->getCurrentOccupancy());
00105             break;
00106         case LAST_STEP_LENGTH:
00107             tempMsg.writeUnsignedByte(TYPE_FLOAT);
00108             tempMsg.writeFloat((float) il->getCurrentLength());
00109             break;
00110         case LAST_STEP_TIME_SINCE_DETECTION:
00111             tempMsg.writeUnsignedByte(TYPE_FLOAT);
00112             tempMsg.writeFloat((float) il->getTimestepsSinceLastDetection());
00113             break;
00114         default:
00115             break;
00116         }
00117     }
00118     if (withStatus) {
00119         TraCIServerAPIHelper::writeStatusCmd(CMD_GET_INDUCTIONLOOP_VARIABLE, RTYPE_OK, warning, outputStorage);
00120     }
00121     // send response
00122     outputStorage.writeUnsignedByte(0); // command length -> extended
00123     outputStorage.writeInt(1 + 4 + tempMsg.size());
00124     outputStorage.writeStorage(tempMsg);
00125     return true;
00126 }


The documentation for this class was generated from the following files:

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