OMNet++tictoc2

接上一篇文章

tictoc2运行及代码讲解

基于上一篇所讲解的tictoc1我们接下来看一下tictoc2
我们希望自己的网络界面更加的美观
在这里插入图片描述
在这里插入图片描述

1 NED文件

tictoc2.ned源文件代码

simple Txc2//定义Txc2节点,拥有输入输出,给他加入了图标文件,可以对图标颜色形状进行修改
{
    parameters:
        @display("i=block/routing"); // add a default iconj增加图标文件
    gates:
        input in;
        output out;
}

//
// Make the two module look a bit different with colorization effect.
// Use cyan for `tic', and yellow for `toc'.
//
network Tictoc2//定义网络Tictoc2,
{
    @display("bgb=284,250");
    submodules:
        tic: Txc2 {
            parameters:
                @display("i=,cyan;p=63,158"); // do not change the icon (first arg of i=) just colorize it
        }
        toc: Txc2 {
            parameters:
                @display("i=,gold;p=186,69"); // here too
        }
    connections:
        tic.out --> {  delay = 100ms; } --> toc.in;
        tic.in <-- {  delay = 100ms; } <-- toc.out;
}


2 c++文件

代码中加入下面语句,用于加入日志记录(EV, OMNeT++提供了一个复杂的记录工具 有记录的水平,记录频道,过滤,等等。)
EV << “Sending initial message\n”;
EV << “Received message `” << msg->getName() << “', sending it out again\n”;

#include <string.h>
#include <omnetpp.h>

using namespace omnetpp;

/**
 * In this step we add some debug messages to Txc1. When you run the
 * simulation in the OMNeT++ Qtenv GUI, the log will appear in the bottom
 * panel of the Qtenv window. To see only the log from `tic' or `toc' alone,
 * go into them by double-clicking their icons, and the bottom panel will
 * be filtered accordingly. (You can go back with the up arrow button on
 * the toolbar.)
 */
class Txc2 : public cSimpleModule
{
  protected:
    virtual void initialize() override;
    virtual void handleMessage(cMessage *msg) override;
};

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)
{
    // 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");
}


3 运行结果

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值