Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

PhoneAppIO.cpp

Committer:
AntonLS
Date:
2015-04-17
Revision:
5:1b9734e68327
Child:
11:d3aa5fca2330

File content as of revision 5:1b9734e68327:

/*
 *  Buffered IO of pending CharacteristicWrites meant to Nofify
 *   the phone/tablet application.   ALS  20150416
 *
 */

#include "PhoneAppIO.h"

PhoneAppIO::PhoneAppIO( BLEDevice *ble, int txBufferSize, int rxBufferSize )
            : mts::MTSBufferedIO( txBufferSize, rxBufferSize )
{
    PhoneAppIO::ble = ble;
    data            = NULL;
    bytesRead       = 0;
}

PhoneAppIO::~PhoneAppIO()
{
}


void PhoneAppIO::toPhoneBuf( uint8_t *data, uint16_t bytesRead )
{
    PhoneAppIO::data      = data;
    PhoneAppIO::bytesRead = bytesRead;
    handleRead();
}

void PhoneAppIO::handleRead()
{
    int charsToBuf = rxBuffer.write( (char *)data, bytesRead );
    if( charsToBuf != bytesRead )
    {
        printf( "[ERROR] ToPhoneCharacteristic Data Lost, tried %d, got %d\r\n", bytesRead, charsToBuf );
    }
}

void PhoneAppIO::handleWrite()
{
    /** This method should be used to transfer
    * data from the internal write buffer (txBuffer) to the physical interface.
    * Note that this function is called everytime new data is written to the
    * txBuffer though one of the write calls.
    */

    while( txBuffer.size() != 0 )
    {
        if( 1 /* ble. writeable() */ )
        {
            char byte;
            if( txBuffer.read( byte ) == 1 )
            {
                // Write Characteristic
            }

        } else
          {
              return;
          }
    }
}

/* EOF */