Trial code integration web page update with analogue data and ntp support
Dependencies: NTPClient_NetServices mbed
lpc1768/if/lwip/lwipNetTcpSocket.h@0:8cc2035bebfc, 2010-08-06 (annotated)
- Committer:
- pmr1
- Date:
- Fri Aug 06 17:57:45 2010 +0000
- Revision:
- 0:8cc2035bebfc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pmr1 | 0:8cc2035bebfc | 1 | |
pmr1 | 0:8cc2035bebfc | 2 | /* |
pmr1 | 0:8cc2035bebfc | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
pmr1 | 0:8cc2035bebfc | 4 | |
pmr1 | 0:8cc2035bebfc | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
pmr1 | 0:8cc2035bebfc | 6 | of this software and associated documentation files (the "Software"), to deal |
pmr1 | 0:8cc2035bebfc | 7 | in the Software without restriction, including without limitation the rights |
pmr1 | 0:8cc2035bebfc | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
pmr1 | 0:8cc2035bebfc | 9 | copies of the Software, and to permit persons to whom the Software is |
pmr1 | 0:8cc2035bebfc | 10 | furnished to do so, subject to the following conditions: |
pmr1 | 0:8cc2035bebfc | 11 | |
pmr1 | 0:8cc2035bebfc | 12 | The above copyright notice and this permission notice shall be included in |
pmr1 | 0:8cc2035bebfc | 13 | all copies or substantial portions of the Software. |
pmr1 | 0:8cc2035bebfc | 14 | |
pmr1 | 0:8cc2035bebfc | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
pmr1 | 0:8cc2035bebfc | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
pmr1 | 0:8cc2035bebfc | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
pmr1 | 0:8cc2035bebfc | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
pmr1 | 0:8cc2035bebfc | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
pmr1 | 0:8cc2035bebfc | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
pmr1 | 0:8cc2035bebfc | 21 | THE SOFTWARE. |
pmr1 | 0:8cc2035bebfc | 22 | */ |
pmr1 | 0:8cc2035bebfc | 23 | |
pmr1 | 0:8cc2035bebfc | 24 | #ifndef LWIPNETTCPSOCKET_H |
pmr1 | 0:8cc2035bebfc | 25 | #define LWIPNETTCPSOCKET_H |
pmr1 | 0:8cc2035bebfc | 26 | |
pmr1 | 0:8cc2035bebfc | 27 | #define NET_LWIP_STACK 1 |
pmr1 | 0:8cc2035bebfc | 28 | #include "lwip/ip_addr.h" |
pmr1 | 0:8cc2035bebfc | 29 | #include "if/net/net.h" |
pmr1 | 0:8cc2035bebfc | 30 | #include "LwipNetIf.h" |
pmr1 | 0:8cc2035bebfc | 31 | |
pmr1 | 0:8cc2035bebfc | 32 | //Implements NetTcpSockets over lwIP raw API |
pmr1 | 0:8cc2035bebfc | 33 | |
pmr1 | 0:8cc2035bebfc | 34 | struct tcp_pcb; //Represents a Tcp Connection, "Protocol Control Block", see rawapi.txt & tcp.h |
pmr1 | 0:8cc2035bebfc | 35 | struct pbuf; //Lwip Buffer Container |
pmr1 | 0:8cc2035bebfc | 36 | |
pmr1 | 0:8cc2035bebfc | 37 | typedef signed char err_t; |
pmr1 | 0:8cc2035bebfc | 38 | |
pmr1 | 0:8cc2035bebfc | 39 | class LwipNetTcpSocket: public NetTcpSocket |
pmr1 | 0:8cc2035bebfc | 40 | { |
pmr1 | 0:8cc2035bebfc | 41 | public: |
pmr1 | 0:8cc2035bebfc | 42 | LwipNetTcpSocket(tcp_pcb* pPcb = NULL); //Passes a pcb if already created (by an accept req for instance), in that case transfers ownership |
pmr1 | 0:8cc2035bebfc | 43 | virtual ~LwipNetTcpSocket(); |
pmr1 | 0:8cc2035bebfc | 44 | |
pmr1 | 0:8cc2035bebfc | 45 | virtual NetTcpSocketErr bind(const Host& me); |
pmr1 | 0:8cc2035bebfc | 46 | virtual NetTcpSocketErr listen(); |
pmr1 | 0:8cc2035bebfc | 47 | virtual NetTcpSocketErr connect(const Host& host); |
pmr1 | 0:8cc2035bebfc | 48 | virtual NetTcpSocketErr accept(Host* pClient, NetTcpSocket** ppNewNetTcpSocket); |
pmr1 | 0:8cc2035bebfc | 49 | |
pmr1 | 0:8cc2035bebfc | 50 | virtual int /*if < 0 : NetTcpSocketErr*/ send(const char* buf, int len); |
pmr1 | 0:8cc2035bebfc | 51 | virtual int /*if < 0 : NetTcpSocketErr*/ recv(char* buf, int len); |
pmr1 | 0:8cc2035bebfc | 52 | |
pmr1 | 0:8cc2035bebfc | 53 | virtual NetTcpSocketErr close(); |
pmr1 | 0:8cc2035bebfc | 54 | |
pmr1 | 0:8cc2035bebfc | 55 | virtual NetTcpSocketErr poll(); |
pmr1 | 0:8cc2035bebfc | 56 | |
pmr1 | 0:8cc2035bebfc | 57 | protected: |
pmr1 | 0:8cc2035bebfc | 58 | volatile tcp_pcb* m_pPcb; |
pmr1 | 0:8cc2035bebfc | 59 | |
pmr1 | 0:8cc2035bebfc | 60 | //Events callbacks from lwIp |
pmr1 | 0:8cc2035bebfc | 61 | err_t acceptCb(tcp_pcb* newpcb, err_t err); |
pmr1 | 0:8cc2035bebfc | 62 | err_t connectedCb(tcp_pcb* tpcb, err_t err); |
pmr1 | 0:8cc2035bebfc | 63 | |
pmr1 | 0:8cc2035bebfc | 64 | void errCb(err_t err); |
pmr1 | 0:8cc2035bebfc | 65 | |
pmr1 | 0:8cc2035bebfc | 66 | err_t sentCb(tcp_pcb* tpcb, u16_t len); |
pmr1 | 0:8cc2035bebfc | 67 | err_t recvCb(tcp_pcb* tpcb, pbuf *p, err_t err); |
pmr1 | 0:8cc2035bebfc | 68 | |
pmr1 | 0:8cc2035bebfc | 69 | private: |
pmr1 | 0:8cc2035bebfc | 70 | void cleanUp(); //Flush input buffer |
pmr1 | 0:8cc2035bebfc | 71 | |
pmr1 | 0:8cc2035bebfc | 72 | // queue<tcp_pcb*> m_lpInPcb; //Incoming connections that have not been accepted yet |
pmr1 | 0:8cc2035bebfc | 73 | queue<LwipNetTcpSocket*> m_lpInNetTcpSocket; //Incoming connections that have not been accepted yet |
pmr1 | 0:8cc2035bebfc | 74 | |
pmr1 | 0:8cc2035bebfc | 75 | volatile pbuf* m_pReadPbuf; //Ptr to read buffer |
pmr1 | 0:8cc2035bebfc | 76 | |
pmr1 | 0:8cc2035bebfc | 77 | //Static callbacks : Transforms into a C++ callback |
pmr1 | 0:8cc2035bebfc | 78 | static err_t sAcceptCb(void *arg, struct tcp_pcb *newpcb, err_t err); |
pmr1 | 0:8cc2035bebfc | 79 | static err_t sConnectedCb(void *arg, struct tcp_pcb *tpcb, err_t err); |
pmr1 | 0:8cc2035bebfc | 80 | |
pmr1 | 0:8cc2035bebfc | 81 | static void sErrCb(void *arg, err_t err); |
pmr1 | 0:8cc2035bebfc | 82 | |
pmr1 | 0:8cc2035bebfc | 83 | static err_t sSentCb(void *arg, struct tcp_pcb *tpcb, u16_t len); |
pmr1 | 0:8cc2035bebfc | 84 | static err_t sRecvCb(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err); |
pmr1 | 0:8cc2035bebfc | 85 | |
pmr1 | 0:8cc2035bebfc | 86 | }; |
pmr1 | 0:8cc2035bebfc | 87 | |
pmr1 | 0:8cc2035bebfc | 88 | #endif |