我在 TRACI 客户端中编写了一个函数来查询 SUMO(TRACI 服务器)以获取汽车的当前位置,我在 XY 坐标系中得到了正确的位置。现在我想将这个检索到的 XY 位置更改为纬度和经度。我按照http://www.sumo.dlr.de/wiki/TraCI/Simulation_Value_Retrieval#Command_0x82:_Position_Conversion上的文档进行编码, 但我收到错误! . 请看代码
TraCITestClient::Position TraCITestClient::getPosition()
{
send_commandGetVariable(0xa4, 0x42, "veh1");
tcpip::Storage inMsg;
try {
std::string acknowledgement;
check_resultState(inMsg, 0xa4, false, &acknowledgement);
} catch (tcpip::SocketException& e) {
pos.x = -1;
pos.y = -1;
return pos;
}
check_commandGetResult(inMsg, 0xa4, -1, false);
// report result state
try {
int variableID = inMsg.readUnsignedByte();
std::string objectID = inMsg.readString();
int valueDataType = inMsg.readUnsignedByte();
pos.x = inMsg.readDouble();
pos.y = inMsg.readDouble();
} catch (tcpip::SocketException& e) {
std::stringstream msg;
msg << "Error while receiving command: " << e.what();
errorMsg(msg);
pos.x = -1;
pos.y = -1;
return pos;
}
//till here i am getting correct value in pos.x and pos.y
// now i want to convert these XY coordinates to actual Lat Long
tcpip::Storage* tmp = new tcpip::Storage;
tmp->writeByte(TYPE_COMPOUND);
tmp->writeInt(2);
tmp->writeDouble(pos.x);
tmp->writeDouble(pos.y);
tmp->writeByte(TYPE_UBYTE);
tmp->writeUnsignedByte(POSITION_LON_LAT);
send_commandGetVariable(0x82, 0x58, "veh1",tmp); //**here i am getting error**
tcpip::Storage inMsgX;
try {
std::string acknowledgement;
check_resultState(inMsgX, 0x82, false, &acknowledgement);
} catch (tcpip::SocketException& e) {
return pos;
}
check_commandGetResult(inMsgX, 0x82, -1, false);
// report result state
try {
int variableID = inMsgX.readUnsignedByte();
std::string objectID = inMsgX.readString();
int valueDataType = inMsgX.readUnsignedByte();
pos.x = inMsgX.readDouble();
pos.y = inMsgX.readDouble();
} catch (tcpip::SocketException& e) {
std::stringstream msg;
msg << "Error while receiving command: " << e.what();
errorMsg(msg);
return pos;
}
return pos;
}
所以我在 SUMO 服务器上遇到的错误是:错误:tcpip::Storage::readIsSafe: 想要从存储中读取 823066624 字节,但仅剩 20 个正在退出(出错)。