EV3UartGenerator
prerel
|
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... | |
uint8_t EV3UartGenerator::Framing::checksum | ( | const uint8_t * | buf, |
const uint8_t | len | ||
) |
Calculates the checksum for an EV3 data message.
buf | source buffer |
len | length of data message in the source buffer |
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().
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.
dest | destination buffer |
modes | upper bound of sensor modes in sensor mode set [0, 7] |
modes_visible | upper bound of sensor modes in the set of sensor modes visible [0, 7] to the user |
-1 | on 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().
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
dest | destination buffer |
mode | mode to select [0, 7] |
-1 | on error (not used) |
Definition at line 58 of file framing.cpp.
References checksum(), EV3UartGenerator::Magics::CMD_BASE, length_code(), and EV3UartGenerator::Magics::SELECT.
int8_t EV3UartGenerator::Framing::frame_cmd_speed_message | ( | uint8_t * | dest, |
const uint32_t | speed | ||
) |
Frame an EV3 commmand message, containing UART baudrate information.
dest | destination buffer |
speed | baudrate requested / maximum baudrate supported by the device. |
-1 | on 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().
int8_t EV3UartGenerator::Framing::frame_cmd_type_message | ( | uint8_t * | dest, |
const uint8_t | type | ||
) |
Frame an EV3 command message, containing sensor type information
dest | destination buffer |
type | sensor type index [0, 255] |
-1 | on 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().
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.
dest | destination buffer |
data | data to write to the sensor |
len | length of array of data to write to the sensor [1, 32] |
-1 | on 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.
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
dest | destination buffer |
mode | mode index [0, 7] |
data | data to be sent |
len | length of data to be sent [1, 32] |
-1 | on 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.
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.
dest | destination buffer | ||||||||||
mode | mode index [0, 7] | ||||||||||
elems | number of data elements in a DATA message, limited to:
| ||||||||||
data_type | type of data elements | ||||||||||
width | number of characters (including decimal separator) used to display readings from the sensor [0, 15] | ||||||||||
decimals | number of characters after the decimal place used to display readings from the sensor [0, 15] |
-1 | on error (not used) |
Definition at line 167 of file framing.cpp.
References checksum(), EV3UartGenerator::Magics::INFO_BASE, and length_code().
Referenced by main().
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.
dest | destination buffer |
mode | mode index [0, 7] |
name | mode name [1 to 32 ASCII byte characters in length] |
-1 | on 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().
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.
dest | destination buffer |
mode | mode index [0, 7] |
span_type | type of span for which information is to be sent for |
lower | lower bound of the span |
upper | upper bound of the span |
-1 | on error (unused) |
Definition at line 109 of file framing.cpp.
References checksum(), EV3UartGenerator::SimpleEndian::htole32(), EV3UartGenerator::Magics::INFO_BASE, and length_code().
Referenced by main().
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.
dest | destination buffer |
mode | mode index [0 - 7] |
symbol | symbol text representation string [1 to 8 ASCII bytes in length] |
-1 | on 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().
int8_t EV3UartGenerator::Framing::frame_sys_message | ( | uint8_t * | dest, |
Magics::SYS | sys_type | ||
) |
Frame an EV3 system message.
dest | destination buffer |
sys_type | type of the system message |
-1 | on error (unused) |
Definition at line 17 of file framing.cpp.
References EV3UartGenerator::Magics::SYS_BASE.
Referenced by main().
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.
dest | address of the byte right after the end of the payload segment |
len | length of payload segment [1, 32] |
Definition at line 211 of file framing.cpp.
References log2().
Referenced by frame_cmd_write_message(), frame_data_message(), and frame_info_message_name().
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.
len | length of the payload [1, 32] |
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().
constexpr uint8_t EV3UartGenerator::Framing::log2 | ( | uint8_t | val | ) |
Calculates the integer log_2 of a particular unsigned integer value, rounded up.
val | value to calculate log_2 for [1, 255] |
val
rounded up to the next biggest integer.val
of 0. Definition at line 231 of file framing.hpp.
Referenced by insert_padding(), and length_code().
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.
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().
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().
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().
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().