MIP_SDK  v3.0.0-425-g6df21bd
MicroStrain Communications Library for embedded systems
Namespaces | Classes | Typedefs | Functions
microstrain Namespace Reference

Namespaces

 C
 
 connections
 
 detail
 
 extras
 
 serialization
 
 strings
 

Classes

struct  BitfieldMemberIthruJ
 A class which represents part of a bitfield (see BitfieldMemberN) More...
 
struct  BitfieldMemberItoJ
 A class which represents part of a bitfield (see BitfieldMemberN) More...
 
struct  BitfieldMemberN
 A class which represents part of a bitfield. More...
 
class  Connection
 Represents a type of connection. More...
 
class  Id
 Representes an ID number ranging from 1..N including N. More...
 
class  Index
 Represents an index ranging from 0..N excluding N. More...
 
struct  IntegerWithBits
 Helper type to get an integer of at least N bits in size. More...
 
struct  IntegerWithBytes
 Helper type to get an integer of at least N bytes in size. More...
 
struct  IntegerWithBytes< 1 >
 
struct  IntegerWithBytes< 2 >
 
struct  IntegerWithBytes< 3 >
 
struct  IntegerWithBytes< 4 >
 
struct  IntegerWithBytes< 5 >
 
struct  IntegerWithBytes< 6 >
 
struct  IntegerWithBytes< 7 >
 
struct  IntegerWithBytes< 8 >
 
class  SaturatingInt
 A class representing an integer that saturates instead of overflowing. More...
 
class  Serializer
 Serializes or deserializes data to/from a byte buffer. More...
 
class  SerializerBase
 Represents a view of a buffer of bytes of known capacity. More...
 
struct  Span
 Implementation of std::span from C++20. More...
 
struct  Span< T, DYNAMIC_EXTENT >
 

Typedefs

using EmbeddedTimestamp = C::microstrain_embedded_timestamp
 
using EmbeddedTimeout = C::microstrain_embedded_timeout
 
using BigEndianSerializer = Serializer< serialization::Endian::big >
 
using LittleEndianSerializer = Serializer< serialization::Endian::little >
 

Functions

template<typename T >
constexpr T bitmaskFirstN (unsigned int nbits)
 Creates a bitmask with 1s in the first N bits, i.e. bits [0..N). More...
 
template<typename T >
constexpr T bitmaskN (unsigned int bitI, unsigned int nbits)
 Creates a bitmask with N '1' bits starting at bit I. More...
 
template<typename T >
constexpr T bitmaskItoJ (unsigned int bitI, unsigned int bitJ)
 Creates a bitmask with bits [bitI..bitJ) set to 1 (excludes bit J). More...
 
template<typename T >
constexpr T bitmaskIthruJ (unsigned int bitI, unsigned int bitJ)
 Creates a bitmask with bits [bitI..bitJ] set to 1 (includes bit J). More...
 
template<typename RegType >
constexpr bool testBit (RegType reg, unsigned int bit)
 Checks if a specific bit in a value is set. More...
 
template<typename RegType >
constexpr void setBit (RegType &reg, unsigned int bit, bool value=true)
 Sets a specific bit in a variable to a specified value. More...
 
template<typename RegType >
constexpr RegType getBitsN (RegType reg, unsigned int bitI, unsigned int nbits)
 Extracts a bitfield from a variable value. More...
 
template<typename RegType >
constexpr RegType getBitsItoJ (RegType reg, unsigned int bitI, unsigned int bitJ)
 Extracts a bitfield from a variable value. More...
 
template<typename RegType >
constexpr RegType getBitsIthruJ (RegType reg, unsigned int bitI, unsigned int bitJ)
 Extracts a bitfield from a variable value. More...
 
template<typename RegType >
constexpr void setBitsN (RegType &reg, unsigned int bitI, unsigned int nbits)
 Sets a series of consecutive bits in a variable to 1. More...
 
template<typename RegType >
constexpr void setBitsItoJ (RegType &reg, unsigned int bitI, unsigned int bitJ)
 Sets a series of consecutive bits in a variable to 1. More...
 
