Library for Using BLE as Stream Object

Dependents:   bel-example-pentabarf

Committer:
twixx
Date:
Wed Jan 03 15:07:11 2018 +0000
Revision:
0:062c87342d61
added Ble Serial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
twixx 0:062c87342d61 1 /* mbed Microcontroller Library
twixx 0:062c87342d61 2 * Copyright (c) 2006-2013 ARM Limited
twixx 0:062c87342d61 3 *
twixx 0:062c87342d61 4 * Licensed under the Apache License, Version 2.0 (the "License");
twixx 0:062c87342d61 5 * you may not use this file except in compliance with the License.
twixx 0:062c87342d61 6 * You may obtain a copy of the License at
twixx 0:062c87342d61 7 *
twixx 0:062c87342d61 8 * http://www.apache.org/licenses/LICENSE-2.0
twixx 0:062c87342d61 9 *
twixx 0:062c87342d61 10 * Unless required by applicable law or agreed to in writing, software
twixx 0:062c87342d61 11 * distributed under the License is distributed on an "AS IS" BASIS,
twixx 0:062c87342d61 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
twixx 0:062c87342d61 13 * See the License for the specific language governing permissions and
twixx 0:062c87342d61 14 * limitations under the License.
twixx 0:062c87342d61 15 */
twixx 0:062c87342d61 16 #include "BleSerial.h"
twixx 0:062c87342d61 17 #include "platform/mbed_wait_api.h"
twixx 0:062c87342d61 18
twixx 0:062c87342d61 19 //#if DEVICE_SERIAL
twixx 0:062c87342d61 20
twixx 0:062c87342d61 21 namespace mbed {
twixx 0:062c87342d61 22
twixx 0:062c87342d61 23 BleSerial::BleSerial(BLE &_ble) : Stream() {
twixx 0:062c87342d61 24 this->bleUart = new UARTService(_ble);
twixx 0:062c87342d61 25 }
twixx 0:062c87342d61 26
twixx 0:062c87342d61 27 //bool BleSerial::readable() const{
twixx 0:062c87342d61 28 // return (bool) numBytesReceived;
twixx 0:062c87342d61 29 //}
twixx 0:062c87342d61 30
twixx 0:062c87342d61 31 ssize_t BleSerial::write(const void* buffer, size_t length){
twixx 0:062c87342d61 32 return this->bleUart->write(buffer, length);
twixx 0:062c87342d61 33 }
twixx 0:062c87342d61 34
twixx 0:062c87342d61 35 int BleSerial::_putc(int c){
twixx 0:062c87342d61 36 return this->bleUart->_putc(c);
twixx 0:062c87342d61 37 }
twixx 0:062c87342d61 38
twixx 0:062c87342d61 39 int BleSerial::_getc(){
twixx 0:062c87342d61 40 return this->bleUart->_getc();
twixx 0:062c87342d61 41 }
twixx 0:062c87342d61 42
twixx 0:062c87342d61 43 /**
twixx 0:062c87342d61 44 * Note: TX and RX characteristics are to be interpreted from the viewpoint of the GATT client using this service.
twixx 0:062c87342d61 45 */
twixx 0:062c87342d61 46 uint16_t BleSerial::getTXCHandle() {
twixx 0:062c87342d61 47 return this->bleUart->getTXCharacteristicHandle();
twixx 0:062c87342d61 48 }
twixx 0:062c87342d61 49
twixx 0:062c87342d61 50 /**
twixx 0:062c87342d61 51 * Note: TX and RX characteristics are to be interpreted from the viewpoint of the GATT client using this service.
twixx 0:062c87342d61 52 */
twixx 0:062c87342d61 53 uint16_t BleSerial::getRXCHandle() {
twixx 0:062c87342d61 54 return this->bleUart->getRXCharacteristicHandle();
twixx 0:062c87342d61 55 }
twixx 0:062c87342d61 56
twixx 0:062c87342d61 57 } // namespace mbed
twixx 0:062c87342d61 58
twixx 0:062c87342d61 59 //#endif