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