ReduxLib C++ 2025.0.0-beta2
Loading...
Searching...
No Matches
redux::canand::utils Namespace Reference

Functions

constexpr uint8_t getDeviceType (uint32_t fullId)
 
constexpr uint8_t getApiPage (uint32_t fullId)
 
constexpr uint8_t getApiIndex (uint32_t fullId)
 
constexpr uint8_t getDeviceId (uint32_t fullId)
 
constexpr bool idMatches (uint32_t idToCompare, uint8_t deviceType, uint8_t devId)
 
constexpr uint32_t constructMessageId (uint8_t deviceType, uint16_t devId, uint8_t msgId)
 
constexpr std::chrono::duration< double, std::ratio< 1LL, 1LL > > toChronoSeconds (units::second_t seconds)
 
constexpr void memcpyLE (void *dst, void *src, size_t len)
 
constexpr uint8_t extractU8 (uint64_t data, uint8_t width, uint8_t offset)
 
constexpr uint16_t extractU16 (uint64_t data, uint8_t width, uint8_t offset)
 
constexpr uint32_t extractU32 (uint64_t data, uint8_t width, uint8_t offset)
 
constexpr uint64_t extractU64 (uint64_t data, uint8_t width, uint8_t offset)
 
constexpr int8_t extractI8 (uint64_t data, uint8_t width, uint8_t offset)
 
constexpr int16_t extractI16 (uint64_t data, uint8_t width, uint8_t offset)
 
constexpr int32_t extractI32 (uint64_t data, uint8_t width, uint8_t offset)
 
constexpr int64_t extractI64 (uint64_t data, uint8_t width, uint8_t offset)
 
constexpr float extractF24 (uint64_t data, uint8_t offset)
 
constexpr float extractF32 (uint64_t data, uint8_t offset)
 
constexpr double extractF64 (uint64_t data)
 
constexpr bool extractBool (uint64_t data, uint8_t offset)
 
constexpr uint64_t packUInt (uint64_t data, uint8_t width, uint8_t offset)
 
constexpr uint64_t packInt (int64_t data, uint8_t width, uint8_t offset)
 
constexpr uint64_t packF24 (float data, uint8_t offset)
 
constexpr uint64_t packF32 (float data, uint8_t offset)
 
constexpr uint64_t packF64 (double data, uint8_t offset)
 
constexpr uint64_t packBool (bool data, uint8_t offset)
 
template<typename E >
constexpr std::underlying_type< E >::type to_underlying (E e) noexcept
 

Detailed Description

Series of utility functions for CAN messaging and bit manipulation.

For more information, see https://docs.wpilib.org/en/stable/docs/software/can-devices/can-addressing.html

Function Documentation

◆ constructMessageId()

constexpr uint32_t redux::canand::utils::constructMessageId ( uint8_t  deviceType,
uint16_t  devId,
uint8_t  msgId 
)
constexpr

Construct a CAN message id to send to a Redux device.

Parameters
deviceTypethe device id code
devIdCAN device id
msgIdAPI message id
Returns
a 29-bit full CAN message id

◆ extractBool()

constexpr bool redux::canand::utils::extractBool ( uint64_t  data,
uint8_t  offset 
)
constexpr

Extracts a boolean from a bitfield.

Parameters
databitfield to extract from
offsetthe offset of the boolean bit in the bitfield
Returns
extracted boolean value.

◆ extractF24()

constexpr float redux::canand::utils::extractF24 ( uint64_t  data,
uint8_t  offset 
)
constexpr

Extracts a 24-bit float.

24-bit floats have 1 sign bit, 8 exponent bits, and 15 mantissa bits.

Parameters
databitfield to extract from
offsetbit offset of the float to extract
Returns
extracted float

◆ extractF32()

constexpr float redux::canand::utils::extractF32 ( uint64_t  data,
uint8_t  offset 
)
constexpr

Extracts a 32-bit single-precision float.

Parameters
databitfield to extract from
offsetbit offset of the float to extract
Returns
extracted float

◆ extractF64()

constexpr double redux::canand::utils::extractF64 ( uint64_t  data)
constexpr

Extracts a 64-bit double-precision float.

