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 "m2mresource_stub.h"
ram54288 0:dbad57390bd1 17
ram54288 0:dbad57390bd1 18 uint32_t m2mresource_stub::int_value;
ram54288 0:dbad57390bd1 19 uint8_t* m2mresource_stub::delayed_token;
ram54288 0:dbad57390bd1 20 uint8_t m2mresource_stub::delayed_token_len;
ram54288 0:dbad57390bd1 21 bool m2mresource_stub::bool_value;
ram54288 0:dbad57390bd1 22 // The statically initialized list must be bigh enough to cater
ram54288 0:dbad57390bd1 23 // for all the tests, or the utest framework will complain for memory leak.
ram54288 0:dbad57390bd1 24 M2MResourceInstanceList m2mresource_stub::list(12);
ram54288 0:dbad57390bd1 25
ram54288 0:dbad57390bd1 26 M2MResourceInstance *m2mresource_stub::instance;
ram54288 0:dbad57390bd1 27 M2MObjectInstance *m2mresource_stub::object_instance;
ram54288 0:dbad57390bd1 28 sn_coap_hdr_s *m2mresource_stub::header;
ram54288 0:dbad57390bd1 29 void m2mresource_stub::clear()
ram54288 0:dbad57390bd1 30 {
ram54288 0:dbad57390bd1 31 int_value = 0;
ram54288 0:dbad57390bd1 32 delayed_token = NULL;
ram54288 0:dbad57390bd1 33 delayed_token_len = 0;
ram54288 0:dbad57390bd1 34 bool_value = false;
ram54288 0:dbad57390bd1 35 list.clear();
ram54288 0:dbad57390bd1 36 instance = NULL;
ram54288 0:dbad57390bd1 37 object_instance = NULL;
ram54288 0:dbad57390bd1 38 }
ram54288 0:dbad57390bd1 39
ram54288 0:dbad57390bd1 40 M2MResource::M2MResource(M2MObjectInstance &parent,
ram54288 0:dbad57390bd1 41 const String &resource_name,
ram54288 0:dbad57390bd1 42 const String &resource_type,
ram54288 0:dbad57390bd1 43 M2MResourceInstance::ResourceType type,
ram54288 0:dbad57390bd1 44 const uint8_t *value,
ram54288 0:dbad57390bd1 45 const uint8_t value_length,
ram54288 0:dbad57390bd1 46 char* path,
ram54288 0:dbad57390bd1 47 const uint16_t object_instance_id,
ram54288 0:dbad57390bd1 48 bool multiple_instance,
ram54288 0:dbad57390bd1 49 bool external_blockwise_store)
ram54288 0:dbad57390bd1 50 : M2MResourceInstance(*this, resource_name, resource_type, type, value, value_length, object_instance_id,
ram54288 0:dbad57390bd1 51 path, external_blockwise_store),
ram54288 0:dbad57390bd1 52 _parent(parent),
ram54288 0:dbad57390bd1 53 _delayed_token(NULL),
ram54288 0:dbad57390bd1 54 _delayed_token_len(0),
ram54288 0:dbad57390bd1 55 _has_multiple_instances(multiple_instance),
ram54288 0:dbad57390bd1 56 _delayed_response(false)
ram54288 0:dbad57390bd1 57 {
ram54288 0:dbad57390bd1 58
ram54288 0:dbad57390bd1 59 }
ram54288 0:dbad57390bd1 60
ram54288 0:dbad57390bd1 61 M2MResource::M2MResource(M2MObjectInstance &parent,
ram54288 0:dbad57390bd1 62 const lwm2m_parameters_s* s,
ram54288 0:dbad57390bd1 63 M2MResourceInstance::ResourceType type,
ram54288 0:dbad57390bd1 64 const uint16_t object_instance_id)
ram54288 0:dbad57390bd1 65 : M2MResourceInstance(*this, s, type, object_instance_id),
ram54288 0:dbad57390bd1 66 _parent(parent),
ram54288 0:dbad57390bd1 67 _delayed_token(NULL),
ram54288 0:dbad57390bd1 68 _delayed_token_len(0),
ram54288 0:dbad57390bd1 69 _has_multiple_instances(false),
ram54288 0:dbad57390bd1 70 _delayed_response(false)
ram54288 0:dbad57390bd1 71 {
ram54288 0:dbad57390bd1 72 // tbd: _has_multiple_instances could be in flash, but no real benefit, because of current alignment.
ram54288 0:dbad57390bd1 73 }
ram54288 0:dbad57390bd1 74
ram54288 0:dbad57390bd1 75 M2MResource::M2MResource(M2MObjectInstance &parent,
ram54288 0:dbad57390bd1 76 const String &resource_name,
ram54288 0:dbad57390bd1 77 const String &resource_type,
ram54288 0:dbad57390bd1 78 M2MResourceInstance::ResourceType type,
ram54288 0:dbad57390bd1 79 bool observable,
ram54288 0:dbad57390bd1 80 char *path,
ram54288 0:dbad57390bd1 81 const uint16_t object_instance_id,
ram54288 0:dbad57390bd1 82 bool multiple_instance,
ram54288 0:dbad57390bd1 83 bool external_blockwise_store)
ram54288 0:dbad57390bd1 84 : M2MResourceInstance(*this, resource_name, resource_type, type,
ram54288 0:dbad57390bd1 85 object_instance_id, path, external_blockwise_store),
ram54288 0:dbad57390bd1 86 _parent(parent),
ram54288 0:dbad57390bd1 87 _delayed_token(NULL),
ram54288 0:dbad57390bd1 88 _delayed_token_len(0),
ram54288 0:dbad57390bd1 89 _has_multiple_instances(multiple_instance),
ram54288 0:dbad57390bd1 90 _delayed_response(false)
ram54288 0:dbad57390bd1 91 {
ram54288 0:dbad57390bd1 92
ram54288 0:dbad57390bd1 93 }
ram54288 0:dbad57390bd1 94
ram54288 0:dbad57390bd1 95 M2MResource::~M2MResource()
ram54288 0:dbad57390bd1 96 {
ram54288 0:dbad57390bd1 97 }
ram54288 0:dbad57390bd1 98
ram54288 0:dbad57390bd1 99 bool M2MResource::supports_multiple_instances() const
ram54288 0:dbad57390bd1 100 {
ram54288 0:dbad57390bd1 101 return m2mresource_stub::bool_value;
ram54288 0:dbad57390bd1 102 }
ram54288 0:dbad57390bd1 103
ram54288 0:dbad57390bd1 104 void M2MResource::get_delayed_token(unsigned char *&token, unsigned char &token_len)
ram54288 0:dbad57390bd1 105 {
ram54288 0:dbad57390bd1 106 token_len = 0;
ram54288 0:dbad57390bd1 107 if(token) {
ram54288 0:dbad57390bd1 108 free(token);
ram54288 0:dbad57390bd1 109 token = NULL;
ram54288 0:dbad57390bd1 110 }
ram54288 0:dbad57390bd1 111 token = (uint8_t *)malloc(m2mresource_stub::delayed_token_len);
ram54288 0:dbad57390bd1 112 if(token) {
ram54288 0:dbad57390bd1 113 token_len = m2mresource_stub::delayed_token_len;
ram54288 0:dbad57390bd1 114 memcpy((uint8_t *)token, (uint8_t *)m2mresource_stub::delayed_token, token_len);
ram54288 0:dbad57390bd1 115 }
ram54288 0:dbad57390bd1 116 }
ram54288 0:dbad57390bd1 117
ram54288 0:dbad57390bd1 118 bool M2MResource::remove_resource_instance(uint16_t inst_id)
ram54288 0:dbad57390bd1 119 {
ram54288 0:dbad57390bd1 120 return m2mresource_stub::bool_value;
ram54288 0:dbad57390bd1 121 }
ram54288 0:dbad57390bd1 122
ram54288 0:dbad57390bd1 123 M2MResourceInstance* M2MResource::resource_instance(uint16_t inst_id) const
ram54288 0:dbad57390bd1 124 {
ram54288 0:dbad57390bd1 125 return m2mresource_stub::instance;
ram54288 0:dbad57390bd1 126 }
ram54288 0:dbad57390bd1 127
ram54288 0:dbad57390bd1 128 const M2MResourceInstanceList& M2MResource::resource_instances() const
ram54288 0:dbad57390bd1 129 {
ram54288 0:dbad57390bd1 130 return m2mresource_stub::list;
ram54288 0:dbad57390bd1 131 }
ram54288 0:dbad57390bd1 132
ram54288 0:dbad57390bd1 133 uint16_t M2MResource::resource_instance_count() const
ram54288 0:dbad57390bd1 134 {
ram54288 0:dbad57390bd1 135 return m2mresource_stub::int_value;
ram54288 0:dbad57390bd1 136 }
ram54288 0:dbad57390bd1 137
ram54288 0:dbad57390bd1 138 bool M2MResource::handle_observation_attribute(const char *query)
ram54288 0:dbad57390bd1 139 {
ram54288 0:dbad57390bd1 140 return m2mresource_stub::bool_value;
ram54288 0:dbad57390bd1 141 }
ram54288 0:dbad57390bd1 142
ram54288 0:dbad57390bd1 143 void M2MResource::add_resource_instance(M2MResourceInstance *)
ram54288 0:dbad57390bd1 144 {
ram54288 0:dbad57390bd1 145 }
ram54288 0:dbad57390bd1 146
ram54288 0:dbad57390bd1 147 void M2MResource::add_observation_level(M2MBase::Observation)
ram54288 0:dbad57390bd1 148 {
ram54288 0:dbad57390bd1 149 }
ram54288 0:dbad57390bd1 150
ram54288 0:dbad57390bd1 151 void M2MResource::remove_observation_level(M2MBase::Observation)
ram54288 0:dbad57390bd1 152 {
ram54288 0:dbad57390bd1 153 }
ram54288 0:dbad57390bd1 154
ram54288 0:dbad57390bd1 155 void M2MResource::notification_update()
ram54288 0:dbad57390bd1 156 {
ram54288 0:dbad57390bd1 157 }
ram54288 0:dbad57390bd1 158
ram54288 0:dbad57390bd1 159 sn_coap_hdr_s* M2MResource::handle_get_request(nsdl_s *,
ram54288 0:dbad57390bd1 160 sn_coap_hdr_s *,
ram54288 0:dbad57390bd1 161 M2MObservationHandler *)
ram54288 0:dbad57390bd1 162 {
ram54288 0:dbad57390bd1 163 return m2mresource_stub::header;
ram54288 0:dbad57390bd1 164 }
ram54288 0:dbad57390bd1 165
ram54288 0:dbad57390bd1 166 sn_coap_hdr_s* M2MResource::handle_put_request(nsdl_s *,
ram54288 0:dbad57390bd1 167 sn_coap_hdr_s *,
ram54288 0:dbad57390bd1 168 M2MObservationHandler *,
ram54288 0:dbad57390bd1 169 bool &)
ram54288 0:dbad57390bd1 170 {
ram54288 0:dbad57390bd1 171 return m2mresource_stub::header;
ram54288 0:dbad57390bd1 172 }
ram54288 0:dbad57390bd1 173
ram54288 0:dbad57390bd1 174 sn_coap_hdr_s* M2MResource::handle_post_request(nsdl_s *,
ram54288 0:dbad57390bd1 175 sn_coap_hdr_s *,
ram54288 0:dbad57390bd1 176 M2MObservationHandler *,
ram54288 0:dbad57390bd1 177 bool &, sn_nsdl_addr_s *)
ram54288 0:dbad57390bd1 178 {
ram54288 0:dbad57390bd1 179 return m2mresource_stub::header;
ram54288 0:dbad57390bd1 180 }
ram54288 0:dbad57390bd1 181
ram54288 0:dbad57390bd1 182 M2MObjectInstance& M2MResource::get_parent_object_instance() const
ram54288 0:dbad57390bd1 183 {
ram54288 0:dbad57390bd1 184 return *m2mresource_stub::object_instance;
ram54288 0:dbad57390bd1 185 }
ram54288 0:dbad57390bd1 186
ram54288 0:dbad57390bd1 187 const char* M2MResource::object_name() const
ram54288 0:dbad57390bd1 188 {
ram54288 0:dbad57390bd1 189
ram54288 0:dbad57390bd1 190 }