Core Base Classes for the Light Endpoints

Dependencies:   BufferedSerial

Dependents:   mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet ... more

Committer:
ansond
Date:
Wed Feb 26 18:59:01 2014 +0000
Revision:
20:f2dbbd852e08
Parent:
13:17feb3b34619
Child:
21:cfdaee0a2b50
removed splitter

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 10:62107616fc6c 1 /* Copyright C2013 Doug Anson, MIT License
ansond 10:62107616fc6c 2 *
ansond 10:62107616fc6c 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
ansond 10:62107616fc6c 4 * and associated documentation files the "Software", to deal in the Software without restriction,
ansond 10:62107616fc6c 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
ansond 10:62107616fc6c 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
ansond 10:62107616fc6c 7 * furnished to do so, subject to the following conditions:
ansond 10:62107616fc6c 8 *
ansond 10:62107616fc6c 9 * The above copyright notice and this permission notice shall be included in all copies or
ansond 10:62107616fc6c 10 * substantial portions of the Software.
ansond 10:62107616fc6c 11 *
ansond 10:62107616fc6c 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
ansond 10:62107616fc6c 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ansond 10:62107616fc6c 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
ansond 10:62107616fc6c 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ansond 10:62107616fc6c 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ansond 10:62107616fc6c 17 */
ansond 10:62107616fc6c 18
ansond 10:62107616fc6c 19 #include "MBEDToIOCResourceMap.h"
ansond 10:62107616fc6c 20
ansond 10:62107616fc6c 21 // default constructor
ansond 20:f2dbbd852e08 22 MBEDToIOCResourceMap::MBEDToIOCResourceMap(ErrorHandler *error_handler) {
ansond 20:f2dbbd852e08 23 this->m_error_handler = error_handler;
ansond 20:f2dbbd852e08 24 for(int i=0;i<NUM_MAPPINGS;++i) this->m_map[i] = NULL;
ansond 10:62107616fc6c 25 this->createMap();
ansond 10:62107616fc6c 26 }
ansond 10:62107616fc6c 27
ansond 10:62107616fc6c 28 // destructor
ansond 10:62107616fc6c 29 MBEDToIOCResourceMap::~MBEDToIOCResourceMap() {
ansond 20:f2dbbd852e08 30 for(int i=0;i<NUM_MAPPINGS;++i)
ansond 20:f2dbbd852e08 31 if (this->m_map[i] != NULL) delete this->m_map[i];
ansond 10:62107616fc6c 32 }
ansond 20:f2dbbd852e08 33
ansond 20:f2dbbd852e08 34 // get our error handler
ansond 20:f2dbbd852e08 35 ErrorHandler *MBEDToIOCResourceMap::logger() { return this->m_error_handler; }
ansond 10:62107616fc6c 36
ansond 10:62107616fc6c 37 // lookup MBED equivalent to IOC input
ansond 10:62107616fc6c 38 char *MBEDToIOCResourceMap::getMBEDMappedName(char *ioc_name) {
ansond 10:62107616fc6c 39 bool found = false;
ansond 10:62107616fc6c 40 char *mbed_name = NULL;
ansond 10:62107616fc6c 41
ansond 20:f2dbbd852e08 42 for(int i=0;i<NUM_MAPPINGS && !found && this->m_map[i] != NULL;++i) {
ansond 11:f1c9299a3ca1 43 if (strcmp(this->m_map[i]->iocName(),ioc_name) == 0) {
ansond 10:62107616fc6c 44 found = true;
ansond 11:f1c9299a3ca1 45 mbed_name = this->m_map[i]->mbedName();
ansond 10:62107616fc6c 46 }
ansond 10:62107616fc6c 47 }
ansond 10:62107616fc6c 48 return mbed_name;
ansond 10:62107616fc6c 49 }
ansond 10:62107616fc6c 50
ansond 10:62107616fc6c 51 // create our map - this MUST match the Resource Mapping found in the gateway mapping database
ansond 10:62107616fc6c 52 void MBEDToIOCResourceMap::createMap() {
ansond 20:f2dbbd852e08 53 int i = 0;
ansond 20:f2dbbd852e08 54 this->m_map[i++] = new MapEntry("Property_1","/dev/addldata");
ansond 20:f2dbbd852e08 55 this->m_map[i++] = new MapEntry("Property_2","/dev/location");
ansond 20:f2dbbd852e08 56 this->m_map[i++] = new MapEntry("Property_3","/dev/bat");
ansond 20:f2dbbd852e08 57 this->m_map[i++] = new MapEntry("Property_4","/sen/I");
ansond 20:f2dbbd852e08 58 this->m_map[i++] = new MapEntry("Property_5","/nw/ipaddr");
ansond 20:f2dbbd852e08 59 this->m_map[i++] = new MapEntry("Property_6","/lt/0/dim","Dimming");
ansond 20:f2dbbd852e08 60 this->m_map[i++] = new MapEntry("Property_7","/nw/eripaddr");
ansond 20:f2dbbd852e08 61 this->m_map[i++] = new MapEntry("Property_8","/lt/0/on","EnpointStatus");
ansond 20:f2dbbd852e08 62 this->m_map[i++] = new MapEntry("Property_9","/dev/mdl");
ansond 20:f2dbbd852e08 63 this->m_map[i++] = new MapEntry("Property_10","/gps/int");
ansond 20:f2dbbd852e08 64 this->m_map[i++] = new MapEntry("Property_11","/gps/fix");
ansond 20:f2dbbd852e08 65 this->m_map[i++] = new MapEntry("Property_12","/nw/pipaddr");
ansond 20:f2dbbd852e08 66 this->m_map[i++] = new MapEntry("Property_13","/nw/prssi");
ansond 20:f2dbbd852e08 67 this->m_map[i++] = new MapEntry("Property_14","/sen/temp");
ansond 20:f2dbbd852e08 68 this->m_map[i++] = new MapEntry("Property_15","/sen/V");
ansond 20:f2dbbd852e08 69 this->m_map[i++] = new MapEntry("LOCATION","/gps/loc");
ansond 20:f2dbbd852e08 70
ansond 20:f2dbbd852e08 71 // DEBUG
ansond 20:f2dbbd852e08 72 this->logger()->log("Installed %d Resource Mappings.",i);
ansond 10:62107616fc6c 73 }