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 TCPCALLBACKCONNECTION_H
pehrhovey 0:439354122597 2 #define TCPCALLBACKCONNECTION_H
pehrhovey 0:439354122597 3
pehrhovey 0:439354122597 4 #include "TCPConnection.h"
pehrhovey 0:439354122597 5
pehrhovey 0:439354122597 6 namespace mbed {
pehrhovey 0:439354122597 7
pehrhovey 0:439354122597 8 #define NO_SENT_FNC ((err_t (*)(TCPCallbackConnection *, u16_t))NULL)
pehrhovey 0:439354122597 9 #define NO_RECV_FNC ((err_t (*)(TCPCallbackConnection *, struct pbuf *, err_t))NULL)
pehrhovey 0:439354122597 10 #define NO_POLL_FNC ((err_t (*)(TCPCallbackConnection *))NULL)
pehrhovey 0:439354122597 11 #define NO_ACCEPT_FNC ((err_t (*)(TCPCallbackConnection *, struct tcp_pcb *, err_t))NULL)
pehrhovey 0:439354122597 12 #define NO_CONNECT_FNC ((err_t (*)(TCPCallbackConnection *, err_t))NULL)
pehrhovey 0:439354122597 13 #define NO_ERR_FNC ((void (*)(TCPCallbackConnection *, err_t))NULL)
pehrhovey 0:439354122597 14
pehrhovey 0:439354122597 15
pehrhovey 0:439354122597 16 class TCPCallbackConnection : public TCPConnection {
pehrhovey 0:439354122597 17 public:
pehrhovey 0:439354122597 18 TCPCallbackConnection(struct ip_addr ip_addr, u16_t port,
pehrhovey 0:439354122597 19 err_t (*psent)(TCPCallbackConnection *, u16_t),
pehrhovey 0:439354122597 20 err_t (*precv)(TCPCallbackConnection *, struct pbuf *, err_t),
pehrhovey 0:439354122597 21 err_t (*ppoll)(TCPCallbackConnection *),
pehrhovey 0:439354122597 22 err_t (*pconnected)(TCPCallbackConnection *, err_t),
pehrhovey 0:439354122597 23 void (*perr )(TCPCallbackConnection *, err_t))
pehrhovey 0:439354122597 24 : TCPConnection(ip_addr, port) {
pehrhovey 0:439354122597 25 _sent = psent;
pehrhovey 0:439354122597 26 _recv = precv;
pehrhovey 0:439354122597 27 _poll = ppoll;
pehrhovey 0:439354122597 28 _connected = pconnected;
pehrhovey 0:439354122597 29 _err = perr;
pehrhovey 0:439354122597 30 }
pehrhovey 0:439354122597 31
pehrhovey 0:439354122597 32 TCPCallbackConnection(TCPListener *parent, struct tcp_pcb *npcb,
pehrhovey 0:439354122597 33 err_t (*psent)(TCPCallbackConnection *, u16_t),
pehrhovey 0:439354122597 34 err_t (*precv)(TCPCallbackConnection *, struct pbuf *, err_t),
pehrhovey 0:439354122597 35 err_t (*ppoll)(TCPCallbackConnection *),
pehrhovey 0:439354122597 36 err_t (*pconnected)(TCPCallbackConnection *, err_t),
pehrhovey 0:439354122597 37 void (*perr )(TCPCallbackConnection *, err_t))
pehrhovey 0:439354122597 38 : TCPConnection(parent, npcb) {
pehrhovey 0:439354122597 39 _sent = psent;
pehrhovey 0:439354122597 40 _recv = precv;
pehrhovey 0:439354122597 41 _poll = ppoll;
pehrhovey 0:439354122597 42 _connected = pconnected;
pehrhovey 0:439354122597 43 _err = perr;
pehrhovey 0:439354122597 44 }
pehrhovey 0:439354122597 45
pehrhovey 0:439354122597 46 private:
pehrhovey 0:439354122597 47 /*
pehrhovey 0:439354122597 48 * Function to be called when more send buffer space is available.
pehrhovey 0:439354122597 49 * @param space the amount of bytes available
pehrhovey 0:439354122597 50 * @return ERR_OK: try to send some data by calling tcp_output
pehrhovey 0:439354122597 51 */
pehrhovey 0:439354122597 52 virtual err_t sent(u16_t space) {
pehrhovey 0:439354122597 53 if(_sent) {
pehrhovey 0:439354122597 54 return (_sent)(this, space);
pehrhovey 0:439354122597 55 } else {
pehrhovey 0:439354122597 56 return ERR_OK;
pehrhovey 0:439354122597 57 }
pehrhovey 0:439354122597 58 }
pehrhovey 0:439354122597 59
pehrhovey 0:439354122597 60 /*
pehrhovey 0:439354122597 61 * Function to be called when (in-sequence) data has arrived.
pehrhovey 0:439354122597 62 * @param p the packet buffer which arrived
pehrhovey 0:439354122597 63 * @param err an error argument (TODO: that is current always ERR_OK?)
pehrhovey 0:439354122597 64 * @return ERR_OK: try to send some data by calling tcp_output
pehrhovey 0:439354122597 65 */
pehrhovey 0:439354122597 66 virtual err_t recv(struct pbuf *p, err_t err) {
pehrhovey 0:439354122597 67 if(_recv) {
pehrhovey 0:439354122597 68 return (_recv)(this, p, err);
pehrhovey 0:439354122597 69 } else {
pehrhovey 0:439354122597 70 return ERR_OK;
pehrhovey 0:439354122597 71 }
pehrhovey 0:439354122597 72 }
pehrhovey 0:439354122597 73
pehrhovey 0:439354122597 74 /*
pehrhovey 0:439354122597 75 * Function which is called periodically.
pehrhovey 0:439354122597 76 * The period can be adjusted in multiples of the TCP slow timer interval
pehrhovey 0:439354122597 77 * by changing tcp_pcb.polltmr.
pehrhovey 0:439354122597 78 * @return ERR_OK: try to send some data by calling tcp_output
pehrhovey 0:439354122597 79 */
pehrhovey 0:439354122597 80 virtual err_t poll() {
pehrhovey 0:439354122597 81 if(_poll) {
pehrhovey 0:439354122597 82 return (_poll)(this);
pehrhovey 0:439354122597 83 } else {
pehrhovey 0:439354122597 84 return ERR_OK;
pehrhovey 0:439354122597 85 }
pehrhovey 0:439354122597 86 }
pehrhovey 0:439354122597 87
pehrhovey 0:439354122597 88 virtual err_t connected(err_t err) {
pehrhovey 0:439354122597 89 err = TCPConnection::connected(err);
pehrhovey 0:439354122597 90 if(_connected) {
pehrhovey 0:439354122597 91 return (_connected)(this, err);
pehrhovey 0:439354122597 92 } else {
pehrhovey 0:439354122597 93 return ERR_OK;
pehrhovey 0:439354122597 94 }
pehrhovey 0:439354122597 95 }
pehrhovey 0:439354122597 96
pehrhovey 0:439354122597 97 /*
pehrhovey 0:439354122597 98 * Function to be called whenever a fatal error occurs.
pehrhovey 0:439354122597 99 * There is no pcb parameter since most of the times, the pcb is
pehrhovey 0:439354122597 100 * already deallocated (or there is no pcb) when this function is called.
pehrhovey 0:439354122597 101 * @param err an indication why the error callback is called:
pehrhovey 0:439354122597 102 * ERR_ABRT: aborted through tcp_abort or by a TCP timer
pehrhovey 0:439354122597 103 * ERR_RST: the connection was reset by the remote host
pehrhovey 0:439354122597 104 */
pehrhovey 0:439354122597 105 virtual void err(err_t erra) {
pehrhovey 0:439354122597 106 if(_err) {
pehrhovey 0:439354122597 107 (_err)(this, erra);
pehrhovey 0:439354122597 108 }
pehrhovey 0:439354122597 109 }
pehrhovey 0:439354122597 110
pehrhovey 0:439354122597 111 virtual void dnsreply(const char *hostname, struct ip_addr *addr) {};
pehrhovey 0:439354122597 112
pehrhovey 0:439354122597 113 err_t (*_sent)(TCPCallbackConnection *, u16_t);
pehrhovey 0:439354122597 114 err_t (*_recv)(TCPCallbackConnection *, struct pbuf *p, err_t err);
pehrhovey 0:439354122597 115 err_t (*_poll)(TCPCallbackConnection *);
pehrhovey 0:439354122597 116 err_t (*_accept)(TCPCallbackConnection *, struct tcp_pcb *newpcb, err_t err);
pehrhovey 0:439354122597 117 err_t (*_connected)(TCPCallbackConnection *, err_t err);
pehrhovey 0:439354122597 118 void (*_err )(TCPCallbackConnection *, err_t);
pehrhovey 0:439354122597 119 };
pehrhovey 0:439354122597 120
pehrhovey 0:439354122597 121 };
pehrhovey 0:439354122597 122
pehrhovey 0:439354122597 123 #endif /* TCPCALLBACKCONNECTION_H */