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:
Ren Boting
Date:
Tue Sep 05 11:56:13 2017 +0900
Revision:
2:b894b3508057
Parent:
0:29983394c6b6
Update all libraries and reform main.cpp

Who changed what in which revision?

UserRevisionLine numberNew contents of line
edamame22 0:29983394c6b6 1 /*
edamame22 0:29983394c6b6 2 * Copyright (c) 2016 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
edamame22 0:29983394c6b6 17
edamame22 0:29983394c6b6 18 #ifndef _PAL_MACROS_H
edamame22 0:29983394c6b6 19 #define _PAL_MACROS_H
edamame22 0:29983394c6b6 20
edamame22 0:29983394c6b6 21 #ifdef __cplusplus
edamame22 0:29983394c6b6 22 extern "C" {
edamame22 0:29983394c6b6 23 #endif
edamame22 0:29983394c6b6 24
edamame22 0:29983394c6b6 25 #include "pal_errors.h"
edamame22 0:29983394c6b6 26 // PAL success value
edamame22 0:29983394c6b6 27 #define PAL_SUCCESS 0
edamame22 0:29983394c6b6 28
edamame22 0:29983394c6b6 29 // maximum integer types
edamame22 0:29983394c6b6 30 #define PAL_MAX_UINT8 0xFFU
edamame22 0:29983394c6b6 31 #define PAL_MAX_UINT16 0xFFFFU
edamame22 0:29983394c6b6 32 #define PAL_MAX_UINT32 0xFFFFFFFFUL
edamame22 0:29983394c6b6 33 #define PAL_MAX_INT32 0x7FFFFFFFL
edamame22 0:29983394c6b6 34 #define PAL_MIN_INT32 0x80000000L
edamame22 0:29983394c6b6 35 #define PAL_MAX_UINT64 0xFFFFFFFFFFFFFFFFULL
edamame22 0:29983394c6b6 36 #define PAL_MAX_INT64 0x7FFFFFFFFFFFFFFFLL
edamame22 0:29983394c6b6 37
edamame22 0:29983394c6b6 38 // useful macros
edamame22 0:29983394c6b6 39
edamame22 0:29983394c6b6 40 #define PAL_MAX(a,b) ((a) > (b) ? (a) : (b))
edamame22 0:29983394c6b6 41
edamame22 0:29983394c6b6 42 #define PAL_MIN(a,b) ((a) < (b) ? (a) : (b))
edamame22 0:29983394c6b6 43
edamame22 0:29983394c6b6 44 #define PAL_DIVIDE_ROUND_UP(num, divider) (((num) + (divider) - 1) / (divider))
edamame22 0:29983394c6b6 45
edamame22 0:29983394c6b6 46 #if PAL_COMPILATION_ENDIANITY == 1
edamame22 0:29983394c6b6 47 #define BIG__ENDIAN 1
edamame22 0:29983394c6b6 48 #elif PAL_COMPILATION_ENDIANITY == 0
edamame22 0:29983394c6b6 49 #define LITTLE__ENDIAN 1
edamame22 0:29983394c6b6 50 #else
edamame22 0:29983394c6b6 51 #error neither BIG__ENDIAN nor LITTLE__ENDIAN defined, cannot compile
edamame22 0:29983394c6b6 52 #endif
edamame22 0:29983394c6b6 53
edamame22 0:29983394c6b6 54 // endianity macros
edamame22 0:29983394c6b6 55 #ifdef LITTLE__ENDIAN
edamame22 0:29983394c6b6 56
edamame22 0:29983394c6b6 57 #define PAL_HTONS(x) (((((unsigned short)(x)) >> 8) & 0xff) | \
edamame22 0:29983394c6b6 58 ((((unsigned short)(x)) & 0xff) << 8))
edamame22 0:29983394c6b6 59 #define PAL_NTOHS(x) (((((unsigned short)(x)) >> 8) & 0xff) | \
edamame22 0:29983394c6b6 60 ((((unsigned short)(x)) & 0xff) << 8) )
edamame22 0:29983394c6b6 61 #define PAL_HTONL(x) ((((x)>>24) & 0xffL) | (((x)>>8) & 0xff00L) | \
edamame22 0:29983394c6b6 62 (((x)<<8) & 0xff0000L) | (((x)<<24) & 0xff000000L))
edamame22 0:29983394c6b6 63 #define PAL_NTOHL(x) ((((x)>>24) & 0xffL) | (((x)>>8) & 0xff00L) | \
edamame22 0:29983394c6b6 64 (((x)<<8) & 0xff0000L) | (((x)<<24) & 0xff000000L))
edamame22 0:29983394c6b6 65
edamame22 0:29983394c6b6 66 #elif defined(BIG__ENDIAN)
edamame22 0:29983394c6b6 67
edamame22 0:29983394c6b6 68 #define PAL_HTONS(x) (x)
edamame22 0:29983394c6b6 69 #define PAL_NTOHS(x) (x)
edamame22 0:29983394c6b6 70 #define PAL_HTONL(x) (x)
edamame22 0:29983394c6b6 71 #define PAL_NTOHL(x) (x)
edamame22 0:29983394c6b6 72 #else
edamame22 0:29983394c6b6 73 #error neither BIG__ENDIAN nor LITTLE__ENDIAN defined, cannot compile
edamame22 0:29983394c6b6 74 #endif
edamame22 0:29983394c6b6 75
edamame22 0:29983394c6b6 76
edamame22 0:29983394c6b6 77
edamame22 0:29983394c6b6 78 #define PAL_INVERSE_UINT16_BYTES( val ) \
edamame22 0:29983394c6b6 79 ( ((val) << 8) | (((val) & 0x0000FF00) >> 8))
edamame22 0:29983394c6b6 80
edamame22 0:29983394c6b6 81 #define PAL_INVERSE_UINT32_BYTES( val ) \
edamame22 0:29983394c6b6 82 ( ((val) >> 24) | (((val) & 0x00FF0000) >> 8) | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24) )
edamame22 0:29983394c6b6 83
edamame22 0:29983394c6b6 84 #define PAL_INVERSE_UINT64_BYTES( val ) \
edamame22 0:29983394c6b6 85 ((PAL_INVERSE_UINT32_BYTES( ((val >> 16) >> 16)) &0xffffffff) | ((((uint64_t)PAL_INVERSE_UINT32_BYTES(val & 0xffffffff))<<16)<<16))
edamame22 0:29983394c6b6 86
edamame22 0:29983394c6b6 87 /* Set of Macros similar to the HTONS/L, NTOHS/L ones but converting to/from little endian instead of big endian*/
edamame22 0:29983394c6b6 88 #ifdef LITTLE__ENDIAN
edamame22 0:29983394c6b6 89 #define PAL_LITTLE_ENDIAN_TO_HOST_16BIT(x) (x)
edamame22 0:29983394c6b6 90 #define PAL_LITTLE_ENDIAN_TO_HOST_32BIT(x) (x)
edamame22 0:29983394c6b6 91 #define PAL_LITTLE_ENDIAN_TO_HOST_64BIT(x) (x)
edamame22 0:29983394c6b6 92 #define PAL_HOST_TO_LITTLE_ENDIAN_16BIT(x) (x)
edamame22 0:29983394c6b6 93 #define PAL_HOST_TO_LITTLE_ENDIAN_32BIT(x) (x)
edamame22 0:29983394c6b6 94 #define PAL_HOST_TO_LITTLE_ENDIAN_64BIT(x) (x)
edamame22 0:29983394c6b6 95
edamame22 0:29983394c6b6 96
edamame22 0:29983394c6b6 97 #elif defined(BIG__ENDIAN)
edamame22 0:29983394c6b6 98 #define PAL_LITTLE_ENDIAN_TO_HOST_16BIT(x) (PAL_INVERSE_UINT16_BYTES(((uint16_t)x)))
edamame22 0:29983394c6b6 99 #define PAL_LITTLE_ENDIAN_TO_HOST_32BIT(x) (PAL_INVERSE_UINT32_BYTES(((uint32_t)x)))
edamame22 0:29983394c6b6 100 #define PAL_LITTLE_ENDIAN_TO_HOST_64BIT(x) (PAL_INVERSE_UINT64_BYTES(((uint64_t)x)))
edamame22 0:29983394c6b6 101 #define PAL_HOST_TO_LITTLE_ENDIAN_16BIT(x) (PAL_INVERSE_UINT16_BYTES(((uint16_t)x)))
edamame22 0:29983394c6b6 102 #define PAL_HOST_TO_LITTLE_ENDIAN_32BIT(x) (PAL_INVERSE_UINT32_BYTES(((uint32_t)x)))
edamame22 0:29983394c6b6 103 #define PAL_HOST_TO_LITTLE_ENDIAN_64BIT(x) (PAL_INVERSE_UINT64_BYTES(((uint64_t)x)))
edamame22 0:29983394c6b6 104
edamame22 0:29983394c6b6 105 #else
edamame22 0:29983394c6b6 106 #error neither BIG__ENDIAN nor LITTLE__ENDIAN defined, cannot compile
edamame22 0:29983394c6b6 107 #endif
edamame22 0:29983394c6b6 108
edamame22 0:29983394c6b6 109
edamame22 0:29983394c6b6 110 #define PAL_MODULE_INIT(INIT) INIT= 1
edamame22 0:29983394c6b6 111 #define PAL_MODULE_DEINIT(INIT) INIT= 0
edamame22 0:29983394c6b6 112
edamame22 0:29983394c6b6 113 #ifdef DEBUG
edamame22 0:29983394c6b6 114 #include "pal.h"
edamame22 0:29983394c6b6 115 #define DEBUG_PRINT(ARGS...) PAL_PRINTF(ARGS)
edamame22 0:29983394c6b6 116
edamame22 0:29983394c6b6 117 #define DEBUG_PRINT(ARGS...) PAL_PRINTF(ARGS)
edamame22 0:29983394c6b6 118 #define PAL_MODULE_IS_INIT(INIT) if(!INIT) return PAL_ERR_NOT_INITIALIZED;
edamame22 0:29983394c6b6 119
edamame22 0:29983394c6b6 120
edamame22 0:29983394c6b6 121 #else
edamame22 0:29983394c6b6 122 #define PAL_MODULE_IS_INIT(INIT)
edamame22 0:29983394c6b6 123
edamame22 0:29983394c6b6 124 #define DEBUG_PRINT(ARGS...)
edamame22 0:29983394c6b6 125
edamame22 0:29983394c6b6 126 #endif //DEBUG
edamame22 0:29983394c6b6 127
edamame22 0:29983394c6b6 128 #ifdef __cplusplus
edamame22 0:29983394c6b6 129 }
edamame22 0:29983394c6b6 130 #endif
edamame22 0:29983394c6b6 131 #endif //_PAL_MACROS_H