joey shelton / LED_Demo

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers lwm2mtest.cpp Source File

lwm2mtest.cpp

00001 /*
00002  * Copyright (c) 2015 ARM Limited. All rights reserved.
00003  * SPDX-License-Identifier: Apache-2.0
00004  * Licensed under the Apache License, Version 2.0 (the License); you may
00005  * not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include "lwm2mtest.h"
00017 #include "ns_types.h"
00018 #include "ns_cmdline.h"
00019 
00020 M2MLWClient::M2MLWClient()
00021 : _security(NULL),
00022   _interface(NULL),
00023   _device(NULL),
00024   _bootstrapped(false),
00025   _error(false),
00026   _registered(false),
00027   _unregistered(false),
00028   _registration_updated(false)
00029 {
00030 }
00031 
00032 M2MLWClient::~M2MLWClient()
00033 {
00034     if(_interface) {
00035         delete _interface;
00036     }
00037     if(_security) {
00038         delete _security;
00039     }
00040     if( _register_security){
00041         delete _register_security;
00042     }
00043 }
00044 
00045 
00046 bool M2MLWClient::create_interface(int32_t param_count,
00047                       const char *endpoint,
00048                       const char *resource_type,
00049                       const int32_t lifetime,
00050                       const uint16_t listen_port,
00051                       const char *domain,
00052                       const uint8_t binding_mode,
00053                       const uint8_t network_interface)
00054 {
00055     if(_interface) {
00056         delete _interface;
00057         _interface = NULL;
00058     }
00059     String ep;
00060     String rt;
00061     String dmn;
00062     if(endpoint) {
00063         ep += endpoint;
00064     }
00065     if(resource_type) {
00066         rt += resource_type;
00067     }
00068     if(domain) {
00069         dmn += domain;
00070     }
00071 
00072     // Binding mode cannot be higher than 0x07 since it is an enum, check M2MInterface::BindingMode
00073     if(binding_mode > 0x07) {
00074         return false;
00075     }
00076 
00077     switch (param_count) {
00078         case 0:
00079             _interface = M2MInterfaceFactory::create_interface(*this, ep, rt);
00080             break;
00081         case 1:
00082             _interface = M2MInterfaceFactory::create_interface(*this, ep, rt, lifetime);
00083             break;
00084         case 2:
00085             _interface = M2MInterfaceFactory::create_interface(*this, ep, rt, lifetime, listen_port);
00086             break;
00087         case 3:
00088             _interface = M2MInterfaceFactory::create_interface(*this, ep, rt, lifetime, listen_port, dmn);
00089             break;
00090         case 4:
00091             _interface = M2MInterfaceFactory::create_interface(*this, ep, rt, lifetime, listen_port, dmn, (M2MInterface::BindingMode)binding_mode);
00092             break;
00093         case 5:
00094             _interface = M2MInterfaceFactory::create_interface(*this, ep, rt, lifetime, listen_port, dmn, (M2MInterface::BindingMode)binding_mode, (M2MInterface::NetworkStack)network_interface);
00095             break;
00096     }
00097     return (_interface == NULL) ? false : true;
00098 }
00099 
00100 bool M2MLWClient::create_bootstrap_object(const char *coap_bootstrap_address)
00101 {
00102     bool success = false;
00103     String address;
00104     if(coap_bootstrap_address) {
00105         address += coap_bootstrap_address;
00106     }
00107     if(_security) {
00108         delete _security;
00109     }
00110     _security = M2MInterfaceFactory::create_security(M2MSecurity::Bootstrap);
00111     if(_security) {
00112         if(_security->set_resource_value(M2MSecurity::M2MServerUri, address) &&
00113            _security->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::NoSecurity)) {
00114             success = true;
00115         }
00116     }
00117     return success;
00118 }
00119 
00120 bool M2MLWClient::create_register_object(const char *coap_register_address, bool useSecureConn)
00121 {
00122     bool success = false;
00123     String address;
00124     if(coap_register_address) {
00125         address += coap_register_address;
00126     }
00127     if(_register_security) {
00128         delete _register_security;
00129     }
00130     _register_security = M2MInterfaceFactory::create_security(M2MSecurity::M2MServer);
00131     if(_register_security) {
00132         if( !useSecureConn ){
00133             if(_register_security->set_resource_value(M2MSecurity::M2MServerUri, address) &&
00134                _register_security->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::NoSecurity)) {
00135                 success = true;
00136             }
00137         }else{
00138             if(_register_security->set_resource_value(M2MSecurity::M2MServerUri, address) &&
00139                _register_security->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::Certificate) &&
00140                _register_security->set_resource_value(M2MSecurity::ServerPublicKey,server_cert,server_cert_len) &&
00141                _register_security->set_resource_value(M2MSecurity::PublicKey,cert,cert_len) &&
00142                _register_security->set_resource_value(M2MSecurity::Secretkey,key,key_len) ){
00143                 success = true;
00144             }
00145         }
00146     }
00147     return success;
00148 }
00149 
00150 bool M2MLWClient::test_bootstrap()
00151 {
00152     bool success = false;
00153     if(_interface) {
00154         _interface->bootstrap(_security);
00155         success = true;
00156     }
00157     return success;
00158 }
00159 
00160 bool M2MLWClient::create_device_object(M2MDevice::DeviceResource resource,
00161                                        const char *value)
00162 {
00163     bool success = false;
00164     String value_string;
00165     if(value) {
00166         value_string += value;
00167     }
00168     if(!_device) {
00169         _device = M2MInterfaceFactory::create_device();
00170     }
00171     if(_device) {
00172 
00173         if(_device->create_resource(resource,value_string)){
00174             success = true;
00175         } else {
00176             success = _device->set_resource_value(resource,value);
00177         }
00178     }
00179     return success;
00180 }
00181 
00182 bool M2MLWClient::create_device_object()
00183 {
00184     bool success = false;
00185     if(!_device) {
00186         _device = M2MInterfaceFactory::create_device();
00187         success = true;
00188     }
00189     return success;
00190 }
00191 
00192 bool M2MLWClient::create_device_object(M2MDevice::DeviceResource resource,
00193                           int64_t value)
00194 {
00195     bool success = false;
00196     if(!_device) {
00197         _device = M2MInterfaceFactory::create_device();
00198     }
00199     if(_device) {
00200         if(_device->create_resource(resource,value)) {
00201             success = true;
00202         } else {
00203             success = _device->set_resource_value(resource, value);
00204         }
00205     }
00206     return success;
00207 }
00208 
00209 bool M2MLWClient::create_device_object(M2MDevice::DeviceResource resource,
00210                                        int64_t value,
00211                                        uint16_t instance_id)
00212 {
00213     bool success = false;
00214     if(!_device) {
00215         _device = M2MInterfaceFactory::create_device();
00216     }
00217     if(_device) {
00218         if(_device->create_resource_instance(resource,value,instance_id)) {
00219             success = true;
00220         } else {
00221             success = _device->set_resource_value(resource,
00222                                                   value,
00223                                                   instance_id);
00224         }
00225     }
00226     return success;
00227 }
00228 
00229 bool M2MLWClient::create_firmware_object(M2MFirmware::FirmwareResource resource,
00230                                        const char *value)
00231 {
00232     bool success = false;
00233     String value_string;
00234     if(value) {
00235         value_string += value;
00236     }
00237     if(!_firmware) {
00238         _firmware = M2MInterfaceFactory::create_firmware();
00239     }
00240     if(_firmware) {
00241         if(_firmware->create_resource(resource,value_string)){
00242             success = true;
00243         } else {
00244             success = _firmware->set_resource_value(resource,value);
00245         }
00246     }
00247     return success;
00248 }
00249 
00250 bool M2MLWClient::create_firmware_object()
00251 {
00252     bool success = false;
00253     if(!_firmware) {
00254         _firmware = M2MInterfaceFactory::create_firmware();
00255         success = true;
00256     }    
00257     return success;
00258 }
00259 
00260 bool M2MLWClient::create_firmware_object(M2MFirmware::FirmwareResource resource,
00261                           int64_t value)
00262 {
00263     bool success = false;
00264     if(!_firmware) {
00265         _firmware = M2MInterfaceFactory::create_firmware();
00266     }
00267     if(_firmware) {
00268         if(_firmware->create_resource(resource,value)) {
00269             success = true;
00270         } else {
00271             success = _firmware->set_resource_value(resource, value);            
00272         }
00273     }    
00274     return success;
00275 }
00276 
00277 bool M2MLWClient::create_firmware_object(M2MFirmware::FirmwareResource resource,
00278                                          const uint8_t *value,
00279                                          const uint32_t length)
00280 {
00281     bool success = false;
00282     if(!_firmware) {
00283         _firmware = M2MInterfaceFactory::create_firmware();
00284     }
00285     if(_firmware) {
00286             success = _firmware->set_resource_value(resource, value, length);
00287     }
00288     return success;
00289 }
00290 
00291 void M2MLWClient::set_fw_execute_function()
00292 {
00293     if(_firmware) {
00294         M2MObjectInstance *inst = _firmware->object_instance(0);
00295         if(inst) {
00296             M2MResource *res = inst->resource("2");
00297             if (res) {                
00298                 res->set_execute_function(execute_callback (
00299                                               this,
00300                                               &M2MLWClient::fw_execute_function));
00301             }
00302         }
00303     }
00304 }
00305 
00306 bool M2MLWClient::create_object(const char *name,
00307                                 bool new_instance,
00308                                 uint8_t object_operation,
00309                                 uint8_t object_instance_operation,
00310                                 uint16_t object_instance_id,
00311                                 bool object_observable,
00312                                 bool object_instance_observable)
00313 {
00314     bool success = false;
00315     M2MObjectInstance *inst = NULL;
00316     if(!_object) {
00317         _object = M2MInterfaceFactory::create_object(name);
00318         if(_object) {
00319             _object->set_operation(int_to_operation(object_operation));
00320             _object->set_observable(object_observable);
00321             inst = _object->create_object_instance(object_instance_id);
00322             if(inst) {
00323                 success = true;
00324                 inst->set_operation(int_to_operation(object_instance_operation));
00325                 inst->set_observable(object_instance_observable);
00326             }
00327         }
00328     } else {
00329         if(new_instance) {
00330             inst = _object->create_object_instance(object_instance_id);
00331             if(inst) {
00332                 success = true;
00333                 inst->set_operation(int_to_operation(object_instance_operation));
00334                 inst->set_observable(object_instance_observable);
00335             }
00336         }
00337     }
00338     return success;
00339 }
00340 
00341 bool M2MLWClient::create_static_resource_string(const char *name,
00342                                                 const char *value,
00343                                                 bool multiple_instance,
00344                                                 uint16_t object_instance)
00345 {
00346     bool success = false;
00347     String name_string;
00348     if(name) {
00349         name_string += name;
00350     }
00351     String value_string;
00352     if(value) {
00353         value_string += value;
00354     }
00355     if(_object) {
00356         M2MObjectInstance *inst = _object->object_instance(object_instance);
00357         if(inst) {
00358             if(inst->create_static_resource(name,"resource",
00359                                             M2MResourceInstance::STRING,
00360                                             (const uint8_t*)value_string.c_str(),
00361                                             value_string.size()) != NULL) {
00362                 success = true;
00363             }
00364         }
00365     }
00366     return success;
00367 }
00368 
00369 bool M2MLWClient::create_static_resource_int(const char *name,
00370                                              int64_t value,
00371                                              bool multiple_instance,
00372                                              uint16_t object_instance)
00373 {
00374     bool success = false;
00375     String name_string;
00376     String value_string;
00377 
00378     if(name) {
00379         name_string += name;
00380     }
00381 
00382     char value_buffer[20];
00383     sprintf(value_buffer,"%ld",value);
00384     value_string += value_buffer;
00385 
00386     if(_object) {
00387         M2MObjectInstance *inst = _object->object_instance(object_instance);
00388         if(inst) {
00389             if(inst->create_static_resource(name,"resource",
00390                                             M2MResourceInstance::INTEGER,
00391                                             (const uint8_t*)value_string.c_str(),
00392                                             value_string.size()) != NULL) {
00393                 success = true;
00394             }
00395         }
00396     }
00397     return success;
00398 }
00399 
00400 bool M2MLWClient::create_dynamic_resource_string(const char *name,
00401                                           bool observable,
00402                                           bool multiple_instance,
00403                                           uint16_t object_instance,
00404                                           uint8_t resource_operation)
00405 {
00406     bool success = false;
00407     String name_string;
00408     if(name) {
00409         name_string += name;
00410     }
00411     if(_object) {
00412         M2MObjectInstance *inst = _object->object_instance(object_instance);
00413         if(inst) {
00414             M2MResource *res = inst->create_dynamic_resource(name,"resource",
00415                                                              M2MResourceInstance::STRING,
00416                                                              observable, multiple_instance);
00417             if(res) {
00418                 success = true;
00419                 res->set_operation(int_to_operation(resource_operation));
00420             }
00421         }
00422     }
00423     return success;
00424 }
00425 
00426 bool M2MLWClient::create_dynamic_resource_int(const char *name,
00427                                           bool observable,
00428                                           bool multiple_instance,
00429                                           uint16_t object_instance,
00430                                           uint8_t resource_operation)
00431 {
00432     bool success = false;
00433     String name_string;
00434     if(name) {
00435         name_string += name;
00436     }
00437     if(_object) {
00438         M2MObjectInstance *inst = _object->object_instance(object_instance);
00439         if(inst) {
00440             M2MResource *res = inst->create_dynamic_resource(name,"resource",
00441                                                              M2MResourceInstance::INTEGER,
00442                                                              observable, multiple_instance);
00443             if(res) {
00444                 success = true;
00445                 res->set_operation(int_to_operation(resource_operation));
00446             }
00447         }
00448     }
00449     return success;
00450 }
00451 
00452 bool M2MLWClient::set_resource_value(const char *name,
00453                                           int32_t value,
00454                                           uint16_t object_instance)
00455 {
00456     bool success = false;
00457     String name_string;
00458     String value_string;
00459     if(name) {
00460         name_string += name;
00461     }
00462 
00463     char value_buffer[20];
00464     sprintf(value_buffer,"%d",value);
00465     value_string += value_buffer;
00466 
00467     if(_object && name_string.length() > 0) {
00468         M2MObjectInstance *inst = _object->object_instance(object_instance);
00469         if(inst) {
00470             M2MResource *res = inst->resource(name_string);
00471             if (res) {
00472                 if (res->set_value((const uint8_t*)value_string.c_str(), value_string.size())) {
00473                     success = true;
00474                 }
00475             }
00476         }
00477     }
00478     return success;
00479 }
00480 
00481 bool M2MLWClient::set_resource_value(const char *name,
00482                                      const char *value,
00483                                      uint16_t object_instance)
00484 {
00485     bool success = false;
00486     String name_string;
00487     String value_string;
00488     if(name) {
00489         name_string += name;
00490     }
00491     if(value) {
00492         value_string += value;
00493     }
00494 
00495     if(_object && name_string.length() > 0) {
00496         M2MObjectInstance *inst = _object->object_instance(object_instance);
00497         if(inst) {
00498             M2MResource *res = inst->resource(name_string);
00499             if (res) {
00500                 if (res->set_value((const uint8_t*)value_string.c_str(), value_string.size())) {
00501                     success = true;
00502                 }
00503             }
00504         }
00505     }
00506     return success;
00507 }
00508 
00509 bool M2MLWClient::create_static_resource_instance_string(const char *name,
00510                                                          const char *value,
00511                                                          bool multiple_instance,
00512                                                          uint16_t object_instance,
00513                                                          uint16_t resource_instance)
00514 {
00515     bool success = false;
00516     String name_string;
00517     if(name) {
00518         name_string += name;
00519     }
00520     String value_string;
00521     if(value) {
00522         value_string += value;
00523     }
00524     if(_object) {
00525         M2MObjectInstance *inst = _object->object_instance(object_instance);
00526         if(inst) {
00527             if(inst->create_static_resource_instance(name,"resource",
00528                                                     M2MResourceInstance::STRING,
00529                                                     (const uint8_t*)value_string.c_str(),
00530                                                     value_string.size(),
00531                                                     resource_instance) != NULL) {
00532                 success = true;
00533             }
00534         }
00535     }
00536     return success;
00537 }
00538 
00539 bool M2MLWClient::create_static_resource_instance_int(const char *name,
00540                                                       int32_t value,
00541                                                       bool multiple_instance,
00542                                                       uint16_t object_instance,
00543                                                       uint16_t resource_instance)
00544 {
00545     bool success = false;
00546     String name_string;
00547     String value_string;
00548 
00549     if(name) {
00550         name_string += name;
00551     }
00552 
00553     char value_buffer[20];
00554     sprintf(value_buffer,"%ld",value);
00555     value_string += value_buffer;
00556 
00557     if(_object) {
00558         M2MObjectInstance *inst = _object->object_instance(object_instance);
00559         if(inst) {
00560             if(inst->create_static_resource_instance(name,"resource",
00561                                                     M2MResourceInstance::INTEGER,
00562                                                     (const uint8_t*)value_string.c_str(),
00563                                                     value_string.size(),
00564                                                     resource_instance) != NULL) {
00565                 success = true;
00566             }
00567         }
00568     }
00569     return success;
00570 }
00571 
00572 bool M2MLWClient::create_dynamic_resource_instance_int(const char *name,
00573                                                    bool observable,
00574                                                    bool multiple_instance,
00575                                                    uint16_t object_instance,
00576                                                    uint16_t resource_instance,
00577                                                    uint8_t resource_instance_operation)
00578 {
00579     bool success = false;
00580     String name_string;
00581     if(name) {
00582         name_string += name;
00583     }
00584     if(_object) {
00585         M2MObjectInstance *inst = _object->object_instance(object_instance);
00586         if(inst) {
00587             M2MResourceInstance *res = inst->create_dynamic_resource_instance(name,"resource",
00588                                                                       M2MResourceInstance::INTEGER,
00589                                                                       observable,
00590                                                                       resource_instance);
00591             if( res) {
00592                 success = true;
00593                 res->set_operation(int_to_operation(resource_instance_operation));
00594             }
00595         }
00596     }
00597     return success;
00598 }
00599 
00600 bool M2MLWClient::create_dynamic_resource_instance_string(const char *name,
00601                                                    bool observable,
00602                                                    bool multiple_instance,
00603                                                    uint16_t object_instance,
00604                                                    uint16_t resource_instance,
00605                                                    uint8_t resource_instance_operation)
00606 {
00607     bool success = false;
00608     String name_string;
00609     if(name) {
00610         name_string += name;
00611     }
00612     if(_object) {
00613         M2MObjectInstance *inst = _object->object_instance(object_instance);
00614         if(inst) {
00615             M2MResourceInstance *res = inst->create_dynamic_resource_instance(name,"resource",
00616                                                                       M2MResourceInstance::STRING,
00617                                                                       observable,
00618                                                                       resource_instance);
00619             if( res) {
00620                 success = true;
00621                 res->set_operation(int_to_operation(resource_instance_operation));
00622             }
00623         }
00624     }
00625     return success;
00626 }
00627 
00628 bool M2MLWClient::set_resource_instance_value(const char *name,
00629                                               int32_t value,
00630                                               uint16_t object_instance,
00631                                               uint16_t resource_instance)
00632 {
00633     bool success = false;
00634     String name_string;
00635     String value_string;
00636     if(name) {
00637         name_string += name;
00638     }
00639 
00640     char value_buffer[20];
00641     sprintf(value_buffer,"%d",value);
00642     value_string += value_buffer;
00643 
00644     if(_object && name_string.length() > 0) {
00645         M2MObjectInstance *inst = _object->object_instance(object_instance);
00646         if(inst) {
00647             M2MResource *res = inst->resource(name_string);
00648             if (res) {
00649                 M2MResourceInstance *res_inst = res->resource_instance(resource_instance);
00650                 if(res_inst) {
00651                     if (res_inst->set_value((const uint8_t*)value_string.c_str(), value_string.size())) {
00652                         success = true;
00653                     }
00654                 }
00655             }
00656         }
00657     }
00658     return success;
00659 }
00660 
00661 bool M2MLWClient::set_resource_instance_value(const char *name,
00662                                               const char *value,
00663                                               uint16_t object_instance,
00664                                               uint16_t resource_instance)
00665 {
00666     bool success = false;
00667     String name_string;
00668     String value_string;
00669     if(name) {
00670         name_string += name;
00671     }
00672     if(value) {
00673         value_string += value;
00674     }
00675 
00676     if(_object && name_string.length() > 0) {
00677         M2MObjectInstance *inst = _object->object_instance(object_instance);
00678         if(inst) {
00679             M2MResource *res = inst->resource(name_string);
00680             if (res) {
00681                 M2MResourceInstance *res_inst = res->resource_instance(resource_instance);
00682                 if(res_inst) {
00683                     if (res_inst->set_value((const uint8_t*)value_string.c_str(), value_string.size())) {
00684                         success = true;
00685                     }
00686                 }
00687             }
00688         }
00689     }
00690     return success;
00691 }
00692 
00693 bool M2MLWClient::test_register()
00694 {
00695     bool success = false;
00696     M2MObjectList object_list;
00697     if(_device) {
00698         object_list.push_back(_device);
00699     }
00700     if(_firmware) {
00701         object_list.push_back(_firmware);
00702     }
00703     if(_object) {
00704         object_list.push_back(_object);
00705     }
00706     if(_interface) {
00707         _interface->register_object(_register_security,object_list);
00708         success = true;
00709     }
00710     return success;
00711 }
00712 
00713 bool M2MLWClient::test_update_register(const uint32_t lifetime)
00714 {
00715     bool success = false;
00716     if(_interface && _register_security) {
00717         success = true;
00718         _interface->update_registration(_register_security,lifetime);
00719     }
00720     return success;
00721 }
00722 
00723 bool M2MLWClient::test_unregister()
00724 {
00725     bool success = false;
00726     if(_interface) {
00727          success = true;
00728         _interface->unregister_object(_register_security);
00729     }
00730     return success;
00731 }
00732 
00733 void M2MLWClient::bootstrap_done(M2MSecurity *server_object)
00734 {
00735     if(server_object) {
00736         _register_security = server_object;
00737         _bootstrapped = true;
00738         cmd_printf("\nBootstrapped\n");
00739         cmd_ready( CMDLINE_RETCODE_SUCCESS );
00740     }
00741 }
00742 
00743 void M2MLWClient::object_registered(M2MSecurity *security_object, const M2MServer &server_object)
00744 {
00745     _registered = true;
00746     cmd_printf("\nRegistered\n");
00747     cmd_ready( CMDLINE_RETCODE_SUCCESS );
00748 }
00749 
00750 void M2MLWClient::object_unregistered(M2MSecurity *server_object)
00751 {
00752     _unregistered = true;
00753     if(_device) {
00754         M2MDevice::delete_instance();
00755         _device = NULL;
00756     }
00757     if(_object) {
00758         delete _object;
00759         _object = NULL;
00760     }
00761     if(_security) {
00762         delete _security;
00763         _security = NULL;
00764     }
00765     if(_register_security) {
00766         delete _register_security;
00767         _register_security = NULL;
00768     }
00769     cmd_printf("\nUnregistered\n");
00770     cmd_ready( CMDLINE_RETCODE_SUCCESS );
00771 }
00772 
00773 void M2MLWClient::registration_updated(M2MSecurity *security_object,
00774                                        const M2MServer &server_object)
00775 {
00776     _registration_updated = true;
00777     cmd_printf("\nregistration updated\n");
00778     cmd_ready( CMDLINE_RETCODE_SUCCESS );
00779 }
00780 
00781 void M2MLWClient::error(M2MInterface::Error error)
00782 {
00783     _error = true;
00784     cmd_printf("\nError occured Error Code : %d\n", (int8_t)error);
00785     cmd_ready( CMDLINE_RETCODE_SUCCESS );
00786 }
00787 
00788 void M2MLWClient::value_updated(M2MBase *base, M2MBase::BaseType type)
00789 {
00790     cmd_printf("\nValue updated of Object name %s and Type \n",
00791                base->name().c_str(), type);
00792 }
00793 
00794 M2MBase::Operation M2MLWClient::int_to_operation(uint8_t operation)
00795 {
00796     M2MBase::Operation op = M2MBase::NOT_ALLOWED;
00797     switch(operation) {
00798         case 0:
00799             op = M2MBase::NOT_ALLOWED;
00800             break;
00801         case 1:
00802             op = M2MBase::GET_ALLOWED;
00803             break;
00804         case 2:
00805             op = M2MBase::PUT_ALLOWED;
00806             break;
00807         case 3:
00808             op = M2MBase::GET_PUT_ALLOWED;
00809             break;
00810         case 4:
00811             op = M2MBase::POST_ALLOWED;
00812             break;
00813         case 5:
00814             op = M2MBase::GET_POST_ALLOWED;
00815             break;
00816         case 6:
00817             op = M2MBase::PUT_POST_ALLOWED;
00818             break;
00819         case 7:
00820             op = M2MBase::GET_PUT_POST_ALLOWED;
00821             break;
00822         case 8:
00823             op = M2MBase::DELETE_ALLOWED;
00824             break;
00825         default:
00826             break;
00827     }
00828     return op;
00829 }
00830 
00831 void M2MLWClient::fw_execute_function(void *argument)
00832 {
00833     if(argument) {
00834         char* arguments = (char*)argument;
00835         cmd_printf("Received %s!!\n", arguments);
00836     }
00837     cmd_printf("Firmware update executed\n");
00838 }
00839 
00840 void M2MLWClient::firmware_resource_int(int resource)
00841 {
00842     cmd_printf("Firmware resource value int\n");
00843     cmd_printf("%ld\n", _firmware->resource_value_int(static_cast<M2MFirmware::FirmwareResource>(resource)));
00844 }
00845 
00846 void M2MLWClient::firmware_resource_string(int resource)
00847 {
00848     cmd_printf("Firmware resource value string\n");
00849     cmd_printf("%s\n", _firmware->resource_value_string(static_cast<M2MFirmware::FirmwareResource>(resource)).c_str());
00850 }
00851 
00852 void M2MLWClient::firmware_resource_buffer()
00853 {
00854     cmd_printf("Firmware resource value buffer\n");
00855     uint8_t *value = 0;
00856     uint32_t valueSize = _firmware->resource_value_buffer(M2MFirmware::Package, value);
00857     cmd_printf("%s\n", value);
00858     free(value);
00859 }