本文整理汇总了C++中TraCIServer类的典型用法代码示例。如果您正苦于以下问题:C++ TraCIServer类的具体用法?C++ TraCIServer怎么用?C++ TraCIServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TraCIServer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: catch
bool
TraCIServerAPI_VehicleType::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
std::string warning = ""; // additional description for response
// variable
int variable = inputStorage.readUnsignedByte();
if (variable != VAR_LENGTH && variable != VAR_MAXSPEED && variable != VAR_VEHICLECLASS
&& variable != VAR_SPEED_FACTOR && variable != VAR_SPEED_DEVIATION && variable != VAR_EMISSIONCLASS
&& variable != VAR_WIDTH && variable != VAR_MINGAP && variable != VAR_SHAPECLASS
&& variable != VAR_ACCEL && variable != VAR_DECEL && variable != VAR_IMPERFECTION
&& variable != VAR_TAU && variable != VAR_COLOR
) {
server.writeStatusCmd(CMD_SET_VEHICLETYPE_VARIABLE, RTYPE_ERR, "Change Vehicle Type State: unsupported variable specified", outputStorage);
return false;
}
// id
std::string id = inputStorage.readString();
MSVehicleType* v = MSNet::getInstance()->getVehicleControl().getVType(id);
if (v == 0) {
server.writeStatusCmd(CMD_SET_VEHICLETYPE_VARIABLE, RTYPE_ERR, "Vehicle type '" + id + "' is not known", outputStorage);
return false;
}
// process
try {
if (setVariable(CMD_SET_VEHICLETYPE_VARIABLE, variable, inputStorage.readUnsignedByte(),
*v, server, inputStorage, outputStorage)) {
server.writeStatusCmd(CMD_SET_VEHICLETYPE_VARIABLE, RTYPE_OK, warning, outputStorage);
return true;
}
} catch (ProcessError& e) {
server.writeStatusCmd(CMD_SET_VEHICLETYPE_VARIABLE, RTYPE_ERR, e.what(), outputStorage);
}
return false;
}
开发者ID:smendez-hi,项目名称:SUMO-hib,代码行数:34,代码来源:TraCIServerAPI_VehicleType.cpp
示例2: getMainWindow
// ===========================================================================
// method definitions
// ===========================================================================
bool
TraCIServerAPI_GUI::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
// variable & id
int variable = inputStorage.readUnsignedByte();
std::string id = inputStorage.readString();
// check variable
if (variable != ID_LIST && variable != VAR_VIEW_ZOOM && variable != VAR_VIEW_OFFSET
&& variable != VAR_VIEW_SCHEMA && variable != VAR_VIEW_BOUNDARY) {
return server.writeErrorStatusCmd(CMD_GET_GUI_VARIABLE, "Get GUI Variable: unsupported variable specified", outputStorage);
}
// begin response building
tcpip::Storage tempMsg;
// response-code, variableID, objectID
tempMsg.writeUnsignedByte(RESPONSE_GET_GUI_VARIABLE);
tempMsg.writeUnsignedByte(variable);
tempMsg.writeString(id);
// process request
if (variable == ID_LIST) {
std::vector<std::string> ids = getMainWindow()->getViewIDs();
tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
tempMsg.writeStringList(ids);
} else {
GUISUMOAbstractView* v = getNamedView(id);
if (v == 0) {
return server.writeErrorStatusCmd(CMD_GET_GUI_VARIABLE, "View '" + id + "' is not known", outputStorage);
}
switch (variable) {
case VAR_VIEW_ZOOM:
tempMsg.writeUnsignedByte(TYPE_DOUBLE);
tempMsg.writeDouble(v->getChanger().getZoom());
break;
case VAR_VIEW_OFFSET:
tempMsg.writeUnsignedByte(POSITION_2D);
tempMsg.writeDouble(v->getChanger().getXPos());
tempMsg.writeDouble(v->getChanger().getYPos());
break;
case VAR_VIEW_SCHEMA: {
FXComboBox& c = v->getColoringSchemesCombo();
tempMsg.writeUnsignedByte(TYPE_STRING);
tempMsg.writeString((std::string)c.getItem(c.getCurrentItem()).text());
break;
}
case VAR_VIEW_BOUNDARY: {
tempMsg.writeUnsignedByte(TYPE_BOUNDINGBOX);
Boundary b = v->getVisibleBoundary();
tempMsg.writeDouble(b.xmin());
tempMsg.writeDouble(b.ymin());
tempMsg.writeDouble(b.xmax());
tempMsg.writeDouble(b.ymax());
break;
}
default:
break;
}
}
server.writeStatusCmd(CMD_GET_GUI_VARIABLE, RTYPE_OK, "", outputStorage);
server.writeResponseWithLength(outputStorage, tempMsg);
return true;
}
开发者ID:RamonHPSilveira,项目名称:urbansim,代码行数:63,代码来源:TraCIServerAPI_GUI.cpp
示例3: switch
// ===========================================================================
// method definitions
// ===========================================================================
bool
TraCIServerAPI_POI::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
const int variable = inputStorage.readUnsignedByte();
const std::string id = inputStorage.readString();
server.initWrapper(libsumo::RESPONSE_GET_POI_VARIABLE, variable, id);
try {
if (!libsumo::POI::handleVariable(id, variable, &server)) {
switch (variable) {
case libsumo::VAR_PARAMETER: {
std::string paramName = "";
if (!server.readTypeCheckingString(inputStorage, paramName)) {
return server.writeErrorStatusCmd(libsumo::CMD_GET_POI_VARIABLE, "Retrieval of a parameter requires its name.", outputStorage);
}
server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_STRING);
server.getWrapperStorage().writeString(libsumo::POI::getParameter(id, paramName));
break;
}
default:
return server.writeErrorStatusCmd(libsumo::CMD_GET_POI_VARIABLE, "Get PoI Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
}
}
} catch (libsumo::TraCIException& e) {
return server.writeErrorStatusCmd(libsumo::CMD_GET_POI_VARIABLE, e.what(), outputStorage);
}
server.writeStatusCmd(libsumo::CMD_GET_POI_VARIABLE, libsumo::RTYPE_OK, "", outputStorage);
server.writeResponseWithLength(outputStorage, server.getWrapperStorage());
return true;
}
开发者ID:behrisch,项目名称:sumo,代码行数:32,代码来源:TraCIServerAPI_POI.cpp
示例4: switch
bool
TraCIServerAPI_Simulation::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
std::string warning = ""; // additional description for response
// variable
int variable = inputStorage.readUnsignedByte();
if (variable != CMD_CLEAR_PENDING_VEHICLES) {
return server.writeErrorStatusCmd(CMD_SET_SIM_VARIABLE, "Set Simulation Variable: unsupported variable specified", outputStorage);
}
// id
std::string id = inputStorage.readString();
// process
switch (variable) {
case CMD_CLEAR_PENDING_VEHICLES: {
//clear any pending vehicle insertions
std::string route;
if (!server.readTypeCheckingString(inputStorage, route)) {
return server.writeErrorStatusCmd(CMD_SET_SIM_VARIABLE, "A string is needed for clearing pending vehicles.", outputStorage);
}
MSNet::getInstance()->getInsertionControl().clearPendingVehicles(route);
}
break;
default:
break;
}
server.writeStatusCmd(CMD_SET_SIM_VARIABLE, RTYPE_OK, warning, outputStorage);
return true;
}
开发者ID:,项目名称:,代码行数:28,代码来源:
示例5: getPoI
// ===========================================================================
// method definitions
// ===========================================================================
bool
TraCIServerAPI_POI::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
// variable & id
int variable = inputStorage.readUnsignedByte();
std::string id = inputStorage.readString();
// check variable
if (variable != ID_LIST && variable != VAR_TYPE && variable != VAR_COLOR && variable != VAR_POSITION && variable != ID_COUNT) {
return server.writeErrorStatusCmd(CMD_GET_POI_VARIABLE, "Get PoI Variable: unsupported variable specified", outputStorage);
}
// begin response building
tcpip::Storage tempMsg;
// response-code, variableID, objectID
tempMsg.writeUnsignedByte(RESPONSE_GET_POI_VARIABLE);
tempMsg.writeUnsignedByte(variable);
tempMsg.writeString(id);
// process request
if (variable == ID_LIST || variable == ID_COUNT) {
std::vector<std::string> ids;
ShapeContainer& shapeCont = MSNet::getInstance()->getShapeContainer();
shapeCont.getPOIs().insertIDs(ids);
if (variable == ID_LIST) {
tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
tempMsg.writeStringList(ids);
} else {
tempMsg.writeUnsignedByte(TYPE_INTEGER);
tempMsg.writeInt((int) ids.size());
}
} else {
PointOfInterest* p = getPoI(id);
if (p == 0) {
return server.writeErrorStatusCmd(CMD_GET_POI_VARIABLE, "POI '" + id + "' is not known", outputStorage);
}
switch (variable) {
case VAR_TYPE:
tempMsg.writeUnsignedByte(TYPE_STRING);
tempMsg.writeString(p->getType());
break;
case VAR_COLOR:
tempMsg.writeUnsignedByte(TYPE_COLOR);
tempMsg.writeUnsignedByte(p->getColor().red());
tempMsg.writeUnsignedByte(p->getColor().green());
tempMsg.writeUnsignedByte(p->getColor().blue());
tempMsg.writeUnsignedByte(p->getColor().alpha());
break;
case VAR_POSITION:
tempMsg.writeUnsignedByte(POSITION_2D);
tempMsg.writeDouble(p->x());
tempMsg.writeDouble(p->y());
break;
default:
break;
}
}
server.writeStatusCmd(CMD_GET_POI_VARIABLE, RTYPE_OK, "", outputStorage);
server.writeResponseWithLength(outputStorage, tempMsg);
return true;
}
开发者ID:namnatulco,项目名称:sumo-complete,代码行数:61,代码来源:TraCIServerAPI_POI.cpp
示例6: if
// ===========================================================================
// method definitions
// ===========================================================================
bool
TraCIServerAPI_Junction::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
// variable
int variable = inputStorage.readUnsignedByte();
std::string id = inputStorage.readString();
// check variable
if (variable != ID_LIST && variable != VAR_POSITION && variable != ID_COUNT && variable != VAR_SHAPE) {
return server.writeErrorStatusCmd(CMD_GET_JUNCTION_VARIABLE, "Get Junction Variable: unsupported variable specified", outputStorage);
}
// begin response building
tcpip::Storage tempMsg;
// response-code, variableID, objectID
tempMsg.writeUnsignedByte(RESPONSE_GET_JUNCTION_VARIABLE);
tempMsg.writeUnsignedByte(variable);
tempMsg.writeString(id);
if (variable == ID_LIST) {
std::vector<std::string> ids;
MSNet::getInstance()->getJunctionControl().insertIDs(ids);
tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
tempMsg.writeStringList(ids);
} else if (variable == ID_COUNT) {
std::vector<std::string> ids;
MSNet::getInstance()->getJunctionControl().insertIDs(ids);
tempMsg.writeUnsignedByte(TYPE_INTEGER);
tempMsg.writeInt((int) ids.size());
} else {
MSJunction* j = MSNet::getInstance()->getJunctionControl().get(id);
if (j == 0) {
return server.writeErrorStatusCmd(CMD_GET_JUNCTION_VARIABLE, "Junction '" + id + "' is not known", outputStorage);
}
switch (variable) {
case ID_LIST:
break;
case VAR_POSITION:
tempMsg.writeUnsignedByte(POSITION_2D);
tempMsg.writeDouble(j->getPosition().x());
tempMsg.writeDouble(j->getPosition().y());
break;
case VAR_SHAPE:
tempMsg.writeUnsignedByte(TYPE_POLYGON);
tempMsg.writeUnsignedByte((int)MIN2(static_cast<size_t>(255), j->getShape().size()));
for (unsigned int iPoint = 0; iPoint < MIN2(static_cast<size_t>(255), j->getShape().size()); ++iPoint) {
tempMsg.writeDouble(j->getShape()[iPoint].x());
tempMsg.writeDouble(j->getShape()[iPoint].y());
}
break;
default:
break;
}
}
server.writeStatusCmd(CMD_GET_JUNCTION_VARIABLE, RTYPE_OK, "", outputStorage);
server.writeResponseWithLength(outputStorage, tempMsg);
return true;
}
开发者ID:namnatulco,项目名称:sumo-complete,代码行数:59,代码来源:TraCIServerAPI_Junction.cpp
示例7: if
// ===========================================================================
// method definitions
// ===========================================================================
bool
TraCIServerAPI_Route::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
// variable & id
int variable = inputStorage.readUnsignedByte();
std::string id = inputStorage.readString();
// check variable
if (variable != ID_LIST && variable != VAR_EDGES && variable != ID_COUNT) {
server.writeStatusCmd(CMD_GET_ROUTE_VARIABLE, RTYPE_ERR, "Get Route Variable: unsupported variable specified", outputStorage);
return false;
}
// begin response building
tcpip::Storage tempMsg;
// response-code, variableID, objectID
tempMsg.writeUnsignedByte(RESPONSE_GET_ROUTE_VARIABLE);
tempMsg.writeUnsignedByte(variable);
tempMsg.writeString(id);
// process request
if (variable == ID_LIST) {
std::vector<std::string> ids;
MSRoute::insertIDs(ids);
tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
tempMsg.writeStringList(ids);
} else if (variable == ID_COUNT) {
std::vector<std::string> ids;
MSRoute::insertIDs(ids);
tempMsg.writeUnsignedByte(TYPE_INTEGER);
tempMsg.writeInt((int) ids.size());
} else {
const MSRoute* r = MSRoute::dictionary(id);
if (r == 0) {
server.writeStatusCmd(CMD_GET_ROUTE_VARIABLE, RTYPE_ERR, "Route '" + id + "' is not known", outputStorage);
return false;
}
switch (variable) {
case VAR_EDGES:
tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
tempMsg.writeInt(r->size());
for (MSRouteIterator i = r->begin(); i != r->end(); ++i) {
tempMsg.writeString((*i)->getID());
}
break;
default:
break;
}
}
server.writeStatusCmd(CMD_GET_ROUTE_VARIABLE, RTYPE_OK, "", outputStorage);
server.writeResponseWithLength(outputStorage, tempMsg);
return true;
}
开发者ID:rudhir-upretee,项目名称:SUMO_Src,代码行数:53,代码来源:TraCIServerAPI_Route.cpp
示例8: switch
bool
TraCIServerAPI_Route::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
std::string warning = ""; // additional description for response
// variable
int variable = inputStorage.readUnsignedByte();
if (variable != ADD) {
server.writeStatusCmd(CMD_SET_ROUTE_VARIABLE, RTYPE_ERR, "Change Route State: unsupported variable specified", outputStorage);
return false;
}
// id
std::string id = inputStorage.readString();
// process
int valueDataType = inputStorage.readUnsignedByte();
switch (variable) {
case ADD: {
if (valueDataType != TYPE_STRINGLIST) {
server.writeStatusCmd(CMD_SET_ROUTE_VARIABLE, RTYPE_ERR, "A string list is needed for adding a new route.", outputStorage);
return false;
}
//read itemNo
int numEdges = inputStorage.readInt();
MSEdgeVector edges;
while (numEdges--) {
std::string edgeID = inputStorage.readString();
MSEdge* edge = MSEdge::dictionary(edgeID);
if (edge == 0) {
server.writeStatusCmd(CMD_SET_ROUTE_VARIABLE, RTYPE_ERR, "Unknown edge '" + edgeID + "' in route.", outputStorage);
return false;
}
edges.push_back(edge);
}
const std::vector<SUMOVehicleParameter::Stop> stops;
if (!MSRoute::dictionary(id, new MSRoute(id, edges, 1, 0, stops))) {
server.writeStatusCmd(CMD_SET_ROUTE_VARIABLE, RTYPE_ERR, "Could not add route.", outputStorage);
return false;
}
}
break;
default:
break;
}
server.writeStatusCmd(CMD_SET_ROUTE_VARIABLE, RTYPE_OK, warning, outputStorage);
return true;
}
开发者ID:rudhir-upretee,项目名称:SUMO_Src,代码行数:45,代码来源:TraCIServerAPI_Route.cpp
示例9: if
// ===========================================================================
// method definitions
// ===========================================================================
bool
TraCIServerAPI_VehicleType::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
std::string warning = ""; // additional description for response
// variable & id
int variable = inputStorage.readUnsignedByte();
std::string id = inputStorage.readString();
// check variable
if (variable != ID_LIST && variable != VAR_LENGTH && variable != VAR_MAXSPEED && variable != VAR_ACCEL && variable != VAR_DECEL
&& variable != VAR_TAU && variable != VAR_VEHICLECLASS && variable != VAR_EMISSIONCLASS && variable != VAR_SHAPECLASS
&& variable != VAR_SPEED_FACTOR && variable != VAR_SPEED_DEVIATION && variable != VAR_IMPERFECTION
&& variable != VAR_MINGAP && variable != VAR_WIDTH && variable != VAR_COLOR && variable != ID_COUNT) {
server.writeStatusCmd(CMD_GET_VEHICLETYPE_VARIABLE, RTYPE_ERR, "Get Vehicle Type Variable: unsupported variable specified", outputStorage);
return false;
}
// begin response building
tcpip::Storage tempMsg;
// response-code, variableID, objectID
tempMsg.writeUnsignedByte(RESPONSE_GET_VEHICLETYPE_VARIABLE);
tempMsg.writeUnsignedByte(variable);
tempMsg.writeString(id);
// process request
if (variable == ID_LIST) {
std::vector<std::string> ids;
MSNet::getInstance()->getVehicleControl().insertVTypeIDs(ids);
tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
tempMsg.writeStringList(ids);
} else if (variable == ID_COUNT) {
std::vector<std::string> ids;
MSNet::getInstance()->getVehicleControl().insertVTypeIDs(ids);
tempMsg.writeUnsignedByte(TYPE_INTEGER);
tempMsg.writeInt((int) ids.size());
} else {
MSVehicleType* v = MSNet::getInstance()->getVehicleControl().getVType(id);
if (v == 0) {
server.writeStatusCmd(CMD_GET_VEHICLETYPE_VARIABLE, RTYPE_ERR, "Vehicle type '" + id + "' is not known", outputStorage);
return false;
}
getVariable(variable, *v, tempMsg);
}
server.writeStatusCmd(CMD_GET_VEHICLETYPE_VARIABLE, RTYPE_OK, warning, outputStorage);
server.writeResponseWithLength(outputStorage, tempMsg);
return true;
}
开发者ID:smendez-hi,项目名称:SUMO-hib,代码行数:47,代码来源:TraCIServerAPI_VehicleType.cpp
示例10: toHex
bool
TraCIServerAPI_Simulation::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
std::string warning = ""; // additional description for response
// variable
int variable = inputStorage.readUnsignedByte();
if (variable != CMD_CLEAR_PENDING_VEHICLES
&& variable != CMD_SAVE_SIMSTATE) {
return server.writeErrorStatusCmd(CMD_SET_SIM_VARIABLE, "Set Simulation Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
}
// id
std::string id = inputStorage.readString();
// process
try {
switch (variable) {
case CMD_CLEAR_PENDING_VEHICLES: {
//clear any pending vehicle insertions
std::string route;
if (!server.readTypeCheckingString(inputStorage, route)) {
return server.writeErrorStatusCmd(CMD_SET_SIM_VARIABLE, "A string is needed for clearing pending vehicles.", outputStorage);
}
libsumo::Simulation::clearPending(route);
}
break;
case CMD_SAVE_SIMSTATE: {
//save current simulation state
std::string file;
if (!server.readTypeCheckingString(inputStorage, file)) {
return server.writeErrorStatusCmd(CMD_SET_SIM_VARIABLE, "A string is needed for saving simulation state.", outputStorage);
}
libsumo::Simulation::saveState(file);
}
break;
default:
break;
}
} catch (libsumo::TraCIException& e) {
return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, e.what(), outputStorage);
}
server.writeStatusCmd(CMD_SET_SIM_VARIABLE, RTYPE_OK, warning, outputStorage);
return true;
}
开发者ID:fieryzig,项目名称:sumo,代码行数:42,代码来源:TraCIServerAPI_Simulation.cpp
示例11: toHex
// ===========================================================================
// method definitions
// ===========================================================================
bool
TraCIServerAPI_MultiEntryExit::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
const int variable = inputStorage.readUnsignedByte();
const std::string id = inputStorage.readString();
server.initWrapper(libsumo::RESPONSE_GET_MULTIENTRYEXIT_VARIABLE, variable, id);
try {
if (!libsumo::MultiEntryExit::handleVariable(id, variable, &server)) {
return server.writeErrorStatusCmd(libsumo::CMD_GET_MULTIENTRYEXIT_VARIABLE, "Get Multi Entry Exit Detector Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
}
} catch (libsumo::TraCIException& e) {
return server.writeErrorStatusCmd(libsumo::CMD_GET_MULTIENTRYEXIT_VARIABLE, e.what(), outputStorage);
}
server.writeStatusCmd(libsumo::CMD_GET_MULTIENTRYEXIT_VARIABLE, libsumo::RTYPE_OK, "", outputStorage);
server.writeResponseWithLength(outputStorage, server.getWrapperStorage());
return true;
}
开发者ID:behrisch,项目名称:sumo,代码行数:20,代码来源:TraCIServerAPI_MultiEntryExit.cpp
示例12: switch
bool
TraCIServerAPI_Route::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
std::string warning = ""; // additional description for response
// variable
int variable = inputStorage.readUnsignedByte();
if (variable != ADD) {
return server.writeErrorStatusCmd(CMD_SET_ROUTE_VARIABLE, "Change Route State: unsupported variable specified", outputStorage);
}
// id
std::string id = inputStorage.readString();
// process
switch (variable) {
case ADD: {
std::vector<std::string> edgeIDs;
if (!server.readTypeCheckingStringList(inputStorage, edgeIDs)) {
return server.writeErrorStatusCmd(CMD_SET_ROUTE_VARIABLE, "A string list is needed for adding a new route.", outputStorage);
}
//read itemNo
MSEdgeVector edges;
for (std::vector<std::string>::const_iterator i = edgeIDs.begin(); i != edgeIDs.end(); ++i) {
MSEdge* edge = MSEdge::dictionary(*i);
if (edge == 0) {
return server.writeErrorStatusCmd(CMD_SET_ROUTE_VARIABLE, "Unknown edge '" + *i + "' in route.", outputStorage);
}
edges.push_back(edge);
}
const std::vector<SUMOVehicleParameter::Stop> stops;
if (!MSRoute::dictionary(id, new MSRoute(id, edges, 1, 0, stops))) {
return server.writeErrorStatusCmd(CMD_SET_ROUTE_VARIABLE, "Could not add route.", outputStorage);
}
}
break;
default:
break;
}
server.writeStatusCmd(CMD_SET_ROUTE_VARIABLE, RTYPE_OK, warning, outputStorage);
return true;
}
开发者ID:rudhir-upretee,项目名称:Sumo17_With_Netsim,代码行数:39,代码来源:TraCIServerAPI_Route.cpp
示例13: if
// ===========================================================================
// method definitions
// ===========================================================================
bool
TraCIServerAPI_MeMeDetector::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
std::string warning = ""; // additional description for response
// variable & id
int variable = inputStorage.readUnsignedByte();
std::string id = inputStorage.readString();
// check variable
if (variable != ID_LIST && variable != LAST_STEP_VEHICLE_NUMBER && variable != LAST_STEP_MEAN_SPEED
&& variable != LAST_STEP_VEHICLE_ID_LIST && variable != LAST_STEP_VEHICLE_HALTING_NUMBER
&& variable != ID_COUNT) {
server.writeStatusCmd(CMD_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE, RTYPE_ERR, "Get MeMeDetector Variable: unsupported variable specified", outputStorage);
return false;
}
// begin response building
tcpip::Storage tempMsg;
// response-code, variableID, objectID
tempMsg.writeUnsignedByte(RESPONSE_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE);
tempMsg.writeUnsignedByte(variable);
tempMsg.writeString(id);
if (variable == ID_LIST) {
std::vector<std::string> ids;
MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_ENTRY_EXIT_DETECTOR).insertIDs(ids);
tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
tempMsg.writeStringList(ids);
} else if (variable == ID_COUNT) {
std::vector<std::string> ids;
MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_ENTRY_EXIT_DETECTOR).insertIDs(ids);
tempMsg.writeUnsignedByte(TYPE_INTEGER);
tempMsg.writeInt((int) ids.size());
} else {
MSE3Collector* e3 = static_cast<MSE3Collector*>(MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_ENTRY_EXIT_DETECTOR).get(id));
if (e3 == 0) {
server.writeStatusCmd(CMD_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE, RTYPE_ERR, "Areal detector '" + id + "' is not known", outputStorage);
return false;
}
switch (variable) {
case ID_LIST:
break;
case LAST_STEP_VEHICLE_NUMBER:
tempMsg.writeUnsignedByte(TYPE_INTEGER);
tempMsg.writeInt((int) e3->getVehiclesWithin());
break;
case LAST_STEP_MEAN_SPEED:
tempMsg.writeUnsignedByte(TYPE_DOUBLE);
tempMsg.writeDouble(e3->getCurrentMeanSpeed());
break;
case LAST_STEP_VEHICLE_ID_LIST: {
tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
std::vector<std::string> ids = e3->getCurrentVehicleIDs();
tempMsg.writeStringList(ids);
}
break;
case LAST_STEP_VEHICLE_HALTING_NUMBER:
tempMsg.writeUnsignedByte(TYPE_INTEGER);
tempMsg.writeInt((int) e3->getCurrentHaltingNumber());
break;
default:
break;
}
}
server.writeStatusCmd(CMD_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE, RTYPE_OK, warning, outputStorage);
server.writeResponseWithLength(outputStorage, tempMsg);
return true;
}
开发者ID:smendez-hi,项目名称:SUMO-hib,代码行数:68,代码来源:TraCIServerAPI_MeMeDetector.cpp
示例14: toHex
bool
TraCIServerAPI_POI::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
std::string warning = ""; // additional description for response
// variable & id
int variable = inputStorage.readUnsignedByte();
std::string id = inputStorage.readString();
// check variable
if (variable != libsumo::VAR_TYPE &&
variable != libsumo::VAR_COLOR &&
variable != libsumo::VAR_POSITION &&
variable != libsumo::VAR_WIDTH &&
variable != libsumo::VAR_HEIGHT &&
variable != libsumo::VAR_ANGLE &&
variable != libsumo::VAR_IMAGEFILE &&
variable != libsumo::VAR_HIGHLIGHT &&
variable != libsumo::ADD &&
variable != libsumo::REMOVE &&
variable != libsumo::VAR_PARAMETER) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "Change PoI State: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
}
// process
try {
switch (variable) {
case libsumo::VAR_TYPE: {
std::string type;
if (!server.readTypeCheckingString(inputStorage, type)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The type must be given as a string.", outputStorage);
}
libsumo::POI::setType(id, type);
}
break;
case libsumo::VAR_COLOR: {
libsumo::TraCIColor col;
if (!server.readTypeCheckingColor(inputStorage, col)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The color must be given using an according type.", outputStorage);
}
libsumo::POI::setColor(id, col);
}
break;
case libsumo::VAR_POSITION: {
libsumo::TraCIPosition pos;
if (!server.readTypeCheckingPosition2D(inputStorage, pos)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The position must be given using an according type.", outputStorage);
}
libsumo::POI::setPosition(id, pos.x, pos.y);
}
break;
case libsumo::VAR_WIDTH: {
double width;
if (!server.readTypeCheckingDouble(inputStorage, width)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The width must be given using an according type.", outputStorage);
}
libsumo::POI::setWidth(id, width);
}
break;
case libsumo::VAR_HEIGHT: {
double height;
if (!server.readTypeCheckingDouble(inputStorage, height)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The height must be given using an according type.", outputStorage);
}
libsumo::POI::setHeight(id, height);
}
break;
case libsumo::VAR_ANGLE: {
double angle;
if (!server.readTypeCheckingDouble(inputStorage, angle)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The angle must be given using an according type.", outputStorage);
}
libsumo::POI::setAngle(id, angle);
}
break;
case libsumo::VAR_IMAGEFILE: {
std::string imageFile;
if (!server.readTypeCheckingString(inputStorage, imageFile)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The type must be given as a string.", outputStorage);
}
libsumo::POI::setImageFile(id, imageFile);
}
break;
case libsumo::VAR_HIGHLIGHT: {
// Highlight the POI by adding a polygon (NOTE: duplicated code exists for vehicle domain)
if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "A compound object is needed for highlighting an object.", outputStorage);
}
int itemNo = inputStorage.readUnsignedByte();
if (itemNo > 5) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "Highlighting an object needs zero to five parameters.", outputStorage);
}
libsumo::TraCIColor col = libsumo::TraCIColor(255, 0, 0);
if (itemNo > 0) {
if (!server.readTypeCheckingColor(inputStorage, col)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The first parameter for highlighting must be the highlight color.", outputStorage);
}
}
double size = -1;
if (itemNo > 1) {
if (!server.readTypeCheckingDouble(inputStorage, size)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The second parameter for highlighting must be the highlight size.", outputStorage);
}
//.........这里部分代码省略.........
开发者ID:behrisch,项目名称:sumo,代码行数:101,代码来源:TraCIServerAPI_POI.cpp
示例15: nphase
bool
TraCIServerAPI_TLS::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
std::string warning = ""; // additional description for response
// variable
int variable = inputStorage.readUnsignedByte();
if (variable != TL_PHASE_INDEX && variable != TL_PROGRAM
&& variable != TL_PHASE_DURATION && variable != TL_RED_YELLOW_GREEN_STATE && variable != TL_COMPLETE_PROGRAM_RYG) {
server.writeStatusCmd(CMD_SET_TL_VARIABLE, RTYPE_ERR, "Change TLS State: unsupported variable specified", outputStorage);
return false;
}
std::string id = inputStorage.readString();
if (!MSNet::getInstance()->getTLSControl().knows(id)) {
server.writeStatusCmd(CMD_SET_TL_VARIABLE, RTYPE_ERR, "Traffic light '" + id + "' is not known", outputStorage);
return false;
}
MSTLLogicControl& tlsControl = MSNet::getInstance()->getTLSControl();
SUMOTime cTime = MSNet::getInstance()->getCurrentTimeStep();
MSTLLogicControl::TLSLogicVariants& vars = tlsControl.get(id);
int valueDataType = inputStorage.readUnsignedByte();
switch (variable) {
case TL_PHASE_INDEX: {
if (valueDataType != TYPE_INTEGER) {
server.writeStatusCmd(CMD_SET_TL_VARIABLE, RTYPE_ERR, "The phase index must be given as an integer.", outputStorage);
return false;
}
int index = inputStorage.readInt();
if (index < 0 || vars.getActive()->getPhaseNumber() <= (unsigned int)index) {
server.writeStatusCmd(CMD_SET_TL_VARIABLE, RTYPE_ERR, "The phase index is not in the allowed range.", outputStorage);
return false;
}
int duration = vars.getActive()->getPhase(index).duration;
vars.getActive()->changeStepAndDuration(tlsControl, cTime, index, duration);
}
break;
case TL_PROGRAM: {
if (valueDataType != TYPE_STRING) {
server.writeStatusCmd(CMD_SET_TL_VARIABLE, RTYPE_ERR, "The program must be given as a string.", outputStorage);
return false;
}
std::string subID = inputStorage.readString();
try {
vars.switchTo(tlsControl, subID);
} catch (ProcessError& e) {
server.writeStatusCmd(CMD_SET_TL_VARIABLE, RTYPE_ERR, e.what(), outputStorage);
return false;
}
}
break;
case TL_PHASE_DURATION: {
if (valueDataType != TYPE_INTEGER) {
server.writeStatusCmd(CMD_SET_TL_VARIABLE, RTYPE_ERR, "The phase duration must be given as an integer.", outputStorage);
return false;
}
int duration = inputStorage.readInt();
int index = vars.getActive()->getCurrentPhaseIndex();
vars.getActive()->changeStepAndDuration(tlsControl, cTime, index, duration);
}
break;
case TL_RED_YELLOW_GREEN_STATE: {
if (valueDataType != TYPE_STRING) {
server.writeStatusCmd(CMD_SET_TL_VARIABLE, RTYPE_ERR, "The phase must be given as a string.", outputStorage);
return false;
}
// build only once...
std::string state = inputStorage.readString();
if (vars.getLogic("online") == 0) {
MSPhaseDefinition* phase = new MSPhaseDefinition(DELTA_T, state);
std::vector<MSPhaseDefinition*> phases;
phases.push_back(phase);
MSTrafficLightLogic* logic = new MSSimpleTrafficLightLogic(tlsControl, id, "online", phases, 0, cTime + DELTA_T);
vars.addLogic("online", logic, true, true);
} else {
MSPhaseDefinition nphase(DELTA_T, state);
*(static_cast<MSSimpleTrafficLightLogic*>(vars.getLogic("online"))->getPhases()[0]) = nphase;
}
// @note: this assumes logic "online" is still active
vars.getActive()->setTrafficLightSignals(MSNet::getInstance()->getCurrentTimeStep());
vars.executeOnSwitchActions();
}
break;
case TL_COMPLETE_PROGRAM_RYG: {
if (valueDataType != TYPE_COMPOUND) {
server.writeStatusCmd(CMD_SET_TL_VARIABLE, RTYPE_ERR, "A compound object is needed for setting a new program.", outputStorage);
return false;
}
//read itemNo
inputStorage.readInt();
if (inputStorage.readUnsignedByte() != TYPE_STRING) {
server.writeStatusCmd(CMD_SET_TL_VARIABLE, RTYPE_ERR, "set program: 1. parameter (subid) must be a string.", outputStorage);
return false;
}
std::string subid = inputStorage.readString();
if (inputStorage.readUnsignedByte() != TYPE_INTEGER) {
server.writeStatusCmd(CMD_SET_TL_VARIABLE, RTYPE_ERR, "set program: 2. parameter (type) must be an int.", outputStorage);
return false;
}
//read type
inputStorage.readInt();
if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
//.........这里部分代码省略.........
开发者ID:rudhir-upretee,项目名称:SUMO_Src,代码行数:101,代码来源:TraCIServerAPI_TLS.cpp
示例16: switch
// ===========================================================================
// method definitions
// ===========================================================================
bool
TraCIServerAPI_Simulation::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
const int variable = inputStorage.readUnsignedByte();
const std::string id = inputStorage.readString();
server.initWrapper(RESPONSE_GET_SIM_VARIABLE, variable, id);
try {
switch (variable) {
case VAR_TIME:
server.getWrapperStorage().writeUnsignedByte(TYPE_DOUBLE);
server.getWrapperStorage().writeDouble(SIMTIME);
break;
case VAR_TIME_STEP:
server.getWrapperStorage().writeUnsignedByte(TYPE_INTEGER);
server.getWrapperStorage().writeInt((int)libsumo::Simulation::getCurrentTime());
break;
case VAR_LOADED_VEHICLES_NUMBER:
writeVehicleStateNumber(server, server.getWrapperStorage(), MSNet::VEHICLE_STATE_BUILT);
break;
case VAR_LOADED_VEHICLES_IDS:
writeVehicleStateIDs(server, server.getWrapperStorage(), MSNet::VEHICLE_STATE_BUILT);
break;
case VAR_DEPARTED_VEHICLES_NUMBER:
writeVehicleStateNumber(server, server.getWrapperStorage(), MSNet::VEHICLE_STATE_DEPARTED);
break;
case VAR_DEPARTED_VEHICLES_IDS:
writeVehicleStateIDs(server, server.getWrapperStorage(), MSNet::VEHICLE_STATE_DEPARTED);
break;
case VAR_TELEPORT_STARTING_VEHICLES_NUMBER:
writeVehicleStateNumber(server, server.getWrapperStorage(), MSNet::VEHICLE_STATE_STARTING_TELEPORT);
break;
case VAR_TELEPORT_STARTING_VEHICLES_IDS:
writeVehicleStateIDs(server, server.getWrapperStorage(), MSNet::VEHICLE_STATE_STARTING_TELEPORT)
|
请发表评论