⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 udp__demo_8c-example.html

📁 Freescale mcu OpenTCP-1.0.4.doc.html.zip 文档
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Example Documentation</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.2.18 --><center><a class="qindex" href="main.html">Main Page</a> &nbsp; <a class="qindex" href="modules.html">Modules</a> &nbsp; <a class="qindex" href="annotated.html">Data Structures</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Data Fields</a> &nbsp; <a class="qindex" href="globals.html">Globals</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; <a class="qindex" href="examples.html">Examples</a> &nbsp; </center><hr><h1>udp_demo.c</h1><p>Small UDP application example showing possible organization of applications using OpenTCP.<p>Basically all OpenTCP applications are divided in three separate functions:<ul><li>app_init() - initialization part of the application where  variables are initialized, system resources reserved, etc.<li>app_run() - application main loop which is invoked from the  main main loop. Here, event-based processingis performed where upon certain event (timer expiration, communication event...) data is usually sent from and/or other control functions are invoked.<li>app_event_listener - callback function invoked by the TCP/IP stack on data arrival events (for UDP only this event currently exists)</ul>More details about this example:<p><div class="fragment"><pre><span class="comment">/*</span><span class="comment"> *Copyright (c) 2000-2002 Viola Systems Ltd.</span><span class="comment"> *All rights reserved.</span><span class="comment"> *</span><span class="comment"> *Redistribution and use in source and binary forms, with or without </span><span class="comment"> *modification, are permitted provided that the following conditions </span><span class="comment"> *are met:</span><span class="comment"> *</span><span class="comment"> *1. Redistributions of source code must retain the above copyright </span><span class="comment"> *notice, this list of conditions and the following disclaimer.</span><span class="comment"> *</span><span class="comment"> *2. Redistributions in binary form must reproduce the above copyright </span><span class="comment"> *notice, this list of conditions and the following disclaimer in the </span><span class="comment"> *documentation and/or other materials provided with the distribution.</span><span class="comment"> *</span><span class="comment"> *3. The end-user documentation included with the redistribution, if </span><span class="comment"> *any, must include the following acknowledgment:</span><span class="comment"> *      "This product includes software developed by Viola </span><span class="comment"> *      Systems (http://www.violasystems.com/)."</span><span class="comment"> *</span><span class="comment"> *Alternately, this acknowledgment may appear in the software itself, </span><span class="comment"> *if and wherever such third-party acknowledgments normally appear.</span><span class="comment"> *</span><span class="comment"> *4. The names "OpenTCP" and "Viola Systems" must not be used to </span><span class="comment"> *endorse or promote products derived from this software without prior </span><span class="comment"> *written permission. For written permission, please contact </span><span class="comment"> *opentcp@opentcp.org.</span><span class="comment"> *</span><span class="comment"> *5. Products derived from this software may not be called "OpenTCP", </span><span class="comment"> *nor may "OpenTCP" appear in their name, without prior written </span><span class="comment"> *permission of the Viola Systems Ltd.</span><span class="comment"> *</span><span class="comment"> *THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED </span><span class="comment"> *WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF </span><span class="comment"> *MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. </span><span class="comment"> *IN NO EVENT SHALL VIOLA SYSTEMS LTD. OR ITS CONTRIBUTORS BE LIABLE </span><span class="comment"> *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR </span><span class="comment"> *CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF </span><span class="comment"> *SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR </span><span class="comment"> *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, </span><span class="comment"> *WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE </span><span class="comment"> *OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, </span><span class="comment"> *EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span><span class="comment"> *====================================================================</span><span class="comment"> *</span><span class="comment"> *OpenTCP is the unified open source TCP/IP stack available on a series </span><span class="comment"> *of 8/16-bit microcontrollers, please see &lt;http://www.opentcp.org&gt;.</span><span class="comment"> *</span><span class="comment"> *For more information on how to network-enable your devices, or how to </span><span class="comment"> *obtain commercial technical support for OpenTCP, please see </span><span class="comment"> *&lt;http://www.violasystems.com/&gt;.</span><span class="comment"> */</span><span class="preprocessor">#include &lt;<a class="code" href="debug_8h.html">inet/debug.h</a>&gt;</span><span class="preprocessor">#include &lt;<a class="code" href="datatypes_8h.html">inet/datatypes.h</a>&gt;</span><span class="preprocessor">#include &lt;<a class="code" href="globalvariables_8h.html">inet/globalvariables.h</a>&gt;</span><span class="preprocessor">#include &lt;<a class="code" href="system_8h.html">inet/system.h</a>&gt;</span><span class="preprocessor">#include &lt;<a class="code" href="tcp__ip_8h.html">inet/tcp_ip.h</a>&gt;</span><span class="comment">/* The applications that use UDP must implement following function stubs                        */</span><span class="comment">/* void application_name_init (void) - call once when processor starts                          */</span><span class="comment">/* void application_name_run (void) - call periodically on main loop                            */</span><span class="comment">/* INT32 application_name_eventlistener (INT8, UINT8, UINT32, UINT16, UINT16, UINT16)   */</span><span class="comment">/* - called by TCP input process to inform arriving data, errors etc                            */</span><span class="comment">/* These will probably go to some include file */</span><span class="keywordtype">void</span> udp_demo_init(<span class="keywordtype">void</span>);<span class="keywordtype">void</span> udp_demo_run(<span class="keywordtype">void</span>);INT32 udp_demo_eventlistener(INT8 , UINT8 , UINT32 , UINT16 , UINT16 , UINT16 );UINT8 <a class="code" href="udp__demo_8c.html#a4">udp_demo_soch</a>;UINT8 <a class="code" href="udp__demo_8c.html#a5">udp_demo_senddata</a>; <span class="preprocessor">#define UDP_DEMO_PORT   5000 </span><span class="preprocessor">#define UDP_DEMO_RMTHOST_IP     0xAC100101      </span><span class="preprocessor">#define UDP_DEMO_RMTHOST_PRT    5001    </span><span class="preprocessor"></span><span class="comment">/* Internal function used for sending data to a predefined host */</span>INT16 udp_demo_send(<span class="keywordtype">void</span>);<span class="comment">/* Initialize resources needed for the UDP socket application */</span><span class="keywordtype">void</span> udp_demo_init(<span class="keywordtype">void</span>){        DEBUGOUT(<span class="stringliteral">"Initializing UDP demo client\r\n"</span>);                <span class="comment">/* Get socket:</span><span class="comment">         *      0 - for now not type of service implemented in UDP</span><span class="comment">         *      udp_echo_eventlistener - pointer to listener function</span><span class="comment">         *      UDP_OPT_SEND_CS|UDP_OPT_CHECK_CS - checksum options. Calculate</span><span class="comment">         *              checksum for outgoing packets and check checksum for</span><span class="comment">         *              received packets.</span><span class="comment">         */</span>        <a class="code" href="udp__demo_8c.html#a4">udp_demo_soch</a>=<a name="a0"></a><a class="code" href="group__udp__app__api.html#a0">udp_getsocket</a>(0 , udp_demo_eventlistener , <a class="code" href="tcp__ip_8h.html#a5">UDP_OPT_SEND_CS</a> | <a class="code" href="tcp__ip_8h.html#a6">UDP_OPT_CHECK_CS</a>);                <span class="keywordflow">if</span>(<a class="code" href="udp__demo_8c.html#a4">udp_demo_soch</a> == -1){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -