Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of football_project by
PhoneAppIO.cpp@5:1b9734e68327, 2015-04-17 (annotated)
- Committer:
- AntonLS
- Date:
- Fri Apr 17 04:20:07 2015 +0000
- Revision:
- 5:1b9734e68327
- Child:
- 11:d3aa5fca2330
Waits for BLE ready on characteristic update.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| AntonLS | 5:1b9734e68327 | 1 | /* |
| AntonLS | 5:1b9734e68327 | 2 | * Buffered IO of pending CharacteristicWrites meant to Nofify |
| AntonLS | 5:1b9734e68327 | 3 | * the phone/tablet application. ALS 20150416 |
| AntonLS | 5:1b9734e68327 | 4 | * |
| AntonLS | 5:1b9734e68327 | 5 | */ |
| AntonLS | 5:1b9734e68327 | 6 | |
| AntonLS | 5:1b9734e68327 | 7 | #include "PhoneAppIO.h" |
| AntonLS | 5:1b9734e68327 | 8 | |
| AntonLS | 5:1b9734e68327 | 9 | PhoneAppIO::PhoneAppIO( BLEDevice *ble, int txBufferSize, int rxBufferSize ) |
| AntonLS | 5:1b9734e68327 | 10 | : mts::MTSBufferedIO( txBufferSize, rxBufferSize ) |
| AntonLS | 5:1b9734e68327 | 11 | { |
| AntonLS | 5:1b9734e68327 | 12 | PhoneAppIO::ble = ble; |
| AntonLS | 5:1b9734e68327 | 13 | data = NULL; |
| AntonLS | 5:1b9734e68327 | 14 | bytesRead = 0; |
| AntonLS | 5:1b9734e68327 | 15 | } |
| AntonLS | 5:1b9734e68327 | 16 | |
| AntonLS | 5:1b9734e68327 | 17 | PhoneAppIO::~PhoneAppIO() |
| AntonLS | 5:1b9734e68327 | 18 | { |
| AntonLS | 5:1b9734e68327 | 19 | } |
| AntonLS | 5:1b9734e68327 | 20 | |
| AntonLS | 5:1b9734e68327 | 21 | |
| AntonLS | 5:1b9734e68327 | 22 | void PhoneAppIO::toPhoneBuf( uint8_t *data, uint16_t bytesRead ) |
| AntonLS | 5:1b9734e68327 | 23 | { |
| AntonLS | 5:1b9734e68327 | 24 | PhoneAppIO::data = data; |
| AntonLS | 5:1b9734e68327 | 25 | PhoneAppIO::bytesRead = bytesRead; |
| AntonLS | 5:1b9734e68327 | 26 | handleRead(); |
| AntonLS | 5:1b9734e68327 | 27 | } |
| AntonLS | 5:1b9734e68327 | 28 | |
| AntonLS | 5:1b9734e68327 | 29 | void PhoneAppIO::handleRead() |
| AntonLS | 5:1b9734e68327 | 30 | { |
| AntonLS | 5:1b9734e68327 | 31 | int charsToBuf = rxBuffer.write( (char *)data, bytesRead ); |
| AntonLS | 5:1b9734e68327 | 32 | if( charsToBuf != bytesRead ) |
| AntonLS | 5:1b9734e68327 | 33 | { |
| AntonLS | 5:1b9734e68327 | 34 | printf( "[ERROR] ToPhoneCharacteristic Data Lost, tried %d, got %d\r\n", bytesRead, charsToBuf ); |
| AntonLS | 5:1b9734e68327 | 35 | } |
| AntonLS | 5:1b9734e68327 | 36 | } |
| AntonLS | 5:1b9734e68327 | 37 | |
| AntonLS | 5:1b9734e68327 | 38 | void PhoneAppIO::handleWrite() |
| AntonLS | 5:1b9734e68327 | 39 | { |
| AntonLS | 5:1b9734e68327 | 40 | /** This method should be used to transfer |
| AntonLS | 5:1b9734e68327 | 41 | * data from the internal write buffer (txBuffer) to the physical interface. |
| AntonLS | 5:1b9734e68327 | 42 | * Note that this function is called everytime new data is written to the |
| AntonLS | 5:1b9734e68327 | 43 | * txBuffer though one of the write calls. |
| AntonLS | 5:1b9734e68327 | 44 | */ |
| AntonLS | 5:1b9734e68327 | 45 | |
| AntonLS | 5:1b9734e68327 | 46 | while( txBuffer.size() != 0 ) |
| AntonLS | 5:1b9734e68327 | 47 | { |
| AntonLS | 5:1b9734e68327 | 48 | if( 1 /* ble. writeable() */ ) |
| AntonLS | 5:1b9734e68327 | 49 | { |
| AntonLS | 5:1b9734e68327 | 50 | char byte; |
| AntonLS | 5:1b9734e68327 | 51 | if( txBuffer.read( byte ) == 1 ) |
| AntonLS | 5:1b9734e68327 | 52 | { |
| AntonLS | 5:1b9734e68327 | 53 | // Write Characteristic |
| AntonLS | 5:1b9734e68327 | 54 | } |
| AntonLS | 5:1b9734e68327 | 55 | |
| AntonLS | 5:1b9734e68327 | 56 | } else |
| AntonLS | 5:1b9734e68327 | 57 | { |
| AntonLS | 5:1b9734e68327 | 58 | return; |
| AntonLS | 5:1b9734e68327 | 59 | } |
| AntonLS | 5:1b9734e68327 | 60 | } |
| AntonLS | 5:1b9734e68327 | 61 | } |
| AntonLS | 5:1b9734e68327 | 62 | |
| AntonLS | 5:1b9734e68327 | 63 | /* EOF */ |
