JM9 XRCU Board 0.2.0a
Libraries API Reference
Loading...
Searching...
No Matches
Serial_unpacker Class Reference

JM9 UART packet unpacker. More...

#include <Serial_unpacker.h>

Inheritance diagram for Serial_unpacker:
JM9_unpacker

Public Member Functions

 Serial_unpacker (HardwareSerial &init_uart, const uint8_t init_start_byte)
 Creates an unpacker.
 
 ~Serial_unpacker ()
 Destroys this unpacker.
 
bool update ()
 Checks if a new packet is received.
 
const uint8_t * get_packet_ptr ()
 Gets the pointer to the received data.
 
uint8_t get_packet_len ()
 Gets the length of the received data.
 
HardwareSerialget_uart ()
 Gets the UART object to read packets from.
 

Detailed Description

JM9 UART packet unpacker.

Author
YH Choi @ JM9

Constructor & Destructor Documentation

◆ Serial_unpacker()

Serial_unpacker::Serial_unpacker ( HardwareSerial & init_uart,
const uint8_t init_start_byte )

Creates an unpacker.

Parameters
init_uartthe UART object to read packets from
init_start_bytethe start byte of each packet

◆ ~Serial_unpacker()

Serial_unpacker::~Serial_unpacker ( )

Destroys this unpacker.

Releases the used memory.

Member Function Documentation

◆ get_packet_len()

uint8_t Serial_unpacker::get_packet_len ( )

Gets the length of the received data.

Only call this method after update() returns true.
To be used with get_packet_ptr().

Returns
the length of the received data
See also
update()
get_packet_ptr()

◆ get_packet_ptr()

const uint8_t * Serial_unpacker::get_packet_ptr ( )

Gets the pointer to the received data.

The byte array pointed by this pointer contains data bytes only.
Only call this method after update() returns true,
otherwise the packet is incomplete and unusable.
To be used with get_packet_len().

Returns
the pointer to the read-only received data
See also
update()
get_packet_len()

◆ get_uart()

HardwareSerial & Serial_unpacker::get_uart ( )

Gets the UART object to read packets from.

Returns
the UART object to read packets from

◆ update()

bool Serial_unpacker::update ( )

Checks if a new packet is received.

Returns
true if a new packet is completely received, checksumed and accepted, false otherwise

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