|
Comms CCF
This is a simple communication layer based on COBS, CBOR and FNV-1A
|
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. | |
|
inline |
Sends a logs message.
Log some data. Returns the number of bytes logged (all the bytes not just the formatted string), or nullopt if failed to log.
|
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).
|
inline |
Process incoming packets to dispatch e.g. RPC.
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.)
Push RX'ed character to RX queue. Safe to call from interrupt context.
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.
|
inline |
Send data over a channel.
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).