tvm
|
CRT communication session management class. Assumes the following properties provided by the underlying transport: More...
#include <session.h>
Public Types | |
typedef void(* | MessageReceivedFunc) (void *context, MessageType message_type, FrameBuffer *buf) |
Callback invoked when a full message is received. More... | |
Public Member Functions | |
Session (Framer *framer, FrameBuffer *receive_buffer, MessageReceivedFunc message_received_func, void *message_received_func_context) | |
tvm_crt_error_t | Initialize (uint8_t initial_session_nonce) |
Send a session terminate message, usually done at startup to interrupt a hanging remote. More... | |
tvm_crt_error_t | TerminateSession () |
Terminate any previously-established session. More... | |
tvm_crt_error_t | StartSession () |
Start a new session regardless of state. Sends kStartSessionMessage. More... | |
WriteStream * | Receiver () |
Obtain a WriteStream implementation for use by the framing layer. More... | |
tvm_crt_error_t | SendMessage (MessageType message_type, const uint8_t *message_data, size_t message_size_bytes) |
Send a full message including header, payload, and CRC footer. More... | |
tvm_crt_error_t | StartMessage (MessageType message_type, size_t message_size_bytes) |
Send the framing and session layer headers. More... | |
tvm_crt_error_t | SendBodyChunk (const uint8_t *chunk_data, size_t chunk_size_bytes) |
Send a part of the message body. More... | |
tvm_crt_error_t | FinishMessage () |
Finish sending the message by sending the framing layer footer. More... | |
bool | IsEstablished () const |
Returns true if the session is in the established state. More... | |
void | ClearReceiveBuffer () |
Clear the receive buffer and prepare to receive next message. More... | |
Static Public Attributes | |
static constexpr const uint8_t | kInvalidNonce = 0 |
An invalid nonce value that typically indicates an unknown nonce. More... | |
static constexpr const uint8_t | kVersion = 0x01 |
A version number used to check compatibility of the remote session implementation. More... | |
CRT communication session management class. Assumes the following properties provided by the underlying transport:
Specifically, designed for use with UARTs. Will probably work over semihosting, USB, and TCP; will probably not work reliably enough over UDP.
typedef void(* tvm::runtime::micro_rpc::Session::MessageReceivedFunc) (void *context, MessageType message_type, FrameBuffer *buf) |
Callback invoked when a full message is received.
This function is called in the following situations:
context | The value of message_received_func_context passed to the constructor. |
message_type | The type of session message received. Currently, this is always either kNormal or kLog. |
buf | When message_type is not kStartSessionMessage, a FrameBuffer whose read cursor is at the first byte of the message payload. Otherwise, NULL. |
|
inline |
void tvm::runtime::micro_rpc::Session::ClearReceiveBuffer | ( | ) |
Clear the receive buffer and prepare to receive next message.
Call this function after MessageReceivedFunc is invoked. Any SessionReceiver::Write() calls made will return errors until this function is called to prevent them from corrupting the valid message in the receive buffer.
tvm_crt_error_t tvm::runtime::micro_rpc::Session::FinishMessage | ( | ) |
Finish sending the message by sending the framing layer footer.
tvm_crt_error_t tvm::runtime::micro_rpc::Session::Initialize | ( | uint8_t | initial_session_nonce | ) |
Send a session terminate message, usually done at startup to interrupt a hanging remote.
initial_session_nonce | Initial nonce that should be used on the first session start message. Callers should ensure this is different across device resets. |
|
inline |
Returns true if the session is in the established state.
|
inline |
Obtain a WriteStream implementation for use by the framing layer.
tvm_crt_error_t tvm::runtime::micro_rpc::Session::SendBodyChunk | ( | const uint8_t * | chunk_data, |
size_t | chunk_size_bytes | ||
) |
Send a part of the message body.
This function allows messages to be sent in pieces.
chunk_data | The data contained in this message body chunk. |
chunk_size_bytes | The number of valid bytes in chunk_data. |
tvm_crt_error_t tvm::runtime::micro_rpc::Session::SendMessage | ( | MessageType | message_type, |
const uint8_t * | message_data, | ||
size_t | message_size_bytes | ||
) |
Send a full message including header, payload, and CRC footer.
message_type | One of MessageType; distinguishes the type of traffic at the session layer. |
message_data | The data contained in the message. |
message_size_bytes | The number of valid bytes in message_data. |
tvm_crt_error_t tvm::runtime::micro_rpc::Session::StartMessage | ( | MessageType | message_type, |
size_t | message_size_bytes | ||
) |
Send the framing and session layer headers.
This function allows messages to be sent in pieces.
message_type | One of MessageType; distinguishes the type of traffic at the session layer. |
message_size_bytes | The size of the message body, in bytes. Excludes the framing and session layer headers. |
tvm_crt_error_t tvm::runtime::micro_rpc::Session::StartSession | ( | ) |
Start a new session regardless of state. Sends kStartSessionMessage.
Generally speaking, this function should be called once per device reset by exactly one side in the system. No traffic can flow until this function is called.
tvm_crt_error_t tvm::runtime::micro_rpc::Session::TerminateSession | ( | ) |
Terminate any previously-established session.
|
staticconstexpr |
An invalid nonce value that typically indicates an unknown nonce.
|
staticconstexpr |
A version number used to check compatibility of the remote session implementation.