template<typename RegType >
constexpr void setBitsIthruJ (RegType &reg, unsigned int bitI, unsigned int bitJ)
 Sets a series of consecutive bits in a variable to 1. More...
 
template<typename RegType >
constexpr void clearBitsN (RegType &reg, unsigned int bitI, unsigned int nbits)
 Sets a series of consecutive bits in a variable to 0. More...
 
template<typename RegType >
constexpr void clearBitsItoJ (RegType &reg, unsigned int bitI, unsigned int bitJ)
 Sets a series of consecutive bits in a variable to 0. More...
 
template<typename RegType >
constexpr void clearBitsIthruJ (RegType &reg, unsigned int bitI, unsigned int bitJ)
 Sets a series of consecutive bits in a variable to 0. More...
 
template<typename RegType , typename ValType >
constexpr void setBitsN (RegType &reg, unsigned int bitI, unsigned int nbits, ValType value)
 Writes a value to a specific set of bits in a variable as if it were a bitfield. More...
 
template<typename RegType , typename ValType >
constexpr void setBitsItoJ (RegType &reg, unsigned int bitI, unsigned int bitJ, ValType value)
 Writes a value to a specific set of bits in a variable as if it were a bitfield. More...
 
template<typename RegType , typename ValType >
constexpr void modifyBitsIthruJ (RegType &reg, unsigned int bitI, unsigned int bitJ, ValType value)
 Writes a value to a specific set of bits in a variable as if it were a bitfield. More...
 
template<class T >
constexpr T add_sat (T x, T y) noexcept
 
template<class T >
constexpr T sub_sat (T x, T y) noexcept
 
template<class T , class U >
constexpr T saturate_cast (U x) noexcept
 Convert an integral value to a different integral type while preventing overflow. More...
 
template<class T , class U >
constexpr void assign_sat (T &destination, U value)
 Assign an integral value to a destination variable, clamping its value to the range of the destination type. More...
 
template<class T , class U >
constexpr T & accum_sat (T &counter, U amount)
 Add a value to an accumulator and prevent it from overflowing. More...
 
template<class T , class U >
constexpr T & reduce_sat (T &counter, U amount)
 Subtract a value from an accumulator and prevent it from overflowing. More...
 
constexpr bool operator== (Id l, Index r)
 
constexpr bool operator== (Index l, Id r)
 
template<class Container >
auto * indexOrNull (Container &container, Index index)
 
template<class Container , typename Value >
auto indexOrDefault (Container &container, Index index, Value default_)
 
template<serialization::Endian E, class T >
std::enable_if< std::is_arithmetic< T >::value, size_t >::type insert (Serializer< E > &buffer, T value)
 Inserts a numeric value to a Serializer. More...
 
template<serialization::Endian E, class T >
std::enable_if< std::is_arithmetic< T >::value, size_t >::type extract (Serializer< E > &buffer, T &value)
 Reads a numeric value from a Serializer. More...
 
