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

📄 udp__demo_8c-source.html

📁 Freescale mcu OpenTCP-1.0.4.doc.html.zip 文档
💻 HTML
📖 第 1 页 / 共 2 页
字号:
00127         <span class="comment">/* open socket for receiving/sending of the data on defined port*/</span>00128         <a class="code" href="udp_8c.html#a5">udp_open</a>(<a class="code" href="udp__demo_8c.html#a4">udp_demo_soch</a>,<a class="code" href="udp__demo_8c.html#a0">UDP_DEMO_PORT</a>);00129         00130         <span class="comment">/* for now no data sending */</span>00131         <a class="code" href="udp__demo_8c.html#a5">udp_demo_senddata</a>=0;00132 }00133 00134 <span class="comment">/* UDP Demo app main loop that is periodically invoked from the</span>00135 <span class="comment"> * main loop (see main_demo.c)</span>00136 <span class="comment"> */</span>00137 <span class="keywordtype">void</span> udp_demo_run(<span class="keywordtype">void</span>){00138         <span class="comment">/* do maybe some other UDP demo app stuff</span>00139 <span class="comment">         * .....</span>00140 <span class="comment">         */</span>00141         <span class="keywordflow">if</span>(udp_demo_senddata) {00142                 <span class="keywordflow">switch</span>(udp_demo_send()){00143                         <span class="keywordflow">case</span> -1:00144                                 DEBUGOUT(<span class="stringliteral">"Error (General error, e.g. parameters)\r\n"</span>);00145                                 <span class="keywordflow">break</span>; 00146                         <span class="keywordflow">case</span> -2:00147                                 DEBUGOUT(<span class="stringliteral">"ARP or lower layer not ready, try again\r\n"</span>);00148                                 <span class="keywordflow">break</span>;00149                         <span class="keywordflow">case</span> -3:00150                                 DEBUGOUT(<span class="stringliteral">"Socket closed or socket handle not valid!\r\n"</span>);00151                                 <span class="keywordflow">break</span>;00152                         <span class="keywordflow">default</span>:00153                                 <span class="comment">/* data sent (could check how many bytes too)</span>00154 <span class="comment">                                 * if no more data to send, reset flag</span>00155 <span class="comment">                                 */</span>00156                                 <a class="code" href="udp__demo_8c.html#a5">udp_demo_senddata</a>=0;00157                                 <span class="keywordflow">break</span>;00158                 00159                 }00160         }00161 }00162 00163 <span class="comment">/*</span>00164 <span class="comment"> * Event listener invoked when TCP/IP stack receives UDP datagram for</span>00165 <span class="comment"> * a given socket. Parameters:</span>00166 <span class="comment"> * - cbhandle - handle of the socket this packet is intended for. Check it</span>00167 <span class="comment"> *      just to be sure, but in general case not needed</span>00168 <span class="comment"> * - event - event that is notified. For UDP, only UDP_EVENT_DATA</span>00169 <span class="comment"> * - ipaddr - IP address of remote host who sent the UDP datagram</span>00170 <span class="comment"> * - port - port number of remote host who sent the UDP datagram</span>00171 <span class="comment"> * - buffindex - buffer index in RTL8019AS allowing you to read </span>00172 <span class="comment"> *      received data more than once from Ethernet controller by</span>00173 <span class="comment"> *      invoking NETWORK_RECEIVE_INITIALIZE(buffindex) and then start</span>00174 <span class="comment"> *      reading the bytes all over again</span>00175 <span class="comment"> */</span> 00176 INT32 udp_demo_eventlistener(INT8 cbhandle, UINT8 event, UINT32 ipaddr, UINT16 port, UINT16 buffindex, UINT16 datalen){00177         UINT16 i;00178         <span class="keywordflow">if</span>(cbhandle!=<a class="code" href="udp__demo_8c.html#a4">udp_demo_soch</a>){00179                 DEBUGOUT(<span class="stringliteral">"Not my handle!!!!"</span>);00180                 <span class="keywordflow">return</span> (-1);00181         }00182         00183         <span class="keywordflow">switch</span>(event){00184                 <span class="keywordflow">case</span> <a class="code" href="tcp__ip_8h.html#a31">UDP_EVENT_DATA</a>:00185                         00186                         <span class="comment">/* read data that was received (and </span>00187 <span class="comment">                         * probably do something with it :-)</span>00188 <span class="comment">                         */</span>00189                         <span class="keywordflow">for</span>(i=0;i&lt;datalen;i++)00190                                 <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00191                                 00192                         <span class="comment">/* If needed initialize data sending</span>00193 <span class="comment">                         * by setting udp_demo_senddata variable or</span>00194 <span class="comment">                         * send data directly from event listener (</span>00195 <span class="comment">                         * only possible for UDP applications!!!!</span>00196 <span class="comment">                         */</span>00197                          00198                         <span class="keywordflow">break</span>;00199                         00200                 <span class="keywordflow">default</span>:00201                         <span class="comment">/* should never get here */</span>00202                         DEBUGOUT(<span class="stringliteral">"Unknown UDP event :-("</span>);00203                         <span class="keywordflow">break</span>;00204         }00205         <span class="keywordflow">return</span> 0;00206 }00207 00208 <span class="comment">/* internal function invoked to send UDP message to, in this case,</span>00209 <span class="comment"> * some predefined host.</span>00210 <span class="comment"> */</span>00211 <span class="preprocessor">#define MSG_SIZE 20</span>00212 <span class="preprocessor"></span>INT16 udp_demo_send(<span class="keywordtype">void</span>){00213         UINT8   i;00214         00215         <span class="comment">/* put message in buffer. Message needs to start from UDP_APP_OFFSET</span>00216 <span class="comment">         * because TCP/IP stack will put headers in front of the message to</span>00217 <span class="comment">         * avoid data copying</span>00218 <span class="comment">         */</span>00219         <span class="keywordflow">for</span>(i=0;i&lt;MSG_SIZE;i++)00220                 net_buf[<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a>+i]=i;00221         00222         <span class="comment">/* send message         */</span>00223         <span class="keywordflow">return</span> <a class="code" href="udp_8c.html#a7">udp_send</a>(<a class="code" href="udp__demo_8c.html#a4">udp_demo_soch</a>,<a class="code" href="udp__demo_8c.html#a1">UDP_DEMO_RMTHOST_IP</a>,<a class="code" href="udp__demo_8c.html#a2">UDP_DEMO_RMTHOST_PRT</a>,net_buf+<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a>,<a class="code" href="group__opentcp__config.html#a4">NETWORK_TX_BUFFER_SIZE</a>-<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a>,MSG_SIZE);00224         00225 }</pre></div><hr><address style="align: right;"><small>Generated on Sun Aug 3 20:32:59 2003 for OpenTCP by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.18 </small></address></body></html>

⌨️ 快捷键说明

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