Control of mbed using OSC. Based on code from the Make Controller. Right now you can turn the onboard LEDs on/off and toggle 8 digital out pins. More I/O will be done in the future.

Dependencies:   mbed

Committer:
pehrhovey
Date:
Wed Mar 17 03:17:38 2010 +0000
Revision:
0:439354122597

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pehrhovey 0:439354122597 1 #ifndef TCPCONNECTION_H
pehrhovey 0:439354122597 2 #define TCPCONNECTION_H
pehrhovey 0:439354122597 3
pehrhovey 0:439354122597 4 #include "arch/cc.h"
pehrhovey 0:439354122597 5 #include "lwip/err.h"
pehrhovey 0:439354122597 6 //#include "lwip/tcp.h"
pehrhovey 0:439354122597 7
pehrhovey 0:439354122597 8 #include "TCPItem.h"
pehrhovey 0:439354122597 9
pehrhovey 0:439354122597 10 namespace mbed {
pehrhovey 0:439354122597 11
pehrhovey 0:439354122597 12 class NetServer;
pehrhovey 0:439354122597 13 class TCPListener;
pehrhovey 0:439354122597 14
pehrhovey 0:439354122597 15 class TCPConnection : public TCPItem {
pehrhovey 0:439354122597 16 public:
pehrhovey 0:439354122597 17 TCPConnection(struct ip_addr, u16_t);
pehrhovey 0:439354122597 18 TCPConnection(TCPListener *, struct tcp_pcb *);
pehrhovey 0:439354122597 19
pehrhovey 0:439354122597 20 virtual ~TCPConnection();
pehrhovey 0:439354122597 21
pehrhovey 0:439354122597 22 void connect();
pehrhovey 0:439354122597 23
pehrhovey 0:439354122597 24 err_t write(void *, u16_t len, u8_t flags = TCP_WRITE_FLAG_COPY) const;
pehrhovey 0:439354122597 25
pehrhovey 0:439354122597 26 void recved(u32_t len) const;
pehrhovey 0:439354122597 27 u16_t sndbuf() const { return tcp_sndbuf(_pcb); }
pehrhovey 0:439354122597 28
pehrhovey 0:439354122597 29 void set_poll_timer(const u32_t &time) {
pehrhovey 0:439354122597 30 if(_pcb) {
pehrhovey 0:439354122597 31 _pcb->polltmr = time;
pehrhovey 0:439354122597 32 }
pehrhovey 0:439354122597 33 }
pehrhovey 0:439354122597 34
pehrhovey 0:439354122597 35 u32_t get_poll_interval() const {
pehrhovey 0:439354122597 36 return (_pcb)? _pcb->pollinterval: 0;
pehrhovey 0:439354122597 37 }
pehrhovey 0:439354122597 38
pehrhovey 0:439354122597 39 void set_poll_interval(const u32_t &value) {
pehrhovey 0:439354122597 40 if(_pcb) {
pehrhovey 0:439354122597 41 _pcb->pollinterval = value;
pehrhovey 0:439354122597 42 }
pehrhovey 0:439354122597 43 }
pehrhovey 0:439354122597 44
pehrhovey 0:439354122597 45 u32_t get_poll_timer() const {
pehrhovey 0:439354122597 46 return (_pcb)? _pcb->polltmr: 0;
pehrhovey 0:439354122597 47 }
pehrhovey 0:439354122597 48
pehrhovey 0:439354122597 49 protected:
pehrhovey 0:439354122597 50 TCPConnection();
pehrhovey 0:439354122597 51
pehrhovey 0:439354122597 52 /**
pehrhovey 0:439354122597 53 * Function to be called when more send buffer space is available.
pehrhovey 0:439354122597 54 * @param space the amount of bytes available
pehrhovey 0:439354122597 55 * @return ERR_OK: try to send some data by calling tcp_output
pehrhovey 0:439354122597 56 */
pehrhovey 0:439354122597 57 virtual err_t sent(u16_t space) = 0;
pehrhovey 0:439354122597 58
pehrhovey 0:439354122597 59 /**
pehrhovey 0:439354122597 60 * Function to be called when (in-sequence) data has arrived.
pehrhovey 0:439354122597 61 * @param p the packet buffer which arrived
pehrhovey 0:439354122597 62 * @param err an error argument (TODO: that is current always ERR_OK?)
pehrhovey 0:439354122597 63 * @return ERR_OK: try to send some data by calling tcp_output
pehrhovey 0:439354122597 64 */
pehrhovey 0:439354122597 65 virtual err_t recv(struct pbuf *p, err_t err) = 0;
pehrhovey 0:439354122597 66
pehrhovey 0:439354122597 67 /**
pehrhovey 0:439354122597 68 * Function to be called when a connection has been set up.
pehrhovey 0:439354122597 69 * @param pcb the tcp_pcb that now is connected
pehrhovey 0:439354122597 70 * @param err an error argument (TODO: that is current always ERR_OK?)
pehrhovey 0:439354122597 71 * @return value is currently ignored
pehrhovey 0:439354122597 72 */
pehrhovey 0:439354122597 73 virtual err_t connected(err_t err);
pehrhovey 0:439354122597 74
pehrhovey 0:439354122597 75 /**
pehrhovey 0:439354122597 76 * Function which is called periodically.
pehrhovey 0:439354122597 77 * The period can be adjusted in multiples of the TCP slow timer interval
pehrhovey 0:439354122597 78 * by changing tcp_pcb.polltmr.
pehrhovey 0:439354122597 79 * @return ERR_OK: try to send some data by calling tcp_output
pehrhovey 0:439354122597 80 */
pehrhovey 0:439354122597 81 virtual err_t poll() = 0;
pehrhovey 0:439354122597 82
pehrhovey 0:439354122597 83 /**
pehrhovey 0:439354122597 84 * Function to be called whenever a fatal error occurs.
pehrhovey 0:439354122597 85 * There is no pcb parameter since most of the times, the pcb is
pehrhovey 0:439354122597 86 * already deallocated (or there is no pcb) when this function is called.
pehrhovey 0:439354122597 87 * @param err an indication why the error callback is called:
pehrhovey 0:439354122597 88 * ERR_ABRT: aborted through tcp_abort or by a TCP timer
pehrhovey 0:439354122597 89 * ERR_RST: the connection was reset by the remote host
pehrhovey 0:439354122597 90 */
pehrhovey 0:439354122597 91 virtual void err(err_t err) = 0;
pehrhovey 0:439354122597 92
pehrhovey 0:439354122597 93 virtual void dnsreply(const char *hostname, struct ip_addr *addr) = 0;
pehrhovey 0:439354122597 94
pehrhovey 0:439354122597 95 err_t dnsrequest(const char *hostname, struct ip_addr *addr) const;
pehrhovey 0:439354122597 96
pehrhovey 0:439354122597 97 private:
pehrhovey 0:439354122597 98 static void dnsreply_callback(const char *name, struct ip_addr *ipaddr, void *arg);
pehrhovey 0:439354122597 99 static err_t connected_callback(void *arg, struct tcp_pcb *pcb, err_t err);
pehrhovey 0:439354122597 100 static err_t sent_callback(void *arg, struct tcp_pcb *pcb, u16_t space);
pehrhovey 0:439354122597 101 static err_t recv_callback(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err);
pehrhovey 0:439354122597 102 static err_t poll_callback(void *arg, struct tcp_pcb *pcb);
pehrhovey 0:439354122597 103 static void error_callback(void *arg, err_t erra);
pehrhovey 0:439354122597 104
pehrhovey 0:439354122597 105 protected:
pehrhovey 0:439354122597 106 TCPListener *_parent;
pehrhovey 0:439354122597 107 struct ip_addr _ipaddr;
pehrhovey 0:439354122597 108 u16_t _port;
pehrhovey 0:439354122597 109
pehrhovey 0:439354122597 110 friend class NetServer;
pehrhovey 0:439354122597 111 };
pehrhovey 0:439354122597 112
pehrhovey 0:439354122597 113 };
pehrhovey 0:439354122597 114
pehrhovey 0:439354122597 115 #endif /* TCPCONNECTION_H */