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/hw/GattServer.h@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 | #ifndef __GATT_SERVER_H__ |
jksoft | 0:8c643bfe55b7 | 18 | #define __GATT_SERVER_H__ |
jksoft | 0:8c643bfe55b7 | 19 | |
jksoft | 0:8c643bfe55b7 | 20 | #include "mbed.h" |
jksoft | 0:8c643bfe55b7 | 21 | #include "blecommon.h" |
jksoft | 0:8c643bfe55b7 | 22 | #include "GattService.h" |
jksoft | 0:8c643bfe55b7 | 23 | #include "GattServerEvents.h" |
jksoft | 0:8c643bfe55b7 | 24 | |
jksoft | 0:8c643bfe55b7 | 25 | /**************************************************************************/ |
jksoft | 0:8c643bfe55b7 | 26 | /*! |
jksoft | 0:8c643bfe55b7 | 27 | \brief |
jksoft | 0:8c643bfe55b7 | 28 | The base class used to abstract GATT Server functionality to a specific |
jksoft | 0:8c643bfe55b7 | 29 | radio transceiver, SOC or BLE Stack. |
jksoft | 0:8c643bfe55b7 | 30 | */ |
jksoft | 0:8c643bfe55b7 | 31 | /**************************************************************************/ |
jksoft | 0:8c643bfe55b7 | 32 | class GattServer |
jksoft | 0:8c643bfe55b7 | 33 | { |
jksoft | 0:8c643bfe55b7 | 34 | private: |
jksoft | 0:8c643bfe55b7 | 35 | GattServerEvents *m_pEventHandler; |
jksoft | 0:8c643bfe55b7 | 36 | |
jksoft | 0:8c643bfe55b7 | 37 | public: |
jksoft | 0:8c643bfe55b7 | 38 | /* These functions must be defined in the sub-class */ |
jksoft | 0:8c643bfe55b7 | 39 | virtual ble_error_t addService(GattService &) = 0; |
jksoft | 0:8c643bfe55b7 | 40 | virtual ble_error_t readValue(uint16_t, uint8_t[], uint16_t) = 0; |
jksoft | 0:8c643bfe55b7 | 41 | virtual ble_error_t updateValue(uint16_t, uint8_t[], uint16_t) = 0; |
jksoft | 0:8c643bfe55b7 | 42 | |
jksoft | 0:8c643bfe55b7 | 43 | // ToDo: For updateValue, check the CCCD to see if the value we are |
jksoft | 0:8c643bfe55b7 | 44 | // updating has the notify or indicate bits sent, and if BOTH are set |
jksoft | 0:8c643bfe55b7 | 45 | // be sure to call sd_ble_gatts_hvx() twice with notify then indicate! |
jksoft | 0:8c643bfe55b7 | 46 | // Strange use case, but valid and must be covered! |
jksoft | 0:8c643bfe55b7 | 47 | |
jksoft | 0:8c643bfe55b7 | 48 | /* Event callback handlers */ |
jksoft | 0:8c643bfe55b7 | 49 | void setEventHandler(GattServerEvents *pEventHandler) {m_pEventHandler = pEventHandler;} |
jksoft | 0:8c643bfe55b7 | 50 | void handleEvent(GattServerEvents::gattEvent_e type, uint16_t charHandle) { |
jksoft | 0:8c643bfe55b7 | 51 | if (NULL == m_pEventHandler) |
jksoft | 0:8c643bfe55b7 | 52 | return; |
jksoft | 0:8c643bfe55b7 | 53 | switch(type) { |
jksoft | 0:8c643bfe55b7 | 54 | case GattServerEvents::GATT_EVENT_DATA_SENT: |
jksoft | 0:8c643bfe55b7 | 55 | m_pEventHandler->onDataSent(charHandle); |
jksoft | 0:8c643bfe55b7 | 56 | break; |
jksoft | 0:8c643bfe55b7 | 57 | case GattServerEvents::GATT_EVENT_DATA_WRITTEN: |
jksoft | 0:8c643bfe55b7 | 58 | m_pEventHandler->onDataWritten(charHandle); |
jksoft | 0:8c643bfe55b7 | 59 | break; |
jksoft | 0:8c643bfe55b7 | 60 | case GattServerEvents::GATT_EVENT_UPDATES_ENABLED: |
jksoft | 0:8c643bfe55b7 | 61 | m_pEventHandler->onUpdatesEnabled(charHandle); |
jksoft | 0:8c643bfe55b7 | 62 | break; |
jksoft | 0:8c643bfe55b7 | 63 | case GattServerEvents::GATT_EVENT_UPDATES_DISABLED: |
jksoft | 0:8c643bfe55b7 | 64 | m_pEventHandler->onUpdatesDisabled(charHandle); |
jksoft | 0:8c643bfe55b7 | 65 | break; |
jksoft | 0:8c643bfe55b7 | 66 | case GattServerEvents::GATT_EVENT_CONFIRMATION_RECEIVED: |
jksoft | 0:8c643bfe55b7 | 67 | m_pEventHandler->onConfirmationReceived(charHandle); |
jksoft | 0:8c643bfe55b7 | 68 | break; |
jksoft | 0:8c643bfe55b7 | 69 | } |
jksoft | 0:8c643bfe55b7 | 70 | } |
jksoft | 0:8c643bfe55b7 | 71 | |
jksoft | 0:8c643bfe55b7 | 72 | uint8_t serviceCount; |
jksoft | 0:8c643bfe55b7 | 73 | uint8_t characteristicCount; |
jksoft | 0:8c643bfe55b7 | 74 | }; |
jksoft | 0:8c643bfe55b7 | 75 | |
jksoft | 0:8c643bfe55b7 | 76 | #endif |