mbed based IoT Gateway More details http://blog.thiseldo.co.uk/wp-filez/IoTGateway.pdf
Dependencies: NetServices FatFileSystem csv_parser mbed MQTTClient RF12B DNSResolver SDFileSystem
Payloads/PayloadV2.h@5:0dbc27a7af55, 2012-05-09 (annotated)
- Committer:
- SomeRandomBloke
- Date:
- Wed May 09 20:29:30 2012 +0000
- Revision:
- 5:0dbc27a7af55
- Parent:
- 0:a29a0225f203
Reduced debug output
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SomeRandomBloke | 0:a29a0225f203 | 1 | /** IoT Gateway RFM12B payload V2 format handling |
SomeRandomBloke | 0:a29a0225f203 | 2 | * |
SomeRandomBloke | 0:a29a0225f203 | 3 | * @author Andrew Lindsay |
SomeRandomBloke | 0:a29a0225f203 | 4 | * |
SomeRandomBloke | 0:a29a0225f203 | 5 | * @section LICENSE |
SomeRandomBloke | 0:a29a0225f203 | 6 | * |
SomeRandomBloke | 0:a29a0225f203 | 7 | * Copyright (c) 2012 Andrew Lindsay (andrew [at] thiseldo [dot] co [dot] uk) |
SomeRandomBloke | 0:a29a0225f203 | 8 | * |
SomeRandomBloke | 0:a29a0225f203 | 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
SomeRandomBloke | 0:a29a0225f203 | 10 | * of this software and associated documentation files (the "Software"), to deal |
SomeRandomBloke | 0:a29a0225f203 | 11 | * in the Software without restriction, including without limitation the rights |
SomeRandomBloke | 0:a29a0225f203 | 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
SomeRandomBloke | 0:a29a0225f203 | 13 | * copies of the Software, and to permit persons to whom the Software is |
SomeRandomBloke | 0:a29a0225f203 | 14 | * furnished to do so, subject to the following conditions: |
SomeRandomBloke | 0:a29a0225f203 | 15 | |
SomeRandomBloke | 0:a29a0225f203 | 16 | * The above copyright notice and this permission notice shall be included in |
SomeRandomBloke | 0:a29a0225f203 | 17 | * all copies or substantial portions of the Software. |
SomeRandomBloke | 0:a29a0225f203 | 18 | * |
SomeRandomBloke | 0:a29a0225f203 | 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
SomeRandomBloke | 0:a29a0225f203 | 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
SomeRandomBloke | 0:a29a0225f203 | 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
SomeRandomBloke | 0:a29a0225f203 | 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
SomeRandomBloke | 0:a29a0225f203 | 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
SomeRandomBloke | 0:a29a0225f203 | 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
SomeRandomBloke | 0:a29a0225f203 | 25 | * THE SOFTWARE. |
SomeRandomBloke | 0:a29a0225f203 | 26 | * |
SomeRandomBloke | 0:a29a0225f203 | 27 | * @section DESCRIPTION |
SomeRandomBloke | 0:a29a0225f203 | 28 | * |
SomeRandomBloke | 0:a29a0225f203 | 29 | * |
SomeRandomBloke | 0:a29a0225f203 | 30 | */ |
SomeRandomBloke | 0:a29a0225f203 | 31 | |
SomeRandomBloke | 0:a29a0225f203 | 32 | #ifndef _PAYLOADV2_H |
SomeRandomBloke | 0:a29a0225f203 | 33 | #define _PAYLOADV2_H |
SomeRandomBloke | 0:a29a0225f203 | 34 | |
SomeRandomBloke | 0:a29a0225f203 | 35 | #include "mbed.h" |
SomeRandomBloke | 0:a29a0225f203 | 36 | #include "PayloadDef.h" |
SomeRandomBloke | 0:a29a0225f203 | 37 | |
SomeRandomBloke | 0:a29a0225f203 | 38 | #define V2_DATATYPE_BYTE 0 |
SomeRandomBloke | 0:a29a0225f203 | 39 | #define V2_DATATYPE_SHORT 1 |
SomeRandomBloke | 0:a29a0225f203 | 40 | #define V2_DATATYPE_LONG 2 |
SomeRandomBloke | 0:a29a0225f203 | 41 | #define V2_DATATYPE_STRING 3 |
SomeRandomBloke | 0:a29a0225f203 | 42 | |
SomeRandomBloke | 0:a29a0225f203 | 43 | /** V2 header definition |
SomeRandomBloke | 0:a29a0225f203 | 44 | */ |
SomeRandomBloke | 0:a29a0225f203 | 45 | typedef struct { |
SomeRandomBloke | 0:a29a0225f203 | 46 | uint8_t typeId; // Type and sensor ID high |
SomeRandomBloke | 0:a29a0225f203 | 47 | uint8_t id; // Sensor ID |
SomeRandomBloke | 0:a29a0225f203 | 48 | } __attribute__((packed)) payloadv2Header; |
SomeRandomBloke | 0:a29a0225f203 | 49 | |
SomeRandomBloke | 0:a29a0225f203 | 50 | /** Byte reading definition |
SomeRandomBloke | 0:a29a0225f203 | 51 | */ |
SomeRandomBloke | 0:a29a0225f203 | 52 | typedef struct { |
SomeRandomBloke | 0:a29a0225f203 | 53 | uint16_t type:4; // Type |
SomeRandomBloke | 0:a29a0225f203 | 54 | uint16_t id:12; // Sensor ID |
SomeRandomBloke | 0:a29a0225f203 | 55 | int8_t reading; // Reading |
SomeRandomBloke | 0:a29a0225f203 | 56 | } __attribute__((packed)) payloadv2ByteReading; |
SomeRandomBloke | 0:a29a0225f203 | 57 | |
SomeRandomBloke | 0:a29a0225f203 | 58 | /** Short reading definition |
SomeRandomBloke | 0:a29a0225f203 | 59 | */ |
SomeRandomBloke | 0:a29a0225f203 | 60 | typedef struct { |
SomeRandomBloke | 0:a29a0225f203 | 61 | uint16_t type:4; // Type |
SomeRandomBloke | 0:a29a0225f203 | 62 | uint16_t id:12; // Sensor ID |
SomeRandomBloke | 0:a29a0225f203 | 63 | int16_t reading; // Reading |
SomeRandomBloke | 0:a29a0225f203 | 64 | } __attribute__((packed)) payloadv2ShortReading; |
SomeRandomBloke | 0:a29a0225f203 | 65 | |
SomeRandomBloke | 0:a29a0225f203 | 66 | /** Long reading definition |
SomeRandomBloke | 0:a29a0225f203 | 67 | */ |
SomeRandomBloke | 0:a29a0225f203 | 68 | typedef struct { |
SomeRandomBloke | 0:a29a0225f203 | 69 | uint16_t type:4; // Type |
SomeRandomBloke | 0:a29a0225f203 | 70 | uint16_t id:12; // Sensor ID |
SomeRandomBloke | 0:a29a0225f203 | 71 | int32_t reading; // Reading |
SomeRandomBloke | 0:a29a0225f203 | 72 | } __attribute__((packed)) payloadv2LongReading; |
SomeRandomBloke | 0:a29a0225f203 | 73 | |
SomeRandomBloke | 0:a29a0225f203 | 74 | /** String reading definition |
SomeRandomBloke | 0:a29a0225f203 | 75 | */ |
SomeRandomBloke | 0:a29a0225f203 | 76 | typedef struct { |
SomeRandomBloke | 0:a29a0225f203 | 77 | uint16_t type:4; // Type |
SomeRandomBloke | 0:a29a0225f203 | 78 | uint16_t id:12; // Sensor ID |
SomeRandomBloke | 0:a29a0225f203 | 79 | int8_t length; // String length |
SomeRandomBloke | 0:a29a0225f203 | 80 | uint8_t str[1]; // First character or data |
SomeRandomBloke | 0:a29a0225f203 | 81 | } __attribute__((packed)) payloadv2StringReading; |
SomeRandomBloke | 0:a29a0225f203 | 82 | |
SomeRandomBloke | 0:a29a0225f203 | 83 | /** Class definition for Payload V2 format |
SomeRandomBloke | 0:a29a0225f203 | 84 | */ |
SomeRandomBloke | 0:a29a0225f203 | 85 | class PayloadV2: public PayloadDef { |
SomeRandomBloke | 0:a29a0225f203 | 86 | public: |
SomeRandomBloke | 0:a29a0225f203 | 87 | /** Default Constructor |
SomeRandomBloke | 0:a29a0225f203 | 88 | */ |
SomeRandomBloke | 0:a29a0225f203 | 89 | PayloadV2(); |
SomeRandomBloke | 0:a29a0225f203 | 90 | |
SomeRandomBloke | 0:a29a0225f203 | 91 | /** Alternative constructor for passing payload details |
SomeRandomBloke | 0:a29a0225f203 | 92 | * |
SomeRandomBloke | 0:a29a0225f203 | 93 | * @param pptr Pointer to payload data |
SomeRandomBloke | 0:a29a0225f203 | 94 | * @param plen Length of paylod data |
SomeRandomBloke | 0:a29a0225f203 | 95 | */ |
SomeRandomBloke | 0:a29a0225f203 | 96 | PayloadV2( uint8_t *pptr, short plen ); |
SomeRandomBloke | 0:a29a0225f203 | 97 | |
SomeRandomBloke | 0:a29a0225f203 | 98 | /** Get the number of readings in a payload |
SomeRandomBloke | 0:a29a0225f203 | 99 | * |
SomeRandomBloke | 0:a29a0225f203 | 100 | * @returns the number of readings found in payload so they can be read |
SomeRandomBloke | 0:a29a0225f203 | 101 | */ |
SomeRandomBloke | 0:a29a0225f203 | 102 | virtual short numReadings(); |
SomeRandomBloke | 0:a29a0225f203 | 103 | |
SomeRandomBloke | 0:a29a0225f203 | 104 | /** Get a single reading from the payload |
SomeRandomBloke | 0:a29a0225f203 | 105 | * |
SomeRandomBloke | 0:a29a0225f203 | 106 | * @param readingNum The number of the reading, starts from 0 upto number of readings in payload |
SomeRandomBloke | 0:a29a0225f203 | 107 | * @returns Integer representation of reading |
SomeRandomBloke | 0:a29a0225f203 | 108 | */ |
SomeRandomBloke | 0:a29a0225f203 | 109 | virtual int reading( short readingNum ); |
SomeRandomBloke | 0:a29a0225f203 | 110 | |
SomeRandomBloke | 0:a29a0225f203 | 111 | /** Get the sensor ID for the specified reading within the payload |
SomeRandomBloke | 0:a29a0225f203 | 112 | * |
SomeRandomBloke | 0:a29a0225f203 | 113 | * @param readingNum The number of the reading, starts from 0 upto number of readings in payload |
SomeRandomBloke | 0:a29a0225f203 | 114 | * @returns Integer representation of reading |
SomeRandomBloke | 0:a29a0225f203 | 115 | */ |
SomeRandomBloke | 0:a29a0225f203 | 116 | virtual short sensorId( short readingNum ); |
SomeRandomBloke | 0:a29a0225f203 | 117 | |
SomeRandomBloke | 0:a29a0225f203 | 118 | /* The next functions are extra to the PayloadV2 type */ |
SomeRandomBloke | 0:a29a0225f203 | 119 | |
SomeRandomBloke | 0:a29a0225f203 | 120 | /** Get the pointer to the specified reading within the payload |
SomeRandomBloke | 0:a29a0225f203 | 121 | * |
SomeRandomBloke | 0:a29a0225f203 | 122 | * @param readingNum The number of the reading, starts from 0 upto number of readings in payload |
SomeRandomBloke | 0:a29a0225f203 | 123 | * @returns Pointer to the reading |
SomeRandomBloke | 0:a29a0225f203 | 124 | */ |
SomeRandomBloke | 0:a29a0225f203 | 125 | uint8_t *readingPtr( short readingNum ); |
SomeRandomBloke | 0:a29a0225f203 | 126 | |
SomeRandomBloke | 0:a29a0225f203 | 127 | /** Get a single Byte reading from the payload |
SomeRandomBloke | 0:a29a0225f203 | 128 | * |
SomeRandomBloke | 0:a29a0225f203 | 129 | * @param readingNum The number of the reading, starts from 0 upto number of readings in payload |
SomeRandomBloke | 0:a29a0225f203 | 130 | * @returns Byte 8 bit Integer representation of reading |
SomeRandomBloke | 0:a29a0225f203 | 131 | */ |
SomeRandomBloke | 0:a29a0225f203 | 132 | int8_t readingByte( short readingNum ); |
SomeRandomBloke | 0:a29a0225f203 | 133 | |
SomeRandomBloke | 0:a29a0225f203 | 134 | /** Get a single short reading from the payload |
SomeRandomBloke | 0:a29a0225f203 | 135 | * |
SomeRandomBloke | 0:a29a0225f203 | 136 | * @param readingNum The number of the reading, starts from 0 upto number of readings in payload |
SomeRandomBloke | 0:a29a0225f203 | 137 | * @returns Short, 16 bit Integer representation of reading |
SomeRandomBloke | 0:a29a0225f203 | 138 | */ |
SomeRandomBloke | 0:a29a0225f203 | 139 | short readingShort( short readingNum ); |
SomeRandomBloke | 0:a29a0225f203 | 140 | |
SomeRandomBloke | 0:a29a0225f203 | 141 | /** Get a single Long reading from the payload |
SomeRandomBloke | 0:a29a0225f203 | 142 | * |
SomeRandomBloke | 0:a29a0225f203 | 143 | * @param readingNum The number of the reading, starts from 0 upto number of readings in payload |
SomeRandomBloke | 0:a29a0225f203 | 144 | * @returns Long 32bit Integer representation of reading |
SomeRandomBloke | 0:a29a0225f203 | 145 | */ |
SomeRandomBloke | 0:a29a0225f203 | 146 | int readingLong( short readingNum ); |
SomeRandomBloke | 0:a29a0225f203 | 147 | |
SomeRandomBloke | 0:a29a0225f203 | 148 | /** Get the type of the specified reading |
SomeRandomBloke | 0:a29a0225f203 | 149 | * |
SomeRandomBloke | 0:a29a0225f203 | 150 | * @param readingNum The number of the reading, starts from 0 upto number of readings in payload |
SomeRandomBloke | 0:a29a0225f203 | 151 | * @returns type of the reading, byte, short, long, string. |
SomeRandomBloke | 0:a29a0225f203 | 152 | */ |
SomeRandomBloke | 0:a29a0225f203 | 153 | short readingType( short readingNum ); |
SomeRandomBloke | 0:a29a0225f203 | 154 | }; |
SomeRandomBloke | 0:a29a0225f203 | 155 | |
SomeRandomBloke | 0:a29a0225f203 | 156 | #endif /* _PAYLOADV2_H */ |