ID the MBED processor on the network if you have more than one. View MBED name on DHCP of your Router - Example \"MBED PE\" Change your ID in Core / host.h
LPC1768/if/lwip/lwipNetUdpSocket.h@0:fd3b85615428, 2010-11-06 (annotated)
- Committer:
- JeffM
- Date:
- Sat Nov 06 14:11:02 2010 +0000
- Revision:
- 0:fd3b85615428
MBED ID 1A
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JeffM | 0:fd3b85615428 | 1 | |
JeffM | 0:fd3b85615428 | 2 | /* |
JeffM | 0:fd3b85615428 | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
JeffM | 0:fd3b85615428 | 4 | |
JeffM | 0:fd3b85615428 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
JeffM | 0:fd3b85615428 | 6 | of this software and associated documentation files (the "Software"), to deal |
JeffM | 0:fd3b85615428 | 7 | in the Software without restriction, including without limitation the rights |
JeffM | 0:fd3b85615428 | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
JeffM | 0:fd3b85615428 | 9 | copies of the Software, and to permit persons to whom the Software is |
JeffM | 0:fd3b85615428 | 10 | furnished to do so, subject to the following conditions: |
JeffM | 0:fd3b85615428 | 11 | |
JeffM | 0:fd3b85615428 | 12 | The above copyright notice and this permission notice shall be included in |
JeffM | 0:fd3b85615428 | 13 | all copies or substantial portions of the Software. |
JeffM | 0:fd3b85615428 | 14 | |
JeffM | 0:fd3b85615428 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
JeffM | 0:fd3b85615428 | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
JeffM | 0:fd3b85615428 | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
JeffM | 0:fd3b85615428 | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
JeffM | 0:fd3b85615428 | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
JeffM | 0:fd3b85615428 | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
JeffM | 0:fd3b85615428 | 21 | THE SOFTWARE. |
JeffM | 0:fd3b85615428 | 22 | */ |
JeffM | 0:fd3b85615428 | 23 | |
JeffM | 0:fd3b85615428 | 24 | #ifndef LWIPNETUDPSOCKET_H |
JeffM | 0:fd3b85615428 | 25 | #define LWIPNETUDPSOCKET_H |
JeffM | 0:fd3b85615428 | 26 | |
JeffM | 0:fd3b85615428 | 27 | #define NET_LWIP_STACK 1 |
JeffM | 0:fd3b85615428 | 28 | //#include "lwip/ip_addr.h" |
JeffM | 0:fd3b85615428 | 29 | #include "if/net/netudpsocket.h" |
JeffM | 0:fd3b85615428 | 30 | #include "LwipNetIf.h" |
JeffM | 0:fd3b85615428 | 31 | |
JeffM | 0:fd3b85615428 | 32 | #include "stdint.h" |
JeffM | 0:fd3b85615428 | 33 | |
JeffM | 0:fd3b85615428 | 34 | #include <list> |
JeffM | 0:fd3b85615428 | 35 | using std::list; |
JeffM | 0:fd3b85615428 | 36 | |
JeffM | 0:fd3b85615428 | 37 | //Implements NetUdpSockets over lwIP raw API |
JeffM | 0:fd3b85615428 | 38 | |
JeffM | 0:fd3b85615428 | 39 | struct udp_pcb; //Represents a Udp Connection, "Protocol Control Block", see rawapi.txt & udp.h |
JeffM | 0:fd3b85615428 | 40 | struct pbuf; //Lwip Buffer Container |
JeffM | 0:fd3b85615428 | 41 | typedef struct ip_addr ip_addr_t; |
JeffM | 0:fd3b85615428 | 42 | |
JeffM | 0:fd3b85615428 | 43 | //typedef signed char err_t; |
JeffM | 0:fd3b85615428 | 44 | typedef uint16_t u16_t; |
JeffM | 0:fd3b85615428 | 45 | |
JeffM | 0:fd3b85615428 | 46 | class LwipNetUdpSocket: public NetUdpSocket |
JeffM | 0:fd3b85615428 | 47 | { |
JeffM | 0:fd3b85615428 | 48 | public: |
JeffM | 0:fd3b85615428 | 49 | LwipNetUdpSocket(udp_pcb* pPcb = NULL); //Passes a pcb if already created (by an accept req for instance), in that case transfers ownership |
JeffM | 0:fd3b85615428 | 50 | virtual ~LwipNetUdpSocket(); |
JeffM | 0:fd3b85615428 | 51 | |
JeffM | 0:fd3b85615428 | 52 | virtual NetUdpSocketErr bind(const Host& me); |
JeffM | 0:fd3b85615428 | 53 | |
JeffM | 0:fd3b85615428 | 54 | virtual int /*if < 0 : NetUdpSocketErr*/ sendto(const char* buf, int len, Host* pHost); |
JeffM | 0:fd3b85615428 | 55 | virtual int /*if < 0 : NetUdpSocketErr*/ recvfrom(char* buf, int len, Host* pHost); |
JeffM | 0:fd3b85615428 | 56 | |
JeffM | 0:fd3b85615428 | 57 | virtual NetUdpSocketErr close(); |
JeffM | 0:fd3b85615428 | 58 | |
JeffM | 0:fd3b85615428 | 59 | virtual NetUdpSocketErr poll(); |
JeffM | 0:fd3b85615428 | 60 | |
JeffM | 0:fd3b85615428 | 61 | protected: |
JeffM | 0:fd3b85615428 | 62 | volatile udp_pcb* m_pPcb; |
JeffM | 0:fd3b85615428 | 63 | |
JeffM | 0:fd3b85615428 | 64 | //Event callback from lwIp |
JeffM | 0:fd3b85615428 | 65 | void recvCb(udp_pcb* pcb, struct pbuf* p, ip_addr_t* addr, u16_t port); |
JeffM | 0:fd3b85615428 | 66 | |
JeffM | 0:fd3b85615428 | 67 | private: |
JeffM | 0:fd3b85615428 | 68 | void cleanUp(); //Flush input buffer |
JeffM | 0:fd3b85615428 | 69 | struct InPacket |
JeffM | 0:fd3b85615428 | 70 | { |
JeffM | 0:fd3b85615428 | 71 | volatile pbuf* pBuf; |
JeffM | 0:fd3b85615428 | 72 | ip_addr_t addr; |
JeffM | 0:fd3b85615428 | 73 | u16_t port; |
JeffM | 0:fd3b85615428 | 74 | }; |
JeffM | 0:fd3b85615428 | 75 | |
JeffM | 0:fd3b85615428 | 76 | list<InPacket> m_lInPkt; |
JeffM | 0:fd3b85615428 | 77 | IpAddr m_multicastGroup; |
JeffM | 0:fd3b85615428 | 78 | |
JeffM | 0:fd3b85615428 | 79 | //Static callback : Transforms into a C++ callback |
JeffM | 0:fd3b85615428 | 80 | static void sRecvCb(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t port); |
JeffM | 0:fd3b85615428 | 81 | |
JeffM | 0:fd3b85615428 | 82 | }; |
JeffM | 0:fd3b85615428 | 83 | |
JeffM | 0:fd3b85615428 | 84 | #endif |