M_Tsing
2022-08-06 11:54
采纳率: 100%
浏览 14
已结题

omnet中获取了节点坐标后如何在发送信息时获取两个节点之间距离。

这是我找到的一段获取节点坐标的cc代码,但是之后怎么获取两个节点之间的距离?还望有人能给出具体方法。
#include <string.h>
#include <omnetpp.h>

class Txc2 : public cSimpleModule
{
private:
//添加模块坐标属性
const char *positionX;
const char *positionY;
protected:
virtual void initialize();
virtual void handleMessage(cMessage *msg);
};

Define_Module(Txc2);

void Txc2::initialize()
{
if (strcmp("tic", getName()) == 0)
{
// The ev' object works like cout' in C++.
EV << "Sending initial message\n";
cMessage *msg = new cMessage("tictocMsg");
send(msg, "out");
}
}

void Txc2::handleMessage(cMessage *msg)
{
EV <<"获取坐标\n";
cDisplayString& dispStr = getDisplayString();
positionX = dispStr.getTagArg("p", 0);
positionY = dispStr.getTagArg("p", 1);
EV<<positionX<< endl;
EV<<positionY<< endl;

// msg->getName() is name of the msg object, here it will be "tictocMsg".
EV << "Received message `" << msg->getName() << "', sending it out again\n";
send(msg, "out");

}

2条回答 默认 最新

相关推荐 更多相似问题