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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers memp.h Source File

memp.h

00001 /*
00002  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
00003  * All rights reserved. 
00004  * 
00005  * Redistribution and use in source and binary forms, with or without modification, 
00006  * are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright notice,
00009  *    this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright notice,
00011  *    this list of conditions and the following disclaimer in the documentation
00012  *    and/or other materials provided with the distribution.
00013  * 3. The name of the author may not be used to endorse or promote products
00014  *    derived from this software without specific prior written permission. 
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
00017  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00018  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
00019  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00020  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
00021  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
00024  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
00025  * OF SUCH DAMAGE.
00026  *
00027  * This file is part of the lwIP TCP/IP stack.
00028  * 
00029  * Author: Adam Dunkels <adam@sics.se>
00030  *
00031  */
00032 
00033 #ifndef __LWIP_MEMP_H__
00034 #define __LWIP_MEMP_H__
00035 
00036 #include "lwip/opt.h"
00037 
00038 #ifdef __cplusplus
00039 extern "C" {
00040 #endif
00041 
00042 /* Create the list of all memory pools managed by memp. MEMP_MAX represents a NULL pool at the end */
00043 typedef enum {
00044 #define LWIP_MEMPOOL(name,num,size,desc)  MEMP_##name,
00045 #include "lwip/memp_std.h"
00046   MEMP_MAX
00047 } memp_t;
00048 
00049 #if MEM_USE_POOLS
00050 /* Use a helper type to get the start and end of the user "memory pools" for mem_malloc */
00051 typedef enum {
00052     /* Get the first (via:
00053        MEMP_POOL_HELPER_START = ((u8_t) 1*MEMP_POOL_A + 0*MEMP_POOL_B + 0*MEMP_POOL_C + 0)*/
00054     MEMP_POOL_HELPER_FIRST = ((u8_t)
00055 #define LWIP_MEMPOOL(name,num,size,desc)
00056 #define LWIP_MALLOC_MEMPOOL_START 1
00057 #define LWIP_MALLOC_MEMPOOL(num, size) * MEMP_POOL_##size + 0
00058 #define LWIP_MALLOC_MEMPOOL_END
00059 #include "lwip/memp_std.h"
00060     ) ,
00061     /* Get the last (via:
00062        MEMP_POOL_HELPER_END = ((u8_t) 0 + MEMP_POOL_A*0 + MEMP_POOL_B*0 + MEMP_POOL_C*1) */
00063     MEMP_POOL_HELPER_LAST = ((u8_t)
00064 #define LWIP_MEMPOOL(name,num,size,desc)
00065 #define LWIP_MALLOC_MEMPOOL_START
00066 #define LWIP_MALLOC_MEMPOOL(num, size) 0 + MEMP_POOL_##size *
00067 #define LWIP_MALLOC_MEMPOOL_END 1
00068 #include "lwip/memp_std.h"
00069     )
00070 } memp_pool_helper_t;
00071 
00072 /* The actual start and stop values are here (cast them over)
00073    We use this helper type and these defines so we can avoid using const memp_t values */
00074 #define MEMP_POOL_FIRST ((memp_t) MEMP_POOL_HELPER_FIRST)
00075 #define MEMP_POOL_LAST   ((memp_t) MEMP_POOL_HELPER_LAST)
00076 #endif /* MEM_USE_POOLS */
00077 
00078 #if MEMP_MEM_MALLOC || MEM_USE_POOLS
00079 extern const u16_t memp_sizes[MEMP_MAX];
00080 #endif /* MEMP_MEM_MALLOC || MEM_USE_POOLS */
00081 
00082 #if MEMP_MEM_MALLOC
00083 
00084 #include "mem.h"
00085 
00086 #define memp_init()
00087 #define memp_malloc(type)     mem_malloc(memp_sizes[type])
00088 #define memp_free(type, mem)  mem_free(mem)
00089 
00090 #else /* MEMP_MEM_MALLOC */
00091 
00092 #if MEM_USE_POOLS
00093 /** This structure is used to save the pool one element came from. */
00094 struct memp_malloc_helper
00095 {
00096    memp_t poolnr;
00097 };
00098 #endif /* MEM_USE_POOLS */
00099 
00100 void  memp_init(void);
00101 
00102 #if MEMP_OVERFLOW_CHECK
00103 void *memp_malloc_fn(memp_t type, const char* file, const int line);
00104 #define memp_malloc(t) memp_malloc_fn((t), __FILE__, __LINE__)
00105 #else
00106 void *memp_malloc(memp_t type);
00107 #endif
00108 void  memp_free(memp_t type, void *mem);
00109 
00110 #endif /* MEMP_MEM_MALLOC */
00111 
00112 #ifdef __cplusplus
00113 }
00114 #endif
00115 
00116 #endif /* __LWIP_MEMP_H__ */