mbed client lightswitch demo
Dependencies: mbed Socket lwip-eth lwip-sys lwip
Fork of mbed-client-classic-example-lwip by
mbed-client/source/m2mdevice.cpp@11:cada08fc8a70, 2016-06-09 (annotated)
- Committer:
- mbedAustin
- Date:
- Thu Jun 09 17:08:36 2016 +0000
- Revision:
- 11:cada08fc8a70
Commit for public Consumption
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedAustin | 11:cada08fc8a70 | 1 | /* |
mbedAustin | 11:cada08fc8a70 | 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. |
mbedAustin | 11:cada08fc8a70 | 3 | * SPDX-License-Identifier: Apache-2.0 |
mbedAustin | 11:cada08fc8a70 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
mbedAustin | 11:cada08fc8a70 | 5 | * not use this file except in compliance with the License. |
mbedAustin | 11:cada08fc8a70 | 6 | * You may obtain a copy of the License at |
mbedAustin | 11:cada08fc8a70 | 7 | * |
mbedAustin | 11:cada08fc8a70 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbedAustin | 11:cada08fc8a70 | 9 | * |
mbedAustin | 11:cada08fc8a70 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbedAustin | 11:cada08fc8a70 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
mbedAustin | 11:cada08fc8a70 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbedAustin | 11:cada08fc8a70 | 13 | * See the License for the specific language governing permissions and |
mbedAustin | 11:cada08fc8a70 | 14 | * limitations under the License. |
mbedAustin | 11:cada08fc8a70 | 15 | */ |
mbedAustin | 11:cada08fc8a70 | 16 | #include <cstdio> |
mbedAustin | 11:cada08fc8a70 | 17 | #include "mbed-client/m2mdevice.h" |
mbedAustin | 11:cada08fc8a70 | 18 | #include "mbed-client/m2mconstants.h" |
mbedAustin | 11:cada08fc8a70 | 19 | #include "mbed-client/m2mobject.h" |
mbedAustin | 11:cada08fc8a70 | 20 | #include "mbed-client/m2mobjectinstance.h" |
mbedAustin | 11:cada08fc8a70 | 21 | #include "mbed-client/m2mresource.h" |
mbedAustin | 11:cada08fc8a70 | 22 | #include "ns_trace.h" |
mbedAustin | 11:cada08fc8a70 | 23 | |
mbedAustin | 11:cada08fc8a70 | 24 | M2MDevice* M2MDevice::_instance = NULL; |
mbedAustin | 11:cada08fc8a70 | 25 | |
mbedAustin | 11:cada08fc8a70 | 26 | M2MDevice* M2MDevice::get_instance() |
mbedAustin | 11:cada08fc8a70 | 27 | { |
mbedAustin | 11:cada08fc8a70 | 28 | if(_instance == NULL) { |
mbedAustin | 11:cada08fc8a70 | 29 | _instance = new M2MDevice(); |
mbedAustin | 11:cada08fc8a70 | 30 | } |
mbedAustin | 11:cada08fc8a70 | 31 | return _instance; |
mbedAustin | 11:cada08fc8a70 | 32 | } |
mbedAustin | 11:cada08fc8a70 | 33 | |
mbedAustin | 11:cada08fc8a70 | 34 | void M2MDevice::delete_instance() |
mbedAustin | 11:cada08fc8a70 | 35 | { |
mbedAustin | 11:cada08fc8a70 | 36 | if(_instance) { |
mbedAustin | 11:cada08fc8a70 | 37 | delete _instance; |
mbedAustin | 11:cada08fc8a70 | 38 | _instance = NULL; |
mbedAustin | 11:cada08fc8a70 | 39 | } |
mbedAustin | 11:cada08fc8a70 | 40 | } |
mbedAustin | 11:cada08fc8a70 | 41 | |
mbedAustin | 11:cada08fc8a70 | 42 | M2MDevice::M2MDevice() |
mbedAustin | 11:cada08fc8a70 | 43 | : M2MObject(M2M_DEVICE_ID) |
mbedAustin | 11:cada08fc8a70 | 44 | { |
mbedAustin | 11:cada08fc8a70 | 45 | _device_instance = M2MObject::create_object_instance(); |
mbedAustin | 11:cada08fc8a70 | 46 | |
mbedAustin | 11:cada08fc8a70 | 47 | if(_device_instance) { |
mbedAustin | 11:cada08fc8a70 | 48 | _device_instance->set_coap_content_type(COAP_CONTENT_OMA_TLV_TYPE); |
mbedAustin | 11:cada08fc8a70 | 49 | |
mbedAustin | 11:cada08fc8a70 | 50 | M2MResource* res = _device_instance->create_dynamic_resource(DEVICE_REBOOT, |
mbedAustin | 11:cada08fc8a70 | 51 | OMA_RESOURCE_TYPE, |
mbedAustin | 11:cada08fc8a70 | 52 | M2MResourceInstance::OPAQUE, |
mbedAustin | 11:cada08fc8a70 | 53 | false); |
mbedAustin | 11:cada08fc8a70 | 54 | if(res) { |
mbedAustin | 11:cada08fc8a70 | 55 | res->set_operation(M2MBase::POST_ALLOWED); |
mbedAustin | 11:cada08fc8a70 | 56 | } |
mbedAustin | 11:cada08fc8a70 | 57 | |
mbedAustin | 11:cada08fc8a70 | 58 | M2MResourceInstance* instance = _device_instance->create_dynamic_resource_instance(DEVICE_ERROR_CODE, |
mbedAustin | 11:cada08fc8a70 | 59 | OMA_RESOURCE_TYPE, |
mbedAustin | 11:cada08fc8a70 | 60 | M2MResourceInstance::INTEGER, |
mbedAustin | 11:cada08fc8a70 | 61 | false,0); |
mbedAustin | 11:cada08fc8a70 | 62 | if(instance) { |
mbedAustin | 11:cada08fc8a70 | 63 | instance->set_operation(M2MBase::GET_ALLOWED); |
mbedAustin | 11:cada08fc8a70 | 64 | instance->set_value((const uint8_t*)ERROR_CODE_VALUE.c_str(), |
mbedAustin | 11:cada08fc8a70 | 65 | (uint32_t)ERROR_CODE_VALUE.length()); |
mbedAustin | 11:cada08fc8a70 | 66 | } |
mbedAustin | 11:cada08fc8a70 | 67 | res = _device_instance->create_dynamic_resource(DEVICE_SUPPORTED_BINDING_MODE, |
mbedAustin | 11:cada08fc8a70 | 68 | OMA_RESOURCE_TYPE, |
mbedAustin | 11:cada08fc8a70 | 69 | M2MResourceInstance::STRING, |
mbedAustin | 11:cada08fc8a70 | 70 | false); |
mbedAustin | 11:cada08fc8a70 | 71 | if(res) { |
mbedAustin | 11:cada08fc8a70 | 72 | res->set_operation(M2MBase::GET_ALLOWED); |
mbedAustin | 11:cada08fc8a70 | 73 | res->set_value((const uint8_t*)BINDING_MODE_UDP.c_str(), |
mbedAustin | 11:cada08fc8a70 | 74 | (uint32_t)BINDING_MODE_UDP.length()); |
mbedAustin | 11:cada08fc8a70 | 75 | } |
mbedAustin | 11:cada08fc8a70 | 76 | } |
mbedAustin | 11:cada08fc8a70 | 77 | } |
mbedAustin | 11:cada08fc8a70 | 78 | |
mbedAustin | 11:cada08fc8a70 | 79 | M2MDevice::~M2MDevice() |
mbedAustin | 11:cada08fc8a70 | 80 | { |
mbedAustin | 11:cada08fc8a70 | 81 | } |
mbedAustin | 11:cada08fc8a70 | 82 | |
mbedAustin | 11:cada08fc8a70 | 83 | M2MResource* M2MDevice::create_resource(DeviceResource resource, const String &value) |
mbedAustin | 11:cada08fc8a70 | 84 | { |
mbedAustin | 11:cada08fc8a70 | 85 | M2MResource* res = NULL; |
mbedAustin | 11:cada08fc8a70 | 86 | String device_id = ""; |
mbedAustin | 11:cada08fc8a70 | 87 | M2MBase::Operation operation = M2MBase::GET_ALLOWED; |
mbedAustin | 11:cada08fc8a70 | 88 | if(!is_resource_present(resource) && value.size() <= MAX_ALLOWED_STRING_LENGTH) { |
mbedAustin | 11:cada08fc8a70 | 89 | switch(resource) { |
mbedAustin | 11:cada08fc8a70 | 90 | case Manufacturer: |
mbedAustin | 11:cada08fc8a70 | 91 | device_id = DEVICE_MANUFACTURER; |
mbedAustin | 11:cada08fc8a70 | 92 | break; |
mbedAustin | 11:cada08fc8a70 | 93 | case DeviceType: |
mbedAustin | 11:cada08fc8a70 | 94 | device_id = DEVICE_DEVICE_TYPE; |
mbedAustin | 11:cada08fc8a70 | 95 | break; |
mbedAustin | 11:cada08fc8a70 | 96 | case ModelNumber: |
mbedAustin | 11:cada08fc8a70 | 97 | device_id = DEVICE_MODEL_NUMBER; |
mbedAustin | 11:cada08fc8a70 | 98 | break; |
mbedAustin | 11:cada08fc8a70 | 99 | case SerialNumber: |
mbedAustin | 11:cada08fc8a70 | 100 | device_id = DEVICE_SERIAL_NUMBER; |
mbedAustin | 11:cada08fc8a70 | 101 | break; |
mbedAustin | 11:cada08fc8a70 | 102 | case HardwareVersion: |
mbedAustin | 11:cada08fc8a70 | 103 | device_id = DEVICE_HARDWARE_VERSION; |
mbedAustin | 11:cada08fc8a70 | 104 | break; |
mbedAustin | 11:cada08fc8a70 | 105 | case FirmwareVersion: |
mbedAustin | 11:cada08fc8a70 | 106 | device_id = DEVICE_FIRMWARE_VERSION; |
mbedAustin | 11:cada08fc8a70 | 107 | break; |
mbedAustin | 11:cada08fc8a70 | 108 | case SoftwareVersion: |
mbedAustin | 11:cada08fc8a70 | 109 | device_id = DEVICE_SOFTWARE_VERSION; |
mbedAustin | 11:cada08fc8a70 | 110 | break; |
mbedAustin | 11:cada08fc8a70 | 111 | case UTCOffset: |
mbedAustin | 11:cada08fc8a70 | 112 | device_id = DEVICE_UTC_OFFSET; |
mbedAustin | 11:cada08fc8a70 | 113 | operation = M2MBase::GET_PUT_ALLOWED; |
mbedAustin | 11:cada08fc8a70 | 114 | break; |
mbedAustin | 11:cada08fc8a70 | 115 | case Timezone: |
mbedAustin | 11:cada08fc8a70 | 116 | device_id = DEVICE_TIMEZONE; |
mbedAustin | 11:cada08fc8a70 | 117 | operation = M2MBase::GET_PUT_ALLOWED; |
mbedAustin | 11:cada08fc8a70 | 118 | break; |
mbedAustin | 11:cada08fc8a70 | 119 | default: |
mbedAustin | 11:cada08fc8a70 | 120 | break; |
mbedAustin | 11:cada08fc8a70 | 121 | } |
mbedAustin | 11:cada08fc8a70 | 122 | } |
mbedAustin | 11:cada08fc8a70 | 123 | if(!device_id.empty()) { |
mbedAustin | 11:cada08fc8a70 | 124 | if(_device_instance) { |
mbedAustin | 11:cada08fc8a70 | 125 | res = _device_instance->create_dynamic_resource(device_id, |
mbedAustin | 11:cada08fc8a70 | 126 | OMA_RESOURCE_TYPE, |
mbedAustin | 11:cada08fc8a70 | 127 | M2MResourceInstance::STRING, |
mbedAustin | 11:cada08fc8a70 | 128 | false); |
mbedAustin | 11:cada08fc8a70 | 129 | |
mbedAustin | 11:cada08fc8a70 | 130 | if(res ) { |
mbedAustin | 11:cada08fc8a70 | 131 | res->set_operation(operation); |
mbedAustin | 11:cada08fc8a70 | 132 | if (value.empty()) { |
mbedAustin | 11:cada08fc8a70 | 133 | res->clear_value(); |
mbedAustin | 11:cada08fc8a70 | 134 | } else { |
mbedAustin | 11:cada08fc8a70 | 135 | res->set_value((const uint8_t*)value.c_str(), |
mbedAustin | 11:cada08fc8a70 | 136 | (uint32_t)value.length()); |
mbedAustin | 11:cada08fc8a70 | 137 | } |
mbedAustin | 11:cada08fc8a70 | 138 | } |
mbedAustin | 11:cada08fc8a70 | 139 | } |
mbedAustin | 11:cada08fc8a70 | 140 | } |
mbedAustin | 11:cada08fc8a70 | 141 | return res; |
mbedAustin | 11:cada08fc8a70 | 142 | } |
mbedAustin | 11:cada08fc8a70 | 143 | |
mbedAustin | 11:cada08fc8a70 | 144 | M2MResource* M2MDevice::create_resource(DeviceResource resource, int64_t value) |
mbedAustin | 11:cada08fc8a70 | 145 | { |
mbedAustin | 11:cada08fc8a70 | 146 | M2MResource* res = NULL; |
mbedAustin | 11:cada08fc8a70 | 147 | String device_id = ""; |
mbedAustin | 11:cada08fc8a70 | 148 | M2MBase::Operation operation = M2MBase::GET_ALLOWED; |
mbedAustin | 11:cada08fc8a70 | 149 | if(!is_resource_present(resource)) { |
mbedAustin | 11:cada08fc8a70 | 150 | switch(resource) { |
mbedAustin | 11:cada08fc8a70 | 151 | case BatteryLevel: |
mbedAustin | 11:cada08fc8a70 | 152 | if(check_value_range(resource, value)) { |
mbedAustin | 11:cada08fc8a70 | 153 | device_id = DEVICE_BATTERY_LEVEL; |
mbedAustin | 11:cada08fc8a70 | 154 | } |
mbedAustin | 11:cada08fc8a70 | 155 | break; |
mbedAustin | 11:cada08fc8a70 | 156 | case BatteryStatus: |
mbedAustin | 11:cada08fc8a70 | 157 | if(check_value_range(resource, value)) { |
mbedAustin | 11:cada08fc8a70 | 158 | device_id = DEVICE_BATTERY_STATUS; |
mbedAustin | 11:cada08fc8a70 | 159 | } |
mbedAustin | 11:cada08fc8a70 | 160 | break; |
mbedAustin | 11:cada08fc8a70 | 161 | case MemoryFree: |
mbedAustin | 11:cada08fc8a70 | 162 | device_id = DEVICE_MEMORY_FREE; |
mbedAustin | 11:cada08fc8a70 | 163 | break; |
mbedAustin | 11:cada08fc8a70 | 164 | case MemoryTotal: |
mbedAustin | 11:cada08fc8a70 | 165 | device_id = DEVICE_MEMORY_TOTAL; |
mbedAustin | 11:cada08fc8a70 | 166 | break; |
mbedAustin | 11:cada08fc8a70 | 167 | case CurrentTime: |
mbedAustin | 11:cada08fc8a70 | 168 | device_id = DEVICE_CURRENT_TIME; |
mbedAustin | 11:cada08fc8a70 | 169 | operation = M2MBase::GET_PUT_ALLOWED; |
mbedAustin | 11:cada08fc8a70 | 170 | break; |
mbedAustin | 11:cada08fc8a70 | 171 | default: |
mbedAustin | 11:cada08fc8a70 | 172 | break; |
mbedAustin | 11:cada08fc8a70 | 173 | } |
mbedAustin | 11:cada08fc8a70 | 174 | } |
mbedAustin | 11:cada08fc8a70 | 175 | if(!device_id.empty()) { |
mbedAustin | 11:cada08fc8a70 | 176 | if(_device_instance) { |
mbedAustin | 11:cada08fc8a70 | 177 | res = _device_instance->create_dynamic_resource(device_id, |
mbedAustin | 11:cada08fc8a70 | 178 | OMA_RESOURCE_TYPE, |
mbedAustin | 11:cada08fc8a70 | 179 | M2MResourceInstance::INTEGER, |
mbedAustin | 11:cada08fc8a70 | 180 | false); |
mbedAustin | 11:cada08fc8a70 | 181 | |
mbedAustin | 11:cada08fc8a70 | 182 | if(res) { |
mbedAustin | 11:cada08fc8a70 | 183 | char *buffer = (char*)memory_alloc(20); |
mbedAustin | 11:cada08fc8a70 | 184 | if(buffer) { |
mbedAustin | 11:cada08fc8a70 | 185 | int size = snprintf(buffer, 20,"%lld", (long long int)value); |
mbedAustin | 11:cada08fc8a70 | 186 | res->set_operation(operation); |
mbedAustin | 11:cada08fc8a70 | 187 | res->set_value((const uint8_t*)buffer, |
mbedAustin | 11:cada08fc8a70 | 188 | (uint32_t)size); |
mbedAustin | 11:cada08fc8a70 | 189 | memory_free(buffer); |
mbedAustin | 11:cada08fc8a70 | 190 | } |
mbedAustin | 11:cada08fc8a70 | 191 | } |
mbedAustin | 11:cada08fc8a70 | 192 | } |
mbedAustin | 11:cada08fc8a70 | 193 | } |
mbedAustin | 11:cada08fc8a70 | 194 | return res; |
mbedAustin | 11:cada08fc8a70 | 195 | } |
mbedAustin | 11:cada08fc8a70 | 196 | |
mbedAustin | 11:cada08fc8a70 | 197 | M2MResourceInstance* M2MDevice::create_resource_instance(DeviceResource resource, int64_t value, |
mbedAustin | 11:cada08fc8a70 | 198 | uint16_t instance_id) |
mbedAustin | 11:cada08fc8a70 | 199 | { |
mbedAustin | 11:cada08fc8a70 | 200 | M2MResourceInstance* res = NULL; |
mbedAustin | 11:cada08fc8a70 | 201 | String device_id = ""; |
mbedAustin | 11:cada08fc8a70 | 202 | // For these resources multiple instance can exist |
mbedAustin | 11:cada08fc8a70 | 203 | if(AvailablePowerSources == resource) { |
mbedAustin | 11:cada08fc8a70 | 204 | if(check_value_range(resource, value)) { |
mbedAustin | 11:cada08fc8a70 | 205 | device_id = DEVICE_AVAILABLE_POWER_SOURCES; |
mbedAustin | 11:cada08fc8a70 | 206 | } |
mbedAustin | 11:cada08fc8a70 | 207 | } else if(PowerSourceVoltage == resource) { |
mbedAustin | 11:cada08fc8a70 | 208 | device_id = DEVICE_POWER_SOURCE_VOLTAGE; |
mbedAustin | 11:cada08fc8a70 | 209 | } else if(PowerSourceCurrent == resource) { |
mbedAustin | 11:cada08fc8a70 | 210 | device_id = DEVICE_POWER_SOURCE_CURRENT; |
mbedAustin | 11:cada08fc8a70 | 211 | } else if(ErrorCode == resource) { |
mbedAustin | 11:cada08fc8a70 | 212 | if(check_value_range(resource, value)) { |
mbedAustin | 11:cada08fc8a70 | 213 | device_id = DEVICE_ERROR_CODE; |
mbedAustin | 11:cada08fc8a70 | 214 | } |
mbedAustin | 11:cada08fc8a70 | 215 | } |
mbedAustin | 11:cada08fc8a70 | 216 | |
mbedAustin | 11:cada08fc8a70 | 217 | if(!device_id.empty()) { |
mbedAustin | 11:cada08fc8a70 | 218 | if(_device_instance) { |
mbedAustin | 11:cada08fc8a70 | 219 | res = _device_instance->create_dynamic_resource_instance(device_id,OMA_RESOURCE_TYPE, |
mbedAustin | 11:cada08fc8a70 | 220 | M2MResourceInstance::INTEGER, |
mbedAustin | 11:cada08fc8a70 | 221 | false, instance_id); |
mbedAustin | 11:cada08fc8a70 | 222 | |
mbedAustin | 11:cada08fc8a70 | 223 | if(res) { |
mbedAustin | 11:cada08fc8a70 | 224 | char *buffer = (char*)memory_alloc(20); |
mbedAustin | 11:cada08fc8a70 | 225 | if(buffer) { |
mbedAustin | 11:cada08fc8a70 | 226 | int size = snprintf(buffer, 20,"%lld", (long long int)value); |
mbedAustin | 11:cada08fc8a70 | 227 | // Only read operation is allowed for above resources |
mbedAustin | 11:cada08fc8a70 | 228 | res->set_operation(M2MBase::GET_ALLOWED); |
mbedAustin | 11:cada08fc8a70 | 229 | res->set_value((const uint8_t*)buffer, |
mbedAustin | 11:cada08fc8a70 | 230 | (uint32_t)size); |
mbedAustin | 11:cada08fc8a70 | 231 | memory_free(buffer); |
mbedAustin | 11:cada08fc8a70 | 232 | } |
mbedAustin | 11:cada08fc8a70 | 233 | } |
mbedAustin | 11:cada08fc8a70 | 234 | } |
mbedAustin | 11:cada08fc8a70 | 235 | } |
mbedAustin | 11:cada08fc8a70 | 236 | return res; |
mbedAustin | 11:cada08fc8a70 | 237 | } |
mbedAustin | 11:cada08fc8a70 | 238 | M2MResource* M2MDevice::create_resource(DeviceResource resource) |
mbedAustin | 11:cada08fc8a70 | 239 | { |
mbedAustin | 11:cada08fc8a70 | 240 | M2MResource* res = NULL; |
mbedAustin | 11:cada08fc8a70 | 241 | if(!is_resource_present(resource)) { |
mbedAustin | 11:cada08fc8a70 | 242 | String device_Id; |
mbedAustin | 11:cada08fc8a70 | 243 | if(FactoryReset == resource) { |
mbedAustin | 11:cada08fc8a70 | 244 | device_Id = DEVICE_FACTORY_RESET; |
mbedAustin | 11:cada08fc8a70 | 245 | } else if(ResetErrorCode == resource) { |
mbedAustin | 11:cada08fc8a70 | 246 | device_Id = DEVICE_RESET_ERROR_CODE; |
mbedAustin | 11:cada08fc8a70 | 247 | } |
mbedAustin | 11:cada08fc8a70 | 248 | if(_device_instance && !device_Id.empty()) { |
mbedAustin | 11:cada08fc8a70 | 249 | res = _device_instance->create_dynamic_resource(device_Id, |
mbedAustin | 11:cada08fc8a70 | 250 | OMA_RESOURCE_TYPE, |
mbedAustin | 11:cada08fc8a70 | 251 | M2MResourceInstance::OPAQUE, |
mbedAustin | 11:cada08fc8a70 | 252 | false); |
mbedAustin | 11:cada08fc8a70 | 253 | if(res) { |
mbedAustin | 11:cada08fc8a70 | 254 | res->set_operation(M2MBase::POST_ALLOWED); |
mbedAustin | 11:cada08fc8a70 | 255 | } |
mbedAustin | 11:cada08fc8a70 | 256 | } |
mbedAustin | 11:cada08fc8a70 | 257 | } |
mbedAustin | 11:cada08fc8a70 | 258 | return res; |
mbedAustin | 11:cada08fc8a70 | 259 | } |
mbedAustin | 11:cada08fc8a70 | 260 | |
mbedAustin | 11:cada08fc8a70 | 261 | bool M2MDevice::delete_resource(DeviceResource resource) |
mbedAustin | 11:cada08fc8a70 | 262 | { |
mbedAustin | 11:cada08fc8a70 | 263 | bool success = false; |
mbedAustin | 11:cada08fc8a70 | 264 | if(M2MDevice::Reboot != resource && |
mbedAustin | 11:cada08fc8a70 | 265 | M2MDevice::ErrorCode != resource && |
mbedAustin | 11:cada08fc8a70 | 266 | M2MDevice::SupportedBindingMode != resource) { |
mbedAustin | 11:cada08fc8a70 | 267 | if(_device_instance) { |
mbedAustin | 11:cada08fc8a70 | 268 | success = _device_instance->remove_resource(resource_name(resource)); |
mbedAustin | 11:cada08fc8a70 | 269 | } |
mbedAustin | 11:cada08fc8a70 | 270 | } |
mbedAustin | 11:cada08fc8a70 | 271 | return success; |
mbedAustin | 11:cada08fc8a70 | 272 | } |
mbedAustin | 11:cada08fc8a70 | 273 | |
mbedAustin | 11:cada08fc8a70 | 274 | bool M2MDevice::delete_resource_instance(DeviceResource resource, |
mbedAustin | 11:cada08fc8a70 | 275 | uint16_t instance_id) |
mbedAustin | 11:cada08fc8a70 | 276 | { |
mbedAustin | 11:cada08fc8a70 | 277 | bool success = false; |
mbedAustin | 11:cada08fc8a70 | 278 | if(M2MDevice::Reboot != resource && |
mbedAustin | 11:cada08fc8a70 | 279 | M2MDevice::ErrorCode != resource && |
mbedAustin | 11:cada08fc8a70 | 280 | M2MDevice::SupportedBindingMode != resource) { |
mbedAustin | 11:cada08fc8a70 | 281 | if(_device_instance) { |
mbedAustin | 11:cada08fc8a70 | 282 | success = _device_instance->remove_resource_instance(resource_name(resource),instance_id); |
mbedAustin | 11:cada08fc8a70 | 283 | } |
mbedAustin | 11:cada08fc8a70 | 284 | } |
mbedAustin | 11:cada08fc8a70 | 285 | return success; |
mbedAustin | 11:cada08fc8a70 | 286 | } |
mbedAustin | 11:cada08fc8a70 | 287 | |
mbedAustin | 11:cada08fc8a70 | 288 | bool M2MDevice::set_resource_value(DeviceResource resource, |
mbedAustin | 11:cada08fc8a70 | 289 | const String &value, |
mbedAustin | 11:cada08fc8a70 | 290 | uint16_t instance_id) |
mbedAustin | 11:cada08fc8a70 | 291 | { |
mbedAustin | 11:cada08fc8a70 | 292 | bool success = false; |
mbedAustin | 11:cada08fc8a70 | 293 | M2MResourceInstance* res = get_resource_instance(resource,instance_id); |
mbedAustin | 11:cada08fc8a70 | 294 | if(res && value.size() <= MAX_ALLOWED_STRING_LENGTH) { |
mbedAustin | 11:cada08fc8a70 | 295 | if(M2MDevice::Manufacturer == resource || |
mbedAustin | 11:cada08fc8a70 | 296 | M2MDevice::ModelNumber == resource || |
mbedAustin | 11:cada08fc8a70 | 297 | M2MDevice::DeviceType == resource || |
mbedAustin | 11:cada08fc8a70 | 298 | M2MDevice::SerialNumber == resource || |
mbedAustin | 11:cada08fc8a70 | 299 | M2MDevice::HardwareVersion == resource || |
mbedAustin | 11:cada08fc8a70 | 300 | M2MDevice::FirmwareVersion == resource || |
mbedAustin | 11:cada08fc8a70 | 301 | M2MDevice::SoftwareVersion == resource || |
mbedAustin | 11:cada08fc8a70 | 302 | M2MDevice::UTCOffset == resource || |
mbedAustin | 11:cada08fc8a70 | 303 | M2MDevice::Timezone == resource) { |
mbedAustin | 11:cada08fc8a70 | 304 | if (value.empty()) { |
mbedAustin | 11:cada08fc8a70 | 305 | res->clear_value(); |
mbedAustin | 11:cada08fc8a70 | 306 | success = true; |
mbedAustin | 11:cada08fc8a70 | 307 | } else { |
mbedAustin | 11:cada08fc8a70 | 308 | success = res->set_value((const uint8_t*)value.c_str(),(uint32_t)value.length()); |
mbedAustin | 11:cada08fc8a70 | 309 | } |
mbedAustin | 11:cada08fc8a70 | 310 | } |
mbedAustin | 11:cada08fc8a70 | 311 | } |
mbedAustin | 11:cada08fc8a70 | 312 | return success; |
mbedAustin | 11:cada08fc8a70 | 313 | } |
mbedAustin | 11:cada08fc8a70 | 314 | |
mbedAustin | 11:cada08fc8a70 | 315 | bool M2MDevice::set_resource_value(DeviceResource resource, |
mbedAustin | 11:cada08fc8a70 | 316 | int64_t value, |
mbedAustin | 11:cada08fc8a70 | 317 | uint16_t instance_id) |
mbedAustin | 11:cada08fc8a70 | 318 | { |
mbedAustin | 11:cada08fc8a70 | 319 | bool success = false; |
mbedAustin | 11:cada08fc8a70 | 320 | M2MResourceInstance* res = get_resource_instance(resource,instance_id); |
mbedAustin | 11:cada08fc8a70 | 321 | if(res) { |
mbedAustin | 11:cada08fc8a70 | 322 | if(M2MDevice::BatteryLevel == resource || |
mbedAustin | 11:cada08fc8a70 | 323 | M2MDevice::BatteryStatus == resource || |
mbedAustin | 11:cada08fc8a70 | 324 | M2MDevice::MemoryFree == resource || |
mbedAustin | 11:cada08fc8a70 | 325 | M2MDevice::MemoryTotal == resource || |
mbedAustin | 11:cada08fc8a70 | 326 | M2MDevice::ErrorCode == resource || |
mbedAustin | 11:cada08fc8a70 | 327 | M2MDevice::CurrentTime == resource || |
mbedAustin | 11:cada08fc8a70 | 328 | M2MDevice::AvailablePowerSources == resource || |
mbedAustin | 11:cada08fc8a70 | 329 | M2MDevice::PowerSourceVoltage == resource || |
mbedAustin | 11:cada08fc8a70 | 330 | M2MDevice::PowerSourceCurrent == resource) { |
mbedAustin | 11:cada08fc8a70 | 331 | // If it is any of the above resource |
mbedAustin | 11:cada08fc8a70 | 332 | // set the value of the resource. |
mbedAustin | 11:cada08fc8a70 | 333 | if (check_value_range(resource, value)) { |
mbedAustin | 11:cada08fc8a70 | 334 | char *buffer = (char*)memory_alloc(20); |
mbedAustin | 11:cada08fc8a70 | 335 | if(buffer) { |
mbedAustin | 11:cada08fc8a70 | 336 | int size = snprintf(buffer, 20,"%lld",(long long int)value); |
mbedAustin | 11:cada08fc8a70 | 337 | success = res->set_value((const uint8_t*)buffer, |
mbedAustin | 11:cada08fc8a70 | 338 | (uint32_t)size); |
mbedAustin | 11:cada08fc8a70 | 339 | memory_free(buffer); |
mbedAustin | 11:cada08fc8a70 | 340 | } |
mbedAustin | 11:cada08fc8a70 | 341 | } |
mbedAustin | 11:cada08fc8a70 | 342 | } |
mbedAustin | 11:cada08fc8a70 | 343 | } |
mbedAustin | 11:cada08fc8a70 | 344 | return success; |
mbedAustin | 11:cada08fc8a70 | 345 | } |
mbedAustin | 11:cada08fc8a70 | 346 | |
mbedAustin | 11:cada08fc8a70 | 347 | String M2MDevice::resource_value_string(DeviceResource resource, |
mbedAustin | 11:cada08fc8a70 | 348 | uint16_t instance_id) const |
mbedAustin | 11:cada08fc8a70 | 349 | { |
mbedAustin | 11:cada08fc8a70 | 350 | String value = ""; |
mbedAustin | 11:cada08fc8a70 | 351 | M2MResourceInstance* res = get_resource_instance(resource,instance_id); |
mbedAustin | 11:cada08fc8a70 | 352 | if(res) { |
mbedAustin | 11:cada08fc8a70 | 353 | if(M2MDevice::Manufacturer == resource || |
mbedAustin | 11:cada08fc8a70 | 354 | M2MDevice::ModelNumber == resource || |
mbedAustin | 11:cada08fc8a70 | 355 | M2MDevice::DeviceType == resource || |
mbedAustin | 11:cada08fc8a70 | 356 | M2MDevice::SerialNumber == resource || |
mbedAustin | 11:cada08fc8a70 | 357 | M2MDevice::HardwareVersion == resource || |
mbedAustin | 11:cada08fc8a70 | 358 | M2MDevice::FirmwareVersion == resource || |
mbedAustin | 11:cada08fc8a70 | 359 | M2MDevice::SoftwareVersion == resource || |
mbedAustin | 11:cada08fc8a70 | 360 | M2MDevice::UTCOffset == resource || |
mbedAustin | 11:cada08fc8a70 | 361 | M2MDevice::Timezone == resource) { |
mbedAustin | 11:cada08fc8a70 | 362 | |
mbedAustin | 11:cada08fc8a70 | 363 | uint8_t* buffer = NULL; |
mbedAustin | 11:cada08fc8a70 | 364 | uint32_t length = 0; |
mbedAustin | 11:cada08fc8a70 | 365 | res->get_value(buffer,length); |
mbedAustin | 11:cada08fc8a70 | 366 | |
mbedAustin | 11:cada08fc8a70 | 367 | char *char_buffer = (char*)malloc(length+1); |
mbedAustin | 11:cada08fc8a70 | 368 | if(char_buffer) { |
mbedAustin | 11:cada08fc8a70 | 369 | memset(char_buffer,0,length+1); |
mbedAustin | 11:cada08fc8a70 | 370 | memcpy(char_buffer,(char*)buffer,length); |
mbedAustin | 11:cada08fc8a70 | 371 | |
mbedAustin | 11:cada08fc8a70 | 372 | String s_name(char_buffer); |
mbedAustin | 11:cada08fc8a70 | 373 | value = s_name; |
mbedAustin | 11:cada08fc8a70 | 374 | if(char_buffer) { |
mbedAustin | 11:cada08fc8a70 | 375 | free(char_buffer); |
mbedAustin | 11:cada08fc8a70 | 376 | } |
mbedAustin | 11:cada08fc8a70 | 377 | } |
mbedAustin | 11:cada08fc8a70 | 378 | if(buffer) { |
mbedAustin | 11:cada08fc8a70 | 379 | free(buffer); |
mbedAustin | 11:cada08fc8a70 | 380 | } |
mbedAustin | 11:cada08fc8a70 | 381 | } |
mbedAustin | 11:cada08fc8a70 | 382 | } |
mbedAustin | 11:cada08fc8a70 | 383 | return value; |
mbedAustin | 11:cada08fc8a70 | 384 | } |
mbedAustin | 11:cada08fc8a70 | 385 | |
mbedAustin | 11:cada08fc8a70 | 386 | int64_t M2MDevice::resource_value_int(DeviceResource resource, |
mbedAustin | 11:cada08fc8a70 | 387 | uint16_t instance_id) const |
mbedAustin | 11:cada08fc8a70 | 388 | { |
mbedAustin | 11:cada08fc8a70 | 389 | int64_t value = -1; |
mbedAustin | 11:cada08fc8a70 | 390 | M2MResourceInstance* res = get_resource_instance(resource,instance_id); |
mbedAustin | 11:cada08fc8a70 | 391 | if(res) { |
mbedAustin | 11:cada08fc8a70 | 392 | if(M2MDevice::BatteryLevel == resource || |
mbedAustin | 11:cada08fc8a70 | 393 | M2MDevice::BatteryStatus == resource || |
mbedAustin | 11:cada08fc8a70 | 394 | M2MDevice::MemoryFree == resource || |
mbedAustin | 11:cada08fc8a70 | 395 | M2MDevice::MemoryTotal == resource || |
mbedAustin | 11:cada08fc8a70 | 396 | M2MDevice::ErrorCode == resource || |
mbedAustin | 11:cada08fc8a70 | 397 | M2MDevice::CurrentTime == resource || |
mbedAustin | 11:cada08fc8a70 | 398 | M2MDevice::AvailablePowerSources == resource || |
mbedAustin | 11:cada08fc8a70 | 399 | M2MDevice::PowerSourceVoltage == resource || |
mbedAustin | 11:cada08fc8a70 | 400 | M2MDevice::PowerSourceCurrent == resource) { |
mbedAustin | 11:cada08fc8a70 | 401 | // Get the value and convert it into integer |
mbedAustin | 11:cada08fc8a70 | 402 | uint8_t* buffer = NULL; |
mbedAustin | 11:cada08fc8a70 | 403 | uint32_t length = 0; |
mbedAustin | 11:cada08fc8a70 | 404 | res->get_value(buffer,length); |
mbedAustin | 11:cada08fc8a70 | 405 | if(buffer) { |
mbedAustin | 11:cada08fc8a70 | 406 | value = atoi((const char*)buffer); |
mbedAustin | 11:cada08fc8a70 | 407 | free(buffer); |
mbedAustin | 11:cada08fc8a70 | 408 | } |
mbedAustin | 11:cada08fc8a70 | 409 | } |
mbedAustin | 11:cada08fc8a70 | 410 | } |
mbedAustin | 11:cada08fc8a70 | 411 | return value; |
mbedAustin | 11:cada08fc8a70 | 412 | } |
mbedAustin | 11:cada08fc8a70 | 413 | |
mbedAustin | 11:cada08fc8a70 | 414 | bool M2MDevice::is_resource_present(DeviceResource resource) const |
mbedAustin | 11:cada08fc8a70 | 415 | { |
mbedAustin | 11:cada08fc8a70 | 416 | bool success = false; |
mbedAustin | 11:cada08fc8a70 | 417 | M2MResourceInstance* res = get_resource_instance(resource,0); |
mbedAustin | 11:cada08fc8a70 | 418 | if(res) { |
mbedAustin | 11:cada08fc8a70 | 419 | success = true; |
mbedAustin | 11:cada08fc8a70 | 420 | } |
mbedAustin | 11:cada08fc8a70 | 421 | return success; |
mbedAustin | 11:cada08fc8a70 | 422 | } |
mbedAustin | 11:cada08fc8a70 | 423 | |
mbedAustin | 11:cada08fc8a70 | 424 | uint16_t M2MDevice::per_resource_count(DeviceResource res) const |
mbedAustin | 11:cada08fc8a70 | 425 | { |
mbedAustin | 11:cada08fc8a70 | 426 | uint16_t count = 0; |
mbedAustin | 11:cada08fc8a70 | 427 | if(_device_instance) { |
mbedAustin | 11:cada08fc8a70 | 428 | count = _device_instance->resource_count(resource_name(res)); |
mbedAustin | 11:cada08fc8a70 | 429 | } |
mbedAustin | 11:cada08fc8a70 | 430 | return count; |
mbedAustin | 11:cada08fc8a70 | 431 | } |
mbedAustin | 11:cada08fc8a70 | 432 | |
mbedAustin | 11:cada08fc8a70 | 433 | uint16_t M2MDevice::total_resource_count() const |
mbedAustin | 11:cada08fc8a70 | 434 | { |
mbedAustin | 11:cada08fc8a70 | 435 | uint16_t count = 0; |
mbedAustin | 11:cada08fc8a70 | 436 | if(_device_instance) { |
mbedAustin | 11:cada08fc8a70 | 437 | count = _device_instance->resources().size(); |
mbedAustin | 11:cada08fc8a70 | 438 | } |
mbedAustin | 11:cada08fc8a70 | 439 | return count; |
mbedAustin | 11:cada08fc8a70 | 440 | } |
mbedAustin | 11:cada08fc8a70 | 441 | |
mbedAustin | 11:cada08fc8a70 | 442 | M2MResourceInstance* M2MDevice::get_resource_instance(DeviceResource dev_res, |
mbedAustin | 11:cada08fc8a70 | 443 | uint16_t instance_id) const |
mbedAustin | 11:cada08fc8a70 | 444 | { |
mbedAustin | 11:cada08fc8a70 | 445 | M2MResource* res = NULL; |
mbedAustin | 11:cada08fc8a70 | 446 | M2MResourceInstance* inst = NULL; |
mbedAustin | 11:cada08fc8a70 | 447 | if(_device_instance) { |
mbedAustin | 11:cada08fc8a70 | 448 | res = _device_instance->resource(resource_name(dev_res)); |
mbedAustin | 11:cada08fc8a70 | 449 | if(res) { |
mbedAustin | 11:cada08fc8a70 | 450 | if(res->supports_multiple_instances()) { |
mbedAustin | 11:cada08fc8a70 | 451 | inst = res->resource_instance(instance_id); |
mbedAustin | 11:cada08fc8a70 | 452 | } else { |
mbedAustin | 11:cada08fc8a70 | 453 | inst = res; |
mbedAustin | 11:cada08fc8a70 | 454 | } |
mbedAustin | 11:cada08fc8a70 | 455 | } |
mbedAustin | 11:cada08fc8a70 | 456 | } |
mbedAustin | 11:cada08fc8a70 | 457 | return inst; |
mbedAustin | 11:cada08fc8a70 | 458 | } |
mbedAustin | 11:cada08fc8a70 | 459 | |
mbedAustin | 11:cada08fc8a70 | 460 | String M2MDevice::resource_name(DeviceResource resource) const |
mbedAustin | 11:cada08fc8a70 | 461 | { |
mbedAustin | 11:cada08fc8a70 | 462 | String res_name = ""; |
mbedAustin | 11:cada08fc8a70 | 463 | switch(resource) { |
mbedAustin | 11:cada08fc8a70 | 464 | case Manufacturer: |
mbedAustin | 11:cada08fc8a70 | 465 | res_name = DEVICE_MANUFACTURER; |
mbedAustin | 11:cada08fc8a70 | 466 | break; |
mbedAustin | 11:cada08fc8a70 | 467 | case DeviceType: |
mbedAustin | 11:cada08fc8a70 | 468 | res_name = DEVICE_DEVICE_TYPE; |
mbedAustin | 11:cada08fc8a70 | 469 | break; |
mbedAustin | 11:cada08fc8a70 | 470 | case ModelNumber: |
mbedAustin | 11:cada08fc8a70 | 471 | res_name = DEVICE_MODEL_NUMBER; |
mbedAustin | 11:cada08fc8a70 | 472 | break; |
mbedAustin | 11:cada08fc8a70 | 473 | case SerialNumber: |
mbedAustin | 11:cada08fc8a70 | 474 | res_name = DEVICE_SERIAL_NUMBER; |
mbedAustin | 11:cada08fc8a70 | 475 | break; |
mbedAustin | 11:cada08fc8a70 | 476 | case HardwareVersion: |
mbedAustin | 11:cada08fc8a70 | 477 | res_name = DEVICE_HARDWARE_VERSION; |
mbedAustin | 11:cada08fc8a70 | 478 | break; |
mbedAustin | 11:cada08fc8a70 | 479 | case FirmwareVersion: |
mbedAustin | 11:cada08fc8a70 | 480 | res_name = DEVICE_FIRMWARE_VERSION; |
mbedAustin | 11:cada08fc8a70 | 481 | break; |
mbedAustin | 11:cada08fc8a70 | 482 | case SoftwareVersion: |
mbedAustin | 11:cada08fc8a70 | 483 | res_name = DEVICE_SOFTWARE_VERSION; |
mbedAustin | 11:cada08fc8a70 | 484 | break; |
mbedAustin | 11:cada08fc8a70 | 485 | case Reboot: |
mbedAustin | 11:cada08fc8a70 | 486 | res_name = DEVICE_REBOOT; |
mbedAustin | 11:cada08fc8a70 | 487 | break; |
mbedAustin | 11:cada08fc8a70 | 488 | case FactoryReset: |
mbedAustin | 11:cada08fc8a70 | 489 | res_name = DEVICE_FACTORY_RESET; |
mbedAustin | 11:cada08fc8a70 | 490 | break; |
mbedAustin | 11:cada08fc8a70 | 491 | case AvailablePowerSources: |
mbedAustin | 11:cada08fc8a70 | 492 | res_name = DEVICE_AVAILABLE_POWER_SOURCES; |
mbedAustin | 11:cada08fc8a70 | 493 | break; |
mbedAustin | 11:cada08fc8a70 | 494 | case PowerSourceVoltage: |
mbedAustin | 11:cada08fc8a70 | 495 | res_name = DEVICE_POWER_SOURCE_VOLTAGE; |
mbedAustin | 11:cada08fc8a70 | 496 | break; |
mbedAustin | 11:cada08fc8a70 | 497 | case PowerSourceCurrent: |
mbedAustin | 11:cada08fc8a70 | 498 | res_name = DEVICE_POWER_SOURCE_CURRENT; |
mbedAustin | 11:cada08fc8a70 | 499 | break; |
mbedAustin | 11:cada08fc8a70 | 500 | case BatteryLevel: |
mbedAustin | 11:cada08fc8a70 | 501 | res_name = DEVICE_BATTERY_LEVEL; |
mbedAustin | 11:cada08fc8a70 | 502 | break; |
mbedAustin | 11:cada08fc8a70 | 503 | case BatteryStatus: |
mbedAustin | 11:cada08fc8a70 | 504 | res_name = DEVICE_BATTERY_STATUS; |
mbedAustin | 11:cada08fc8a70 | 505 | break; |
mbedAustin | 11:cada08fc8a70 | 506 | case MemoryFree: |
mbedAustin | 11:cada08fc8a70 | 507 | res_name = DEVICE_MEMORY_FREE; |
mbedAustin | 11:cada08fc8a70 | 508 | break; |
mbedAustin | 11:cada08fc8a70 | 509 | case MemoryTotal: |
mbedAustin | 11:cada08fc8a70 | 510 | res_name = DEVICE_MEMORY_TOTAL; |
mbedAustin | 11:cada08fc8a70 | 511 | break; |
mbedAustin | 11:cada08fc8a70 | 512 | case ErrorCode: |
mbedAustin | 11:cada08fc8a70 | 513 | res_name = DEVICE_ERROR_CODE; |
mbedAustin | 11:cada08fc8a70 | 514 | break; |
mbedAustin | 11:cada08fc8a70 | 515 | case ResetErrorCode: |
mbedAustin | 11:cada08fc8a70 | 516 | res_name = DEVICE_RESET_ERROR_CODE; |
mbedAustin | 11:cada08fc8a70 | 517 | break; |
mbedAustin | 11:cada08fc8a70 | 518 | case CurrentTime: |
mbedAustin | 11:cada08fc8a70 | 519 | res_name = DEVICE_CURRENT_TIME; |
mbedAustin | 11:cada08fc8a70 | 520 | break; |
mbedAustin | 11:cada08fc8a70 | 521 | case UTCOffset: |
mbedAustin | 11:cada08fc8a70 | 522 | res_name = DEVICE_UTC_OFFSET; |
mbedAustin | 11:cada08fc8a70 | 523 | break; |
mbedAustin | 11:cada08fc8a70 | 524 | case Timezone: |
mbedAustin | 11:cada08fc8a70 | 525 | res_name = DEVICE_TIMEZONE; |
mbedAustin | 11:cada08fc8a70 | 526 | break; |
mbedAustin | 11:cada08fc8a70 | 527 | case SupportedBindingMode: |
mbedAustin | 11:cada08fc8a70 | 528 | res_name = DEVICE_SUPPORTED_BINDING_MODE; |
mbedAustin | 11:cada08fc8a70 | 529 | break; |
mbedAustin | 11:cada08fc8a70 | 530 | } |
mbedAustin | 11:cada08fc8a70 | 531 | return res_name; |
mbedAustin | 11:cada08fc8a70 | 532 | } |
mbedAustin | 11:cada08fc8a70 | 533 | |
mbedAustin | 11:cada08fc8a70 | 534 | bool M2MDevice::check_value_range(DeviceResource resource, int64_t value) const |
mbedAustin | 11:cada08fc8a70 | 535 | { |
mbedAustin | 11:cada08fc8a70 | 536 | bool success = false; |
mbedAustin | 11:cada08fc8a70 | 537 | switch (resource) { |
mbedAustin | 11:cada08fc8a70 | 538 | case AvailablePowerSources: |
mbedAustin | 11:cada08fc8a70 | 539 | if(value >= 0 && value <= 7) { |
mbedAustin | 11:cada08fc8a70 | 540 | success = true; |
mbedAustin | 11:cada08fc8a70 | 541 | } |
mbedAustin | 11:cada08fc8a70 | 542 | break; |
mbedAustin | 11:cada08fc8a70 | 543 | case BatteryLevel: |
mbedAustin | 11:cada08fc8a70 | 544 | if (value >= 0 && value <= 100) { |
mbedAustin | 11:cada08fc8a70 | 545 | success = true; |
mbedAustin | 11:cada08fc8a70 | 546 | } |
mbedAustin | 11:cada08fc8a70 | 547 | break; |
mbedAustin | 11:cada08fc8a70 | 548 | case BatteryStatus: |
mbedAustin | 11:cada08fc8a70 | 549 | if (value >= 0 && value <= 6) { |
mbedAustin | 11:cada08fc8a70 | 550 | success = true; |
mbedAustin | 11:cada08fc8a70 | 551 | } |
mbedAustin | 11:cada08fc8a70 | 552 | break; |
mbedAustin | 11:cada08fc8a70 | 553 | case ErrorCode: |
mbedAustin | 11:cada08fc8a70 | 554 | if (value >= 0 && value <= 8) { |
mbedAustin | 11:cada08fc8a70 | 555 | success = true; |
mbedAustin | 11:cada08fc8a70 | 556 | } |
mbedAustin | 11:cada08fc8a70 | 557 | break; |
mbedAustin | 11:cada08fc8a70 | 558 | default: |
mbedAustin | 11:cada08fc8a70 | 559 | success = true; |
mbedAustin | 11:cada08fc8a70 | 560 | break; |
mbedAustin | 11:cada08fc8a70 | 561 | } |
mbedAustin | 11:cada08fc8a70 | 562 | return success; |
mbedAustin | 11:cada08fc8a70 | 563 | } |