我是靠谱客的博主 舒服毛衣,最近开发中收集的这篇文章主要介绍OMNET++基础知识一,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

常用import和export导入导出文件
tictoc1的学习
在这里插入图片描述
ned文件

simple Txc1
//通过simple构建了一个节点
{
gates: //节点有两个门
input in;//输入门
output out;//输出门
}
//
// Two instances (tic and toc) of Txc1 connected both ways.
// Tic and toc will pass messages to one another.
//
network Tictoc1//构造一个网络,网络名称叫做Tictoc1
{
@display("bgb=147,150");//display可以理解为显示
submodules:
tic: Txc1 {
@display("p=31,36");
}
toc: Txc1 {
@display("p=91,83");
}
connections://两个节点如何连接
tic.out --> {
delay = 100ms; } --> toc.in;
tic.in <-- {
delay = 100ms; } <-- toc.out;
}

cc文件

#include <string.h>
#include <omnetpp.h>
using namespace omnetpp;
/**
* Derive the Txc1 class from cSimpleModule. In the Tictoc1 network,
* both the `tic' and `toc' modules are Txc1 objects, created by OMNeT++
* at the beginning of the simulation.
*/
class Txc1 : public cSimpleModule
{
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()
{
// Initialize is called at the beginning of the simulation.
// To bootstrap the tic-toc-tic-toc process, one of the modules needs
// to send the first message. Let this be `tic'.
// Am I Tic or Toc?
if (strcmp("tic", getName()) == 0) {//获取模块的名称,网络有两个子模块(tic、toc)
// create and send first message on gate "out". "tictocMsg" is an
// arbitrary string which will be the name of the message object.
cMessage *msg = new cMessage("tictocMsg");//生成一个消息
send(msg, "out");//通过out门发出消息
}
}
void Txc1::handleMessage(cMessage *msg)//toc收到消息后
{
// The handleMessage() method is called whenever a message arrives
// at the module. Here, we just send it to the other module, through
// gate `out'. Because both `tic' and `toc' does the same, the message
// will bounce between the two.
send(msg, "out"); // send out the message
}

最后

以上就是舒服毛衣为你收集整理的OMNET++基础知识一的全部内容,希望文章能够帮你解决OMNET++基础知识一所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(48)

评论列表共有 0 条评论

立即
投稿
返回
顶部