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
Diff: PhoneAppIO.h
- Revision:
- 11:d3aa5fca2330
- Parent:
- 5:1b9734e68327
- Child:
- 19:afcbb425b3cf
diff -r 72ceef287b0f -r d3aa5fca2330 PhoneAppIO.h
--- a/PhoneAppIO.h Tue Apr 21 07:00:55 2015 +0000
+++ b/PhoneAppIO.h Thu Apr 23 06:36:57 2015 +0000
@@ -1,6 +1,8 @@
/*
+ * True Agility
+ *
* Buffered IO of pending CharacteristicWrites meant to Nofify
- * the phone/tablet application. ALS 20150416
+ * the phone/tablet application. Started 20150416 ALS
*
*/
@@ -10,9 +12,15 @@
#include "mbed.h"
#include "BLEDevice.h"
#include <cstdarg>
+#include <cstdio>
#include "MTSBufferedIO.h"
+#include "Vars.h"
#define STRING_STACK_LIMIT 120
+#define TXRX_BUF_LEN 20
+
+extern uint8_t txPayload[];
+extern bool updateCharacteristic( GattAttribute::Handle_t handle, const uint8_t *data, uint16_t bytesRead );
// namespace moo
// {
@@ -20,16 +28,18 @@
class PhoneAppIO : public mts::MTSBufferedIO
{
public:
- PhoneAppIO( BLEDevice *ble, int txBufferSize=1280, int rxBufferSize=1280 );
+ PhoneAppIO( BLEDevice &ble, GattAttribute::Handle_t toPhoneHandle,
+ GattAttribute::Handle_t toConeHandle,
+ int txBufferSize=1280, int rxBufferSize=256 );
- /** Destructs an MTSSerial object and frees all related resources, including
+ /** Destructs a PhoneAppIO object and frees all related resources, including
* internal buffers.
*/
~PhoneAppIO();
/** Write a string to the buffer
*
- * @param str The string to write
+ * @param str The string to write (append your own CR)
*
* @returns 0 if the write succeeds, EOF for error
*/
@@ -69,16 +79,50 @@
return len;
}
- void toPhoneBuf( uint8_t *data, uint16_t bytesRead );
+ int putchar( int ch )
+ {
+ return ((0 == write( (char)ch )) ? EOF : ch);
+ }
+
+ int getchar()
+ {
+ char ch;
+ return ((0 == atomicRead( ch )) ? EOF : ch);
+ }
+
+ uint16_t maybeHandleRead( const GattCharacteristicWriteCBParams *params ); // Called by onDataWritten() from BLE.
+ uint16_t maybeHandleWrite(); // Called by toPhoneChk() from main loop.
+
+ bool loopbackMode;
+ bool busy;
protected:
- BLEDevice *ble;
- uint8_t *data;
- uint16_t bytesRead;
+ BLEDevice *bleP;
+ bool bleWasntReady;
+
+ GattAttribute::Handle_t toPhoneHandle;
+ GattAttribute::Handle_t toConeHandle;
+
+ char *data;
+ uint16_t bytesRead;
+
+ uint8_t rx_buf[TXRX_BUF_LEN];
+ uint8_t rx_len;
private:
virtual void handleWrite(); // Method for handling data to be written
virtual void handleRead(); // Method for handling data to be read
+
+ // For locking out read() during write() to prevent buffer state corruption.
+ virtual void disableTxIrq();
+ virtual void enableTxIrq();
+
+ // For locking out write() during read() to prevent buffer state corruption.
+ virtual void disableRxIrq();
+ virtual void enableRxIrq();
+
+ bool writing;
+ bool reading;
};
// }
