TraCIServerAPI_Lane Class Reference

#include <TraCIServerAPI_Lane.h>


Detailed Description

APIs for getting/setting lane values via TraCI.

Definition at line 43 of file TraCIServerAPI_Lane.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 0xa3: Get Lane Variable).
static bool processSet (tcpip::Storage &inputStorage, tcpip::Storage &outputStorage) throw (traci::TraCIException)
 Processes a set value command (Command 0xc3: Change Lane State).

Private Member Functions

TraCIServerAPI_Laneoperator= (const TraCIServerAPI_Lane &s)
 invalidated assignment operator
 TraCIServerAPI_Lane (const TraCIServerAPI_Lane &s)
 invalidated copy constructor

Constructor & Destructor Documentation

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

invalidated copy constructor


Member Function Documentation

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

invalidated assignment operator

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

Processes a get value command (Command 0xa3: Get Lane 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 52 of file TraCIServerAPI_Lane.cpp.

References CMD_GET_LANE_VARIABLE, MSLane::dictionary(), MSLane::getAllowedClasses(), MSNet::getCurrentTimeStep(), MSLane::getEdge(), MSLane::getHarmonoise_NoiseEmissions(), MSLane::getHBEFA_CO2Emissions(), MSLane::getHBEFA_COEmissions(), MSLane::getHBEFA_FuelConsumption(), MSLane::getHBEFA_HCEmissions(), MSLane::getHBEFA_NOxEmissions(), MSLane::getHBEFA_PMxEmissions(), MSLane::getID(), MSEdge::getID(), MSNet::getInstance(), MSLink::getLane(), MSLink::getLength(), MSLane::getLength(), MSLane::getLinkCont(), MSLane::getMaxSpeed(), MSLane::getMeanSpeed(), MSLane::getNotAllowedClasses(), MSLane::getOccupancy(), MSLane::getShape(), getVehicleClassName(), MSLane::getVehicleNumber(), MSLane::getVehiclesSecure(), MSLink::hasApproachingFoe(), MSLink::havePriority(), ID_LIST, MSLane::insertIDs(), LANE_ALLOWED, LANE_DISALLOWED, LANE_EDGE_ID, LANE_LINK_NUMBER, LANE_LINKS, LAST_STEP_LENGTH, LAST_STEP_MEAN_SPEED, LAST_STEP_OCCUPANCY, LAST_STEP_VEHICLE_HALTING_NUMBER, LAST_STEP_VEHICLE_ID_LIST, LAST_STEP_VEHICLE_NUMBER, MIN2(), MSLink::opened(), MSLane::releaseVehicles(), RESPONSE_GET_LANE_VARIABLE, RTYPE_ERR, RTYPE_OK, tcpip::Storage::size(), Position2DVector::size(), SUMOReal, TYPE_COMPOUND, TYPE_FLOAT, TYPE_INTEGER, TYPE_POLYGON, TYPE_STRING, TYPE_STRINGLIST, TYPE_UBYTE, VAR_CO2EMISSION, VAR_COEMISSION, VAR_CURRENT_TRAVELTIME, VAR_FUELCONSUMPTION, VAR_HCEMISSION, VAR_LENGTH, VAR_MAXSPEED, VAR_NOISEEMISSION, VAR_NOXEMISSION, VAR_PMXEMISSION, VAR_SHAPE, tcpip::Storage::writeFloat(), tcpip::Storage::writeInt(), TraCIServerAPIHelper::writeStatusCmd(), tcpip::Storage::writeStorage(), tcpip::Storage::writeString(), tcpip::Storage::writeStringList(), and tcpip::Storage::writeUnsignedByte().

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

00054                                                                        {
00055     Storage tmpResult;
00056     std::string warning = "";   // additional description for response
00057     // variable
00058     int variable = inputStorage.readUnsignedByte();
00059     std::string id = inputStorage.readString();
00060     // check variable
00061     if (variable!=ID_LIST&&variable!=LANE_LINK_NUMBER&&variable!=LANE_EDGE_ID&&variable!=VAR_LENGTH
00062             &&variable!=VAR_MAXSPEED&&variable!=LANE_LINKS&&variable!=VAR_SHAPE
00063             &&variable!=VAR_CO2EMISSION&&variable!=VAR_COEMISSION&&variable!=VAR_HCEMISSION&&variable!=VAR_PMXEMISSION
00064             &&variable!=VAR_NOXEMISSION&&variable!=VAR_FUELCONSUMPTION&&variable!=VAR_NOISEEMISSION
00065             &&variable!=LAST_STEP_MEAN_SPEED&&variable!=LAST_STEP_VEHICLE_NUMBER
00066             &&variable!=LAST_STEP_VEHICLE_ID_LIST&&variable!=LAST_STEP_OCCUPANCY&&variable!=LAST_STEP_VEHICLE_HALTING_NUMBER
00067             &&variable!=LAST_STEP_LENGTH&&variable!=VAR_CURRENT_TRAVELTIME
00068             &&variable!=LANE_ALLOWED&&variable!=LANE_DISALLOWED) {
00069         TraCIServerAPIHelper::writeStatusCmd(CMD_GET_LANE_VARIABLE, RTYPE_ERR, "Get Lane Variable: unsupported variable specified", outputStorage);
00070         return false;
00071     }
00072     // begin response building
00073     Storage tempMsg;
00074     //  response-code, variableID, objectID
00075     tempMsg.writeUnsignedByte(RESPONSE_GET_LANE_VARIABLE);
00076     tempMsg.writeUnsignedByte(variable);
00077     tempMsg.writeString(id);
00078     if (variable==ID_LIST) {
00079         std::vector<std::string> ids;
00080         MSLane::insertIDs(ids);
00081         tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
00082         tempMsg.writeStringList(ids);
00083     } else {
00084         MSLane *lane = MSLane::dictionary(id);
00085         if (lane==0) {
00086             TraCIServerAPIHelper::writeStatusCmd(CMD_GET_LANE_VARIABLE, RTYPE_ERR, "Lane '" + id + "' is not known", outputStorage);
00087             return false;
00088         }
00089         switch (variable) {
00090         case LANE_LINK_NUMBER:
00091             tempMsg.writeUnsignedByte(TYPE_UBYTE);
00092             tempMsg.writeUnsignedByte((int) lane->getLinkCont().size());
00093             break;
00094         case LANE_EDGE_ID:
00095             tempMsg.writeUnsignedByte(TYPE_STRING);
00096             tempMsg.writeString(lane->getEdge().getID());
00097             break;
00098         case VAR_LENGTH:
00099             tempMsg.writeUnsignedByte(TYPE_FLOAT);
00100             tempMsg.writeFloat(lane->getLength());
00101             break;
00102         case VAR_MAXSPEED:
00103             tempMsg.writeUnsignedByte(TYPE_FLOAT);
00104             tempMsg.writeFloat(lane->getMaxSpeed());
00105             break;
00106         case LANE_LINKS: {
00107             tempMsg.writeUnsignedByte(TYPE_COMPOUND);
00108             Storage tempContent;
00109             unsigned int cnt = 0;
00110             tempContent.writeUnsignedByte(TYPE_INTEGER);
00111             const MSLinkCont &links = lane->getLinkCont();
00112             tempContent.writeInt((int) links.size());
00113             ++cnt;
00114             for (MSLinkCont::const_iterator i=links.begin(); i!=links.end(); ++i) {
00115                 MSLink *link = (*i);
00116                 // approached non-internal lane (if any)
00117                 tempContent.writeUnsignedByte(TYPE_STRING);
00118                 tempContent.writeString(link->getLane()!=0 ? link->getLane()->getID() : "");
00119                 ++cnt;
00120                 // approached "via", internal lane (if any)
00121                 tempContent.writeUnsignedByte(TYPE_STRING);
00122 #ifdef HAVE_INTERNAL_LANES
00123                 tempContent.writeString(link->getViaLane()!=0 ? link->getViaLane()->getID() : "");
00124 #else
00125                 tempContent.writeString("");
00126 #endif
00127                 ++cnt;
00128                 // priority
00129                 tempContent.writeUnsignedByte(TYPE_UBYTE);
00130                 tempContent.writeUnsignedByte(link->havePriority() ? 1 : 0);
00131                 ++cnt;
00132                 // opened
00133                 tempContent.writeUnsignedByte(TYPE_UBYTE);
00134                 tempContent.writeUnsignedByte(link->opened(MSNet::getInstance()->getCurrentTimeStep(), MSNet::getInstance()->getCurrentTimeStep()) ? 1 : 0);
00135                 ++cnt;
00136                 // approaching foe
00137                 tempContent.writeUnsignedByte(TYPE_UBYTE);
00138                 tempContent.writeUnsignedByte(link->hasApproachingFoe(MSNet::getInstance()->getCurrentTimeStep(), MSNet::getInstance()->getCurrentTimeStep()) ? 1 : 0);
00139                 ++cnt;
00140                 // state (not implemented, yet)
00141                 tempContent.writeUnsignedByte(TYPE_STRING);
00142                 tempContent.writeString("");
00143                 ++cnt;
00144                 // direction (not implemented, yet)
00145                 tempContent.writeUnsignedByte(TYPE_STRING);
00146                 tempContent.writeString("");
00147                 ++cnt;
00148                 // length
00149                 tempContent.writeUnsignedByte(TYPE_FLOAT);
00150                 tempContent.writeFloat(link->getLength());
00151                 ++cnt;
00152             }
00153             tempMsg.writeInt((int) cnt);
00154             tempMsg.writeStorage(tempContent);
00155         }
00156         break;
00157         case LANE_ALLOWED: {
00158             const std::vector<SUMOVehicleClass> &allowed = lane->getAllowedClasses();
00159             std::vector<std::string> allowedS;
00160             for (std::vector<SUMOVehicleClass>::const_iterator i=allowed.begin(); i!=allowed.end(); ++i) {
00161                 allowedS.push_back(getVehicleClassName(*i));
00162             }
00163             tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
00164             tempMsg.writeStringList(allowedS);
00165         }
00166         case LANE_DISALLOWED: {
00167             const std::vector<SUMOVehicleClass> &disallowed = lane->getNotAllowedClasses();
00168             std::vector<std::string> disallowedS;
00169             for (std::vector<SUMOVehicleClass>::const_iterator i=disallowed.begin(); i!=disallowed.end(); ++i) {
00170                 disallowedS.push_back(getVehicleClassName(*i));
00171             }
00172             tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
00173             tempMsg.writeStringList(disallowedS);
00174         }
00175         break;
00176         case VAR_SHAPE:
00177             tempMsg.writeUnsignedByte(TYPE_POLYGON);
00178             tempMsg.writeUnsignedByte(MIN2(static_cast<size_t>(255),lane->getShape().size()));
00179             for (int iPoint=0; iPoint < MIN2(static_cast<size_t>(255),lane->getShape().size()); ++iPoint) {
00180                 tempMsg.writeFloat(lane->getShape()[iPoint].x());
00181                 tempMsg.writeFloat(lane->getShape()[iPoint].y());
00182             }
00183             break;
00184         case VAR_CO2EMISSION:
00185             tempMsg.writeUnsignedByte(TYPE_FLOAT);
00186             tempMsg.writeFloat(lane->getHBEFA_CO2Emissions());
00187             break;
00188         case VAR_COEMISSION:
00189             tempMsg.writeUnsignedByte(TYPE_FLOAT);
00190             tempMsg.writeFloat(lane->getHBEFA_COEmissions());
00191             break;
00192         case VAR_HCEMISSION:
00193             tempMsg.writeUnsignedByte(TYPE_FLOAT);
00194             tempMsg.writeFloat(lane->getHBEFA_HCEmissions());
00195             break;
00196         case VAR_PMXEMISSION:
00197             tempMsg.writeUnsignedByte(TYPE_FLOAT);
00198             tempMsg.writeFloat(lane->getHBEFA_PMxEmissions());
00199             break;
00200         case VAR_NOXEMISSION:
00201             tempMsg.writeUnsignedByte(TYPE_FLOAT);
00202             tempMsg.writeFloat(lane->getHBEFA_NOxEmissions());
00203             break;
00204         case VAR_FUELCONSUMPTION:
00205             tempMsg.writeUnsignedByte(TYPE_FLOAT);
00206             tempMsg.writeFloat(lane->getHBEFA_FuelConsumption());
00207             break;
00208         case VAR_NOISEEMISSION:
00209             tempMsg.writeUnsignedByte(TYPE_FLOAT);
00210             tempMsg.writeFloat(lane->getHarmonoise_NoiseEmissions());
00211             break;
00212         case LAST_STEP_VEHICLE_NUMBER:
00213             tempMsg.writeUnsignedByte(TYPE_INTEGER);
00214             tempMsg.writeInt((int) lane->getVehicleNumber());
00215             break;
00216         case LAST_STEP_MEAN_SPEED:
00217             tempMsg.writeUnsignedByte(TYPE_FLOAT);
00218             tempMsg.writeFloat(lane->getMeanSpeed());
00219             break;
00220         case LAST_STEP_VEHICLE_ID_LIST: {
00221             std::vector<std::string> vehIDs;
00222             const std::deque<MSVehicle*> &vehs = lane->getVehiclesSecure();
00223             for (std::deque<MSVehicle*>::const_iterator j=vehs.begin(); j!=vehs.end(); ++j) {
00224                 vehIDs.push_back((*j)->getID());
00225             }
00226             lane->releaseVehicles();
00227             tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
00228             tempMsg.writeStringList(vehIDs);
00229         }
00230         break;
00231         case LAST_STEP_OCCUPANCY:
00232             tempMsg.writeUnsignedByte(TYPE_FLOAT);
00233             tempMsg.writeFloat(lane->getOccupancy());
00234             break;
00235         case LAST_STEP_VEHICLE_HALTING_NUMBER: {
00236             int halting = 0;
00237             const std::deque<MSVehicle*> &vehs = lane->getVehiclesSecure();
00238             for (std::deque<MSVehicle*>::const_iterator j=vehs.begin(); j!=vehs.end(); ++j) {
00239                 if ((*j)->getSpeed()<0.1) {
00240                     ++halting;
00241                 }
00242             }
00243             lane->releaseVehicles();
00244             tempMsg.writeUnsignedByte(TYPE_INTEGER);
00245             tempMsg.writeInt(halting);
00246         }
00247         break;
00248         case LAST_STEP_LENGTH: {
00249             SUMOReal lengthSum = 0;
00250             const std::deque<MSVehicle*> &vehs = lane->getVehiclesSecure();
00251             for (std::deque<MSVehicle*>::const_iterator j=vehs.begin(); j!=vehs.end(); ++j) {
00252                 lengthSum += (*j)->getVehicleType().getLength();
00253             }
00254             tempMsg.writeUnsignedByte(TYPE_FLOAT);
00255             if (vehs.size()==0) {
00256                 tempMsg.writeFloat(0);
00257             } else {
00258                 tempMsg.writeFloat(lengthSum / (SUMOReal) vehs.size());
00259             }
00260             lane->releaseVehicles();
00261         }
00262         break;
00263         case VAR_CURRENT_TRAVELTIME: {
00264             SUMOReal meanSpeed = lane->getMeanSpeed();
00265             tempMsg.writeUnsignedByte(TYPE_FLOAT);
00266             if (meanSpeed!=0) {
00267                 tempMsg.writeFloat(lane->getLength() / meanSpeed);
00268             } else {
00269                 tempMsg.writeFloat(1000000.);
00270             }
00271         }
00272         break;
00273         default:
00274             break;
00275         }
00276     }
00277     if (withStatus) {
00278         TraCIServerAPIHelper::writeStatusCmd(CMD_GET_LANE_VARIABLE, RTYPE_OK, warning, outputStorage);
00279     }
00280     // send response
00281     outputStorage.writeUnsignedByte(0); // command length -> extended
00282     outputStorage.writeInt(1 + 4 + tempMsg.size());
00283     outputStorage.writeStorage(tempMsg);
00284     return true;
00285 }

bool TraCIServerAPI_Lane::processSet ( tcpip::Storage inputStorage,
tcpip::Storage outputStorage 
) throw (traci::TraCIException) [static]

Processes a set value command (Command 0xc3: Change Lane State).

Parameters:
[in] inputStorage The storage to read the command from
[out] outputStorage The storage to write the result to

Definition at line 289 of file TraCIServerAPI_Lane.cpp.

References CMD_SET_LANE_VARIABLE, MSLane::dictionary(), MSLane::getEdge(), LANE_ALLOWED, LANE_DISALLOWED, parseVehicleClasses(), MSEdge::rebuildAllowedLanes(), RTYPE_ERR, RTYPE_OK, MSLane::setAllowedClasses(), MSLane::setLength(), MSLane::setMaxSpeed(), MSLane::setNotAllowedClasses(), SUMOReal, TYPE_FLOAT, TYPE_STRINGLIST, VAR_LENGTH, VAR_MAXSPEED, and TraCIServerAPIHelper::writeStatusCmd().

Referenced by traci::TraCIServer::dispatchCommand().

00290                                                                                    {
00291     std::string warning = ""; // additional description for response
00292     // variable
00293     int variable = inputStorage.readUnsignedByte();
00294     if (variable!=VAR_MAXSPEED&&variable!=VAR_LENGTH&&variable!=LANE_ALLOWED&&variable!=LANE_DISALLOWED) {
00295         TraCIServerAPIHelper::writeStatusCmd(CMD_SET_LANE_VARIABLE, RTYPE_ERR, "Change Lane State: unsupported variable specified", outputStorage);
00296         return false;
00297     }
00298     // id
00299     std::string id = inputStorage.readString();
00300     MSLane *l = MSLane::dictionary(id);
00301     if (l==0) {
00302         TraCIServerAPIHelper::writeStatusCmd(CMD_SET_LANE_VARIABLE, RTYPE_ERR, "Lane '" + id + "' is not known", outputStorage);
00303         return false;
00304     }
00305     // process
00306     int valueDataType = inputStorage.readUnsignedByte();
00307     switch (variable) {
00308     case VAR_MAXSPEED: {
00309         // speed
00310         if (valueDataType!=TYPE_FLOAT) {
00311             TraCIServerAPIHelper::writeStatusCmd(CMD_SET_LANE_VARIABLE, RTYPE_ERR, "The speed must be given as a float.", outputStorage);
00312             return false;
00313         }
00314         SUMOReal val = inputStorage.readFloat();
00315         l->setMaxSpeed(val);
00316     }
00317     break;
00318     case VAR_LENGTH: {
00319         // speed
00320         if (valueDataType!=TYPE_FLOAT) {
00321             TraCIServerAPIHelper::writeStatusCmd(CMD_SET_LANE_VARIABLE, RTYPE_ERR, "The length must be given as a float.", outputStorage);
00322             return false;
00323         }
00324         SUMOReal val = inputStorage.readFloat();
00325         l->setLength(val);
00326     }
00327     break;
00328     case LANE_ALLOWED: {
00329         if (valueDataType!=TYPE_STRINGLIST) {
00330             TraCIServerAPIHelper::writeStatusCmd(CMD_SET_LANE_VARIABLE, RTYPE_ERR, "Allowed classes must be given as a list of strings.", outputStorage);
00331             return false;
00332         }
00333         std::vector<SUMOVehicleClass> allowed;
00334         parseVehicleClasses(inputStorage.readStringList(), allowed);
00335         l->setAllowedClasses(allowed);
00336         l->getEdge().rebuildAllowedLanes();
00337     }
00338     break;
00339     case LANE_DISALLOWED: {
00340         if (valueDataType!=TYPE_STRINGLIST) {
00341             TraCIServerAPIHelper::writeStatusCmd(CMD_SET_LANE_VARIABLE, RTYPE_ERR, "Not allowed classes must be given as a list of strings.", outputStorage);
00342             return false;
00343         }
00344         std::vector<SUMOVehicleClass> disallowed;
00345         parseVehicleClasses(inputStorage.readStringList(), disallowed);
00346         l->setNotAllowedClasses(disallowed);
00347         l->getEdge().rebuildAllowedLanes();
00348     }
00349     break;
00350     default:
00351         break;
00352     }
00353     TraCIServerAPIHelper::writeStatusCmd(CMD_SET_LANE_VARIABLE, RTYPE_OK, warning, outputStorage);
00354     return true;
00355 }


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