This is an example of BLE GATT Client, which receives broadcast data from BLE_Server_BME280 ( a GATT server) , then transfers values up to mbed Device Connector (cloud).

Please refer details about BLEClient_mbedDevConn below. https://github.com/soramame21/BLEClient_mbedDevConn

The location of required BLE GATT server, BLE_Server_BME280, is at here. https://developer.mbed.org/users/edamame22/code/BLE_Server_BME280/

Committer:
edamame22
Date:
Thu Apr 13 04:48:11 2017 +0000
Revision:
0:29983394c6b6
Initial commit

Who changed what in which revision?

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