Dependencies:   MMA7660 LM75B

Committer:
MACRUM
Date:
Sat Jun 30 01:40:30 2018 +0000
Revision:
0:119624335925
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MACRUM 0:119624335925 1 /*
MACRUM 0:119624335925 2 * Copyright (c) 2015 ARM Limited. All rights reserved.
MACRUM 0:119624335925 3 * SPDX-License-Identifier: Apache-2.0
MACRUM 0:119624335925 4 * Licensed under the Apache License, Version 2.0 (the License); you may
MACRUM 0:119624335925 5 * not use this file except in compliance with the License.
MACRUM 0:119624335925 6 * You may obtain a copy of the License at
MACRUM 0:119624335925 7 *
MACRUM 0:119624335925 8 * http://www.apache.org/licenses/LICENSE-2.0
MACRUM 0:119624335925 9 *
MACRUM 0:119624335925 10 * Unless required by applicable law or agreed to in writing, software
MACRUM 0:119624335925 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
MACRUM 0:119624335925 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MACRUM 0:119624335925 13 * See the License for the specific language governing permissions and
MACRUM 0:119624335925 14 * limitations under the License.
MACRUM 0:119624335925 15 */
MACRUM 0:119624335925 16 #include "mbed-client/m2mvector.h"
MACRUM 0:119624335925 17 #include "mbed-client/m2mobject.h"
MACRUM 0:119624335925 18 #include "mbed-client/m2mobjectinstance.h"
MACRUM 0:119624335925 19 #include "mbed-client/m2mresource.h"
MACRUM 0:119624335925 20
MACRUM 0:119624335925 21 /**
MACRUM 0:119624335925 22 * @brief M2MTLVDeserializer
MACRUM 0:119624335925 23 * TLV Deserialiser get the object instances and resources as binary data and
MACRUM 0:119624335925 24 * builds the <code>lwm2m</code> representation from it. See OMA-LWM2M
MACRUM 0:119624335925 25 * specification, chapter 6.1 for the resource model and chapter 6.3.3 for
MACRUM 0:119624335925 26 * the OMA-TLV specification.
MACRUM 0:119624335925 27 */
MACRUM 0:119624335925 28 class M2MTLVDeserializer {
MACRUM 0:119624335925 29
MACRUM 0:119624335925 30 public :
MACRUM 0:119624335925 31
MACRUM 0:119624335925 32 typedef enum {
MACRUM 0:119624335925 33 None,
MACRUM 0:119624335925 34 NotFound,
MACRUM 0:119624335925 35 NotAllowed,
MACRUM 0:119624335925 36 NotValid,
MACRUM 0:119624335925 37 OutOfMemory
MACRUM 0:119624335925 38 } Error;
MACRUM 0:119624335925 39
MACRUM 0:119624335925 40 typedef enum {
MACRUM 0:119624335925 41 Put,
MACRUM 0:119624335925 42 Post
MACRUM 0:119624335925 43 } Operation;
MACRUM 0:119624335925 44
MACRUM 0:119624335925 45
MACRUM 0:119624335925 46 /**
MACRUM 0:119624335925 47 * This method checks whether the given binary encodes an object instance
MACRUM 0:119624335925 48 * or something else. It returns <code>true</code> if bits 7-6 of the first
MACRUM 0:119624335925 49 * byte is "00".
MACRUM 0:119624335925 50 * @param tlv Binary to be checked as LWM2M object instance
MACRUM 0:119624335925 51 * @return <code>true</code> or <code>false</code>.
MACRUM 0:119624335925 52 */
MACRUM 0:119624335925 53 static bool is_object_instance(const uint8_t *tlv);
MACRUM 0:119624335925 54
MACRUM 0:119624335925 55 /**
MACRUM 0:119624335925 56 * This method checks whether the given binary encodes a resource or
MACRUM 0:119624335925 57 * something else. It returns <code>true</code> if bits 7-6 of the first
MACRUM 0:119624335925 58 * byte is "11".
MACRUM 0:119624335925 59 * @param tlv Binary to be checked as LWM2M resource.
MACRUM 0:119624335925 60 * @return <code>true</code> or <code>false</code>.
MACRUM 0:119624335925 61 */
MACRUM 0:119624335925 62 static bool is_resource(const uint8_t *tlv);
MACRUM 0:119624335925 63
MACRUM 0:119624335925 64 /**
MACRUM 0:119624335925 65 * This method checks whether the given binary encodes a multiple resource
MACRUM 0:119624335925 66 * or something else. It returns <code>true</code> if bits 7-6 of the first
MACRUM 0:119624335925 67 * byte is "10".
MACRUM 0:119624335925 68 * @param tlv Binary to be checked as LWM2M multiple resource.
MACRUM 0:119624335925 69 * @return <code>true</code> or <code>false</code>.
MACRUM 0:119624335925 70 */
MACRUM 0:119624335925 71 static bool is_multiple_resource(const uint8_t *tlv);
MACRUM 0:119624335925 72
MACRUM 0:119624335925 73 /**
MACRUM 0:119624335925 74 * This method checks whether the given binary encodes a resource instance
MACRUM 0:119624335925 75 * or something else. It returns <code>true</code> if bits 7-6 of the first
MACRUM 0:119624335925 76 * byte is "01".
MACRUM 0:119624335925 77 * @param tlv Binary to be checked as LWM2M resource instance.
MACRUM 0:119624335925 78 * @return <code>true</code> or <code>false</code>.
MACRUM 0:119624335925 79 */
MACRUM 0:119624335925 80 static bool is_resource_instance(const uint8_t *tlv);
MACRUM 0:119624335925 81
MACRUM 0:119624335925 82 /**
MACRUM 0:119624335925 83 * Deserialises the given binary that must encode object instances. Binary
MACRUM 0:119624335925 84 * array can be checked before invoking this method with
MACRUM 0:119624335925 85 */
MACRUM 0:119624335925 86 static M2MTLVDeserializer::Error deserialise_object_instances(const uint8_t* tlv,
MACRUM 0:119624335925 87 uint32_t tlv_size,
MACRUM 0:119624335925 88 M2MObject &object,
MACRUM 0:119624335925 89 M2MTLVDeserializer::Operation operation);
MACRUM 0:119624335925 90
MACRUM 0:119624335925 91 /**
MACRUM 0:119624335925 92 * Deserialises the given binary that must encode resources. Binary array
MACRUM 0:119624335925 93 * can be checked before invoking this method.
MACRUM 0:119624335925 94 */
MACRUM 0:119624335925 95 static M2MTLVDeserializer::Error deserialize_resources(const uint8_t *tlv,
MACRUM 0:119624335925 96 uint32_t tlv_size,
MACRUM 0:119624335925 97 M2MObjectInstance &object_instance,
MACRUM 0:119624335925 98 M2MTLVDeserializer::Operation operation);
MACRUM 0:119624335925 99
MACRUM 0:119624335925 100 /**
MACRUM 0:119624335925 101 * Deserialises the given binary that must encode resource instances. Binary array
MACRUM 0:119624335925 102 * can be checked before invoking this method.
MACRUM 0:119624335925 103 */
MACRUM 0:119624335925 104 static M2MTLVDeserializer::Error deserialize_resource_instances(const uint8_t *tlv,
MACRUM 0:119624335925 105 uint32_t tlv_size,
MACRUM 0:119624335925 106 M2MResource &resource,
MACRUM 0:119624335925 107 M2MTLVDeserializer::Operation operation);
MACRUM 0:119624335925 108 /**
MACRUM 0:119624335925 109 * This method return object instance id or resource id.
MACRUM 0:119624335925 110 * @param tlv Binary to be checked
MACRUM 0:119624335925 111 * @return Object instance id or resource id.
MACRUM 0:119624335925 112 */
MACRUM 0:119624335925 113 static uint16_t instance_id(const uint8_t *tlv);
MACRUM 0:119624335925 114
MACRUM 0:119624335925 115 private:
MACRUM 0:119624335925 116
MACRUM 0:119624335925 117 static M2MTLVDeserializer::Error deserialize_object_instances(const uint8_t *tlv,
MACRUM 0:119624335925 118 uint32_t tlv_size,
MACRUM 0:119624335925 119 uint32_t offset,
MACRUM 0:119624335925 120 M2MObject &object,
MACRUM 0:119624335925 121 M2MTLVDeserializer::Operation operation,
MACRUM 0:119624335925 122 bool update_value);
MACRUM 0:119624335925 123
MACRUM 0:119624335925 124 static M2MTLVDeserializer::Error deserialize_resources(const uint8_t *tlv,
MACRUM 0:119624335925 125 uint32_t tlv_size,
MACRUM 0:119624335925 126 uint32_t offset,
MACRUM 0:119624335925 127 M2MObjectInstance &object_instance,
MACRUM 0:119624335925 128 M2MTLVDeserializer::Operation operation,
MACRUM 0:119624335925 129 bool update_value);
MACRUM 0:119624335925 130
MACRUM 0:119624335925 131 static M2MTLVDeserializer::Error deserialize_resource_instances(const uint8_t *tlv,
MACRUM 0:119624335925 132 uint32_t tlv_size,
MACRUM 0:119624335925 133 uint32_t offset,
MACRUM 0:119624335925 134 M2MResource &resource,
MACRUM 0:119624335925 135 M2MObjectInstance &object_instance,
MACRUM 0:119624335925 136 M2MTLVDeserializer::Operation operation,
MACRUM 0:119624335925 137 bool update_value);
MACRUM 0:119624335925 138
MACRUM 0:119624335925 139 static M2MTLVDeserializer::Error deserialize_resource_instances(const uint8_t *tlv,
MACRUM 0:119624335925 140 uint32_t tlv_size,
MACRUM 0:119624335925 141 uint32_t offset,
MACRUM 0:119624335925 142 M2MResource &resource,
MACRUM 0:119624335925 143 M2MTLVDeserializer::Operation operation,
MACRUM 0:119624335925 144 bool update_value);
MACRUM 0:119624335925 145
MACRUM 0:119624335925 146 static bool is_object_instance(const uint8_t *tlv, uint32_t offset);
MACRUM 0:119624335925 147
MACRUM 0:119624335925 148 static bool is_resource(const uint8_t *tlv, uint32_t offset);
MACRUM 0:119624335925 149
MACRUM 0:119624335925 150 static bool is_multiple_resource(const uint8_t *tlv, uint32_t offset);
MACRUM 0:119624335925 151
MACRUM 0:119624335925 152 static bool is_resource_instance(const uint8_t *tlv, uint32_t offset);
MACRUM 0:119624335925 153
MACRUM 0:119624335925 154 static bool set_resource_instance_value(M2MResourceBase *res, const uint8_t *tlv, const uint32_t size);
MACRUM 0:119624335925 155
MACRUM 0:119624335925 156 static void remove_resources(const uint8_t *tlv,
MACRUM 0:119624335925 157 uint32_t tlv_size,
MACRUM 0:119624335925 158 M2MObjectInstance &object_instance,
MACRUM 0:119624335925 159 uint32_t offset_size);
MACRUM 0:119624335925 160
MACRUM 0:119624335925 161 static void remove_resource_instances(const uint8_t *tlv,
MACRUM 0:119624335925 162 uint32_t tlv_size,
MACRUM 0:119624335925 163 M2MResource &resource,
MACRUM 0:119624335925 164 uint32_t offset_size);
MACRUM 0:119624335925 165 };
MACRUM 0:119624335925 166
MACRUM 0:119624335925 167 class TypeIdLength {
MACRUM 0:119624335925 168
MACRUM 0:119624335925 169 public:
MACRUM 0:119624335925 170 TypeIdLength(const uint8_t *tlv, uint32_t offset);
MACRUM 0:119624335925 171
MACRUM 0:119624335925 172 void deserialize();
MACRUM 0:119624335925 173
MACRUM 0:119624335925 174 void deserialiseID(uint32_t idLength);
MACRUM 0:119624335925 175
MACRUM 0:119624335925 176 void deserialiseLength(uint32_t lengthType);
MACRUM 0:119624335925 177
MACRUM 0:119624335925 178 const uint8_t *_tlv;
MACRUM 0:119624335925 179 uint32_t _offset;
MACRUM 0:119624335925 180 uint32_t _type;
MACRUM 0:119624335925 181 uint16_t _id;
MACRUM 0:119624335925 182 uint32_t _length;
MACRUM 0:119624335925 183
MACRUM 0:119624335925 184 friend class Test_M2MTLVDeserializer;
MACRUM 0:119624335925 185 };