lpc1768

Committer:
jh1cdv00
Date:
Tue Jan 27 01:38:19 2015 +0000
Revision:
0:f35dada1dac1
lpc1768

Who changed what in which revision?

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