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 "mbed-client/m2mvector.h"
ram54288 0:dbad57390bd1 17 #include "mbed-client/m2mobject.h"
ram54288 0:dbad57390bd1 18 #include "mbed-client/m2mobjectinstance.h"
ram54288 0:dbad57390bd1 19 #include "mbed-client/m2mresource.h"
ram54288 0:dbad57390bd1 20
ram54288 0:dbad57390bd1 21 /**
ram54288 0:dbad57390bd1 22 * @brief M2MTLVDeserializer
ram54288 0:dbad57390bd1 23 * TLV Deserialiser get the object instances and resources as binary data and
ram54288 0:dbad57390bd1 24 * builds the <code>lwm2m</code> representation from it. See OMA-LWM2M
ram54288 0:dbad57390bd1 25 * specification, chapter 6.1 for the resource model and chapter 6.3.3 for
ram54288 0:dbad57390bd1 26 * the OMA-TLV specification.
ram54288 0:dbad57390bd1 27 */
ram54288 0:dbad57390bd1 28 class M2MTLVDeserializer {
ram54288 0:dbad57390bd1 29
ram54288 0:dbad57390bd1 30 public :
ram54288 0:dbad57390bd1 31
ram54288 0:dbad57390bd1 32 typedef enum {
ram54288 0:dbad57390bd1 33 None,
ram54288 0:dbad57390bd1 34 NotFound,
ram54288 0:dbad57390bd1 35 NotAllowed,
ram54288 0:dbad57390bd1 36 NotValid
ram54288 0:dbad57390bd1 37 } Error;
ram54288 0:dbad57390bd1 38
ram54288 0:dbad57390bd1 39 typedef enum {
ram54288 0:dbad57390bd1 40 Put,
ram54288 0:dbad57390bd1 41 Post
ram54288 0:dbad57390bd1 42 } Operation;
ram54288 0:dbad57390bd1 43
ram54288 0:dbad57390bd1 44
ram54288 0:dbad57390bd1 45 /**
ram54288 0:dbad57390bd1 46 * Constructor.
ram54288 0:dbad57390bd1 47 */
ram54288 0:dbad57390bd1 48 M2MTLVDeserializer();
ram54288 0:dbad57390bd1 49
ram54288 0:dbad57390bd1 50 /**
ram54288 0:dbad57390bd1 51 * Destructor.
ram54288 0:dbad57390bd1 52 */
ram54288 0:dbad57390bd1 53 ~M2MTLVDeserializer();
ram54288 0:dbad57390bd1 54
ram54288 0:dbad57390bd1 55 /**
ram54288 0:dbad57390bd1 56 * This method checks whether the given binary encodes an object instance
ram54288 0:dbad57390bd1 57 * or something else. It returns <code>true</code> if bits 7-6 of the first
ram54288 0:dbad57390bd1 58 * byte is "00".
ram54288 0:dbad57390bd1 59 * @param tlv Binary to be checked as LWM2M object instance
ram54288 0:dbad57390bd1 60 * @return <code>true</code> or <code>false</code>.
ram54288 0:dbad57390bd1 61 */
ram54288 0:dbad57390bd1 62 bool is_object_instance(uint8_t *tlv);
ram54288 0:dbad57390bd1 63
ram54288 0:dbad57390bd1 64
ram54288 0:dbad57390bd1 65 /**
ram54288 0:dbad57390bd1 66 * This method checks whether the given binary encodes a resource or
ram54288 0:dbad57390bd1 67 * something else. It returns <code>true</code> if bits 7-6 of the first
ram54288 0:dbad57390bd1 68 * byte is "11".
ram54288 0:dbad57390bd1 69 * @param tlv Binary to be checked as LWM2M resource.
ram54288 0:dbad57390bd1 70 * @return <code>true</code> or <code>false</code>.
ram54288 0:dbad57390bd1 71 */
ram54288 0:dbad57390bd1 72 bool is_resource(uint8_t *tlv);
ram54288 0:dbad57390bd1 73
ram54288 0:dbad57390bd1 74 /**
ram54288 0:dbad57390bd1 75 * This method checks whether the given binary encodes a multiple resource
ram54288 0:dbad57390bd1 76 * or something else. It returns <code>true</code> if bits 7-6 of the first
ram54288 0:dbad57390bd1 77 * byte is "10".
ram54288 0:dbad57390bd1 78 * @param tlv Binary to be checked as LWM2M multiple resource.
ram54288 0:dbad57390bd1 79 * @return <code>true</code> or <code>false</code>.
ram54288 0:dbad57390bd1 80 */
ram54288 0:dbad57390bd1 81 bool is_multiple_resource(uint8_t *tlv);
ram54288 0:dbad57390bd1 82
ram54288 0:dbad57390bd1 83 /**
ram54288 0:dbad57390bd1 84 * This method checks whether the given binary encodes a resource instance
ram54288 0:dbad57390bd1 85 * or something else. It returns <code>true</code> if bits 7-6 of the first
ram54288 0:dbad57390bd1 86 * byte is "01".
ram54288 0:dbad57390bd1 87 * @param tlv Binary to be checked as LWM2M resource instance.
ram54288 0:dbad57390bd1 88 * @return <code>true</code> or <code>false</code>.
ram54288 0:dbad57390bd1 89 */
ram54288 0:dbad57390bd1 90 bool is_resource_instance(uint8_t *tlv);
ram54288 0:dbad57390bd1 91
ram54288 0:dbad57390bd1 92 /**
ram54288 0:dbad57390bd1 93 * Deserialises the given binary that must encode object instances. Binary
ram54288 0:dbad57390bd1 94 * array can be checked before invoking this method with
ram54288 0:dbad57390bd1 95 */
ram54288 0:dbad57390bd1 96 M2MTLVDeserializer::Error deserialise_object_instances(uint8_t* tlv,
ram54288 0:dbad57390bd1 97 uint32_t tlv_size,
ram54288 0:dbad57390bd1 98 M2MObject &object,
ram54288 0:dbad57390bd1 99 M2MTLVDeserializer::Operation operation);
ram54288 0:dbad57390bd1 100
ram54288 0:dbad57390bd1 101 /**
ram54288 0:dbad57390bd1 102 * Deserialises the given binary that must encode resources. Binary array
ram54288 0:dbad57390bd1 103 * can be checked before invoking this method.
ram54288 0:dbad57390bd1 104 */
ram54288 0:dbad57390bd1 105 M2MTLVDeserializer::Error deserialize_resources(uint8_t *tlv,
ram54288 0:dbad57390bd1 106 uint32_t tlv_size,
ram54288 0:dbad57390bd1 107 M2MObjectInstance &object_instance,
ram54288 0:dbad57390bd1 108 M2MTLVDeserializer::Operation operation);
ram54288 0:dbad57390bd1 109
ram54288 0:dbad57390bd1 110 /**
ram54288 0:dbad57390bd1 111 * Deserialises the given binary that must encode resource instances. Binary array
ram54288 0:dbad57390bd1 112 * can be checked before invoking this method.
ram54288 0:dbad57390bd1 113 */
ram54288 0:dbad57390bd1 114 M2MTLVDeserializer::Error deserialize_resource_instances(uint8_t *tlv,
ram54288 0:dbad57390bd1 115 uint32_t tlv_size,
ram54288 0:dbad57390bd1 116 M2MResource &resource,
ram54288 0:dbad57390bd1 117 M2MTLVDeserializer::Operation operation);
ram54288 0:dbad57390bd1 118 /**
ram54288 0:dbad57390bd1 119 * This method return object instance id or resource id.
ram54288 0:dbad57390bd1 120 * @param tlv Binary to be checked
ram54288 0:dbad57390bd1 121 * @return Object instance id or resource id.
ram54288 0:dbad57390bd1 122 */
ram54288 0:dbad57390bd1 123 uint16_t instance_id(uint8_t *tlv);
ram54288 0:dbad57390bd1 124
ram54288 0:dbad57390bd1 125 private:
ram54288 0:dbad57390bd1 126
ram54288 0:dbad57390bd1 127 M2MTLVDeserializer::Error deserialize_object_instances(uint8_t *tlv,
ram54288 0:dbad57390bd1 128 uint32_t tlv_size,
ram54288 0:dbad57390bd1 129 uint32_t offset,
ram54288 0:dbad57390bd1 130 M2MObject &object,
ram54288 0:dbad57390bd1 131 M2MTLVDeserializer::Operation operation,
ram54288 0:dbad57390bd1 132 bool update_value);
ram54288 0:dbad57390bd1 133
ram54288 0:dbad57390bd1 134 M2MTLVDeserializer::Error deserialize_resources(uint8_t *tlv,
ram54288 0:dbad57390bd1 135 uint32_t tlv_size,
ram54288 0:dbad57390bd1 136 uint32_t offset,
ram54288 0:dbad57390bd1 137 M2MObjectInstance &object_instance,
ram54288 0:dbad57390bd1 138 M2MTLVDeserializer::Operation operation,
ram54288 0:dbad57390bd1 139 bool update_value);
ram54288 0:dbad57390bd1 140
ram54288 0:dbad57390bd1 141 M2MTLVDeserializer::Error deserialize_resource_instances(uint8_t *tlv,
ram54288 0:dbad57390bd1 142 uint32_t tlv_size,
ram54288 0:dbad57390bd1 143 uint32_t offset,
ram54288 0:dbad57390bd1 144 M2MResource &resource,
ram54288 0:dbad57390bd1 145 M2MObjectInstance &object_instance,
ram54288 0:dbad57390bd1 146 M2MTLVDeserializer::Operation operation,
ram54288 0:dbad57390bd1 147 bool update_value);
ram54288 0:dbad57390bd1 148
ram54288 0:dbad57390bd1 149 M2MTLVDeserializer::Error deserialize_resource_instances(uint8_t *tlv,
ram54288 0:dbad57390bd1 150 uint32_t tlv_size,
ram54288 0:dbad57390bd1 151 uint32_t offset,
ram54288 0:dbad57390bd1 152 M2MResource &resource,
ram54288 0:dbad57390bd1 153 M2MTLVDeserializer::Operation operation,
ram54288 0:dbad57390bd1 154 bool update_value);
ram54288 0:dbad57390bd1 155
ram54288 0:dbad57390bd1 156 bool is_object_instance(uint8_t *tlv, uint32_t offset);
ram54288 0:dbad57390bd1 157
ram54288 0:dbad57390bd1 158 bool is_resource(uint8_t *tlv, uint32_t offset);
ram54288 0:dbad57390bd1 159
ram54288 0:dbad57390bd1 160 bool is_multiple_resource(uint8_t *tlv, uint32_t offset);
ram54288 0:dbad57390bd1 161
ram54288 0:dbad57390bd1 162 bool is_resource_instance(uint8_t *tlv, uint32_t offset);
ram54288 0:dbad57390bd1 163 };
ram54288 0:dbad57390bd1 164
ram54288 0:dbad57390bd1 165 class TypeIdLength {
ram54288 0:dbad57390bd1 166
ram54288 0:dbad57390bd1 167 public:
ram54288 0:dbad57390bd1 168
ram54288 0:dbad57390bd1 169 static TypeIdLength* createTypeIdLength(uint8_t *tlv, uint32_t offset);
ram54288 0:dbad57390bd1 170
ram54288 0:dbad57390bd1 171 TypeIdLength* deserialize();
ram54288 0:dbad57390bd1 172
ram54288 0:dbad57390bd1 173 void deserialiseID (uint32_t idLength);
ram54288 0:dbad57390bd1 174
ram54288 0:dbad57390bd1 175 void deserialiseLength (uint32_t lengthType);
ram54288 0:dbad57390bd1 176
ram54288 0:dbad57390bd1 177 uint8_t *_tlv;
ram54288 0:dbad57390bd1 178 uint32_t _offset;
ram54288 0:dbad57390bd1 179 uint32_t _type;
ram54288 0:dbad57390bd1 180 uint16_t _id;
ram54288 0:dbad57390bd1 181 uint32_t _length;
ram54288 0:dbad57390bd1 182
ram54288 0:dbad57390bd1 183 friend class Test_M2MTLVDeserializer;
ram54288 0:dbad57390bd1 184 };