FRDM K64F Metronome

Committer:
ram54288
Date:
Sun May 14 18:37:05 2017 +0000
Revision:
0:dbad57390bd1
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ram54288 0:dbad57390bd1 1 /*
ram54288 0:dbad57390bd1 2 * Copyright (c) 2015 ARM Limited. All rights reserved.
ram54288 0:dbad57390bd1 3 * SPDX-License-Identifier: Apache-2.0
ram54288 0:dbad57390bd1 4 * Licensed under the Apache License, Version 2.0 (the License); you may
ram54288 0:dbad57390bd1 5 * not use this file except in compliance with the License.
ram54288 0:dbad57390bd1 6 * You may obtain a copy of the License at
ram54288 0:dbad57390bd1 7 *
ram54288 0:dbad57390bd1 8 * http://www.apache.org/licenses/LICENSE-2.0
ram54288 0:dbad57390bd1 9 *
ram54288 0:dbad57390bd1 10 * Unless required by applicable law or agreed to in writing, software
ram54288 0:dbad57390bd1 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
ram54288 0:dbad57390bd1 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ram54288 0:dbad57390bd1 13 * See the License for the specific language governing permissions and
ram54288 0:dbad57390bd1 14 * limitations under the License.
ram54288 0:dbad57390bd1 15 */
ram54288 0:dbad57390bd1 16 #include "m2mresourceinstance_stub.h"
ram54288 0:dbad57390bd1 17
ram54288 0:dbad57390bd1 18 uint32_t m2mresourceinstance_stub::int_value;
ram54288 0:dbad57390bd1 19 bool m2mresourceinstance_stub::bool_value;
ram54288 0:dbad57390bd1 20 String *m2mresourceinstance_stub::string_value;
ram54288 0:dbad57390bd1 21 M2MResourceInstance::ResourceType m2mresourceinstance_stub::resource_type;
ram54288 0:dbad57390bd1 22 sn_coap_hdr_s *m2mresourceinstance_stub::header;
ram54288 0:dbad57390bd1 23 uint8_t* m2mresourceinstance_stub::value;
ram54288 0:dbad57390bd1 24 M2MBase::BaseType m2mresourceinstance_stub::base_type;
ram54288 0:dbad57390bd1 25
ram54288 0:dbad57390bd1 26
ram54288 0:dbad57390bd1 27 void m2mresourceinstance_stub::clear()
ram54288 0:dbad57390bd1 28 {
ram54288 0:dbad57390bd1 29 int_value = 0;
ram54288 0:dbad57390bd1 30 bool_value = false;
ram54288 0:dbad57390bd1 31 resource_type = M2MResourceInstance::STRING;
ram54288 0:dbad57390bd1 32 header = NULL;
ram54288 0:dbad57390bd1 33 value = NULL;
ram54288 0:dbad57390bd1 34 base_type = M2MBase::ResourceInstance;
ram54288 0:dbad57390bd1 35 string_value = NULL;
ram54288 0:dbad57390bd1 36 }
ram54288 0:dbad57390bd1 37
ram54288 0:dbad57390bd1 38 M2MResourceInstance::M2MResourceInstance(M2MResource &parent,
ram54288 0:dbad57390bd1 39 const String &res_name,
ram54288 0:dbad57390bd1 40 const String &resource_type,
ram54288 0:dbad57390bd1 41 M2MResourceInstance::ResourceType type,
ram54288 0:dbad57390bd1 42 const uint16_t object_instance_id,
ram54288 0:dbad57390bd1 43 char* path,
ram54288 0:dbad57390bd1 44 bool external_blockwise_store)
ram54288 0:dbad57390bd1 45 : M2MBase(res_name,
ram54288 0:dbad57390bd1 46 M2MBase::Dynamic,
ram54288 0:dbad57390bd1 47 resource_type,
ram54288 0:dbad57390bd1 48 path,
ram54288 0:dbad57390bd1 49 external_blockwise_store),
ram54288 0:dbad57390bd1 50 _parent_resource(parent),
ram54288 0:dbad57390bd1 51 _value(NULL),
ram54288 0:dbad57390bd1 52 _value_length(0),
ram54288 0:dbad57390bd1 53 _block_message_data(NULL),
ram54288 0:dbad57390bd1 54 _execute_callback(NULL),
ram54288 0:dbad57390bd1 55 _resource_callback(NULL),
ram54288 0:dbad57390bd1 56 _execute_function_pointer(NULL),
ram54288 0:dbad57390bd1 57 _notification_sent_function_pointer(NULL),
ram54288 0:dbad57390bd1 58 _notification_sent_callback(NULL),
ram54288 0:dbad57390bd1 59 _object_instance_id(object_instance_id),
ram54288 0:dbad57390bd1 60 _resource_type(type)
ram54288 0:dbad57390bd1 61 {
ram54288 0:dbad57390bd1 62
ram54288 0:dbad57390bd1 63 }
ram54288 0:dbad57390bd1 64
ram54288 0:dbad57390bd1 65 M2MResourceInstance::M2MResourceInstance(M2MResource &parent,
ram54288 0:dbad57390bd1 66 const String &res_name,
ram54288 0:dbad57390bd1 67 const String &resource_type,
ram54288 0:dbad57390bd1 68 M2MResourceInstance::ResourceType type,
ram54288 0:dbad57390bd1 69 const uint8_t *value,
ram54288 0:dbad57390bd1 70 const uint8_t value_length,
ram54288 0:dbad57390bd1 71 const uint16_t object_instance_id,
ram54288 0:dbad57390bd1 72 char* path,
ram54288 0:dbad57390bd1 73 bool external_blockwise_store)
ram54288 0:dbad57390bd1 74 : M2MBase(res_name,
ram54288 0:dbad57390bd1 75 M2MBase::Static,
ram54288 0:dbad57390bd1 76 resource_type,
ram54288 0:dbad57390bd1 77 path,
ram54288 0:dbad57390bd1 78 external_blockwise_store),
ram54288 0:dbad57390bd1 79 _parent_resource(parent),
ram54288 0:dbad57390bd1 80 _value(NULL),
ram54288 0:dbad57390bd1 81 _value_length(0),
ram54288 0:dbad57390bd1 82 _block_message_data(NULL),
ram54288 0:dbad57390bd1 83 _execute_callback(NULL),
ram54288 0:dbad57390bd1 84 _resource_callback(NULL),
ram54288 0:dbad57390bd1 85 _execute_function_pointer(NULL),
ram54288 0:dbad57390bd1 86 _notification_sent_function_pointer(NULL),
ram54288 0:dbad57390bd1 87 _notification_sent_callback(NULL),
ram54288 0:dbad57390bd1 88 _object_instance_id(object_instance_id),
ram54288 0:dbad57390bd1 89 _resource_type(type)
ram54288 0:dbad57390bd1 90 {
ram54288 0:dbad57390bd1 91 }
ram54288 0:dbad57390bd1 92
ram54288 0:dbad57390bd1 93 M2MResourceInstance::M2MResourceInstance(M2MResource &parent,
ram54288 0:dbad57390bd1 94 const lwm2m_parameters_s* s,
ram54288 0:dbad57390bd1 95 M2MResourceInstance::ResourceType type,
ram54288 0:dbad57390bd1 96 const uint16_t object_instance_id)
ram54288 0:dbad57390bd1 97 : M2MBase(s),
ram54288 0:dbad57390bd1 98 _parent_resource(parent),
ram54288 0:dbad57390bd1 99 _value(NULL),
ram54288 0:dbad57390bd1 100 _value_length(0),
ram54288 0:dbad57390bd1 101 _block_message_data(NULL),
ram54288 0:dbad57390bd1 102 _execute_callback(NULL),
ram54288 0:dbad57390bd1 103 _resource_callback(NULL),
ram54288 0:dbad57390bd1 104 _execute_function_pointer(NULL),
ram54288 0:dbad57390bd1 105 _notification_sent_function_pointer(NULL),
ram54288 0:dbad57390bd1 106 _object_instance_id(object_instance_id),
ram54288 0:dbad57390bd1 107 _resource_type(type)
ram54288 0:dbad57390bd1 108 {
ram54288 0:dbad57390bd1 109 }
ram54288 0:dbad57390bd1 110
ram54288 0:dbad57390bd1 111 M2MResourceInstance::~M2MResourceInstance()
ram54288 0:dbad57390bd1 112 {
ram54288 0:dbad57390bd1 113 }
ram54288 0:dbad57390bd1 114
ram54288 0:dbad57390bd1 115 M2MBase::BaseType M2MResourceInstance::base_type() const
ram54288 0:dbad57390bd1 116 {
ram54288 0:dbad57390bd1 117 return m2mresourceinstance_stub::base_type;
ram54288 0:dbad57390bd1 118 }
ram54288 0:dbad57390bd1 119
ram54288 0:dbad57390bd1 120 M2MResourceInstance::ResourceType M2MResourceInstance::resource_instance_type() const
ram54288 0:dbad57390bd1 121 {
ram54288 0:dbad57390bd1 122 return m2mresourceinstance_stub::resource_type;
ram54288 0:dbad57390bd1 123 }
ram54288 0:dbad57390bd1 124
ram54288 0:dbad57390bd1 125 bool M2MResourceInstance::handle_observation_attribute(const char *)
ram54288 0:dbad57390bd1 126 {
ram54288 0:dbad57390bd1 127 return m2mresourceinstance_stub::bool_value;
ram54288 0:dbad57390bd1 128 }
ram54288 0:dbad57390bd1 129
ram54288 0:dbad57390bd1 130 void M2MResourceInstance::set_execute_function(execute_callback)
ram54288 0:dbad57390bd1 131 {
ram54288 0:dbad57390bd1 132 }
ram54288 0:dbad57390bd1 133
ram54288 0:dbad57390bd1 134 bool M2MResourceInstance::set_value(const uint8_t *,
ram54288 0:dbad57390bd1 135 const uint32_t )
ram54288 0:dbad57390bd1 136 {
ram54288 0:dbad57390bd1 137 return m2mresourceinstance_stub::bool_value;
ram54288 0:dbad57390bd1 138 }
ram54288 0:dbad57390bd1 139
ram54288 0:dbad57390bd1 140 bool M2MResourceInstance::set_value(int64_t value)
ram54288 0:dbad57390bd1 141 {
ram54288 0:dbad57390bd1 142 return m2mresourceinstance_stub::bool_value;
ram54288 0:dbad57390bd1 143 }
ram54288 0:dbad57390bd1 144
ram54288 0:dbad57390bd1 145
ram54288 0:dbad57390bd1 146 void M2MResourceInstance::clear_value()
ram54288 0:dbad57390bd1 147 {
ram54288 0:dbad57390bd1 148 if (m2mresourceinstance_stub::value) {
ram54288 0:dbad57390bd1 149 free(m2mresourceinstance_stub::value);
ram54288 0:dbad57390bd1 150 m2mresourceinstance_stub::value = NULL;
ram54288 0:dbad57390bd1 151 m2mresourceinstance_stub::int_value = 0;
ram54288 0:dbad57390bd1 152 }
ram54288 0:dbad57390bd1 153 }
ram54288 0:dbad57390bd1 154
ram54288 0:dbad57390bd1 155 void M2MResourceInstance::execute(void *)
ram54288 0:dbad57390bd1 156 {
ram54288 0:dbad57390bd1 157 }
ram54288 0:dbad57390bd1 158
ram54288 0:dbad57390bd1 159 void M2MResourceInstance::get_value(uint8_t *&value, uint32_t &value_length)
ram54288 0:dbad57390bd1 160 {
ram54288 0:dbad57390bd1 161 value_length = 0;
ram54288 0:dbad57390bd1 162 if(value) {
ram54288 0:dbad57390bd1 163 free(value);
ram54288 0:dbad57390bd1 164 value = NULL;
ram54288 0:dbad57390bd1 165 }
ram54288 0:dbad57390bd1 166 value = (uint8_t *)malloc(m2mresourceinstance_stub::int_value);
ram54288 0:dbad57390bd1 167 if(value) {
ram54288 0:dbad57390bd1 168 value_length = m2mresourceinstance_stub::int_value;
ram54288 0:dbad57390bd1 169 memcpy((uint8_t *)value, (uint8_t *)m2mresourceinstance_stub::value, value_length);
ram54288 0:dbad57390bd1 170 }
ram54288 0:dbad57390bd1 171 }
ram54288 0:dbad57390bd1 172
ram54288 0:dbad57390bd1 173 int M2MResourceInstance::get_value_int()
ram54288 0:dbad57390bd1 174 {
ram54288 0:dbad57390bd1 175 // Note: this is a copy-paste from the original version, as the tests
ram54288 0:dbad57390bd1 176 // set only m2mresourceinstance_stub::value.
ram54288 0:dbad57390bd1 177
ram54288 0:dbad57390bd1 178 int value_int = 0;
ram54288 0:dbad57390bd1 179 // Get the value and convert it into integer. This is not the most
ram54288 0:dbad57390bd1 180 // efficient way, as it takes pointless heap copy to get the zero termination.
ram54288 0:dbad57390bd1 181 uint8_t* buffer = NULL;
ram54288 0:dbad57390bd1 182 uint32_t length;
ram54288 0:dbad57390bd1 183 get_value(buffer,length);
ram54288 0:dbad57390bd1 184 if(buffer) {
ram54288 0:dbad57390bd1 185 value_int = atoi((const char*)buffer);
ram54288 0:dbad57390bd1 186 free(buffer);
ram54288 0:dbad57390bd1 187 }
ram54288 0:dbad57390bd1 188 return value_int;
ram54288 0:dbad57390bd1 189 }
ram54288 0:dbad57390bd1 190
ram54288 0:dbad57390bd1 191 String M2MResourceInstance::get_value_string() const
ram54288 0:dbad57390bd1 192 {
ram54288 0:dbad57390bd1 193 // XXX: do a better constructor to avoid pointless malloc
ram54288 0:dbad57390bd1 194 String value;
ram54288 0:dbad57390bd1 195 if (m2mresourceinstance_stub::value) {
ram54288 0:dbad57390bd1 196 value.append_raw((char*)m2mresourceinstance_stub::value, m2mresourceinstance_stub::int_value);
ram54288 0:dbad57390bd1 197 }
ram54288 0:dbad57390bd1 198
ram54288 0:dbad57390bd1 199 return value;
ram54288 0:dbad57390bd1 200 }
ram54288 0:dbad57390bd1 201
ram54288 0:dbad57390bd1 202 uint8_t* M2MResourceInstance::value() const
ram54288 0:dbad57390bd1 203 {
ram54288 0:dbad57390bd1 204 return m2mresourceinstance_stub::value;
ram54288 0:dbad57390bd1 205 }
ram54288 0:dbad57390bd1 206
ram54288 0:dbad57390bd1 207 uint32_t M2MResourceInstance::value_length() const
ram54288 0:dbad57390bd1 208 {
ram54288 0:dbad57390bd1 209 return m2mresourceinstance_stub::int_value;
ram54288 0:dbad57390bd1 210 }
ram54288 0:dbad57390bd1 211
ram54288 0:dbad57390bd1 212 sn_coap_hdr_s* M2MResourceInstance::handle_get_request(nsdl_s *,
ram54288 0:dbad57390bd1 213 sn_coap_hdr_s *,
ram54288 0:dbad57390bd1 214 M2MObservationHandler *)
ram54288 0:dbad57390bd1 215 {
ram54288 0:dbad57390bd1 216 return m2mresourceinstance_stub::header;
ram54288 0:dbad57390bd1 217 }
ram54288 0:dbad57390bd1 218
ram54288 0:dbad57390bd1 219 sn_coap_hdr_s* M2MResourceInstance::handle_put_request(nsdl_s *,
ram54288 0:dbad57390bd1 220 sn_coap_hdr_s *,
ram54288 0:dbad57390bd1 221 M2MObservationHandler *,
ram54288 0:dbad57390bd1 222 bool &)
ram54288 0:dbad57390bd1 223 {
ram54288 0:dbad57390bd1 224 return m2mresourceinstance_stub::header;
ram54288 0:dbad57390bd1 225 }
ram54288 0:dbad57390bd1 226
ram54288 0:dbad57390bd1 227 void M2MResourceInstance::set_resource_observer(M2MResourceCallback *callback)
ram54288 0:dbad57390bd1 228 {
ram54288 0:dbad57390bd1 229
ram54288 0:dbad57390bd1 230 }
ram54288 0:dbad57390bd1 231
ram54288 0:dbad57390bd1 232 uint16_t M2MResourceInstance::object_instance_id() const
ram54288 0:dbad57390bd1 233 {
ram54288 0:dbad57390bd1 234 return m2mresourceinstance_stub::int_value;
ram54288 0:dbad57390bd1 235 }
ram54288 0:dbad57390bd1 236
ram54288 0:dbad57390bd1 237 void M2MResourceInstance::set_execute_function(execute_callback_2 callback)
ram54288 0:dbad57390bd1 238 {
ram54288 0:dbad57390bd1 239 }
ram54288 0:dbad57390bd1 240
ram54288 0:dbad57390bd1 241 M2MBlockMessage* M2MResourceInstance::block_message() const
ram54288 0:dbad57390bd1 242 {
ram54288 0:dbad57390bd1 243
ram54288 0:dbad57390bd1 244 }
ram54288 0:dbad57390bd1 245
ram54288 0:dbad57390bd1 246 void M2MResourceInstance::set_incoming_block_message_callback(incoming_block_message_callback callback)
ram54288 0:dbad57390bd1 247 {
ram54288 0:dbad57390bd1 248 }
ram54288 0:dbad57390bd1 249
ram54288 0:dbad57390bd1 250 void M2MResourceInstance::set_outgoing_block_message_callback(outgoing_block_message_callback callback)
ram54288 0:dbad57390bd1 251 {
ram54288 0:dbad57390bd1 252
ram54288 0:dbad57390bd1 253 }
ram54288 0:dbad57390bd1 254
ram54288 0:dbad57390bd1 255 void M2MResourceInstance::set_notification_sent_callback(notification_sent_callback callback)
ram54288 0:dbad57390bd1 256 {
ram54288 0:dbad57390bd1 257 }
ram54288 0:dbad57390bd1 258
ram54288 0:dbad57390bd1 259 void M2MResourceInstance::set_notification_sent_callback(notification_sent_callback_2 callback)
ram54288 0:dbad57390bd1 260 {
ram54288 0:dbad57390bd1 261 }
ram54288 0:dbad57390bd1 262
ram54288 0:dbad57390bd1 263 void M2MResourceInstance::notification_sent()
ram54288 0:dbad57390bd1 264 {
ram54288 0:dbad57390bd1 265 }
ram54288 0:dbad57390bd1 266
ram54288 0:dbad57390bd1 267 const char* M2MResourceInstance::object_name() const
ram54288 0:dbad57390bd1 268 {
ram54288 0:dbad57390bd1 269
ram54288 0:dbad57390bd1 270 }