EV3UartGenerator
/home/shenghao/eclipse-workspace/EV3UartGenerator/framing.hpp File Reference
#include <magics.hpp>
Include dependency graph for framing.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int8_t EV3UartGenerator::Framing::frame_sys_message (uint8_t *dest, Magics::SYS sys_type)
 
int8_t EV3UartGenerator::Framing::frame_cmd_type_message (uint8_t *dest, const uint8_t type)
 
int8_t EV3UartGenerator::Framing::frame_cmd_modes_message (uint8_t *dest, const uint8_t modes, const uint8_t modes_available)
 
int8_t EV3UartGenerator::Framing::frame_cmd_speed_message (uint8_t *dest, const uint32_t speed)
 
int8_t EV3UartGenerator::Framing::frame_cmd_select_message (uint8_t *dest, const uint8_t mode)
 
int8_t EV3UartGenerator::Framing::frame_cmd_write_message (uint8_t *dest, const uint8_t *data, const uint8_t len)
 
int8_t EV3UartGenerator::Framing::frame_info_message_name (uint8_t *dest, const uint8_t mode, const char *name)
 
int8_t EV3UartGenerator::Framing::frame_info_message_span (uint8_t *dest, const uint8_t mode, Magics::INFO_SPAN span_type, const float lower, const float upper)
 
int8_t EV3UartGenerator::Framing::frame_info_message_symbol (uint8_t *dest, const uint8_t mode, const char *symbol)
 
int8_t EV3UartGenerator::Framing::frame_info_message_format (uint8_t *dest, const uint8_t mode, const uint8_t elems, Magics::INFO_DTYPE data_type, const uint8_t width, const uint8_t decimals)
 
int8_t EV3UartGenerator::Framing::frame_data_message (uint8_t *dest, const uint8_t mode, const uint8_t *data, const uint8_t len)
 
uint8_t EV3UartGenerator::Framing::checksum (const uint8_t *buf, const uint8_t len)
 
constexpr uint8_t EV3UartGenerator::Framing::log2 (uint8_t val)
 
constexpr uint8_t EV3UartGenerator::Framing::length_code (uint8_t len)
 
uint8_t EV3UartGenerator::Framing::insert_padding (uint8_t *dest, uint8_t len)
 

Variables

constexpr uint8_t EV3UartGenerator::Framing::BUFFER_MIN { 0x23 }
 Minimum size of the buffer (in bytes) that the user has to provide to each of the framing functions, to avoid any chance of a buffer overflow.
 
constexpr uint8_t EV3UartGenerator::Framing::PAYLOAD_SENSOR_TO_EV3_MAX { 0x20 }
 Maximum size of any payload sent in the EV3 UART sensor protocol, in bytes, to the EV3.
 
constexpr uint8_t EV3UartGenerator::Framing::PAYLOAD_EV3_TO_SENSOR_MAX { 0x20 }
 Maximum size of any payload sent in the EV3 UART sensor protocol, in bytes, from the EV3 to the sensor.
 
constexpr uint8_t EV3UartGenerator::Framing::PAYLOAD_MIN { 0x01 }
 Minimum size of any payload sent in the EV3 UART sensor protocol, regardless of direction, in bytes.
 
constexpr uint8_t EV3UartGenerator::Framing::SYMBOL_MAX { 0x08 }
 Maximum length of the string representation (ASCII) of any symbol referencing a the SI unit used to represent the data output from a sensor, in a particular mode.
 

Detailed Description

Functions that help to create buffers of data that can be sent directly to the EV3.

See LICENSE for more details

Definition in file framing.hpp.

Function Documentation

◆ checksum()

uint8_t EV3UartGenerator::Framing::checksum ( const uint8_t *  buf,
const uint8_t  len 
)

Calculates the checksum for an EV3 data message.

Parameters
bufsource buffer
lenlength of data message in the source buffer
Returns
checksum of len bytes of data in the source buffer

Definition at line 203 of file framing.cpp.

References EV3UartGenerator::Framing::checksum().

Referenced by EV3UartGenerator::Framing::checksum().

Here is the call graph for this function:

◆ frame_cmd_modes_message()

