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 LWIPNETTCPSOCKET_H
fablabtruck 0:3852426a5068 25 #define LWIPNETTCPSOCKET_H
fablabtruck 0:3852426a5068 26
fablabtruck 0:3852426a5068 27 #define NET_LWIP_STACK 1
fablabtruck 0:3852426a5068 28 #include "if/net/nettcpsocket.h"
fablabtruck 0:3852426a5068 29 #include "LwipNetIf.h"
fablabtruck 0:3852426a5068 30
fablabtruck 0:3852426a5068 31 #include "stdint.h"
fablabtruck 0:3852426a5068 32
fablabtruck 0:3852426a5068 33 //Implements NetTcpSockets over lwIP raw API
fablabtruck 0:3852426a5068 34
fablabtruck 0:3852426a5068 35 struct tcp_pcb; //Represents a Tcp Connection, "Protocol Control Block", see rawapi.txt & tcp.h
fablabtruck 0:3852426a5068 36 struct pbuf; //Lwip Buffer Container
fablabtruck 0:3852426a5068 37
fablabtruck 0:3852426a5068 38 typedef signed char err_t;
fablabtruck 0:3852426a5068 39 typedef uint16_t u16_t;
fablabtruck 0:3852426a5068 40
fablabtruck 0:3852426a5068 41 class LwipNetTcpSocket: public NetTcpSocket
fablabtruck 0:3852426a5068 42 {
fablabtruck 0:3852426a5068 43 public:
fablabtruck 0:3852426a5068 44 LwipNetTcpSocket(tcp_pcb* pPcb = NULL); //Passes a pcb if already created (by an accept req for instance), in that case transfers ownership
fablabtruck 0:3852426a5068 45 virtual ~LwipNetTcpSocket();
fablabtruck 0:3852426a5068 46
fablabtruck 0:3852426a5068 47 virtual NetTcpSocketErr bind(const Host& me);
fablabtruck 0:3852426a5068 48 virtual NetTcpSocketErr listen();
fablabtruck 0:3852426a5068 49 virtual NetTcpSocketErr connect(const Host& host);
fablabtruck 0:3852426a5068 50 virtual NetTcpSocketErr accept(Host* pClient, NetTcpSocket** ppNewNetTcpSocket);
fablabtruck 0:3852426a5068 51
fablabtruck 0:3852426a5068 52 virtual int /*if < 0 : NetTcpSocketErr*/ send(const char* buf, int len);
fablabtruck 0:3852426a5068 53 virtual int /*if < 0 : NetTcpSocketErr*/ recv(char* buf, int len);
fablabtruck 0:3852426a5068 54
fablabtruck 0:3852426a5068 55 virtual NetTcpSocketErr close();
fablabtruck 0:3852426a5068 56
fablabtruck 0:3852426a5068 57 virtual NetTcpSocketErr poll();
fablabtruck 0:3852426a5068 58
fablabtruck 0:3852426a5068 59 protected:
fablabtruck 0:3852426a5068 60 volatile tcp_pcb* m_pPcb;
fablabtruck 0:3852426a5068 61
fablabtruck 0:3852426a5068 62 //Events callbacks from lwIp
fablabtruck 0:3852426a5068 63 err_t acceptCb(tcp_pcb* newpcb, err_t err);
fablabtruck 0:3852426a5068 64 err_t connectedCb(tcp_pcb* tpcb, err_t err);
fablabtruck 0:3852426a5068 65
fablabtruck 0:3852426a5068 66 void errCb(err_t err);
fablabtruck 0:3852426a5068 67
fablabtruck 0:3852426a5068 68 err_t sentCb(tcp_pcb* tpcb, u16_t len);
fablabtruck 0:3852426a5068 69 err_t recvCb(tcp_pcb* tpcb, pbuf *p, err_t err);
fablabtruck 0:3852426a5068 70
fablabtruck 0:3852426a5068 71 private:
fablabtruck 0:3852426a5068 72 void cleanUp(); //Flush input buffer
fablabtruck 0:3852426a5068 73
fablabtruck 0:3852426a5068 74 // queue<tcp_pcb*> m_lpInPcb; //Incoming connections that have not been accepted yet
fablabtruck 0:3852426a5068 75 queue<LwipNetTcpSocket*> m_lpInNetTcpSocket; //Incoming connections that have not been accepted yet
fablabtruck 0:3852426a5068 76
fablabtruck 0:3852426a5068 77 volatile pbuf* m_pReadPbuf; //Ptr to read buffer
fablabtruck 0:3852426a5068 78
fablabtruck 0:3852426a5068 79 //Static callbacks : Transforms into a C++ callback
fablabtruck 0:3852426a5068 80 static err_t sAcceptCb(void *arg, struct tcp_pcb *newpcb, err_t err);
fablabtruck 0:3852426a5068 81 static err_t sConnectedCb(void *arg, struct tcp_pcb *tpcb, err_t err);
fablabtruck 0:3852426a5068 82
fablabtruck 0:3852426a5068 83 static void sErrCb(void *arg, err_t err);
fablabtruck 0:3852426a5068 84
fablabtruck 0:3852426a5068 85 static err_t sSentCb(void *arg, struct tcp_pcb *tpcb, u16_t len);
fablabtruck 0:3852426a5068 86 static err_t sRecvCb(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err);
fablabtruck 0:3852426a5068 87
fablabtruck 0:3852426a5068 88 };
fablabtruck 0:3852426a5068 89
fablabtruck 0:3852426a5068 90 #endif