mqtt specific components for the impact mbed endpoint library

Dependents:   mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_mqtt_endpoint_nxp

Committer:
ansond
Date:
Thu Mar 27 17:48:38 2014 +0000
Revision:
5:1ba6e68bf50e
Parent:
0:a3fc1c6ef150
Child:
6:2db2c7e75ad9
updates

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:a3fc1c6ef150 1 /* Copyright C2013 Doug Anson, MIT License
ansond 0:a3fc1c6ef150 2 *
ansond 0:a3fc1c6ef150 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
ansond 0:a3fc1c6ef150 4 * and associated documentation files the "Software", to deal in the Software without restriction,
ansond 0:a3fc1c6ef150 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
ansond 0:a3fc1c6ef150 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
ansond 0:a3fc1c6ef150 7 * furnished to do so, subject to the following conditions:
ansond 0:a3fc1c6ef150 8 *
ansond 0:a3fc1c6ef150 9 * The above copyright notice and this permission notice shall be included in all copies or
ansond 0:a3fc1c6ef150 10 * substantial portions of the Software.
ansond 0:a3fc1c6ef150 11 *
ansond 0:a3fc1c6ef150 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
ansond 0:a3fc1c6ef150 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ansond 0:a3fc1c6ef150 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
ansond 0:a3fc1c6ef150 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ansond 0:a3fc1c6ef150 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ansond 0:a3fc1c6ef150 17 */
ansond 0:a3fc1c6ef150 18
ansond 0:a3fc1c6ef150 19 #ifndef _MBED_ENDPOINT_H_
ansond 0:a3fc1c6ef150 20 #define _MBED_ENDPOINT_H_
ansond 0:a3fc1c6ef150 21
ansond 0:a3fc1c6ef150 22 // Ethernet Interface
ansond 0:a3fc1c6ef150 23 #include "EthernetInterface.h"
ansond 0:a3fc1c6ef150 24
ansond 0:a3fc1c6ef150 25 // ErrorHandler support
ansond 0:a3fc1c6ef150 26 #include "ErrorHandler.h"
ansond 0:a3fc1c6ef150 27
ansond 0:a3fc1c6ef150 28 // MBED to IOC Resource Map
ansond 0:a3fc1c6ef150 29 #include "MBEDToIOCResourceMap.h"
ansond 0:a3fc1c6ef150 30
ansond 0:a3fc1c6ef150 31 // Transport support
ansond 0:a3fc1c6ef150 32 #include "MQTTTransport.h"
ansond 0:a3fc1c6ef150 33 #include "IOCHTTPTransport.h"
ansond 0:a3fc1c6ef150 34
ansond 0:a3fc1c6ef150 35 // Light Support
ansond 0:a3fc1c6ef150 36 #include "Light.h"
ansond 0:a3fc1c6ef150 37
ansond 0:a3fc1c6ef150 38 // ResourceFactory Support
ansond 0:a3fc1c6ef150 39 #include "ResourceFactory.h"
ansond 0:a3fc1c6ef150 40
ansond 0:a3fc1c6ef150 41 // Preferences Support
ansond 0:a3fc1c6ef150 42 #include "Preferences.h"
ansond 0:a3fc1c6ef150 43
ansond 0:a3fc1c6ef150 44 class MBEDEndpoint {
ansond 0:a3fc1c6ef150 45 private:
ansond 0:a3fc1c6ef150 46 EthernetInterface *m_ethernet; // ethernet interface
ansond 0:a3fc1c6ef150 47 ErrorHandler *m_error_handler; // our error handler
ansond 0:a3fc1c6ef150 48 Transport *m_transports[NUM_TRANSPORTS]; // our transport
ansond 0:a3fc1c6ef150 49 Light *m_lights[NUM_LIGHTS]; // our lights (at least 1)
ansond 0:a3fc1c6ef150 50 char m_endpoint_name[LIGHT_NAME_LEN+1]; // our endpoint name (light[0])
ansond 0:a3fc1c6ef150 51 MBEDToIOCResourceMap *m_map; // IOC <--> MBED resource mapping
ansond 0:a3fc1c6ef150 52 Preferences *m_preferences; // preference support
ansond 0:a3fc1c6ef150 53 char m_lcd_status[TEMP_BUFFER_LEN+1]; // LCD status buffer
ansond 0:a3fc1c6ef150 54 char m_gw_address[PREFERENCE_VALUE_LEN+1]; // GW address buffer
ansond 0:a3fc1c6ef150 55 int m_instance_id; // instance ID for this endpoint
ansond 0:a3fc1c6ef150 56
ansond 0:a3fc1c6ef150 57 public:
ansond 0:a3fc1c6ef150 58 MBEDEndpoint(ErrorHandler *error_handler,EthernetInterface *ethernet);
ansond 0:a3fc1c6ef150 59 ~MBEDEndpoint();
ansond 0:a3fc1c6ef150 60 ResourceFactory *initResourceFactory();
ansond 0:a3fc1c6ef150 61 void run();
ansond 0:a3fc1c6ef150 62
ansond 0:a3fc1c6ef150 63 int indexOfLight(char *name);
ansond 0:a3fc1c6ef150 64 ResourceFactory *getResources(int index);
ansond 0:a3fc1c6ef150 65
ansond 0:a3fc1c6ef150 66 bool loadEndpoints();
ansond 0:a3fc1c6ef150 67 bool updateEndpoints();
ansond 0:a3fc1c6ef150 68 bool updateEndpoints(int index);
ansond 0:a3fc1c6ef150 69
ansond 0:a3fc1c6ef150 70 char *getEndpointName();
ansond 0:a3fc1c6ef150 71 char *getGWAddress();
ansond 0:a3fc1c6ef150 72 Preferences *preferences();
ansond 0:a3fc1c6ef150 73
ansond 0:a3fc1c6ef150 74 char *getLCDStatus();
ansond 0:a3fc1c6ef150 75
ansond 0:a3fc1c6ef150 76 int getInstanceID();
ansond 0:a3fc1c6ef150 77
ansond 0:a3fc1c6ef150 78 MBEDToIOCResourceMap *getMap();
ansond 0:a3fc1c6ef150 79
ansond 0:a3fc1c6ef150 80 protected:
ansond 0:a3fc1c6ef150 81
ansond 0:a3fc1c6ef150 82 private:
ansond 5:1ba6e68bf50e 83 bool initializeEndpointPersonality();
ansond 5:1ba6e68bf50e 84 bool closeEndpointPersonality();
ansond 5:1ba6e68bf50e 85
ansond 5:1ba6e68bf50e 86 ResourceFactory *initLightResourceFactory();
ansond 0:a3fc1c6ef150 87 void initPreferences();
ansond 0:a3fc1c6ef150 88 void initGWAddress();
ansond 0:a3fc1c6ef150 89 void initEndpointName();
ansond 0:a3fc1c6ef150 90 bool initializeLights();
ansond 0:a3fc1c6ef150 91 bool initializeTransport(int index,char *key,Transport *transport);
ansond 0:a3fc1c6ef150 92 bool initializeTransports();
ansond 0:a3fc1c6ef150 93 bool initializeEthernet(EthernetInterface *ethernet);
ansond 0:a3fc1c6ef150 94 bool loadEndpoint(Light *light);
ansond 0:a3fc1c6ef150 95 bool updateEndpoint(Light *light);
ansond 0:a3fc1c6ef150 96 char *buildIOCPayload(char *data,int data_length,Light *light);
ansond 0:a3fc1c6ef150 97 void saveIOCID(Light *light,char *data);
ansond 0:a3fc1c6ef150 98 bool closeLights();
ansond 0:a3fc1c6ef150 99 bool closeTransport(int index,char *key);
ansond 0:a3fc1c6ef150 100 bool closeTransports();
ansond 0:a3fc1c6ef150 101 bool closeEthernet();
ansond 0:a3fc1c6ef150 102 ErrorHandler *logger();
ansond 0:a3fc1c6ef150 103 int min(int value1, int value2);
ansond 0:a3fc1c6ef150 104 };
ansond 0:a3fc1c6ef150 105
ansond 0:a3fc1c6ef150 106 #endif // _MBED_ENDPOINT_H_