int8_t EV3UartGenerator::Framing::frame_cmd_modes_message ( uint8_t *  dest,
const uint8_t  modes,
const uint8_t  modes_visible 
)

Frame an EV3 command message, containing sensor mode information.

For sensor mode set upper bounds, an upper bound of n implies that modes n - 1, n - 2, n - 3 ... 0 are contained in the set of modes bounded by the upper bound.

Parameters
destdestination buffer
modesupper bound of sensor modes in sensor mode set [0, 7]
modes_visibleupper bound of sensor modes in the set of sensor modes visible [0, 7] to the user
Returns
length of framed message (written to the buffer), if positive.
Return values
-1on error (not used)
Note
Only the three least significant mode number bits are considered. No out-of-range values will be passed to the EV3.

Definition at line 33 of file framing.cpp.

References EV3UartGenerator::Framing::frame_cmd_modes_message().

Referenced by EV3UartGenerator::Framing::frame_cmd_modes_message().

Here is the call graph for this function:

◆ frame_cmd_select_message()

int8_t EV3UartGenerator::Framing::frame_cmd_select_message ( uint8_t *  dest,
const uint8_t  mode 
)

Frame an EV3 command message, selecting a particular mode of the sensor

Parameters
destdestination buffer
modemode to select [0, 7]
Returns
length of framed message (written to the buffer), if positive.
Return values
-1on error (not used)

Definition at line 58 of file framing.cpp.

References EV3UartGenerator::Framing::frame_cmd_select_message().

Referenced by EV3UartGenerator::Framing::frame_cmd_select_message().

Here is the call graph for this function:

◆ frame_cmd_speed_message()

int8_t EV3UartGenerator::Framing::frame_cmd_speed_message ( uint8_t *  dest,
const uint32_t  speed 
)

Frame an EV3 commmand message, containing UART baudrate information.

Parameters
destdestination buffer
speedbaudrate requested / maximum baudrate supported by the device.
Returns
length of framed message (written to the buffer), if positive.
Return values
-1on error (not used)

Definition at line 45 of file framing.cpp.

References EV3UartGenerator::Framing::frame_cmd_speed_message().

Referenced by EV3UartGenerator::Framing::frame_cmd_speed_message().

Here is the call graph for this function:

◆ frame_cmd_type_message()

int8_t EV3UartGenerator::Framing::frame_cmd_type_message ( uint8_t *  dest,
const uint8_t  type 
)

Frame an EV3 command message, containing sensor type information

Parameters
destdestination buffer
typesensor type index [0, 255]
Returns
length of framed message (written to the buffer), if positive.
Return values
-1on error (unused)

Definition at line 23 of file framing.cpp.

References EV3UartGenerator::Framing::frame_cmd_type_message().

Referenced by EV3UartGenerator::Framing::frame_cmd_type_message().

Here is the call graph for this function:

◆ frame_cmd_write_message()

int8_t EV3UartGenerator::Framing::frame_cmd_write_message ( uint8_t *  dest,
const uint8_t *  data,
const uint8_t  len 
)

Frame an EV3 command message, writing arbitrary data to the sensor.

Parameters
destdestination buffer
datadata to write to the sensor
lenlength of array of data to write to the sensor [PAYLOAD_MIN, PAYLOAD_EV3_TO_SENSOR_MAX]
Returns
length of framed message (written to the buffer), if positive.
Return values
-1on error (length overrun / underrun)

Definition at line 68 of file framing.cpp.

References EV3UartGenerator::Framing::frame_cmd_write_message(), EV3UartGenerator::Framing::PAYLOAD_EV3_TO_SENSOR_MAX, and EV3UartGenerator::Framing::PAYLOAD_MIN.

Referenced by EV3UartGenerator::Framing::frame_cmd_write_message().

Here is the call graph for this function:

◆ frame_data_message()

int8_t EV3UartGenerator::Framing::frame_data_message ( uint8_t *  dest,
const uint8_t  mode,
const uint8_t *  data,
const uint8_t  len 
)

Frame an EV3 data message, containing information from a sensor to be sent to an EV3, for the sensor running in a particular mode

