Проблемы с обработкой сообщений вен, Omnet++
Я пытаюсь понять эту проблему, которую я не понимаю. Я модифицирую пример Veins, использую другую карту и пытаюсь обрабатывать сообщения. Я должен послать 3 WSA, когда произошла авария с интервалом в 3 секунды.
Первый wsm отправляется правильно, но что касается двух других во время симуляции, у меня есть этот вывод "посылка wsm". может кто-нибудь объяснить мне, почему? Спасибо
Я прикрепляю TraciDemo11p
//
// Copyright (C) 2006-2011 Christoph Sommer <christoph.sommer@uibk.ac.at>
//
// Documentation for these modules is at http://veins.car2x.org/
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#include "veins/modules/application/traci/TraCIDemo11p.h"
#include <iostream>
#include <string>
using namespace std;
Define_Module(TraCIDemo11p);
void TraCIDemo11p::initialize(int stage) {
BaseWaveApplLayer::initialize(stage);
if (stage == 0) {
sentMessage = false;
lastDroveAt = simTime();
currentSubscribedServiceId = -1;
}
}
void TraCIDemo11p::onWSA(WaveServiceAdvertisment* wsa) {
if (currentSubscribedServiceId == -1) {
mac->changeServiceChannel(wsa->getTargetChannel());
currentSubscribedServiceId = wsa->getPsid();
if (currentOfferedServiceId != wsa->getPsid()) {
stopService();
startService((Channels::ChannelNumber) wsa->getTargetChannel(), wsa->getPsid(), "Mirrored Traffic Service");
}
}
}
void TraCIDemo11p::onWSM(WaveShortMessage* wsm) {
findHost()->getDisplayString().updateWith("r=16,green"); // Colouring in the simulation
EV<<"WSM to change route received!"<<endl;
if (mobility->getRoadId()[0] != ':') traciVehicle->changeRoute(wsm->getWsmData(), 9999); // wsm->getWsmData() -> ID of route to avoid ; 9999 -> extra travel time allowed (here it is almost unlimited)
if (!sentMessage) {
sentMessage = true;
//repeat the received traffic update once in 2 seconds plus some random delay
wsm->setSenderAddress(myId);
wsm->setSerial(3);
scheduleAt(simTime() + 2 + uniform(0.01,0.2), wsm->dup());
}
}
void TraCIDemo11p::handleSelfMsg(cMessage* msg) {
if (WaveShortMessage* wsm = dynamic_cast<WaveShortMessage*>(msg)) {
//send this message on the service channel until the counter is 3 or higher.
//this code only runs when channel switching is enabled
sendDown(wsm->dup());
wsm->setSerial(wsm->getSerial() +1);
if (wsm->getSerial() >= 3) {
//stop service advertisements
stopService();
delete(wsm);
}
else {
scheduleAt(simTime()+1, wsm);
}
}
else {
BaseWaveApplLayer::handleSelfMsg(msg);
}
}
void TraCIDemo11p::handlePositionUpdate(cObject* obj) {
BaseWaveApplLayer::handlePositionUpdate(obj);
//string semaphore_status;
// stopped for for at least 10s?
if (mobility->getSpeed() < 1) {
if (simTime() - lastDroveAt >= 15 && sentMessage == false) {
findHost()->getDisplayString().updateWith("r=16,red");
sentMessage = true;
//semaphore_status = traci.trafficlight.getRedYellowGreenState(cluster_266558600_288718468);
//EV << semaphore_status << endl;
EV << "messaggio stampato a terminale" << endl;
WaveShortMessage* wsm = new WaveShortMessage();
populateWSM(wsm);
wsm->setWsmData(mobility->getRoadId().c_str());
WaveShortMessage* wsm2 = new WaveShortMessage();
populateWSM(wsm2);
wsm2->setWsmData(mobility->getRoadId().c_str());
scheduleAt(simTime()+3,wsm2);
WaveShortMessage* wsm3 = new WaveShortMessage();
populateWSM(wsm3);
wsm2->setWsmData(mobility->getRoadId().c_str());
scheduleAt(simTime()+6,wsm3);
// In SUMO a map is defined by a collection of segments. Every segment is ID by a number, representing the ID of the road.
// This ID is inserted inside the WSM data.
//host is standing still due to crash
if (dataOnSch) {
startService(Channels::SCH2, 42, "Traffic Information Service");
//started service and server advertising, schedule message to self to send later
scheduleAt(computeAsynchronousSendingTime(1,type_SCH),wsm);
//scheduleAt(computeAsynchronousSendingTime(simTime()+6,type_SCH),wsm3);
}
else {
//send right away on CCH, because channel switching is disabled
sendDown(wsm);
// sendDown(wsm2);
// sendDown(wsm3);
}
}
}
else {
lastDroveAt = simTime();
}
}