Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Committer:
AntonLS
Date:
Thu Feb 11 17:47:28 2016 +0000
Revision:
67:5650f461722a
Parent:
41:dee3fd34e37a
Radio message arch like old cones. Static or Auto node IDs.  Missed ack detect. Dark alert fix. Fixes cone death.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AntonLS 5:1b9734e68327 1 /*
AntonLS 11:d3aa5fca2330 2 * True Agility
AntonLS 11:d3aa5fca2330 3 *
AntonLS 5:1b9734e68327 4 * Buffered IO of pending CharacteristicWrites meant to Nofify
AntonLS 11:d3aa5fca2330 5 * the phone/tablet application. Started 20150416 ALS
AntonLS 5:1b9734e68327 6 *
AntonLS 5:1b9734e68327 7 */
AntonLS 5:1b9734e68327 8
AntonLS 5:1b9734e68327 9 #ifndef PHONEAPPIO_H
AntonLS 5:1b9734e68327 10 #define PHONEAPPIO_H
AntonLS 5:1b9734e68327 11
AntonLS 5:1b9734e68327 12 #include "mbed.h"
AntonLS 5:1b9734e68327 13 #include "BLEDevice.h"
AntonLS 5:1b9734e68327 14 #include <cstdarg>
AntonLS 11:d3aa5fca2330 15 #include <cstdio>
AntonLS 5:1b9734e68327 16 #include "MTSBufferedIO.h"
AntonLS 11:d3aa5fca2330 17 #include "Vars.h"
AntonLS 67:5650f461722a 18 #include "types.h"
AntonLS 5:1b9734e68327 19
AntonLS 30:c60b0d52b067 20 #define STRING_STACK_LIMIT 64 /* 120 */
AntonLS 11:d3aa5fca2330 21 #define TXRX_BUF_LEN 20
AntonLS 11:d3aa5fca2330 22
AntonLS 11:d3aa5fca2330 23 extern uint8_t txPayload[];
AntonLS 11:d3aa5fca2330 24 extern bool updateCharacteristic( GattAttribute::Handle_t handle, const uint8_t *data, uint16_t bytesRead );
AntonLS 5:1b9734e68327 25
AntonLS 5:1b9734e68327 26 // namespace moo
AntonLS 5:1b9734e68327 27 // {
AntonLS 5:1b9734e68327 28
AntonLS 5:1b9734e68327 29 class PhoneAppIO : public mts::MTSBufferedIO
AntonLS 5:1b9734e68327 30 {
AntonLS 5:1b9734e68327 31 public:
AntonLS 11:d3aa5fca2330 32 PhoneAppIO( BLEDevice &ble, GattAttribute::Handle_t toPhoneHandle,
AntonLS 11:d3aa5fca2330 33 GattAttribute::Handle_t toConeHandle,
AntonLS 67:5650f461722a 34 int txBufferSize=PHSENDBUFSIZ, int rxBufferSize=120 );
AntonLS 5:1b9734e68327 35
AntonLS 11:d3aa5fca2330 36 /** Destructs a PhoneAppIO object and frees all related resources, including
AntonLS 5:1b9734e68327 37 * internal buffers.
AntonLS 5:1b9734e68327 38 */
AntonLS 5:1b9734e68327 39 ~PhoneAppIO();
AntonLS 5:1b9734e68327 40
AntonLS 5:1b9734e68327 41 /** Write a string to the buffer
AntonLS 5:1b9734e68327 42 *
AntonLS 11:d3aa5fca2330 43 * @param str The string to write (append your own CR)
AntonLS 5:1b9734e68327 44 *
AntonLS 5:1b9734e68327 45 * @returns 0 if the write succeeds, EOF for error
AntonLS 5:1b9734e68327 46 */
AntonLS 5:1b9734e68327 47 int puts( const char *str )
AntonLS 5:1b9734e68327 48 {
AntonLS 5:1b9734e68327 49 return write( str, strlen( str ) );
AntonLS 5:1b9734e68327 50 }
AntonLS 5:1b9734e68327 51
AntonLS 5:1b9734e68327 52 int printf( const char *format, ... )
AntonLS 5:1b9734e68327 53 {
AntonLS 5:1b9734e68327 54 va_list arg;
AntonLS 5:1b9734e68327 55 va_start( arg, format );
AntonLS 5:1b9734e68327 56
AntonLS 5:1b9734e68327 57 int len = PhoneAppIO::vprintf( format, arg );
AntonLS 5:1b9734e68327 58
AntonLS 5:1b9734e68327 59 va_end( arg );
AntonLS 5:1b9734e68327 60
AntonLS 5:1b9734e68327 61 return len;
AntonLS 5:1b9734e68327 62 }
AntonLS 5:1b9734e68327 63 int vprintf( const char *format, va_list arg )
AntonLS 5:1b9734e68327 64 {
AntonLS 5:1b9734e68327 65 int len = vsnprintf( NULL, 0, format, arg );
AntonLS 5:1b9734e68327 66 if( len < STRING_STACK_LIMIT )
AntonLS 5:1b9734e68327 67 {
AntonLS 5:1b9734e68327 68 char temp[STRING_STACK_LIMIT];
elmbed 23:26f27c462976 69 vsnprintf( temp, sizeof(temp), format, arg );
AntonLS 5:1b9734e68327 70 puts( temp );
AntonLS 5:1b9734e68327 71
AntonLS 5:1b9734e68327 72 } else
AntonLS 5:1b9734e68327 73 {
AntonLS 5:1b9734e68327 74 char *temp = new char[len + 1];
AntonLS 5:1b9734e68327 75 vsprintf( temp, format, arg );
AntonLS 5:1b9734e68327 76 puts( temp );
AntonLS 5:1b9734e68327 77 delete[] temp;
AntonLS 5:1b9734e68327 78 }
AntonLS 5:1b9734e68327 79
AntonLS 5:1b9734e68327 80 return len;
AntonLS 5:1b9734e68327 81 }
AntonLS 5:1b9734e68327 82
AntonLS 11:d3aa5fca2330 83 int putchar( int ch )
AntonLS 11:d3aa5fca2330 84 {
AntonLS 11:d3aa5fca2330 85 return ((0 == write( (char)ch )) ? EOF : ch);
AntonLS 11:d3aa5fca2330 86 }
AntonLS 11:d3aa5fca2330 87
AntonLS 11:d3aa5fca2330 88 int getchar()
AntonLS 11:d3aa5fca2330 89 {
AntonLS 11:d3aa5fca2330 90 char ch;
AntonLS 11:d3aa5fca2330 91 return ((0 == atomicRead( ch )) ? EOF : ch);
AntonLS 11:d3aa5fca2330 92 }
AntonLS 11:d3aa5fca2330 93
AntonLS 11:d3aa5fca2330 94 uint16_t maybeHandleRead( const GattCharacteristicWriteCBParams *params ); // Called by onDataWritten() from BLE.
AntonLS 11:d3aa5fca2330 95 uint16_t maybeHandleWrite(); // Called by toPhoneChk() from main loop.
AntonLS 19:afcbb425b3cf 96 uint16_t injectHandleRead( char *buf, int len ); // Inject data from elsewhere simulating BLE-in.
AntonLS 11:d3aa5fca2330 97
AntonLS 11:d3aa5fca2330 98 bool loopbackMode;
AntonLS 11:d3aa5fca2330 99 bool busy;
AntonLS 5:1b9734e68327 100
AntonLS 5:1b9734e68327 101 protected:
AntonLS 11:d3aa5fca2330 102 BLEDevice *bleP;
AntonLS 11:d3aa5fca2330 103 bool bleWasntReady;
AntonLS 11:d3aa5fca2330 104
AntonLS 11:d3aa5fca2330 105 GattAttribute::Handle_t toPhoneHandle;
AntonLS 11:d3aa5fca2330 106 GattAttribute::Handle_t toConeHandle;
AntonLS 11:d3aa5fca2330 107
AntonLS 11:d3aa5fca2330 108 char *data;
AntonLS 11:d3aa5fca2330 109 uint16_t bytesRead;
AntonLS 11:d3aa5fca2330 110
AntonLS 11:d3aa5fca2330 111 uint8_t rx_buf[TXRX_BUF_LEN];
AntonLS 11:d3aa5fca2330 112 uint8_t rx_len;
AntonLS 5:1b9734e68327 113
AntonLS 5:1b9734e68327 114 private:
AntonLS 5:1b9734e68327 115 virtual void handleWrite(); // Method for handling data to be written
AntonLS 5:1b9734e68327 116 virtual void handleRead(); // Method for handling data to be read
AntonLS 11:d3aa5fca2330 117
AntonLS 11:d3aa5fca2330 118 // For locking out read() during write() to prevent buffer state corruption.
AntonLS 11:d3aa5fca2330 119 virtual void disableTxIrq();
AntonLS 11:d3aa5fca2330 120 virtual void enableTxIrq();
AntonLS 11:d3aa5fca2330 121
AntonLS 11:d3aa5fca2330 122 // For locking out write() during read() to prevent buffer state corruption.
AntonLS 11:d3aa5fca2330 123 virtual void disableRxIrq();
AntonLS 11:d3aa5fca2330 124 virtual void enableRxIrq();
AntonLS 11:d3aa5fca2330 125
AntonLS 11:d3aa5fca2330 126 bool writing;
AntonLS 11:d3aa5fca2330 127 bool reading;
AntonLS 5:1b9734e68327 128 };
AntonLS 5:1b9734e68327 129
AntonLS 5:1b9734e68327 130 // }
AntonLS 5:1b9734e68327 131
AntonLS 5:1b9734e68327 132 #endif /* PHONEAPPIO_H */
AntonLS 5:1b9734e68327 133
AntonLS 5:1b9734e68327 134 /* EOF */