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

Namespaces

 C
 
 connections
 
 extras
 
 serialization
 

Classes

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...
 
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 >
 

Enumerations

enum  LogLevel {
  LogLevel::OFF = MICROSTRAIN_LOG_LEVEL_OFF, LogLevel::FATAL = MICROSTRAIN_LOG_LEVEL_FATAL, LogLevel::ERROR = MICROSTRAIN_LOG_LEVEL_ERROR, LogLevel::WARN = MICROSTRAIN_LOG_LEVEL_WARN,
  LogLevel::INFO = MICROSTRAIN_LOG_LEVEL_INFO, LogLevel::DEBUG = MICROSTRAIN_LOG_LEVEL_DEBUG, LogLevel::TRACE = MICROSTRAIN_LOG_LEVEL_TRACE
}
 

Functions

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

◆ BigEndianSerializer

◆ EmbeddedTimeout

◆ EmbeddedTimestamp

◆ LittleEndianSerializer

Enumeration Type Documentation

◆ LogLevel

enum microstrain::LogLevel
strong
Enumerator
OFF 
FATAL 
ERROR 
WARN 
INFO 
DEBUG 
TRACE 

Function Documentation

◆ extract() [1/10]

template<serialization::Endian E, class T , decltype &::extract = nullptr>
std::enable_if<std::is_class<T>::value , size_t>::type microstrain::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.

Example:

class Foo
{
int x, y;
float z;
// E.g. for big endian serialization:
extract(serializer, x, y, z); // Read x, y, and z parameters.
}
// OR, if both big and little serialization are desired:
template<microstrain::Endian E>
void insert(microstrain::Serializer<E>& serializer) {
extract(serializer, x, y, z); // Read x, y, and z parameters.
}
};
Template Parameters
EEndianness of buffer. Automatically deduced from the serializer parameter.
TType of the class. Automatically deduced from the object parameter.
Parameters
serializerSerializer object pointing to the source buffer.
objectThe class to read from the buffer.
Returns
The number of bytes read.

◆ extract() [2/10]

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

Reads a numeric value from a Serializer.

Template Parameters
EEndianness of buffer. Automatically deduced from the serializer parameter.
TType of the value to read. Automatically deduced from the value parameter.
Parameters
bufferSerializer object pointing to the source buffer.
[out]valueThe read value is stored in this variable. Can be a reference to bool, int, uint32_t, float, etc.
Returns
The size of T, for consistency.

◆ extract() [3/10]

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.

◆ extract() [4/10]

template<serialization::Endian E, class T , size_t N>
size_t microstrain::extract ( Serializer< E > &  serializer,
const std::array< T, N > &  values 
)

Reads a std::array from a Serializer.

Template Parameters
EEndianness of buffer. Automatically deduced from the serializer parameter.
TType of array elements. Automatically deduced from the values parameter.
Parameters
serializerSerializer object pointing to the source buffer.
valuesstd::array of values
Returns
The total number of bytes read.

◆ extract() [5/10]

template<serialization::Endian E, class T >
size_t microstrain::extract ( Serializer< E > &  serializer,
microstrain::Span< const T >  values 
)

Reads an array from a Serializer via a Span.

Template Parameters
EEndianness of buffer. Automatically deduced from the serializer parameter.
TType of array elements. Automatically deduced from the values parameter.
Parameters
serializerSerializer object pointing to the source buffer.
valuesSpan containing pointer and count.
Returns
The total number of bytes read.

◆ extract() [6/10]

template<serialization::Endian E, class T >
size_t microstrain::extract ( Serializer< E > &  serializer,
T *  values,
size_t  count 
)

Reads an array from a Serializer.

Template Parameters
EEndianness of buffer. Automatically deduced from the serializer parameter.
TType of array elements. Automatically deduced from the values parameter.
Parameters
serializerSerializer object pointing to the source buffer.
valuesPointer to the first value in the array.
countNumber of elements in the array to read.
Returns
The total number of bytes read.

◆ extract() [7/10]

template<serialization::Endian E, class T , size_t N>
size_t microstrain::extract ( Serializer< E > &  serializer,
T(&)  values[N] 
)

Reads a fixed-size array from a Serializer.

Template Parameters
EEndianness of buffer. Automatically deduced from the serializer parameter.
TType of array elements. Automatically deduced from the values parameter.
Parameters
serializerSerializer object pointing to the source buffer.
valuesC-style array of values
Returns
The total number of bytes read.

◆ extract() [8/10]

