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@192:54b758a8eaaa, 2014-09-26 (annotated)
- Committer:
- ansond
- Date:
- Fri Sep 26 05:16:07 2014 +0000
- Revision:
- 192:54b758a8eaaa
- Parent:
- 156:6fb77af2c6a5
updates to new logger name
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 | 192:54b758a8eaaa | 22 | MBEDToIOCResourceMap::MBEDToIOCResourceMap(Logger *logger) : BaseClass(logger,NULL) { |
ansond | 20:f2dbbd852e08 | 23 | for(int i=0;i<NUM_MAPPINGS;++i) this->m_map[i] = NULL; |
ansond | 47:fa96ddc36f04 | 24 | this->m_count = 0; |
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 | 47:fa96ddc36f04 | 30 | for(int i=0;i<this->m_count;++i) |
ansond | 20:f2dbbd852e08 | 31 | if (this->m_map[i] != NULL) delete this->m_map[i]; |
ansond | 10:62107616fc6c | 32 | } |
ansond | 135:7f3f963cd159 | 33 | |
ansond | 25:2a001b4f7024 | 34 | // get the IOC equivalent resource name from the Endpoint resource name |
ansond | 25:2a001b4f7024 | 35 | char *MBEDToIOCResourceMap::endpointNameToIOCName(char *mbed_name) { |
ansond | 25:2a001b4f7024 | 36 | bool found = false; |
ansond | 25:2a001b4f7024 | 37 | char *ioc_name = NULL; |
ansond | 25:2a001b4f7024 | 38 | |
ansond | 25:2a001b4f7024 | 39 | // lookup the IOC name and map it to an MBED (NSP) name |
ansond | 47:fa96ddc36f04 | 40 | for(int i=0;i<this->m_count && !found && this->m_map[i] != NULL && mbed_name != NULL;++i) { |
ansond | 25:2a001b4f7024 | 41 | if (strcmp(this->m_map[i]->mbedName(),mbed_name) == 0) { |
ansond | 25:2a001b4f7024 | 42 | found = true; |
ansond | 25:2a001b4f7024 | 43 | ioc_name = this->m_map[i]->iocName(); |
ansond | 25:2a001b4f7024 | 44 | } |
ansond | 25:2a001b4f7024 | 45 | } |
ansond | 25:2a001b4f7024 | 46 | return ioc_name; |
ansond | 25:2a001b4f7024 | 47 | } |
ansond | 10:62107616fc6c | 48 | |
ansond | 25:2a001b4f7024 | 49 | // get the Endpoint resource name from the IOC resource name given |
ansond | 25:2a001b4f7024 | 50 | char *MBEDToIOCResourceMap::iocNameToEndpointName(char *ioc_name) { |
ansond | 10:62107616fc6c | 51 | bool found = false; |
ansond | 10:62107616fc6c | 52 | char *mbed_name = NULL; |
ansond | 10:62107616fc6c | 53 | |
ansond | 21:cfdaee0a2b50 | 54 | // convert if we have a nickname |
ansond | 21:cfdaee0a2b50 | 55 | char *actual_ioc_name = this->convertFromNickName(ioc_name); |
ansond | 21:cfdaee0a2b50 | 56 | |
ansond | 21:cfdaee0a2b50 | 57 | // lookup the IOC name and map it to an MBED (NSP) name |
ansond | 47:fa96ddc36f04 | 58 | for(int i=0;i<this->m_count && !found && this->m_map[i] != NULL && ioc_name != NULL;++i) { |
ansond | 21:cfdaee0a2b50 | 59 | if (strcmp(this->m_map[i]->iocName(),actual_ioc_name) == 0) { |
ansond | 10:62107616fc6c | 60 | found = true; |
ansond | 11:f1c9299a3ca1 | 61 | mbed_name = this->m_map[i]->mbedName(); |
ansond | 10:62107616fc6c | 62 | } |
ansond | 10:62107616fc6c | 63 | } |
ansond | 10:62107616fc6c | 64 | return mbed_name; |
ansond | 10:62107616fc6c | 65 | } |
ansond | 10:62107616fc6c | 66 | |
ansond | 21:cfdaee0a2b50 | 67 | // convert from an IOC nickname to the actual IOC property name |
ansond | 21:cfdaee0a2b50 | 68 | char *MBEDToIOCResourceMap::convertFromNickName(char *ioc_name) { |
ansond | 21:cfdaee0a2b50 | 69 | char *actual_name = ioc_name; |
ansond | 21:cfdaee0a2b50 | 70 | bool found = false; |
ansond | 21:cfdaee0a2b50 | 71 | |
ansond | 47:fa96ddc36f04 | 72 | for(int i=0;i<this->m_count && !found && this->m_map[i] != NULL && ioc_name != NULL;++i) { |
ansond | 47:fa96ddc36f04 | 73 | if (this->m_map[i]->iocNickName() != NULL && strcmp(this->m_map[i]->iocNickName(),ioc_name) == 0) { |
ansond | 21:cfdaee0a2b50 | 74 | found = true; |
ansond | 21:cfdaee0a2b50 | 75 | actual_name = this->m_map[i]->iocName(); |
ansond | 21:cfdaee0a2b50 | 76 | } |
ansond | 21:cfdaee0a2b50 | 77 | } |
ansond | 21:cfdaee0a2b50 | 78 | |
ansond | 21:cfdaee0a2b50 | 79 | return actual_name; |
ansond | 21:cfdaee0a2b50 | 80 | } |
ansond | 21:cfdaee0a2b50 | 81 | |
ansond | 10:62107616fc6c | 82 | // create our map - this MUST match the Resource Mapping found in the gateway mapping database |
ansond | 10:62107616fc6c | 83 | void MBEDToIOCResourceMap::createMap() { |
ansond | 47:fa96ddc36f04 | 84 | this->m_map[this->m_count++] = new MapEntry("Property_1","/dev/addldata"); |
ansond | 47:fa96ddc36f04 | 85 | this->m_map[this->m_count++] = new MapEntry("Property_2","/dev/location"); |
ansond | 47:fa96ddc36f04 | 86 | this->m_map[this->m_count++] = new MapEntry("Property_3","/dev/bat"); |
ansond | 47:fa96ddc36f04 | 87 | this->m_map[this->m_count++] = new MapEntry("Property_4","/sen/I"); |
ansond | 47:fa96ddc36f04 | 88 | this->m_map[this->m_count++] = new MapEntry("Property_5","/nw/ipaddr"); |
ansond | 47:fa96ddc36f04 | 89 | this->m_map[this->m_count++] = new MapEntry("Property_6","/lt/0/dim","Dimming"); |
ansond | 47:fa96ddc36f04 | 90 | this->m_map[this->m_count++] = new MapEntry("Property_7","/nw/eripaddr"); |
ansond | 156:6fb77af2c6a5 | 91 | this->m_map[this->m_count++] = new MapEntry("Property_8","/lt/0/on","EndpointState"); |
ansond | 47:fa96ddc36f04 | 92 | this->m_map[this->m_count++] = new MapEntry("Property_9","/dev/mdl"); |
ansond | 47:fa96ddc36f04 | 93 | this->m_map[this->m_count++] = new MapEntry("Property_10","/gps/int"); |
ansond | 47:fa96ddc36f04 | 94 | this->m_map[this->m_count++] = new MapEntry("Property_11","/gps/fix"); |
ansond | 88:6a6d0b8751cb | 95 | this->m_map[this->m_count++] = new MapEntry("Property_12","/dev/panic","Panic"); |
ansond | 85:8af3f3101ba3 | 96 | this->m_map[this->m_count++] = new MapEntry("Property_13","/nw/pipaddr"); |
ansond | 85:8af3f3101ba3 | 97 | this->m_map[this->m_count++] = new MapEntry("Property_14","/nw/prssi"); |
ansond | 85:8af3f3101ba3 | 98 | this->m_map[this->m_count++] = new MapEntry("Property_15","/sen/temp"); |
ansond | 85:8af3f3101ba3 | 99 | this->m_map[this->m_count++] = new MapEntry("Property_16","/sen/V"); |
ansond | 47:fa96ddc36f04 | 100 | this->m_map[this->m_count++] = new MapEntry("LOCATION","/gps/loc"); |
ansond | 20:f2dbbd852e08 | 101 | |
ansond | 20:f2dbbd852e08 | 102 | // DEBUG |
ansond | 47:fa96ddc36f04 | 103 | this->logger()->log("Installed %d Resource Mappings.",this->m_count); |
ansond | 10:62107616fc6c | 104 | } |