Core Base Classes for the Light Endpoints
Dependents: mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet ... more
MBEDToIOCResourceMap.cpp@25:2a001b4f7024, 2014-02-27 (annotated)
- Committer:
- ansond
- Date:
- Thu Feb 27 04:05:31 2014 +0000
- Revision:
- 25:2a001b4f7024
- Parent:
- 21:cfdaee0a2b50
- Child:
- 27:be7de89f3fa6
updates
Who changed what in which revision?
User | Revision | Line number | New 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 | 25:2a001b4f7024 | 36 | |
ansond | 25:2a001b4f7024 | 37 | // get the IOC equivalent resource name from the Endpoint resource name |
ansond | 25:2a001b4f7024 | 38 | char *MBEDToIOCResourceMap::endpointNameToIOCName(char *mbed_name) { |
ansond | 25:2a001b4f7024 | 39 | bool found = false; |
ansond | 25:2a001b4f7024 | 40 | char *ioc_name = NULL; |
ansond | 25:2a001b4f7024 | 41 | |
ansond | 25:2a001b4f7024 | 42 | // lookup the IOC name and map it to an MBED (NSP) name |
ansond | 25:2a001b4f7024 | 43 | for(int i=0;i<NUM_MAPPINGS && !found && this->m_map[i] != NULL;++i) { |
ansond | 25:2a001b4f7024 | 44 | if (strcmp(this->m_map[i]->mbedName(),mbed_name) == 0) { |
ansond | 25:2a001b4f7024 | 45 | found = true; |
ansond | 25:2a001b4f7024 | 46 | ioc_name = this->m_map[i]->iocName(); |
ansond | 25:2a001b4f7024 | 47 | } |
ansond | 25:2a001b4f7024 | 48 | } |
ansond | 25:2a001b4f7024 | 49 | return ioc_name; |
ansond | 25:2a001b4f7024 | 50 | } |
ansond | 10:62107616fc6c | 51 | |
ansond | 25:2a001b4f7024 | 52 | // get the Endpoint resource name from the IOC resource name given |
ansond | 25:2a001b4f7024 | 53 | char *MBEDToIOCResourceMap::iocNameToEndpointName(char *ioc_name) { |
ansond | 10:62107616fc6c | 54 | bool found = false; |
ansond | 10:62107616fc6c | 55 | char *mbed_name = NULL; |
ansond | 10:62107616fc6c | 56 | |
ansond | 21:cfdaee0a2b50 | 57 | // convert if we have a nickname |
ansond | 21:cfdaee0a2b50 | 58 | char *actual_ioc_name = this->convertFromNickName(ioc_name); |
ansond | 21:cfdaee0a2b50 | 59 | |
ansond | 21:cfdaee0a2b50 | 60 | // lookup the IOC name and map it to an MBED (NSP) name |
ansond | 20:f2dbbd852e08 | 61 | for(int i=0;i<NUM_MAPPINGS && !found && this->m_map[i] != NULL;++i) { |
ansond | 21:cfdaee0a2b50 | 62 | if (strcmp(this->m_map[i]->iocName(),actual_ioc_name) == 0) { |
ansond | 10:62107616fc6c | 63 | found = true; |
ansond | 11:f1c9299a3ca1 | 64 | mbed_name = this->m_map[i]->mbedName(); |
ansond | 10:62107616fc6c | 65 | } |
ansond | 10:62107616fc6c | 66 | } |
ansond | 10:62107616fc6c | 67 | return mbed_name; |
ansond | 10:62107616fc6c | 68 | } |
ansond | 10:62107616fc6c | 69 | |
ansond | 21:cfdaee0a2b50 | 70 | // convert from an IOC nickname to the actual IOC property name |
ansond | 21:cfdaee0a2b50 | 71 | char *MBEDToIOCResourceMap::convertFromNickName(char *ioc_name) { |
ansond | 21:cfdaee0a2b50 | 72 | char *actual_name = ioc_name; |
ansond | 21:cfdaee0a2b50 | 73 | bool found = false; |
ansond | 21:cfdaee0a2b50 | 74 | |
ansond | 21:cfdaee0a2b50 | 75 | for(int i=0;i<NUM_MAPPINGS && !found && this->m_map[i] != NULL;++i) { |
ansond | 21:cfdaee0a2b50 | 76 | if (strcmp(this->m_map[i]->iocNickName(),ioc_name) == 0) { |
ansond | 21:cfdaee0a2b50 | 77 | found = true; |
ansond | 21:cfdaee0a2b50 | 78 | actual_name = this->m_map[i]->iocName(); |
ansond | 21:cfdaee0a2b50 | 79 | } |
ansond | 21:cfdaee0a2b50 | 80 | } |
ansond | 21:cfdaee0a2b50 | 81 | |
ansond | 21:cfdaee0a2b50 | 82 | return actual_name; |
ansond | 21:cfdaee0a2b50 | 83 | } |
ansond | 21:cfdaee0a2b50 | 84 | |
ansond | 10:62107616fc6c | 85 | // create our map - this MUST match the Resource Mapping found in the gateway mapping database |
ansond | 10:62107616fc6c | 86 | void MBEDToIOCResourceMap::createMap() { |
ansond | 20:f2dbbd852e08 | 87 | int i = 0; |
ansond | 20:f2dbbd852e08 | 88 | this->m_map[i++] = new MapEntry("Property_1","/dev/addldata"); |
ansond | 20:f2dbbd852e08 | 89 | this->m_map[i++] = new MapEntry("Property_2","/dev/location"); |
ansond | 20:f2dbbd852e08 | 90 | this->m_map[i++] = new MapEntry("Property_3","/dev/bat"); |
ansond | 20:f2dbbd852e08 | 91 | this->m_map[i++] = new MapEntry("Property_4","/sen/I"); |
ansond | 20:f2dbbd852e08 | 92 | this->m_map[i++] = new MapEntry("Property_5","/nw/ipaddr"); |
ansond | 20:f2dbbd852e08 | 93 | this->m_map[i++] = new MapEntry("Property_6","/lt/0/dim","Dimming"); |
ansond | 20:f2dbbd852e08 | 94 | this->m_map[i++] = new MapEntry("Property_7","/nw/eripaddr"); |
ansond | 20:f2dbbd852e08 | 95 | this->m_map[i++] = new MapEntry("Property_8","/lt/0/on","EnpointStatus"); |
ansond | 20:f2dbbd852e08 | 96 | this->m_map[i++] = new MapEntry("Property_9","/dev/mdl"); |
ansond | 20:f2dbbd852e08 | 97 | this->m_map[i++] = new MapEntry("Property_10","/gps/int"); |
ansond | 20:f2dbbd852e08 | 98 | this->m_map[i++] = new MapEntry("Property_11","/gps/fix"); |
ansond | 20:f2dbbd852e08 | 99 | this->m_map[i++] = new MapEntry("Property_12","/nw/pipaddr"); |
ansond | 20:f2dbbd852e08 | 100 | this->m_map[i++] = new MapEntry("Property_13","/nw/prssi"); |
ansond | 20:f2dbbd852e08 | 101 | this->m_map[i++] = new MapEntry("Property_14","/sen/temp"); |
ansond | 20:f2dbbd852e08 | 102 | this->m_map[i++] = new MapEntry("Property_15","/sen/V"); |
ansond | 20:f2dbbd852e08 | 103 | this->m_map[i++] = new MapEntry("LOCATION","/gps/loc"); |
ansond | 20:f2dbbd852e08 | 104 | |
ansond | 20:f2dbbd852e08 | 105 | // DEBUG |
ansond | 20:f2dbbd852e08 | 106 | this->logger()->log("Installed %d Resource Mappings.",i); |
ansond | 10:62107616fc6c | 107 | } |