我正在使用omnetpp 5.4.1,静脉4.7.1和sumo-0.30.0。 我正在TraCIDemo11p中编写自己的代码,我确实需要使用bsm消息。但是TraCIDemo11p不允许我使用它。 例如,我在TraCIDemo11p类的handlepositionupdate方法中创建了一个数组,因为我想在其中添加bsm。但是我遇到运行时错误,但是当我添加wsa和wsm时没有发生错误。 我有什么问题 我真的需要帮助,感谢您的指导。 我的代码是: TraCIDemo11p :: handlePositionUpdate(cObject * obj){ BaseWaveApplLayer :: handlePositionUpdate(obj);
// stopped for for at least 10s?
if (mobility->getSpeed() < 1) {
if (simTime() - lastDroveAt >= 10 && sentMessage == false) {
findHost()->getDisplayString().updateWith("r=16,red");
sentMessage = true;
WaveShortMessage* wsm = new WaveShortMessage();
populateWSM(wsm);
wsm->setWsmData(mobility->getRoadId().c_str());
//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);
}
else {
//send right away on CCH, because channel switching is disabled
sendDown(wsm);
}
}
}
else {
lastDroveAt = simTime();
}
协调方senderPosition =移动性-> getCurrentPosition();
//Get all available nodes in simulation
std::map<std::string, cModule*> availableCars = mobility->getManager()-
getManagedHosts();
//Iterate through collection and find distance,
std::map<std::string, cModule*>::iterator it;
for(it = availableCars.begin(); it != availableCars.end(); it++)
{
TraCIMobility* mobility1 = TraCIMobilityAccess().get(it->second);
Coord receiverPosition = mobility1->getCurrentPosition();
double distance=senderPosition.distance(receiverPosition);
std::cout<<"we defined distance"<<endl;
WaveShortMessage* wsm = new WaveShortMessage();
BasicSafetyMessage* bsm = new BasicSafetyMessage();
wsm->setDistance(distance);
cArray array("array1");
array.add(wsm);
double dist[400];
double TheMax=dist[0];
for(int i=0;i<array.size();i++){
std::cout<< wsm->getDistance() << endl;
dist[i]=wsm->getDistance();
if(dist[i]>TheMax){
TheMax=dist[i];
int index=i;
std::cout<<"the max distance is "<<TheMax<<endl;
}}
simtime_t T=simTime()+60;
Coord senderPosition1=mobility->getPositionAt(T);
double direction1=mobility->getAngleRad();
std::map<std::string, cModule*> availableCars = mobility->getManager()-
>getManagedHosts();
std::map<std::string, cModule*>::iterator it;
for(it = availableCars.begin(); it != availableCars.end(); it++)
{
TraCIMobility* mobility2 = TraCIMobilityAccess().get(it->second);
double direction2=mobility2->getAngleRad();
Coord receiverPosition1=mobility2->getPositionAt(T);
if(direction2!=direction1){
std::cout<<"they move in opposite direction"<<endl;
}
double distance1=senderPosition.distance(receiverPosition);
std::cout<<"the first distance is "<<distance1 <<endl;
WaveShortMessage* wsm = new WaveShortMessage();
BasicSafetyMessage* bsm = new BasicSafetyMessage();
cArray array("array1");
int index = array.add(wsm);
double distance2=senderPosition1.distance(receiverPosition1);
std::cout<<"the second distance is:"<<distance2<<endl;
if(distance2>distance1){
std::cout<<"they are getting far away"<<endl;
array.remove(wsm);
} } }}