This is the firmware for the LaOS - Laser Open Source project. You can use it to drive a laser cutter. For hardware and more information, look at our wiki: http://wiki.laoslaser.org

Dependencies:   EthernetNetIf mbed

Committer:
fablabtruck
Date:
Fri Jun 08 09:26:40 2012 +0000
Revision:
0:3852426a5068
svn revision 379

Who changed what in which revision?

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