phyphox BLE
Plot your Arduino's data in the phyphox app and control the board from the phone
Loading...
Searching...
No Matches
phyphox::Server Class Reference

#include <Server.h>

Inheritance diagram for phyphox::Server:

Classes

class  SerializerSource
 The serializer's byte view, so the transfer can read it. More...
 

Public Member Functions

 Server (Transport &transport)
 
 ~Server ()
 
void setClock (uint32_t(*nowMs)())
 Millisecond clock for the transfer's retry timing (the façade passes millis).
 
void setDeviceName (const char *name)
 
void setMtu (uint16_t payload)
 
void setConnectionParameters (uint16_t minInterval, uint16_t maxInterval, uint16_t latency, uint16_t timeout)
 
void addExperiment (const PhyphoxBleExperiment &exp)
 Serve the description (copies it; builds the part table).
 
void setCustomXml (const uint8_t *xml, uint32_t len)
 Serve user-supplied XML instead; the 1.x GATT layout (cddf1002 data, cddf1003 config with five floats, events) is created so hand-written documents keep working.
 
bool start ()
 Request the start.
 
bool ensureStarted ()
 Bring the transport up now if start() was requested and it is not up yet.
 
void poll ()
 drives the transfer; calls transport_.poll()
 
bool started () const
 
bool startFailed () const
 The transport refused to come up (no module answered, a service could not be created).
 
bool writeFloats (const float *values, uint8_t count)
 1…5 floats → data characteristic
 
bool writeBytes (const uint8_t *bytes, uint16_t len)
 raw array (≤ MTU payload)
 
ChannelStore & channels ()
 
void setChannelCallbacks (uint8_t channel, ChangeCallback onChange, PressCallback onPress)
 Attach callbacks to a channel at any time, before or after the experiment was added.
 
const ExperimentEvent & lastEvent () const
 
void setConfigHandler (void(*h)())
 
void setEventHandler (void(*h)())
 
const uint8_t * legacyConfig () const
 User-XML mode: the raw last value of the 1.x config characteristic.
 
const TransferSession & transfer () const
 
bool customXml () const
 
uint16_t mtu () const
 
void printXml (Sink &sink)
 The document as served: the user's own bytes in user-XML mode, else the generated one.
 
void ensureDocument ()
 
const ExperimentStore & store () const
 
const ServerStats & stats () const
 
uint16_t connections () const
 
bool subscribed () const
 
void onConnect () override
 
void onDisconnect () override
 
void onSubscribe (CharId id, bool enabled) override
 The central enabled/disabled notifications on id (only CH_EXPERIMENT and CH_DATA are notifiable).
 
void onWrite (CharId id, const uint8_t *data, uint16_t len) override
 The central wrote len bytes to id.
 
void onNotifyStatus (CharId id, bool accepted) override
 Asynchronous verdict on the last notify() for stacks that report it later.
 
void pump () override
 Drive the transfer: send what is due.
 
- Public Member Functions inherited from phyphox::TransportListener
virtual ~TransportListener ()
 

Constructor & Destructor Documentation

◆ Server()

phyphox::Server::Server ( Transport &  transport)
inline

◆ ~Server()

phyphox::Server::~Server ( )

Member Function Documentation

◆ addExperiment()

void phyphox::Server::addExperiment ( const PhyphoxBleExperiment &  exp)

Serve the description (copies it; builds the part table).

May be called after start(): the new document is served from the next transfer on.

◆ channels()

ChannelStore & phyphox::Server::channels ( )
inline

◆ connections()

uint16_t phyphox::Server::connections ( ) const
inline

◆ customXml()

bool phyphox::Server::customXml ( ) const
inline

◆ ensureDocument()

void phyphox::Server::ensureDocument ( )

◆ ensureStarted()

bool phyphox::Server::ensureStarted ( )

Bring the transport up now if start() was requested and it is not up yet.

◆ lastEvent()

const ExperimentEvent & phyphox::Server::lastEvent ( ) const
inline

◆ legacyConfig()

const uint8_t * phyphox::Server::legacyConfig ( ) const
inline