Parameters
databitfield to extract from
Returns
extracted float

◆ extractI16()

constexpr int16_t redux::canand::utils::extractI16 ( uint64_t  data,
uint8_t  width,
uint8_t  offset 
)
constexpr

Extracts a signed integer up to 16 bits wide, performing a sign extension if necessary.

Parameters
databitfield to extract from
widthwidth of integer in bits. Values larger than 16 are undefined behavior.
offsetbit offset of the integer to extract
Returns
extracted integer

◆ extractI32()

constexpr int32_t redux::canand::utils::extractI32 ( uint64_t  data,
uint8_t  width,
uint8_t  offset 
)
constexpr

Extracts a signed integer up to 32 bits wide, performing a sign extension if necessary.

Parameters
databitfield to extract from
widthwidth of integer in bits. Values larger than 32 are undefined behavior.
offsetbit offset of the integer to extract
Returns
extracted integer

◆ extractI64()

constexpr int64_t redux::canand::utils::extractI64 ( uint64_t  data,
uint8_t  width,
uint8_t  offset 
)
constexpr

Extracts a signed integer up to 64 bits wide, performing a sign extension if necessary.

Parameters
databitfield to extract from
widthwidth of integer in bits. Values larger than 64 are undefined behavior.
offsetbit offset of the integer to extract
Returns
extracted integer

◆ extractI8()

constexpr int8_t redux::canand::utils::extractI8 ( uint64_t  data,
uint8_t  width,
uint8_t  offset 
)
constexpr

Extracts a signed integer up to 8 bits wide, performing a sign extension if necessary.

Parameters
databitfield to extract from
widthwidth of integer in bits. Values larger than 8 are undefined behavior.
offsetbit offset of the integer to extract
Returns
extracted integer

◆ extractU16()

constexpr uint16_t redux::canand::utils::extractU16 ( uint64_t  data,
uint8_t  width,
uint8_t  offset 
)
constexpr

Extracts an unsigned integer up to 16 bits wide.

Parameters
databitfield to extract from
widthwidth of integer in bits. Values larger than 16 are undefined behavior.
offsetbit offset of the integer to extract
Returns
extracted integer

◆ extractU32()

constexpr uint32_t redux::canand::utils::extractU32 ( uint64_t  data,
uint8_t  width,
uint8_t  offset 
)
constexpr

Extracts an unsigned integer up to 32 bits wide.

Parameters
databitfield to extract from
widthwidth of integer in bits. Values larger than 32 are undefined behavior.
offsetbit offset of the integer to extract
Returns
extracted integer

◆ extractU64()

constexpr uint64_t redux::canand::utils::extractU64 ( uint64_t  data,
uint8_t  width,
uint8_t  offset 
)
constexpr

Extracts an unsigned integer up to 64 bits wide.

Parameters
databitfield to extract from
widthwidth of integer in bits. Values larger than 64 are undefined behavior.
offsetbit offset of the integer to extract
Returns
extracted integer

◆ extractU8()

constexpr uint8_t redux::canand::utils::extractU8 ( uint64_t  data,
uint8_t  width,
uint8_t  offset 
)
constexpr

Extracts an unsigned integer up to 8 bits wide.

Parameters
databitfield to extract from
widthwidth of integer in bits. Values larger than 8 are undefined behavior.
offsetbit offset of the integer to extract
Returns
extracted integer

◆ getApiIndex()

constexpr uint8_t redux::canand::utils::getApiIndex ( uint32_t  fullId)
constexpr

Extracts the 8-bit API index from a full message id. Instead of doing a 6bit/4bit split for api class/api index, we use 2bit/8bit.

Parameters
fullIdthe full 29-bit message id
Returns
the product id code

◆ getApiPage()

constexpr uint8_t redux::canand::utils::getApiPage ( uint32_t  fullId)
constexpr

Extracts 2-bit product id/API class from a full message id. Instead of doing a 6bit/4bit split for api class/api index, we use 2bit/8bit.

Parameters
fullIdthe full 29-bit message id
Returns
the product id code

◆ getDeviceId()

constexpr uint8_t redux::canand::utils::getDeviceId ( uint32_t  fullId)
constexpr

