iOSのBLEコントローラアプリ「RCBController」とmbed HRM1017を接続し、RCサーボモータを操作するテストプログラムです。
Dependencies: BLE_API_Native_IRC Servo mbed
Fork of BLE_RCBController by
- 古いBLEライブラリを使っているのでプラットフォームは”Nordic nRF51822”を選択してください。
- ライブラリ類はUpdateしないでください。コンパイルエラーになります。
うまく接続できない時は、iPhone/iPadのBluetoothをOFF->ONしてキャッシュをクリアしてみてください。
BLE_API_Native_IRC/UUID.cpp@2:1a3fb1a40edf, 2014-07-30 (annotated)
- Committer:
- robo8080
- Date:
- Wed Jul 30 00:09:23 2014 +0000
- Revision:
- 2:1a3fb1a40edf
- Parent:
- 0:8c643bfe55b7
test2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:8c643bfe55b7 | 1 | /* mbed Microcontroller Library |
jksoft | 0:8c643bfe55b7 | 2 | * Copyright (c) 2006-2013 ARM Limited |
jksoft | 0:8c643bfe55b7 | 3 | * |
jksoft | 0:8c643bfe55b7 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
jksoft | 0:8c643bfe55b7 | 5 | * you may not use this file except in compliance with the License. |
jksoft | 0:8c643bfe55b7 | 6 | * You may obtain a copy of the License at |
jksoft | 0:8c643bfe55b7 | 7 | * |
jksoft | 0:8c643bfe55b7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
jksoft | 0:8c643bfe55b7 | 9 | * |
jksoft | 0:8c643bfe55b7 | 10 | * Unless required by applicable law or agreed to in writing, software |
jksoft | 0:8c643bfe55b7 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
jksoft | 0:8c643bfe55b7 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
jksoft | 0:8c643bfe55b7 | 13 | * See the License for the specific language governing permissions and |
jksoft | 0:8c643bfe55b7 | 14 | * limitations under the License. |
jksoft | 0:8c643bfe55b7 | 15 | */ |
jksoft | 0:8c643bfe55b7 | 16 | |
jksoft | 0:8c643bfe55b7 | 17 | |
jksoft | 0:8c643bfe55b7 | 18 | #include <stdio.h> |
jksoft | 0:8c643bfe55b7 | 19 | #include <string.h> |
jksoft | 0:8c643bfe55b7 | 20 | |
jksoft | 0:8c643bfe55b7 | 21 | #include "UUID.h" |
jksoft | 0:8c643bfe55b7 | 22 | |
jksoft | 0:8c643bfe55b7 | 23 | /**************************************************************************/ |
jksoft | 0:8c643bfe55b7 | 24 | /*! |
jksoft | 0:8c643bfe55b7 | 25 | @brief Creates an empty 128-bit UUID |
jksoft | 0:8c643bfe55b7 | 26 | |
jksoft | 0:8c643bfe55b7 | 27 | @note This UUID must be assigned a valid value via the 'update' |
jksoft | 0:8c643bfe55b7 | 28 | function before it can be safely used! |
jksoft | 0:8c643bfe55b7 | 29 | */ |
jksoft | 0:8c643bfe55b7 | 30 | /**************************************************************************/ |
jksoft | 0:8c643bfe55b7 | 31 | UUID::UUID(void) |
jksoft | 0:8c643bfe55b7 | 32 | { |
jksoft | 0:8c643bfe55b7 | 33 | memset(base, 0, 16); |
jksoft | 0:8c643bfe55b7 | 34 | value = 0; |
jksoft | 0:8c643bfe55b7 | 35 | type = UUID_TYPE_SHORT; |
jksoft | 0:8c643bfe55b7 | 36 | } |
jksoft | 0:8c643bfe55b7 | 37 | |
jksoft | 0:8c643bfe55b7 | 38 | /**************************************************************************/ |
jksoft | 0:8c643bfe55b7 | 39 | /*! |
jksoft | 0:8c643bfe55b7 | 40 | @brief Creates a new 128-bit UUID |
jksoft | 0:8c643bfe55b7 | 41 | |
jksoft | 0:8c643bfe55b7 | 42 | @note The UUID is a unique 128-bit (16 byte) ID used to identify |
jksoft | 0:8c643bfe55b7 | 43 | different service or characteristics on the BLE device. |
jksoft | 0:8c643bfe55b7 | 44 | |
jksoft | 0:8c643bfe55b7 | 45 | @note When creating a UUID, the constructor will check if all bytes |
jksoft | 0:8c643bfe55b7 | 46 | except bytes 2/3 are equal to 0. If only bytes 2/3 have a |
jksoft | 0:8c643bfe55b7 | 47 | value, the UUID will be treated as a short/BLE UUID, and the |
jksoft | 0:8c643bfe55b7 | 48 | .type field will be set to UUID::UUID_TYPE_SHORT. If any |
jksoft | 0:8c643bfe55b7 | 49 | of the bytes outside byte 2/3 have a non-zero value, the UUID |
jksoft | 0:8c643bfe55b7 | 50 | will be considered a 128-bit ID, and .type will be assigned |
jksoft | 0:8c643bfe55b7 | 51 | as UUID::UUID_TYPE_LONG. |
jksoft | 0:8c643bfe55b7 | 52 | |
jksoft | 0:8c643bfe55b7 | 53 | @param[in] uuid_base |
jksoft | 0:8c643bfe55b7 | 54 | The 128-bit (16-byte) UUID value. For 128-bit values, |
jksoft | 0:8c643bfe55b7 | 55 | assign all 16 bytes. For 16-bit values, assign the |
jksoft | 0:8c643bfe55b7 | 56 | 16-bits to byte 2 and 3, and leave the rest of the bytes |
jksoft | 0:8c643bfe55b7 | 57 | as 0. |
jksoft | 0:8c643bfe55b7 | 58 | |
jksoft | 0:8c643bfe55b7 | 59 | @section EXAMPLE |
jksoft | 0:8c643bfe55b7 | 60 | |
jksoft | 0:8c643bfe55b7 | 61 | @code |
jksoft | 0:8c643bfe55b7 | 62 | |
jksoft | 0:8c643bfe55b7 | 63 | // Create a short UUID (0x180F) |
jksoft | 0:8c643bfe55b7 | 64 | uint8_t shortID[16] = { 0, 0, 0x0F, 0x18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
jksoft | 0:8c643bfe55b7 | 65 | UUID ble_uuid = UUID(shortID); |
jksoft | 0:8c643bfe55b7 | 66 | // ble_uuid.type = UUID_TYPE_SHORT |
jksoft | 0:8c643bfe55b7 | 67 | // ble_uuid.value = 0x180F |
jksoft | 0:8c643bfe55b7 | 68 | |
jksoft | 0:8c643bfe55b7 | 69 | // Creeate a long UUID |
jksoft | 0:8c643bfe55b7 | 70 | uint8_t longID[16] = { 0x00, 0x11, 0x22, 0x33, |
jksoft | 0:8c643bfe55b7 | 71 | 0x44, 0x55, 0x66, 0x77, |
jksoft | 0:8c643bfe55b7 | 72 | 0x88, 0x99, 0xAA, 0xBB, |
jksoft | 0:8c643bfe55b7 | 73 | 0xCC, 0xDD, 0xEE, 0xFF }; |
jksoft | 0:8c643bfe55b7 | 74 | UUID custom_uuid = UUID(longID); |
jksoft | 0:8c643bfe55b7 | 75 | // custom_uuid.type = UUID_TYPE_LONG |
jksoft | 0:8c643bfe55b7 | 76 | // custom_uuid.value = 0x3322 |
jksoft | 0:8c643bfe55b7 | 77 | // custom_uuid.base = 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF |
jksoft | 0:8c643bfe55b7 | 78 | |
jksoft | 0:8c643bfe55b7 | 79 | @endcode |
jksoft | 0:8c643bfe55b7 | 80 | */ |
jksoft | 0:8c643bfe55b7 | 81 | /**************************************************************************/ |
jksoft | 0:8c643bfe55b7 | 82 | UUID::UUID(uint8_t const uuid_base[16]) |
jksoft | 0:8c643bfe55b7 | 83 | { |
jksoft | 0:8c643bfe55b7 | 84 | memcpy(base, uuid_base, 16); |
jksoft | 0:8c643bfe55b7 | 85 | value = (uint16_t)((uuid_base[3] << 8) | (uuid_base[2])); |
jksoft | 0:8c643bfe55b7 | 86 | |
jksoft | 0:8c643bfe55b7 | 87 | /* Check if this is a short of a long UUID */ |
jksoft | 0:8c643bfe55b7 | 88 | if (uuid_base[0] + uuid_base[1] + |
jksoft | 0:8c643bfe55b7 | 89 | uuid_base[4] + uuid_base[5] + uuid_base[6] + uuid_base[7] + |
jksoft | 0:8c643bfe55b7 | 90 | uuid_base[8] + uuid_base[9] + uuid_base[10] + uuid_base[11] + |
jksoft | 0:8c643bfe55b7 | 91 | uuid_base[12] + uuid_base[13] + uuid_base[14] + uuid_base[15] == 0) |
jksoft | 0:8c643bfe55b7 | 92 | { |
jksoft | 0:8c643bfe55b7 | 93 | type = UUID_TYPE_SHORT; |
jksoft | 0:8c643bfe55b7 | 94 | } |
jksoft | 0:8c643bfe55b7 | 95 | else |
jksoft | 0:8c643bfe55b7 | 96 | { |
jksoft | 0:8c643bfe55b7 | 97 | type = UUID_TYPE_LONG; |
jksoft | 0:8c643bfe55b7 | 98 | } |
jksoft | 0:8c643bfe55b7 | 99 | } |
jksoft | 0:8c643bfe55b7 | 100 | |
jksoft | 0:8c643bfe55b7 | 101 | /**************************************************************************/ |
jksoft | 0:8c643bfe55b7 | 102 | /*! |
jksoft | 0:8c643bfe55b7 | 103 | @brief Creates a short (16-bit) UUID |
jksoft | 0:8c643bfe55b7 | 104 | |
jksoft | 0:8c643bfe55b7 | 105 | @param[in] ble_uuid |
jksoft | 0:8c643bfe55b7 | 106 | The 16-bit BLE UUID value. |
jksoft | 0:8c643bfe55b7 | 107 | */ |
jksoft | 0:8c643bfe55b7 | 108 | /**************************************************************************/ |
jksoft | 0:8c643bfe55b7 | 109 | UUID::UUID(uint16_t const ble_uuid) |
jksoft | 0:8c643bfe55b7 | 110 | { |
jksoft | 0:8c643bfe55b7 | 111 | memset(base, 0, 16); |
jksoft | 0:8c643bfe55b7 | 112 | memcpy(base+2, (uint8_t *)&ble_uuid, 2); |
jksoft | 0:8c643bfe55b7 | 113 | value = ble_uuid; |
jksoft | 0:8c643bfe55b7 | 114 | type = UUID_TYPE_SHORT; |
jksoft | 0:8c643bfe55b7 | 115 | } |
jksoft | 0:8c643bfe55b7 | 116 | |
jksoft | 0:8c643bfe55b7 | 117 | /**************************************************************************/ |
jksoft | 0:8c643bfe55b7 | 118 | /*! |
jksoft | 0:8c643bfe55b7 | 119 | @brief UUID destructor |
jksoft | 0:8c643bfe55b7 | 120 | */ |
jksoft | 0:8c643bfe55b7 | 121 | /**************************************************************************/ |
jksoft | 0:8c643bfe55b7 | 122 | UUID::~UUID(void) |
jksoft | 0:8c643bfe55b7 | 123 | { |
jksoft | 0:8c643bfe55b7 | 124 | } |
jksoft | 0:8c643bfe55b7 | 125 | |
jksoft | 0:8c643bfe55b7 | 126 | /**************************************************************************/ |
jksoft | 0:8c643bfe55b7 | 127 | /*! |
jksoft | 0:8c643bfe55b7 | 128 | @brief Updates the value of the UUID |
jksoft | 0:8c643bfe55b7 | 129 | |
jksoft | 0:8c643bfe55b7 | 130 | @args[in] uuid_base |
jksoft | 0:8c643bfe55b7 | 131 | The 128-bit value to use when updating the UUID. For |
jksoft | 0:8c643bfe55b7 | 132 | 16-bit IDs, insert the ID in bytes 2/3 in LSB format. |
jksoft | 0:8c643bfe55b7 | 133 | |
jksoft | 0:8c643bfe55b7 | 134 | @returns BLE_ERROR_NONE (0) if everything executed correctly, or an |
jksoft | 0:8c643bfe55b7 | 135 | error code if there was a problem |
jksoft | 0:8c643bfe55b7 | 136 | @retval BLE_ERROR_NONE |
jksoft | 0:8c643bfe55b7 | 137 | Everything executed correctly |
jksoft | 0:8c643bfe55b7 | 138 | |
jksoft | 0:8c643bfe55b7 | 139 | @section EXAMPLE |
jksoft | 0:8c643bfe55b7 | 140 | |
jksoft | 0:8c643bfe55b7 | 141 | @code |
jksoft | 0:8c643bfe55b7 | 142 | |
jksoft | 0:8c643bfe55b7 | 143 | @endcode |
jksoft | 0:8c643bfe55b7 | 144 | */ |
jksoft | 0:8c643bfe55b7 | 145 | /**************************************************************************/ |
jksoft | 0:8c643bfe55b7 | 146 | ble_error_t UUID::update(uint8_t const uuid_base[16]) |
jksoft | 0:8c643bfe55b7 | 147 | { |
jksoft | 0:8c643bfe55b7 | 148 | memcpy(base, uuid_base, 16); |
jksoft | 0:8c643bfe55b7 | 149 | value = (uint16_t)((uuid_base[3] << 8) | (uuid_base[2])); |
jksoft | 0:8c643bfe55b7 | 150 | |
jksoft | 0:8c643bfe55b7 | 151 | /* Check if this is a short of a long UUID */ |
jksoft | 0:8c643bfe55b7 | 152 | if (uuid_base[0] + uuid_base[1] + |
jksoft | 0:8c643bfe55b7 | 153 | uuid_base[4] + uuid_base[5] + uuid_base[6] + uuid_base[7] + |
jksoft | 0:8c643bfe55b7 | 154 | uuid_base[8] + uuid_base[9] + uuid_base[10] + uuid_base[11] + |
jksoft | 0:8c643bfe55b7 | 155 | uuid_base[12] + uuid_base[13] + uuid_base[14] + uuid_base[15] == 0) |
jksoft | 0:8c643bfe55b7 | 156 | { |
jksoft | 0:8c643bfe55b7 | 157 | type = UUID_TYPE_SHORT; |
jksoft | 0:8c643bfe55b7 | 158 | } |
jksoft | 0:8c643bfe55b7 | 159 | else |
jksoft | 0:8c643bfe55b7 | 160 | { |
jksoft | 0:8c643bfe55b7 | 161 | type = UUID_TYPE_LONG; |
jksoft | 0:8c643bfe55b7 | 162 | } |
jksoft | 0:8c643bfe55b7 | 163 | |
jksoft | 0:8c643bfe55b7 | 164 | return BLE_ERROR_NONE; |
jksoft | 0:8c643bfe55b7 | 165 | } |
jksoft | 0:8c643bfe55b7 | 166 | |
jksoft | 0:8c643bfe55b7 | 167 | /**************************************************************************/ |
jksoft | 0:8c643bfe55b7 | 168 | /*! |
jksoft | 0:8c643bfe55b7 | 169 | @brief Updates the value of the UUID |
jksoft | 0:8c643bfe55b7 | 170 | |
jksoft | 0:8c643bfe55b7 | 171 | @args[in] ble_uuid |
jksoft | 0:8c643bfe55b7 | 172 | The 16-bit value to use when updating the UUID. |
jksoft | 0:8c643bfe55b7 | 173 | |
jksoft | 0:8c643bfe55b7 | 174 | @returns BLE_ERROR_NONE (0) if everything executed correctly, or an |
jksoft | 0:8c643bfe55b7 | 175 | error code if there was a problem |
jksoft | 0:8c643bfe55b7 | 176 | @retval BLE_ERROR_NONE |
jksoft | 0:8c643bfe55b7 | 177 | Everything executed correctly |
jksoft | 0:8c643bfe55b7 | 178 | |
jksoft | 0:8c643bfe55b7 | 179 | @section EXAMPLE |
jksoft | 0:8c643bfe55b7 | 180 | |
jksoft | 0:8c643bfe55b7 | 181 | @code |
jksoft | 0:8c643bfe55b7 | 182 | |
jksoft | 0:8c643bfe55b7 | 183 | @endcode |
jksoft | 0:8c643bfe55b7 | 184 | */ |
jksoft | 0:8c643bfe55b7 | 185 | /**************************************************************************/ |
jksoft | 0:8c643bfe55b7 | 186 | ble_error_t UUID::update(uint16_t const ble_uuid) |
jksoft | 0:8c643bfe55b7 | 187 | { |
jksoft | 0:8c643bfe55b7 | 188 | memset(base, 0, 16); |
jksoft | 0:8c643bfe55b7 | 189 | memcpy(base+2, (uint8_t *)&ble_uuid, 2); |
jksoft | 0:8c643bfe55b7 | 190 | value = ble_uuid; |
jksoft | 0:8c643bfe55b7 | 191 | type = UUID_TYPE_SHORT; |
jksoft | 0:8c643bfe55b7 | 192 | |
jksoft | 0:8c643bfe55b7 | 193 | return BLE_ERROR_NONE; |
jksoft | 0:8c643bfe55b7 | 194 | } |