Parameters
destdestination buffer
modemode index [0, 7]
datadata to be sent
lenlength of data to be sent, with length in range [PAYLOAD_MIN, PAYLOAD_SENSOR_TO_EV3_MAX]
Returns
length of framed message (written to the buffer), if positive.
Return values
-1on error (length overrun)
Note
Only the three least significant mode number bits are considered. No out-of-range values will be passed to the EV3.

Definition at line 184 of file framing.cpp.

References EV3UartGenerator::Framing::frame_data_message(), EV3UartGenerator::Framing::PAYLOAD_MIN, and EV3UartGenerator::Framing::PAYLOAD_SENSOR_TO_EV3_MAX.

Referenced by EV3UartGenerator::Framing::frame_data_message().

Here is the call graph for this function:

◆ frame_info_message_format()

int8_t EV3UartGenerator::Framing::frame_info_message_format ( uint8_t *  dest,
const uint8_t  mode,
const uint8_t  elems,
Magics::INFO_DTYPE  data_type,
const uint8_t  width,
const uint8_t  decimals 
)

Frame an EV3 information message, informing the EV3 of the type and number of data elements contained in the data messages coming from the sensor, as well as the number of decimal places and width to use when displaying readings for the sensor, for a particular mode of the sensor.

Parameters
destdestination buffer
modemode index [0, 7]
elemsnumber of data elements in a DATA message, limited to:
Data type Number of data elements
S8 [1, 32]
S16 [1, 16]
S32 [1, 8]
F32 [1, 8]
data_typetype of data elements
widthnumber of characters (including decimal separator) used to display readings from the sensor [0, 15]
decimalsnumber of characters after the decimal place used to display readings from the sensor [0, 15]
Returns
length of framed message (written to the buffer), if positive.
Return values
-1on error (not used)
Note
Only the three least significant mode number bits are considered, and only the four least significant bits of the width and decimals parameter are considered. No out-of-range values will be passed to the EV3.

Definition at line 167 of file framing.cpp.

References EV3UartGenerator::Framing::frame_info_message_format().

Referenced by EV3UartGenerator::Framing::frame_info_message_format().

Here is the call graph for this function:

◆ frame_info_message_name()

int8_t EV3UartGenerator::Framing::frame_info_message_name ( uint8_t *  dest,
const uint8_t  mode,
const char *  name 
)

Frame an EV3 information message, informing the EV3 of the mode name for a particular mode of the sensor.

Parameters
destdestination buffer
modemode index [0, 7]
namemode name, a character sequence encoded in 1-byte ASCII representation, with terminating null, with length (not inclusive of null byte) in range [PAYLOAD_MIN, PAYLOAD_SENSOR_TO_EV3_MAX]
Returns
length of framed message (written to the buffer), if positive.
Return values
-1on error (length overrun / underrun / name == nullptr)
Note
Only the three least significant mode number bits are considered. No out-of-range values will be passed to the EV3.

Definition at line 87 of file framing.cpp.

References EV3UartGenerator::Framing::frame_info_message_name(), EV3UartGenerator::Framing::PAYLOAD_MIN, and EV3UartGenerator::Framing::PAYLOAD_SENSOR_TO_EV3_MAX.

Referenced by EV3UartGenerator::Framing::frame_info_message_name().

Here is the call graph for this function:

◆ frame_info_message_span()

int8_t EV3UartGenerator::Framing::frame_info_message_span ( uint8_t *  dest,
const uint8_t  mode,
Magics::INFO_SPAN  span_type,
const float  lower,
const float  upper 
)

Frame an EV3 information message, informing the EV3 of the span of values returned from this sensor, for different units of readings from the sensor, for a particular mode of the sensor

This message is optional, and may be omitted during the initialization process, where mode information is sent from the sensor to the EV3.

Parameters
destdestination buffer
modemode index [0, 7]
span_typetype of span for which information is to be sent for
lowerlower bound of the span
upperupper bound of the span
Returns
length of framed message (written to the buffer), if positive.
Return values
-1on error (unused)
Warning
this function MUST NOT be used in environments where the representation of single precision floating point numbers does not follow the IEEE standard.
Note
Only the three least significant mode number bits are considered. No out-of-range values will be passed to the EV3.

