TraCIServerAPI_VehicleType.cpp
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029
00030 #include <microsim/MSNet.h>
00031 #include <microsim/MSVehicleType.h>
00032 #include "TraCIConstants.h"
00033 #include "TraCIServerAPIHelper.h"
00034 #include "TraCIServerAPI_VehicleType.h"
00035
00036 #ifdef CHECK_MEMORY_LEAKS
00037 #include <foreign/nvwa/debug_new.h>
00038 #endif // CHECK_MEMORY_LEAKS
00039
00040
00041
00042
00043
00044 using namespace std;
00045 using namespace traci;
00046 using namespace tcpip;
00047
00048
00049
00050
00051
00052 bool
00053 TraCIServerAPI_VehicleType::processGet(tcpip::Storage &inputStorage,
00054 tcpip::Storage &outputStorage,
00055 bool withStatus) throw(TraCIException) {
00056 std::string warning = "";
00057
00058 int variable = inputStorage.readUnsignedByte();
00059 std::string id = inputStorage.readString();
00060
00061 if (variable!=ID_LIST&&variable!=VAR_LENGTH&&variable!=VAR_MAXSPEED&&variable!=VAR_ACCEL&&variable!=VAR_DECEL
00062 &&variable!=VAR_TAU&&variable!=VAR_VEHICLECLASS&&variable!=VAR_EMISSIONCLASS&&variable!=VAR_SHAPECLASS
00063 &&variable!=VAR_GUIOFFSET&&variable!=VAR_WIDTH&&variable!=VAR_COLOR) {
00064 TraCIServerAPIHelper::writeStatusCmd(CMD_GET_VEHICLETYPE_VARIABLE, RTYPE_ERR, "Get Vehicle Type Variable: unsupported variable specified", outputStorage);
00065 return false;
00066 }
00067
00068 Storage tempMsg;
00069
00070 tempMsg.writeUnsignedByte(RESPONSE_GET_VEHICLETYPE_VARIABLE);
00071 tempMsg.writeUnsignedByte(variable);
00072 tempMsg.writeString(id);
00073
00074 if (variable==ID_LIST) {
00075 std::vector<std::string> ids;
00076 MSNet::getInstance()->getVehicleControl().insertVTypeIDs(ids);
00077 tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
00078 tempMsg.writeStringList(ids);
00079 } else {
00080 MSVehicleType *v = MSNet::getInstance()->getVehicleControl().getVType(id);
00081 if (v==0) {
00082 TraCIServerAPIHelper::writeStatusCmd(CMD_GET_VEHICLETYPE_VARIABLE, RTYPE_ERR, "Vehicle type '" + id + "' is not known", outputStorage);
00083 return false;
00084 }
00085 switch (variable) {
00086 case VAR_LENGTH:
00087 tempMsg.writeUnsignedByte(TYPE_FLOAT);
00088 tempMsg.writeFloat(v->getLength());
00089 break;
00090 case VAR_MAXSPEED:
00091 tempMsg.writeUnsignedByte(TYPE_FLOAT);
00092 tempMsg.writeFloat(v->getMaxSpeed());
00093 break;
00094 case VAR_ACCEL:
00095 tempMsg.writeUnsignedByte(TYPE_FLOAT);
00096 tempMsg.writeFloat(v->getCarFollowModel().getMaxAccel(0));
00097 break;
00098 case VAR_DECEL:
00099 tempMsg.writeUnsignedByte(TYPE_FLOAT);
00100 tempMsg.writeFloat(v->getCarFollowModel().getMaxDecel());
00101 break;
00102 case VAR_TAU:
00103 tempMsg.writeUnsignedByte(TYPE_FLOAT);
00104 tempMsg.writeFloat(v->getCarFollowModel().getTau());
00105 break;
00106 case VAR_VEHICLECLASS:
00107 tempMsg.writeUnsignedByte(TYPE_STRING);
00108 tempMsg.writeString(getVehicleClassName(v->getVehicleClass()));
00109 break;
00110 case VAR_EMISSIONCLASS:
00111 tempMsg.writeUnsignedByte(TYPE_STRING);
00112 tempMsg.writeString(getVehicleEmissionTypeName(v->getEmissionClass()));
00113 break;
00114 case VAR_SHAPECLASS:
00115 tempMsg.writeUnsignedByte(TYPE_STRING);
00116 tempMsg.writeString(getVehicleShapeName(v->getGuiShape()));
00117 break;
00118 case VAR_GUIOFFSET:
00119 tempMsg.writeUnsignedByte(TYPE_FLOAT);
00120 tempMsg.writeFloat(v->getGuiOffset());
00121 break;
00122 case VAR_WIDTH:
00123 tempMsg.writeUnsignedByte(TYPE_FLOAT);
00124 tempMsg.writeFloat(v->getGuiWidth());
00125 break;
00126 case VAR_COLOR:
00127 tempMsg.writeUnsignedByte(TYPE_COLOR);
00128 tempMsg.writeUnsignedByte((int)(v->getColor().red()*255.));
00129 tempMsg.writeUnsignedByte((int)(v->getColor().green()*255.));
00130 tempMsg.writeUnsignedByte((int)(v->getColor().blue()*255.));
00131 tempMsg.writeUnsignedByte(255);
00132 break;
00133 default:
00134 break;
00135 }
00136 }
00137 if (withStatus) {
00138 TraCIServerAPIHelper::writeStatusCmd(CMD_GET_VEHICLETYPE_VARIABLE, RTYPE_OK, warning, outputStorage);
00139 }
00140
00141 outputStorage.writeUnsignedByte(0);
00142 outputStorage.writeInt(1 + 4 + tempMsg.size());
00143 outputStorage.writeStorage(tempMsg);
00144 return true;
00145 }
00146
00147
00148 bool
00149 TraCIServerAPI_VehicleType::processSet(tcpip::Storage &inputStorage,
00150 tcpip::Storage &outputStorage) throw(TraCIException) {
00151 return true;
00152 }
00153
00154
00155
00156
00157