template<serialization::Endian E, typename T0 , typename T1 , typename... Ts>
size_t microstrain::extract ( Serializer< E > &  serializer,
T0 &  value0,
T1 &  value1,
Ts &...  values 
)

Reads multiple values from a Serializer.

This function is equivalent to calling extract on each parameter in sequence.

This function can make use of C++17 fold expressions to improve performance by combining the buffer bounds checks when all types are of known size (i.e. numeric types).

Template Parameters
EEndianness of buffer. Automatically deduced from the serializer parameter.
TsTypes of values. Automatically deduced from the values parameters.
Parameters
serializerSerializer object pointing to the destination buffer.
valuesOne or more parameters to be read.
Returns
The total number of bytes read.

◆ extract() [9/10]

template<serialization::Endian E, class T >
bool microstrain::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.

Use this overload to read a single value without needing to manually construct a Serializer object.

Example:

uint8_t buffer[4] = {0x01, 0x02, 0x03, 0x04};
uint32_t value_BE;
uint32_t value_LE;
extract<microstrain::Endian::big>(value_BE, buffer, sizeof(buffer), 0, true);
extract<microstrain::Endian::little>(value_LE, buffer, sizeof(buffer), 0, true);
// value_BE == 0x01020304
// value_LE == 0x04030201
Template Parameters
EEndianness of buffer. Must be manually specified.
TType of value. Automatically deduced from the value parameter.
Parameters
valueParameter to deserialize. This can be any serializable type.
bufferPointer to first element of the byte buffer.
buffer_lengthLength/size of buffer.
offsetStarting offset (default 0).
exact_sizeReturns true only if exactly buffer_length-offset bytes are read. Default false.
Returns
False if the buffer doesn't have enough data.
False if exact_size is true and the number of bytes read plus offset didn't equal buffer_length.
True otherwise.

◆ extract() [10/10]

template<serialization::Endian E, class T >
bool microstrain::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).

Use this overload to read a single value without needing to manually construct a Serializer object.

Template Parameters
EEndianness of buffer. Must be manually specified.
TType of value. Automatically deduced from the value parameter.
Parameters
valueParameter to deserialize. This can be any serializable type.
bufferSource buffer span.
offsetStarting offset (default 0).
exact_sizeReturns true only if exactly buffer.size()-offset bytes are read. Default false.
Returns
False if the buffer doesn't have enough data.
False if exact_size is true and the number of bytes read plus offset didn't equal buffer_length.
True otherwise.

◆ 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() [1/10]

template<serialization::Endian E, class T >
bool microstrain::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.

Use this overload to write a single value without needing to manually construct a Serializer object.

Example:

uint8_t buffer[256];
uint32_t value = 16909060; // 0x01020304
insert<microstrain::Endian::big>(value, buffer, sizeof(buffer), 0, false);
// Buffer = [0x01, 0x02, 0x03, 0x04]
insert<microstrain::Endian::little>(value, buffer, sizeof(buffer), 0, false);
// Buffer = [0x04, 0x03, 0x02, 0x01]
Template Parameters
EEndianness of buffer. Must be manually specified.
TType of value. Automatically deduced from the value parameter.
Parameters
valueParameter to serialize. This can be any serializable type.
bufferPointer to first element of the byte buffer.
buffer_lengthLength/size of buffer.
offsetStarting offset. Default 0.
exact_sizeReturns true only if exactly buffer_length plus offset bytes are written. Default false.
Returns
False if the buffer isn't large enough.
False if exact_size is true and the number of bytes written didn't equal buffer_length.
True otherwise.

◆ insert() [2/10]

template<serialization::Endian E, class T , decltype &::insert = nullptr>
std::enable_if<std::is_class<T>::value , size_t>::type microstrain::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.

Example:

class Foo
{
int x, y;
float z;
// E.g. for big endian serialization:
void insert(microstrain::BigEndianSerializer& serializer) const {
insert(serializer, x, y, z); // Write x, y, and z parameters.
}
// OR, if both big and little serialization are desired:
template<microstrain::Endian E>
void insert(microstrain::Serializer<E>& serializer) const {
insert(serializer, x, y, z); // Write x, y, and z parameters.
}
};
Template Parameters
EEndianness of buffer. Automatically deduced from the serializer parameter.
TType of the class. Automatically deduced from the object parameter.
Parameters
serializerSerializer object pointing to the destination buffer.
objectThe class to write to the buffer.
Returns
The number of bytes written.

◆ insert() [3/10]

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

Inserts a numeric value to a Serializer.