Definition at line 109 of file framing.cpp.

References EV3UartGenerator::Framing::frame_info_message_span().

Referenced by EV3UartGenerator::Framing::frame_info_message_span().

Here is the call graph for this function:

◆ frame_info_message_symbol()

int8_t EV3UartGenerator::Framing::frame_info_message_symbol ( uint8_t *  dest,
const uint8_t  mode,
const char *  symbol 
)

Frame an EV3 information message, informing the EV3 of the text representation of the symbol (unit) used to represent the SI unit that can be used to quantify readings from the sensor, for readings from the sensor coming from a particular mode index.

Parameters
destdestination buffer
modemode index [0 - 7]
symbolsymbol text representation string, a string of characters encoded in 1-byte ASCII with terminating null byte, with length (not including terminating null) in range [PAYLOAD_MIN, PAYLOAD_SENSOR_TO_EV3_MAX]
Returns
length of framed message (written to the buffer), if positive.
Return values
-1on error (length overrun / underrun / symbol == nullptr)
Note
Only the three least significant mode number bits are considered. No out-of-range values will be passed to the EV3.

Definition at line 142 of file framing.cpp.

References EV3UartGenerator::Framing::frame_info_message_symbol(), EV3UartGenerator::Framing::PAYLOAD_MIN, and EV3UartGenerator::Framing::SYMBOL_MAX.

Referenced by EV3UartGenerator::Framing::frame_info_message_symbol().

Here is the call graph for this function:

◆ frame_sys_message()

int8_t EV3UartGenerator::Framing::frame_sys_message ( uint8_t *  dest,
Magics::SYS  sys_type 
)

Frame an EV3 system message.

Parameters
destdestination buffer
sys_typetype of the system message
Returns
length of framed message (written to the buffer), if positive.
Return values
-1on error (unused)

Definition at line 17 of file framing.cpp.

References EV3UartGenerator::Framing::frame_sys_message().

Referenced by EV3UartGenerator::Framing::frame_sys_message().

Here is the call graph for this function:

◆ insert_padding()

uint8_t EV3UartGenerator::Framing::insert_padding ( uint8_t *  dest,
uint8_t  len 
)

Inserts padding bytes at the end of a payload segment, so that the size of the payload segment is a non-negative power of two.

Parameters
destaddress of the byte right after the end of the payload segment
lenlength of payload segment [PAYLOAD_MIN, PAYLOAD_SENSOR_TO_EV3_MAX]
Returns
number of padding bytes written

Definition at line 211 of file framing.cpp.

References EV3UartGenerator::Framing::insert_padding(), and EV3UartGenerator::Framing::log2().

Referenced by EV3UartGenerator::Framing::insert_padding().

Here is the call graph for this function:

◆ length_code()

constexpr uint8_t EV3UartGenerator::Framing::length_code ( uint8_t  len)

Calculates the value that is to be OR'd into the message type byte to represent the length of the payload in the message.

Parameters
lenlength of the payload [PAYLOAD_MIN, PAYLOAD_SENSOR_TO_EV3_MAX]
Returns
value to be OR'd into the message type byte to represent the length of the payload in the message.

Definition at line 270 of file framing.hpp.

References EV3UartGenerator::Framing::length_code(), and EV3UartGenerator::Framing::log2().

Referenced by EV3UartGenerator::Framing::length_code().

Here is the call graph for this function:

◆ log2()

constexpr uint8_t EV3UartGenerator::Framing::log2 ( uint8_t  val)

Calculates the integer log_2 of a particular unsigned integer value, rounded up.

Parameters
valvalue to calculate log_2 for [1, 255]
Returns
result of log_2 of val rounded up to the next biggest integer.
Warning
undefined for val of 0.

Definition at line 256 of file framing.hpp.

References EV3UartGenerator::Framing::log2().

Referenced by EV3UartGenerator::Framing::insert_padding(), EV3UartGenerator::Framing::length_code(), and EV3UartGenerator::Framing::log2().

Here is the call graph for this function: