Measure system

Dependencies:   EthernetNetIf mbed RF12B

Committer:
benecsj
Date:
Thu Mar 10 19:56:45 2011 +0000
Revision:
1:b26ab2467b1a

        

Who changed what in which revision?

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