Ram Gandikota
/
IOTMetronome
FRDM K64F Metronome
mbed-client/test/lwm2mtestapplication/cmd_lwm2m.cpp@0:dbad57390bd1, 2017-05-14 (annotated)
- Committer:
- ram54288
- Date:
- Sun May 14 18:37:05 2017 +0000
- Revision:
- 0:dbad57390bd1
Initial commit
Who changed what in which revision?
User | Revision | Line number | New 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 <string.h> |
ram54288 | 0:dbad57390bd1 | 17 | #include <stdlib.h> |
ram54288 | 0:dbad57390bd1 | 18 | #include <stdarg.h> |
ram54288 | 0:dbad57390bd1 | 19 | |
ram54288 | 0:dbad57390bd1 | 20 | //libServices |
ram54288 | 0:dbad57390bd1 | 21 | #include "ns_types.h" |
ram54288 | 0:dbad57390bd1 | 22 | #include "ns_cmdline.h" |
ram54288 | 0:dbad57390bd1 | 23 | #include "cmd_lwm2m.h" |
ram54288 | 0:dbad57390bd1 | 24 | #include "lwm2mtest.h" |
ram54288 | 0:dbad57390bd1 | 25 | |
ram54288 | 0:dbad57390bd1 | 26 | #define CMD_MAN_LWM2M_CLIENT "lwm2m-client <cmd> [options] LWM2M mbed Client API\n"\ |
ram54288 | 0:dbad57390bd1 | 27 | "setup <p> [options] Set up the LWM2M Interface\n"\ |
ram54288 | 0:dbad57390bd1 | 28 | "<p>:\n"\ |
ram54288 | 0:dbad57390bd1 | 29 | " Options for setup command\n"\ |
ram54288 | 0:dbad57390bd1 | 30 | " --endpoint <name> Endpoint Name (mandatory)\n"\ |
ram54288 | 0:dbad57390bd1 | 31 | " --type <name> Resource Type\n"\ |
ram54288 | 0:dbad57390bd1 | 32 | " --lifetime <n> Lifetime in seconds, default is -1 means not included\n"\ |
ram54288 | 0:dbad57390bd1 | 33 | " --port <n> Listen port, default is 5683\n"\ |
ram54288 | 0:dbad57390bd1 | 34 | " --domain <name> Domain for mbed Device Server, default is empty\n"\ |
ram54288 | 0:dbad57390bd1 | 35 | " --binding_mode <n> Binding Mode, NOT_SET = 0|UDP = 1(default)|QUEUE = 2|SMS = 4\n"\ |
ram54288 | 0:dbad57390bd1 | 36 | " --network_interface <n> Network Interface, Uninitialized = 0 ,LwIP_IPv4 = 1(default), LwIP_IPv6 = 2, Nanostack_IPv6 = 4\n"\ |
ram54288 | 0:dbad57390bd1 | 37 | "bootstrap_object <p> [options]\n"\ |
ram54288 | 0:dbad57390bd1 | 38 | "<p>:\n"\ |
ram54288 | 0:dbad57390bd1 | 39 | " Options for bootstrap object command\n"\ |
ram54288 | 0:dbad57390bd1 | 40 | " --address <name> Bootstrap server address, format is coap://192.168.0.1:5683\n"\ |
ram54288 | 0:dbad57390bd1 | 41 | "bootstrap Issues Bootstrap command\n"\ |
ram54288 | 0:dbad57390bd1 | 42 | "object <p> [options]\n"\ |
ram54288 | 0:dbad57390bd1 | 43 | "<p>:\n"\ |
ram54288 | 0:dbad57390bd1 | 44 | " Options for custom object\n"\ |
ram54288 | 0:dbad57390bd1 | 45 | " --name <name> Object name\n"\ |
ram54288 | 0:dbad57390bd1 | 46 | " --new_instance <n> If you need new instance 0=false(default), 1=true\n"\ |
ram54288 | 0:dbad57390bd1 | 47 | " --object_observable <n> Object is observable false=0(default), true=1\n"\ |
ram54288 | 0:dbad57390bd1 | 48 | " --object_instance_observable <n> Object Instance is observable false=0(default), true=1\n"\ |
ram54288 | 0:dbad57390bd1 | 49 | " --object_instance_id <n> Instance id of object instance 0=(default)\n"\ |
ram54288 | 0:dbad57390bd1 | 50 | " --object_operation <n> Operation Mode, Default is 0, NOT_ALLOWED = 0, GET_ALLOWED = 1,\n"\ |
ram54288 | 0:dbad57390bd1 | 51 | "PUT_ALLOWED = 2, GET_PUT_ALLOWED = 3, POST_ALLOWED = 4,GET_POST_ALLOWED = 5,\n"\ |
ram54288 | 0:dbad57390bd1 | 52 | "PUT_POST_ALLOWED = 6, GET_PUT_POST_ALLOWED = 7, DELETE_ALLOWED = 8\n"\ |
ram54288 | 0:dbad57390bd1 | 53 | " --object_instance_operation <n> Operation Mode, Default is 0, NOT_ALLOWED = 0, GET_ALLOWED = 1,\n"\ |
ram54288 | 0:dbad57390bd1 | 54 | "PUT_ALLOWED = 2, GET_PUT_ALLOWED = 3, POST_ALLOWED = 4,GET_POST_ALLOWED = 5,\n"\ |
ram54288 | 0:dbad57390bd1 | 55 | "PUT_POST_ALLOWED = 6, GET_PUT_POST_ALLOWED = 7, DELETE_ALLOWED = 8\n"\ |
ram54288 | 0:dbad57390bd1 | 56 | "static_resource <p> [options]\n"\ |
ram54288 | 0:dbad57390bd1 | 57 | "<p>:\n"\ |
ram54288 | 0:dbad57390bd1 | 58 | " Options for static resource\n"\ |
ram54288 | 0:dbad57390bd1 | 59 | " --object_instance <n> Instance Id of the object this resource is associated with, default is 0\n"\ |
ram54288 | 0:dbad57390bd1 | 60 | " --name <name> Resource name\n"\ |
ram54288 | 0:dbad57390bd1 | 61 | " --value <name> Resource value\n"\ |
ram54288 | 0:dbad57390bd1 | 62 | " --value_type <n> Value Type String=0, Integer=1\n"\ |
ram54288 | 0:dbad57390bd1 | 63 | " --multiple_instance <n> Supports multiple instances, false=0(default), true=1\n"\ |
ram54288 | 0:dbad57390bd1 | 64 | "dynamic_resource <p> [options]\n"\ |
ram54288 | 0:dbad57390bd1 | 65 | "<p>:\n"\ |
ram54288 | 0:dbad57390bd1 | 66 | " Options for dynamic resource\n"\ |
ram54288 | 0:dbad57390bd1 | 67 | " --object_instance <n> Instance Id of the object this resource is associated with, default is 0\n"\ |
ram54288 | 0:dbad57390bd1 | 68 | " --name <name> Resource name\n"\ |
ram54288 | 0:dbad57390bd1 | 69 | " --observable <n> Resource is observable false=0(default), true=1\n"\ |
ram54288 | 0:dbad57390bd1 | 70 | " --multiple_instance <n> Supports multiple instances, false=0(default), true=1\n"\ |
ram54288 | 0:dbad57390bd1 | 71 | " --resource_operation <n> Operation Mode, Default is 1, NOT_ALLOWED = 0, GET_ALLOWED = 1,\n"\ |
ram54288 | 0:dbad57390bd1 | 72 | "PUT_ALLOWED = 2, GET_PUT_ALLOWED = 3, POST_ALLOWED = 4,GET_POST_ALLOWED = 5,\n"\ |
ram54288 | 0:dbad57390bd1 | 73 | "PUT_POST_ALLOWED = 6, GET_PUT_POST_ALLOWED = 7, DELETE_ALLOWED = 8\n"\ |
ram54288 | 0:dbad57390bd1 | 74 | "dynamic_resource <p> [options]\n"\ |
ram54288 | 0:dbad57390bd1 | 75 | "static_resource_instance <p> [options]\n"\ |
ram54288 | 0:dbad57390bd1 | 76 | "<p>:\n"\ |
ram54288 | 0:dbad57390bd1 | 77 | " Options for static resource instance\n"\ |
ram54288 | 0:dbad57390bd1 | 78 | " --object_instance <n> Instance Id of the object this resource is associated with, default is 0\n"\ |
ram54288 | 0:dbad57390bd1 | 79 | " --resource_instance <n> Instance Id of the resource associated with, default is 0\n"\ |
ram54288 | 0:dbad57390bd1 | 80 | " --name <name> Resource name\n"\ |
ram54288 | 0:dbad57390bd1 | 81 | " --value <name> Resource value\n"\ |
ram54288 | 0:dbad57390bd1 | 82 | " --value_type <n> Value Type String=0, Integer=1\n"\ |
ram54288 | 0:dbad57390bd1 | 83 | " --multiple_instance <n> Supports multiple instances, false=0(default), true=1\n"\ |
ram54288 | 0:dbad57390bd1 | 84 | "dynamic_resource <p> [options]\n"\ |
ram54288 | 0:dbad57390bd1 | 85 | "dynamic_resource_instance <p> [options]\n"\ |
ram54288 | 0:dbad57390bd1 | 86 | "<p>:\n"\ |
ram54288 | 0:dbad57390bd1 | 87 | " Options for dynamic resource instance\n"\ |
ram54288 | 0:dbad57390bd1 | 88 | " --object_instance <n> Instance Id of the object this resource is associated with, default is 0\n"\ |
ram54288 | 0:dbad57390bd1 | 89 | " --resource_instance <n> Instance Id of the resource associated with, default is 0\n"\ |
ram54288 | 0:dbad57390bd1 | 90 | " --name <name> Resource name\n"\ |
ram54288 | 0:dbad57390bd1 | 91 | " --value_type <n> Value Type String=0, Integer=1(default)\n"\ |
ram54288 | 0:dbad57390bd1 | 92 | " --observable <n> Resource is observable false=0(default), true=1\n"\ |
ram54288 | 0:dbad57390bd1 | 93 | " --multiple_instance <n> Supports multiple instances, false=0(default), true=1\n"\ |
ram54288 | 0:dbad57390bd1 | 94 | " --resource_instance_operation <n> Operation Mode, Default is 1, NOT_ALLOWED = 0, GET_ALLOWED = 1,\n"\ |
ram54288 | 0:dbad57390bd1 | 95 | "PUT_ALLOWED = 2, GET_PUT_ALLOWED = 3, POST_ALLOWED = 4,GET_POST_ALLOWED = 5,\n"\ |
ram54288 | 0:dbad57390bd1 | 96 | "PUT_POST_ALLOWED = 6, GET_PUT_POST_ALLOWED = 7, DELETE_ALLOWED = 8\n"\ |
ram54288 | 0:dbad57390bd1 | 97 | "dynamic_resource <p> [options]\n"\ |
ram54288 | 0:dbad57390bd1 | 98 | "device <p> [options]\n"\ |
ram54288 | 0:dbad57390bd1 | 99 | "<p>:\n"\ |
ram54288 | 0:dbad57390bd1 | 100 | " Options for device object \n"\ |
ram54288 | 0:dbad57390bd1 | 101 | " --manufacturer <name> Manufacturer name\n"\ |
ram54288 | 0:dbad57390bd1 | 102 | " --model_number <name> Model number\n"\ |
ram54288 | 0:dbad57390bd1 | 103 | " --serial_number <name> Serial number\n"\ |
ram54288 | 0:dbad57390bd1 | 104 | " --device_type <name> Device Type\n"\ |
ram54288 | 0:dbad57390bd1 | 105 | " --hardware_version <name> Hardware version\n"\ |
ram54288 | 0:dbad57390bd1 | 106 | " --software_version <name> Software version\n"\ |
ram54288 | 0:dbad57390bd1 | 107 | " --firmware_version <name> Firmware version\n"\ |
ram54288 | 0:dbad57390bd1 | 108 | " --available_power_sources <n> Number of available power sources, Must have Instance ID\n"\ |
ram54288 | 0:dbad57390bd1 | 109 | " --power_source_voltage <n> Power source voltage, Must have Instance ID\n"\ |
ram54288 | 0:dbad57390bd1 | 110 | " --power_source_current <n> Power source current, Must have Instance ID\n"\ |
ram54288 | 0:dbad57390bd1 | 111 | " --battery_level <n> Battery level\n"\ |
ram54288 | 0:dbad57390bd1 | 112 | " --battery_status <n> Battery status\n"\ |
ram54288 | 0:dbad57390bd1 | 113 | " --memory_free <n> Free memory, in bytes\n"\ |
ram54288 | 0:dbad57390bd1 | 114 | " --memory_total <n> Free memory in bytes\n"\ |
ram54288 | 0:dbad57390bd1 | 115 | " --error_code <n> Error Code, Must have Instance ID\n"\ |
ram54288 | 0:dbad57390bd1 | 116 | " --current_time <n> Current Time, EPOCH format\n"\ |
ram54288 | 0:dbad57390bd1 | 117 | " --utc_offset <name> UTC Format\n"\ |
ram54288 | 0:dbad57390bd1 | 118 | " --timezone <name> Time zone \n"\ |
ram54288 | 0:dbad57390bd1 | 119 | " --instance_id <n> Instance ID for multiple resources \n"\ |
ram54288 | 0:dbad57390bd1 | 120 | "firmware <p> [options]\n"\ |
ram54288 | 0:dbad57390bd1 | 121 | "<p>:\n"\ |
ram54288 | 0:dbad57390bd1 | 122 | " Options for firmware object \n"\ |
ram54288 | 0:dbad57390bd1 | 123 | " --package <name> Firmware package\n"\ |
ram54288 | 0:dbad57390bd1 | 124 | " --package_uri <name> URI from where the device can download package\n"\ |
ram54288 | 0:dbad57390bd1 | 125 | " --state <n> State of firmware update\n"\ |
ram54288 | 0:dbad57390bd1 | 126 | " --update_supported_objects <bool> Send update registration message after fw update\n"\ |
ram54288 | 0:dbad57390bd1 | 127 | " --update_results <n> Result of downloading or updating firmware\n"\ |
ram54288 | 0:dbad57390bd1 | 128 | " --package_name <name> Package name\n"\ |
ram54288 | 0:dbad57390bd1 | 129 | " --package_version <name> Package version\n"\ |
ram54288 | 0:dbad57390bd1 | 130 | "register_object <p> [options]\n"\ |
ram54288 | 0:dbad57390bd1 | 131 | "<p>:\n"\ |
ram54288 | 0:dbad57390bd1 | 132 | " Options for register command\n"\ |
ram54288 | 0:dbad57390bd1 | 133 | " --address <name> mbed Device Server address, format is coap://192.168.0.1:5683\n"\ |
ram54288 | 0:dbad57390bd1 | 134 | " --secure <number> 1 == secure mode, non-secure otherwise (remember: secure port is 5684)\n"\ |
ram54288 | 0:dbad57390bd1 | 135 | "register Issues Register command\n"\ |
ram54288 | 0:dbad57390bd1 | 136 | "update-register <p> [options] Issues Update registration command\n"\ |
ram54288 | 0:dbad57390bd1 | 137 | "<p>:\n"\ |
ram54288 | 0:dbad57390bd1 | 138 | " Options for update-register command\n"\ |
ram54288 | 0:dbad57390bd1 | 139 | " --lifetime <n> Lifetime value in seconds\n"\ |
ram54288 | 0:dbad57390bd1 | 140 | "unregister Issues Un-register command\n"\ |
ram54288 | 0:dbad57390bd1 | 141 | "set_value <p> [options]\n"\ |
ram54288 | 0:dbad57390bd1 | 142 | "<p>:\n"\ |
ram54288 | 0:dbad57390bd1 | 143 | " Options for set_value command \n"\ |
ram54288 | 0:dbad57390bd1 | 144 | " --name <name> Resource name (Mandatory)\n"\ |
ram54288 | 0:dbad57390bd1 | 145 | " --value <value> Resource value (Mandatory)\n"\ |
ram54288 | 0:dbad57390bd1 | 146 | " --object_instance <n> Instance ID of object this resource is associated with, default is 0\n"\ |
ram54288 | 0:dbad57390bd1 | 147 | "set_value_instance <p> [options]\n"\ |
ram54288 | 0:dbad57390bd1 | 148 | "<p>:\n"\ |
ram54288 | 0:dbad57390bd1 | 149 | " Options for set_value_instance command for Resource Instances\n"\ |
ram54288 | 0:dbad57390bd1 | 150 | " --name <name> Resource name (Mandatory)\n"\ |
ram54288 | 0:dbad57390bd1 | 151 | " --value <value> Resource value (Mandatory)\n"\ |
ram54288 | 0:dbad57390bd1 | 152 | " --object_instance <n> Instance ID of object this resource is associated with, default is 0\n"\ |
ram54288 | 0:dbad57390bd1 | 153 | " --resource_instance <n> Instance ID of object of the resource, default is 0\n"\ |
ram54288 | 0:dbad57390bd1 | 154 | "resource_value <p> [options]\n"\ |
ram54288 | 0:dbad57390bd1 | 155 | "<p>:\n"\ |
ram54288 | 0:dbad57390bd1 | 156 | " Options for resource_value command\n"\ |
ram54288 | 0:dbad57390bd1 | 157 | " --firmware <n> Resource instance id in Firmware object\n"\ |
ram54288 | 0:dbad57390bd1 | 158 | |
ram54288 | 0:dbad57390bd1 | 159 | #define EXIT_MANUAL "exit :closes the application\n" |
ram54288 | 0:dbad57390bd1 | 160 | |
ram54288 | 0:dbad57390bd1 | 161 | |
ram54288 | 0:dbad57390bd1 | 162 | int lwm2m_client_command(int argc, char *argv[]); |
ram54288 | 0:dbad57390bd1 | 163 | int lwm2m_client_setup_command(int argc, char *argv[]); |
ram54288 | 0:dbad57390bd1 | 164 | int lwm2m_client_device_command(int argc, char *argv[]); |
ram54288 | 0:dbad57390bd1 | 165 | int lwm2m_client_object_command(int argc, char *argv[]); |
ram54288 | 0:dbad57390bd1 | 166 | int lwm2m_client_static_resource_command(int argc, char *argv[]); |
ram54288 | 0:dbad57390bd1 | 167 | int lwm2m_client_dynamic_resource_command(int argc, char *argv[]); |
ram54288 | 0:dbad57390bd1 | 168 | int lwm2m_client_static_resource_instance_command(int argc, char *argv[]); |
ram54288 | 0:dbad57390bd1 | 169 | int lwm2m_client_dynamic_resource_instance_command(int argc, char *argv[]); |
ram54288 | 0:dbad57390bd1 | 170 | int lwm2m_client_bootstrap_object_command(int argc, char *argv[]); |
ram54288 | 0:dbad57390bd1 | 171 | int lwm2m_client_bootstrap_command(); |
ram54288 | 0:dbad57390bd1 | 172 | int lwm2m_client_register_object_command(int argc, char *argv[]); |
ram54288 | 0:dbad57390bd1 | 173 | int lwm2m_client_register_command(); |
ram54288 | 0:dbad57390bd1 | 174 | int lwm2m_client_update_register_command(int argc, char *argv[]); |
ram54288 | 0:dbad57390bd1 | 175 | int lwm2m_client_unregister_command(); |
ram54288 | 0:dbad57390bd1 | 176 | int lwm2m_client_set_value_command(int argc, char *argv[]); |
ram54288 | 0:dbad57390bd1 | 177 | int lwm2m_client_set_value_instance_command(int argc, char *argv[]); |
ram54288 | 0:dbad57390bd1 | 178 | int lwm2m_client_firmware_command(int argc, char *argv[]); |
ram54288 | 0:dbad57390bd1 | 179 | int lwm2m_client_resource_value(int argc, char *argv[]); |
ram54288 | 0:dbad57390bd1 | 180 | int exit_command(int argc, char *argv[]); |
ram54288 | 0:dbad57390bd1 | 181 | |
ram54288 | 0:dbad57390bd1 | 182 | void lwm2m_command_init(void) |
ram54288 | 0:dbad57390bd1 | 183 | { |
ram54288 | 0:dbad57390bd1 | 184 | cmd_add("lwm2m-client", lwm2m_client_command, "LWM2M Client specific command", CMD_MAN_LWM2M_CLIENT); |
ram54288 | 0:dbad57390bd1 | 185 | cmd_alias_add("lwm2m-client-test-setup", "lwm2m-client setup --endpoint lwm2m-endpoint --type test --lifetime 3600"); |
ram54288 | 0:dbad57390bd1 | 186 | cmd_alias_add("lwm2m-client-test-device", "lwm2m-client device --manufacturer ARM --model_number 2015 --serial_number 12345"); |
ram54288 | 0:dbad57390bd1 | 187 | cmd_alias_add("lwm2m-client-test-bootstrap-object", "lwm2m-client bootstrap_object --address coap://10.45.3.10:5693"); |
ram54288 | 0:dbad57390bd1 | 188 | cmd_alias_add("lwm2m-client-test-register-object", "lwm2m-client register_object --address coap://10.45.3.10:5683"); |
ram54288 | 0:dbad57390bd1 | 189 | 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"); |
ram54288 | 0:dbad57390bd1 | 190 | cmd_alias_add("lwm2m-client-test-dynamic_resource", "lwm2m-client dynamic_resource --name 1 --resource_operation 3 --observable 0"); |
ram54288 | 0:dbad57390bd1 | 191 | cmd_alias_add("lwm2m-client-test-secure-register-object", "lwm2m-client register_object --address coap://10.45.3.10:5684 --secure 1"); |
ram54288 | 0:dbad57390bd1 | 192 | cmd_add("exit", exit_command, "exit command", EXIT_MANUAL); |
ram54288 | 0:dbad57390bd1 | 193 | } |
ram54288 | 0:dbad57390bd1 | 194 | char *test_mem_block = 0; |
ram54288 | 0:dbad57390bd1 | 195 | int test_timer; |
ram54288 | 0:dbad57390bd1 | 196 | M2MLWClient lwm2m_client; |
ram54288 | 0:dbad57390bd1 | 197 | |
ram54288 | 0:dbad57390bd1 | 198 | int lwm2m_client_command(int argc, char *argv[]) |
ram54288 | 0:dbad57390bd1 | 199 | { |
ram54288 | 0:dbad57390bd1 | 200 | if( strcmp(argv[1], "setup") == 0 ) |
ram54288 | 0:dbad57390bd1 | 201 | { |
ram54288 | 0:dbad57390bd1 | 202 | return lwm2m_client_setup_command(argc, argv); |
ram54288 | 0:dbad57390bd1 | 203 | } |
ram54288 | 0:dbad57390bd1 | 204 | else if( strcmp(argv[1], "bootstrap_object") == 0 ) |
ram54288 | 0:dbad57390bd1 | 205 | { |
ram54288 | 0:dbad57390bd1 | 206 | return lwm2m_client_bootstrap_object_command(argc, argv); |
ram54288 | 0:dbad57390bd1 | 207 | } |
ram54288 | 0:dbad57390bd1 | 208 | else if( strcmp(argv[1], "bootstrap") == 0 ) |
ram54288 | 0:dbad57390bd1 | 209 | { |
ram54288 | 0:dbad57390bd1 | 210 | return lwm2m_client_bootstrap_command(); |
ram54288 | 0:dbad57390bd1 | 211 | } |
ram54288 | 0:dbad57390bd1 | 212 | else if( strcmp(argv[1], "device") == 0 ) |
ram54288 | 0:dbad57390bd1 | 213 | { |
ram54288 | 0:dbad57390bd1 | 214 | return lwm2m_client_device_command(argc, argv); |
ram54288 | 0:dbad57390bd1 | 215 | } |
ram54288 | 0:dbad57390bd1 | 216 | else if( strcmp(argv[1], "firmware") == 0 ) |
ram54288 | 0:dbad57390bd1 | 217 | { |
ram54288 | 0:dbad57390bd1 | 218 | return lwm2m_client_firmware_command(argc, argv); |
ram54288 | 0:dbad57390bd1 | 219 | } |
ram54288 | 0:dbad57390bd1 | 220 | else if( strcmp(argv[1], "resource_value") == 0 ) |
ram54288 | 0:dbad57390bd1 | 221 | { |
ram54288 | 0:dbad57390bd1 | 222 | return lwm2m_client_resource_value(argc, argv); |
ram54288 | 0:dbad57390bd1 | 223 | } |
ram54288 | 0:dbad57390bd1 | 224 | else if( strcmp(argv[1], "object") == 0 ) |
ram54288 | 0:dbad57390bd1 | 225 | { |
ram54288 | 0:dbad57390bd1 | 226 | return lwm2m_client_object_command(argc, argv); |
ram54288 | 0:dbad57390bd1 | 227 | } |
ram54288 | 0:dbad57390bd1 | 228 | else if( strcmp(argv[1], "static_resource") == 0 ) |
ram54288 | 0:dbad57390bd1 | 229 | { |
ram54288 | 0:dbad57390bd1 | 230 | return lwm2m_client_static_resource_command(argc, argv); |
ram54288 | 0:dbad57390bd1 | 231 | } |
ram54288 | 0:dbad57390bd1 | 232 | else if( strcmp(argv[1], "dynamic_resource") == 0 ) |
ram54288 | 0:dbad57390bd1 | 233 | { |
ram54288 | 0:dbad57390bd1 | 234 | return lwm2m_client_dynamic_resource_command(argc, argv); |
ram54288 | 0:dbad57390bd1 | 235 | } |
ram54288 | 0:dbad57390bd1 | 236 | else if( strcmp(argv[1], "static_resource_instance") == 0 ) |
ram54288 | 0:dbad57390bd1 | 237 | { |
ram54288 | 0:dbad57390bd1 | 238 | return lwm2m_client_static_resource_instance_command(argc, argv); |
ram54288 | 0:dbad57390bd1 | 239 | } |
ram54288 | 0:dbad57390bd1 | 240 | else if( strcmp(argv[1], "dynamic_resource_instance") == 0 ) |
ram54288 | 0:dbad57390bd1 | 241 | { |
ram54288 | 0:dbad57390bd1 | 242 | return lwm2m_client_dynamic_resource_instance_command(argc, argv); |
ram54288 | 0:dbad57390bd1 | 243 | } |
ram54288 | 0:dbad57390bd1 | 244 | else if( strcmp(argv[1], "register_object") == 0 ) |
ram54288 | 0:dbad57390bd1 | 245 | { |
ram54288 | 0:dbad57390bd1 | 246 | return lwm2m_client_register_object_command(argc, argv); |
ram54288 | 0:dbad57390bd1 | 247 | } |
ram54288 | 0:dbad57390bd1 | 248 | else if( strcmp(argv[1], "register") == 0 ) |
ram54288 | 0:dbad57390bd1 | 249 | { |
ram54288 | 0:dbad57390bd1 | 250 | return lwm2m_client_register_command(); |
ram54288 | 0:dbad57390bd1 | 251 | } |
ram54288 | 0:dbad57390bd1 | 252 | else if( strcmp(argv[1], "update-register") == 0 ) |
ram54288 | 0:dbad57390bd1 | 253 | { |
ram54288 | 0:dbad57390bd1 | 254 | return lwm2m_client_update_register_command(argc, argv); |
ram54288 | 0:dbad57390bd1 | 255 | } |
ram54288 | 0:dbad57390bd1 | 256 | else if( strcmp(argv[1], "unregister") == 0 ) |
ram54288 | 0:dbad57390bd1 | 257 | { |
ram54288 | 0:dbad57390bd1 | 258 | return lwm2m_client_unregister_command(); |
ram54288 | 0:dbad57390bd1 | 259 | } |
ram54288 | 0:dbad57390bd1 | 260 | else if ( strcmp(argv[1], "set_value") == 0) |
ram54288 | 0:dbad57390bd1 | 261 | { |
ram54288 | 0:dbad57390bd1 | 262 | return lwm2m_client_set_value_command(argc, argv); |
ram54288 | 0:dbad57390bd1 | 263 | } |
ram54288 | 0:dbad57390bd1 | 264 | else if ( strcmp(argv[1], "set_value_instance") == 0) |
ram54288 | 0:dbad57390bd1 | 265 | { |
ram54288 | 0:dbad57390bd1 | 266 | return lwm2m_client_set_value_instance_command(argc, argv); |
ram54288 | 0:dbad57390bd1 | 267 | } |
ram54288 | 0:dbad57390bd1 | 268 | //:TODO what another commands should be there ? |
ram54288 | 0:dbad57390bd1 | 269 | return CMDLINE_RETCODE_COMMAND_NOT_IMPLEMENTED; |
ram54288 | 0:dbad57390bd1 | 270 | } |
ram54288 | 0:dbad57390bd1 | 271 | |
ram54288 | 0:dbad57390bd1 | 272 | int lwm2m_client_setup_command(int argc, char *argv[]) |
ram54288 | 0:dbad57390bd1 | 273 | { |
ram54288 | 0:dbad57390bd1 | 274 | char *endpoint = 0; |
ram54288 | 0:dbad57390bd1 | 275 | char *type = 0; |
ram54288 | 0:dbad57390bd1 | 276 | int lifetime = -1; |
ram54288 | 0:dbad57390bd1 | 277 | int32_t port = 5683; |
ram54288 | 0:dbad57390bd1 | 278 | char *domain = 0; |
ram54288 | 0:dbad57390bd1 | 279 | int32_t binding_mode = 1; |
ram54288 | 0:dbad57390bd1 | 280 | int32_t network_interface = 1; |
ram54288 | 0:dbad57390bd1 | 281 | |
ram54288 | 0:dbad57390bd1 | 282 | if (!cmd_parameter_val(argc, argv, "--endpoint", &endpoint)) { |
ram54288 | 0:dbad57390bd1 | 283 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 284 | } |
ram54288 | 0:dbad57390bd1 | 285 | int opt_params = 0; |
ram54288 | 0:dbad57390bd1 | 286 | cmd_parameter_val(argc, argv, "--type", &type); |
ram54288 | 0:dbad57390bd1 | 287 | if (cmd_parameter_int(argc, argv, "--lifetime", &lifetime)) { |
ram54288 | 0:dbad57390bd1 | 288 | if (opt_params != 0) { |
ram54288 | 0:dbad57390bd1 | 289 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 290 | } |
ram54288 | 0:dbad57390bd1 | 291 | else { |
ram54288 | 0:dbad57390bd1 | 292 | opt_params += 1; |
ram54288 | 0:dbad57390bd1 | 293 | } |
ram54288 | 0:dbad57390bd1 | 294 | } |
ram54288 | 0:dbad57390bd1 | 295 | if (cmd_parameter_int(argc, argv, "--port", &port)) { |
ram54288 | 0:dbad57390bd1 | 296 | if (port > UINT16_MAX || opt_params != 1) { |
ram54288 | 0:dbad57390bd1 | 297 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 298 | } |
ram54288 | 0:dbad57390bd1 | 299 | else { |
ram54288 | 0:dbad57390bd1 | 300 | opt_params += 1; |
ram54288 | 0:dbad57390bd1 | 301 | } |
ram54288 | 0:dbad57390bd1 | 302 | } |
ram54288 | 0:dbad57390bd1 | 303 | if (cmd_parameter_val(argc, argv, "--domain", &domain)) { |
ram54288 | 0:dbad57390bd1 | 304 | if (opt_params != 2) { |
ram54288 | 0:dbad57390bd1 | 305 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 306 | } |
ram54288 | 0:dbad57390bd1 | 307 | else { |
ram54288 | 0:dbad57390bd1 | 308 | opt_params += 1; |
ram54288 | 0:dbad57390bd1 | 309 | } |
ram54288 | 0:dbad57390bd1 | 310 | } |
ram54288 | 0:dbad57390bd1 | 311 | if (cmd_parameter_int(argc, argv, "--binding_mode", &binding_mode)) { |
ram54288 | 0:dbad57390bd1 | 312 | if (opt_params != 3) { |
ram54288 | 0:dbad57390bd1 | 313 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 314 | } |
ram54288 | 0:dbad57390bd1 | 315 | else { |
ram54288 | 0:dbad57390bd1 | 316 | opt_params += 1; |
ram54288 | 0:dbad57390bd1 | 317 | } |
ram54288 | 0:dbad57390bd1 | 318 | } |
ram54288 | 0:dbad57390bd1 | 319 | if (cmd_parameter_int(argc, argv, "--network_interface", &network_interface)) { |
ram54288 | 0:dbad57390bd1 | 320 | if (opt_params != 4) { |
ram54288 | 0:dbad57390bd1 | 321 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 322 | } |
ram54288 | 0:dbad57390bd1 | 323 | else { |
ram54288 | 0:dbad57390bd1 | 324 | opt_params += 1; |
ram54288 | 0:dbad57390bd1 | 325 | } |
ram54288 | 0:dbad57390bd1 | 326 | } |
ram54288 | 0:dbad57390bd1 | 327 | |
ram54288 | 0:dbad57390bd1 | 328 | bool success = false; |
ram54288 | 0:dbad57390bd1 | 329 | if (lwm2m_client.create_interface(opt_params, |
ram54288 | 0:dbad57390bd1 | 330 | endpoint, |
ram54288 | 0:dbad57390bd1 | 331 | type, |
ram54288 | 0:dbad57390bd1 | 332 | lifetime, |
ram54288 | 0:dbad57390bd1 | 333 | port, |
ram54288 | 0:dbad57390bd1 | 334 | domain, |
ram54288 | 0:dbad57390bd1 | 335 | binding_mode, |
ram54288 | 0:dbad57390bd1 | 336 | network_interface)) { |
ram54288 | 0:dbad57390bd1 | 337 | return CMDLINE_RETCODE_SUCCESS; |
ram54288 | 0:dbad57390bd1 | 338 | } |
ram54288 | 0:dbad57390bd1 | 339 | |
ram54288 | 0:dbad57390bd1 | 340 | return CMDLINE_RETCODE_FAIL; |
ram54288 | 0:dbad57390bd1 | 341 | } |
ram54288 | 0:dbad57390bd1 | 342 | |
ram54288 | 0:dbad57390bd1 | 343 | int lwm2m_client_device_command(int argc, char *argv[]) |
ram54288 | 0:dbad57390bd1 | 344 | { |
ram54288 | 0:dbad57390bd1 | 345 | int return_code = CMDLINE_RETCODE_SUCCESS;// CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 346 | char *manufacturer = 0; |
ram54288 | 0:dbad57390bd1 | 347 | char *model_number = 0; |
ram54288 | 0:dbad57390bd1 | 348 | char *serial_number = 0; |
ram54288 | 0:dbad57390bd1 | 349 | char *device_type = 0; |
ram54288 | 0:dbad57390bd1 | 350 | char *hardware_version = 0; |
ram54288 | 0:dbad57390bd1 | 351 | char *software_version = 0; |
ram54288 | 0:dbad57390bd1 | 352 | char *firmware_version = 0; |
ram54288 | 0:dbad57390bd1 | 353 | char *utc_offset = 0; |
ram54288 | 0:dbad57390bd1 | 354 | char *timezone = 0; |
ram54288 | 0:dbad57390bd1 | 355 | int32_t current_time = 0; |
ram54288 | 0:dbad57390bd1 | 356 | int32_t available_power_sources = 0; |
ram54288 | 0:dbad57390bd1 | 357 | int32_t power_source_voltage = 0; |
ram54288 | 0:dbad57390bd1 | 358 | int32_t power_source_current = 0; |
ram54288 | 0:dbad57390bd1 | 359 | int32_t battery_status = 0; |
ram54288 | 0:dbad57390bd1 | 360 | int32_t battery_level = 0; |
ram54288 | 0:dbad57390bd1 | 361 | int32_t memory_free = 0; |
ram54288 | 0:dbad57390bd1 | 362 | int32_t memory_total = 0; |
ram54288 | 0:dbad57390bd1 | 363 | int32_t error_code = 0; |
ram54288 | 0:dbad57390bd1 | 364 | int32_t instance_id = 0; |
ram54288 | 0:dbad57390bd1 | 365 | |
ram54288 | 0:dbad57390bd1 | 366 | lwm2m_client.create_device_object(); |
ram54288 | 0:dbad57390bd1 | 367 | |
ram54288 | 0:dbad57390bd1 | 368 | if(cmd_parameter_val(argc, argv, "--manufacturer", &manufacturer)) { |
ram54288 | 0:dbad57390bd1 | 369 | if(!lwm2m_client.create_device_object(M2MDevice::Manufacturer, |
ram54288 | 0:dbad57390bd1 | 370 | manufacturer)) { |
ram54288 | 0:dbad57390bd1 | 371 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 372 | } |
ram54288 | 0:dbad57390bd1 | 373 | } |
ram54288 | 0:dbad57390bd1 | 374 | if(cmd_parameter_val(argc, argv, "--model_number", &model_number)) { |
ram54288 | 0:dbad57390bd1 | 375 | if(!lwm2m_client.create_device_object(M2MDevice::ModelNumber, |
ram54288 | 0:dbad57390bd1 | 376 | model_number)) { |
ram54288 | 0:dbad57390bd1 | 377 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 378 | } |
ram54288 | 0:dbad57390bd1 | 379 | } |
ram54288 | 0:dbad57390bd1 | 380 | if(cmd_parameter_val(argc, argv, "--serial_number", &serial_number)){ |
ram54288 | 0:dbad57390bd1 | 381 | if(!lwm2m_client.create_device_object(M2MDevice::SerialNumber, |
ram54288 | 0:dbad57390bd1 | 382 | serial_number)) { |
ram54288 | 0:dbad57390bd1 | 383 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 384 | } |
ram54288 | 0:dbad57390bd1 | 385 | } |
ram54288 | 0:dbad57390bd1 | 386 | if(cmd_parameter_val(argc, argv, "--device_type", &device_type)){ |
ram54288 | 0:dbad57390bd1 | 387 | if(!lwm2m_client.create_device_object(M2MDevice::DeviceType, |
ram54288 | 0:dbad57390bd1 | 388 | device_type)) { |
ram54288 | 0:dbad57390bd1 | 389 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 390 | } |
ram54288 | 0:dbad57390bd1 | 391 | } |
ram54288 | 0:dbad57390bd1 | 392 | if(cmd_parameter_val(argc, argv, "--hardware_version", &hardware_version)){ |
ram54288 | 0:dbad57390bd1 | 393 | if(!lwm2m_client.create_device_object(M2MDevice::HardwareVersion, |
ram54288 | 0:dbad57390bd1 | 394 | hardware_version)) { |
ram54288 | 0:dbad57390bd1 | 395 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 396 | } |
ram54288 | 0:dbad57390bd1 | 397 | } |
ram54288 | 0:dbad57390bd1 | 398 | if(cmd_parameter_val(argc, argv, "--software_version", &software_version)){ |
ram54288 | 0:dbad57390bd1 | 399 | if(!lwm2m_client.create_device_object(M2MDevice::SoftwareVersion, |
ram54288 | 0:dbad57390bd1 | 400 | software_version)) { |
ram54288 | 0:dbad57390bd1 | 401 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 402 | } |
ram54288 | 0:dbad57390bd1 | 403 | } |
ram54288 | 0:dbad57390bd1 | 404 | if(cmd_parameter_val(argc, argv, "--firmware_version", &firmware_version)){ |
ram54288 | 0:dbad57390bd1 | 405 | if(!lwm2m_client.create_device_object(M2MDevice::FirmwareVersion, |
ram54288 | 0:dbad57390bd1 | 406 | firmware_version)) { |
ram54288 | 0:dbad57390bd1 | 407 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 408 | } |
ram54288 | 0:dbad57390bd1 | 409 | } |
ram54288 | 0:dbad57390bd1 | 410 | if(cmd_parameter_int(argc, argv, "--available_power_sources", &available_power_sources)){ |
ram54288 | 0:dbad57390bd1 | 411 | if(cmd_parameter_int(argc, argv, "--instance_id", &instance_id)) { |
ram54288 | 0:dbad57390bd1 | 412 | if(!lwm2m_client.create_device_object(M2MDevice::AvailablePowerSources, |
ram54288 | 0:dbad57390bd1 | 413 | available_power_sources,instance_id)) { |
ram54288 | 0:dbad57390bd1 | 414 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 415 | } |
ram54288 | 0:dbad57390bd1 | 416 | } |
ram54288 | 0:dbad57390bd1 | 417 | } |
ram54288 | 0:dbad57390bd1 | 418 | if(cmd_parameter_int(argc, argv, "--power_source_voltage", &power_source_voltage)){ |
ram54288 | 0:dbad57390bd1 | 419 | if(cmd_parameter_int(argc, argv, "--instance_id", &instance_id)) { |
ram54288 | 0:dbad57390bd1 | 420 | if(!lwm2m_client.create_device_object(M2MDevice::PowerSourceVoltage, |
ram54288 | 0:dbad57390bd1 | 421 | power_source_voltage,instance_id)) { |
ram54288 | 0:dbad57390bd1 | 422 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 423 | } |
ram54288 | 0:dbad57390bd1 | 424 | } |
ram54288 | 0:dbad57390bd1 | 425 | } |
ram54288 | 0:dbad57390bd1 | 426 | if(cmd_parameter_int(argc, argv, "--power_source_current", &power_source_current)){ |
ram54288 | 0:dbad57390bd1 | 427 | if(cmd_parameter_int(argc, argv, "--instance_id", &instance_id)) { |
ram54288 | 0:dbad57390bd1 | 428 | if(!lwm2m_client.create_device_object(M2MDevice::PowerSourceCurrent, |
ram54288 | 0:dbad57390bd1 | 429 | power_source_current,instance_id)) { |
ram54288 | 0:dbad57390bd1 | 430 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 431 | } |
ram54288 | 0:dbad57390bd1 | 432 | } |
ram54288 | 0:dbad57390bd1 | 433 | } |
ram54288 | 0:dbad57390bd1 | 434 | if(cmd_parameter_int(argc, argv, "--battery_level", &battery_level)){ |
ram54288 | 0:dbad57390bd1 | 435 | if(!lwm2m_client.create_device_object(M2MDevice::BatteryLevel, |
ram54288 | 0:dbad57390bd1 | 436 | battery_level)) { |
ram54288 | 0:dbad57390bd1 | 437 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 438 | } |
ram54288 | 0:dbad57390bd1 | 439 | } |
ram54288 | 0:dbad57390bd1 | 440 | if(cmd_parameter_int(argc, argv, "--battery_status", &battery_status)){ |
ram54288 | 0:dbad57390bd1 | 441 | if(!lwm2m_client.create_device_object(M2MDevice::BatteryStatus, |
ram54288 | 0:dbad57390bd1 | 442 | battery_status)) { |
ram54288 | 0:dbad57390bd1 | 443 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 444 | } |
ram54288 | 0:dbad57390bd1 | 445 | } |
ram54288 | 0:dbad57390bd1 | 446 | if(cmd_parameter_int(argc, argv, "--memory_free", &memory_free)){ |
ram54288 | 0:dbad57390bd1 | 447 | if(!lwm2m_client.create_device_object(M2MDevice::MemoryFree, |
ram54288 | 0:dbad57390bd1 | 448 | memory_free)) { |
ram54288 | 0:dbad57390bd1 | 449 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 450 | } |
ram54288 | 0:dbad57390bd1 | 451 | } |
ram54288 | 0:dbad57390bd1 | 452 | if(cmd_parameter_int(argc, argv, "--memory_total", &memory_total)){ |
ram54288 | 0:dbad57390bd1 | 453 | if(!lwm2m_client.create_device_object(M2MDevice::MemoryTotal, |
ram54288 | 0:dbad57390bd1 | 454 | memory_total)) { |
ram54288 | 0:dbad57390bd1 | 455 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 456 | } |
ram54288 | 0:dbad57390bd1 | 457 | } |
ram54288 | 0:dbad57390bd1 | 458 | if(cmd_parameter_int(argc, argv, "--error_code", &error_code)){ |
ram54288 | 0:dbad57390bd1 | 459 | if(cmd_parameter_int(argc, argv, "--instance_id", &instance_id)) { |
ram54288 | 0:dbad57390bd1 | 460 | if(!lwm2m_client.create_device_object(M2MDevice::ErrorCode, |
ram54288 | 0:dbad57390bd1 | 461 | error_code,instance_id)) { |
ram54288 | 0:dbad57390bd1 | 462 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 463 | } |
ram54288 | 0:dbad57390bd1 | 464 | } |
ram54288 | 0:dbad57390bd1 | 465 | } |
ram54288 | 0:dbad57390bd1 | 466 | if(cmd_parameter_int(argc, argv, "--current_time", ¤t_time)){ |
ram54288 | 0:dbad57390bd1 | 467 | if(!lwm2m_client.create_device_object(M2MDevice::CurrentTime, |
ram54288 | 0:dbad57390bd1 | 468 | current_time)) { |
ram54288 | 0:dbad57390bd1 | 469 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 470 | } |
ram54288 | 0:dbad57390bd1 | 471 | } |
ram54288 | 0:dbad57390bd1 | 472 | if(cmd_parameter_val(argc, argv, "--utc_offset", &utc_offset)){ |
ram54288 | 0:dbad57390bd1 | 473 | if(!lwm2m_client.create_device_object(M2MDevice::UTCOffset, |
ram54288 | 0:dbad57390bd1 | 474 | utc_offset)) { |
ram54288 | 0:dbad57390bd1 | 475 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 476 | } |
ram54288 | 0:dbad57390bd1 | 477 | } |
ram54288 | 0:dbad57390bd1 | 478 | if(cmd_parameter_val(argc, argv, "--timezone", &timezone)){ |
ram54288 | 0:dbad57390bd1 | 479 | if(!lwm2m_client.create_device_object(M2MDevice::Timezone, |
ram54288 | 0:dbad57390bd1 | 480 | timezone)) { |
ram54288 | 0:dbad57390bd1 | 481 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 482 | } |
ram54288 | 0:dbad57390bd1 | 483 | } |
ram54288 | 0:dbad57390bd1 | 484 | |
ram54288 | 0:dbad57390bd1 | 485 | return return_code; |
ram54288 | 0:dbad57390bd1 | 486 | } |
ram54288 | 0:dbad57390bd1 | 487 | |
ram54288 | 0:dbad57390bd1 | 488 | int lwm2m_client_firmware_command(int argc, char *argv[]) |
ram54288 | 0:dbad57390bd1 | 489 | { |
ram54288 | 0:dbad57390bd1 | 490 | int return_code = CMDLINE_RETCODE_SUCCESS;// CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 491 | char *package = 0; |
ram54288 | 0:dbad57390bd1 | 492 | char *package_uri = 0; |
ram54288 | 0:dbad57390bd1 | 493 | char *package_name = 0; |
ram54288 | 0:dbad57390bd1 | 494 | char *package_version = 0; |
ram54288 | 0:dbad57390bd1 | 495 | int32_t state = 1; |
ram54288 | 0:dbad57390bd1 | 496 | int32_t update_result = 0; |
ram54288 | 0:dbad57390bd1 | 497 | int32_t update_supported_objects = 0; |
ram54288 | 0:dbad57390bd1 | 498 | |
ram54288 | 0:dbad57390bd1 | 499 | lwm2m_client.create_firmware_object(); |
ram54288 | 0:dbad57390bd1 | 500 | |
ram54288 | 0:dbad57390bd1 | 501 | if(cmd_parameter_val(argc, argv, "--package", &package)) { |
ram54288 | 0:dbad57390bd1 | 502 | uint16_t length = (uint16_t)sizeof(package); |
ram54288 | 0:dbad57390bd1 | 503 | if(!lwm2m_client.create_firmware_object(M2MFirmware::Package, |
ram54288 | 0:dbad57390bd1 | 504 | (const uint8_t*)package, length)) { |
ram54288 | 0:dbad57390bd1 | 505 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 506 | } |
ram54288 | 0:dbad57390bd1 | 507 | } |
ram54288 | 0:dbad57390bd1 | 508 | |
ram54288 | 0:dbad57390bd1 | 509 | if(cmd_parameter_val(argc, argv, "--package_uri", &package_uri)) { |
ram54288 | 0:dbad57390bd1 | 510 | if(!lwm2m_client.create_firmware_object(M2MFirmware::PackageUri, |
ram54288 | 0:dbad57390bd1 | 511 | package_uri)) { |
ram54288 | 0:dbad57390bd1 | 512 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 513 | } |
ram54288 | 0:dbad57390bd1 | 514 | } |
ram54288 | 0:dbad57390bd1 | 515 | if(cmd_parameter_int(argc, argv, "--state", &state)) { |
ram54288 | 0:dbad57390bd1 | 516 | if(!lwm2m_client.create_firmware_object(M2MFirmware::State, |
ram54288 | 0:dbad57390bd1 | 517 | state)) { |
ram54288 | 0:dbad57390bd1 | 518 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 519 | } |
ram54288 | 0:dbad57390bd1 | 520 | } |
ram54288 | 0:dbad57390bd1 | 521 | if(cmd_parameter_int(argc, argv, "--update_supported_objects", &update_supported_objects)) { |
ram54288 | 0:dbad57390bd1 | 522 | if(!lwm2m_client.create_firmware_object(M2MFirmware::UpdateSupportedObjects, |
ram54288 | 0:dbad57390bd1 | 523 | update_supported_objects)) { |
ram54288 | 0:dbad57390bd1 | 524 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 525 | } |
ram54288 | 0:dbad57390bd1 | 526 | } |
ram54288 | 0:dbad57390bd1 | 527 | if(cmd_parameter_int(argc, argv, "--update_results", &update_result)) { |
ram54288 | 0:dbad57390bd1 | 528 | if(!lwm2m_client.create_firmware_object(M2MFirmware::UpdateResult, |
ram54288 | 0:dbad57390bd1 | 529 | update_result)) { |
ram54288 | 0:dbad57390bd1 | 530 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 531 | } |
ram54288 | 0:dbad57390bd1 | 532 | } |
ram54288 | 0:dbad57390bd1 | 533 | if(cmd_parameter_val(argc, argv, "--package_name", &package_name)) { |
ram54288 | 0:dbad57390bd1 | 534 | if(!lwm2m_client.create_firmware_object(M2MFirmware::PackageName, |
ram54288 | 0:dbad57390bd1 | 535 | package_name)) { |
ram54288 | 0:dbad57390bd1 | 536 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 537 | } |
ram54288 | 0:dbad57390bd1 | 538 | } |
ram54288 | 0:dbad57390bd1 | 539 | if(cmd_parameter_val(argc, argv, "--package_version", &package_version)) { |
ram54288 | 0:dbad57390bd1 | 540 | if(!lwm2m_client.create_firmware_object(M2MFirmware::PackageVersion, |
ram54288 | 0:dbad57390bd1 | 541 | package_version)) { |
ram54288 | 0:dbad57390bd1 | 542 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 543 | } |
ram54288 | 0:dbad57390bd1 | 544 | } |
ram54288 | 0:dbad57390bd1 | 545 | lwm2m_client.set_fw_execute_function(); |
ram54288 | 0:dbad57390bd1 | 546 | return return_code; |
ram54288 | 0:dbad57390bd1 | 547 | } |
ram54288 | 0:dbad57390bd1 | 548 | |
ram54288 | 0:dbad57390bd1 | 549 | int lwm2m_client_resource_value(int argc, char *argv[]) |
ram54288 | 0:dbad57390bd1 | 550 | { |
ram54288 | 0:dbad57390bd1 | 551 | int resource = 0; |
ram54288 | 0:dbad57390bd1 | 552 | if(cmd_parameter_int(argc, argv, "--firmware", &resource)) { |
ram54288 | 0:dbad57390bd1 | 553 | if (resource == 3 || resource == 4 || resource == 5) { |
ram54288 | 0:dbad57390bd1 | 554 | lwm2m_client.firmware_resource_int(resource); |
ram54288 | 0:dbad57390bd1 | 555 | } |
ram54288 | 0:dbad57390bd1 | 556 | else if (resource == 0) { |
ram54288 | 0:dbad57390bd1 | 557 | lwm2m_client.firmware_resource_buffer(); |
ram54288 | 0:dbad57390bd1 | 558 | } |
ram54288 | 0:dbad57390bd1 | 559 | else { |
ram54288 | 0:dbad57390bd1 | 560 | lwm2m_client.firmware_resource_string(resource); |
ram54288 | 0:dbad57390bd1 | 561 | } |
ram54288 | 0:dbad57390bd1 | 562 | } |
ram54288 | 0:dbad57390bd1 | 563 | return CMDLINE_RETCODE_SUCCESS; |
ram54288 | 0:dbad57390bd1 | 564 | } |
ram54288 | 0:dbad57390bd1 | 565 | |
ram54288 | 0:dbad57390bd1 | 566 | int lwm2m_client_object_command(int argc, char *argv[]) |
ram54288 | 0:dbad57390bd1 | 567 | { |
ram54288 | 0:dbad57390bd1 | 568 | int return_code = CMDLINE_RETCODE_SUCCESS;// CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 569 | char *object_name = 0; |
ram54288 | 0:dbad57390bd1 | 570 | int32_t new_instance = 0; |
ram54288 | 0:dbad57390bd1 | 571 | int32_t object_operation = 0; |
ram54288 | 0:dbad57390bd1 | 572 | int32_t object_instance_operation = 0; |
ram54288 | 0:dbad57390bd1 | 573 | int32_t object_instance_id = 0; |
ram54288 | 0:dbad57390bd1 | 574 | int32_t object_observable = 0; |
ram54288 | 0:dbad57390bd1 | 575 | int32_t object_instance_observable = 0; |
ram54288 | 0:dbad57390bd1 | 576 | |
ram54288 | 0:dbad57390bd1 | 577 | if(cmd_parameter_val(argc, argv, "--name", &object_name)) { |
ram54288 | 0:dbad57390bd1 | 578 | cmd_parameter_int(argc, argv, "--new_instance", &new_instance); |
ram54288 | 0:dbad57390bd1 | 579 | cmd_parameter_int(argc, argv, "--object_operation", &object_operation); |
ram54288 | 0:dbad57390bd1 | 580 | cmd_parameter_int(argc, argv, "--object_instance_operation", &object_instance_operation); |
ram54288 | 0:dbad57390bd1 | 581 | cmd_parameter_int(argc, argv, "--object_instance_id", &object_instance_id); |
ram54288 | 0:dbad57390bd1 | 582 | cmd_parameter_int(argc, argv, "--object_observable", &object_observable); |
ram54288 | 0:dbad57390bd1 | 583 | cmd_parameter_int(argc, argv, "--object_instance_observable", &object_instance_observable); |
ram54288 | 0:dbad57390bd1 | 584 | |
ram54288 | 0:dbad57390bd1 | 585 | if(!lwm2m_client.create_object(object_name, |
ram54288 | 0:dbad57390bd1 | 586 | new_instance, |
ram54288 | 0:dbad57390bd1 | 587 | object_operation, |
ram54288 | 0:dbad57390bd1 | 588 | object_instance_operation, |
ram54288 | 0:dbad57390bd1 | 589 | object_instance_id, |
ram54288 | 0:dbad57390bd1 | 590 | object_observable, |
ram54288 | 0:dbad57390bd1 | 591 | object_instance_observable)) { |
ram54288 | 0:dbad57390bd1 | 592 | return_code = CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 593 | } |
ram54288 | 0:dbad57390bd1 | 594 | } |
ram54288 | 0:dbad57390bd1 | 595 | return return_code; |
ram54288 | 0:dbad57390bd1 | 596 | } |
ram54288 | 0:dbad57390bd1 | 597 | |
ram54288 | 0:dbad57390bd1 | 598 | int lwm2m_client_static_resource_command(int argc, char *argv[]) |
ram54288 | 0:dbad57390bd1 | 599 | { |
ram54288 | 0:dbad57390bd1 | 600 | int return_code = CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 601 | char *name = 0; |
ram54288 | 0:dbad57390bd1 | 602 | char *value_string = 0; |
ram54288 | 0:dbad57390bd1 | 603 | int32_t value_int = 0; |
ram54288 | 0:dbad57390bd1 | 604 | int32_t value_type = -1; |
ram54288 | 0:dbad57390bd1 | 605 | int32_t multiple_instance = 0; |
ram54288 | 0:dbad57390bd1 | 606 | int32_t object_instance = 0; |
ram54288 | 0:dbad57390bd1 | 607 | |
ram54288 | 0:dbad57390bd1 | 608 | cmd_parameter_int(argc, argv, "--multiple_instance", &multiple_instance); |
ram54288 | 0:dbad57390bd1 | 609 | cmd_parameter_int(argc, argv, "--object_instance", &object_instance); |
ram54288 | 0:dbad57390bd1 | 610 | |
ram54288 | 0:dbad57390bd1 | 611 | |
ram54288 | 0:dbad57390bd1 | 612 | if(cmd_parameter_int(argc, argv, "--value_type", &value_type)) { |
ram54288 | 0:dbad57390bd1 | 613 | if(0 == value_type){ |
ram54288 | 0:dbad57390bd1 | 614 | if(cmd_parameter_val(argc, argv, "--name", &name) && |
ram54288 | 0:dbad57390bd1 | 615 | cmd_parameter_val(argc, argv, "--value", &value_string)) { |
ram54288 | 0:dbad57390bd1 | 616 | if(lwm2m_client.create_static_resource_string(name,value_string, |
ram54288 | 0:dbad57390bd1 | 617 | multiple_instance,object_instance)) { |
ram54288 | 0:dbad57390bd1 | 618 | return_code = CMDLINE_RETCODE_SUCCESS; |
ram54288 | 0:dbad57390bd1 | 619 | } |
ram54288 | 0:dbad57390bd1 | 620 | } |
ram54288 | 0:dbad57390bd1 | 621 | } else if(1 == value_type){ |
ram54288 | 0:dbad57390bd1 | 622 | if(cmd_parameter_val(argc, argv, "--name", &name) && |
ram54288 | 0:dbad57390bd1 | 623 | cmd_parameter_int(argc, argv, "--value", &value_int)) { |
ram54288 | 0:dbad57390bd1 | 624 | if(lwm2m_client.create_static_resource_int(name,value_int, |
ram54288 | 0:dbad57390bd1 | 625 | multiple_instance,object_instance)) { |
ram54288 | 0:dbad57390bd1 | 626 | return_code = CMDLINE_RETCODE_SUCCESS; |
ram54288 | 0:dbad57390bd1 | 627 | } |
ram54288 | 0:dbad57390bd1 | 628 | } |
ram54288 | 0:dbad57390bd1 | 629 | } |
ram54288 | 0:dbad57390bd1 | 630 | } |
ram54288 | 0:dbad57390bd1 | 631 | return return_code; |
ram54288 | 0:dbad57390bd1 | 632 | } |
ram54288 | 0:dbad57390bd1 | 633 | |
ram54288 | 0:dbad57390bd1 | 634 | int lwm2m_client_dynamic_resource_command(int argc, char *argv[]) |
ram54288 | 0:dbad57390bd1 | 635 | { |
ram54288 | 0:dbad57390bd1 | 636 | int return_code = CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 637 | char *name = 0; |
ram54288 | 0:dbad57390bd1 | 638 | int32_t multiple_instance = 0; |
ram54288 | 0:dbad57390bd1 | 639 | int32_t object_instance = 0; |
ram54288 | 0:dbad57390bd1 | 640 | int32_t observable = 0; |
ram54288 | 0:dbad57390bd1 | 641 | int32_t resource_operation = 1; |
ram54288 | 0:dbad57390bd1 | 642 | int32_t value_type = -1; |
ram54288 | 0:dbad57390bd1 | 643 | |
ram54288 | 0:dbad57390bd1 | 644 | cmd_parameter_int(argc, argv, "--value_type", &value_type); |
ram54288 | 0:dbad57390bd1 | 645 | cmd_parameter_int(argc, argv, "--multiple_instance", &multiple_instance); |
ram54288 | 0:dbad57390bd1 | 646 | cmd_parameter_int(argc, argv, "--object_instance", &object_instance); |
ram54288 | 0:dbad57390bd1 | 647 | cmd_parameter_int(argc, argv, "--observable", &observable); |
ram54288 | 0:dbad57390bd1 | 648 | cmd_parameter_int(argc, argv, "--resource_operation", &resource_operation); |
ram54288 | 0:dbad57390bd1 | 649 | if(-1 == value_type){ |
ram54288 | 0:dbad57390bd1 | 650 | value_type = 1; |
ram54288 | 0:dbad57390bd1 | 651 | } |
ram54288 | 0:dbad57390bd1 | 652 | |
ram54288 | 0:dbad57390bd1 | 653 | if(cmd_parameter_val(argc, argv, "--name", &name)) { |
ram54288 | 0:dbad57390bd1 | 654 | if(0 == value_type) { |
ram54288 | 0:dbad57390bd1 | 655 | if(lwm2m_client.create_dynamic_resource_string(name,observable, |
ram54288 | 0:dbad57390bd1 | 656 | multiple_instance, |
ram54288 | 0:dbad57390bd1 | 657 | object_instance, |
ram54288 | 0:dbad57390bd1 | 658 | resource_operation)) { |
ram54288 | 0:dbad57390bd1 | 659 | return_code = CMDLINE_RETCODE_SUCCESS; |
ram54288 | 0:dbad57390bd1 | 660 | } |
ram54288 | 0:dbad57390bd1 | 661 | } |
ram54288 | 0:dbad57390bd1 | 662 | else if(1 == value_type){ |
ram54288 | 0:dbad57390bd1 | 663 | if(lwm2m_client.create_dynamic_resource_int(name,observable, |
ram54288 | 0:dbad57390bd1 | 664 | multiple_instance, |
ram54288 | 0:dbad57390bd1 | 665 | object_instance, |
ram54288 | 0:dbad57390bd1 | 666 | resource_operation)) { |
ram54288 | 0:dbad57390bd1 | 667 | return_code = CMDLINE_RETCODE_SUCCESS; |
ram54288 | 0:dbad57390bd1 | 668 | } |
ram54288 | 0:dbad57390bd1 | 669 | } |
ram54288 | 0:dbad57390bd1 | 670 | |
ram54288 | 0:dbad57390bd1 | 671 | } |
ram54288 | 0:dbad57390bd1 | 672 | return return_code; |
ram54288 | 0:dbad57390bd1 | 673 | } |
ram54288 | 0:dbad57390bd1 | 674 | |
ram54288 | 0:dbad57390bd1 | 675 | int lwm2m_client_static_resource_instance_command(int argc, char *argv[]) |
ram54288 | 0:dbad57390bd1 | 676 | { |
ram54288 | 0:dbad57390bd1 | 677 | int return_code = CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 678 | char *name = 0; |
ram54288 | 0:dbad57390bd1 | 679 | char *value_string = 0; |
ram54288 | 0:dbad57390bd1 | 680 | int32_t value_int = 0; |
ram54288 | 0:dbad57390bd1 | 681 | int32_t value_type = -1; |
ram54288 | 0:dbad57390bd1 | 682 | int32_t multiple_instance = 0; |
ram54288 | 0:dbad57390bd1 | 683 | int32_t object_instance = 0; |
ram54288 | 0:dbad57390bd1 | 684 | int32_t resource_instance = 0; |
ram54288 | 0:dbad57390bd1 | 685 | |
ram54288 | 0:dbad57390bd1 | 686 | cmd_parameter_int(argc, argv, "--multiple_instance", &multiple_instance); |
ram54288 | 0:dbad57390bd1 | 687 | cmd_parameter_int(argc, argv, "--object_instance", &object_instance); |
ram54288 | 0:dbad57390bd1 | 688 | cmd_parameter_int(argc, argv, "--resource_instance", &resource_instance); |
ram54288 | 0:dbad57390bd1 | 689 | |
ram54288 | 0:dbad57390bd1 | 690 | if(cmd_parameter_int(argc, argv, "--value_type", &value_type)) { |
ram54288 | 0:dbad57390bd1 | 691 | if(0 == value_type){ |
ram54288 | 0:dbad57390bd1 | 692 | if(cmd_parameter_val(argc, argv, "--name", &name) && |
ram54288 | 0:dbad57390bd1 | 693 | cmd_parameter_val(argc, argv, "--value", &value_string)) { |
ram54288 | 0:dbad57390bd1 | 694 | if(lwm2m_client.create_static_resource_instance_string(name,value_string, |
ram54288 | 0:dbad57390bd1 | 695 | multiple_instance, |
ram54288 | 0:dbad57390bd1 | 696 | object_instance, |
ram54288 | 0:dbad57390bd1 | 697 | resource_instance)) { |
ram54288 | 0:dbad57390bd1 | 698 | return_code = CMDLINE_RETCODE_SUCCESS; |
ram54288 | 0:dbad57390bd1 | 699 | } |
ram54288 | 0:dbad57390bd1 | 700 | } |
ram54288 | 0:dbad57390bd1 | 701 | } else if(1 == value_type){ |
ram54288 | 0:dbad57390bd1 | 702 | if(cmd_parameter_val(argc, argv, "--name", &name) && |
ram54288 | 0:dbad57390bd1 | 703 | cmd_parameter_int(argc, argv, "--value", &value_int)) { |
ram54288 | 0:dbad57390bd1 | 704 | if(lwm2m_client.create_static_resource_instance_int(name,value_int, |
ram54288 | 0:dbad57390bd1 | 705 | multiple_instance, |
ram54288 | 0:dbad57390bd1 | 706 | object_instance, |
ram54288 | 0:dbad57390bd1 | 707 | resource_instance)) { |
ram54288 | 0:dbad57390bd1 | 708 | return_code = CMDLINE_RETCODE_SUCCESS; |
ram54288 | 0:dbad57390bd1 | 709 | } |
ram54288 | 0:dbad57390bd1 | 710 | } |
ram54288 | 0:dbad57390bd1 | 711 | } |
ram54288 | 0:dbad57390bd1 | 712 | } |
ram54288 | 0:dbad57390bd1 | 713 | return return_code; |
ram54288 | 0:dbad57390bd1 | 714 | } |
ram54288 | 0:dbad57390bd1 | 715 | |
ram54288 | 0:dbad57390bd1 | 716 | int lwm2m_client_dynamic_resource_instance_command(int argc, char *argv[]) |
ram54288 | 0:dbad57390bd1 | 717 | { |
ram54288 | 0:dbad57390bd1 | 718 | int return_code = CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 719 | char *name = 0; |
ram54288 | 0:dbad57390bd1 | 720 | int32_t multiple_instance = 0; |
ram54288 | 0:dbad57390bd1 | 721 | int32_t object_instance = 0; |
ram54288 | 0:dbad57390bd1 | 722 | int32_t resource_instance = 0; |
ram54288 | 0:dbad57390bd1 | 723 | int32_t observable = 0; |
ram54288 | 0:dbad57390bd1 | 724 | int32_t resource_instance_operation = 1; |
ram54288 | 0:dbad57390bd1 | 725 | int32_t value_type = -1; |
ram54288 | 0:dbad57390bd1 | 726 | |
ram54288 | 0:dbad57390bd1 | 727 | cmd_parameter_int(argc, argv, "--value_type", &value_type); |
ram54288 | 0:dbad57390bd1 | 728 | cmd_parameter_int(argc, argv, "--multiple_instance", &multiple_instance); |
ram54288 | 0:dbad57390bd1 | 729 | cmd_parameter_int(argc, argv, "--object_instance", &object_instance); |
ram54288 | 0:dbad57390bd1 | 730 | cmd_parameter_int(argc, argv, "--resource_instance", &resource_instance); |
ram54288 | 0:dbad57390bd1 | 731 | cmd_parameter_int(argc, argv, "--observable", &observable); |
ram54288 | 0:dbad57390bd1 | 732 | cmd_parameter_int(argc, argv, "--resource_instance_operation", &resource_instance_operation); |
ram54288 | 0:dbad57390bd1 | 733 | if(-1 == value_type){ |
ram54288 | 0:dbad57390bd1 | 734 | value_type = 1; |
ram54288 | 0:dbad57390bd1 | 735 | } |
ram54288 | 0:dbad57390bd1 | 736 | |
ram54288 | 0:dbad57390bd1 | 737 | if(cmd_parameter_val(argc, argv, "--name", &name)) { |
ram54288 | 0:dbad57390bd1 | 738 | if(0 == value_type){ |
ram54288 | 0:dbad57390bd1 | 739 | if(lwm2m_client.create_dynamic_resource_instance_string(name,observable, |
ram54288 | 0:dbad57390bd1 | 740 | multiple_instance, |
ram54288 | 0:dbad57390bd1 | 741 | object_instance, |
ram54288 | 0:dbad57390bd1 | 742 | resource_instance, |
ram54288 | 0:dbad57390bd1 | 743 | resource_instance_operation)) { |
ram54288 | 0:dbad57390bd1 | 744 | return_code = CMDLINE_RETCODE_SUCCESS; |
ram54288 | 0:dbad57390bd1 | 745 | } |
ram54288 | 0:dbad57390bd1 | 746 | } |
ram54288 | 0:dbad57390bd1 | 747 | else if(1 == value_type){ |
ram54288 | 0:dbad57390bd1 | 748 | if(lwm2m_client.create_dynamic_resource_instance_int(name,observable, |
ram54288 | 0:dbad57390bd1 | 749 | multiple_instance, |
ram54288 | 0:dbad57390bd1 | 750 | object_instance, |
ram54288 | 0:dbad57390bd1 | 751 | resource_instance, |
ram54288 | 0:dbad57390bd1 | 752 | resource_instance_operation)) { |
ram54288 | 0:dbad57390bd1 | 753 | return_code = CMDLINE_RETCODE_SUCCESS; |
ram54288 | 0:dbad57390bd1 | 754 | } |
ram54288 | 0:dbad57390bd1 | 755 | } |
ram54288 | 0:dbad57390bd1 | 756 | } |
ram54288 | 0:dbad57390bd1 | 757 | return return_code; |
ram54288 | 0:dbad57390bd1 | 758 | } |
ram54288 | 0:dbad57390bd1 | 759 | |
ram54288 | 0:dbad57390bd1 | 760 | int lwm2m_client_bootstrap_object_command(int argc, char *argv[]) |
ram54288 | 0:dbad57390bd1 | 761 | { |
ram54288 | 0:dbad57390bd1 | 762 | int return_code = CMDLINE_RETCODE_FAIL; |
ram54288 | 0:dbad57390bd1 | 763 | char *address = 0; |
ram54288 | 0:dbad57390bd1 | 764 | |
ram54288 | 0:dbad57390bd1 | 765 | if( cmd_parameter_val(argc, argv, "--address", &address) ){ |
ram54288 | 0:dbad57390bd1 | 766 | if(lwm2m_client.create_bootstrap_object(address)){ |
ram54288 | 0:dbad57390bd1 | 767 | return_code = CMDLINE_RETCODE_SUCCESS; |
ram54288 | 0:dbad57390bd1 | 768 | } |
ram54288 | 0:dbad57390bd1 | 769 | } else { |
ram54288 | 0:dbad57390bd1 | 770 | return_code = CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 771 | } |
ram54288 | 0:dbad57390bd1 | 772 | return return_code; |
ram54288 | 0:dbad57390bd1 | 773 | } |
ram54288 | 0:dbad57390bd1 | 774 | |
ram54288 | 0:dbad57390bd1 | 775 | int lwm2m_client_bootstrap_command() |
ram54288 | 0:dbad57390bd1 | 776 | { |
ram54288 | 0:dbad57390bd1 | 777 | int return_code = CMDLINE_RETCODE_FAIL; |
ram54288 | 0:dbad57390bd1 | 778 | |
ram54288 | 0:dbad57390bd1 | 779 | if(lwm2m_client.test_bootstrap()){ |
ram54288 | 0:dbad57390bd1 | 780 | return_code = CMDLINE_RETCODE_EXCUTING_CONTINUE; |
ram54288 | 0:dbad57390bd1 | 781 | } |
ram54288 | 0:dbad57390bd1 | 782 | return return_code; |
ram54288 | 0:dbad57390bd1 | 783 | } |
ram54288 | 0:dbad57390bd1 | 784 | |
ram54288 | 0:dbad57390bd1 | 785 | int lwm2m_client_register_object_command(int argc, char *argv[]) |
ram54288 | 0:dbad57390bd1 | 786 | { |
ram54288 | 0:dbad57390bd1 | 787 | char *address = 0; |
ram54288 | 0:dbad57390bd1 | 788 | cmd_parameter_val(argc, argv, "--address", &address); |
ram54288 | 0:dbad57390bd1 | 789 | |
ram54288 | 0:dbad57390bd1 | 790 | int useSecureConn = 0; |
ram54288 | 0:dbad57390bd1 | 791 | if( !cmd_parameter_int(argc, argv, "--secure", &useSecureConn) ){ |
ram54288 | 0:dbad57390bd1 | 792 | useSecureConn = 0; |
ram54288 | 0:dbad57390bd1 | 793 | } |
ram54288 | 0:dbad57390bd1 | 794 | |
ram54288 | 0:dbad57390bd1 | 795 | if(lwm2m_client.create_register_object(address, useSecureConn == 1)) { |
ram54288 | 0:dbad57390bd1 | 796 | return CMDLINE_RETCODE_SUCCESS; |
ram54288 | 0:dbad57390bd1 | 797 | } |
ram54288 | 0:dbad57390bd1 | 798 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 799 | } |
ram54288 | 0:dbad57390bd1 | 800 | |
ram54288 | 0:dbad57390bd1 | 801 | int lwm2m_client_register_command() |
ram54288 | 0:dbad57390bd1 | 802 | { |
ram54288 | 0:dbad57390bd1 | 803 | if(lwm2m_client.test_register()) { |
ram54288 | 0:dbad57390bd1 | 804 | return CMDLINE_RETCODE_EXCUTING_CONTINUE; |
ram54288 | 0:dbad57390bd1 | 805 | } |
ram54288 | 0:dbad57390bd1 | 806 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 807 | } |
ram54288 | 0:dbad57390bd1 | 808 | |
ram54288 | 0:dbad57390bd1 | 809 | int lwm2m_client_update_register_command(int argc, char *argv[]) |
ram54288 | 0:dbad57390bd1 | 810 | { |
ram54288 | 0:dbad57390bd1 | 811 | int ret_code = CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 812 | int32_t lifetime = 0; |
ram54288 | 0:dbad57390bd1 | 813 | |
ram54288 | 0:dbad57390bd1 | 814 | cmd_parameter_int(argc, argv, "--lifetime", &lifetime); |
ram54288 | 0:dbad57390bd1 | 815 | |
ram54288 | 0:dbad57390bd1 | 816 | if(lifetime >= 0) { |
ram54288 | 0:dbad57390bd1 | 817 | if(lwm2m_client.test_update_register(lifetime)) { |
ram54288 | 0:dbad57390bd1 | 818 | ret_code = CMDLINE_RETCODE_EXCUTING_CONTINUE; |
ram54288 | 0:dbad57390bd1 | 819 | } |
ram54288 | 0:dbad57390bd1 | 820 | } |
ram54288 | 0:dbad57390bd1 | 821 | return ret_code; |
ram54288 | 0:dbad57390bd1 | 822 | } |
ram54288 | 0:dbad57390bd1 | 823 | |
ram54288 | 0:dbad57390bd1 | 824 | int lwm2m_client_unregister_command() |
ram54288 | 0:dbad57390bd1 | 825 | { |
ram54288 | 0:dbad57390bd1 | 826 | if(lwm2m_client.test_unregister()) { |
ram54288 | 0:dbad57390bd1 | 827 | return CMDLINE_RETCODE_EXCUTING_CONTINUE; |
ram54288 | 0:dbad57390bd1 | 828 | } |
ram54288 | 0:dbad57390bd1 | 829 | return CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 830 | } |
ram54288 | 0:dbad57390bd1 | 831 | |
ram54288 | 0:dbad57390bd1 | 832 | int lwm2m_client_set_value_command(int argc, char *argv[]) |
ram54288 | 0:dbad57390bd1 | 833 | { |
ram54288 | 0:dbad57390bd1 | 834 | int return_code = CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 835 | char *name = 0; |
ram54288 | 0:dbad57390bd1 | 836 | int32_t value = 0; |
ram54288 | 0:dbad57390bd1 | 837 | int32_t object_instance = 0; |
ram54288 | 0:dbad57390bd1 | 838 | |
ram54288 | 0:dbad57390bd1 | 839 | cmd_parameter_int(argc, argv, "--object_instance", &object_instance); |
ram54288 | 0:dbad57390bd1 | 840 | |
ram54288 | 0:dbad57390bd1 | 841 | if(cmd_parameter_val(argc, argv, "--name", &name) && |
ram54288 | 0:dbad57390bd1 | 842 | cmd_parameter_int(argc, argv, "--value", &value)) { |
ram54288 | 0:dbad57390bd1 | 843 | if(lwm2m_client.set_resource_value(name,value,object_instance)) { |
ram54288 | 0:dbad57390bd1 | 844 | return_code = CMDLINE_RETCODE_SUCCESS; |
ram54288 | 0:dbad57390bd1 | 845 | } |
ram54288 | 0:dbad57390bd1 | 846 | } |
ram54288 | 0:dbad57390bd1 | 847 | return return_code; |
ram54288 | 0:dbad57390bd1 | 848 | } |
ram54288 | 0:dbad57390bd1 | 849 | |
ram54288 | 0:dbad57390bd1 | 850 | int lwm2m_client_set_value_instance_command(int argc, char *argv[]) |
ram54288 | 0:dbad57390bd1 | 851 | { |
ram54288 | 0:dbad57390bd1 | 852 | int return_code = CMDLINE_RETCODE_INVALID_PARAMETERS; |
ram54288 | 0:dbad57390bd1 | 853 | char *name = 0; |
ram54288 | 0:dbad57390bd1 | 854 | int32_t value = 0; |
ram54288 | 0:dbad57390bd1 | 855 | int32_t object_instance = 0; |
ram54288 | 0:dbad57390bd1 | 856 | int32_t resource_instance = 0; |
ram54288 | 0:dbad57390bd1 | 857 | |
ram54288 | 0:dbad57390bd1 | 858 | cmd_parameter_int(argc, argv, "--object_instance", &object_instance); |
ram54288 | 0:dbad57390bd1 | 859 | cmd_parameter_int(argc, argv, "--resource_instance", &resource_instance); |
ram54288 | 0:dbad57390bd1 | 860 | |
ram54288 | 0:dbad57390bd1 | 861 | if(cmd_parameter_val(argc, argv, "--name", &name) && |
ram54288 | 0:dbad57390bd1 | 862 | cmd_parameter_int(argc, argv, "--value", &value)) { |
ram54288 | 0:dbad57390bd1 | 863 | if(lwm2m_client.set_resource_instance_value(name,value, |
ram54288 | 0:dbad57390bd1 | 864 | object_instance, |
ram54288 | 0:dbad57390bd1 | 865 | resource_instance)) { |
ram54288 | 0:dbad57390bd1 | 866 | return_code = CMDLINE_RETCODE_SUCCESS; |
ram54288 | 0:dbad57390bd1 | 867 | } |
ram54288 | 0:dbad57390bd1 | 868 | } |
ram54288 | 0:dbad57390bd1 | 869 | return return_code; |
ram54288 | 0:dbad57390bd1 | 870 | } |
ram54288 | 0:dbad57390bd1 | 871 | |
ram54288 | 0:dbad57390bd1 | 872 | int exit_command(int argc, char *argv[]) |
ram54288 | 0:dbad57390bd1 | 873 | { |
ram54288 | 0:dbad57390bd1 | 874 | exit(1); |
ram54288 | 0:dbad57390bd1 | 875 | } |