在示例TraCIDemo11p
中使用静脉我想添加一个定期发送(每个1)一个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:我知道错误说边缘跟踪&#39;无法识别这意味着在ondata方法中设置的条件不起作用!! 那么请告诉我如何解决它或者是否存在其他问题?答案 0 :(得分:1)
尝试使用char*
比较两个==
意味着您正在比较内存地址,而不是(如您所假设)存储在那里的文本。