c++/omnnet++在静脉浸泡,静脉_INET中忽略了功能

发布于 2025-02-02 21:03:49 字数 1781 浏览 1 评论 0原文

我不知道我是否没有在Eclipse/Omnet ++中添加函数背后的逻辑: 尝试将新的函数“ init_func”添加到静脉启动

#pragma once

#include "veins_inet.h"

#include "VeinsInetApplicationBase.h"

class VEINS_INET_API VeinsInetSampleApplication : public veins::VeinsInetApplicationBase {
protected:
bool haveForwarded = false;

protected:
virtual bool startApplication() override;
virtual bool stopApplication() override;
virtual void processPacket(std::shared_ptr<inet::Packet> pk) override;
// ADAPTION 2022/05/28
virtual void init_func();


public:
VeinsInetSampleApplication();
~VeinsInetSampleApplication();


};

。我的模拟。

这是代码段,基本上应在时间t = 5秒钟向我的所有模拟节点发送消息。与StartApplication()函数的唯一区别在于,发送消息是在t = 5sec处触发的。而不是t = 10秒。 startapplication()函数正确地完成了其作业,即使我将其评论并仅使我的init_func()函数运行也被忽略了。 (我尝试了此操作,以排除“此”指针等的任何问题,这表明这两个功能之间都存在“不良互动”)。因此,似乎我的init_func()似乎没有注册。但是我不知道。是否有人知道为什么Omnet ++在这里忽略了为什么“ init_func()”?

init_func()的代码:(

void VeinsInetSampleApplication::init_func()
{

// host[0] should stop at t=5s, change in timerManger.create(...)
if (getParentModule()->getIndex() == 0) {
    auto callback = [this]() {
        getParentModule()->getDisplayString().setTagArg("i", 1, "red");

        traciVehicle->setSpeed(0);

        auto payload = makeShared<VeinsInetSampleMessage>();
        timestampPayload(payload);
        payload->setChunkLength(B(100));
        payload->setRoadId(traciVehicle->getRoadId().c_str());

        auto packet = createPacket("accident");
        packet->insertAtBack(payload);
        sendPacket(std::move(packet));
    };


    timerManager.create(veins::TimerSpecification(callback).oneshotAt(SimTime(5, SIMTIME_S)));
}


}

当然也不是成功的)。

我还将“ init_func”的返回类型更改为bool,以进一步提高相似性。但是, 卢卡斯

I don't know whether I don't get the logic behind adding a function to eclipse/omnet++:
Tried to simply add a new function "init_func" to the VeinsInetSampleApplication.h Header file

#pragma once

#include "veins_inet.h"

#include "VeinsInetApplicationBase.h"

class VEINS_INET_API VeinsInetSampleApplication : public veins::VeinsInetApplicationBase {
protected:
bool haveForwarded = false;

protected:
virtual bool startApplication() override;
virtual bool stopApplication() override;
virtual void processPacket(std::shared_ptr<inet::Packet> pk) override;
// ADAPTION 2022/05/28
virtual void init_func();


public:
VeinsInetSampleApplication();
~VeinsInetSampleApplication();


};

However when I simply copy the initialization code of the startApplication() function into "init_func()" in VeinsInetSampleApplication.cc "init_func()" is simply ignored by my simulation.

Here's the code snippet which basically shall send a message to all my simulation nodes at time t=5 sec. The only difference to the startApplication() function is that the message sending is triggered at t=5sec. and not at t=10sec.
The startApplication() function does its job correctly and even if i comment it out and only make my init_func() function run it is also ignored. (I tried this in order to rule out any issues with the "this" pointer etc. which would suggest there is a "bad interaction" between both functions). So it really seems like my init_func() is not registered. But I don't know. Does anybody have an idea why "init_func()" might be ignored here by Omnet++?

Code of init_func():

void VeinsInetSampleApplication::init_func()
{

// host[0] should stop at t=5s, change in timerManger.create(...)
if (getParentModule()->getIndex() == 0) {
    auto callback = [this]() {
        getParentModule()->getDisplayString().setTagArg("i", 1, "red");

        traciVehicle->setSpeed(0);

        auto payload = makeShared<VeinsInetSampleMessage>();
        timestampPayload(payload);
        payload->setChunkLength(B(100));
        payload->setRoadId(traciVehicle->getRoadId().c_str());

        auto packet = createPacket("accident");
        packet->insertAtBack(payload);
        sendPacket(std::move(packet));
    };


    timerManager.create(veins::TimerSpecification(callback).oneshotAt(SimTime(5, SIMTIME_S)));
}


}

(I also changed return type of "init_func" to bool to further increase similarity. But that of course was also not successful)

Best regards,
Lukas

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小兔几 2025-02-09 21:03:49

init_func()被忽略了,因为initialize()也不通过任何其他方法来调用它。您决定创建一种新方法,因此您必须在代码中某个地方添加该方法的调用。

init_func() is ignored because it is not called neither by initialize() nor by any other method. You decided to create a new method, so you have to add calling of that method somewhere in the code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文