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 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
iva2k 0:e614f7875b60 3 * All rights reserved.
iva2k 0:e614f7875b60 4 *
iva2k 0:e614f7875b60 5 * Redistribution and use in source and binary forms, with or without modification,
iva2k 0:e614f7875b60 6 * are permitted provided that the following conditions are met:
iva2k 0:e614f7875b60 7 *
iva2k 0:e614f7875b60 8 * 1. Redistributions of source code must retain the above copyright notice,
iva2k 0:e614f7875b60 9 * this list of conditions and the following disclaimer.
iva2k 0:e614f7875b60 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
iva2k 0:e614f7875b60 11 * this list of conditions and the following disclaimer in the documentation
iva2k 0:e614f7875b60 12 * and/or other materials provided with the distribution.
iva2k 0:e614f7875b60 13 * 3. The name of the author may not be used to endorse or promote products
iva2k 0:e614f7875b60 14 * derived from this software without specific prior written permission.
iva2k 0:e614f7875b60 15 *
iva2k 0:e614f7875b60 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
iva2k 0:e614f7875b60 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
iva2k 0:e614f7875b60 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
iva2k 0:e614f7875b60 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
iva2k 0:e614f7875b60 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
iva2k 0:e614f7875b60 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
iva2k 0:e614f7875b60 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
iva2k 0:e614f7875b60 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
iva2k 0:e614f7875b60 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
iva2k 0:e614f7875b60 25 * OF SUCH DAMAGE.
iva2k 0:e614f7875b60 26 *
iva2k 0:e614f7875b60 27 * This file is part of the lwIP TCP/IP stack.
iva2k 0:e614f7875b60 28 *
iva2k 0:e614f7875b60 29 * Author: Adam Dunkels <adam@sics.se>
iva2k 0:e614f7875b60 30 *
iva2k 0:e614f7875b60 31 */
iva2k 0:e614f7875b60 32
iva2k 0:e614f7875b60 33 #ifndef __LWIP_MEMP_H__
iva2k 0:e614f7875b60 34 #define __LWIP_MEMP_H__
iva2k 0:e614f7875b60 35
iva2k 0:e614f7875b60 36 #include "lwip/opt.h"
iva2k 0:e614f7875b60 37
iva2k 0:e614f7875b60 38 #ifdef __cplusplus
iva2k 0:e614f7875b60 39 extern "C" {
iva2k 0:e614f7875b60 40 #endif
iva2k 0:e614f7875b60 41
iva2k 0:e614f7875b60 42 /* Create the list of all memory pools managed by memp. MEMP_MAX represents a NULL pool at the end */
iva2k 0:e614f7875b60 43 typedef enum {
iva2k 0:e614f7875b60 44 #define LWIP_MEMPOOL(name,num,size,desc) MEMP_##name,
iva2k 0:e614f7875b60 45 #include "lwip/memp_std.h"
iva2k 0:e614f7875b60 46 MEMP_MAX
iva2k 0:e614f7875b60 47 } memp_t;
iva2k 0:e614f7875b60 48
iva2k 0:e614f7875b60 49 #if MEM_USE_POOLS
iva2k 0:e614f7875b60 50 /* Use a helper type to get the start and end of the user "memory pools" for mem_malloc */
iva2k 0:e614f7875b60 51 typedef enum {
iva2k 0:e614f7875b60 52 /* Get the first (via:
iva2k 0:e614f7875b60 53 MEMP_POOL_HELPER_START = ((u8_t) 1*MEMP_POOL_A + 0*MEMP_POOL_B + 0*MEMP_POOL_C + 0)*/
iva2k 0:e614f7875b60 54 MEMP_POOL_HELPER_FIRST = ((u8_t)
iva2k 0:e614f7875b60 55 #define LWIP_MEMPOOL(name,num,size,desc)
iva2k 0:e614f7875b60 56 #define LWIP_MALLOC_MEMPOOL_START 1
iva2k 0:e614f7875b60 57 #define LWIP_MALLOC_MEMPOOL(num, size) * MEMP_POOL_##size + 0
iva2k 0:e614f7875b60 58 #define LWIP_MALLOC_MEMPOOL_END
iva2k 0:e614f7875b60 59 #include "lwip/memp_std.h"
iva2k 0:e614f7875b60 60 ) ,
iva2k 0:e614f7875b60 61 /* Get the last (via:
iva2k 0:e614f7875b60 62 MEMP_POOL_HELPER_END = ((u8_t) 0 + MEMP_POOL_A*0 + MEMP_POOL_B*0 + MEMP_POOL_C*1) */
iva2k 0:e614f7875b60 63 MEMP_POOL_HELPER_LAST = ((u8_t)
iva2k 0:e614f7875b60 64 #define LWIP_MEMPOOL(name,num,size,desc)
iva2k 0:e614f7875b60 65 #define LWIP_MALLOC_MEMPOOL_START
iva2k 0:e614f7875b60 66 #define LWIP_MALLOC_MEMPOOL(num, size) 0 + MEMP_POOL_##size *
iva2k 0:e614f7875b60 67 #define LWIP_MALLOC_MEMPOOL_END 1
iva2k 0:e614f7875b60 68 #include "lwip/memp_std.h"
iva2k 0:e614f7875b60 69 )
iva2k 0:e614f7875b60 70 } memp_pool_helper_t;
iva2k 0:e614f7875b60 71
iva2k 0:e614f7875b60 72 /* The actual start and stop values are here (cast them over)
iva2k 0:e614f7875b60 73 We use this helper type and these defines so we can avoid using const memp_t values */
iva2k 0:e614f7875b60 74 #define MEMP_POOL_FIRST ((memp_t) MEMP_POOL_HELPER_FIRST)
iva2k 0:e614f7875b60 75 #define MEMP_POOL_LAST ((memp_t) MEMP_POOL_HELPER_LAST)
iva2k 0:e614f7875b60 76 #endif /* MEM_USE_POOLS */
iva2k 0:e614f7875b60 77
iva2k 0:e614f7875b60 78 #if MEMP_MEM_MALLOC || MEM_USE_POOLS
iva2k 0:e614f7875b60 79 extern const u16_t memp_sizes[MEMP_MAX];
iva2k 0:e614f7875b60 80 #endif /* MEMP_MEM_MALLOC || MEM_USE_POOLS */
iva2k 0:e614f7875b60 81
iva2k 0:e614f7875b60 82 #if MEMP_MEM_MALLOC
iva2k 0:e614f7875b60 83
iva2k 0:e614f7875b60 84 #include "mem.h"
iva2k 0:e614f7875b60 85
iva2k 0:e614f7875b60 86 #define memp_init()
iva2k 0:e614f7875b60 87 #define memp_malloc(type) mem_malloc(memp_sizes[type])
iva2k 0:e614f7875b60 88 #define memp_free(type, mem) mem_free(mem)
iva2k 0:e614f7875b60 89
iva2k 0:e614f7875b60 90 #else /* MEMP_MEM_MALLOC */
iva2k 0:e614f7875b60 91
iva2k 0:e614f7875b60 92 #if MEM_USE_POOLS
iva2k 0:e614f7875b60 93 /** This structure is used to save the pool one element came from. */
iva2k 0:e614f7875b60 94 struct memp_malloc_helper
iva2k 0:e614f7875b60 95 {
iva2k 0:e614f7875b60 96 memp_t poolnr;
iva2k 0:e614f7875b60 97 };
iva2k 0:e614f7875b60 98 #endif /* MEM_USE_POOLS */
iva2k 0:e614f7875b60 99
iva2k 0:e614f7875b60 100 void memp_init(void);
iva2k 0:e614f7875b60 101
iva2k 0:e614f7875b60 102 #if MEMP_OVERFLOW_CHECK
iva2k 0:e614f7875b60 103 void *memp_malloc_fn(memp_t type, const char* file, const int line);
iva2k 0:e614f7875b60 104 #define memp_malloc(t) memp_malloc_fn((t), __FILE__, __LINE__)
iva2k 0:e614f7875b60 105 #else
iva2k 0:e614f7875b60 106 void *memp_malloc(memp_t type);
iva2k 0:e614f7875b60 107 #endif
iva2k 0:e614f7875b60 108 void memp_free(memp_t type, void *mem);
iva2k 0:e614f7875b60 109
iva2k 0:e614f7875b60 110 #endif /* MEMP_MEM_MALLOC */
iva2k 0:e614f7875b60 111
iva2k 0:e614f7875b60 112 #ifdef __cplusplus
iva2k 0:e614f7875b60 113 }
iva2k 0:e614f7875b60 114 #endif
iva2k 0:e614f7875b60 115
iva2k 0:e614f7875b60 116 #endif /* __LWIP_MEMP_H__ */