FRDM K64F Metronome

Committer:
ram54288
Date:
Sun May 14 18:37:05 2017 +0000
Revision:
0:dbad57390bd1
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ram54288 0:dbad57390bd1 1 /*
ram54288 0:dbad57390bd1 2 * Copyright (c) 2015 ARM Limited. All rights reserved.
ram54288 0:dbad57390bd1 3 * SPDX-License-Identifier: Apache-2.0
ram54288 0:dbad57390bd1 4 * Licensed under the Apache License, Version 2.0 (the License); you may
ram54288 0:dbad57390bd1 5 * not use this file except in compliance with the License.
ram54288 0:dbad57390bd1 6 * You may obtain a copy of the License at
ram54288 0:dbad57390bd1 7 *
ram54288 0:dbad57390bd1 8 * http://www.apache.org/licenses/LICENSE-2.0
ram54288 0:dbad57390bd1 9 *
ram54288 0:dbad57390bd1 10 * Unless required by applicable law or agreed to in writing, software
ram54288 0:dbad57390bd1 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
ram54288 0:dbad57390bd1 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ram54288 0:dbad57390bd1 13 * See the License for the specific language governing permissions and
ram54288 0:dbad57390bd1 14 * limitations under the License.
ram54288 0:dbad57390bd1 15 */
ram54288 0:dbad57390bd1 16 #include "lwm2mtest.h"
ram54288 0:dbad57390bd1 17 #include "ns_types.h"
ram54288 0:dbad57390bd1 18 #include "ns_cmdline.h"
ram54288 0:dbad57390bd1 19
ram54288 0:dbad57390bd1 20 M2MLWClient::M2MLWClient()
ram54288 0:dbad57390bd1 21 : _security(NULL),
ram54288 0:dbad57390bd1 22 _interface(NULL),
ram54288 0:dbad57390bd1 23 _device(NULL),
ram54288 0:dbad57390bd1 24 _bootstrapped(false),
ram54288 0:dbad57390bd1 25 _error(false),
ram54288 0:dbad57390bd1 26 _registered(false),
ram54288 0:dbad57390bd1 27 _unregistered(false),
ram54288 0:dbad57390bd1 28 _registration_updated(false)
ram54288 0:dbad57390bd1 29 {
ram54288 0:dbad57390bd1 30 }
ram54288 0:dbad57390bd1 31
ram54288 0:dbad57390bd1 32 M2MLWClient::~M2MLWClient()
ram54288 0:dbad57390bd1 33 {
ram54288 0:dbad57390bd1 34 if(_interface) {
ram54288 0:dbad57390bd1 35 delete _interface;
ram54288 0:dbad57390bd1 36 }
ram54288 0:dbad57390bd1 37 if(_security) {
ram54288 0:dbad57390bd1 38 delete _security;
ram54288 0:dbad57390bd1 39 }
ram54288 0:dbad57390bd1 40 if( _register_security){
ram54288 0:dbad57390bd1 41 delete _register_security;
ram54288 0:dbad57390bd1 42 }
ram54288 0:dbad57390bd1 43 }
ram54288 0:dbad57390bd1 44
ram54288 0:dbad57390bd1 45
ram54288 0:dbad57390bd1 46 bool M2MLWClient::create_interface(int32_t param_count,
ram54288 0:dbad57390bd1 47 const char *endpoint,
ram54288 0:dbad57390bd1 48 const char *resource_type,
ram54288 0:dbad57390bd1 49 const int32_t lifetime,
ram54288 0:dbad57390bd1 50 const uint16_t listen_port,
ram54288 0:dbad57390bd1 51 const char *domain,
ram54288 0:dbad57390bd1 52 const uint8_t binding_mode,
ram54288 0:dbad57390bd1 53 const uint8_t network_interface)
ram54288 0:dbad57390bd1 54 {
ram54288 0:dbad57390bd1 55 if(_interface) {
ram54288 0:dbad57390bd1 56 delete _interface;
ram54288 0:dbad57390bd1 57 _interface = NULL;
ram54288 0:dbad57390bd1 58 }
ram54288 0:dbad57390bd1 59 String ep;
ram54288 0:dbad57390bd1 60 String rt;
ram54288 0:dbad57390bd1 61 String dmn;
ram54288 0:dbad57390bd1 62 if(endpoint) {
ram54288 0:dbad57390bd1 63 ep += endpoint;
ram54288 0:dbad57390bd1 64 }
ram54288 0:dbad57390bd1 65 if(resource_type) {
ram54288 0:dbad57390bd1 66 rt += resource_type;
ram54288 0:dbad57390bd1 67 }
ram54288 0:dbad57390bd1 68 if(domain) {
ram54288 0:dbad57390bd1 69 dmn += domain;
ram54288 0:dbad57390bd1 70 }
ram54288 0:dbad57390bd1 71
ram54288 0:dbad57390bd1 72 // Binding mode cannot be higher than 0x07 since it is an enum, check M2MInterface::BindingMode
ram54288 0:dbad57390bd1 73 if(binding_mode > 0x07) {
ram54288 0:dbad57390bd1 74 return false;
ram54288 0:dbad57390bd1 75 }
ram54288 0:dbad57390bd1 76
ram54288 0:dbad57390bd1 77 switch (param_count) {
ram54288 0:dbad57390bd1 78 case 0:
ram54288 0:dbad57390bd1 79 _interface = M2MInterfaceFactory::create_interface(*this, ep, rt);
ram54288 0:dbad57390bd1 80 break;
ram54288 0:dbad57390bd1 81 case 1:
ram54288 0:dbad57390bd1 82 _interface = M2MInterfaceFactory::create_interface(*this, ep, rt, lifetime);
ram54288 0:dbad57390bd1 83 break;
ram54288 0:dbad57390bd1 84 case 2:
ram54288 0:dbad57390bd1 85 _interface = M2MInterfaceFactory::create_interface(*this, ep, rt, lifetime, listen_port);
ram54288 0:dbad57390bd1 86 break;
ram54288 0:dbad57390bd1 87 case 3:
ram54288 0:dbad57390bd1 88 _interface = M2MInterfaceFactory::create_interface(*this, ep, rt, lifetime, listen_port, dmn);
ram54288 0:dbad57390bd1 89 break;
ram54288 0:dbad57390bd1 90 case 4:
ram54288 0:dbad57390bd1 91 _interface = M2MInterfaceFactory::create_interface(*this, ep, rt, lifetime, listen_port, dmn, (M2MInterface::BindingMode)binding_mode);
ram54288 0:dbad57390bd1 92 break;
ram54288 0:dbad57390bd1 93 case 5:
ram54288 0:dbad57390bd1 94 _interface = M2MInterfaceFactory::create_interface(*this, ep, rt, lifetime, listen_port, dmn, (M2MInterface::BindingMode)binding_mode, (M2MInterface::NetworkStack)network_interface);
ram54288 0:dbad57390bd1 95 break;
ram54288 0:dbad57390bd1 96 }
ram54288 0:dbad57390bd1 97 return (_interface == NULL) ? false : true;
ram54288 0:dbad57390bd1 98 }
ram54288 0:dbad57390bd1 99
ram54288 0:dbad57390bd1 100 bool M2MLWClient::create_bootstrap_object(const char *coap_bootstrap_address)
ram54288 0:dbad57390bd1 101 {
ram54288 0:dbad57390bd1 102 bool success = false;
ram54288 0:dbad57390bd1 103 String address;
ram54288 0:dbad57390bd1 104 if(coap_bootstrap_address) {
ram54288 0:dbad57390bd1 105 address += coap_bootstrap_address;
ram54288 0:dbad57390bd1 106 }
ram54288 0:dbad57390bd1 107 if(_security) {
ram54288 0:dbad57390bd1 108 delete _security;
ram54288 0:dbad57390bd1 109 }
ram54288 0:dbad57390bd1 110 _security = M2MInterfaceFactory::create_security(M2MSecurity::Bootstrap);
ram54288 0:dbad57390bd1 111 if(_security) {
ram54288 0:dbad57390bd1 112 if(_security->set_resource_value(M2MSecurity::M2MServerUri, address) &&
ram54288 0:dbad57390bd1 113 _security->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::NoSecurity)) {
ram54288 0:dbad57390bd1 114 success = true;
ram54288 0:dbad57390bd1 115 }
ram54288 0:dbad57390bd1 116 }
ram54288 0:dbad57390bd1 117 return success;
ram54288 0:dbad57390bd1 118 }
ram54288 0:dbad57390bd1 119
ram54288 0:dbad57390bd1 120 bool M2MLWClient::create_register_object(const char *coap_register_address, bool useSecureConn)
ram54288 0:dbad57390bd1 121 {
ram54288 0:dbad57390bd1 122 bool success = false;
ram54288 0:dbad57390bd1 123 String address;
ram54288 0:dbad57390bd1 124 if(coap_register_address) {
ram54288 0:dbad57390bd1 125 address += coap_register_address;
ram54288 0:dbad57390bd1 126 }
ram54288 0:dbad57390bd1 127 if(_register_security) {
ram54288 0:dbad57390bd1 128 delete _register_security;
ram54288 0:dbad57390bd1 129 }
ram54288 0:dbad57390bd1 130 _register_security = M2MInterfaceFactory::create_security(M2MSecurity::M2MServer);
ram54288 0:dbad57390bd1 131 if(_register_security) {
ram54288 0:dbad57390bd1 132 if( !useSecureConn ){
ram54288 0:dbad57390bd1 133 if(_register_security->set_resource_value(M2MSecurity::M2MServerUri, address) &&
ram54288 0:dbad57390bd1 134 _register_security->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::NoSecurity)) {
ram54288 0:dbad57390bd1 135 success = true;
ram54288 0:dbad57390bd1 136 }
ram54288 0:dbad57390bd1 137 }else{
ram54288 0:dbad57390bd1 138 if(_register_security->set_resource_value(M2MSecurity::M2MServerUri, address) &&
ram54288 0:dbad57390bd1 139 _register_security->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::Certificate) &&
ram54288 0:dbad57390bd1 140 _register_security->set_resource_value(M2MSecurity::ServerPublicKey,server_cert,server_cert_len) &&
ram54288 0:dbad57390bd1 141 _register_security->set_resource_value(M2MSecurity::PublicKey,cert,cert_len) &&
ram54288 0:dbad57390bd1 142 _register_security->set_resource_value(M2MSecurity::Secretkey,key,key_len) ){
ram54288 0:dbad57390bd1 143 success = true;
ram54288 0:dbad57390bd1 144 }
ram54288 0:dbad57390bd1 145 }
ram54288 0:dbad57390bd1 146 }
ram54288 0:dbad57390bd1 147 return success;
ram54288 0:dbad57390bd1 148 }
ram54288 0:dbad57390bd1 149
ram54288 0:dbad57390bd1 150 bool M2MLWClient::test_bootstrap()
ram54288 0:dbad57390bd1 151 {
ram54288 0:dbad57390bd1 152 bool success = false;
ram54288 0:dbad57390bd1 153 if(_interface) {
ram54288 0:dbad57390bd1 154 _interface->bootstrap(_security);
ram54288 0:dbad57390bd1 155 success = true;
ram54288 0:dbad57390bd1 156 }
ram54288 0:dbad57390bd1 157 return success;
ram54288 0:dbad57390bd1 158 }
ram54288 0:dbad57390bd1 159
ram54288 0:dbad57390bd1 160 bool M2MLWClient::create_device_object(M2MDevice::DeviceResource resource,
ram54288 0:dbad57390bd1 161 const char *value)
ram54288 0:dbad57390bd1 162 {
ram54288 0:dbad57390bd1 163 bool success = false;
ram54288 0:dbad57390bd1 164 String value_string;
ram54288 0:dbad57390bd1 165 if(value) {
ram54288 0:dbad57390bd1 166 value_string += value;
ram54288 0:dbad57390bd1 167 }
ram54288 0:dbad57390bd1 168 if(!_device) {
ram54288 0:dbad57390bd1 169 _device = M2MInterfaceFactory::create_device();
ram54288 0:dbad57390bd1 170 }
ram54288 0:dbad57390bd1 171 if(_device) {
ram54288 0:dbad57390bd1 172
ram54288 0:dbad57390bd1 173 if(_device->create_resource(resource,value_string)){
ram54288 0:dbad57390bd1 174 success = true;
ram54288 0:dbad57390bd1 175 } else {
ram54288 0:dbad57390bd1 176 success = _device->set_resource_value(resource,value);
ram54288 0:dbad57390bd1 177 }
ram54288 0:dbad57390bd1 178 }
ram54288 0:dbad57390bd1 179 return success;
ram54288 0:dbad57390bd1 180 }
ram54288 0:dbad57390bd1 181
ram54288 0:dbad57390bd1 182 bool M2MLWClient::create_device_object()
ram54288 0:dbad57390bd1 183 {
ram54288 0:dbad57390bd1 184 bool success = false;
ram54288 0:dbad57390bd1 185 if(!_device) {
ram54288 0:dbad57390bd1 186 _device = M2MInterfaceFactory::create_device();
ram54288 0:dbad57390bd1 187 success = true;
ram54288 0:dbad57390bd1 188 }
ram54288 0:dbad57390bd1 189 return success;
ram54288 0:dbad57390bd1 190 }
ram54288 0:dbad57390bd1 191
ram54288 0:dbad57390bd1 192 bool M2MLWClient::create_device_object(M2MDevice::DeviceResource resource,
ram54288 0:dbad57390bd1 193 int64_t value)
ram54288 0:dbad57390bd1 194 {
ram54288 0:dbad57390bd1 195 bool success = false;
ram54288 0:dbad57390bd1 196 if(!_device) {
ram54288 0:dbad57390bd1 197 _device = M2MInterfaceFactory::create_device();
ram54288 0:dbad57390bd1 198 }
ram54288 0:dbad57390bd1 199 if(_device) {
ram54288 0:dbad57390bd1 200 if(_device->create_resource(resource,value)) {
ram54288 0:dbad57390bd1 201 success = true;
ram54288 0:dbad57390bd1 202 } else {
ram54288 0:dbad57390bd1 203 success = _device->set_resource_value(resource, value);
ram54288 0:dbad57390bd1 204 }
ram54288 0:dbad57390bd1 205 }
ram54288 0:dbad57390bd1 206 return success;
ram54288 0:dbad57390bd1 207 }
ram54288 0:dbad57390bd1 208
ram54288 0:dbad57390bd1 209 bool M2MLWClient::create_device_object(M2MDevice::DeviceResource resource,
ram54288 0:dbad57390bd1 210 int64_t value,
ram54288 0:dbad57390bd1 211 uint16_t instance_id)
ram54288 0:dbad57390bd1 212 {
ram54288 0:dbad57390bd1 213 bool success = false;
ram54288 0:dbad57390bd1 214 if(!_device) {
ram54288 0:dbad57390bd1 215 _device = M2MInterfaceFactory::create_device();
ram54288 0:dbad57390bd1 216 }
ram54288 0:dbad57390bd1 217 if(_device) {
ram54288 0:dbad57390bd1 218 if(_device->create_resource_instance(resource,value,instance_id)) {
ram54288 0:dbad57390bd1 219 success = true;
ram54288 0:dbad57390bd1 220 } else {
ram54288 0:dbad57390bd1 221 success = _device->set_resource_value(resource,
ram54288 0:dbad57390bd1 222 value,
ram54288 0:dbad57390bd1 223 instance_id);
ram54288 0:dbad57390bd1 224 }
ram54288 0:dbad57390bd1 225 }
ram54288 0:dbad57390bd1 226 return success;
ram54288 0:dbad57390bd1 227 }
ram54288 0:dbad57390bd1 228
ram54288 0:dbad57390bd1 229 bool M2MLWClient::create_firmware_object(M2MFirmware::FirmwareResource resource,
ram54288 0:dbad57390bd1 230 const char *value)
ram54288 0:dbad57390bd1 231 {
ram54288 0:dbad57390bd1 232 bool success = false;
ram54288 0:dbad57390bd1 233 String value_string;
ram54288 0:dbad57390bd1 234 if(value) {
ram54288 0:dbad57390bd1 235 value_string += value;
ram54288 0:dbad57390bd1 236 }
ram54288 0:dbad57390bd1 237 if(!_firmware) {
ram54288 0:dbad57390bd1 238 _firmware = M2MInterfaceFactory::create_firmware();
ram54288 0:dbad57390bd1 239 }
ram54288 0:dbad57390bd1 240 if(_firmware) {
ram54288 0:dbad57390bd1 241 if(_firmware->create_resource(resource,value_string)){
ram54288 0:dbad57390bd1 242 success = true;
ram54288 0:dbad57390bd1 243 } else {
ram54288 0:dbad57390bd1 244 success = _firmware->set_resource_value(resource,value);
ram54288 0:dbad57390bd1 245 }
ram54288 0:dbad57390bd1 246 }
ram54288 0:dbad57390bd1 247 return success;
ram54288 0:dbad57390bd1 248 }
ram54288 0:dbad57390bd1 249
ram54288 0:dbad57390bd1 250 bool M2MLWClient::create_firmware_object()
ram54288 0:dbad57390bd1 251 {
ram54288 0:dbad57390bd1 252 bool success = false;
ram54288 0:dbad57390bd1 253 if(!_firmware) {
ram54288 0:dbad57390bd1 254 _firmware = M2MInterfaceFactory::create_firmware();
ram54288 0:dbad57390bd1 255 success = true;
ram54288 0:dbad57390bd1 256 }
ram54288 0:dbad57390bd1 257 return success;
ram54288 0:dbad57390bd1 258 }
ram54288 0:dbad57390bd1 259
ram54288 0:dbad57390bd1 260 bool M2MLWClient::create_firmware_object(M2MFirmware::FirmwareResource resource,
ram54288 0:dbad57390bd1 261 int64_t value)
ram54288 0:dbad57390bd1 262 {
ram54288 0:dbad57390bd1 263 bool success = false;
ram54288 0:dbad57390bd1 264 if(!_firmware) {
ram54288 0:dbad57390bd1 265 _firmware = M2MInterfaceFactory::create_firmware();
ram54288 0:dbad57390bd1 266 }
ram54288 0:dbad57390bd1 267 if(_firmware) {
ram54288 0:dbad57390bd1 268 if(_firmware->create_resource(resource,value)) {
ram54288 0:dbad57390bd1 269 success = true;
ram54288 0:dbad57390bd1 270 } else {
ram54288 0:dbad57390bd1 271 success = _firmware->set_resource_value(resource, value);
ram54288 0:dbad57390bd1 272 }
ram54288 0:dbad57390bd1 273 }
ram54288 0:dbad57390bd1 274 return success;
ram54288 0:dbad57390bd1 275 }
ram54288 0:dbad57390bd1 276
ram54288 0:dbad57390bd1 277 bool M2MLWClient::create_firmware_object(M2MFirmware::FirmwareResource resource,
ram54288 0:dbad57390bd1 278 const uint8_t *value,
ram54288 0:dbad57390bd1 279 const uint32_t length)
ram54288 0:dbad57390bd1 280 {
ram54288 0:dbad57390bd1 281 bool success = false;
ram54288 0:dbad57390bd1 282 if(!_firmware) {
ram54288 0:dbad57390bd1 283 _firmware = M2MInterfaceFactory::create_firmware();
ram54288 0:dbad57390bd1 284 }
ram54288 0:dbad57390bd1 285 if(_firmware) {
ram54288 0:dbad57390bd1 286 success = _firmware->set_resource_value(resource, value, length);
ram54288 0:dbad57390bd1 287 }
ram54288 0:dbad57390bd1 288 return success;
ram54288 0:dbad57390bd1 289 }
ram54288 0:dbad57390bd1 290
ram54288 0:dbad57390bd1 291 void M2MLWClient::set_fw_execute_function()
ram54288 0:dbad57390bd1 292 {
ram54288 0:dbad57390bd1 293 if(_firmware) {
ram54288 0:dbad57390bd1 294 M2MObjectInstance *inst = _firmware->object_instance(0);
ram54288 0:dbad57390bd1 295 if(inst) {
ram54288 0:dbad57390bd1 296 M2MResource *res = inst->resource("2");
ram54288 0:dbad57390bd1 297 if (res) {
ram54288 0:dbad57390bd1 298 res->set_execute_function(execute_callback(
ram54288 0:dbad57390bd1 299 this,
ram54288 0:dbad57390bd1 300 &M2MLWClient::fw_execute_function));
ram54288 0:dbad57390bd1 301 }
ram54288 0:dbad57390bd1 302 }
ram54288 0:dbad57390bd1 303 }
ram54288 0:dbad57390bd1 304 }
ram54288 0:dbad57390bd1 305
ram54288 0:dbad57390bd1 306 bool M2MLWClient::create_object(const char *name,
ram54288 0:dbad57390bd1 307 bool new_instance,
ram54288 0:dbad57390bd1 308 uint8_t object_operation,
ram54288 0:dbad57390bd1 309 uint8_t object_instance_operation,
ram54288 0:dbad57390bd1 310 uint16_t object_instance_id,
ram54288 0:dbad57390bd1 311 bool object_observable,
ram54288 0:dbad57390bd1 312 bool object_instance_observable)
ram54288 0:dbad57390bd1 313 {
ram54288 0:dbad57390bd1 314 bool success = false;
ram54288 0:dbad57390bd1 315 M2MObjectInstance *inst = NULL;
ram54288 0:dbad57390bd1 316 if(!_object) {
ram54288 0:dbad57390bd1 317 _object = M2MInterfaceFactory::create_object(name);
ram54288 0:dbad57390bd1 318 if(_object) {
ram54288 0:dbad57390bd1 319 _object->set_operation(int_to_operation(object_operation));
ram54288 0:dbad57390bd1 320 _object->set_observable(object_observable);
ram54288 0:dbad57390bd1 321 inst = _object->create_object_instance(object_instance_id);
ram54288 0:dbad57390bd1 322 if(inst) {
ram54288 0:dbad57390bd1 323 success = true;
ram54288 0:dbad57390bd1 324 inst->set_operation(int_to_operation(object_instance_operation));
ram54288 0:dbad57390bd1 325 inst->set_observable(object_instance_observable);
ram54288 0:dbad57390bd1 326 }
ram54288 0:dbad57390bd1 327 }
ram54288 0:dbad57390bd1 328 } else {
ram54288 0:dbad57390bd1 329 if(new_instance) {
ram54288 0:dbad57390bd1 330 inst = _object->create_object_instance(object_instance_id);
ram54288 0:dbad57390bd1 331 if(inst) {
ram54288 0:dbad57390bd1 332 success = true;
ram54288 0:dbad57390bd1 333 inst->set_operation(int_to_operation(object_instance_operation));
ram54288 0:dbad57390bd1 334 inst->set_observable(object_instance_observable);
ram54288 0:dbad57390bd1 335 }
ram54288 0:dbad57390bd1 336 }
ram54288 0:dbad57390bd1 337 }
ram54288 0:dbad57390bd1 338 return success;
ram54288 0:dbad57390bd1 339 }
ram54288 0:dbad57390bd1 340
ram54288 0:dbad57390bd1 341 bool M2MLWClient::create_static_resource_string(const char *name,
ram54288 0:dbad57390bd1 342 const char *value,
ram54288 0:dbad57390bd1 343 bool multiple_instance,
ram54288 0:dbad57390bd1 344 uint16_t object_instance)
ram54288 0:dbad57390bd1 345 {
ram54288 0:dbad57390bd1 346 bool success = false;
ram54288 0:dbad57390bd1 347 String name_string;
ram54288 0:dbad57390bd1 348 if(name) {
ram54288 0:dbad57390bd1 349 name_string += name;
ram54288 0:dbad57390bd1 350 }
ram54288 0:dbad57390bd1 351 String value_string;
ram54288 0:dbad57390bd1 352 if(value) {
ram54288 0:dbad57390bd1 353 value_string += value;
ram54288 0:dbad57390bd1 354 }
ram54288 0:dbad57390bd1 355 if(_object) {
ram54288 0:dbad57390bd1 356 M2MObjectInstance *inst = _object->object_instance(object_instance);
ram54288 0:dbad57390bd1 357 if(inst) {
ram54288 0:dbad57390bd1 358 if(inst->create_static_resource(name,"resource",
ram54288 0:dbad57390bd1 359 M2MResourceInstance::STRING,
ram54288 0:dbad57390bd1 360 (const uint8_t*)value_string.c_str(),
ram54288 0:dbad57390bd1 361 value_string.size()) != NULL) {
ram54288 0:dbad57390bd1 362 success = true;
ram54288 0:dbad57390bd1 363 }
ram54288 0:dbad57390bd1 364 }
ram54288 0:dbad57390bd1 365 }
ram54288 0:dbad57390bd1 366 return success;
ram54288 0:dbad57390bd1 367 }
ram54288 0:dbad57390bd1 368
ram54288 0:dbad57390bd1 369 bool M2MLWClient::create_static_resource_int(const char *name,
ram54288 0:dbad57390bd1 370 int64_t value,
ram54288 0:dbad57390bd1 371 bool multiple_instance,
ram54288 0:dbad57390bd1 372 uint16_t object_instance)
ram54288 0:dbad57390bd1 373 {
ram54288 0:dbad57390bd1 374 bool success = false;
ram54288 0:dbad57390bd1 375 String name_string;
ram54288 0:dbad57390bd1 376 String value_string;
ram54288 0:dbad57390bd1 377
ram54288 0:dbad57390bd1 378 if(name) {
ram54288 0:dbad57390bd1 379 name_string += name;
ram54288 0:dbad57390bd1 380 }
ram54288 0:dbad57390bd1 381
ram54288 0:dbad57390bd1 382 char value_buffer[20];
ram54288 0:dbad57390bd1 383 sprintf(value_buffer,"%ld",value);
ram54288 0:dbad57390bd1 384 value_string += value_buffer;
ram54288 0:dbad57390bd1 385
ram54288 0:dbad57390bd1 386 if(_object) {
ram54288 0:dbad57390bd1 387 M2MObjectInstance *inst = _object->object_instance(object_instance);
ram54288 0:dbad57390bd1 388 if(inst) {
ram54288 0:dbad57390bd1 389 if(inst->create_static_resource(name,"resource",
ram54288 0:dbad57390bd1 390 M2MResourceInstance::INTEGER,
ram54288 0:dbad57390bd1 391 (const uint8_t*)value_string.c_str(),
ram54288 0:dbad57390bd1 392 value_string.size()) != NULL) {
ram54288 0:dbad57390bd1 393 success = true;
ram54288 0:dbad57390bd1 394 }
ram54288 0:dbad57390bd1 395 }
ram54288 0:dbad57390bd1 396 }
ram54288 0:dbad57390bd1 397 return success;
ram54288 0:dbad57390bd1 398 }
ram54288 0:dbad57390bd1 399
ram54288 0:dbad57390bd1 400 bool M2MLWClient::create_dynamic_resource_string(const char *name,
ram54288 0:dbad57390bd1 401 bool observable,
ram54288 0:dbad57390bd1 402 bool multiple_instance,
ram54288 0:dbad57390bd1 403 uint16_t object_instance,
ram54288 0:dbad57390bd1 404 uint8_t resource_operation)
ram54288 0:dbad57390bd1 405 {
ram54288 0:dbad57390bd1 406 bool success = false;
ram54288 0:dbad57390bd1 407 String name_string;
ram54288 0:dbad57390bd1 408 if(name) {
ram54288 0:dbad57390bd1 409 name_string += name;
ram54288 0:dbad57390bd1 410 }
ram54288 0:dbad57390bd1 411 if(_object) {
ram54288 0:dbad57390bd1 412 M2MObjectInstance *inst = _object->object_instance(object_instance);
ram54288 0:dbad57390bd1 413 if(inst) {
ram54288 0:dbad57390bd1 414 M2MResource *res = inst->create_dynamic_resource(name,"resource",
ram54288 0:dbad57390bd1 415 M2MResourceInstance::STRING,
ram54288 0:dbad57390bd1 416 observable, multiple_instance);
ram54288 0:dbad57390bd1 417 if(res) {
ram54288 0:dbad57390bd1 418 success = true;
ram54288 0:dbad57390bd1 419 res->set_operation(int_to_operation(resource_operation));
ram54288 0:dbad57390bd1 420 }
ram54288 0:dbad57390bd1 421 }
ram54288 0:dbad57390bd1 422 }
ram54288 0:dbad57390bd1 423 return success;
ram54288 0:dbad57390bd1 424 }
ram54288 0:dbad57390bd1 425
ram54288 0:dbad57390bd1 426 bool M2MLWClient::create_dynamic_resource_int(const char *name,
ram54288 0:dbad57390bd1 427 bool observable,
ram54288 0:dbad57390bd1 428 bool multiple_instance,
ram54288 0:dbad57390bd1 429 uint16_t object_instance,
ram54288 0:dbad57390bd1 430 uint8_t resource_operation)
ram54288 0:dbad57390bd1 431 {
ram54288 0:dbad57390bd1 432 bool success = false;
ram54288 0:dbad57390bd1 433 String name_string;
ram54288 0:dbad57390bd1 434 if(name) {
ram54288 0:dbad57390bd1 435 name_string += name;
ram54288 0:dbad57390bd1 436 }
ram54288 0:dbad57390bd1 437 if(_object) {
ram54288 0:dbad57390bd1 438 M2MObjectInstance *inst = _object->object_instance(object_instance);
ram54288 0:dbad57390bd1 439 if(inst) {
ram54288 0:dbad57390bd1 440 M2MResource *res = inst->create_dynamic_resource(name,"resource",
ram54288 0:dbad57390bd1 441 M2MResourceInstance::INTEGER,
ram54288 0:dbad57390bd1 442 observable, multiple_instance);
ram54288 0:dbad57390bd1 443 if(res) {
ram54288 0:dbad57390bd1 444 success = true;
ram54288 0:dbad57390bd1 445 res->set_operation(int_to_operation(resource_operation));
ram54288 0:dbad57390bd1 446 }
ram54288 0:dbad57390bd1 447 }
ram54288 0:dbad57390bd1 448 }
ram54288 0:dbad57390bd1 449 return success;
ram54288 0:dbad57390bd1 450 }
ram54288 0:dbad57390bd1 451
ram54288 0:dbad57390bd1 452 bool M2MLWClient::set_resource_value(const char *name,
ram54288 0:dbad57390bd1 453 int32_t value,
ram54288 0:dbad57390bd1 454 uint16_t object_instance)
ram54288 0:dbad57390bd1 455 {
ram54288 0:dbad57390bd1 456 bool success = false;
ram54288 0:dbad57390bd1 457 String name_string;
ram54288 0:dbad57390bd1 458 String value_string;
ram54288 0:dbad57390bd1 459 if(name) {
ram54288 0:dbad57390bd1 460 name_string += name;
ram54288 0:dbad57390bd1 461 }
ram54288 0:dbad57390bd1 462
ram54288 0:dbad57390bd1 463 char value_buffer[20];
ram54288 0:dbad57390bd1 464 sprintf(value_buffer,"%d",value);
ram54288 0:dbad57390bd1 465 value_string += value_buffer;
ram54288 0:dbad57390bd1 466
ram54288 0:dbad57390bd1 467 if(_object && name_string.length() > 0) {
ram54288 0:dbad57390bd1 468 M2MObjectInstance *inst = _object->object_instance(object_instance);
ram54288 0:dbad57390bd1 469 if(inst) {
ram54288 0:dbad57390bd1 470 M2MResource *res = inst->resource(name_string);
ram54288 0:dbad57390bd1 471 if (res) {
ram54288 0:dbad57390bd1 472 if (res->set_value((const uint8_t*)value_string.c_str(), value_string.size())) {
ram54288 0:dbad57390bd1 473 success = true;
ram54288 0:dbad57390bd1 474 }
ram54288 0:dbad57390bd1 475 }
ram54288 0:dbad57390bd1 476 }
ram54288 0:dbad57390bd1 477 }
ram54288 0:dbad57390bd1 478 return success;
ram54288 0:dbad57390bd1 479 }
ram54288 0:dbad57390bd1 480
ram54288 0:dbad57390bd1 481 bool M2MLWClient::set_resource_value(const char *name,
ram54288 0:dbad57390bd1 482 const char *value,
ram54288 0:dbad57390bd1 483 uint16_t object_instance)
ram54288 0:dbad57390bd1 484 {
ram54288 0:dbad57390bd1 485 bool success = false;
ram54288 0:dbad57390bd1 486 String name_string;
ram54288 0:dbad57390bd1 487 String value_string;
ram54288 0:dbad57390bd1 488 if(name) {
ram54288 0:dbad57390bd1 489 name_string += name;
ram54288 0:dbad57390bd1 490 }
ram54288 0:dbad57390bd1 491 if(value) {
ram54288 0:dbad57390bd1 492 value_string += value;
ram54288 0:dbad57390bd1 493 }
ram54288 0:dbad57390bd1 494
ram54288 0:dbad57390bd1 495 if(_object && name_string.length() > 0) {
ram54288 0:dbad57390bd1 496 M2MObjectInstance *inst = _object->object_instance(object_instance);
ram54288 0:dbad57390bd1 497 if(inst) {
ram54288 0:dbad57390bd1 498 M2MResource *res = inst->resource(name_string);
ram54288 0:dbad57390bd1 499 if (res) {
ram54288 0:dbad57390bd1 500 if (res->set_value((const uint8_t*)value_string.c_str(), value_string.size())) {
ram54288 0:dbad57390bd1 501 success = true;
ram54288 0:dbad57390bd1 502 }
ram54288 0:dbad57390bd1 503 }
ram54288 0:dbad57390bd1 504 }
ram54288 0:dbad57390bd1 505 }
ram54288 0:dbad57390bd1 506 return success;
ram54288 0:dbad57390bd1 507 }
ram54288 0:dbad57390bd1 508
ram54288 0:dbad57390bd1 509 bool M2MLWClient::create_static_resource_instance_string(const char *name,
ram54288 0:dbad57390bd1 510 const char *value,
ram54288 0:dbad57390bd1 511 bool multiple_instance,
ram54288 0:dbad57390bd1 512 uint16_t object_instance,
ram54288 0:dbad57390bd1 513 uint16_t resource_instance)
ram54288 0:dbad57390bd1 514 {
ram54288 0:dbad57390bd1 515 bool success = false;
ram54288 0:dbad57390bd1 516 String name_string;
ram54288 0:dbad57390bd1 517 if(name) {
ram54288 0:dbad57390bd1 518 name_string += name;
ram54288 0:dbad57390bd1 519 }
ram54288 0:dbad57390bd1 520 String value_string;
ram54288 0:dbad57390bd1 521 if(value) {
ram54288 0:dbad57390bd1 522 value_string += value;
ram54288 0:dbad57390bd1 523 }
ram54288 0:dbad57390bd1 524 if(_object) {
ram54288 0:dbad57390bd1 525 M2MObjectInstance *inst = _object->object_instance(object_instance);
ram54288 0:dbad57390bd1 526 if(inst) {
ram54288 0:dbad57390bd1 527 if(inst->create_static_resource_instance(name,"resource",
ram54288 0:dbad57390bd1 528 M2MResourceInstance::STRING,
ram54288 0:dbad57390bd1 529 (const uint8_t*)value_string.c_str(),
ram54288 0:dbad57390bd1 530 value_string.size(),
ram54288 0:dbad57390bd1 531 resource_instance) != NULL) {
ram54288 0:dbad57390bd1 532 success = true;
ram54288 0:dbad57390bd1 533 }
ram54288 0:dbad57390bd1 534 }
ram54288 0:dbad57390bd1 535 }
ram54288 0:dbad57390bd1 536 return success;
ram54288 0:dbad57390bd1 537 }
ram54288 0:dbad57390bd1 538
ram54288 0:dbad57390bd1 539 bool M2MLWClient::create_static_resource_instance_int(const char *name,
ram54288 0:dbad57390bd1 540 int32_t value,
ram54288 0:dbad57390bd1 541 bool multiple_instance,
ram54288 0:dbad57390bd1 542 uint16_t object_instance,
ram54288 0:dbad57390bd1 543 uint16_t resource_instance)
ram54288 0:dbad57390bd1 544 {
ram54288 0:dbad57390bd1 545 bool success = false;
ram54288 0:dbad57390bd1 546 String name_string;
ram54288 0:dbad57390bd1 547 String value_string;
ram54288 0:dbad57390bd1 548
ram54288 0:dbad57390bd1 549 if(name) {
ram54288 0:dbad57390bd1 550 name_string += name;
ram54288 0:dbad57390bd1 551 }
ram54288 0:dbad57390bd1 552
ram54288 0:dbad57390bd1 553 char value_buffer[20];
ram54288 0:dbad57390bd1 554 sprintf(value_buffer,"%ld",value);
ram54288 0:dbad57390bd1 555 value_string += value_buffer;
ram54288 0:dbad57390bd1 556
ram54288 0:dbad57390bd1 557 if(_object) {
ram54288 0:dbad57390bd1 558 M2MObjectInstance *inst = _object->object_instance(object_instance);
ram54288 0:dbad57390bd1 559 if(inst) {
ram54288 0:dbad57390bd1 560 if(inst->create_static_resource_instance(name,"resource",
ram54288 0:dbad57390bd1 561 M2MResourceInstance::INTEGER,
ram54288 0:dbad57390bd1 562 (const uint8_t*)value_string.c_str(),
ram54288 0:dbad57390bd1 563 value_string.size(),
ram54288 0:dbad57390bd1 564 resource_instance) != NULL) {
ram54288 0:dbad57390bd1 565 success = true;
ram54288 0:dbad57390bd1 566 }
ram54288 0:dbad57390bd1 567 }
ram54288 0:dbad57390bd1 568 }
ram54288 0:dbad57390bd1 569 return success;
ram54288 0:dbad57390bd1 570 }
ram54288 0:dbad57390bd1 571
ram54288 0:dbad57390bd1 572 bool M2MLWClient::create_dynamic_resource_instance_int(const char *name,
ram54288 0:dbad57390bd1 573 bool observable,
ram54288 0:dbad57390bd1 574 bool multiple_instance,
ram54288 0:dbad57390bd1 575 uint16_t object_instance,
ram54288 0:dbad57390bd1 576 uint16_t resource_instance,
ram54288 0:dbad57390bd1 577 uint8_t resource_instance_operation)
ram54288 0:dbad57390bd1 578 {
ram54288 0:dbad57390bd1 579 bool success = false;
ram54288 0:dbad57390bd1 580 String name_string;
ram54288 0:dbad57390bd1 581 if(name) {
ram54288 0:dbad57390bd1 582 name_string += name;
ram54288 0:dbad57390bd1 583 }
ram54288 0:dbad57390bd1 584 if(_object) {
ram54288 0:dbad57390bd1 585 M2MObjectInstance *inst = _object->object_instance(object_instance);
ram54288 0:dbad57390bd1 586 if(inst) {
ram54288 0:dbad57390bd1 587 M2MResourceInstance *res = inst->create_dynamic_resource_instance(name,"resource",
ram54288 0:dbad57390bd1 588 M2MResourceInstance::INTEGER,
ram54288 0:dbad57390bd1 589 observable,
ram54288 0:dbad57390bd1 590 resource_instance);
ram54288 0:dbad57390bd1 591 if( res) {
ram54288 0:dbad57390bd1 592 success = true;
ram54288 0:dbad57390bd1 593 res->set_operation(int_to_operation(resource_instance_operation));
ram54288 0:dbad57390bd1 594 }
ram54288 0:dbad57390bd1 595 }
ram54288 0:dbad57390bd1 596 }
ram54288 0:dbad57390bd1 597 return success;
ram54288 0:dbad57390bd1 598 }
ram54288 0:dbad57390bd1 599
ram54288 0:dbad57390bd1 600 bool M2MLWClient::create_dynamic_resource_instance_string(const char *name,
ram54288 0:dbad57390bd1 601 bool observable,
ram54288 0:dbad57390bd1 602 bool multiple_instance,
ram54288 0:dbad57390bd1 603 uint16_t object_instance,
ram54288 0:dbad57390bd1 604 uint16_t resource_instance,
ram54288 0:dbad57390bd1 605 uint8_t resource_instance_operation)
ram54288 0:dbad57390bd1 606 {
ram54288 0:dbad57390bd1 607 bool success = false;
ram54288 0:dbad57390bd1 608 String name_string;
ram54288 0:dbad57390bd1 609 if(name) {
ram54288 0:dbad57390bd1 610 name_string += name;
ram54288 0:dbad57390bd1 611 }
ram54288 0:dbad57390bd1 612 if(_object) {
ram54288 0:dbad57390bd1 613 M2MObjectInstance *inst = _object->object_instance(object_instance);
ram54288 0:dbad57390bd1 614 if(inst) {
ram54288 0:dbad57390bd1 615 M2MResourceInstance *res = inst->create_dynamic_resource_instance(name,"resource",
ram54288 0:dbad57390bd1 616 M2MResourceInstance::STRING,
ram54288 0:dbad57390bd1 617 observable,
ram54288 0:dbad57390bd1 618 resource_instance);
ram54288 0:dbad57390bd1 619 if( res) {
ram54288 0:dbad57390bd1 620 success = true;
ram54288 0:dbad57390bd1 621 res->set_operation(int_to_operation(resource_instance_operation));
ram54288 0:dbad57390bd1 622 }
ram54288 0:dbad57390bd1 623 }
ram54288 0:dbad57390bd1 624 }
ram54288 0:dbad57390bd1 625 return success;
ram54288 0:dbad57390bd1 626 }
ram54288 0:dbad57390bd1 627
ram54288 0:dbad57390bd1 628 bool M2MLWClient::set_resource_instance_value(const char *name,
ram54288 0:dbad57390bd1 629 int32_t value,
ram54288 0:dbad57390bd1 630 uint16_t object_instance,
ram54288 0:dbad57390bd1 631 uint16_t resource_instance)
ram54288 0:dbad57390bd1 632 {
ram54288 0:dbad57390bd1 633 bool success = false;
ram54288 0:dbad57390bd1 634 String name_string;
ram54288 0:dbad57390bd1 635 String value_string;
ram54288 0:dbad57390bd1 636 if(name) {
ram54288 0:dbad57390bd1 637 name_string += name;
ram54288 0:dbad57390bd1 638 }
ram54288 0:dbad57390bd1 639
ram54288 0:dbad57390bd1 640 char value_buffer[20];
ram54288 0:dbad57390bd1 641 sprintf(value_buffer,"%d",value);
ram54288 0:dbad57390bd1 642 value_string += value_buffer;
ram54288 0:dbad57390bd1 643
ram54288 0:dbad57390bd1 644 if(_object && name_string.length() > 0) {
ram54288 0:dbad57390bd1 645 M2MObjectInstance *inst = _object->object_instance(object_instance);
ram54288 0:dbad57390bd1 646 if(inst) {
ram54288 0:dbad57390bd1 647 M2MResource *res = inst->resource(name_string);
ram54288 0:dbad57390bd1 648 if (res) {
ram54288 0:dbad57390bd1 649 M2MResourceInstance *res_inst = res->resource_instance(resource_instance);
ram54288 0:dbad57390bd1 650 if(res_inst) {
ram54288 0:dbad57390bd1 651 if (res_inst->set_value((const uint8_t*)value_string.c_str(), value_string.size())) {
ram54288 0:dbad57390bd1 652 success = true;
ram54288 0:dbad57390bd1 653 }
ram54288 0:dbad57390bd1 654 }
ram54288 0:dbad57390bd1 655 }
ram54288 0:dbad57390bd1 656 }
ram54288 0:dbad57390bd1 657 }
ram54288 0:dbad57390bd1 658 return success;
ram54288 0:dbad57390bd1 659 }
ram54288 0:dbad57390bd1 660
ram54288 0:dbad57390bd1 661 bool M2MLWClient::set_resource_instance_value(const char *name,
ram54288 0:dbad57390bd1 662 const char *value,
ram54288 0:dbad57390bd1 663 uint16_t object_instance,
ram54288 0:dbad57390bd1 664 uint16_t resource_instance)
ram54288 0:dbad57390bd1 665 {
ram54288 0:dbad57390bd1 666 bool success = false;
ram54288 0:dbad57390bd1 667 String name_string;
ram54288 0:dbad57390bd1 668 String value_string;
ram54288 0:dbad57390bd1 669 if(name) {
ram54288 0:dbad57390bd1 670 name_string += name;
ram54288 0:dbad57390bd1 671 }
ram54288 0:dbad57390bd1 672 if(value) {
ram54288 0:dbad57390bd1 673 value_string += value;
ram54288 0:dbad57390bd1 674 }
ram54288 0:dbad57390bd1 675
ram54288 0:dbad57390bd1 676 if(_object && name_string.length() > 0) {
ram54288 0:dbad57390bd1 677 M2MObjectInstance *inst = _object->object_instance(object_instance);
ram54288 0:dbad57390bd1 678 if(inst) {
ram54288 0:dbad57390bd1 679 M2MResource *res = inst->resource(name_string);
ram54288 0:dbad57390bd1 680 if (res) {
ram54288 0:dbad57390bd1 681 M2MResourceInstance *res_inst = res->resource_instance(resource_instance);
ram54288 0:dbad57390bd1 682 if(res_inst) {
ram54288 0:dbad57390bd1 683 if (res_inst->set_value((const uint8_t*)value_string.c_str(), value_string.size())) {
ram54288 0:dbad57390bd1 684 success = true;
ram54288 0:dbad57390bd1 685 }
ram54288 0:dbad57390bd1 686 }
ram54288 0:dbad57390bd1 687 }
ram54288 0:dbad57390bd1 688 }
ram54288 0:dbad57390bd1 689 }
ram54288 0:dbad57390bd1 690 return success;
ram54288 0:dbad57390bd1 691 }
ram54288 0:dbad57390bd1 692
ram54288 0:dbad57390bd1 693 bool M2MLWClient::test_register()
ram54288 0:dbad57390bd1 694 {
ram54288 0:dbad57390bd1 695 bool success = false;
ram54288 0:dbad57390bd1 696 M2MObjectList object_list;
ram54288 0:dbad57390bd1 697 if(_device) {
ram54288 0:dbad57390bd1 698 object_list.push_back(_device);
ram54288 0:dbad57390bd1 699 }
ram54288 0:dbad57390bd1 700 if(_firmware) {
ram54288 0:dbad57390bd1 701 object_list.push_back(_firmware);
ram54288 0:dbad57390bd1 702 }
ram54288 0:dbad57390bd1 703 if(_object) {
ram54288 0:dbad57390bd1 704 object_list.push_back(_object);
ram54288 0:dbad57390bd1 705 }
ram54288 0:dbad57390bd1 706 if(_interface) {
ram54288 0:dbad57390bd1 707 _interface->register_object(_register_security,object_list);
ram54288 0:dbad57390bd1 708 success = true;
ram54288 0:dbad57390bd1 709 }
ram54288 0:dbad57390bd1 710 return success;
ram54288 0:dbad57390bd1 711 }
ram54288 0:dbad57390bd1 712
ram54288 0:dbad57390bd1 713 bool M2MLWClient::test_update_register(const uint32_t lifetime)
ram54288 0:dbad57390bd1 714 {
ram54288 0:dbad57390bd1 715 bool success = false;
ram54288 0:dbad57390bd1 716 if(_interface && _register_security) {
ram54288 0:dbad57390bd1 717 success = true;
ram54288 0:dbad57390bd1 718 _interface->update_registration(_register_security,lifetime);
ram54288 0:dbad57390bd1 719 }
ram54288 0:dbad57390bd1 720 return success;
ram54288 0:dbad57390bd1 721 }
ram54288 0:dbad57390bd1 722
ram54288 0:dbad57390bd1 723 bool M2MLWClient::test_unregister()
ram54288 0:dbad57390bd1 724 {
ram54288 0:dbad57390bd1 725 bool success = false;
ram54288 0:dbad57390bd1 726 if(_interface) {
ram54288 0:dbad57390bd1 727 success = true;
ram54288 0:dbad57390bd1 728 _interface->unregister_object(_register_security);
ram54288 0:dbad57390bd1 729 }
ram54288 0:dbad57390bd1 730 return success;
ram54288 0:dbad57390bd1 731 }
ram54288 0:dbad57390bd1 732
ram54288 0:dbad57390bd1 733 void M2MLWClient::bootstrap_done(M2MSecurity *server_object)
ram54288 0:dbad57390bd1 734 {
ram54288 0:dbad57390bd1 735 if(server_object) {
ram54288 0:dbad57390bd1 736 _register_security = server_object;
ram54288 0:dbad57390bd1 737 _bootstrapped = true;
ram54288 0:dbad57390bd1 738 cmd_printf("\nBootstrapped\n");
ram54288 0:dbad57390bd1 739 cmd_ready( CMDLINE_RETCODE_SUCCESS );
ram54288 0:dbad57390bd1 740 }
ram54288 0:dbad57390bd1 741 }
ram54288 0:dbad57390bd1 742
ram54288 0:dbad57390bd1 743 void M2MLWClient::object_registered(M2MSecurity *security_object, const M2MServer &server_object)
ram54288 0:dbad57390bd1 744 {
ram54288 0:dbad57390bd1 745 _registered = true;
ram54288 0:dbad57390bd1 746 cmd_printf("\nRegistered\n");
ram54288 0:dbad57390bd1 747 cmd_ready( CMDLINE_RETCODE_SUCCESS );
ram54288 0:dbad57390bd1 748 }
ram54288 0:dbad57390bd1 749
ram54288 0:dbad57390bd1 750 void M2MLWClient::object_unregistered(M2MSecurity *server_object)
ram54288 0:dbad57390bd1 751 {
ram54288 0:dbad57390bd1 752 _unregistered = true;
ram54288 0:dbad57390bd1 753 if(_device) {
ram54288 0:dbad57390bd1 754 M2MDevice::delete_instance();
ram54288 0:dbad57390bd1 755 _device = NULL;
ram54288 0:dbad57390bd1 756 }
ram54288 0:dbad57390bd1 757 if(_object) {
ram54288 0:dbad57390bd1 758 delete _object;
ram54288 0:dbad57390bd1 759 _object = NULL;
ram54288 0:dbad57390bd1 760 }
ram54288 0:dbad57390bd1 761 if(_security) {
ram54288 0:dbad57390bd1 762 delete _security;
ram54288 0:dbad57390bd1 763 _security = NULL;
ram54288 0:dbad57390bd1 764 }
ram54288 0:dbad57390bd1 765 if(_register_security) {
ram54288 0:dbad57390bd1 766 delete _register_security;
ram54288 0:dbad57390bd1 767 _register_security = NULL;
ram54288 0:dbad57390bd1 768 }
ram54288 0:dbad57390bd1 769 cmd_printf("\nUnregistered\n");
ram54288 0:dbad57390bd1 770 cmd_ready( CMDLINE_RETCODE_SUCCESS );
ram54288 0:dbad57390bd1 771 }
ram54288 0:dbad57390bd1 772
ram54288 0:dbad57390bd1 773 void M2MLWClient::registration_updated(M2MSecurity *security_object,
ram54288 0:dbad57390bd1 774 const M2MServer &server_object)
ram54288 0:dbad57390bd1 775 {
ram54288 0:dbad57390bd1 776 _registration_updated = true;
ram54288 0:dbad57390bd1 777 cmd_printf("\nregistration updated\n");
ram54288 0:dbad57390bd1 778 cmd_ready( CMDLINE_RETCODE_SUCCESS );
ram54288 0:dbad57390bd1 779 }
ram54288 0:dbad57390bd1 780
ram54288 0:dbad57390bd1 781 void M2MLWClient::error(M2MInterface::Error error)
ram54288 0:dbad57390bd1 782 {
ram54288 0:dbad57390bd1 783 _error = true;
ram54288 0:dbad57390bd1 784 cmd_printf("\nError occured Error Code : %d\n", (int8_t)error);
ram54288 0:dbad57390bd1 785 cmd_ready( CMDLINE_RETCODE_SUCCESS );
ram54288 0:dbad57390bd1 786 }
ram54288 0:dbad57390bd1 787
ram54288 0:dbad57390bd1 788 void M2MLWClient::value_updated(M2MBase *base, M2MBase::BaseType type)
ram54288 0:dbad57390bd1 789 {
ram54288 0:dbad57390bd1 790 cmd_printf("\nValue updated of Object name %s and Type \n",
ram54288 0:dbad57390bd1 791 base->name().c_str(), type);
ram54288 0:dbad57390bd1 792 }
ram54288 0:dbad57390bd1 793
ram54288 0:dbad57390bd1 794 M2MBase::Operation M2MLWClient::int_to_operation(uint8_t operation)
ram54288 0:dbad57390bd1 795 {
ram54288 0:dbad57390bd1 796 M2MBase::Operation op = M2MBase::NOT_ALLOWED;
ram54288 0:dbad57390bd1 797 switch(operation) {
ram54288 0:dbad57390bd1 798 case 0:
ram54288 0:dbad57390bd1 799 op = M2MBase::NOT_ALLOWED;
ram54288 0:dbad57390bd1 800 break;
ram54288 0:dbad57390bd1 801 case 1:
ram54288 0:dbad57390bd1 802 op = M2MBase::GET_ALLOWED;
ram54288 0:dbad57390bd1 803 break;
ram54288 0:dbad57390bd1 804 case 2:
ram54288 0:dbad57390bd1 805 op = M2MBase::PUT_ALLOWED;
ram54288 0:dbad57390bd1 806 break;
ram54288 0:dbad57390bd1 807 case 3:
ram54288 0:dbad57390bd1 808 op = M2MBase::GET_PUT_ALLOWED;
ram54288 0:dbad57390bd1 809 break;
ram54288 0:dbad57390bd1 810 case 4:
ram54288 0:dbad57390bd1 811 op = M2MBase::POST_ALLOWED;
ram54288 0:dbad57390bd1 812 break;
ram54288 0:dbad57390bd1 813 case 5:
ram54288 0:dbad57390bd1 814 op = M2MBase::GET_POST_ALLOWED;
ram54288 0:dbad57390bd1 815 break;
ram54288 0:dbad57390bd1 816 case 6:
ram54288 0:dbad57390bd1 817 op = M2MBase::PUT_POST_ALLOWED;
ram54288 0:dbad57390bd1 818 break;
ram54288 0:dbad57390bd1 819 case 7:
ram54288 0:dbad57390bd1 820 op = M2MBase::GET_PUT_POST_ALLOWED;
ram54288 0:dbad57390bd1 821 break;
ram54288 0:dbad57390bd1 822 case 8:
ram54288 0:dbad57390bd1 823 op = M2MBase::DELETE_ALLOWED;
ram54288 0:dbad57390bd1 824 break;
ram54288 0:dbad57390bd1 825 default:
ram54288 0:dbad57390bd1 826 break;
ram54288 0:dbad57390bd1 827 }
ram54288 0:dbad57390bd1 828 return op;
ram54288 0:dbad57390bd1 829 }
ram54288 0:dbad57390bd1 830
ram54288 0:dbad57390bd1 831 void M2MLWClient::fw_execute_function(void *argument)
ram54288 0:dbad57390bd1 832 {
ram54288 0:dbad57390bd1 833 if(argument) {
ram54288 0:dbad57390bd1 834 char* arguments = (char*)argument;
ram54288 0:dbad57390bd1 835 cmd_printf("Received %s!!\n", arguments);
ram54288 0:dbad57390bd1 836 }
ram54288 0:dbad57390bd1 837 cmd_printf("Firmware update executed\n");
ram54288 0:dbad57390bd1 838 }
ram54288 0:dbad57390bd1 839
ram54288 0:dbad57390bd1 840 void M2MLWClient::firmware_resource_int(int resource)
ram54288 0:dbad57390bd1 841 {
ram54288 0:dbad57390bd1 842 cmd_printf("Firmware resource value int\n");
ram54288 0:dbad57390bd1 843 cmd_printf("%ld\n", _firmware->resource_value_int(static_cast<M2MFirmware::FirmwareResource>(resource)));
ram54288 0:dbad57390bd1 844 }
ram54288 0:dbad57390bd1 845
ram54288 0:dbad57390bd1 846 void M2MLWClient::firmware_resource_string(int resource)
ram54288 0:dbad57390bd1 847 {
ram54288 0:dbad57390bd1 848 cmd_printf("Firmware resource value string\n");
ram54288 0:dbad57390bd1 849 cmd_printf("%s\n", _firmware->resource_value_string(static_cast<M2MFirmware::FirmwareResource>(resource)).c_str());
ram54288 0:dbad57390bd1 850 }
ram54288 0:dbad57390bd1 851
ram54288 0:dbad57390bd1 852 void M2MLWClient::firmware_resource_buffer()
ram54288 0:dbad57390bd1 853 {
ram54288 0:dbad57390bd1 854 cmd_printf("Firmware resource value buffer\n");
ram54288 0:dbad57390bd1 855 uint8_t *value = 0;
ram54288 0:dbad57390bd1 856 uint32_t valueSize = _firmware->resource_value_buffer(M2MFirmware::Package, value);
ram54288 0:dbad57390bd1 857 cmd_printf("%s\n", value);
ram54288 0:dbad57390bd1 858 free(value);
ram54288 0:dbad57390bd1 859 }