<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="description" content="OMNeT++ 4 中文版Tictoc指南,来自奥普网络http://www.oopsweb.net"/>
<meta name="keywords" content="OMNeT++ 4,OMNeT++,Tictoc,网络模拟,无线传感器网络,通信网络"/>
<title>Tictoc Tutorial: txc9.cc</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.5 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="pages.html"><span>Related Pages</span></a></li>
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
<li><a href="dirs.html"><span>Directories</span></a></li>
</ul>
</div>
</div>
<div class="contents">
<h1><a class="anchor" name="txc9.cc"><a class="el" href="txc9_8cc.html">txc9.cc</a> </a></h1><div class="fragment"><pre class="fragment"><span class="comment">//</span>
<span class="comment">// This file is part of an OMNeT++/OMNEST simulation example.</span>
<span class="comment">//</span>
<span class="comment">// Copyright (C) 2003-2008 Andras Varga</span>
<span class="comment">//</span>
<span class="comment">// This file is distributed WITHOUT ANY WARRANTY. See the file</span>
<span class="comment">// `license' for details on this and other legal matters.</span>
<span class="comment">//</span>
<span class="preprocessor">#include <stdio.h></span>
<span class="preprocessor">#include <string.h></span>
<span class="preprocessor">#include <omnetpp.h></span>
<span class="keyword">class </span><a class="code" href="classTic9.html">Tic9</a> : <span class="keyword">public</span> <a class="codeRef" doxygen="opptags.xml:../api//" href="../api//classcSimpleModule.html">cSimpleModule</a>
{
<span class="keyword">private</span>:
simtime_t timeout; <span class="comment">// timeout</span>
<a class="codeRef" doxygen="opptags.xml:../api//" href="../api//classcMessage.html">cMessage</a> *timeoutEvent; <span class="comment">// holds pointer to the timeout self-message</span>
<span class="keywordtype">int</span> seq; <span class="comment">// message sequence number</span>
<a class="codeRef" doxygen="opptags.xml:../api//" href="../api//classcMessage.html">cMessage</a> *message; <span class="comment">// message that has to be re-sent on timeout</span>
<span class="keyword">public</span>:
<a class="code" href="classTic9.html">Tic9</a>();
<span class="keyword">virtual</span> ~<a class="code" href="classTic9.html">Tic9</a>();
<span class="keyword">protected</span>:
<span class="keyword">virtual</span> <a class="codeRef" doxygen="opptags.xml:../api//" href="../api//classcMessage.html">cMessage</a> *generateNewMessage();
<span class="keyword">virtual</span> <span class="keywordtype">void</span> sendCopyOf(<a class="codeRef" doxygen="opptags.xml:../api//" href="../api//classcMessage.html">cMessage</a> *msg);
<span class="keyword">virtual</span> <span class="keywordtype">void</span> initialize();
<span class="keyword">virtual</span> <span class="keywordtype">void</span> handleMessage(<a class="codeRef" doxygen="opptags.xml:../api//" href="../api//classcMessage.html">cMessage</a> *msg);
};
<a class="code" href="txc1_8cc.html#5ac407c43df69e3adc074c5c56d511ff">Define_Module</a>(<a class="code" href="classTic9.html">Tic9</a>);
<a class="code" href="classTic9.html#053c33016a59b3c3af383ad1d22496b9">Tic9::Tic9</a>()
{
<a class="code" href="classTic9.html#694851df464e6712932962fa6afe8e8d">timeoutEvent</a> = <a class="code" href="classTic9.html#559f8331047cee02dbff9e03b2a83eb3">message</a> = NULL;
}
<a class="code" href="classTic9.html#bb09707e14c2c78ede4373338a1d458e">Tic9::~Tic9</a>()
{
<a class="codeRef" doxygen="opptags.xml:../api//" href="../api//classcSimpleModule.html#59d46fbc9a77cb3e8164b0f624a51699">cancelAndDelete</a>(<a class="code" href="classTic9.html#694851df464e6712932962fa6afe8e8d">timeoutEvent</a>);
<span class="keyword">delete</span> <a class="code" href="classTic9.html#559f8331047cee02dbff9e03b2a83eb3">message</a>;
}
<span class="keywordtype">void</span> <a class="code" href="classTic9.html#3b100ef7831fd5ec050019d1bcb8804f">Tic9::initialize</a>()
{
<span class="comment">// Initialize variables.</span>
<a class="code" href="classTic9.html#8cfab4487172256992228c7e5c58eadc">seq</a> = 0;
<a class="code" href="classTic9.html#af910949436727dd40604c4d2d0e0851">timeout</a> = 1.0;
<a class="code" href="classTic9.html#694851df464e6712932962fa6afe8e8d">timeoutEvent</a> = <span class="keyword">new</span> <a class="codeRef" doxygen="opptags.xml:../api//" href="../api//classcOwnedObject.html#f46e516dfdf6a913fe913c4c2e496cf2">cMessage</a>(<span class="stringliteral">"timeoutEvent"</span>);
<span class="comment">// Generate and send initial message.</span>
<a class="codeRef" doxygen="opptags.xml:../api//" href="../api//group__Envir.html#g650ef3eff8a2900bef69dae29c05d2dd">EV</a> << <span class="stringliteral">"Sending initial message\n"</span>;
<a class="code" href="classTic9.html#559f8331047cee02dbff9e03b2a83eb3">message</a> = <a class="code" href="classTic9.html#729ebf1c6017dbe15c1b277ff32d9e9f">generateNewMessage</a>();
<a class="code" href="classTic9.html#3f5dff4f46521d7f01a1fea3194dce8a">sendCopyOf</a>(<a class="code" href="classTic9.html#559f8331047cee02dbff9e03b2a83eb3">message</a>);
<a class="codeRef" doxygen="opptags.xml:../api//" href="../api//classcSimpleModule.html#29a64f1f0c560ac75494940d5c7a048d">scheduleAt</a>(simTime()+<a class="code" href="classTic9.html#af910949436727dd40604c4d2d0e0851">timeout</a>, <a class="code" href="classTic9.html#694851df464e6712932962fa6afe8e8d">timeoutEvent</a>);
}
<span class="keywordtype">void</span> <a class="code" href="classTic9.html#8a20492db273120e0e2c7239b5445d15">Tic9::handleMessage</a>(<a class="codeRef" doxygen="opptags.xml:../api//" href="../api//classcMessage.html">cMessage</a> *msg)
{
<span class="keywordflow">if</span> (msg==<a class="code" href="classTic9.html#694851df464e6712932962fa6afe8e8d">timeoutEvent</a>)
{
<span class="comment">// If we receive the timeout event, that means the packet hasn't</span>
<span class="comment">// arrived in time and we have to re-send it.</span>
<a class="codeRef" doxygen="opptags.xml:../api//" href="../api//group__Envir.html#g650ef3eff8a2900bef69dae29c05d2dd">EV</a> << <span class="stringliteral">"Timeout expired, resending message and restarting timer\n"</span>;
<a class="code" href="classTic9.html#3f5dff4f46521d7f01a1fea3194dce8a">sendCopyOf</a>(<a class="code" href="classTic9.html#559f8331047cee02dbff9e03b2a83eb3">message</a>);
<a class="codeRef" doxygen="opptags.xml:../api//" href="../api//classcSimpleModule.html#29a64f1f0c560ac75494940d5c7a048d">scheduleAt</a>(simTime()+<a class="code" href="classTic9.html#af910949436727dd40604c4d2d0e0851">timeout</a>, <a class="code" href="classTic9.html#694851df464e6712932962fa6afe8e8d">timeoutEvent</a>);
}
<span class="keywordflow">else</span> <span class="comment">// message arrived</span>
{
<span class="comment">// Acknowledgement received!</span>
<a class="codeRef" doxygen="opptags.xml:../api//" href="../api//group__Envir.html#g650ef3eff8a2900bef69dae29c05d2dd">EV</a> << <span class="stringliteral">"Received: "</span> << msg-><a class="codeRef" doxygen="opptags.xml:../api//" href="../api//classcNamedObject.html#5b06a5fdb473bb997c939ba55435c041">getName</a>() << <spa
没有合适的资源?快使用搜索试试~ 我知道了~
OMNeTPP-TicToc.rar_6txc cc_Omnetpp_omnet++tictoc案例_omnetpp-4.5_o
共39个文件
htm:33个
mht:6个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 27 浏览量
2022-09-24
18:01:49
上传
评论
收藏 632KB RAR 举报
温馨提示
这个文件适合入门学习OMNET++,里面有最基本的案例和代码,安装软件后可以上机运行调试和学习,是很好的基础入门材料
资源推荐
资源详情
资源评论
收起资源包目录
OMNeTPP-TicToc.rar (39个子文件)
OMNeT++ TicToc指南
Tictoc Tutorial 5_用OMNeT++ IDE使结果可视化.mht 211KB
Tictoc 指南 1_ 开始.mht 83KB
CODE
tictoc12.ned.htm 3KB
txc7.cc.htm 8KB
tictoc9.ned.htm 3KB
tictoc7.ned.htm 3KB
tictoc1.ned.htm 3KB
tictoc15.msg.htm 2KB
tictoc11.ned.htm 3KB
txc11.cc.htm 7KB
txc14.cc.htm 10KB
txc10.cc.htm 7KB
tictoc4.ned.htm 3KB
txc1.cc.htm 5KB
tictoc3.ned.htm 3KB
omnetpp.ini.htm 3KB
txc2.cc.htm 5KB
tictoc14.msg.htm 2KB
tictoc6.ned.htm 3KB
txc4.cc.htm 6KB
tictoc15.ned.htm 3KB
tictoc10.ned.htm 3KB
tictoc14.ned.htm 3KB
txc3.cc.htm 7KB
tictoc2.ned.htm 3KB
txc12.cc.htm 7KB
txc9.cc.htm 14KB
txc13.cc.htm 9KB
txc15.cc.htm 13KB
txc6.cc.htm 9KB
tictoc13.ned.htm 3KB
tictoc13.msg.htm 2KB
tictoc5.ned.htm 4KB
txc8.cc.htm 11KB
tictoc8.ned.htm 3KB
Tictoc Tutorial 4_ 添加统计收集.mht 233KB
Tictoc 指南OMNeT++ TicToc 指南.mht 20KB
Tictoc Tutorial 3_ 转向现实网络.mht 151KB
Tictoc Tutorial 2_ 增强的双节点 TicToc.mht 195KB
共 39 条
- 1
资源评论
JonSco
- 粉丝: 66
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功