Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MAX44000 PWM_Tone_Library nexpaq_mdk
Fork of LED_Demo by
cmd_lwm2m.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 <string.h> 00017 #include <stdlib.h> 00018 #include <stdarg.h> 00019 00020 //libServices 00021 #include "ns_types.h" 00022 #include "ns_cmdline.h" 00023 #include "cmd_lwm2m.h" 00024 #include "lwm2mtest.h" 00025 00026 #define CMD_MAN_LWM2M_CLIENT "lwm2m-client <cmd> [options] LWM2M mbed Client API\n"\ 00027 "setup <p> [options] Set up the LWM2M Interface\n"\ 00028 "<p>:\n"\ 00029 " Options for setup command\n"\ 00030 " --endpoint <name> Endpoint Name (mandatory)\n"\ 00031 " --type <name> Resource Type\n"\ 00032 " --lifetime <n> Lifetime in seconds, default is -1 means not included\n"\ 00033 " --port <n> Listen port, default is 5683\n"\ 00034 " --domain <name> Domain for mbed Device Server, default is empty\n"\ 00035 " --binding_mode <n> Binding Mode, NOT_SET = 0|UDP = 1(default)|QUEUE = 2|SMS = 4\n"\ 00036 " --network_interface <n> Network Interface, Uninitialized = 0 ,LwIP_IPv4 = 1(default), LwIP_IPv6 = 2, Nanostack_IPv6 = 4\n"\ 00037 "bootstrap_object <p> [options]\n"\ 00038 "<p>:\n"\ 00039 " Options for bootstrap object command\n"\ 00040 " --address <name> Bootstrap server address, format is coap://192.168.0.1:5683\n"\ 00041 "bootstrap Issues Bootstrap command\n"\ 00042 "object <p> [options]\n"\ 00043 "<p>:\n"\ 00044 " Options for custom object\n"\ 00045 " --name <name> Object name\n"\ 00046 " --new_instance <n> If you need new instance 0=false(default), 1=true\n"\ 00047 " --object_observable <n> Object is observable false=0(default), true=1\n"\ 00048 " --object_instance_observable <n> Object Instance is observable false=0(default), true=1\n"\ 00049 " --object_instance_id <n> Instance id of object instance 0=(default)\n"\ 00050 " --object_operation <n> Operation Mode, Default is 0, NOT_ALLOWED = 0, GET_ALLOWED = 1,\n"\ 00051 "PUT_ALLOWED = 2, GET_PUT_ALLOWED = 3, POST_ALLOWED = 4,GET_POST_ALLOWED = 5,\n"\ 00052 "PUT_POST_ALLOWED = 6, GET_PUT_POST_ALLOWED = 7, DELETE_ALLOWED = 8\n"\ 00053 " --object_instance_operation <n> Operation Mode, Default is 0, NOT_ALLOWED = 0, GET_ALLOWED = 1,\n"\ 00054 "PUT_ALLOWED = 2, GET_PUT_ALLOWED = 3, POST_ALLOWED = 4,GET_POST_ALLOWED = 5,\n"\ 00055 "PUT_POST_ALLOWED = 6, GET_PUT_POST_ALLOWED = 7, DELETE_ALLOWED = 8\n"\ 00056 "static_resource <p> [options]\n"\ 00057 "<p>:\n"\ 00058 " Options for static resource\n"\ 00059 " --object_instance <n> Instance Id of the object this resource is associated with, default is 0\n"\ 00060 " --name <name> Resource name\n"\ 00061 " --value <name> Resource value\n"\ 00062 " --value_type <n> Value Type String=0, Integer=1\n"\ 00063 " --multiple_instance <n> Supports multiple instances, false=0(default), true=1\n"\ 00064 "dynamic_resource <p> [options]\n"\ 00065 "<p>:\n"\ 00066 " Options for dynamic resource\n"\ 00067 " --object_instance <n> Instance Id of the object this resource is associated with, default is 0\n"\ 00068 " --name <name> Resource name\n"\ 00069 " --observable <n> Resource is observable false=0(default), true=1\n"\ 00070 " --multiple_instance <n> Supports multiple instances, false=0(default), true=1\n"\ 00071 " --resource_operation <n> Operation Mode, Default is 1, NOT_ALLOWED = 0, GET_ALLOWED = 1,\n"\ 00072 "PUT_ALLOWED = 2, GET_PUT_ALLOWED = 3, POST_ALLOWED = 4,GET_POST_ALLOWED = 5,\n"\ 00073 "PUT_POST_ALLOWED = 6, GET_PUT_POST_ALLOWED = 7, DELETE_ALLOWED = 8\n"\ 00074 "dynamic_resource <p> [options]\n"\ 00075 "static_resource_instance <p> [options]\n"\ 00076 "<p>:\n"\ 00077 " Options for static resource instance\n"\ 00078 " --object_instance <n> Instance Id of the object this resource is associated with, default is 0\n"\ 00079 " --resource_instance <n> Instance Id of the resource associated with, default is 0\n"\ 00080 " --name <name> Resource name\n"\ 00081 " --value <name> Resource value\n"\ 00082 " --value_type <n> Value Type String=0, Integer=1\n"\ 00083 " --multiple_instance <n> Supports multiple instances, false=0(default), true=1\n"\ 00084 "dynamic_resource <p> [options]\n"\ 00085 "dynamic_resource_instance <p> [options]\n"\ 00086 "<p>:\n"\ 00087 " Options for dynamic resource instance\n"\ 00088 " --object_instance <n> Instance Id of the object this resource is associated with, default is 0\n"\ 00089 " --resource_instance <n> Instance Id of the resource associated with, default is 0\n"\ 00090 " --name <name> Resource name\n"\ 00091 " --value_type <n> Value Type String=0, Integer=1(default)\n"\ 00092 " --observable <n> Resource is observable false=0(default), true=1\n"\ 00093 " --multiple_instance <n> Supports multiple instances, false=0(default), true=1\n"\ 00094 " --resource_instance_operation <n> Operation Mode, Default is 1, NOT_ALLOWED = 0, GET_ALLOWED = 1,\n"\ 00095 "PUT_ALLOWED = 2, GET_PUT_ALLOWED = 3, POST_ALLOWED = 4,GET_POST_ALLOWED = 5,\n"\ 00096 "PUT_POST_ALLOWED = 6, GET_PUT_POST_ALLOWED = 7, DELETE_ALLOWED = 8\n"\ 00097 "dynamic_resource <p> [options]\n"\ 00098 "device <p> [options]\n"\ 00099 "<p>:\n"\ 00100 " Options for device object \n"\ 00101 " --manufacturer <name> Manufacturer name\n"\ 00102 " --model_number <name> Model number\n"\ 00103 " --serial_number <name> Serial number\n"\ 00104 " --device_type <name> Device Type\n"\ 00105 " --hardware_version <name> Hardware version\n"\ 00106 " --software_version <name> Software version\n"\ 00107 " --firmware_version <name> Firmware version\n"\ 00108 " --available_power_sources <n> Number of available power sources, Must have Instance ID\n"\ 00109 " --power_source_voltage <n> Power source voltage, Must have Instance ID\n"\ 00110 " --power_source_current <n> Power source current, Must have Instance ID\n"\ 00111 " --battery_level <n> Battery level\n"\ 00112 " --battery_status <n> Battery status\n"\ 00113 " --memory_free <n> Free memory, in bytes\n"\ 00114 " --memory_total <n> Free memory in bytes\n"\ 00115 " --error_code <n> Error Code, Must have Instance ID\n"\ 00116 " --current_time <n> Current Time, EPOCH format\n"\ 00117 " --utc_offset <name> UTC Format\n"\ 00118 " --timezone <name> Time zone \n"\ 00119 " --instance_id <n> Instance ID for multiple resources \n"\ 00120 "firmware <p> [options]\n"\ 00121 "<p>:\n"\ 00122 " Options for firmware object \n"\ 00123 " --package <name> Firmware package\n"\ 00124 " --package_uri <name> URI from where the device can download package\n"\ 00125 " --state <n> State of firmware update\n"\ 00126 " --update_supported_objects <bool> Send update registration message after fw update\n"\ 00127 " --update_results <n> Result of downloading or updating firmware\n"\ 00128 " --package_name <name> Package name\n"\ 00129 " --package_version <name> Package version\n"\ 00130 "register_object <p> [options]\n"\ 00131 "<p>:\n"\ 00132 " Options for register command\n"\ 00133 " --address <name> mbed Device Server address, format is coap://192.168.0.1:5683\n"\ 00134 " --secure <number> 1 == secure mode, non-secure otherwise (remember: secure port is 5684)\n"\ 00135 "register Issues Register command\n"\ 00136 "update-register <p> [options] Issues Update registration command\n"\ 00137 "<p>:\n"\ 00138 " Options for update-register command\n"\ 00139 " --lifetime <n> Lifetime value in seconds\n"\ 00140 "unregister Issues Un-register command\n"\ 00141 "set_value <p> [options]\n"\ 00142 "<p>:\n"\ 00143 " Options for set_value command \n"\ 00144 " --name <name> Resource name (Mandatory)\n"\ 00145 " --value <value> Resource value (Mandatory)\n"\ 00146 " --object_instance <n> Instance ID of object this resource is associated with, default is 0\n"\ 00147 "set_value_instance <p> [options]\n"\ 00148 "<p>:\n"\ 00149 " Options for set_value_instance command for Resource Instances\n"\ 00150 " --name <name> Resource name (Mandatory)\n"\ 00151 " --value <value> Resource value (Mandatory)\n"\ 00152 " --object_instance <n> Instance ID of object this resource is associated with, default is 0\n"\ 00153 " --resource_instance <n> Instance ID of object of the resource, default is 0\n"\ 00154 "resource_value <p> [options]\n"\ 00155 "<p>:\n"\ 00156 " Options for resource_value command\n"\ 00157 " --firmware <n> Resource instance id in Firmware object\n"\ 00158 00159 #define EXIT_MANUAL "exit :closes the application\n" 00160 00161 00162 int lwm2m_client_command(int argc, char *argv[]); 00163 int lwm2m_client_setup_command(int argc, char *argv[]); 00164 int lwm2m_client_device_command(int argc, char *argv[]); 00165 int lwm2m_client_object_command(int argc, char *argv[]); 00166 int lwm2m_client_static_resource_command(int argc, char *argv[]); 00167 int lwm2m_client_dynamic_resource_command(int argc, char *argv[]); 00168 int lwm2m_client_static_resource_instance_command(int argc, char *argv[]); 00169 int lwm2m_client_dynamic_resource_instance_command(int argc, char *argv[]); 00170 int lwm2m_client_bootstrap_object_command(int argc, char *argv[]); 00171 int lwm2m_client_bootstrap_command(); 00172 int lwm2m_client_register_object_command(int argc, char *argv[]); 00173 int lwm2m_client_register_command(); 00174 int lwm2m_client_update_register_command(int argc, char *argv[]); 00175 int lwm2m_client_unregister_command(); 00176 int lwm2m_client_set_value_command(int argc, char *argv[]); 00177 int lwm2m_client_set_value_instance_command(int argc, char *argv[]); 00178 int lwm2m_client_firmware_command(int argc, char *argv[]); 00179 int lwm2m_client_resource_value(int argc, char *argv[]); 00180 int exit_command(int argc, char *argv[]); 00181 00182 void lwm2m_command_init(void) 00183 { 00184 cmd_add("lwm2m-client", lwm2m_client_command, "LWM2M Client specific command", CMD_MAN_LWM2M_CLIENT); 00185 cmd_alias_add("lwm2m-client-test-setup", "lwm2m-client setup --endpoint lwm2m-endpoint --type test --lifetime 3600"); 00186 cmd_alias_add("lwm2m-client-test-device", "lwm2m-client device --manufacturer ARM --model_number 2015 --serial_number 12345"); 00187 cmd_alias_add("lwm2m-client-test-bootstrap-object", "lwm2m-client bootstrap_object --address coap://10.45.3.10:5693"); 00188 cmd_alias_add("lwm2m-client-test-register-object", "lwm2m-client register_object --address coap://10.45.3.10:5683"); 00189 cmd_alias_add("lwm2m-client-test-object", "lwm2m-client object --name 10 --object_observable 1 --object_instance_observable 1 --object_operation 3 --object_instance_operation 3"); 00190 cmd_alias_add("lwm2m-client-test-dynamic_resource", "lwm2m-client dynamic_resource --name 1 --resource_operation 3 --observable 0"); 00191 cmd_alias_add("lwm2m-client-test-secure-register-object", "lwm2m-client register_object --address coap://10.45.3.10:5684 --secure 1"); 00192 cmd_add("exit", exit_command, "exit command", EXIT_MANUAL); 00193 } 00194 char *test_mem_block = 0; 00195 int test_timer; 00196 M2MLWClient lwm2m_client; 00197 00198 int lwm2m_client_command(int argc, char *argv[]) 00199 { 00200 if( strcmp(argv[1], "setup") == 0 ) 00201 { 00202 return lwm2m_client_setup_command(argc, argv); 00203 } 00204 else if( strcmp(argv[1], "bootstrap_object") == 0 ) 00205 { 00206 return lwm2m_client_bootstrap_object_command(argc, argv); 00207 } 00208 else if( strcmp(argv[1], "bootstrap") == 0 ) 00209 { 00210 return lwm2m_client_bootstrap_command(); 00211 } 00212 else if( strcmp(argv[1], "device") == 0 ) 00213 { 00214 return lwm2m_client_device_command(argc, argv); 00215 } 00216 else if( strcmp(argv[1], "firmware") == 0 ) 00217 { 00218 return lwm2m_client_firmware_command(argc, argv); 00219 } 00220 else if( strcmp(argv[1], "resource_value") == 0 ) 00221 { 00222 return lwm2m_client_resource_value(argc, argv); 00223 } 00224 else if( strcmp(argv[1], "object") == 0 ) 00225 { 00226 return lwm2m_client_object_command(argc, argv); 00227 } 00228 else if( strcmp(argv[1], "static_resource") == 0 ) 00229 { 00230 return lwm2m_client_static_resource_command(argc, argv); 00231 } 00232 else if( strcmp(argv[1], "dynamic_resource") == 0 ) 00233 { 00234 return lwm2m_client_dynamic_resource_command(argc, argv); 00235 } 00236 else if( strcmp(argv[1], "static_resource_instance") == 0 ) 00237 { 00238 return lwm2m_client_static_resource_instance_command(argc, argv); 00239 } 00240 else if( strcmp(argv[1], "dynamic_resource_instance") == 0 ) 00241 { 00242 return lwm2m_client_dynamic_resource_instance_command(argc, argv); 00243 } 00244 else if( strcmp(argv[1], "register_object") == 0 ) 00245 { 00246 return lwm2m_client_register_object_command(argc, argv); 00247 } 00248 else if( strcmp(argv[1], "register") == 0 ) 00249 { 00250 return lwm2m_client_register_command(); 00251 } 00252 else if( strcmp(argv[1], "update-register") == 0 ) 00253 { 00254 return lwm2m_client_update_register_command(argc, argv); 00255 } 00256 else if( strcmp(argv[1], "unregister") == 0 ) 00257 { 00258 return lwm2m_client_unregister_command(); 00259 } 00260 else if ( strcmp(argv[1], "set_value") == 0) 00261 { 00262 return lwm2m_client_set_value_command(argc, argv); 00263 } 00264 else if ( strcmp(argv[1], "set_value_instance") == 0) 00265 { 00266 return lwm2m_client_set_value_instance_command(argc, argv); 00267 } 00268 //:TODO what another commands should be there ? 00269 return CMDLINE_RETCODE_COMMAND_NOT_IMPLEMENTED; 00270 } 00271 00272 int lwm2m_client_setup_command(int argc, char *argv[]) 00273 { 00274 char *endpoint = 0; 00275 char *type = 0; 00276 int lifetime = -1; 00277 int32_t port = 5683; 00278 char *domain = 0; 00279 int32_t binding_mode = 1; 00280 int32_t network_interface = 1; 00281 00282 if (!cmd_parameter_val(argc, argv, "--endpoint", &endpoint)) { 00283 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00284 } 00285 int opt_params = 0; 00286 cmd_parameter_val(argc, argv, "--type", &type); 00287 if (cmd_parameter_int(argc, argv, "--lifetime", &lifetime)) { 00288 if (opt_params != 0) { 00289 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00290 } 00291 else { 00292 opt_params += 1; 00293 } 00294 } 00295 if (cmd_parameter_int(argc, argv, "--port", &port)) { 00296 if (port > UINT16_MAX || opt_params != 1) { 00297 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00298 } 00299 else { 00300 opt_params += 1; 00301 } 00302 } 00303 if (cmd_parameter_val(argc, argv, "--domain", &domain)) { 00304 if (opt_params != 2) { 00305 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00306 } 00307 else { 00308 opt_params += 1; 00309 } 00310 } 00311 if (cmd_parameter_int(argc, argv, "--binding_mode", &binding_mode)) { 00312 if (opt_params != 3) { 00313 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00314 } 00315 else { 00316 opt_params += 1; 00317 } 00318 } 00319 if (cmd_parameter_int(argc, argv, "--network_interface", &network_interface)) { 00320 if (opt_params != 4) { 00321 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00322 } 00323 else { 00324 opt_params += 1; 00325 } 00326 } 00327 00328 bool success = false; 00329 if (lwm2m_client.create_interface(opt_params, 00330 endpoint, 00331 type, 00332 lifetime, 00333 port, 00334 domain, 00335 binding_mode, 00336 network_interface)) { 00337 return CMDLINE_RETCODE_SUCCESS; 00338 } 00339 00340 return CMDLINE_RETCODE_FAIL; 00341 } 00342 00343 int lwm2m_client_device_command(int argc, char *argv[]) 00344 { 00345 int return_code = CMDLINE_RETCODE_SUCCESS;// CMDLINE_RETCODE_INVALID_PARAMETERS; 00346 char *manufacturer = 0; 00347 char *model_number = 0; 00348 char *serial_number = 0; 00349 char *device_type = 0; 00350 char *hardware_version = 0; 00351 char *software_version = 0; 00352 char *firmware_version = 0; 00353 char *utc_offset = 0; 00354 char *timezone = 0; 00355 int32_t current_time = 0; 00356 int32_t available_power_sources = 0; 00357 int32_t power_source_voltage = 0; 00358 int32_t power_source_current = 0; 00359 int32_t battery_status = 0; 00360 int32_t battery_level = 0; 00361 int32_t memory_free = 0; 00362 int32_t memory_total = 0; 00363 int32_t error_code = 0; 00364 int32_t instance_id = 0; 00365 00366 lwm2m_client.create_device_object(); 00367 00368 if(cmd_parameter_val(argc, argv, "--manufacturer", &manufacturer)) { 00369 if(!lwm2m_client.create_device_object(M2MDevice::Manufacturer, 00370 manufacturer)) { 00371 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00372 } 00373 } 00374 if(cmd_parameter_val(argc, argv, "--model_number", &model_number)) { 00375 if(!lwm2m_client.create_device_object(M2MDevice::ModelNumber, 00376 model_number)) { 00377 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00378 } 00379 } 00380 if(cmd_parameter_val(argc, argv, "--serial_number", &serial_number)){ 00381 if(!lwm2m_client.create_device_object(M2MDevice::SerialNumber, 00382 serial_number)) { 00383 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00384 } 00385 } 00386 if(cmd_parameter_val(argc, argv, "--device_type", &device_type)){ 00387 if(!lwm2m_client.create_device_object(M2MDevice::DeviceType, 00388 device_type)) { 00389 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00390 } 00391 } 00392 if(cmd_parameter_val(argc, argv, "--hardware_version", &hardware_version)){ 00393 if(!lwm2m_client.create_device_object(M2MDevice::HardwareVersion, 00394 hardware_version)) { 00395 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00396 } 00397 } 00398 if(cmd_parameter_val(argc, argv, "--software_version", &software_version)){ 00399 if(!lwm2m_client.create_device_object(M2MDevice::SoftwareVersion, 00400 software_version)) { 00401 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00402 } 00403 } 00404 if(cmd_parameter_val(argc, argv, "--firmware_version", &firmware_version)){ 00405 if(!lwm2m_client.create_device_object(M2MDevice::FirmwareVersion, 00406 firmware_version)) { 00407 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00408 } 00409 } 00410 if(cmd_parameter_int(argc, argv, "--available_power_sources", &available_power_sources)){ 00411 if(cmd_parameter_int(argc, argv, "--instance_id", &instance_id)) { 00412 if(!lwm2m_client.create_device_object(M2MDevice::AvailablePowerSources, 00413 available_power_sources,instance_id)) { 00414 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00415 } 00416 } 00417 } 00418 if(cmd_parameter_int(argc, argv, "--power_source_voltage", &power_source_voltage)){ 00419 if(cmd_parameter_int(argc, argv, "--instance_id", &instance_id)) { 00420 if(!lwm2m_client.create_device_object(M2MDevice::PowerSourceVoltage, 00421 power_source_voltage,instance_id)) { 00422 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00423 } 00424 } 00425 } 00426 if(cmd_parameter_int(argc, argv, "--power_source_current", &power_source_current)){ 00427 if(cmd_parameter_int(argc, argv, "--instance_id", &instance_id)) { 00428 if(!lwm2m_client.create_device_object(M2MDevice::PowerSourceCurrent, 00429 power_source_current,instance_id)) { 00430 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00431 } 00432 } 00433 } 00434 if(cmd_parameter_int(argc, argv, "--battery_level", &battery_level)){ 00435 if(!lwm2m_client.create_device_object(M2MDevice::BatteryLevel, 00436 battery_level)) { 00437 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00438 } 00439 } 00440 if(cmd_parameter_int(argc, argv, "--battery_status", &battery_status)){ 00441 if(!lwm2m_client.create_device_object(M2MDevice::BatteryStatus, 00442 battery_status)) { 00443 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00444 } 00445 } 00446 if(cmd_parameter_int(argc, argv, "--memory_free", &memory_free)){ 00447 if(!lwm2m_client.create_device_object(M2MDevice::MemoryFree, 00448 memory_free)) { 00449 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00450 } 00451 } 00452 if(cmd_parameter_int(argc, argv, "--memory_total", &memory_total)){ 00453 if(!lwm2m_client.create_device_object(M2MDevice::MemoryTotal, 00454 memory_total)) { 00455 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00456 } 00457 } 00458 if(cmd_parameter_int(argc, argv, "--error_code", &error_code)){ 00459 if(cmd_parameter_int(argc, argv, "--instance_id", &instance_id)) { 00460 if(!lwm2m_client.create_device_object(M2MDevice::ErrorCode, 00461 error_code,instance_id)) { 00462 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00463 } 00464 } 00465 } 00466 if(cmd_parameter_int(argc, argv, "--current_time", ¤t_time)){ 00467 if(!lwm2m_client.create_device_object(M2MDevice::CurrentTime, 00468 current_time)) { 00469 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00470 } 00471 } 00472 if(cmd_parameter_val(argc, argv, "--utc_offset", &utc_offset)){ 00473 if(!lwm2m_client.create_device_object(M2MDevice::UTCOffset, 00474 utc_offset)) { 00475 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00476 } 00477 } 00478 if(cmd_parameter_val(argc, argv, "--timezone", &timezone)){ 00479 if(!lwm2m_client.create_device_object(M2MDevice::Timezone, 00480 timezone)) { 00481 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00482 } 00483 } 00484 00485 return return_code; 00486 } 00487 00488 int lwm2m_client_firmware_command(int argc, char *argv[]) 00489 { 00490 int return_code = CMDLINE_RETCODE_SUCCESS;// CMDLINE_RETCODE_INVALID_PARAMETERS; 00491 char *package = 0; 00492 char *package_uri = 0; 00493 char *package_name = 0; 00494 char *package_version = 0; 00495 int32_t state = 1; 00496 int32_t update_result = 0; 00497 int32_t update_supported_objects = 0; 00498 00499 lwm2m_client.create_firmware_object(); 00500 00501 if(cmd_parameter_val(argc, argv, "--package", &package)) { 00502 uint16_t length = (uint16_t)sizeof(package); 00503 if(!lwm2m_client.create_firmware_object(M2MFirmware::Package, 00504 (const uint8_t*)package, length)) { 00505 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00506 } 00507 } 00508 00509 if(cmd_parameter_val(argc, argv, "--package_uri", &package_uri)) { 00510 if(!lwm2m_client.create_firmware_object(M2MFirmware::PackageUri, 00511 package_uri)) { 00512 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00513 } 00514 } 00515 if(cmd_parameter_int(argc, argv, "--state", &state)) { 00516 if(!lwm2m_client.create_firmware_object(M2MFirmware::State, 00517 state)) { 00518 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00519 } 00520 } 00521 if(cmd_parameter_int(argc, argv, "--update_supported_objects", &update_supported_objects)) { 00522 if(!lwm2m_client.create_firmware_object(M2MFirmware::UpdateSupportedObjects, 00523 update_supported_objects)) { 00524 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00525 } 00526 } 00527 if(cmd_parameter_int(argc, argv, "--update_results", &update_result)) { 00528 if(!lwm2m_client.create_firmware_object(M2MFirmware::UpdateResult, 00529 update_result)) { 00530 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00531 } 00532 } 00533 if(cmd_parameter_val(argc, argv, "--package_name", &package_name)) { 00534 if(!lwm2m_client.create_firmware_object(M2MFirmware::PackageName, 00535 package_name)) { 00536 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00537 } 00538 } 00539 if(cmd_parameter_val(argc, argv, "--package_version", &package_version)) { 00540 if(!lwm2m_client.create_firmware_object(M2MFirmware::PackageVersion, 00541 package_version)) { 00542 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00543 } 00544 } 00545 lwm2m_client.set_fw_execute_function(); 00546 return return_code; 00547 } 00548 00549 int lwm2m_client_resource_value(int argc, char *argv[]) 00550 { 00551 int resource = 0; 00552 if(cmd_parameter_int(argc, argv, "--firmware", &resource)) { 00553 if (resource == 3 || resource == 4 || resource == 5) { 00554 lwm2m_client.firmware_resource_int(resource); 00555 } 00556 else if (resource == 0) { 00557 lwm2m_client.firmware_resource_buffer(); 00558 } 00559 else { 00560 lwm2m_client.firmware_resource_string(resource); 00561 } 00562 } 00563 return CMDLINE_RETCODE_SUCCESS; 00564 } 00565 00566 int lwm2m_client_object_command(int argc, char *argv[]) 00567 { 00568 int return_code = CMDLINE_RETCODE_SUCCESS;// CMDLINE_RETCODE_INVALID_PARAMETERS; 00569 char *object_name = 0; 00570 int32_t new_instance = 0; 00571 int32_t object_operation = 0; 00572 int32_t object_instance_operation = 0; 00573 int32_t object_instance_id = 0; 00574 int32_t object_observable = 0; 00575 int32_t object_instance_observable = 0; 00576 00577 if(cmd_parameter_val(argc, argv, "--name", &object_name)) { 00578 cmd_parameter_int(argc, argv, "--new_instance", &new_instance); 00579 cmd_parameter_int(argc, argv, "--object_operation", &object_operation); 00580 cmd_parameter_int(argc, argv, "--object_instance_operation", &object_instance_operation); 00581 cmd_parameter_int(argc, argv, "--object_instance_id", &object_instance_id); 00582 cmd_parameter_int(argc, argv, "--object_observable", &object_observable); 00583 cmd_parameter_int(argc, argv, "--object_instance_observable", &object_instance_observable); 00584 00585 if(!lwm2m_client.create_object(object_name, 00586 new_instance, 00587 object_operation, 00588 object_instance_operation, 00589 object_instance_id, 00590 object_observable, 00591 object_instance_observable)) { 00592 return_code = CMDLINE_RETCODE_INVALID_PARAMETERS; 00593 } 00594 } 00595 return return_code; 00596 } 00597 00598 int lwm2m_client_static_resource_command(int argc, char *argv[]) 00599 { 00600 int return_code = CMDLINE_RETCODE_INVALID_PARAMETERS; 00601 char *name = 0; 00602 char *value_string = 0; 00603 int32_t value_int = 0; 00604 int32_t value_type = -1; 00605 int32_t multiple_instance = 0; 00606 int32_t object_instance = 0; 00607 00608 cmd_parameter_int(argc, argv, "--multiple_instance", &multiple_instance); 00609 cmd_parameter_int(argc, argv, "--object_instance", &object_instance); 00610 00611 00612 if(cmd_parameter_int(argc, argv, "--value_type", &value_type)) { 00613 if(0 == value_type){ 00614 if(cmd_parameter_val(argc, argv, "--name", &name) && 00615 cmd_parameter_val(argc, argv, "--value", &value_string)) { 00616 if(lwm2m_client.create_static_resource_string(name,value_string, 00617 multiple_instance,object_instance)) { 00618 return_code = CMDLINE_RETCODE_SUCCESS; 00619 } 00620 } 00621 } else if(1 == value_type){ 00622 if(cmd_parameter_val(argc, argv, "--name", &name) && 00623 cmd_parameter_int(argc, argv, "--value", &value_int)) { 00624 if(lwm2m_client.create_static_resource_int(name,value_int, 00625 multiple_instance,object_instance)) { 00626 return_code = CMDLINE_RETCODE_SUCCESS; 00627 } 00628 } 00629 } 00630 } 00631 return return_code; 00632 } 00633 00634 int lwm2m_client_dynamic_resource_command(int argc, char *argv[]) 00635 { 00636 int return_code = CMDLINE_RETCODE_INVALID_PARAMETERS; 00637 char *name = 0; 00638 int32_t multiple_instance = 0; 00639 int32_t object_instance = 0; 00640 int32_t observable = 0; 00641 int32_t resource_operation = 1; 00642 int32_t value_type = -1; 00643 00644 cmd_parameter_int(argc, argv, "--value_type", &value_type); 00645 cmd_parameter_int(argc, argv, "--multiple_instance", &multiple_instance); 00646 cmd_parameter_int(argc, argv, "--object_instance", &object_instance); 00647 cmd_parameter_int(argc, argv, "--observable", &observable); 00648 cmd_parameter_int(argc, argv, "--resource_operation", &resource_operation); 00649 if(-1 == value_type){ 00650 value_type = 1; 00651 } 00652 00653 if(cmd_parameter_val(argc, argv, "--name", &name)) { 00654 if(0 == value_type) { 00655 if(lwm2m_client.create_dynamic_resource_string(name,observable, 00656 multiple_instance, 00657 object_instance, 00658 resource_operation)) { 00659 return_code = CMDLINE_RETCODE_SUCCESS; 00660 } 00661 } 00662 else if(1 == value_type){ 00663 if(lwm2m_client.create_dynamic_resource_int(name,observable, 00664 multiple_instance, 00665 object_instance, 00666 resource_operation)) { 00667 return_code = CMDLINE_RETCODE_SUCCESS; 00668 } 00669 } 00670 00671 } 00672 return return_code; 00673 } 00674 00675 int lwm2m_client_static_resource_instance_command(int argc, char *argv[]) 00676 { 00677 int return_code = CMDLINE_RETCODE_INVALID_PARAMETERS; 00678 char *name = 0; 00679 char *value_string = 0; 00680 int32_t value_int = 0; 00681 int32_t value_type = -1; 00682 int32_t multiple_instance = 0; 00683 int32_t object_instance = 0; 00684 int32_t resource_instance = 0; 00685 00686 cmd_parameter_int(argc, argv, "--multiple_instance", &multiple_instance); 00687 cmd_parameter_int(argc, argv, "--object_instance", &object_instance); 00688 cmd_parameter_int(argc, argv, "--resource_instance", &resource_instance); 00689 00690 if(cmd_parameter_int(argc, argv, "--value_type", &value_type)) { 00691 if(0 == value_type){ 00692 if(cmd_parameter_val(argc, argv, "--name", &name) && 00693 cmd_parameter_val(argc, argv, "--value", &value_string)) { 00694 if(lwm2m_client.create_static_resource_instance_string(name,value_string, 00695 multiple_instance, 00696 object_instance, 00697 resource_instance)) { 00698 return_code = CMDLINE_RETCODE_SUCCESS; 00699 } 00700 } 00701 } else if(1 == value_type){ 00702 if(cmd_parameter_val(argc, argv, "--name", &name) && 00703 cmd_parameter_int(argc, argv, "--value", &value_int)) { 00704 if(lwm2m_client.create_static_resource_instance_int(name,value_int, 00705 multiple_instance, 00706 object_instance, 00707 resource_instance)) { 00708 return_code = CMDLINE_RETCODE_SUCCESS; 00709 } 00710 } 00711 } 00712 } 00713 return return_code; 00714 } 00715 00716 int lwm2m_client_dynamic_resource_instance_command(int argc, char *argv[]) 00717 { 00718 int return_code = CMDLINE_RETCODE_INVALID_PARAMETERS; 00719 char *name = 0; 00720 int32_t multiple_instance = 0; 00721 int32_t object_instance = 0; 00722 int32_t resource_instance = 0; 00723 int32_t observable = 0; 00724 int32_t resource_instance_operation = 1; 00725 int32_t value_type = -1; 00726 00727 cmd_parameter_int(argc, argv, "--value_type", &value_type); 00728 cmd_parameter_int(argc, argv, "--multiple_instance", &multiple_instance); 00729 cmd_parameter_int(argc, argv, "--object_instance", &object_instance); 00730 cmd_parameter_int(argc, argv, "--resource_instance", &resource_instance); 00731 cmd_parameter_int(argc, argv, "--observable", &observable); 00732 cmd_parameter_int(argc, argv, "--resource_instance_operation", &resource_instance_operation); 00733 if(-1 == value_type){ 00734 value_type = 1; 00735 } 00736 00737 if(cmd_parameter_val(argc, argv, "--name", &name)) { 00738 if(0 == value_type){ 00739 if(lwm2m_client.create_dynamic_resource_instance_string(name,observable, 00740 multiple_instance, 00741 object_instance, 00742 resource_instance, 00743 resource_instance_operation)) { 00744 return_code = CMDLINE_RETCODE_SUCCESS; 00745 } 00746 } 00747 else if(1 == value_type){ 00748 if(lwm2m_client.create_dynamic_resource_instance_int(name,observable, 00749 multiple_instance, 00750 object_instance, 00751 resource_instance, 00752 resource_instance_operation)) { 00753 return_code = CMDLINE_RETCODE_SUCCESS; 00754 } 00755 } 00756 } 00757 return return_code; 00758 } 00759 00760 int lwm2m_client_bootstrap_object_command(int argc, char *argv[]) 00761 { 00762 int return_code = CMDLINE_RETCODE_FAIL; 00763 char *address = 0; 00764 00765 if( cmd_parameter_val(argc, argv, "--address", &address) ){ 00766 if(lwm2m_client.create_bootstrap_object(address)){ 00767 return_code = CMDLINE_RETCODE_SUCCESS; 00768 } 00769 } else { 00770 return_code = CMDLINE_RETCODE_INVALID_PARAMETERS; 00771 } 00772 return return_code; 00773 } 00774 00775 int lwm2m_client_bootstrap_command() 00776 { 00777 int return_code = CMDLINE_RETCODE_FAIL; 00778 00779 if(lwm2m_client.test_bootstrap()){ 00780 return_code = CMDLINE_RETCODE_EXCUTING_CONTINUE; 00781 } 00782 return return_code; 00783 } 00784 00785 int lwm2m_client_register_object_command(int argc, char *argv[]) 00786 { 00787 char *address = 0; 00788 cmd_parameter_val(argc, argv, "--address", &address); 00789 00790 int useSecureConn = 0; 00791 if( !cmd_parameter_int(argc, argv, "--secure", &useSecureConn) ){ 00792 useSecureConn = 0; 00793 } 00794 00795 if(lwm2m_client.create_register_object(address, useSecureConn == 1)) { 00796 return CMDLINE_RETCODE_SUCCESS; 00797 } 00798 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00799 } 00800 00801 int lwm2m_client_register_command() 00802 { 00803 if(lwm2m_client.test_register()) { 00804 return CMDLINE_RETCODE_EXCUTING_CONTINUE; 00805 } 00806 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00807 } 00808 00809 int lwm2m_client_update_register_command(int argc, char *argv[]) 00810 { 00811 int ret_code = CMDLINE_RETCODE_INVALID_PARAMETERS; 00812 int32_t lifetime = 0; 00813 00814 cmd_parameter_int(argc, argv, "--lifetime", &lifetime); 00815 00816 if(lifetime >= 0) { 00817 if(lwm2m_client.test_update_register(lifetime)) { 00818 ret_code = CMDLINE_RETCODE_EXCUTING_CONTINUE; 00819 } 00820 } 00821 return ret_code; 00822 } 00823 00824 int lwm2m_client_unregister_command() 00825 { 00826 if(lwm2m_client.test_unregister()) { 00827 return CMDLINE_RETCODE_EXCUTING_CONTINUE; 00828 } 00829 return CMDLINE_RETCODE_INVALID_PARAMETERS; 00830 } 00831 00832 int lwm2m_client_set_value_command(int argc, char *argv[]) 00833 { 00834 int return_code = CMDLINE_RETCODE_INVALID_PARAMETERS; 00835 char *name = 0; 00836 int32_t value = 0; 00837 int32_t object_instance = 0; 00838 00839 cmd_parameter_int(argc, argv, "--object_instance", &object_instance); 00840 00841 if(cmd_parameter_val(argc, argv, "--name", &name) && 00842 cmd_parameter_int(argc, argv, "--value", &value)) { 00843 if(lwm2m_client.set_resource_value(name,value,object_instance)) { 00844 return_code = CMDLINE_RETCODE_SUCCESS; 00845 } 00846 } 00847 return return_code; 00848 } 00849 00850 int lwm2m_client_set_value_instance_command(int argc, char *argv[]) 00851 { 00852 int return_code = CMDLINE_RETCODE_INVALID_PARAMETERS; 00853 char *name = 0; 00854 int32_t value = 0; 00855 int32_t object_instance = 0; 00856 int32_t resource_instance = 0; 00857 00858 cmd_parameter_int(argc, argv, "--object_instance", &object_instance); 00859 cmd_parameter_int(argc, argv, "--resource_instance", &resource_instance); 00860 00861 if(cmd_parameter_val(argc, argv, "--name", &name) && 00862 cmd_parameter_int(argc, argv, "--value", &value)) { 00863 if(lwm2m_client.set_resource_instance_value(name,value, 00864 object_instance, 00865 resource_instance)) { 00866 return_code = CMDLINE_RETCODE_SUCCESS; 00867 } 00868 } 00869 return return_code; 00870 } 00871 00872 int exit_command(int argc, char *argv[]) 00873 { 00874 exit(1); 00875 }
Generated on Tue Jul 12 2022 12:28:28 by
