Comms CCF
This is a simple communication layer based on COBS, CBOR and FNV-1A
Loading...
Searching...
No Matches
Ccf< Config > Class Template Reference

Public Types

using TxFrame = CircularBuffer<uint8_t, Config.txBufSize, Config.maxPktSize>::Frame

Public Member Functions

bool receiveCharacter (uint8_t byte)
 Push RX'ed character to RX queue. Safe to call from interrupt context.
bool charactersToSend (std::optional< TxFrame > &frame)
 Get TX queue size. Safe to call from interrupt context.
template<typename Rpc>
bool poll (const Rpc &rpc)
 Process incoming packets to dispatch e.g. RPC.
bool send (Channels channel, std::span< uint8_t > &data)
 Send data over a channel.
std::optional< size_t > logToBuffer (std::span< uint8_t > &span, LogLevel level, uint8_t module, const char *fmt,...)
 Logs to a buffer, returning logged size. Threadsafe because it doesn't send the message, just formats it to the buffer.
std::optional< size_t > vLogToBuffer (std::span< uint8_t > &span, LogLevel level, uint8_t module, const char *fmt, va_list args)
 Same as logToBuffer but taking va_list instead of ... varargs.
std::optional< size_t > log (LogLevel level, uint8_t module, const char *fmt,...)
 Sends a logs message.

Member Function Documentation

◆ log()

template<CcfConfig Config>
std::optional< size_t > Ccf< Config >::log ( LogLevel level,
uint8_t module,
const char * fmt,
... )
inline

Sends a logs message.

Note
Not threadsafe, use a mutex – in particular don't call from inside RPC functions either!

Log some data. Returns the number of bytes logged (all the bytes not just the formatted string), or nullopt if failed to log.

See also
DEFERRED_FORMATTING
Todo
Optionally just send the format string pointer (if it is in .rodata) and the client can read it from the ELF file (or download it separately)

◆ logToBuffer()

template<CcfConfig Config>
std::optional< size_t > Ccf< Config >::logToBuffer ( std::span< uint8_t > & span,
LogLevel level,
uint8_t module,
const char * fmt,
... )
inline

Logs to a buffer, returning logged size. Threadsafe because it doesn't send the message, just formats it to the buffer.

Log some data to the buffer, but don't send it yet. Handy for using in interrupts or other reentrant contexts (e.g. using it to log from inside an RPC call). Returns the number of bytes written to the buffer (all the bytes not just the formatted string), or nullopt if it failed to log.

Once it is safe, call send(Channels::Log, span & dataInBuf) on the formatted data. This function changes the span to point to the unused region of the buffer, once done (if it successfully logged, otherwise it leaves it in place).

See also
DEFERRED_FORMATTING
Todo
Optionally just send the format string pointer (if it is in .rodata) and the client can read it from the ELF file (or download it separately)

◆ poll()

template<CcfConfig Config>
template<typename Rpc>
bool Ccf< Config >::poll ( const Rpc & rpc)
inline

Process incoming packets to dispatch e.g. RPC.

Note
Not threadsafe, only call from one thread
Not safe to call from an interrupt context

Process any incoming packets. Returns true if there is an output in response.

Use an external synchronisation mechanism to call this after a null byte has been received. (It just won't have anything to do until then.)

Todo
Just using checksumless zero-length packets to indicate error for now.
Todo
Dispatch on channel
Todo
Just using checksumless zero-length packets to indicate error for now.
Todo
Just using checksumless zero-length packets to indicate error for now.

◆ receiveCharacter()

template<CcfConfig Config>
bool Ccf< Config >::receiveCharacter ( uint8_t byte)
inline

Push RX'ed character to RX queue. Safe to call from interrupt context.

Note
Not threadsafe, only call from a single communications channel's interrupt callback.

If you want to use multiple communications channels multiplexed, you could use separate SPSC queues feeding into this queue.

Call this with any characters received on the transport. It returns true if it is time to call poll.

◆ send()

template<CcfConfig Config>
bool Ccf< Config >::send ( Channels channel,
std::span< uint8_t > & data )
inline

Send data over a channel.

Note
Not threadsafe, use a mutex.

Put some messaget to be sent, returns true if it has succeeded (and therefore you should call the function to send messages from the queue).

Todo
Maybe could be re-entrant/support adding from ISR without locking by exchanging the ISR data buffer with the data not yet notified, then putting the data not yet notified back after. This would make it only not threadsafe for normal tasks which might get switched out between each-other

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