template<serialization::Endian E, class T >
std::enable_if< std::is_enum< T >::value, size_t >::type insert (Serializer< E > &buffer, T value)
 Writes an enum to a Serializer. For this to work properly, the enum must have its underlying type specified, i.e., like enum Foo : uint32_t { /*...*‍/ }; More...
 
template<serialization::Endian E, class T >
std::enable_if< std::is_enum< T >::value, size_t >::type extract (Serializer< E > &buffer, T &value)
 Reads an enum from a Serializer. For this to work properly, the enum must have its underlying type specified, i.e., like enum Foo : uint32_t { /*...*‍/ }; More...
 
template<serialization::Endian E, class T , decltype &::insert = nullptr>
std::enable_if< std::is_class< T >::value, size_t >::type insert (microstrain::Serializer< E > &serializer, const T &object)
 Writes a class object to a Serializer. This overload is available to any class which defines a method insert. It shall take a Serializer reference as the sole parameter. More...
 
template<serialization::Endian E, class T , decltype &::extract = nullptr>
std::enable_if< std::is_class< T >::value, size_t >::type extract (microstrain::Serializer< E > &serializer, T &object)
 Reads a class object from a Serializer. This overload is available to any class which defines a method extract. It shall take a Serializer reference as the sole parameter. More...
 
template<serialization::Endian E, class T >
size_t insert (Serializer< E > &serializer, const T *values, size_t count)
 Writes an array to a Serializer. More...
 
template<serialization::Endian E, class T >
size_t extract (Serializer< E > &serializer, T *values, size_t count)
 Reads an array from a Serializer. More...
 
template<serialization::Endian E, class T >
size_t insert (Serializer< E > &serializer, microstrain::Span< const T > values)
 Writes an array to a Serializer via a Span. More...
 
template<serialization::Endian E, class T >
size_t extract (Serializer< E > &serializer, microstrain::Span< const T > values)
 Reads an array from a Serializer via a Span. More...
 
template<serialization::Endian E, class T , size_t N>
size_t insert (Serializer< E > &serializer, const T(&values)[N])
 Writes a fixed-size array to a Serializer. More...
 
template<serialization::Endian E, class T , size_t N>
size_t extract (Serializer< E > &serializer, T(&values)[N])
 Reads a fixed-size array from a Serializer. More...
 
template<serialization::Endian E, class T , size_t N>
size_t insert (Serializer< E > &serializer, const std::array< T, N > &values)
 Writes a std::array to a Serializer. More...
 
template<serialization::Endian E, class T , size_t N>
size_t extract (Serializer< E > &serializer, const std::array< T, N > &values)
 Reads a std::array from a Serializer. More...
 
template<serialization::Endian E, typename T0 , typename T1 , typename... Ts>
size_t insert (Serializer< E > &serializer, const T0 &value0, const T1 &value1, Ts... values)
 Writes multiple values to a Serializer. More...
 
template<serialization::Endian E, typename T0 , typename T1 , typename... Ts>
size_t extract (Serializer< E > &serializer, T0 &value0, T1 &value1, Ts &... values)
 Reads multiple values from a Serializer. More...
 
template<serialization::Endian E, class T >
bool insert (const T &value, uint8_t *buffer, size_t buffer_length, size_t offset=0, bool exact_size=false)
 Serializes a value to a raw byte buffer. More...
 
template<serialization::Endian E, class T >
bool extract (T &value, const uint8_t *buffer, size_t buffer_length, size_t offset=0, bool exact_size=false)
 Deserializes a value from a raw byte buffer. More...
 
template<serialization::Endian E, class T >
bool insert (T value, microstrain::Span< uint8_t > buffer, size_t offset=0, bool exact_size=false)
 Serializes a value to a raw byte buffer (span version). More...
 
template<serialization::Endian E, class T >
bool extract (T &value, microstrain::Span< const uint8_t > buffer, size_t offset=0, bool exact_size=false)
 Deserializes a value from a raw byte buffer (span version). More...
 

Typedef Documentation

◆ EmbeddedTimeout

◆ EmbeddedTimestamp

Function Documentation

◆ accum_sat()

template<class T , class U >
constexpr T& microstrain::accum_sat ( T &  counter,
amount 
)
constexpr

Add a value to an accumulator and prevent it from overflowing.

Template Parameters
TType of the accumulator. Let the compiler deduce this.
UType of the value being added. Let the compiler deduce this.
Parameters
[out]counterAccumulator variable to modify.
[in]valueValue to add to counter.
Returns
A reference the the accumulator.

◆ add_sat()

template<class T >
constexpr T microstrain::add_sat ( x,
y 
)
constexprnoexcept

◆ assign_sat()

template<class T , class U >
constexpr void microstrain::assign_sat ( T &  destination,
value 
)
constexpr

Assign an integral value to a destination variable, clamping its value to the range of the destination type.

Template Parameters
TDestination type. Let the compiler deduce this.
USource type. Let the compiler deduce this.
Parameters
[out]destinationVariable in which to store the value.
[in]valueValue to store in destination.

◆ bitmaskFirstN()

template<typename T >
constexpr T microstrain::bitmaskFirstN ( unsigned int  nbits)
constexpr

Creates a bitmask with 1s in the first N bits, i.e. bits [0..N).

Template Parameters
TAn unsigned integral type.
Parameters
nbitsThe number of 1 bits starting at location 0. Must not exceed the number of bits in T (e.g. nbits <= 32 for T=uint32_t).
Returns
the bitmask

◆ bitmaskIthruJ()

template<typename T >
constexpr T microstrain::bitmaskIthruJ ( unsigned int  bitI,
unsigned int  bitJ 
)
constexpr

Creates a bitmask with bits [bitI..bitJ] set to 1 (includes bit J).

If bitI == bitJ, then the result will have exactly one bit set.

Template Parameters
TAn unsigned integral type.
Parameters
bitIThe 0-based index of the first 1 bit. Must not exceed the number of bits in T.
bitJThe 0-based index of the the last 1 bit. Must be greater than or equal to bitI and cannot exceed the number of bits in T.
Returns
the bitmask

◆ bitmaskItoJ()

template<typename T >
constexpr T microstrain::bitmaskItoJ ( unsigned int  bitI,
unsigned int  bitJ 
)
constexpr

Creates a bitmask with bits [bitI..bitJ) set to 1 (excludes bit J).

Template Parameters
TAn unsigned integral type.
Parameters
bitIThe 0-based index of the first 1 bit. Must not exceed the number of bits in T.
bitJThe 0-based index of the first 0 bit after the last 1 bit. Must be greater than or equal to bitI and cannot exceed the number of bits in T.
Returns
the bitmask

◆ bitmaskN()

template<typename T >
constexpr T microstrain::bitmaskN ( unsigned int  bitI,
unsigned int  nbits 
)
constexpr

Creates a bitmask with N '1' bits starting at bit I.

If bitI == bitJ, then the result will have exactly one bit set.

Template Parameters
TAn unsigned integral type.
Parameters
bitIThe 0-based index of the first 1 bit. Must be LESS than the number of bits in T (and not equal).
bitJThe 0-based index of the the last 1 bit. Must be greater than or equal to bitI and cannot exceed the number of bits in T.
Returns
the bitmask

◆ clearBitsIthruJ()

template<typename RegType >
constexpr void microstrain::clearBitsIthruJ ( RegType &  reg,
unsigned int  bitI,
unsigned int  bitJ 
)
constexpr

Sets a series of consecutive bits in a variable to 0.

Template Parameters
RegTypeAn unsigned integral type. Let the compiler deduce this.
Parameters
regValue to be modified.
bitIThe 0-based index of the first affected bit.
bitJThe 0-based index of the last affected bit.

◆ clearBitsItoJ()

template<typename RegType >
constexpr void microstrain::clearBitsItoJ ( RegType &  reg,
unsigned int  bitI,
unsigned int  bitJ 
)
constexpr

Sets a series of consecutive bits in a variable to 0.

Template Parameters
RegTypeAn unsigned integral type. Let the compiler deduce this.
Parameters
regValue to be modified.
bitIThe 0-based index of the first affected bit.
bitJThe 0-based index of the bit after the last affected bit.

◆ clearBitsN()

template<typename RegType >
constexpr void microstrain::clearBitsN ( RegType &  reg,
unsigned int  bitI,
unsigned int  nbits 
)
constexpr

Sets a series of consecutive bits in a variable to 0.

Template Parameters
RegTypeAn unsigned integral type. Let the compiler deduce this.
Parameters
regValue to be modified.
bitIThe 0-based index of the first affected bit.
nbitsNumber of consecutive bits to set to '0'.

◆ extract()

template<serialization::Endian E, class T >
std::enable_if<std::is_enum<T>::value, size_t>::type microstrain::extract ( Serializer< E > &  buffer,
T &  value 
)

Reads an enum from a Serializer. For this to work properly, the enum must have its underlying type specified, i.e., like enum Foo : uint32_t { /*...*‍/ };

Template Parameters
EEndianness of buffer. Automatically deduced from the serializer parameter.
TType of the enum. Automatically deduced from the underlying type of the enum.
Parameters
bufferSerializer object pointing to the source buffer.
[out]valueThe value will be stored in this variable.
Returns
The size of T, for consistency.

◆ getBitsIthruJ()

template<typename RegType >
constexpr RegType microstrain::getBitsIthruJ ( RegType  reg,
unsigned int  bitI,
unsigned int  bitJ 
)
constexpr

Extracts a bitfield from a variable value.

Template Parameters
RegTypeAn unsigned integral type. Let the compiler deduce this.
Parameters
regRegister value.
bitIThe 0-based index of the first bit to extract. Must be less than the number of bits in RegType.
bitJThe 0-based index of the last bit to extract. Must be greater than or equal to bitI and less than the number of bits in RegType.
Returns
The value stored in bits [bitI..bitJ] as the same type as reg.

◆ getBitsItoJ()

template<typename RegType >
constexpr RegType microstrain::getBitsItoJ ( RegType  reg,
unsigned int  bitI,
unsigned int  bitJ 
)
constexpr

Extracts a bitfield from a variable value.

Template Parameters
RegTypeAn unsigned integral type. Let the compiler deduce this.
Parameters
regRegister value.
bitIThe 0-based index of the first bit to extract. Must be less than the number of bits in RegType.
bitJThe 0-based index of the bit after last bit to extract. Must be greater than or equal to bitI and cannot exceed the number of bits in RegType.
Returns
The value stored in bits [bitI..bitJ) as the same type as reg.

◆ getBitsN()

template<typename RegType >
constexpr RegType microstrain::getBitsN ( RegType  reg,
unsigned int  bitI,
unsigned int  nbits 
)
constexpr

Extracts a bitfield from a variable value.

Template Parameters
RegTypeAn unsigned integral type. Let the compiler deduce this.
Parameters
regRegister value.
bitIThe 0-based index of the first bit to extract. Must be less than the number of bits in RegType.
nbitsHow many consecutive bits to extract.
Returns
The value stored in bits [bitI..bitI+N) as the same type as reg.

◆ indexOrDefault()

template<class Container , typename Value >
auto microstrain::indexOrDefault ( Container &  container,
Index  index,
Value  default_ 
)

◆ indexOrNull()

template<class Container >
auto* microstrain::indexOrNull ( Container &  container,
Index  index 
)

◆ insert()

template<serialization::Endian E, class T >
std::enable_if<std::is_enum<T>::value, size_t>::type microstrain::insert ( Serializer< E > &  buffer,
value 
)

Writes an enum to a Serializer. For this to work properly, the enum must have its underlying type specified, i.e., like enum Foo : uint32_t { /*...*‍/ };

Template Parameters
EEndianness of buffer. Automatically deduced from the serializer parameter.
TType of the enum. Automatically deduced from the underlying type of the enum.
Parameters
bufferSerializer object pointing to the destination buffer.
valueThe enum value to write to the buffer.
Returns
The size of T, for consistency.

◆ modifyBitsIthruJ()

template<typename RegType , typename ValType >
constexpr void microstrain::modifyBitsIthruJ ( RegType &  reg,
unsigned int  bitI,
unsigned int  bitJ,
ValType  value 
)
constexpr

Writes a value to a specific set of bits in a variable as if it were a bitfield.

Template Parameters
RegTypeAn unsigned integral type. Let the compiler deduce this.
ValTypeAn integral type used for the input value. Let the compiler deduce this.
Parameters
regValue to be modified.
bitIThe 0-based index of the first bit of value in reg.
bitJThe 0-based index of the last bit of value in reg.
valueValue to insert into reg at bit I.

◆ operator==() [1/2]

constexpr bool microstrain::operator== ( Id  l,
Index  r 
)
inlineconstexpr

◆ operator==() [2/2]

constexpr bool microstrain::operator== ( Index  l,
Id  r 
)
inlineconstexpr

◆ reduce_sat()

template<class T , class U >
constexpr T& microstrain::reduce_sat ( T &  counter,
amount 
)
constexpr

Subtract a value from an accumulator and prevent it from overflowing.

Template Parameters
TType of the accumulator. Let the compiler deduce this.
UType of the value being subtracted. Let the compiler deduce this.
Parameters
[out]counterAccumulator variable to modify.
[in]valueValue to subtract from counter.
Returns
A reference the the accumulator.

◆ saturate_cast()

template<class T , class U >
constexpr T microstrain::saturate_cast ( x)
constexprnoexcept

Convert an integral value to a different integral type while preventing overflow.

See https://en.cppreference.com/w/cpp/numeric/saturate_cast

Template Parameters
TResult type.
USource type. Let the compiler deduce this.
Parameters
xValue to cast.
Returns
The value of x, clamped to the valid range of T.

◆ setBit()

template<typename RegType >
constexpr void microstrain::setBit ( RegType &  reg,
unsigned int  bit,
bool  value = true 
)
constexpr

Sets a specific bit in a variable to a specified value.

Template Parameters
RegTypeAn integral type. Let the compiler deduce this.
Parameters
regValue to be modified.
bitThe 0-based index of the bit to modify. Must be less than the number of bits in RegType.
valueSets the bit to this value. Default true.

◆ setBitsIthruJ()

template<typename RegType >
constexpr void microstrain::setBitsIthruJ ( RegType &  reg,
unsigned int  bitI,
unsigned int  bitJ 
)
constexpr

Sets a series of consecutive bits in a variable to 1.

Template Parameters
RegTypeAn unsigned integral type. Let the compiler deduce this.
Parameters
regValue to be modified.
bitIThe 0-based index of the first affected bit.
bitJThe 0-based index of the last affected bit.

◆ setBitsItoJ() [1/2]

template<typename RegType >
constexpr void microstrain::setBitsItoJ ( RegType &  reg,
unsigned int  bitI,
unsigned int  bitJ 
)
constexpr

Sets a series of consecutive bits in a variable to 1.

Template Parameters
RegTypeAn unsigned integral type. Let the compiler deduce this.
Parameters
regValue to be modified.
bitIThe 0-based index of the first affected bit.
bitJThe 0-based index of the bit after the last affected bit.

◆ setBitsItoJ() [2/2]

template<typename RegType , typename ValType >
constexpr void microstrain::setBitsItoJ ( RegType &  reg,
unsigned int  bitI,
unsigned int  bitJ,
ValType  value 
)
constexpr

Writes a value to a specific set of bits in a variable as if it were a bitfield.

Template Parameters
RegTypeAn unsigned integral type. Let the compiler deduce this.
ValTypeAn integral type used for the input value. Let the compiler deduce this.
Parameters
regValue to be modified.
bitIThe 0-based index of the first bit of value in reg.
bitJThe 0-based index of the bit after the last affected bit.
valueValue to insert into reg at bit I.

◆ setBitsN() [1/2]

template<typename RegType >
constexpr void microstrain::setBitsN ( RegType &  reg,
unsigned int  bitI,
unsigned int  nbits 
)
constexpr

Sets a series of consecutive bits in a variable to 1.

Template Parameters
RegTypeAn unsigned integral type. Let the compiler deduce this.
Parameters
regValue to be modified.
bitIThe 0-based index of the first affected bit.
nbitsNumber of consecutive bits to set to '1'.

◆ setBitsN() [2/2]

template<typename RegType , typename ValType >
constexpr void microstrain::setBitsN ( RegType &  reg,
unsigned int  bitI,
unsigned int  nbits,
ValType  value 
)
constexpr

Writes a value to a specific set of bits in a variable as if it were a bitfield.

Template Parameters
RegTypeAn unsigned integral type. Let the compiler deduce this.
ValTypeAn integral type used for the input value. Let the compiler deduce this.
Parameters
regValue to be modified.
bitIThe 0-based index of the first bit of value in reg.
nbitsNumber of consecutive bits used to represent the value in reg.
valueValue to insert into reg at bit I.

◆ sub_sat()

template<class T >
constexpr T microstrain::sub_sat ( x,
y 
)
constexprnoexcept

◆ testBit()

template<typename RegType >
constexpr bool microstrain::testBit ( RegType  reg,
unsigned int  bit 
)
constexpr

Checks if a specific bit in a value is set.

Template Parameters
RegTypeAn integral type. Let the compiler deduce this in most cases.
Parameters
regValue containing the bit to check.
bitThe 0-based index of the bit to check in val. Must be less than the number of bits in RegType.
Returns
True if the bit is set, false otherwise.