Flying Silicon Sensor
PtvBleInterface Class Reference

#include <ptvBleInterface.h>

Inheritance diagram for PtvBleInterface:
BleInterface

Classes

struct  SensorData
 Sensor data structure. More...
 

Public Member Functions

 PtvBleInterface ()
 Default c-tor.
 
void sendMetaMsg (const String &mna, const String &mmo, const String &msn)
 
void sendShortMsg (const SensorData &data)
 
void sendLongMsg (const SensorData &data)
 
void sendChunked (String &msg)
 
int getReceived (String &cmd)
 
void clrReceived ()
 Clear anything received so far.
 
- Public Member Functions inherited from BleInterface
void init (const char *deviceName)
 
void startAdv (void)
 
void sendData (const char *buf, int len)
 
void poll (void)
 
void shutdown (void)
 
int isConnected (void)
 

Protected Member Functions

void poll ()
 
void clrBuffer ()
 Clear internal receive buffer.
 

Protected Attributes

String command
 Holds last received text line / command.
 
char rcvBuffer [FIFO_SZ]
 Receive data buffer, same size as UART FIFO.
 
unsigned int pos
 Write position for next byte.
 
- Protected Attributes inherited from BleInterface
FsUart bleuart
 Customized UART service.
 

Additional Inherited Members

- Static Public Attributes inherited from BleInterface
static const int MtuSize = BLE_ATT_LEN + 3
 BLE MTU size.
 
- Static Protected Member Functions inherited from BleInterface
static void cbDisconnect (uint16_t conn_handle, uint8_t reason)
 
static void cbConnect (uint16_t conn_handle)
 

Detailed Description

Interface for communication via BLE UART

Definition at line 31 of file ptvBleInterface.h.

Constructor & Destructor Documentation

◆ PtvBleInterface()

PtvBleInterface::PtvBleInterface ( )
inline

Default c-tor.

Definition at line 56 of file ptvBleInterface.h.

References clrBuffer().

Member Function Documentation

◆ clrBuffer()

void PtvBleInterface::clrBuffer ( )
inlineprotected

Clear internal receive buffer.

Definition at line 72 of file ptvBleInterface.h.

References pos, and rcvBuffer.

Referenced by clrReceived(), poll(), and PtvBleInterface().

◆ clrReceived()

void PtvBleInterface::clrReceived ( )
inline

Clear anything received so far.

Definition at line 65 of file ptvBleInterface.h.

References clrBuffer(), and command.

Referenced by enable().

◆ getReceived()

int PtvBleInterface::getReceived ( String &  cmd)

Must be called periodically to check for received commands

Parameters
cmd
Returns
1 if a new command was received, else 0

Definition at line 45 of file ptvBleInterface.cpp.

References command, and poll().

Referenced by loopConnected().

◆ poll()

void PtvBleInterface::poll ( void  )
protected

Periodically called to poll BLE connection for received data chunks / commands. Commands / data chunks must be
terminated. Chunk length is limited by buffer size.

Definition at line 62 of file ptvBleInterface.cpp.

References BleInterface::bleuart, clrBuffer(), command, BleInterface::isConnected(), pos, and rcvBuffer.

Referenced by getReceived().

◆ sendChunked()

void PtvBleInterface::sendChunked ( String &  msg)

Transmit one message as multiple chunks via BLE

Parameters
msgString with message ready to send including line end

Definition at line 99 of file ptvBleInterface.cpp.

References CHUNK_DELAY_MS, CHUNK_SZ, LOGL, and BleInterface::sendData().

Referenced by sendLongMsg(), sendMetaMsg(), and sendShortMsg().

◆ sendLongMsg()

void PtvBleInterface::sendLongMsg ( const SensorData data)

Send a message using the long PTVSOAR message format

NOTE: For devices with BLE speed limitations this format is not useful

Parameters
datasensor data record to be sent

Definition at line 163 of file ptvBleInterface.cpp.

References PtvBleInterface::SensorData::absHpa, PtvBleInterface::SensorData::batPct, PtvBleInterface::SensorData::batVolt, PtvBleInterface::SensorData::diffPa, PtvBleInterface::SensorData::humPct, PtvBleInterface::SensorData::isCharging, LOGL, SEND_VOLT, sendChunked(), and PtvBleInterface::SensorData::tempC.

Referenced by loopConnected().

◆ sendMetaMsg()

void PtvBleInterface::sendMetaMsg ( const String &  mna,
const String &  mmo,
const String &  msn 
)

Send a PTVSOAR meta data message

Parameters
mnaManufacturer name
mmoDevice model
msnSevice serial number

Definition at line 147 of file ptvBleInterface.cpp.

References sendChunked().

Referenced by loopConnected().

◆ sendShortMsg()

void PtvBleInterface::sendShortMsg ( const SensorData data)

Send a message using the short PTV format

Length tailored to 2x20 bytes for BLE 4.1 and earlier

Parameters
datasensor data record to be sent

Definition at line 233 of file ptvBleInterface.cpp.

References PtvBleInterface::SensorData::absHpa, PtvBleInterface::SensorData::batPct, PtvBleInterface::SensorData::batVolt, PtvBleInterface::SensorData::diffPa, PtvBleInterface::SensorData::humPct, PtvBleInterface::SensorData::isCharging, SEND_VOLT, sendChunked(), and PtvBleInterface::SensorData::tempC.

Referenced by loopConnected().

Member Data Documentation

◆ command

String PtvBleInterface::command
protected

Holds last received text line / command.

Definition at line 74 of file ptvBleInterface.h.

Referenced by clrReceived(), getReceived(), and poll().

◆ pos

unsigned int PtvBleInterface::pos
protected

Write position for next byte.

Definition at line 78 of file ptvBleInterface.h.

Referenced by clrBuffer(), and poll().

◆ rcvBuffer

char PtvBleInterface::rcvBuffer[FIFO_SZ]
protected

Receive data buffer, same size as UART FIFO.

Definition at line 76 of file ptvBleInterface.h.

Referenced by clrBuffer(), and poll().


The documentation for this class was generated from the following files: