Doug Anson / endpoint_mqtt

Dependents:   mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_mqtt_endpoint_nxp

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MBEDEndpoint.h Source File

MBEDEndpoint.h

00001 /* Copyright C2013 Doug Anson, MIT License
00002  *
00003  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00004  * and associated documentation files the "Software", to deal in the Software without restriction,
00005  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
00006  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
00007  * furnished to do so, subject to the following conditions:
00008  *
00009  * The above copyright notice and this permission notice shall be included in all copies or
00010  * substantial portions of the Software.
00011  *
00012  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00013  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00014  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00015  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00016  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00017  */
00018  
00019 #ifndef _MBED_ENDPOINT_H_
00020 #define _MBED_ENDPOINT_H_
00021 
00022 // BaseClass support
00023 #include "BaseClass.h"
00024 
00025 // MBED to IOC Resource Map
00026 #include "MBEDToIOCResourceMap.h"
00027 
00028 // Transport support
00029 #include "MQTTTransport.h"
00030 #include "IOCHTTPTransport.h"
00031 
00032 // IOC Endpoint support
00033 #include "IOCEndpoint.h"
00034 
00035 // Personality Support
00036 #include "Personality.h"
00037 
00038 // ResourceFactory Support
00039 #include "ResourceFactory.h"
00040 
00041 // Preferences Support
00042 #include "Preferences.h"
00043 
00044 // network selection
00045 #ifdef CELLULAR_NETWORK
00046     // Cellular
00047     #include "MBEDUbloxCellRadio.h"
00048     #include "MBEDUbloxGPS.h"
00049 #else
00050     // Ethernet
00051     #include "EthernetInterface.h"
00052 #endif
00053   
00054 class MBEDEndpoint : public BaseClass {
00055     private:
00056 #ifdef CELLULAR_NETWORK
00057         MBEDUbloxCellRadio   *m_cellular_modem;                            // cell modem
00058         MBEDUbloxGPS         *m_gps;                                       // GPS receiver
00059 #else
00060         EthernetInterface    *m_ethernet;                                  // ethernet interface
00061 #endif
00062         Transport            *m_transports[NUM_TRANSPORTS];                // our transport
00063         Personality          *m_personalities[NUM_PERSONALITY_INSTANCES];  // our personality instances (at least 1)
00064         char                  m_endpoint_name[PERSONALITY_NAME_LEN+1];     // our endpoint name (personality[0])
00065         MBEDToIOCResourceMap *m_map;                                       // IOC <--> MBED resource mapping
00066         Preferences          *m_preferences;                               // preference support
00067         char                  m_lcd_status[TEMP_BUFFER_LEN+1];             // LCD status buffer
00068         char                  m_gw_address[PREFERENCE_VALUE_LEN+1];        // GW address buffer
00069         char                  m_gw_port[PREFERENCE_VALUE_LEN+1];           // GW port buffer
00070         int                   m_instance_id;                               // instance ID for this endpoint
00071         void                 *m_status_reporter;                           // status reporter (optional)
00072          
00073     public:
00074         MBEDEndpoint(Logger *logger,void *transport,void *status_reporter,void *extra);
00075         virtual ~MBEDEndpoint();
00076         ResourceFactory *initResourceFactory();
00077         void run();
00078         
00079         int indexOfPersonality(char *name);
00080         ResourceFactory *getResources(int index);
00081         
00082         bool loadPersonalities();
00083         bool updatePersonalities();
00084         bool updatePersonality(int index);
00085         
00086         char *getEndpointName();
00087         char *getGWAddress();
00088         char *getGWPort();
00089         
00090         char *getLCDStatus();
00091         
00092         int getInstanceID();
00093                 
00094         MBEDToIOCResourceMap *getMap();
00095     
00096         Preferences *preferences();
00097          
00098         void extraEventLoopWork();
00099         
00100     protected:
00101     
00102     private:
00103         bool initializePersonalities();
00104         bool closePersonalities();
00105         
00106         ResourceFactory *initLightResourceFactory();
00107         bool initializeLights();
00108         
00109         void initPreferences();
00110         void initGWAddress();
00111         void initEndpointName();
00112         bool initializeTransport(int index,char *key,Transport *transport);
00113         bool initializeTransports();
00114         bool loadPersonality(Personality *instance);
00115         bool updatePersonality(Personality *instance);
00116         bool closeTransport(int index,char *key);
00117         bool closeTransports();
00118 
00119 #ifdef CELLULAR_NETWORK
00120         bool initializeCellularModem(void *modem);
00121         bool initializeGPSReceiver(void *gps);
00122         bool closeCellularModem();
00123         bool closeGPSReceiver();
00124 #else
00125         bool initializeEthernet(EthernetInterface *ethernet);
00126         bool closeEthernet();
00127 #endif 
00128 };
00129 
00130 #endif // _MBED_ENDPOINT_H_