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 * @file
iva2k 0:e614f7875b60 3 * Abstract Syntax Notation One (ISO 8824, 8825) codec.
iva2k 0:e614f7875b60 4 */
iva2k 0:e614f7875b60 5
iva2k 0:e614f7875b60 6 /*
iva2k 0:e614f7875b60 7 * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
iva2k 0:e614f7875b60 8 * All rights reserved.
iva2k 0:e614f7875b60 9 *
iva2k 0:e614f7875b60 10 * Redistribution and use in source and binary forms, with or without modification,
iva2k 0:e614f7875b60 11 * are permitted provided that the following conditions are met:
iva2k 0:e614f7875b60 12 *
iva2k 0:e614f7875b60 13 * 1. Redistributions of source code must retain the above copyright notice,
iva2k 0:e614f7875b60 14 * this list of conditions and the following disclaimer.
iva2k 0:e614f7875b60 15 * 2. Redistributions in binary form must reproduce the above copyright notice,
iva2k 0:e614f7875b60 16 * this list of conditions and the following disclaimer in the documentation
iva2k 0:e614f7875b60 17 * and/or other materials provided with the distribution.
iva2k 0:e614f7875b60 18 * 3. The name of the author may not be used to endorse or promote products
iva2k 0:e614f7875b60 19 * derived from this software without specific prior written permission.
iva2k 0:e614f7875b60 20 *
iva2k 0:e614f7875b60 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
iva2k 0:e614f7875b60 22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
iva2k 0:e614f7875b60 23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
iva2k 0:e614f7875b60 24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
iva2k 0:e614f7875b60 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
iva2k 0:e614f7875b60 26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
iva2k 0:e614f7875b60 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
iva2k 0:e614f7875b60 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
iva2k 0:e614f7875b60 29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
iva2k 0:e614f7875b60 30 * OF SUCH DAMAGE.
iva2k 0:e614f7875b60 31 *
iva2k 0:e614f7875b60 32 * Author: Christiaan Simons <christiaan.simons@axon.tv>
iva2k 0:e614f7875b60 33 */
iva2k 0:e614f7875b60 34
iva2k 0:e614f7875b60 35 #ifndef __LWIP_SNMP_ASN1_H__
iva2k 0:e614f7875b60 36 #define __LWIP_SNMP_ASN1_H__
iva2k 0:e614f7875b60 37
iva2k 0:e614f7875b60 38 #include "lwip/opt.h"
iva2k 0:e614f7875b60 39 #include "lwip/err.h"
iva2k 0:e614f7875b60 40 #include "lwip/pbuf.h"
iva2k 0:e614f7875b60 41 #include "lwip/snmp.h"
iva2k 0:e614f7875b60 42
iva2k 0:e614f7875b60 43 #if LWIP_SNMP
iva2k 0:e614f7875b60 44
iva2k 0:e614f7875b60 45 #ifdef __cplusplus
iva2k 0:e614f7875b60 46 extern "C" {
iva2k 0:e614f7875b60 47 #endif
iva2k 0:e614f7875b60 48
iva2k 0:e614f7875b60 49 #define SNMP_ASN1_UNIV (!0x80 | !0x40)
iva2k 0:e614f7875b60 50 #define SNMP_ASN1_APPLIC (!0x80 | 0x40)
iva2k 0:e614f7875b60 51 #define SNMP_ASN1_CONTXT ( 0x80 | !0x40)
iva2k 0:e614f7875b60 52
iva2k 0:e614f7875b60 53 #define SNMP_ASN1_CONSTR (0x20)
iva2k 0:e614f7875b60 54 #define SNMP_ASN1_PRIMIT (!0x20)
iva2k 0:e614f7875b60 55
iva2k 0:e614f7875b60 56 /* universal tags */
iva2k 0:e614f7875b60 57 #define SNMP_ASN1_INTEG 2
iva2k 0:e614f7875b60 58 #define SNMP_ASN1_OC_STR 4
iva2k 0:e614f7875b60 59 #define SNMP_ASN1_NUL 5
iva2k 0:e614f7875b60 60 #define SNMP_ASN1_OBJ_ID 6
iva2k 0:e614f7875b60 61 #define SNMP_ASN1_SEQ 16
iva2k 0:e614f7875b60 62
iva2k 0:e614f7875b60 63 /* application specific (SNMP) tags */
iva2k 0:e614f7875b60 64 #define SNMP_ASN1_IPADDR 0 /* octet string size(4) */
iva2k 0:e614f7875b60 65 #define SNMP_ASN1_COUNTER 1 /* u32_t */
iva2k 0:e614f7875b60 66 #define SNMP_ASN1_GAUGE 2 /* u32_t */
iva2k 0:e614f7875b60 67 #define SNMP_ASN1_TIMETICKS 3 /* u32_t */
iva2k 0:e614f7875b60 68 #define SNMP_ASN1_OPAQUE 4 /* octet string */
iva2k 0:e614f7875b60 69
iva2k 0:e614f7875b60 70 /* context specific (SNMP) tags */
iva2k 0:e614f7875b60 71 #define SNMP_ASN1_PDU_GET_REQ 0
iva2k 0:e614f7875b60 72 #define SNMP_ASN1_PDU_GET_NEXT_REQ 1
iva2k 0:e614f7875b60 73 #define SNMP_ASN1_PDU_GET_RESP 2
iva2k 0:e614f7875b60 74 #define SNMP_ASN1_PDU_SET_REQ 3
iva2k 0:e614f7875b60 75 #define SNMP_ASN1_PDU_TRAP 4
iva2k 0:e614f7875b60 76
iva2k 0:e614f7875b60 77 err_t snmp_asn1_dec_type(struct pbuf *p, u16_t ofs, u8_t *type);
iva2k 0:e614f7875b60 78 err_t snmp_asn1_dec_length(struct pbuf *p, u16_t ofs, u8_t *octets_used, u16_t *length);
iva2k 0:e614f7875b60 79 err_t snmp_asn1_dec_u32t(struct pbuf *p, u16_t ofs, u16_t len, u32_t *value);
iva2k 0:e614f7875b60 80 err_t snmp_asn1_dec_s32t(struct pbuf *p, u16_t ofs, u16_t len, s32_t *value);
iva2k 0:e614f7875b60 81 err_t snmp_asn1_dec_oid(struct pbuf *p, u16_t ofs, u16_t len, struct snmp_obj_id *oid);
iva2k 0:e614f7875b60 82 err_t snmp_asn1_dec_raw(struct pbuf *p, u16_t ofs, u16_t len, u16_t raw_len, u8_t *raw);
iva2k 0:e614f7875b60 83
iva2k 0:e614f7875b60 84 void snmp_asn1_enc_length_cnt(u16_t length, u8_t *octets_needed);
iva2k 0:e614f7875b60 85 void snmp_asn1_enc_u32t_cnt(u32_t value, u16_t *octets_needed);
iva2k 0:e614f7875b60 86 void snmp_asn1_enc_s32t_cnt(s32_t value, u16_t *octets_needed);
iva2k 0:e614f7875b60 87 void snmp_asn1_enc_oid_cnt(u8_t ident_len, s32_t *ident, u16_t *octets_needed);
iva2k 0:e614f7875b60 88 err_t snmp_asn1_enc_type(struct pbuf *p, u16_t ofs, u8_t type);
iva2k 0:e614f7875b60 89 err_t snmp_asn1_enc_length(struct pbuf *p, u16_t ofs, u16_t length);
iva2k 0:e614f7875b60 90 err_t snmp_asn1_enc_u32t(struct pbuf *p, u16_t ofs, u16_t octets_needed, u32_t value);
iva2k 0:e614f7875b60 91 err_t snmp_asn1_enc_s32t(struct pbuf *p, u16_t ofs, u16_t octets_needed, s32_t value);
iva2k 0:e614f7875b60 92 err_t snmp_asn1_enc_oid(struct pbuf *p, u16_t ofs, u8_t ident_len, s32_t *ident);
iva2k 0:e614f7875b60 93 err_t snmp_asn1_enc_raw(struct pbuf *p, u16_t ofs, u16_t raw_len, u8_t *raw);
iva2k 0:e614f7875b60 94
iva2k 0:e614f7875b60 95 #ifdef __cplusplus
iva2k 0:e614f7875b60 96 }
iva2k 0:e614f7875b60 97 #endif
iva2k 0:e614f7875b60 98
iva2k 0:e614f7875b60 99 #endif /* LWIP_SNMP */
iva2k 0:e614f7875b60 100
iva2k 0:e614f7875b60 101 #endif /* __LWIP_SNMP_ASN1_H__ */