Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
simple-mbed-cloud-client/mbed-cloud-client/mbed-client/source/m2mfirmware.cpp@0:8f0bb79ddd48, 2021-05-04 (annotated)
- Committer:
- leothedragon
- Date:
- Tue May 04 08:55:12 2021 +0000
- Revision:
- 0:8f0bb79ddd48
nmn
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leothedragon | 0:8f0bb79ddd48 | 1 | /* |
leothedragon | 0:8f0bb79ddd48 | 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. |
leothedragon | 0:8f0bb79ddd48 | 3 | * SPDX-License-Identifier: Apache-2.0 |
leothedragon | 0:8f0bb79ddd48 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
leothedragon | 0:8f0bb79ddd48 | 5 | * not use this file except in compliance with the License. |
leothedragon | 0:8f0bb79ddd48 | 6 | * You may obtain a copy of the License at |
leothedragon | 0:8f0bb79ddd48 | 7 | * |
leothedragon | 0:8f0bb79ddd48 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
leothedragon | 0:8f0bb79ddd48 | 9 | * |
leothedragon | 0:8f0bb79ddd48 | 10 | * Unless required by applicable law or agreed to in writing, software |
leothedragon | 0:8f0bb79ddd48 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
leothedragon | 0:8f0bb79ddd48 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
leothedragon | 0:8f0bb79ddd48 | 13 | * See the License for the specific language governing permissions and |
leothedragon | 0:8f0bb79ddd48 | 14 | * limitations under the License. |
leothedragon | 0:8f0bb79ddd48 | 15 | */ |
leothedragon | 0:8f0bb79ddd48 | 16 | |
leothedragon | 0:8f0bb79ddd48 | 17 | #include "mbed-client/m2mfirmware.h" |
leothedragon | 0:8f0bb79ddd48 | 18 | #include "mbed-client/m2mconstants.h" |
leothedragon | 0:8f0bb79ddd48 | 19 | #include "mbed-client/m2mobject.h" |
leothedragon | 0:8f0bb79ddd48 | 20 | #include "mbed-client/m2mobjectinstance.h" |
leothedragon | 0:8f0bb79ddd48 | 21 | #include "mbed-client/m2mresource.h" |
leothedragon | 0:8f0bb79ddd48 | 22 | #include "include/nsdlaccesshelper.h" |
leothedragon | 0:8f0bb79ddd48 | 23 | |
leothedragon | 0:8f0bb79ddd48 | 24 | #define BUFFER_SIZE 21 |
leothedragon | 0:8f0bb79ddd48 | 25 | #define TRACE_GROUP "mClt" |
leothedragon | 0:8f0bb79ddd48 | 26 | |
leothedragon | 0:8f0bb79ddd48 | 27 | M2MFirmware* M2MFirmware::_instance = NULL; |
leothedragon | 0:8f0bb79ddd48 | 28 | |
leothedragon | 0:8f0bb79ddd48 | 29 | M2MFirmware* M2MFirmware::get_instance() |
leothedragon | 0:8f0bb79ddd48 | 30 | { |
leothedragon | 0:8f0bb79ddd48 | 31 | if(_instance == NULL) { |
leothedragon | 0:8f0bb79ddd48 | 32 | _instance = new M2MFirmware(); |
leothedragon | 0:8f0bb79ddd48 | 33 | } |
leothedragon | 0:8f0bb79ddd48 | 34 | return _instance; |
leothedragon | 0:8f0bb79ddd48 | 35 | } |
leothedragon | 0:8f0bb79ddd48 | 36 | |
leothedragon | 0:8f0bb79ddd48 | 37 | void M2MFirmware::delete_instance() |
leothedragon | 0:8f0bb79ddd48 | 38 | { |
leothedragon | 0:8f0bb79ddd48 | 39 | delete _instance; |
leothedragon | 0:8f0bb79ddd48 | 40 | _instance = NULL; |
leothedragon | 0:8f0bb79ddd48 | 41 | } |
leothedragon | 0:8f0bb79ddd48 | 42 | |
leothedragon | 0:8f0bb79ddd48 | 43 | M2MFirmware::M2MFirmware() |
leothedragon | 0:8f0bb79ddd48 | 44 | : M2MObject(M2M_FIRMWARE_ID, stringdup(M2M_FIRMWARE_ID)) |
leothedragon | 0:8f0bb79ddd48 | 45 | { |
leothedragon | 0:8f0bb79ddd48 | 46 | M2MBase::set_register_uri(false); |
leothedragon | 0:8f0bb79ddd48 | 47 | M2MBase::set_operation(M2MBase::GET_PUT_ALLOWED); |
leothedragon | 0:8f0bb79ddd48 | 48 | _firmware_instance = M2MObject::create_object_instance(); |
leothedragon | 0:8f0bb79ddd48 | 49 | if(_firmware_instance) { |
leothedragon | 0:8f0bb79ddd48 | 50 | _firmware_instance->set_operation(M2MBase::GET_PUT_ALLOWED); |
leothedragon | 0:8f0bb79ddd48 | 51 | create_mandatory_resources(); |
leothedragon | 0:8f0bb79ddd48 | 52 | } |
leothedragon | 0:8f0bb79ddd48 | 53 | } |
leothedragon | 0:8f0bb79ddd48 | 54 | |
leothedragon | 0:8f0bb79ddd48 | 55 | M2MFirmware::~M2MFirmware() |
leothedragon | 0:8f0bb79ddd48 | 56 | { |
leothedragon | 0:8f0bb79ddd48 | 57 | } |
leothedragon | 0:8f0bb79ddd48 | 58 | |
leothedragon | 0:8f0bb79ddd48 | 59 | // Conditionally put the static part of parameter struct into flash. |
leothedragon | 0:8f0bb79ddd48 | 60 | // Unfortunately this can't be done yet by default as there is old API which |
leothedragon | 0:8f0bb79ddd48 | 61 | // may be used to modify the values in sn_nsdl_static_resource_parameters_s. |
leothedragon | 0:8f0bb79ddd48 | 62 | #ifdef MEMORY_OPTIMIZED_API |
leothedragon | 0:8f0bb79ddd48 | 63 | #define STATIC_PARAM_TYPE const |
leothedragon | 0:8f0bb79ddd48 | 64 | #else |
leothedragon | 0:8f0bb79ddd48 | 65 | #define STATIC_PARAM_TYPE |
leothedragon | 0:8f0bb79ddd48 | 66 | #endif |
leothedragon | 0:8f0bb79ddd48 | 67 | |
leothedragon | 0:8f0bb79ddd48 | 68 | #define PACKAGE_PATH FIRMWARE_PATH_PREFIX FIRMWARE_PACKAGE |
leothedragon | 0:8f0bb79ddd48 | 69 | |
leothedragon | 0:8f0bb79ddd48 | 70 | #ifdef RESOURCE_ATTRIBUTES_LIST |
leothedragon | 0:8f0bb79ddd48 | 71 | sn_nsdl_attribute_item_s default_attributes[2] = { |
leothedragon | 0:8f0bb79ddd48 | 72 | {ATTR_RESOURCE_TYPE, OMA_RESOURCE_TYPE}, |
leothedragon | 0:8f0bb79ddd48 | 73 | {ATTR_END, 0} |
leothedragon | 0:8f0bb79ddd48 | 74 | }; |
leothedragon | 0:8f0bb79ddd48 | 75 | #endif |
leothedragon | 0:8f0bb79ddd48 | 76 | |
leothedragon | 0:8f0bb79ddd48 | 77 | STATIC_PARAM_TYPE |
leothedragon | 0:8f0bb79ddd48 | 78 | static sn_nsdl_static_resource_parameters_s firmware_package_params_static = { |
leothedragon | 0:8f0bb79ddd48 | 79 | #ifndef RESOURCE_ATTRIBUTES_LIST |
leothedragon | 0:8f0bb79ddd48 | 80 | #ifndef DISABLE_RESOURCE_TYPE |
leothedragon | 0:8f0bb79ddd48 | 81 | (char*)OMA_RESOURCE_TYPE, // resource_type_ptr |
leothedragon | 0:8f0bb79ddd48 | 82 | #endif |
leothedragon | 0:8f0bb79ddd48 | 83 | #ifndef DISABLE_INTERFACE_DESCRIPTION |
leothedragon | 0:8f0bb79ddd48 | 84 | (char*)"", // interface_description_ptr |
leothedragon | 0:8f0bb79ddd48 | 85 | #endif |
leothedragon | 0:8f0bb79ddd48 | 86 | #else |
leothedragon | 0:8f0bb79ddd48 | 87 | default_attributes, |
leothedragon | 0:8f0bb79ddd48 | 88 | #endif |
leothedragon | 0:8f0bb79ddd48 | 89 | (char*)PACKAGE_PATH, // path |
leothedragon | 0:8f0bb79ddd48 | 90 | // (uint8_t*)"", // resource |
leothedragon | 0:8f0bb79ddd48 | 91 | // 0, // resourcelen |
leothedragon | 0:8f0bb79ddd48 | 92 | false, // external_memory_block |
leothedragon | 0:8f0bb79ddd48 | 93 | SN_GRS_DYNAMIC, // mode |
leothedragon | 0:8f0bb79ddd48 | 94 | false // free_on_delete |
leothedragon | 0:8f0bb79ddd48 | 95 | }; |
leothedragon | 0:8f0bb79ddd48 | 96 | |
leothedragon | 0:8f0bb79ddd48 | 97 | #define PACKAGE_URI_PATH FIRMWARE_PATH_PREFIX FIRMWARE_PACKAGE_URI |
leothedragon | 0:8f0bb79ddd48 | 98 | |
leothedragon | 0:8f0bb79ddd48 | 99 | STATIC_PARAM_TYPE |
leothedragon | 0:8f0bb79ddd48 | 100 | static sn_nsdl_static_resource_parameters_s firmware_package_uri_params_static = { |
leothedragon | 0:8f0bb79ddd48 | 101 | #ifndef RESOURCE_ATTRIBUTES_LIST |
leothedragon | 0:8f0bb79ddd48 | 102 | #ifndef DISABLE_RESOURCE_TYPE |
leothedragon | 0:8f0bb79ddd48 | 103 | (char*)OMA_RESOURCE_TYPE, // resource_type_ptr |
leothedragon | 0:8f0bb79ddd48 | 104 | #endif |
leothedragon | 0:8f0bb79ddd48 | 105 | #ifndef DISABLE_INTERFACE_DESCRIPTION |
leothedragon | 0:8f0bb79ddd48 | 106 | (char*)"", // interface_description_ptr |
leothedragon | 0:8f0bb79ddd48 | 107 | #endif |
leothedragon | 0:8f0bb79ddd48 | 108 | #else |
leothedragon | 0:8f0bb79ddd48 | 109 | default_attributes, |
leothedragon | 0:8f0bb79ddd48 | 110 | #endif |
leothedragon | 0:8f0bb79ddd48 | 111 | (char*)PACKAGE_URI_PATH, // path |
leothedragon | 0:8f0bb79ddd48 | 112 | // (uint8_t*)"", // resource |
leothedragon | 0:8f0bb79ddd48 | 113 | // 0, // resourcelen |
leothedragon | 0:8f0bb79ddd48 | 114 | false, // external_memory_block |
leothedragon | 0:8f0bb79ddd48 | 115 | SN_GRS_DYNAMIC, // mode |
leothedragon | 0:8f0bb79ddd48 | 116 | false // free_on_delete |
leothedragon | 0:8f0bb79ddd48 | 117 | }; |
leothedragon | 0:8f0bb79ddd48 | 118 | |
leothedragon | 0:8f0bb79ddd48 | 119 | #define UPDATE_PATH FIRMWARE_PATH_PREFIX FIRMWARE_UPDATE |
leothedragon | 0:8f0bb79ddd48 | 120 | |
leothedragon | 0:8f0bb79ddd48 | 121 | STATIC_PARAM_TYPE |
leothedragon | 0:8f0bb79ddd48 | 122 | static sn_nsdl_static_resource_parameters_s firmware_update_params_static = { |
leothedragon | 0:8f0bb79ddd48 | 123 | #ifndef RESOURCE_ATTRIBUTES_LIST |
leothedragon | 0:8f0bb79ddd48 | 124 | #ifndef DISABLE_RESOURCE_TYPE |
leothedragon | 0:8f0bb79ddd48 | 125 | (char*)OMA_RESOURCE_TYPE, // resource_type_ptr |
leothedragon | 0:8f0bb79ddd48 | 126 | #endif |
leothedragon | 0:8f0bb79ddd48 | 127 | #ifndef DISABLE_INTERFACE_DESCRIPTION |
leothedragon | 0:8f0bb79ddd48 | 128 | (char*)"", // interface_description_ptr |
leothedragon | 0:8f0bb79ddd48 | 129 | #endif |
leothedragon | 0:8f0bb79ddd48 | 130 | #else |
leothedragon | 0:8f0bb79ddd48 | 131 | default_attributes, |
leothedragon | 0:8f0bb79ddd48 | 132 | #endif |
leothedragon | 0:8f0bb79ddd48 | 133 | (char*)UPDATE_PATH, // path |
leothedragon | 0:8f0bb79ddd48 | 134 | // (uint8_t*)"", // resource |
leothedragon | 0:8f0bb79ddd48 | 135 | // 0, // resourcelen |
leothedragon | 0:8f0bb79ddd48 | 136 | false, // external_memory_block |
leothedragon | 0:8f0bb79ddd48 | 137 | SN_GRS_DYNAMIC, // mode |
leothedragon | 0:8f0bb79ddd48 | 138 | false // free_on_delete |
leothedragon | 0:8f0bb79ddd48 | 139 | }; |
leothedragon | 0:8f0bb79ddd48 | 140 | |
leothedragon | 0:8f0bb79ddd48 | 141 | #define STATE_URI_PATH FIRMWARE_PATH_PREFIX FIRMWARE_STATE |
leothedragon | 0:8f0bb79ddd48 | 142 | |
leothedragon | 0:8f0bb79ddd48 | 143 | STATIC_PARAM_TYPE |
leothedragon | 0:8f0bb79ddd48 | 144 | static sn_nsdl_static_resource_parameters_s firmware_state_params_static = { |
leothedragon | 0:8f0bb79ddd48 | 145 | #ifndef RESOURCE_ATTRIBUTES_LIST |
leothedragon | 0:8f0bb79ddd48 | 146 | #ifndef DISABLE_RESOURCE_TYPE |
leothedragon | 0:8f0bb79ddd48 | 147 | (char*)OMA_RESOURCE_TYPE, // resource_type_ptr |
leothedragon | 0:8f0bb79ddd48 | 148 | #endif |
leothedragon | 0:8f0bb79ddd48 | 149 | #ifndef DISABLE_INTERFACE_DESCRIPTION |
leothedragon | 0:8f0bb79ddd48 | 150 | (char*)"", // interface_description_ptr |
leothedragon | 0:8f0bb79ddd48 | 151 | #endif |
leothedragon | 0:8f0bb79ddd48 | 152 | #else |
leothedragon | 0:8f0bb79ddd48 | 153 | default_attributes, |
leothedragon | 0:8f0bb79ddd48 | 154 | #endif |
leothedragon | 0:8f0bb79ddd48 | 155 | (char*)STATE_URI_PATH, // path |
leothedragon | 0:8f0bb79ddd48 | 156 | false, // external_memory_block |
leothedragon | 0:8f0bb79ddd48 | 157 | SN_GRS_DYNAMIC, // mode |
leothedragon | 0:8f0bb79ddd48 | 158 | false // free_on_delete |
leothedragon | 0:8f0bb79ddd48 | 159 | }; |
leothedragon | 0:8f0bb79ddd48 | 160 | |
leothedragon | 0:8f0bb79ddd48 | 161 | #define UPDATE_RESULT_PATH FIRMWARE_PATH_PREFIX FIRMWARE_UPDATE_RESULT |
leothedragon | 0:8f0bb79ddd48 | 162 | |
leothedragon | 0:8f0bb79ddd48 | 163 | STATIC_PARAM_TYPE |
leothedragon | 0:8f0bb79ddd48 | 164 | static sn_nsdl_static_resource_parameters_s firmware_update_result_params_static = { |
leothedragon | 0:8f0bb79ddd48 | 165 | #ifndef RESOURCE_ATTRIBUTES_LIST |
leothedragon | 0:8f0bb79ddd48 | 166 | #ifndef DISABLE_RESOURCE_TYPE |
leothedragon | 0:8f0bb79ddd48 | 167 | (char*)OMA_RESOURCE_TYPE, // resource_type_ptr |
leothedragon | 0:8f0bb79ddd48 | 168 | #endif |
leothedragon | 0:8f0bb79ddd48 | 169 | #ifndef DISABLE_INTERFACE_DESCRIPTION |
leothedragon | 0:8f0bb79ddd48 | 170 | (char*)"", // interface_description_ptr |
leothedragon | 0:8f0bb79ddd48 | 171 | #endif |
leothedragon | 0:8f0bb79ddd48 | 172 | #else |
leothedragon | 0:8f0bb79ddd48 | 173 | default_attributes, |
leothedragon | 0:8f0bb79ddd48 | 174 | #endif |
leothedragon | 0:8f0bb79ddd48 | 175 | (char*)UPDATE_RESULT_PATH, // path |
leothedragon | 0:8f0bb79ddd48 | 176 | false, // external_memory_block |
leothedragon | 0:8f0bb79ddd48 | 177 | SN_GRS_DYNAMIC, // mode |
leothedragon | 0:8f0bb79ddd48 | 178 | false // free_on_delete |
leothedragon | 0:8f0bb79ddd48 | 179 | }; |
leothedragon | 0:8f0bb79ddd48 | 180 | |
leothedragon | 0:8f0bb79ddd48 | 181 | static sn_nsdl_dynamic_resource_parameters_s firmware_package_params_dynamic = { |
leothedragon | 0:8f0bb79ddd48 | 182 | __nsdl_c_callback, |
leothedragon | 0:8f0bb79ddd48 | 183 | &firmware_package_params_static, |
leothedragon | 0:8f0bb79ddd48 | 184 | NULL, |
leothedragon | 0:8f0bb79ddd48 | 185 | {NULL, NULL}, // link |
leothedragon | 0:8f0bb79ddd48 | 186 | 0, |
leothedragon | 0:8f0bb79ddd48 | 187 | COAP_CONTENT_OMA_PLAIN_TEXT_TYPE, // coap_content_type |
leothedragon | 0:8f0bb79ddd48 | 188 | M2MBase::PUT_ALLOWED, // access |
leothedragon | 0:8f0bb79ddd48 | 189 | 0, // registered |
leothedragon | 0:8f0bb79ddd48 | 190 | false, // publish_uri |
leothedragon | 0:8f0bb79ddd48 | 191 | false, // free_on_delete |
leothedragon | 0:8f0bb79ddd48 | 192 | true, // observable |
leothedragon | 0:8f0bb79ddd48 | 193 | false, // auto-observable |
leothedragon | 0:8f0bb79ddd48 | 194 | false, // always_publish |
leothedragon | 0:8f0bb79ddd48 | 195 | 0 // publish_value |
leothedragon | 0:8f0bb79ddd48 | 196 | }; |
leothedragon | 0:8f0bb79ddd48 | 197 | |
leothedragon | 0:8f0bb79ddd48 | 198 | static sn_nsdl_dynamic_resource_parameters_s firmware_package_uri_params_dynamic = { |
leothedragon | 0:8f0bb79ddd48 | 199 | __nsdl_c_callback, |
leothedragon | 0:8f0bb79ddd48 | 200 | &firmware_package_uri_params_static, |
leothedragon | 0:8f0bb79ddd48 | 201 | NULL, |
leothedragon | 0:8f0bb79ddd48 | 202 | {NULL, NULL}, // link |
leothedragon | 0:8f0bb79ddd48 | 203 | 0, |
leothedragon | 0:8f0bb79ddd48 | 204 | COAP_CONTENT_OMA_PLAIN_TEXT_TYPE, // coap_content_type |
leothedragon | 0:8f0bb79ddd48 | 205 | M2MBase::PUT_ALLOWED, // access |
leothedragon | 0:8f0bb79ddd48 | 206 | 0, // registered |
leothedragon | 0:8f0bb79ddd48 | 207 | false, // publish_uri |
leothedragon | 0:8f0bb79ddd48 | 208 | false, // free_on_delete |
leothedragon | 0:8f0bb79ddd48 | 209 | true, // observable |
leothedragon | 0:8f0bb79ddd48 | 210 | false, // auto-observable |
leothedragon | 0:8f0bb79ddd48 | 211 | false, // always_publish |
leothedragon | 0:8f0bb79ddd48 | 212 | 0 // publish_value |
leothedragon | 0:8f0bb79ddd48 | 213 | }; |
leothedragon | 0:8f0bb79ddd48 | 214 | |
leothedragon | 0:8f0bb79ddd48 | 215 | static sn_nsdl_dynamic_resource_parameters_s firmware_update_params_dynamic = { |
leothedragon | 0:8f0bb79ddd48 | 216 | __nsdl_c_callback, |
leothedragon | 0:8f0bb79ddd48 | 217 | &firmware_update_params_static, |
leothedragon | 0:8f0bb79ddd48 | 218 | NULL, |
leothedragon | 0:8f0bb79ddd48 | 219 | {NULL, NULL}, // link |
leothedragon | 0:8f0bb79ddd48 | 220 | 0, |
leothedragon | 0:8f0bb79ddd48 | 221 | COAP_CONTENT_OMA_PLAIN_TEXT_TYPE, // coap_content_type |
leothedragon | 0:8f0bb79ddd48 | 222 | M2MBase::NOT_ALLOWED, // access |
leothedragon | 0:8f0bb79ddd48 | 223 | 0, // registered |
leothedragon | 0:8f0bb79ddd48 | 224 | false, // publish_uri |
leothedragon | 0:8f0bb79ddd48 | 225 | false, // free_on_delete |
leothedragon | 0:8f0bb79ddd48 | 226 | true, // observable |
leothedragon | 0:8f0bb79ddd48 | 227 | false, // auto-observable |
leothedragon | 0:8f0bb79ddd48 | 228 | false, // always_publish |
leothedragon | 0:8f0bb79ddd48 | 229 | 0 // publish_value |
leothedragon | 0:8f0bb79ddd48 | 230 | }; |
leothedragon | 0:8f0bb79ddd48 | 231 | |
leothedragon | 0:8f0bb79ddd48 | 232 | static sn_nsdl_dynamic_resource_parameters_s firmware_state_params_dynamic = { |
leothedragon | 0:8f0bb79ddd48 | 233 | __nsdl_c_callback, |
leothedragon | 0:8f0bb79ddd48 | 234 | &firmware_state_params_static, |
leothedragon | 0:8f0bb79ddd48 | 235 | NULL, // resource |
leothedragon | 0:8f0bb79ddd48 | 236 | {NULL, NULL}, // link |
leothedragon | 0:8f0bb79ddd48 | 237 | 0, // resourcelen |
leothedragon | 0:8f0bb79ddd48 | 238 | COAP_CONTENT_OMA_PLAIN_TEXT_TYPE, // coap_content_type |
leothedragon | 0:8f0bb79ddd48 | 239 | M2MBase::GET_ALLOWED, // access |
leothedragon | 0:8f0bb79ddd48 | 240 | 0, // registered |
leothedragon | 0:8f0bb79ddd48 | 241 | false, // publish_uri |
leothedragon | 0:8f0bb79ddd48 | 242 | false, // free_on_delete |
leothedragon | 0:8f0bb79ddd48 | 243 | true, // observable |
leothedragon | 0:8f0bb79ddd48 | 244 | false, // auto-observable |
leothedragon | 0:8f0bb79ddd48 | 245 | false, // always_publish |
leothedragon | 0:8f0bb79ddd48 | 246 | 0 // publish_value |
leothedragon | 0:8f0bb79ddd48 | 247 | }; |
leothedragon | 0:8f0bb79ddd48 | 248 | |
leothedragon | 0:8f0bb79ddd48 | 249 | static sn_nsdl_dynamic_resource_parameters_s firmware_update_result_params_dynamic = { |
leothedragon | 0:8f0bb79ddd48 | 250 | __nsdl_c_callback, |
leothedragon | 0:8f0bb79ddd48 | 251 | &firmware_update_result_params_static, |
leothedragon | 0:8f0bb79ddd48 | 252 | NULL, // resource |
leothedragon | 0:8f0bb79ddd48 | 253 | {NULL, NULL}, // link |
leothedragon | 0:8f0bb79ddd48 | 254 | 0, // resourcelen |
leothedragon | 0:8f0bb79ddd48 | 255 | COAP_CONTENT_OMA_PLAIN_TEXT_TYPE, // coap_content_type |
leothedragon | 0:8f0bb79ddd48 | 256 | M2MBase::GET_ALLOWED, // access |
leothedragon | 0:8f0bb79ddd48 | 257 | 0, // registered |
leothedragon | 0:8f0bb79ddd48 | 258 | false, // publish_uri |
leothedragon | 0:8f0bb79ddd48 | 259 | false, // free_on_delete |
leothedragon | 0:8f0bb79ddd48 | 260 | true, // observable |
leothedragon | 0:8f0bb79ddd48 | 261 | false, // auto-observable |
leothedragon | 0:8f0bb79ddd48 | 262 | false, // always_publish |
leothedragon | 0:8f0bb79ddd48 | 263 | 0 // publish_value |
leothedragon | 0:8f0bb79ddd48 | 264 | }; |
leothedragon | 0:8f0bb79ddd48 | 265 | |
leothedragon | 0:8f0bb79ddd48 | 266 | const static M2MBase::lwm2m_parameters firmware_package_params = { |
leothedragon | 0:8f0bb79ddd48 | 267 | 0, // max_age |
leothedragon | 0:8f0bb79ddd48 | 268 | (char*)FIRMWARE_PACKAGE, |
leothedragon | 0:8f0bb79ddd48 | 269 | &firmware_package_params_dynamic, |
leothedragon | 0:8f0bb79ddd48 | 270 | M2MBase::Resource, // base_type |
leothedragon | 0:8f0bb79ddd48 | 271 | M2MBase::OPAQUE, |
leothedragon | 0:8f0bb79ddd48 | 272 | false, |
leothedragon | 0:8f0bb79ddd48 | 273 | false, // free_on_delete |
leothedragon | 0:8f0bb79ddd48 | 274 | false // identifier_int_type |
leothedragon | 0:8f0bb79ddd48 | 275 | }; |
leothedragon | 0:8f0bb79ddd48 | 276 | |
leothedragon | 0:8f0bb79ddd48 | 277 | const static M2MBase::lwm2m_parameters firmware_package_uri_params = { |
leothedragon | 0:8f0bb79ddd48 | 278 | 0, // max_age |
leothedragon | 0:8f0bb79ddd48 | 279 | (char*)FIRMWARE_PACKAGE_URI, |
leothedragon | 0:8f0bb79ddd48 | 280 | &firmware_package_uri_params_dynamic, |
leothedragon | 0:8f0bb79ddd48 | 281 | M2MBase::Resource, // base_type |
leothedragon | 0:8f0bb79ddd48 | 282 | M2MBase::STRING, |
leothedragon | 0:8f0bb79ddd48 | 283 | false, |
leothedragon | 0:8f0bb79ddd48 | 284 | false, // free_on_delete |
leothedragon | 0:8f0bb79ddd48 | 285 | false // identifier_int_type |
leothedragon | 0:8f0bb79ddd48 | 286 | }; |
leothedragon | 0:8f0bb79ddd48 | 287 | |
leothedragon | 0:8f0bb79ddd48 | 288 | const static M2MBase::lwm2m_parameters firmware_update_params = { |
leothedragon | 0:8f0bb79ddd48 | 289 | 0, // max_age |
leothedragon | 0:8f0bb79ddd48 | 290 | (char*)FIRMWARE_UPDATE, |
leothedragon | 0:8f0bb79ddd48 | 291 | &firmware_update_params_dynamic, |
leothedragon | 0:8f0bb79ddd48 | 292 | M2MBase::Resource, // base_type |
leothedragon | 0:8f0bb79ddd48 | 293 | M2MBase::OPAQUE, |
leothedragon | 0:8f0bb79ddd48 | 294 | false, |
leothedragon | 0:8f0bb79ddd48 | 295 | false, // free_on_delete |
leothedragon | 0:8f0bb79ddd48 | 296 | false // identifier_int_type |
leothedragon | 0:8f0bb79ddd48 | 297 | }; |
leothedragon | 0:8f0bb79ddd48 | 298 | |
leothedragon | 0:8f0bb79ddd48 | 299 | const static M2MBase::lwm2m_parameters firmware_state_params = { |
leothedragon | 0:8f0bb79ddd48 | 300 | 0, // max_age |
leothedragon | 0:8f0bb79ddd48 | 301 | (char*)FIRMWARE_STATE, |
leothedragon | 0:8f0bb79ddd48 | 302 | &firmware_state_params_dynamic, |
leothedragon | 0:8f0bb79ddd48 | 303 | M2MBase::Resource, // base_type |
leothedragon | 0:8f0bb79ddd48 | 304 | M2MBase::INTEGER, |
leothedragon | 0:8f0bb79ddd48 | 305 | false, |
leothedragon | 0:8f0bb79ddd48 | 306 | false, // free_on_delete |
leothedragon | 0:8f0bb79ddd48 | 307 | false // identifier_int_type |
leothedragon | 0:8f0bb79ddd48 | 308 | }; |
leothedragon | 0:8f0bb79ddd48 | 309 | |
leothedragon | 0:8f0bb79ddd48 | 310 | const static M2MBase::lwm2m_parameters firmware_update_result_params = { |
leothedragon | 0:8f0bb79ddd48 | 311 | 0, // max_age |
leothedragon | 0:8f0bb79ddd48 | 312 | (char*)FIRMWARE_UPDATE_RESULT, |
leothedragon | 0:8f0bb79ddd48 | 313 | &firmware_update_result_params_dynamic, |
leothedragon | 0:8f0bb79ddd48 | 314 | M2MBase::Resource, // base_type |
leothedragon | 0:8f0bb79ddd48 | 315 | M2MBase::INTEGER, |
leothedragon | 0:8f0bb79ddd48 | 316 | false, |
leothedragon | 0:8f0bb79ddd48 | 317 | false, // free_on_delete |
leothedragon | 0:8f0bb79ddd48 | 318 | false // identifier_int_type |
leothedragon | 0:8f0bb79ddd48 | 319 | }; |
leothedragon | 0:8f0bb79ddd48 | 320 | |
leothedragon | 0:8f0bb79ddd48 | 321 | void M2MFirmware::create_mandatory_resources() |
leothedragon | 0:8f0bb79ddd48 | 322 | { |
leothedragon | 0:8f0bb79ddd48 | 323 | _firmware_instance->set_coap_content_type(COAP_CONTENT_OMA_TLV_TYPE); |
leothedragon | 0:8f0bb79ddd48 | 324 | |
leothedragon | 0:8f0bb79ddd48 | 325 | M2MResource* res; |
leothedragon | 0:8f0bb79ddd48 | 326 | |
leothedragon | 0:8f0bb79ddd48 | 327 | // todo: |
leothedragon | 0:8f0bb79ddd48 | 328 | // perhaps we should have a API for batch creation of objects by using a array |
leothedragon | 0:8f0bb79ddd48 | 329 | // of lwm2m_parameters. |
leothedragon | 0:8f0bb79ddd48 | 330 | res = _firmware_instance->create_dynamic_resource(&firmware_package_params, |
leothedragon | 0:8f0bb79ddd48 | 331 | M2MResourceInstance::OPAQUE, |
leothedragon | 0:8f0bb79ddd48 | 332 | false); |
leothedragon | 0:8f0bb79ddd48 | 333 | |
leothedragon | 0:8f0bb79ddd48 | 334 | res = _firmware_instance->create_dynamic_resource(&firmware_package_uri_params, |
leothedragon | 0:8f0bb79ddd48 | 335 | M2MResourceInstance::STRING, |
leothedragon | 0:8f0bb79ddd48 | 336 | false); |
leothedragon | 0:8f0bb79ddd48 | 337 | |
leothedragon | 0:8f0bb79ddd48 | 338 | res = _firmware_instance->create_dynamic_resource(&firmware_update_params, |
leothedragon | 0:8f0bb79ddd48 | 339 | M2MResourceInstance::OPAQUE, |
leothedragon | 0:8f0bb79ddd48 | 340 | false); |
leothedragon | 0:8f0bb79ddd48 | 341 | |
leothedragon | 0:8f0bb79ddd48 | 342 | res = _firmware_instance->create_dynamic_resource(&firmware_state_params, |
leothedragon | 0:8f0bb79ddd48 | 343 | M2MResourceInstance::INTEGER, |
leothedragon | 0:8f0bb79ddd48 | 344 | true); |
leothedragon | 0:8f0bb79ddd48 | 345 | |
leothedragon | 0:8f0bb79ddd48 | 346 | // XXX: some of the tests expect to have some value available here |
leothedragon | 0:8f0bb79ddd48 | 347 | if (res) { |
leothedragon | 0:8f0bb79ddd48 | 348 | res->set_value(0); |
leothedragon | 0:8f0bb79ddd48 | 349 | } |
leothedragon | 0:8f0bb79ddd48 | 350 | |
leothedragon | 0:8f0bb79ddd48 | 351 | res = _firmware_instance->create_dynamic_resource(&firmware_update_result_params, |
leothedragon | 0:8f0bb79ddd48 | 352 | M2MResourceInstance::INTEGER, |
leothedragon | 0:8f0bb79ddd48 | 353 | true); |
leothedragon | 0:8f0bb79ddd48 | 354 | |
leothedragon | 0:8f0bb79ddd48 | 355 | // XXX: some of the tests expect to have some value available here |
leothedragon | 0:8f0bb79ddd48 | 356 | if (res) { |
leothedragon | 0:8f0bb79ddd48 | 357 | res->set_value(0); |
leothedragon | 0:8f0bb79ddd48 | 358 | } |
leothedragon | 0:8f0bb79ddd48 | 359 | } |
leothedragon | 0:8f0bb79ddd48 | 360 | |
leothedragon | 0:8f0bb79ddd48 | 361 | M2MResource* M2MFirmware::create_resource(FirmwareResource resource, const String &value) |
leothedragon | 0:8f0bb79ddd48 | 362 | { |
leothedragon | 0:8f0bb79ddd48 | 363 | M2MResource* res = NULL; |
leothedragon | 0:8f0bb79ddd48 | 364 | const char* firmware_id_ptr = ""; |
leothedragon | 0:8f0bb79ddd48 | 365 | M2MBase::Operation operation = M2MBase::GET_ALLOWED; |
leothedragon | 0:8f0bb79ddd48 | 366 | if(!is_resource_present(resource)) { |
leothedragon | 0:8f0bb79ddd48 | 367 | switch(resource) { |
leothedragon | 0:8f0bb79ddd48 | 368 | case PackageName: |
leothedragon | 0:8f0bb79ddd48 | 369 | firmware_id_ptr = FIRMWARE_PACKAGE_NAME; |
leothedragon | 0:8f0bb79ddd48 | 370 | break; |
leothedragon | 0:8f0bb79ddd48 | 371 | case PackageVersion: |
leothedragon | 0:8f0bb79ddd48 | 372 | firmware_id_ptr = FIRMWARE_PACKAGE_VERSION; |
leothedragon | 0:8f0bb79ddd48 | 373 | break; |
leothedragon | 0:8f0bb79ddd48 | 374 | default: |
leothedragon | 0:8f0bb79ddd48 | 375 | break; |
leothedragon | 0:8f0bb79ddd48 | 376 | } |
leothedragon | 0:8f0bb79ddd48 | 377 | } |
leothedragon | 0:8f0bb79ddd48 | 378 | String firmware_id(firmware_id_ptr); |
leothedragon | 0:8f0bb79ddd48 | 379 | |
leothedragon | 0:8f0bb79ddd48 | 380 | if(!firmware_id.empty() && value.size() < 256) { |
leothedragon | 0:8f0bb79ddd48 | 381 | if(_firmware_instance) { |
leothedragon | 0:8f0bb79ddd48 | 382 | res = _firmware_instance->create_dynamic_resource(firmware_id, |
leothedragon | 0:8f0bb79ddd48 | 383 | OMA_RESOURCE_TYPE, |
leothedragon | 0:8f0bb79ddd48 | 384 | M2MResourceInstance::STRING, |
leothedragon | 0:8f0bb79ddd48 | 385 | false); |
leothedragon | 0:8f0bb79ddd48 | 386 | |
leothedragon | 0:8f0bb79ddd48 | 387 | if(res) { |
leothedragon | 0:8f0bb79ddd48 | 388 | res->set_register_uri(false); |
leothedragon | 0:8f0bb79ddd48 | 389 | res->set_operation(operation); |
leothedragon | 0:8f0bb79ddd48 | 390 | if(value.empty()) { |
leothedragon | 0:8f0bb79ddd48 | 391 | res->clear_value(); |
leothedragon | 0:8f0bb79ddd48 | 392 | } else { |
leothedragon | 0:8f0bb79ddd48 | 393 | res->set_value((const uint8_t*)value.c_str(), |
leothedragon | 0:8f0bb79ddd48 | 394 | (uint32_t)value.length()); |
leothedragon | 0:8f0bb79ddd48 | 395 | } |
leothedragon | 0:8f0bb79ddd48 | 396 | } |
leothedragon | 0:8f0bb79ddd48 | 397 | } |
leothedragon | 0:8f0bb79ddd48 | 398 | } |
leothedragon | 0:8f0bb79ddd48 | 399 | return res; |
leothedragon | 0:8f0bb79ddd48 | 400 | } |
leothedragon | 0:8f0bb79ddd48 | 401 | |
leothedragon | 0:8f0bb79ddd48 | 402 | M2MResource* M2MFirmware::create_resource(FirmwareResource resource, int64_t value) |
leothedragon | 0:8f0bb79ddd48 | 403 | { |
leothedragon | 0:8f0bb79ddd48 | 404 | M2MResource* res = NULL; |
leothedragon | 0:8f0bb79ddd48 | 405 | const char* firmware_id_ptr = ""; |
leothedragon | 0:8f0bb79ddd48 | 406 | M2MBase::Operation operation = M2MBase::GET_ALLOWED; |
leothedragon | 0:8f0bb79ddd48 | 407 | if(!is_resource_present(resource)) { |
leothedragon | 0:8f0bb79ddd48 | 408 | switch(resource) { |
leothedragon | 0:8f0bb79ddd48 | 409 | case UpdateSupportedObjects: |
leothedragon | 0:8f0bb79ddd48 | 410 | if(check_value_range(resource, value)) { |
leothedragon | 0:8f0bb79ddd48 | 411 | firmware_id_ptr = FIRMWARE_UPDATE_SUPPORTED_OBJECTS; |
leothedragon | 0:8f0bb79ddd48 | 412 | operation = M2MBase::GET_PUT_ALLOWED; |
leothedragon | 0:8f0bb79ddd48 | 413 | } |
leothedragon | 0:8f0bb79ddd48 | 414 | break; |
leothedragon | 0:8f0bb79ddd48 | 415 | default: |
leothedragon | 0:8f0bb79ddd48 | 416 | break; |
leothedragon | 0:8f0bb79ddd48 | 417 | } |
leothedragon | 0:8f0bb79ddd48 | 418 | } |
leothedragon | 0:8f0bb79ddd48 | 419 | |
leothedragon | 0:8f0bb79ddd48 | 420 | const String firmware_id(firmware_id_ptr); |
leothedragon | 0:8f0bb79ddd48 | 421 | |
leothedragon | 0:8f0bb79ddd48 | 422 | if(!firmware_id.empty()) { |
leothedragon | 0:8f0bb79ddd48 | 423 | if(_firmware_instance) { |
leothedragon | 0:8f0bb79ddd48 | 424 | res = _firmware_instance->create_dynamic_resource(firmware_id, |
leothedragon | 0:8f0bb79ddd48 | 425 | OMA_RESOURCE_TYPE, |
leothedragon | 0:8f0bb79ddd48 | 426 | M2MResourceInstance::INTEGER, |
leothedragon | 0:8f0bb79ddd48 | 427 | false); |
leothedragon | 0:8f0bb79ddd48 | 428 | |
leothedragon | 0:8f0bb79ddd48 | 429 | if(res) { |
leothedragon | 0:8f0bb79ddd48 | 430 | res->set_register_uri(false); |
leothedragon | 0:8f0bb79ddd48 | 431 | |
leothedragon | 0:8f0bb79ddd48 | 432 | res->set_operation(operation); |
leothedragon | 0:8f0bb79ddd48 | 433 | res->set_value(value); |
leothedragon | 0:8f0bb79ddd48 | 434 | } |
leothedragon | 0:8f0bb79ddd48 | 435 | } |
leothedragon | 0:8f0bb79ddd48 | 436 | } |
leothedragon | 0:8f0bb79ddd48 | 437 | return res; |
leothedragon | 0:8f0bb79ddd48 | 438 | } |
leothedragon | 0:8f0bb79ddd48 | 439 | |
leothedragon | 0:8f0bb79ddd48 | 440 | bool M2MFirmware::set_resource_value(FirmwareResource resource, |
leothedragon | 0:8f0bb79ddd48 | 441 | const String &value) |
leothedragon | 0:8f0bb79ddd48 | 442 | { |
leothedragon | 0:8f0bb79ddd48 | 443 | bool success = false; |
leothedragon | 0:8f0bb79ddd48 | 444 | M2MResource* res = get_resource(resource); |
leothedragon | 0:8f0bb79ddd48 | 445 | if(res) { |
leothedragon | 0:8f0bb79ddd48 | 446 | if(M2MFirmware::PackageUri == resource || |
leothedragon | 0:8f0bb79ddd48 | 447 | M2MFirmware::PackageName == resource || |
leothedragon | 0:8f0bb79ddd48 | 448 | M2MFirmware::PackageVersion == resource) { |
leothedragon | 0:8f0bb79ddd48 | 449 | if (value.size() < 256) { |
leothedragon | 0:8f0bb79ddd48 | 450 | if(value.empty()) { |
leothedragon | 0:8f0bb79ddd48 | 451 | res->clear_value(); |
leothedragon | 0:8f0bb79ddd48 | 452 | success = true; |
leothedragon | 0:8f0bb79ddd48 | 453 | } else { |
leothedragon | 0:8f0bb79ddd48 | 454 | success = res->set_value((const uint8_t*)value.c_str(),(uint32_t)value.length()); |
leothedragon | 0:8f0bb79ddd48 | 455 | } |
leothedragon | 0:8f0bb79ddd48 | 456 | } |
leothedragon | 0:8f0bb79ddd48 | 457 | } |
leothedragon | 0:8f0bb79ddd48 | 458 | } |
leothedragon | 0:8f0bb79ddd48 | 459 | return success; |
leothedragon | 0:8f0bb79ddd48 | 460 | } |
leothedragon | 0:8f0bb79ddd48 | 461 | |
leothedragon | 0:8f0bb79ddd48 | 462 | bool M2MFirmware::set_resource_value(FirmwareResource resource, |
leothedragon | 0:8f0bb79ddd48 | 463 | int64_t value) |
leothedragon | 0:8f0bb79ddd48 | 464 | { |
leothedragon | 0:8f0bb79ddd48 | 465 | bool success = false; |
leothedragon | 0:8f0bb79ddd48 | 466 | M2MResource* res = get_resource(resource); |
leothedragon | 0:8f0bb79ddd48 | 467 | if(res) { |
leothedragon | 0:8f0bb79ddd48 | 468 | if(M2MFirmware::State == resource || |
leothedragon | 0:8f0bb79ddd48 | 469 | M2MFirmware::UpdateSupportedObjects == resource || |
leothedragon | 0:8f0bb79ddd48 | 470 | M2MFirmware::UpdateResult == resource) { |
leothedragon | 0:8f0bb79ddd48 | 471 | // If it is any of the above resource |
leothedragon | 0:8f0bb79ddd48 | 472 | // set the value of the resource. |
leothedragon | 0:8f0bb79ddd48 | 473 | if (check_value_range(resource, value)) { |
leothedragon | 0:8f0bb79ddd48 | 474 | |
leothedragon | 0:8f0bb79ddd48 | 475 | success = res->set_value(value); |
leothedragon | 0:8f0bb79ddd48 | 476 | } |
leothedragon | 0:8f0bb79ddd48 | 477 | } |
leothedragon | 0:8f0bb79ddd48 | 478 | } |
leothedragon | 0:8f0bb79ddd48 | 479 | return success; |
leothedragon | 0:8f0bb79ddd48 | 480 | } |
leothedragon | 0:8f0bb79ddd48 | 481 | |
leothedragon | 0:8f0bb79ddd48 | 482 | bool M2MFirmware::set_resource_value(FirmwareResource resource, |
leothedragon | 0:8f0bb79ddd48 | 483 | const uint8_t *value, |
leothedragon | 0:8f0bb79ddd48 | 484 | const uint32_t length) |
leothedragon | 0:8f0bb79ddd48 | 485 | { |
leothedragon | 0:8f0bb79ddd48 | 486 | bool success = false; |
leothedragon | 0:8f0bb79ddd48 | 487 | M2MResource* res = get_resource(resource); |
leothedragon | 0:8f0bb79ddd48 | 488 | if(res) { |
leothedragon | 0:8f0bb79ddd48 | 489 | if(M2MFirmware::Package == resource) { |
leothedragon | 0:8f0bb79ddd48 | 490 | success = res->set_value(value,length); |
leothedragon | 0:8f0bb79ddd48 | 491 | } |
leothedragon | 0:8f0bb79ddd48 | 492 | } |
leothedragon | 0:8f0bb79ddd48 | 493 | return success; |
leothedragon | 0:8f0bb79ddd48 | 494 | } |
leothedragon | 0:8f0bb79ddd48 | 495 | |
leothedragon | 0:8f0bb79ddd48 | 496 | bool M2MFirmware::is_resource_present(FirmwareResource resource) const |
leothedragon | 0:8f0bb79ddd48 | 497 | { |
leothedragon | 0:8f0bb79ddd48 | 498 | bool success = false; |
leothedragon | 0:8f0bb79ddd48 | 499 | M2MResource* res = get_resource(resource); |
leothedragon | 0:8f0bb79ddd48 | 500 | if(res) { |
leothedragon | 0:8f0bb79ddd48 | 501 | success = true; |
leothedragon | 0:8f0bb79ddd48 | 502 | } |
leothedragon | 0:8f0bb79ddd48 | 503 | return success; |
leothedragon | 0:8f0bb79ddd48 | 504 | } |
leothedragon | 0:8f0bb79ddd48 | 505 | |
leothedragon | 0:8f0bb79ddd48 | 506 | const char* M2MFirmware::resource_name(FirmwareResource resource) |
leothedragon | 0:8f0bb79ddd48 | 507 | { |
leothedragon | 0:8f0bb79ddd48 | 508 | const char* res_name = ""; |
leothedragon | 0:8f0bb79ddd48 | 509 | switch(resource) { |
leothedragon | 0:8f0bb79ddd48 | 510 | case Package: |
leothedragon | 0:8f0bb79ddd48 | 511 | res_name = FIRMWARE_PACKAGE; |
leothedragon | 0:8f0bb79ddd48 | 512 | break; |
leothedragon | 0:8f0bb79ddd48 | 513 | case PackageUri: |
leothedragon | 0:8f0bb79ddd48 | 514 | res_name = FIRMWARE_PACKAGE_URI; |
leothedragon | 0:8f0bb79ddd48 | 515 | break; |
leothedragon | 0:8f0bb79ddd48 | 516 | case Update: |
leothedragon | 0:8f0bb79ddd48 | 517 | res_name = FIRMWARE_UPDATE; |
leothedragon | 0:8f0bb79ddd48 | 518 | break; |
leothedragon | 0:8f0bb79ddd48 | 519 | case State: |
leothedragon | 0:8f0bb79ddd48 | 520 | res_name = FIRMWARE_STATE; |
leothedragon | 0:8f0bb79ddd48 | 521 | break; |
leothedragon | 0:8f0bb79ddd48 | 522 | case UpdateSupportedObjects: |
leothedragon | 0:8f0bb79ddd48 | 523 | res_name = FIRMWARE_UPDATE_SUPPORTED_OBJECTS; |
leothedragon | 0:8f0bb79ddd48 | 524 | break; |
leothedragon | 0:8f0bb79ddd48 | 525 | case UpdateResult: |
leothedragon | 0:8f0bb79ddd48 | 526 | res_name = FIRMWARE_UPDATE_RESULT; |
leothedragon | 0:8f0bb79ddd48 | 527 | break; |
leothedragon | 0:8f0bb79ddd48 | 528 | case PackageName: |
leothedragon | 0:8f0bb79ddd48 | 529 | res_name = FIRMWARE_PACKAGE_NAME; |
leothedragon | 0:8f0bb79ddd48 | 530 | break; |
leothedragon | 0:8f0bb79ddd48 | 531 | case PackageVersion: |
leothedragon | 0:8f0bb79ddd48 | 532 | res_name = FIRMWARE_PACKAGE_VERSION; |
leothedragon | 0:8f0bb79ddd48 | 533 | break; |
leothedragon | 0:8f0bb79ddd48 | 534 | } |
leothedragon | 0:8f0bb79ddd48 | 535 | return res_name; |
leothedragon | 0:8f0bb79ddd48 | 536 | } |
leothedragon | 0:8f0bb79ddd48 | 537 | |
leothedragon | 0:8f0bb79ddd48 | 538 | uint16_t M2MFirmware::per_resource_count(FirmwareResource res) const |
leothedragon | 0:8f0bb79ddd48 | 539 | { |
leothedragon | 0:8f0bb79ddd48 | 540 | uint16_t count = 0; |
leothedragon | 0:8f0bb79ddd48 | 541 | if(_firmware_instance) { |
leothedragon | 0:8f0bb79ddd48 | 542 | count = _firmware_instance->resource_count(resource_name(res)); |
leothedragon | 0:8f0bb79ddd48 | 543 | } |
leothedragon | 0:8f0bb79ddd48 | 544 | return count; |
leothedragon | 0:8f0bb79ddd48 | 545 | } |
leothedragon | 0:8f0bb79ddd48 | 546 | |
leothedragon | 0:8f0bb79ddd48 | 547 | uint16_t M2MFirmware::total_resource_count() const |
leothedragon | 0:8f0bb79ddd48 | 548 | { |
leothedragon | 0:8f0bb79ddd48 | 549 | uint16_t count = 0; |
leothedragon | 0:8f0bb79ddd48 | 550 | if(_firmware_instance) { |
leothedragon | 0:8f0bb79ddd48 | 551 | count = _firmware_instance->resources().size(); |
leothedragon | 0:8f0bb79ddd48 | 552 | } |
leothedragon | 0:8f0bb79ddd48 | 553 | return count; |
leothedragon | 0:8f0bb79ddd48 | 554 | } |
leothedragon | 0:8f0bb79ddd48 | 555 | |
leothedragon | 0:8f0bb79ddd48 | 556 | uint32_t M2MFirmware::resource_value_buffer(FirmwareResource resource, |
leothedragon | 0:8f0bb79ddd48 | 557 | uint8_t *&data) const |
leothedragon | 0:8f0bb79ddd48 | 558 | { |
leothedragon | 0:8f0bb79ddd48 | 559 | uint32_t size = 0; |
leothedragon | 0:8f0bb79ddd48 | 560 | M2MResource* res = get_resource(resource); |
leothedragon | 0:8f0bb79ddd48 | 561 | if(res) { |
leothedragon | 0:8f0bb79ddd48 | 562 | if(M2MFirmware::Package == resource) { |
leothedragon | 0:8f0bb79ddd48 | 563 | res->get_value(data,size); |
leothedragon | 0:8f0bb79ddd48 | 564 | } |
leothedragon | 0:8f0bb79ddd48 | 565 | } |
leothedragon | 0:8f0bb79ddd48 | 566 | return size; |
leothedragon | 0:8f0bb79ddd48 | 567 | } |
leothedragon | 0:8f0bb79ddd48 | 568 | |
leothedragon | 0:8f0bb79ddd48 | 569 | M2MResource* M2MFirmware::get_resource(FirmwareResource res) const |
leothedragon | 0:8f0bb79ddd48 | 570 | { |
leothedragon | 0:8f0bb79ddd48 | 571 | M2MResource* res_object = NULL; |
leothedragon | 0:8f0bb79ddd48 | 572 | if(_firmware_instance) { |
leothedragon | 0:8f0bb79ddd48 | 573 | const char* res_name_ptr = ""; |
leothedragon | 0:8f0bb79ddd48 | 574 | switch(res) { |
leothedragon | 0:8f0bb79ddd48 | 575 | case Package: |
leothedragon | 0:8f0bb79ddd48 | 576 | res_name_ptr = FIRMWARE_PACKAGE; |
leothedragon | 0:8f0bb79ddd48 | 577 | break; |
leothedragon | 0:8f0bb79ddd48 | 578 | case PackageUri: |
leothedragon | 0:8f0bb79ddd48 | 579 | res_name_ptr = FIRMWARE_PACKAGE_URI; |
leothedragon | 0:8f0bb79ddd48 | 580 | break; |
leothedragon | 0:8f0bb79ddd48 | 581 | case Update: |
leothedragon | 0:8f0bb79ddd48 | 582 | res_name_ptr = FIRMWARE_UPDATE; |
leothedragon | 0:8f0bb79ddd48 | 583 | break; |
leothedragon | 0:8f0bb79ddd48 | 584 | case State: |
leothedragon | 0:8f0bb79ddd48 | 585 | res_name_ptr = FIRMWARE_STATE; |
leothedragon | 0:8f0bb79ddd48 | 586 | break; |
leothedragon | 0:8f0bb79ddd48 | 587 | case UpdateSupportedObjects: |
leothedragon | 0:8f0bb79ddd48 | 588 | res_name_ptr = FIRMWARE_UPDATE_SUPPORTED_OBJECTS; |
leothedragon | 0:8f0bb79ddd48 | 589 | break; |
leothedragon | 0:8f0bb79ddd48 | 590 | case UpdateResult: |
leothedragon | 0:8f0bb79ddd48 | 591 | res_name_ptr = FIRMWARE_UPDATE_RESULT; |
leothedragon | 0:8f0bb79ddd48 | 592 | break; |
leothedragon | 0:8f0bb79ddd48 | 593 | case PackageName: |
leothedragon | 0:8f0bb79ddd48 | 594 | res_name_ptr = FIRMWARE_PACKAGE_NAME; |
leothedragon | 0:8f0bb79ddd48 | 595 | break; |
leothedragon | 0:8f0bb79ddd48 | 596 | case PackageVersion: |
leothedragon | 0:8f0bb79ddd48 | 597 | res_name_ptr = FIRMWARE_PACKAGE_VERSION; |
leothedragon | 0:8f0bb79ddd48 | 598 | break; |
leothedragon | 0:8f0bb79ddd48 | 599 | } |
leothedragon | 0:8f0bb79ddd48 | 600 | |
leothedragon | 0:8f0bb79ddd48 | 601 | res_object = _firmware_instance->resource(res_name_ptr); |
leothedragon | 0:8f0bb79ddd48 | 602 | } |
leothedragon | 0:8f0bb79ddd48 | 603 | return res_object; |
leothedragon | 0:8f0bb79ddd48 | 604 | } |
leothedragon | 0:8f0bb79ddd48 | 605 | |
leothedragon | 0:8f0bb79ddd48 | 606 | bool M2MFirmware::delete_resource(FirmwareResource resource) |
leothedragon | 0:8f0bb79ddd48 | 607 | { |
leothedragon | 0:8f0bb79ddd48 | 608 | bool success = false; |
leothedragon | 0:8f0bb79ddd48 | 609 | if(M2MFirmware::UpdateSupportedObjects == resource || |
leothedragon | 0:8f0bb79ddd48 | 610 | M2MFirmware::PackageName == resource || |
leothedragon | 0:8f0bb79ddd48 | 611 | M2MFirmware::PackageVersion == resource) { |
leothedragon | 0:8f0bb79ddd48 | 612 | if(_firmware_instance) { |
leothedragon | 0:8f0bb79ddd48 | 613 | success = _firmware_instance->remove_resource(resource_name(resource)); |
leothedragon | 0:8f0bb79ddd48 | 614 | } |
leothedragon | 0:8f0bb79ddd48 | 615 | } |
leothedragon | 0:8f0bb79ddd48 | 616 | return success; |
leothedragon | 0:8f0bb79ddd48 | 617 | } |
leothedragon | 0:8f0bb79ddd48 | 618 | |
leothedragon | 0:8f0bb79ddd48 | 619 | int64_t M2MFirmware::resource_value_int(FirmwareResource resource) const |
leothedragon | 0:8f0bb79ddd48 | 620 | { |
leothedragon | 0:8f0bb79ddd48 | 621 | int64_t value = -1; |
leothedragon | 0:8f0bb79ddd48 | 622 | M2MResource* res = get_resource(resource); |
leothedragon | 0:8f0bb79ddd48 | 623 | if(res) { |
leothedragon | 0:8f0bb79ddd48 | 624 | if(M2MFirmware::State == resource || |
leothedragon | 0:8f0bb79ddd48 | 625 | M2MFirmware::UpdateSupportedObjects == resource || |
leothedragon | 0:8f0bb79ddd48 | 626 | M2MFirmware::UpdateResult == resource) { |
leothedragon | 0:8f0bb79ddd48 | 627 | |
leothedragon | 0:8f0bb79ddd48 | 628 | value = res->get_value_int(); |
leothedragon | 0:8f0bb79ddd48 | 629 | } |
leothedragon | 0:8f0bb79ddd48 | 630 | } |
leothedragon | 0:8f0bb79ddd48 | 631 | return value; |
leothedragon | 0:8f0bb79ddd48 | 632 | } |
leothedragon | 0:8f0bb79ddd48 | 633 | |
leothedragon | 0:8f0bb79ddd48 | 634 | String M2MFirmware::resource_value_string(FirmwareResource resource) const |
leothedragon | 0:8f0bb79ddd48 | 635 | { |
leothedragon | 0:8f0bb79ddd48 | 636 | String value = ""; |
leothedragon | 0:8f0bb79ddd48 | 637 | M2MResource* res = get_resource(resource); |
leothedragon | 0:8f0bb79ddd48 | 638 | if(res) { |
leothedragon | 0:8f0bb79ddd48 | 639 | if(M2MFirmware::PackageUri == resource || |
leothedragon | 0:8f0bb79ddd48 | 640 | M2MFirmware::PackageName == resource || |
leothedragon | 0:8f0bb79ddd48 | 641 | M2MFirmware::PackageVersion == resource) { |
leothedragon | 0:8f0bb79ddd48 | 642 | |
leothedragon | 0:8f0bb79ddd48 | 643 | value = res->get_value_string(); |
leothedragon | 0:8f0bb79ddd48 | 644 | } |
leothedragon | 0:8f0bb79ddd48 | 645 | } |
leothedragon | 0:8f0bb79ddd48 | 646 | return value; |
leothedragon | 0:8f0bb79ddd48 | 647 | } |
leothedragon | 0:8f0bb79ddd48 | 648 | |
leothedragon | 0:8f0bb79ddd48 | 649 | bool M2MFirmware::check_value_range(FirmwareResource resource, int64_t value) const |
leothedragon | 0:8f0bb79ddd48 | 650 | { |
leothedragon | 0:8f0bb79ddd48 | 651 | bool success = false; |
leothedragon | 0:8f0bb79ddd48 | 652 | switch (resource) { |
leothedragon | 0:8f0bb79ddd48 | 653 | case UpdateSupportedObjects: |
leothedragon | 0:8f0bb79ddd48 | 654 | if(value == 0 || value == 1) { |
leothedragon | 0:8f0bb79ddd48 | 655 | success = true; |
leothedragon | 0:8f0bb79ddd48 | 656 | } |
leothedragon | 0:8f0bb79ddd48 | 657 | break; |
leothedragon | 0:8f0bb79ddd48 | 658 | case State: |
leothedragon | 0:8f0bb79ddd48 | 659 | if (value >= 0 && value <= 3) { |
leothedragon | 0:8f0bb79ddd48 | 660 | success = true; |
leothedragon | 0:8f0bb79ddd48 | 661 | M2MResource* updateRes = get_resource(M2MFirmware::Update); |
leothedragon | 0:8f0bb79ddd48 | 662 | if (updateRes){ |
leothedragon | 0:8f0bb79ddd48 | 663 | if (value == M2MFirmware::Downloaded) { |
leothedragon | 0:8f0bb79ddd48 | 664 | updateRes->set_operation(M2MBase::POST_ALLOWED); |
leothedragon | 0:8f0bb79ddd48 | 665 | } |
leothedragon | 0:8f0bb79ddd48 | 666 | else { |
leothedragon | 0:8f0bb79ddd48 | 667 | updateRes->set_operation(M2MBase::NOT_ALLOWED); |
leothedragon | 0:8f0bb79ddd48 | 668 | } |
leothedragon | 0:8f0bb79ddd48 | 669 | } |
leothedragon | 0:8f0bb79ddd48 | 670 | } |
leothedragon | 0:8f0bb79ddd48 | 671 | break; |
leothedragon | 0:8f0bb79ddd48 | 672 | case UpdateResult: |
leothedragon | 0:8f0bb79ddd48 | 673 | if (value >= 0 && value <= 7) { |
leothedragon | 0:8f0bb79ddd48 | 674 | success = true; |
leothedragon | 0:8f0bb79ddd48 | 675 | } |
leothedragon | 0:8f0bb79ddd48 | 676 | break; |
leothedragon | 0:8f0bb79ddd48 | 677 | default: |
leothedragon | 0:8f0bb79ddd48 | 678 | break; |
leothedragon | 0:8f0bb79ddd48 | 679 | } |
leothedragon | 0:8f0bb79ddd48 | 680 | return success; |
leothedragon | 0:8f0bb79ddd48 | 681 | } |
leothedragon | 0:8f0bb79ddd48 | 682 | |
leothedragon | 0:8f0bb79ddd48 | 683 | bool M2MFirmware::set_update_execute_callback(execute_callback callback) |
leothedragon | 0:8f0bb79ddd48 | 684 | { |
leothedragon | 0:8f0bb79ddd48 | 685 | M2MResource* m2mresource; |
leothedragon | 0:8f0bb79ddd48 | 686 | |
leothedragon | 0:8f0bb79ddd48 | 687 | m2mresource = get_resource(Update); |
leothedragon | 0:8f0bb79ddd48 | 688 | |
leothedragon | 0:8f0bb79ddd48 | 689 | if(m2mresource) { |
leothedragon | 0:8f0bb79ddd48 | 690 | m2mresource->set_execute_function(callback); |
leothedragon | 0:8f0bb79ddd48 | 691 | return true; |
leothedragon | 0:8f0bb79ddd48 | 692 | } |
leothedragon | 0:8f0bb79ddd48 | 693 | |
leothedragon | 0:8f0bb79ddd48 | 694 | return false; |
leothedragon | 0:8f0bb79ddd48 | 695 | } |
leothedragon | 0:8f0bb79ddd48 | 696 | |
leothedragon | 0:8f0bb79ddd48 | 697 | bool M2MFirmware::set_resource_value_update_callback(FirmwareResource resource, |
leothedragon | 0:8f0bb79ddd48 | 698 | value_updated_callback callback) |
leothedragon | 0:8f0bb79ddd48 | 699 | { |
leothedragon | 0:8f0bb79ddd48 | 700 | M2MResource* m2mresource; |
leothedragon | 0:8f0bb79ddd48 | 701 | |
leothedragon | 0:8f0bb79ddd48 | 702 | m2mresource = get_resource(resource); |
leothedragon | 0:8f0bb79ddd48 | 703 | |
leothedragon | 0:8f0bb79ddd48 | 704 | if(m2mresource) { |
leothedragon | 0:8f0bb79ddd48 | 705 | m2mresource->set_value_updated_function(callback); |
leothedragon | 0:8f0bb79ddd48 | 706 | return true; |
leothedragon | 0:8f0bb79ddd48 | 707 | } |
leothedragon | 0:8f0bb79ddd48 | 708 | |
leothedragon | 0:8f0bb79ddd48 | 709 | return false; |
leothedragon | 0:8f0bb79ddd48 | 710 | } |
leothedragon | 0:8f0bb79ddd48 | 711 | |
leothedragon | 0:8f0bb79ddd48 | 712 | bool M2MFirmware::set_resource_notification_sent_callback(FirmwareResource resource, |
leothedragon | 0:8f0bb79ddd48 | 713 | notification_sent_callback_2 callback) |
leothedragon | 0:8f0bb79ddd48 | 714 | { |
leothedragon | 0:8f0bb79ddd48 | 715 | M2MResource* m2mresource; |
leothedragon | 0:8f0bb79ddd48 | 716 | |
leothedragon | 0:8f0bb79ddd48 | 717 | m2mresource = get_resource(resource); |
leothedragon | 0:8f0bb79ddd48 | 718 | |
leothedragon | 0:8f0bb79ddd48 | 719 | if(m2mresource) { |
leothedragon | 0:8f0bb79ddd48 | 720 | m2mresource->set_notification_sent_callback(callback); |
leothedragon | 0:8f0bb79ddd48 | 721 | return true; |
leothedragon | 0:8f0bb79ddd48 | 722 | } |
leothedragon | 0:8f0bb79ddd48 | 723 | |
leothedragon | 0:8f0bb79ddd48 | 724 | return false; |
leothedragon | 0:8f0bb79ddd48 | 725 | } |
leothedragon | 0:8f0bb79ddd48 | 726 | |
leothedragon | 0:8f0bb79ddd48 | 727 | bool M2MFirmware::set_resource_notification_sent_callback(FirmwareResource resource, |
leothedragon | 0:8f0bb79ddd48 | 728 | notification_delivery_status_cb callback) |
leothedragon | 0:8f0bb79ddd48 | 729 | { |
leothedragon | 0:8f0bb79ddd48 | 730 | M2MResource* m2mresource; |
leothedragon | 0:8f0bb79ddd48 | 731 | |
leothedragon | 0:8f0bb79ddd48 | 732 | m2mresource = get_resource(resource); |
leothedragon | 0:8f0bb79ddd48 | 733 | |
leothedragon | 0:8f0bb79ddd48 | 734 | if(m2mresource) { |
leothedragon | 0:8f0bb79ddd48 | 735 | m2mresource->set_notification_delivery_status_cb(callback, 0); |
leothedragon | 0:8f0bb79ddd48 | 736 | return true; |
leothedragon | 0:8f0bb79ddd48 | 737 | } |
leothedragon | 0:8f0bb79ddd48 | 738 | |
leothedragon | 0:8f0bb79ddd48 | 739 | return false; |
leothedragon | 0:8f0bb79ddd48 | 740 | } |
leothedragon | 0:8f0bb79ddd48 | 741 | |
leothedragon | 0:8f0bb79ddd48 | 742 | bool M2MFirmware::set_resource_notification_sent_callback(FirmwareResource resource, |
leothedragon | 0:8f0bb79ddd48 | 743 | message_delivery_status_cb callback) |
leothedragon | 0:8f0bb79ddd48 | 744 | { |
leothedragon | 0:8f0bb79ddd48 | 745 | M2MResource* m2mresource; |
leothedragon | 0:8f0bb79ddd48 | 746 | |
leothedragon | 0:8f0bb79ddd48 | 747 | m2mresource = get_resource(resource); |
leothedragon | 0:8f0bb79ddd48 | 748 | |
leothedragon | 0:8f0bb79ddd48 | 749 | if(m2mresource) { |
leothedragon | 0:8f0bb79ddd48 | 750 | m2mresource->set_message_delivery_status_cb(callback, 0); |
leothedragon | 0:8f0bb79ddd48 | 751 | return true; |
leothedragon | 0:8f0bb79ddd48 | 752 | } |
leothedragon | 0:8f0bb79ddd48 | 753 | |
leothedragon | 0:8f0bb79ddd48 | 754 | return false; |
leothedragon | 0:8f0bb79ddd48 | 755 | } |
leothedragon | 0:8f0bb79ddd48 | 756 | |
leothedragon | 0:8f0bb79ddd48 | 757 | #ifndef DISABLE_BLOCK_MESSAGE |
leothedragon | 0:8f0bb79ddd48 | 758 | bool M2MFirmware::set_package_block_message_callback(incoming_block_message_callback callback) |
leothedragon | 0:8f0bb79ddd48 | 759 | { |
leothedragon | 0:8f0bb79ddd48 | 760 | M2MResource* m2mresource; |
leothedragon | 0:8f0bb79ddd48 | 761 | |
leothedragon | 0:8f0bb79ddd48 | 762 | m2mresource = get_resource(Package); |
leothedragon | 0:8f0bb79ddd48 | 763 | |
leothedragon | 0:8f0bb79ddd48 | 764 | if(m2mresource) { |
leothedragon | 0:8f0bb79ddd48 | 765 | m2mresource->set_incoming_block_message_callback(callback); |
leothedragon | 0:8f0bb79ddd48 | 766 | return true; |
leothedragon | 0:8f0bb79ddd48 | 767 | } |
leothedragon | 0:8f0bb79ddd48 | 768 | |
leothedragon | 0:8f0bb79ddd48 | 769 | return false; |
leothedragon | 0:8f0bb79ddd48 | 770 | } |
leothedragon | 0:8f0bb79ddd48 | 771 | #endif // DISABLE_BLOCK_MESSAGE |