EV3UartGenerator  prerel
Functions | Variables
EV3UartGenerator::Framing Namespace Reference

Functions

int8_t frame_sys_message (uint8_t *dest, Magics::SYS sys_type)
 
int8_t frame_cmd_type_message (uint8_t *dest, const uint8_t type)
 
int8_t frame_cmd_modes_message (uint8_t *dest, const uint8_t modes, const uint8_t modes_available)
 
int8_t frame_cmd_speed_message (uint8_t *dest, const uint32_t speed)
 
int8_t frame_cmd_select_message (uint8_t *dest, const uint8_t mode)
 
int8_t frame_cmd_write_message (uint8_t *dest, const uint8_t *data, const uint8_t len)
 
int8_t frame_info_message_name (uint8_t *dest, const uint8_t mode, const char *name)
 
int8_t frame_info_message_span (uint8_t *dest, const uint8_t mode, Magics::INFO_SPAN span_type, const float lower, const float upper)
 
int8_t frame_info_message_symbol (uint8_t *dest, const uint8_t mode, const char *symbol)
 
int8_t 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 frame_data_message (uint8_t *dest, const uint8_t mode, const uint8_t *data, const uint8_t len)
 
uint8_t checksum (const uint8_t *buf, const uint8_t len)
 
uint8_t insert_padding (uint8_t *dest, uint8_t len)
 
constexpr uint8_t log2 (uint8_t val)
 
constexpr uint8_t length_code (uint8_t len)
 

Variables

constexpr uint8_t 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. More...
 
constexpr uint8_t PAYLOAD_SENSOR_TO_EV3_MAX { 0x20 }
 Maximum size of any payload sent in the EV3 UART sensor protocol, in bytes, to the EV3. More...
 
constexpr uint8_t PAYLOAD_EV3_TO_SENSOR_MAX { 0x18 }
 Maximum size of any payload sent in the EV3 UART sensor protocol, in bytes, from the EV3 to the sensor. More...
 
constexpr uint8_t PAYLOAD_MIN { 0x01 }
 Minimum size of any payload sent in the EV3 UART sensor protocol, regardless of direction, in bytes. More...
 
constexpr uint8_t 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. More...
 

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.

Referenced by frame_cmd_modes_message(), frame_cmd_select_message(), frame_cmd_speed_message(), frame_cmd_type_message(), frame_cmd_write_message(), frame_data_message(), frame_info_message_format(), frame_info_message_name(), frame_info_message_span(), and frame_info_message_symbol().

◆ 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)

Definition at line 33 of file framing.cpp.

References checksum(), EV3UartGenerator::Magics::CMD_BASE, length_code(), and EV3UartGenerator::Magics::MODES.

Referenced by main().

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 checksum(), EV3UartGenerator::Magics::CMD_BASE, length_code(), and EV3UartGenerator::Magics::SELECT.

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 checksum(), EV3UartGenerator::Magics::CMD_BASE, EV3UartGenerator::SimpleEndian::htole32(), length_code(), and EV3UartGenerator::Magics::SPEED.

Referenced by main().

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 checksum(), EV3UartGenerator::Magics::CMD_BASE, length_code(), and EV3UartGenerator::Magics::TYPE.

Referenced by main().

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 [1, 32]
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 checksum(), EV3UartGenerator::Magics::CMD_BASE, insert_padding(), length_code(), PAYLOAD_EV3_TO_SENSOR_MAX, PAYLOAD_MIN, and EV3UartGenerator::Magics::WRITE.

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 [1, 32]
Returns
length of framed message (written to the buffer), if positive.
Return values
-1on error (length overrun)

Definition at line 184 of file framing.cpp.

References checksum(), EV3UartGenerator::Magics::DATA_BASE, insert_padding(), length_code(), PAYLOAD_MIN, and PAYLOAD_SENSOR_TO_EV3_MAX.

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]
Sr32 [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)

Definition at line 167 of file framing.cpp.

References checksum(), EV3UartGenerator::Magics::INFO_BASE, and length_code().

Referenced by main().

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 [1 to 32 ASCII byte characters in length]
Returns
length of framed message (written to the buffer), if positive.
Return values
-1on error (length overrun / underrun / name == nullptr)

Definition at line 87 of file framing.cpp.

References checksum(), EV3UartGenerator::Magics::INFO_BASE, insert_padding(), length_code(), PAYLOAD_MIN, and PAYLOAD_SENSOR_TO_EV3_MAX.

Referenced by main().

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.

Definition at line 109 of file framing.cpp.

References checksum(), EV3UartGenerator::SimpleEndian::htole32(), EV3UartGenerator::Magics::INFO_BASE, and length_code().

Referenced by main().

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 [1 to 8 ASCII bytes in length]
Returns
length of framed message (written to the buffer), if positive.
Return values
-1on error (length overrun / underrun / symbol == nullptr)

Definition at line 142 of file framing.cpp.

References checksum(), EV3UartGenerator::Magics::INFO_BASE, length_code(), PAYLOAD_MIN, and SYMBOL_MAX.

Referenced by main().

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::Magics::SYS_BASE.

Referenced by main().

◆ 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 [1, 32]
Returns
number of padding bytes written

Definition at line 211 of file framing.cpp.

References log2().

Referenced by frame_cmd_write_message(), frame_data_message(), and frame_info_message_name().

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 [1, 32]
Returns
value to be OR'd into the message type byte to represent the length of the payload in the message.

Definition at line 244 of file framing.hpp.

References log2().

Referenced by frame_cmd_modes_message(), frame_cmd_select_message(), frame_cmd_speed_message(), frame_cmd_type_message(), frame_cmd_write_message(), frame_data_message(), frame_info_message_format(), frame_info_message_name(), frame_info_message_span(), and frame_info_message_symbol().

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 231 of file framing.hpp.

Referenced by insert_padding(), and length_code().

Variable Documentation

◆ BUFFER_MIN

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.

Definition at line 39 of file framing.hpp.

◆ PAYLOAD_EV3_TO_SENSOR_MAX

constexpr uint8_t EV3UartGenerator::Framing::PAYLOAD_EV3_TO_SENSOR_MAX { 0x18 }

Maximum size of any payload sent in the EV3 UART sensor protocol, in bytes, from the EV3 to the sensor.

Definition at line 41 of file framing.hpp.

Referenced by frame_cmd_write_message().

◆ PAYLOAD_MIN

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.

Definition at line 42 of file framing.hpp.

Referenced by frame_cmd_write_message(), frame_data_message(), frame_info_message_name(), and frame_info_message_symbol().

◆ PAYLOAD_SENSOR_TO_EV3_MAX

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.

Definition at line 40 of file framing.hpp.

Referenced by frame_data_message(), and frame_info_message_name().

◆ SYMBOL_MAX

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.

Definition at line 43 of file framing.hpp.

Referenced by frame_info_message_symbol().