User-XML mode: the raw last value of the 1.x config characteristic.

◆ mtu()

uint16_t phyphox::Server::mtu ( ) const
inline

◆ onConnect()

void phyphox::Server::onConnect ( )
overridevirtual

◆ onDisconnect()

void phyphox::Server::onDisconnect ( )
overridevirtual

◆ onNotifyStatus()

void phyphox::Server::onNotifyStatus ( CharId  id,
bool  accepted 
)
overridevirtual

Asynchronous verdict on the last notify() for stacks that report it later.

Transports whose notify() is synchronous never call this.

Implements phyphox::TransportListener.

◆ onSubscribe()

void phyphox::Server::onSubscribe ( CharId  id,
bool  enabled 
)
overridevirtual

The central enabled/disabled notifications on id (only CH_EXPERIMENT and CH_DATA are notifiable).

Implements phyphox::TransportListener.

◆ onWrite()

void phyphox::Server::onWrite ( CharId  id,
const uint8_t *  data,
uint16_t  len 
)
overridevirtual

The central wrote len bytes to id.

Implements phyphox::TransportListener.

◆ poll()

void phyphox::Server::poll ( )

drives the transfer; calls transport_.poll()

◆ printXml()

void phyphox::Server::printXml ( Sink &  sink)

The document as served: the user's own bytes in user-XML mode, else the generated one.

◆ pump()

void phyphox::Server::pump ( )
inlineoverridevirtual

Drive the transfer: send what is due.

Called by the core from poll(), or by a transport that runs the transfer in its own task (ESP32, see drivesTransfer()). Never called from inside a stack callback.

Implements phyphox::TransportListener.

◆ setChannelCallbacks()

void phyphox::Server::setChannelCallbacks ( uint8_t  channel,
ChangeCallback  onChange,
PressCallback  onPress 
)

Attach callbacks to a channel at any time, before or after the experiment was added.

◆ setClock()

void phyphox::Server::setClock ( uint32_t(*)()  nowMs)
inline

Millisecond clock for the transfer's retry timing (the façade passes millis).

◆ setConfigHandler()

void phyphox::Server::setConfigHandler ( void(*)()  h)
inline

◆ setConnectionParameters()

void phyphox::Server::setConnectionParameters ( uint16_t  minInterval,
uint16_t  maxInterval,
uint16_t  latency,
uint16_t  timeout 
)

◆ setCustomXml()

void phyphox::Server::setCustomXml ( const uint8_t *  xml,
uint32_t  len 
)

Serve user-supplied XML instead; the 1.x GATT layout (cddf1002 data, cddf1003 config with five floats, events) is created so hand-written documents keep working.

◆ setDeviceName()

void phyphox::Server::setDeviceName ( const char *  name)
inline

◆ setEventHandler()

void phyphox::Server::setEventHandler ( void(*)()  h)
inline

◆ setMtu()

void phyphox::Server::setMtu ( uint16_t  payload)

◆ start()

bool phyphox::Server::start ( )

Request the start.

The transport is brought up LAZILY, at the first poll() or write(): the 1.x examples call start() before addExperiment(), and the characteristic layout depends on the experiment, so the stack must not be configured before setup() is done.

◆ started()

bool phyphox::Server::started ( ) const
inline

◆ startFailed()

bool phyphox::Server::startFailed ( ) const
inline

The transport refused to come up (no module answered, a service could not be created).

Tried once; poll() and write() do nothing afterwards. PhyphoxBLE::printErrors() reports it.

◆ stats()

const ServerStats & phyphox::Server::stats ( ) const
inline

◆ store()

const ExperimentStore & phyphox::Server::store ( ) const
inline

◆ subscribed()

bool phyphox::Server::subscribed ( ) const
inline

◆ transfer()

const TransferSession & phyphox::Server::transfer ( ) const
inline

◆ writeBytes()

bool phyphox::Server::writeBytes ( const uint8_t *  bytes,
uint16_t  len 
)

raw array (≤ MTU payload)

◆ writeFloats()

bool phyphox::Server::writeFloats ( const float *  values,
uint8_t  count 
)

1…5 floats → data characteristic


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