示例中的静脉 TraCIDemo11p
我想添加一个定期发送(每个 1s)一个 wsm 的方法
这是我修改的内容:
我创建了一个名为“sendTrace”
的方法,它类似于示例中的方法,但更改了 wsm 数据:
void TraCIDemo11p::sendTrace() {
t_channel channel = dataOnSch ? type_SCH : type_CCH;
WaveShortMessage* wsm = prepareWSM("data", dataLengthBits, channel, dataPriority, -1,2);
wsm->setWsmData(traceID.c_str());
sendWSM(wsm);
EV << "Received message2 `" << wsm->getSenderModuleId() << "', sending it out again\n";
}
在 traCIDemo11p.h 中
const std::string traceID ="trace";
在 onData
中,我为收到的消息添加了一个条件:
void TraCIDemo11p::onData(WaveShortMessage* wsm) {
if (wsm->getWsmData()== traceID.c_str()){
infoWsm.push_back(wsm);
EV << "Received message3 `" << wsm->getSenderModuleId() << "', sending it out again\n";
}
else{
findHost()->getDisplayString().updateWith("r=16,green");
annotations->scheduleErase(1, annotations->drawLine(wsm->getSenderPos(), mobility->getPositionAt(simTime()), "blue"));
if (mobility->getRoadId()[0] != ':') traciVehicle->changeRoute(wsm->getWsmData(), 9999);
if (!sentMessage) sendMessage(wsm->getWsmData());
EV << "Received message4`" << wsm->getSenderModuleId() << "', sending it out again\n";
}
在初始化时我发送了第一条轨迹:
void TraCIDemo11p::initialize(int stage) {
BaseWaveApplLayer::initialize(stage);
if (stage == 0) {
...
lastTraceAt = simTime();
sendTrace();
}
在 handleParkingUpdate
中,我控制其他跟踪的发送:
void TraCIDemo11p::handleParkingUpdate(cObject* obj) {
isParking = mobility->getParkingState();
if (sendWhileParking == false) {
if (isParking == true) {
(FindModule<BaseConnectionManager*>::findGlobalModule())->unregisterNic(this->getParentModule()->getSubmodule("nic"));
}
else {
Coord pos = mobility->getCurrentPosition();
(FindModule<BaseConnectionManager*>::findGlobalModule())->registerNic(this->getParentModule()->getSubmodule("nic"), (ChannelAccess*) this->getParentModule()->getSubmodule("nic")->getSubmodule("phy80211p"), &pos);
}
}
然后在运行时我遇到了这个错误!!
<!> Error in module (TraCIDemo11p) RSUExampleScenario.node[0].appl (id=14) at event #54, t=3.100413031916: TraCI server reported error executing command 0xc4 ("Referenced edge 'trace' is not known.")..
我无法确定这个问题的根源,你能帮帮我吗?
PS:我知道错误说边缘'trace'无法识别,这意味着 ondata 方法中设置的条件不起作用! 那么请告诉我如何解决它或者是否还有其他问题?
最佳答案
尝试使用 ==
比较两个 char*
意味着您正在比较内存地址,而不是(如您所假设的那样)那里存储了什么文本。
关于c++ - 使用 TraCIDemo11p 定期发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42201926/