This library is stripped down version of NetServices library. HTTP server and client function is NOT supported.
if/lwip/LwipNetIf.cpp@0:dcf3c92487ca, 2011-07-20 (annotated)
- Committer:
- idinor
- Date:
- Wed Jul 20 11:45:39 2011 +0000
- Revision:
- 0:dcf3c92487ca
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
idinor | 0:dcf3c92487ca | 1 | |
idinor | 0:dcf3c92487ca | 2 | /* |
idinor | 0:dcf3c92487ca | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
idinor | 0:dcf3c92487ca | 4 | |
idinor | 0:dcf3c92487ca | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
idinor | 0:dcf3c92487ca | 6 | of this software and associated documentation files (the "Software"), to deal |
idinor | 0:dcf3c92487ca | 7 | in the Software without restriction, including without limitation the rights |
idinor | 0:dcf3c92487ca | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
idinor | 0:dcf3c92487ca | 9 | copies of the Software, and to permit persons to whom the Software is |
idinor | 0:dcf3c92487ca | 10 | furnished to do so, subject to the following conditions: |
idinor | 0:dcf3c92487ca | 11 | |
idinor | 0:dcf3c92487ca | 12 | The above copyright notice and this permission notice shall be included in |
idinor | 0:dcf3c92487ca | 13 | all copies or substantial portions of the Software. |
idinor | 0:dcf3c92487ca | 14 | |
idinor | 0:dcf3c92487ca | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
idinor | 0:dcf3c92487ca | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
idinor | 0:dcf3c92487ca | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
idinor | 0:dcf3c92487ca | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
idinor | 0:dcf3c92487ca | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
idinor | 0:dcf3c92487ca | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
idinor | 0:dcf3c92487ca | 21 | THE SOFTWARE. |
idinor | 0:dcf3c92487ca | 22 | */ |
idinor | 0:dcf3c92487ca | 23 | |
idinor | 0:dcf3c92487ca | 24 | #include "LwipNetIf.h" |
idinor | 0:dcf3c92487ca | 25 | #include "lwip/init.h" |
idinor | 0:dcf3c92487ca | 26 | #include "lwip/tcp_impl.h" |
idinor | 0:dcf3c92487ca | 27 | #include "lwip/dns.h" |
idinor | 0:dcf3c92487ca | 28 | |
idinor | 0:dcf3c92487ca | 29 | #include "lwipNetTcpSocket.h" |
idinor | 0:dcf3c92487ca | 30 | #include "lwipNetUdpSocket.h" |
idinor | 0:dcf3c92487ca | 31 | #include "lwipNetDnsRequest.h" |
idinor | 0:dcf3c92487ca | 32 | |
idinor | 0:dcf3c92487ca | 33 | #include "netCfg.h" |
idinor | 0:dcf3c92487ca | 34 | #if NET_LWIP_STACK |
idinor | 0:dcf3c92487ca | 35 | |
idinor | 0:dcf3c92487ca | 36 | //See doc/rawapi.txt for details |
idinor | 0:dcf3c92487ca | 37 | |
idinor | 0:dcf3c92487ca | 38 | LwipNetIf::LwipNetIf() : NetIf(), m_tcpTimer(), m_dnsTimer(), m_init(false) |
idinor | 0:dcf3c92487ca | 39 | { |
idinor | 0:dcf3c92487ca | 40 | |
idinor | 0:dcf3c92487ca | 41 | } |
idinor | 0:dcf3c92487ca | 42 | |
idinor | 0:dcf3c92487ca | 43 | |
idinor | 0:dcf3c92487ca | 44 | LwipNetIf::~LwipNetIf() |
idinor | 0:dcf3c92487ca | 45 | { |
idinor | 0:dcf3c92487ca | 46 | |
idinor | 0:dcf3c92487ca | 47 | } |
idinor | 0:dcf3c92487ca | 48 | |
idinor | 0:dcf3c92487ca | 49 | void LwipNetIf::init() |
idinor | 0:dcf3c92487ca | 50 | { |
idinor | 0:dcf3c92487ca | 51 | if(m_init) |
idinor | 0:dcf3c92487ca | 52 | return; |
idinor | 0:dcf3c92487ca | 53 | m_init=true; |
idinor | 0:dcf3c92487ca | 54 | lwip_init(); //init lwip, see init.c for details |
idinor | 0:dcf3c92487ca | 55 | |
idinor | 0:dcf3c92487ca | 56 | //Setup Clocks |
idinor | 0:dcf3c92487ca | 57 | m_tcpTimer.start(); |
idinor | 0:dcf3c92487ca | 58 | m_dnsTimer.start(); |
idinor | 0:dcf3c92487ca | 59 | //m_tcpTicker.attach_us( tcp_tmr, TCP_TMR_INTERVAL * 1000 ); //TCP_TMR_INTERVAL = 250 ms in tcp_impl.h |
idinor | 0:dcf3c92487ca | 60 | //m_dnsTicker.attach_us( dns_tmr, DNS_TMR_INTERVAL * 1000 ); //DNS_TMR_INTERVAL = 1000 ms in dns.h |
idinor | 0:dcf3c92487ca | 61 | } |
idinor | 0:dcf3c92487ca | 62 | |
idinor | 0:dcf3c92487ca | 63 | NetTcpSocket* LwipNetIf::tcpSocket() //Create a new tcp socket |
idinor | 0:dcf3c92487ca | 64 | { |
idinor | 0:dcf3c92487ca | 65 | return new LwipNetTcpSocket(); |
idinor | 0:dcf3c92487ca | 66 | } |
idinor | 0:dcf3c92487ca | 67 | |
idinor | 0:dcf3c92487ca | 68 | NetUdpSocket* LwipNetIf::udpSocket() //Create a new udp socket |
idinor | 0:dcf3c92487ca | 69 | { |
idinor | 0:dcf3c92487ca | 70 | return new LwipNetUdpSocket(); |
idinor | 0:dcf3c92487ca | 71 | } |
idinor | 0:dcf3c92487ca | 72 | |
idinor | 0:dcf3c92487ca | 73 | NetDnsRequest* LwipNetIf::dnsRequest(const char* hostname) //Create a new NetDnsRequest object |
idinor | 0:dcf3c92487ca | 74 | { |
idinor | 0:dcf3c92487ca | 75 | return new LwipNetDnsRequest(hostname); |
idinor | 0:dcf3c92487ca | 76 | } |
idinor | 0:dcf3c92487ca | 77 | |
idinor | 0:dcf3c92487ca | 78 | NetDnsRequest* LwipNetIf::dnsRequest(Host* pHost) //Create a new NetDnsRequest object |
idinor | 0:dcf3c92487ca | 79 | { |
idinor | 0:dcf3c92487ca | 80 | return new LwipNetDnsRequest(pHost); |
idinor | 0:dcf3c92487ca | 81 | } |
idinor | 0:dcf3c92487ca | 82 | |
idinor | 0:dcf3c92487ca | 83 | void LwipNetIf::poll() |
idinor | 0:dcf3c92487ca | 84 | { |
idinor | 0:dcf3c92487ca | 85 | if(m_init && m_tcpTimer.read_ms() >= TCP_TMR_INTERVAL) |
idinor | 0:dcf3c92487ca | 86 | { |
idinor | 0:dcf3c92487ca | 87 | m_tcpTimer.reset(); |
idinor | 0:dcf3c92487ca | 88 | tcp_tmr(); //Poll LwIP |
idinor | 0:dcf3c92487ca | 89 | } |
idinor | 0:dcf3c92487ca | 90 | if(m_init && m_dnsTimer.read_ms() >= DNS_TMR_INTERVAL) |
idinor | 0:dcf3c92487ca | 91 | { |
idinor | 0:dcf3c92487ca | 92 | m_dnsTimer.reset(); |
idinor | 0:dcf3c92487ca | 93 | dns_tmr(); |
idinor | 0:dcf3c92487ca | 94 | } |
idinor | 0:dcf3c92487ca | 95 | //Do some stuff... |
idinor | 0:dcf3c92487ca | 96 | } |
idinor | 0:dcf3c92487ca | 97 | |
idinor | 0:dcf3c92487ca | 98 | #endif |