Andrew Lindsay / Mbed 2 deprecated IoTGateway_Basic

Dependencies:   NetServices FatFileSystem csv_parser mbed MQTTClient RF12B DNSResolver SDFileSystem

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PayloadV2.h Source File

PayloadV2.h

00001 /** IoT Gateway RFM12B payload V2 format handling
00002  *
00003  * @author Andrew Lindsay
00004  *
00005  * @section LICENSE
00006  *
00007  * Copyright (c) 2012 Andrew Lindsay (andrew [at] thiseldo [dot] co [dot] uk)
00008  *
00009  * Permission is hereby granted, free of charge, to any person obtaining a copy
00010  * of this software and associated documentation files (the "Software"), to deal
00011  * in the Software without restriction, including without limitation the rights
00012  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013  * copies of the Software, and to permit persons to whom the Software is
00014  * furnished to do so, subject to the following conditions:
00015 
00016  * The above copyright notice and this permission notice shall be included in
00017  * all copies or substantial portions of the Software.
00018  * 
00019  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025  * THE SOFTWARE.
00026  * 
00027  * @section DESCRIPTION
00028  * 
00029  * 
00030  */
00031  
00032 #ifndef _PAYLOADV2_H
00033 #define _PAYLOADV2_H
00034 
00035 #include "mbed.h"
00036 #include "PayloadDef.h"
00037 
00038 #define V2_DATATYPE_BYTE    0
00039 #define V2_DATATYPE_SHORT   1
00040 #define V2_DATATYPE_LONG    2
00041 #define V2_DATATYPE_STRING  3
00042 
00043 /** V2 header definition
00044  */
00045 typedef struct {
00046     uint8_t typeId;        // Type and sensor ID high
00047     uint8_t id;            // Sensor ID
00048 }  __attribute__((packed)) payloadv2Header;
00049 
00050 /** Byte reading definition
00051  */
00052 typedef struct {
00053     uint16_t type:4;        // Type
00054     uint16_t id:12;         // Sensor ID
00055     int8_t reading;         // Reading
00056 }  __attribute__((packed)) payloadv2ByteReading;
00057 
00058 /** Short reading definition
00059  */
00060 typedef struct {
00061     uint16_t type:4;        // Type
00062     uint16_t id:12;         // Sensor ID
00063     int16_t reading;        // Reading
00064 }  __attribute__((packed)) payloadv2ShortReading;
00065 
00066 /** Long reading definition
00067  */
00068 typedef struct {
00069     uint16_t type:4;        // Type
00070     uint16_t id:12;         // Sensor ID
00071     int32_t reading;        // Reading
00072 }  __attribute__((packed)) payloadv2LongReading;
00073 
00074 /** String reading definition
00075  */
00076 typedef struct {
00077     uint16_t type:4;        // Type
00078     uint16_t id:12;         // Sensor ID
00079     int8_t length;          // String length
00080     uint8_t str[1];         // First character or data
00081 }  __attribute__((packed)) payloadv2StringReading;
00082 
00083 /** Class definition for Payload V2 format
00084  */
00085 class PayloadV2: public PayloadDef {
00086 public:
00087     /** Default Constructor
00088      */
00089     PayloadV2();
00090 
00091     /** Alternative constructor for passing payload details
00092      *
00093      * @param pptr  Pointer to payload data
00094      * @param plen  Length of paylod data
00095      */
00096     PayloadV2( uint8_t *pptr, short plen );
00097 
00098     /** Get the number of readings in a payload
00099      *
00100      * @returns the number of readings found in payload so they can be read
00101      */
00102     virtual short numReadings();
00103 
00104     /** Get a single reading from the payload
00105      *
00106      * @param readingNum The number of the reading, starts from 0 upto number of readings in payload
00107      * @returns Integer representation of reading
00108      */
00109     virtual int reading( short readingNum );
00110 
00111     /** Get the sensor ID for the specified reading within the payload
00112      *
00113      * @param readingNum The number of the reading, starts from 0 upto number of readings in payload
00114      * @returns Integer representation of reading
00115      */
00116     virtual short sensorId( short readingNum );
00117 
00118     /* The next functions are extra to the PayloadV2 type */
00119     
00120     /** Get the pointer to the specified reading within the payload
00121      *
00122      * @param readingNum The number of the reading, starts from 0 upto number of readings in payload
00123      * @returns Pointer to the reading
00124      */
00125     uint8_t *readingPtr( short readingNum );
00126 
00127     /** Get a single Byte reading from the payload
00128      *
00129      * @param readingNum The number of the reading, starts from 0 upto number of readings in payload
00130      * @returns Byte 8 bit Integer representation of reading
00131      */
00132     int8_t readingByte( short readingNum );
00133     
00134     /** Get a single short reading from the payload
00135      *
00136      * @param readingNum The number of the reading, starts from 0 upto number of readings in payload
00137      * @returns Short, 16 bit Integer representation of reading
00138      */
00139     short readingShort( short readingNum );
00140     
00141     /** Get a single Long reading from the payload
00142      *
00143      * @param readingNum The number of the reading, starts from 0 upto number of readings in payload
00144      * @returns Long 32bit Integer representation of reading
00145      */
00146     int readingLong( short readingNum );
00147 
00148     /** Get the type of the specified reading
00149      *
00150      * @param readingNum The number of the reading, starts from 0 upto number of readings in payload
00151      * @returns type of the reading, byte, short, long, string.
00152      */
00153     short readingType( short readingNum );
00154 };
00155 
00156 #endif /* _PAYLOADV2_H */