Extracts 6-bit device id from a full message id This is the "CAN id" that end users will see and care about.

Parameters
fullIdthe full 29-bit message id
Returns
the device CAN id

◆ getDeviceType()

constexpr uint8_t redux::canand::utils::getDeviceType ( uint32_t  fullId)
constexpr

Extracts 5-bit device type code from a full message id

Parameters
fullIdthe full 29-bit message id
Returns
the device type code

◆ idMatches()

constexpr bool redux::canand::utils::idMatches ( uint32_t  idToCompare,
uint8_t  deviceType,
uint8_t  devId 
)
constexpr

Checks if a full CAN id will match against device type, product id, and device id We use this to determine if a message is intended for a specific device.

Parameters
idToComparefull 29-bit id
deviceTypedevice id code
devIddevice id
Returns
whether the parameters matches the message id

◆ memcpyLE()

constexpr void redux::canand::utils::memcpyLE ( void *  dst,
void *  src,
size_t  len 
)
constexpr

Converts a byte buffer to a little endian buffer.

Parameters
dstdestination ptr
srcsource ptr
lenthe length of the data in bytes. If less than 8, the unused bit-space will be zeros.

◆ packBool()

constexpr uint64_t redux::canand::utils::packBool ( bool  data,
uint8_t  offset 
)
constexpr

Packs a boolean as a single bit into a 64-bit field.

Parameters
datathe boolean value
offsetthe 0-indexed offset of the bit in the bitfield
Returns
packed bitfield that can be ORed with other fields to construct a full bitfield

◆ packF24()

constexpr uint64_t redux::canand::utils::packF24 ( float  data,
uint8_t  offset 
)
constexpr

Packs a float into a 24-bit field. This is accomplished by ignoring the least significant 8 bits of the mantissa.

Parameters
datathe float to pack
offsetthe 0-indexed offset of the float in the bitfield
Returns
packed bitfield that can be ORed with other fields to construct a full bitfield

◆ packF32()

constexpr uint64_t redux::canand::utils::packF32 ( float  data,
uint8_t  offset 
)
constexpr

Packs a float into a 32-bit field.

Parameters
datathe float to pack
offsetthe 0-indexed offset of the float in the bitfield
Returns
packed bitfield that can be ORed with other fields to construct a full bitfield

◆ packF64()

constexpr uint64_t redux::canand::utils::packF64 ( double  data,
uint8_t  offset 
)
constexpr

Packs a double into a 64-bit field.

Parameters
datathe double to pack
offsetthe 0-indexed offset of the double in the bitfield
Returns
packed bitfield that can be ORed with other fields to construct a full bitfield

◆ packInt()

constexpr uint64_t redux::canand::utils::packInt ( int64_t  data,
uint8_t  width,
uint8_t  offset 
)
constexpr

Packs a signed integer of variable length into a bitfield as twos complement.

Parameters
datathe signed integer to pack
widththe width of the signed integer
offsetthe 0-indexed offset of the integer in the bitfield
Returns
packed bitfield that can be ORed with other fields to construct a full bitfield

◆ packUInt()

constexpr uint64_t redux::canand::utils::packUInt ( uint64_t  data,
uint8_t  width,
uint8_t  offset 
)
constexpr

Packs an unsigned integer of variable length into a bitfield.

Parameters
datathe unsigned integer to pack
widththe width of the unsigned integer
offsetthe 0-indexed offset of the integer in the bitfield
Returns
packed bitfield that can be ORed with other fields to construct a full bitfield

◆ to_underlying()

template<typename E >
constexpr std::underlying_type< E >::type redux::canand::utils::to_underlying ( e)
constexprnoexcept

Converts an enum to an underlying type

Parameters
evalue to convert
Returns
underlying type

◆ toChronoSeconds()

constexpr std::chrono::duration< double, std::ratio< 1LL, 1LL > > redux::canand::utils::toChronoSeconds ( units::second_t  seconds)
constexpr

Converts seconds from the units library to seconds in std::chrono::duration.

Useful for condition variables.

Parameters
secondsin units::second_t terms
Returns
seconds in std::chrono::duration terms