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