接上一篇文章
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 运行结果