Example program with HTTPServer and sensor data streaming over TCPSockets, using Donatien Garnier's Net APIs and services code on top of LWIP. Files StreamServer.h and .cpp encapsulate streaming over TCPSockets. Broadcast is done by sendToAll(), and all incoming data is echoed back to the client. Echo code can be replaced with some remote control of the streaming interface. See main() that shows how to periodically send some data to all subscribed clients. To subscribe, a client should open a socket at <mbed_ip> port 123. I used few lines in TCL code to set up a quick sink for the data. HTTP files are served on port 80 concurrently to the streaming.

Dependencies:   mbed

Committer:
iva2k
Date:
Sat Jun 12 06:01:50 2010 +0000
Revision:
0:e614f7875b60

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
iva2k 0:e614f7875b60 1 /*****************************************************************************
iva2k 0:e614f7875b60 2 * fsm.h - Network Control Protocol Finite State Machine header file.
iva2k 0:e614f7875b60 3 *
iva2k 0:e614f7875b60 4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
iva2k 0:e614f7875b60 5 * Copyright (c) 1997 Global Election Systems Inc.
iva2k 0:e614f7875b60 6 *
iva2k 0:e614f7875b60 7 * The authors hereby grant permission to use, copy, modify, distribute,
iva2k 0:e614f7875b60 8 * and license this software and its documentation for any purpose, provided
iva2k 0:e614f7875b60 9 * that existing copyright notices are retained in all copies and that this
iva2k 0:e614f7875b60 10 * notice and the following disclaimer are included verbatim in any
iva2k 0:e614f7875b60 11 * distributions. No written agreement, license, or royalty fee is required
iva2k 0:e614f7875b60 12 * for any of the authorized uses.
iva2k 0:e614f7875b60 13 *
iva2k 0:e614f7875b60 14 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
iva2k 0:e614f7875b60 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
iva2k 0:e614f7875b60 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
iva2k 0:e614f7875b60 17 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
iva2k 0:e614f7875b60 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
iva2k 0:e614f7875b60 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
iva2k 0:e614f7875b60 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
iva2k 0:e614f7875b60 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
iva2k 0:e614f7875b60 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
iva2k 0:e614f7875b60 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
iva2k 0:e614f7875b60 24 *
iva2k 0:e614f7875b60 25 ******************************************************************************
iva2k 0:e614f7875b60 26 * REVISION HISTORY
iva2k 0:e614f7875b60 27 *
iva2k 0:e614f7875b60 28 * 03-01-01 Marc Boucher <marc@mbsi.ca>
iva2k 0:e614f7875b60 29 * Ported to lwIP.
iva2k 0:e614f7875b60 30 * 97-11-05 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc.
iva2k 0:e614f7875b60 31 * Original based on BSD code.
iva2k 0:e614f7875b60 32 *****************************************************************************/
iva2k 0:e614f7875b60 33 /*
iva2k 0:e614f7875b60 34 * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions.
iva2k 0:e614f7875b60 35 *
iva2k 0:e614f7875b60 36 * Copyright (c) 1989 Carnegie Mellon University.
iva2k 0:e614f7875b60 37 * All rights reserved.
iva2k 0:e614f7875b60 38 *
iva2k 0:e614f7875b60 39 * Redistribution and use in source and binary forms are permitted
iva2k 0:e614f7875b60 40 * provided that the above copyright notice and this paragraph are
iva2k 0:e614f7875b60 41 * duplicated in all such forms and that any documentation,
iva2k 0:e614f7875b60 42 * advertising materials, and other materials related to such
iva2k 0:e614f7875b60 43 * distribution and use acknowledge that the software was developed
iva2k 0:e614f7875b60 44 * by Carnegie Mellon University. The name of the
iva2k 0:e614f7875b60 45 * University may not be used to endorse or promote products derived
iva2k 0:e614f7875b60 46 * from this software without specific prior written permission.
iva2k 0:e614f7875b60 47 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
iva2k 0:e614f7875b60 48 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
iva2k 0:e614f7875b60 49 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
iva2k 0:e614f7875b60 50 *
iva2k 0:e614f7875b60 51 * $Id: fsm.h,v 1.5 2009/12/31 17:08:08 goldsimon Exp $
iva2k 0:e614f7875b60 52 */
iva2k 0:e614f7875b60 53
iva2k 0:e614f7875b60 54 #ifndef FSM_H
iva2k 0:e614f7875b60 55 #define FSM_H
iva2k 0:e614f7875b60 56
iva2k 0:e614f7875b60 57 /*
iva2k 0:e614f7875b60 58 * LCP Packet header = Code, id, length.
iva2k 0:e614f7875b60 59 */
iva2k 0:e614f7875b60 60 #define HEADERLEN (sizeof (u_char) + sizeof (u_char) + sizeof (u_short))
iva2k 0:e614f7875b60 61
iva2k 0:e614f7875b60 62
iva2k 0:e614f7875b60 63 /*
iva2k 0:e614f7875b60 64 * CP (LCP, IPCP, etc.) codes.
iva2k 0:e614f7875b60 65 */
iva2k 0:e614f7875b60 66 #define CONFREQ 1 /* Configuration Request */
iva2k 0:e614f7875b60 67 #define CONFACK 2 /* Configuration Ack */
iva2k 0:e614f7875b60 68 #define CONFNAK 3 /* Configuration Nak */
iva2k 0:e614f7875b60 69 #define CONFREJ 4 /* Configuration Reject */
iva2k 0:e614f7875b60 70 #define TERMREQ 5 /* Termination Request */
iva2k 0:e614f7875b60 71 #define TERMACK 6 /* Termination Ack */
iva2k 0:e614f7875b60 72 #define CODEREJ 7 /* Code Reject */
iva2k 0:e614f7875b60 73
iva2k 0:e614f7875b60 74
iva2k 0:e614f7875b60 75 /*
iva2k 0:e614f7875b60 76 * Each FSM is described by an fsm structure and fsm callbacks.
iva2k 0:e614f7875b60 77 */
iva2k 0:e614f7875b60 78 typedef struct fsm {
iva2k 0:e614f7875b60 79 int unit; /* Interface unit number */
iva2k 0:e614f7875b60 80 u_short protocol; /* Data Link Layer Protocol field value */
iva2k 0:e614f7875b60 81 int state; /* State */
iva2k 0:e614f7875b60 82 int flags; /* Contains option bits */
iva2k 0:e614f7875b60 83 u_char id; /* Current id */
iva2k 0:e614f7875b60 84 u_char reqid; /* Current request id */
iva2k 0:e614f7875b60 85 u_char seen_ack; /* Have received valid Ack/Nak/Rej to Req */
iva2k 0:e614f7875b60 86 int timeouttime; /* Timeout time in milliseconds */
iva2k 0:e614f7875b60 87 int maxconfreqtransmits; /* Maximum Configure-Request transmissions */
iva2k 0:e614f7875b60 88 int retransmits; /* Number of retransmissions left */
iva2k 0:e614f7875b60 89 int maxtermtransmits; /* Maximum Terminate-Request transmissions */
iva2k 0:e614f7875b60 90 int nakloops; /* Number of nak loops since last ack */
iva2k 0:e614f7875b60 91 int maxnakloops; /* Maximum number of nak loops tolerated */
iva2k 0:e614f7875b60 92 struct fsm_callbacks* callbacks; /* Callback routines */
iva2k 0:e614f7875b60 93 char* term_reason; /* Reason for closing protocol */
iva2k 0:e614f7875b60 94 int term_reason_len; /* Length of term_reason */
iva2k 0:e614f7875b60 95 } fsm;
iva2k 0:e614f7875b60 96
iva2k 0:e614f7875b60 97
iva2k 0:e614f7875b60 98 typedef struct fsm_callbacks {
iva2k 0:e614f7875b60 99 void (*resetci)(fsm*); /* Reset our Configuration Information */
iva2k 0:e614f7875b60 100 int (*cilen)(fsm*); /* Length of our Configuration Information */
iva2k 0:e614f7875b60 101 void (*addci)(fsm*, u_char*, int*); /* Add our Configuration Information */
iva2k 0:e614f7875b60 102 int (*ackci)(fsm*, u_char*, int); /* ACK our Configuration Information */
iva2k 0:e614f7875b60 103 int (*nakci)(fsm*, u_char*, int); /* NAK our Configuration Information */
iva2k 0:e614f7875b60 104 int (*rejci)(fsm*, u_char*, int); /* Reject our Configuration Information */
iva2k 0:e614f7875b60 105 int (*reqci)(fsm*, u_char*, int*, int); /* Request peer's Configuration Information */
iva2k 0:e614f7875b60 106 void (*up)(fsm*); /* Called when fsm reaches LS_OPENED state */
iva2k 0:e614f7875b60 107 void (*down)(fsm*); /* Called when fsm leaves LS_OPENED state */
iva2k 0:e614f7875b60 108 void (*starting)(fsm*); /* Called when we want the lower layer */
iva2k 0:e614f7875b60 109 void (*finished)(fsm*); /* Called when we don't want the lower layer */
iva2k 0:e614f7875b60 110 void (*protreject)(int); /* Called when Protocol-Reject received */
iva2k 0:e614f7875b60 111 void (*retransmit)(fsm*); /* Retransmission is necessary */
iva2k 0:e614f7875b60 112 int (*extcode)(fsm*, int, u_char, u_char*, int); /* Called when unknown code received */
iva2k 0:e614f7875b60 113 char *proto_name; /* String name for protocol (for messages) */
iva2k 0:e614f7875b60 114 } fsm_callbacks;
iva2k 0:e614f7875b60 115
iva2k 0:e614f7875b60 116
iva2k 0:e614f7875b60 117 /*
iva2k 0:e614f7875b60 118 * Link states.
iva2k 0:e614f7875b60 119 */
iva2k 0:e614f7875b60 120 #define LS_INITIAL 0 /* Down, hasn't been opened */
iva2k 0:e614f7875b60 121 #define LS_STARTING 1 /* Down, been opened */
iva2k 0:e614f7875b60 122 #define LS_CLOSED 2 /* Up, hasn't been opened */
iva2k 0:e614f7875b60 123 #define LS_STOPPED 3 /* Open, waiting for down event */
iva2k 0:e614f7875b60 124 #define LS_CLOSING 4 /* Terminating the connection, not open */
iva2k 0:e614f7875b60 125 #define LS_STOPPING 5 /* Terminating, but open */
iva2k 0:e614f7875b60 126 #define LS_REQSENT 6 /* We've sent a Config Request */
iva2k 0:e614f7875b60 127 #define LS_ACKRCVD 7 /* We've received a Config Ack */
iva2k 0:e614f7875b60 128 #define LS_ACKSENT 8 /* We've sent a Config Ack */
iva2k 0:e614f7875b60 129 #define LS_OPENED 9 /* Connection available */
iva2k 0:e614f7875b60 130
iva2k 0:e614f7875b60 131 /*
iva2k 0:e614f7875b60 132 * Flags - indicate options controlling FSM operation
iva2k 0:e614f7875b60 133 */
iva2k 0:e614f7875b60 134 #define OPT_PASSIVE 1 /* Don't die if we don't get a response */
iva2k 0:e614f7875b60 135 #define OPT_RESTART 2 /* Treat 2nd OPEN as DOWN, UP */
iva2k 0:e614f7875b60 136 #define OPT_SILENT 4 /* Wait for peer to speak first */
iva2k 0:e614f7875b60 137
iva2k 0:e614f7875b60 138
iva2k 0:e614f7875b60 139 /*
iva2k 0:e614f7875b60 140 * Prototypes
iva2k 0:e614f7875b60 141 */
iva2k 0:e614f7875b60 142 void fsm_init (fsm*);
iva2k 0:e614f7875b60 143 void fsm_lowerup (fsm*);
iva2k 0:e614f7875b60 144 void fsm_lowerdown (fsm*);
iva2k 0:e614f7875b60 145 void fsm_open (fsm*);
iva2k 0:e614f7875b60 146 void fsm_close (fsm*, char*);
iva2k 0:e614f7875b60 147 void fsm_input (fsm*, u_char*, int);
iva2k 0:e614f7875b60 148 void fsm_protreject (fsm*);
iva2k 0:e614f7875b60 149 void fsm_sdata (fsm*, u_char, u_char, u_char*, int);
iva2k 0:e614f7875b60 150
iva2k 0:e614f7875b60 151
iva2k 0:e614f7875b60 152 /*
iva2k 0:e614f7875b60 153 * Variables
iva2k 0:e614f7875b60 154 */
iva2k 0:e614f7875b60 155 extern int peer_mru[]; /* currently negotiated peer MRU (per unit) */
iva2k 0:e614f7875b60 156
iva2k 0:e614f7875b60 157 #endif /* FSM_H */