Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: NetServices FatFileSystem csv_parser mbed MQTTClient RF12B DNSResolver SDFileSystem
IoTRouting.h
00001 /** IoT Gateway Routing for incoming messages 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 _IOTROUTING_H 00033 #define _IOTROUTING_H 00034 00035 #include "iotgateway.h" 00036 #include "mbed.h" 00037 #include "HTTPClient.h" 00038 #include "OutputDef.h" 00039 #include "OutputPachube.h" 00040 #include "OutputMqtt.h" 00041 #include "OutputEmonCms.h" 00042 #include "OutputSenSe.h" 00043 #include "PayloadV1.h" 00044 #include "PayloadV2.h" 00045 #include "PayloadSimple.h" 00046 #include <vector> 00047 00048 #define STATUS_PAYLOAD_VMASK 0xf8 00049 #define STATUS_PAYLOAD_VERSION 0x06 00050 #define STATUS_PAYLOAD_V1 0x00 00051 #define STATUS_PAYLOAD_V2 0x02 00052 #define STATUS_LOW_BATTERY 0x01 00053 00054 #define PAYLOAD_TYPE_UNKNOWN 99 00055 #define PAYLOAD_TYPE_SIMPLE 0 00056 #define PAYLOAD_TYPE_V1 1 00057 #define PAYLOAD_TYPE_V2 2 00058 00059 #define OUTPUT_UNKNOWN 0 00060 #define OUTPUT_TYPE_PACHUBE 1 00061 #define OUTPUT_TYPE_MQTT 2 00062 #define OUTPUT_TYPE_EMONCMS 3 00063 #define OUTPUT_TYPE_SENSE 4 00064 00065 /** Routing definition for a reading 00066 * Input source, node ID, sensor ID, output 00067 * default is OuptutDef but casts to Pachube or MQTT 00068 */ 00069 typedef struct { 00070 short nodeId; 00071 short sensorId; 00072 float factor; 00073 byte outType; 00074 OutputDef *output; 00075 char *param1; 00076 char *param2; 00077 char *param3; 00078 char *param4; 00079 } __attribute__((packed)) PayloadRouting; 00080 00081 /** Node definition 00082 */ 00083 typedef struct { 00084 uint8_t groupId; 00085 uint8_t nodeId; 00086 uint8_t length; 00087 uint8_t type; 00088 } __attribute__((packed)) IoTNodeDef; 00089 00090 00091 /** Main IoT Gateway RFM12B payload routing class 00092 */ 00093 class IoTRouting { 00094 public: 00095 /** Default Constructor 00096 */ 00097 IoTRouting(); 00098 00099 /** Initialise routing class 00100 */ 00101 void initRouting(); 00102 00103 /** Write a list of nodes to IOTNODE.TXT 00104 * Format is: group,node,length,type 00105 * Where: 00106 * group, node, length are first 3 bytes of received packet 00107 * type is 99 for unknown, 0 for simple, 1 for Type 1, 2 for Type 2 00108 */ 00109 bool writeNodeList(); 00110 00111 /** Write main routing list to file IOTRTR.TXT 00112 * Format is: nodeId,sensorId,factor,outputType,param1,param2,param3,param4 00113 * Where: 00114 * nodeId is the Node ID of the node to the sensor is attached to 00115 * sensorId is the ID of the sensor to define 00116 * factor is a conversion factor to convert from integer to real value. can be 100.0,10.0,1.0,0.1,0.01,0.001. For no conversion use 1.0 00117 * outputType is the type of output, 1 is Pachube, 2 is MQTT 00118 * param1 is Pachube feed number or MQTT topic 00119 * param2 is Pachube datastream number 00120 * param3 and 4 are currently unused 00121 */ 00122 bool writeRoutingList(); 00123 00124 /** Add a node to the nodelist 00125 * 00126 * @param groupId Group ID, byte 0 of received packet 00127 * @param nodeId Node ID, byte 1 00128 * @param length Length of payload, byte 2 00129 * @param type Type of payload, simple, v1, v2 or undefined 00130 */ 00131 void addNodeToList(uint8_t groupId, uint8_t nodeId, uint8_t length, uint8_t type ); 00132 00133 /** Add an item to routing list 00134 * 00135 * @param nodeId ID of the node payload came from 00136 * @param sensorId ID of the sensor within the node 00137 * @param factor Sensor Reading conversion factor, 100, 10, 1, 0.1, 0.01, 0.001 etc 00138 * @param outType Output type, 1 = Pachube, 2 = MQTT, 3 = emonCMS, 4 = Sen.Se 00139 * @param param1 Parameter 1 00140 * @param param2 Parameter 2 00141 * @param param3 Parameter 3 00142 * @param param4 Parameter 4 00143 */ 00144 void addRoutingToList( short nodeId, short sensorId, float factor, byte outType, 00145 char *param1, char *param2, char *param3, char *param4 ); 00146 00147 /** get Payload type 00148 * 00149 * @param data Pointer to start of payload data 00150 * @param dataLen Length of payload data 00151 * @returns payload type, either simple, v1, v2 or unknown 00152 */ 00153 short getPayloadType( uint8_t *data, short dataLen ); 00154 00155 /** Get routing data for specified node/sensor combination 00156 * 00157 * @param nodeId The ID of the node 00158 * @param sensorNum The ID of the sensor 00159 * @returns pointer to routing data 00160 */ 00161 PayloadRouting* getRouting( short nodeId, short sensorNum ); 00162 00163 /** Add output definition to output list 00164 * 00165 * @param output Pointer to output object 00166 * @param outType Numeric value for the output type 00167 */ 00168 void addOutput( OutputDef *output, short outType ); 00169 00170 /** Main payload routing function 00171 * 00172 * @param payload Pointer to payload data 00173 * @param payloadLen Length of th epayload 00174 * @returns flag to indicate payload routed to output or not. 00175 */ 00176 bool routePayload( uint8_t *payload, short payloadLen ); 00177 00178 private: 00179 int sendCount; 00180 OutputDef *pachubeOutput; 00181 OutputDef *mqttOutput; 00182 OutputDef *emonCmsOutput; 00183 OutputDef *senSeOutput; 00184 00185 std::vector<PayloadRouting*> _routing; 00186 std::vector<IoTNodeDef*> _nodeDefList; 00187 00188 }; 00189 00190 #endif /* _IOTROUTING_H */
Generated on Tue Jul 12 2022 22:07:04 by
1.7.2