ID the MBED processor on the network if you have more than one. View MBED name on DHCP of your Router - Example \"MBED PE\" Change your ID in Core / host.h

Committer:
JeffM
Date:
Sat Nov 06 14:11:02 2010 +0000
Revision:
0:fd3b85615428
MBED ID 1A

Who changed what in which revision?

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