Library for Using BLE as Stream Object
Dependents: bel-example-pentabarf
Revision 0:062c87342d61, committed 2018-01-03
- Comitter:
- twixx
- Date:
- Wed Jan 03 15:07:11 2018 +0000
- Commit message:
- added Ble Serial
Changed in this revision
BleSerial.cpp | Show annotated file Show diff for this revision Revisions of this file |
BleSerial.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 062c87342d61 BleSerial.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BleSerial.cpp Wed Jan 03 15:07:11 2018 +0000 @@ -0,0 +1,59 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "BleSerial.h" +#include "platform/mbed_wait_api.h" + +//#if DEVICE_SERIAL + +namespace mbed { + +BleSerial::BleSerial(BLE &_ble) : Stream() { + this->bleUart = new UARTService(_ble); +} + + //bool BleSerial::readable() const{ + // return (bool) numBytesReceived; + //} + + ssize_t BleSerial::write(const void* buffer, size_t length){ + return this->bleUart->write(buffer, length); + } + + int BleSerial::_putc(int c){ + return this->bleUart->_putc(c); + } + + int BleSerial::_getc(){ + return this->bleUart->_getc(); + } + + /** + * Note: TX and RX characteristics are to be interpreted from the viewpoint of the GATT client using this service. + */ + uint16_t BleSerial::getTXCHandle() { + return this->bleUart->getTXCharacteristicHandle(); + } + + /** + * Note: TX and RX characteristics are to be interpreted from the viewpoint of the GATT client using this service. + */ + uint16_t BleSerial::getRXCHandle() { + return this->bleUart->getRXCharacteristicHandle(); + } + +} // namespace mbed + +//#endif
diff -r 000000000000 -r 062c87342d61 BleSerial.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BleSerial.h Wed Jan 03 15:07:11 2018 +0000 @@ -0,0 +1,57 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MBED_BLESERIAL_H +#define MBED_BLESERIAL_H + +#include "platform/platform.h" + +//#if defined (DEVICE_SERIAL) || defined(DOXYGEN_ONLY) + +#include "Stream.h" +#include "UARTService.h" +#include "platform/NonCopyable.h" + +namespace mbed { + +class BleSerial : public Stream, private NonCopyable<BleSerial> { + +public: + //using UARTService::write; + //using Stream::read override; + virtual ssize_t write(const void* buffer, size_t length); + + BleSerial(BLE &_ble); + + uint16_t getTXCHandle(); + uint16_t getRXCHandle(); + + //bool readable(); + //writeable: return (bool) BLE_UART_SERVICE_MAX_DATA_LEN - sendBufferIndex; + +protected: + //using UARTService::_getc; + //using UARTService::_putc; + virtual int _putc(int c); + virtual int _getc(); +private: + UARTService *bleUart; +}; + +} // namespace mbed + +#endif + +//#endif \ No newline at end of file