Template Parameters
EEndianness of buffer. Automatically deduced from the serializer parameter.
TType of the value to write. Automatically deduced from the value parameter.
Parameters
bufferSerializer object pointing to the destination buffer.
valueA number to write to the buffer. Can be bool, int, uint32_t, float, etc.
Returns
The size of T, for consistency.

◆ insert() [4/10]

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.

◆ insert() [5/10]

template<serialization::Endian E, class T , size_t N>
size_t microstrain::insert ( Serializer< E > &  serializer,
const std::array< T, N > &  values 
)

Writes a std::array to a Serializer.

Template Parameters
EEndianness of buffer. Automatically deduced from the serializer parameter.
TType of array elements. Automatically deduced from the values parameter.
Parameters
serializerSerializer object pointing to the destination buffer.
valuesstd::array of values
Returns
The total number of bytes written.

◆ insert() [6/10]

template<serialization::Endian E, class T >
size_t microstrain::insert ( Serializer< E > &  serializer,
const T *  values,
size_t  count 
)

Writes an array to a Serializer.

Template Parameters
EEndianness of buffer. Automatically deduced from the serializer parameter.
TType of array elements. Automatically deduced from the values parameter.
Parameters
serializerSerializer object pointing to the destination buffer.
valuesPointer to the first value in the array.
countNumber of elements in the array to write.
Returns
The total number of bytes written.

◆ insert() [7/10]

template<serialization::Endian E, class T , size_t N>
size_t microstrain::insert ( Serializer< E > &  serializer,
const T(&)  values[N] 
)

Writes a fixed-size array to a Serializer.

Template Parameters
EEndianness of buffer. Automatically deduced from the serializer parameter.
TType of array elements. Automatically deduced from the values parameter.
Parameters
serializerSerializer object pointing to the destination buffer.
valuesC-style array of values
Returns
The total number of bytes written.

◆ insert() [8/10]

template<serialization::Endian E, typename T0 , typename T1 , typename... Ts>
size_t microstrain::insert ( Serializer< E > &  serializer,
const T0 &  value0,
const T1 &  value1,
Ts...  values 
)

Writes multiple values to a Serializer.

This function is equivalent to calling insert on each parameter in sequence.

This function can make use of C++17 fold expressions to improve performance by combining the buffer bounds checks when all types are of known size (i.e. numeric types).

Template Parameters
EEndianness of buffer. Automatically deduced from the serializer parameter.
TsTypes of values. Automatically deduced from the values parameters.
Parameters
serializerSerializer object pointing to the destination buffer.
valuesOne or more parameters to be written.
Returns
The total number of bytes written.

◆ insert() [9/10]

template<serialization::Endian E, class T >
size_t microstrain::insert ( Serializer< E > &  serializer,
microstrain::Span< const T >  values 
)

Writes an array to a Serializer via a Span.

Template Parameters
EEndianness of buffer. Automatically deduced from the serializer parameter.
TType of array elements. Automatically deduced from the values parameter.
Parameters
serializerSerializer object pointing to the destination buffer.
valuesSpan containing pointer and count.
Returns
The total number of bytes written.

◆ insert() [10/10]

template<serialization::Endian E, class T >
bool microstrain::insert ( value,
microstrain::Span< uint8_t >  buffer,
size_t  offset = 0,
bool  exact_size = false 
)

Serializes a value to a raw byte buffer (span version).

Use this overload to write a single value without needing to manually construct a Serializer object.

Template Parameters
EEndianness of buffer. Must be manually specified.
TType of value. Automatically deduced from the value parameter.
Parameters
valueParameter to serialize. This can be any serializable type.
bufferSource buffer span.
offsetStarting offset. Default 0.
exact_sizeReturns true only if exactly buffer.size()-offset bytes are written. Default false.
Returns
False if the buffer isn't large enough.
False if exact_size is true and the number of bytes written didn't equal buffer_length.
True otherwise.

◆ operator==() [1/2]

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

◆ operator==() [2/2]

constexpr bool microstrain::operator== ( Index  l,
Id  r 
)
inlineconstexpr
microstrain::Serializer
Serializes or deserializes data to/from a byte buffer.
Definition: serializer.hpp:125
microstrain::insert
std::enable_if< std::is_arithmetic< T >::value, size_t >::type insert(Serializer< E > &buffer, T value)
Inserts a numeric value to a Serializer.
Definition: serializer.hpp:172
microstrain::extract
std::enable_if< std::is_arithmetic< T >::value, size_t >::type extract(Serializer< E > &buffer, T &value)
Reads a numeric value from a Serializer.
Definition: serializer.hpp:193