节点在Omnet / Inet中的位置

时间:2019-03-16 18:10:25

标签: omnet++ inet

我在复合模块中使用Inet的LinearMobility模块,我需要读取要在.cc代码中使用的节点的位置。我一直在寻找答案,并且遇到了这段代码:

cModule *host = getContainingNode(this); 
IMobility *mobility = check_and_cast<IMobility *>(host->getSubmodule("mobility"));
... = mobility->getCurrentPosition();

但是不幸的是,此代码引发了运行时错误,由于用于移动性的getCurrentPosition()方法不起作用,check_and_cast可能出了点问题。 (我也尝试过dynamic_cast而不是check_and_cast失败,代码仍然抛出错误)。 我收到的错误是:

  

20:11:54 ****为项目复制创建配置版本****   使MODE =释放所有copytic.cc在copytic.cc:5包含的文件中:   在包含的文件中   C:/用户/Rmin/om/inet4/src\inet/mobility/contract/IMobility.h:27:   C:/用户/Rmin/om/inet4/src\inet/common/geometry/common/Coord.h:307:27:   警告:'inet :: Coord :: str'重新声明为内联; 'dllimport'属性   忽略[-Wignored-attributes]内联std :: string Coord :: str()const                             ^在copytic.cc中包含的文件中:5:在以下文件中包含的文件中   C:/用户/Rmin/om/inet4/src\inet/mobility/contract/IMobility.h:28:   C:/用户/Rmin/om/inet4/src\inet/common/geometry/common/EulerAngles.h:77:33:   警告:'inet :: EulerAngles :: str'重新声明为内联; 'dllimport'   属性被忽略[-Wignored-attributes]内联std :: string   EulerAngles :: str()const                                   ^产生2条警告。 token_m.cc创建可执行文件:out / clang-release // copytic.exe   out / clang-release // copytic.o :(。text [_ZN7omnetpp14check_and_castIPN4inet9IMobilityENS_7cModuleEEET_PT0 _] + 0x18):   未定义对__imp__ZTIN4inet9IMobilityE' out/clang-release//copytic.o:(.rdata[_ZTIPN4inet9IMobilityE]+0x18): undefined reference to typeinfo的inet :: IMobility clang ++。exe的引用:   错误:链接器命令失败,退出代码为1(使用-v查看   调用)制作:*** [Makefile:102:out / clang-release // copytic.exe]   错误1

     

20:12:13构建完成(耗时18s.781ms)

我也从源文件中的代码块拍摄了照片:

screenshot of the above-mentioned 3 lines of code

如您所见,getCurrentPosition()方法不起作用,当我注释上述3行代码的第二行和第三行时,模拟运行没有任何问题。 这就是copytic.cc(copytic.cc仅用于测试3行代码,以获取节点的位置,并且没有任何其他用途):

    #include <string.h>
    #include <omnetpp.h>
    #include "token_m.h"
    #include "inet/mobility/contract/IMobility.h"


    using namespace omnetpp;
    using namespace std;
    using namespace inet;

class Txc1 : public cSimpleModule
{

public :
    simtime_t delay = 0.5 ;
    simtime_t delay2 = 0.5 ;
    simtime_t duration = 0.25 ;
    int maxnodes = 10 ;
    string x[10] = {"tic", "toc", "tic"} ;
    int numnodes = 2;
    int freenodeflag = 1;
    string successor ;
    string predecessor ;
    int inring = 0 ;
    string posx ;





protected:
    // The following redefined virtual function holds the algorithm.
    virtual void initialize() override;
    virtual void handleMessage(cMessage *msg) override;
};

// The module class needs to be registered with OMNeT++
Define_Module(Txc1);

void Txc1::initialize()
{

    WATCH(x[0]);
    WATCH(x[1]);
    WATCH(x[2]);
    WATCH(x[3]);
    WATCH(successor);
    WATCH(numnodes);
    WATCH(y);
    WATCH(posx);

        Token *msgt = new Token("tok");
        msgt->setRingorder(0, "tic");
        successor="toc";
        predecessor="toc";
        cModule *target = getModuleByPath("Tictoc1.toc");
        sendDirect(msgt, delay , duration , target , "radioIn");
        inring = 1 ;

}

void Txc1::handleMessage(cMessage *msg)
{

    cModule *host = getParentModule()->getSubmodule("tec")->getSubmodule("mobility");
    IMobility *mmobility = check_and_cast<IMobility *>(host);
    Coord pos = mmobility->getCurrentPosition();



        if (strcmp("tok", msg->getName()) == 0 ) {
                Token *inv1 = new Token("tok");
                Token *inv2 = new Token("tok");
                Token *inv3 = new Token("tok");
                cModule *targetinv1 = getModuleByPath("Tictoc1.tic");
                cModule *targetinv2 = getModuleByPath("Tictoc1.toc");
                cModule *targetinv3 = getModuleByPath("Tictoc1.tec");
                sendDirect(inv1, delay , duration , targetinv1 , "radioIn");
                sendDirect(inv2, delay , duration , targetinv2 , "radioIn");
                sendDirect(inv3, delay , duration , targetinv3 , "radioIn");
            }

    }

0 个答案:

没有答案