robometry::BufferManager class

Class that manages the buffers associated to the channels of the telemetry.

Each BufferManager can handle different types of data, the number of samples is defined in the configuration and it is the same for every channel. On the other hand the data inside the channels can have different dimensionality(e.g. 1x1, 2x3 etc). It contains utilities for saving the data of the channels in mat files, and to save/read the configuration to/from a json file.

Constructors, destructors, conversion operators

BufferManager()
Construct an empty BufferManager object.
BufferManager(const BufferConfig& _bufferConfig)
Construct a new BufferManager object, configuring it via the robometry::BufferConfig.
~BufferManager()
Destroy the BufferManager object.

Public functions

auto enablePeriodicSave(double _save_period) -> bool
Enable the save thread with _save_period seconds of period.
auto configure(const BufferConfig& _bufferConfig) -> bool
Configure the BufferManager through a BufferConfig object.
auto getBufferConfig() const -> BufferConfig
Get the BufferConfig object representing the actual configuration.
void setFileName(const std::string& filename)
Set the file name that will be created by the BufferManager.
void setDefaultPath(const std::string& path)
Set the path where the files will be saved.
void enableCompression(bool enable_compression)
Enable the zlib compression.
void setDescriptionList(const std::vector<std::string>& description_list)
Set the description list that will be saved in all the files.
void resize(size_t new_size)
Resize the Buffer/s.
void set_capacity(size_t new_size)
Set the capacity of Buffer/s.
auto addChannel(const ChannelInfo& channel) -> bool
Add a channel(variable) to the BufferManager.
auto addChannels(const std::vector<ChannelInfo>& channels) -> bool
Add a list of channels(variables) to the BufferManager.
template<typename T>
void push_back(matioCpp::Span<const T> elem, double ts, const std::string& var_name)
Push a new element in the var_name channel.
template<typename T>
void push_back(const std::initializer_list<T>& elem, double ts, const std::string& var_name)
Push a new element in the var_name channel.
template<typename T>
void push_back(matioCpp::Span<const T> elem, const std::string& var_name)
Push a new element in the var_name channel.
template<typename T>
void push_back(const std::initializer_list<T>& elem, const std::string& var_name)
Push a new element in the var_name channel.
template<typename T>
void push_back(const T& elem, double ts, const std::string& var_name)
Push a new element in the var_name channel.
template<typename T>
void push_back(const T& elem, const std::string& var_name)
Push a new element in the var_name channel.
auto saveToFile(bool flush_all = true) -> bool
Save the content of all the channels into a file.
auto saveToFile(std::string& file_name_path, bool flush_all = true) -> bool
Save the content of all the channels into a file.
auto setNowFunction(std::function<double(void)> now) -> bool
Set the now function, by default is std::chrono::duration<double>(std::chrono::system_clock::now().time_since_epoch()).count().
auto setSaveCallback(std::function<bool(const std::string&, const SaveCallbackSaveMethod&method)> saveCallback) -> bool
Set the saveCallback function.

Function documentation

robometry::BufferManager::BufferManager()

Construct an empty BufferManager object.

For being used it has to be configured afterwards.

robometry::BufferManager::BufferManager(const BufferConfig& _bufferConfig)

Construct a new BufferManager object, configuring it via the robometry::BufferConfig.

Parameters
_bufferConfig in The struct containing the configuration for the BufferManager.

robometry::BufferManager::~BufferManager()

Destroy the BufferManager object.

If auto_save is enabled, it saves to file the remaining data in the buffer.

bool robometry::BufferManager::enablePeriodicSave(double _save_period)

Enable the save thread with _save_period seconds of period.

Parameters
_save_period in The period in seconds of the save thread.
Returns true on success, false otherwise.

If the thread has been started yet in the configuration through BufferConfing, it skips it.

bool robometry::BufferManager::configure(const BufferConfig& _bufferConfig)

Configure the BufferManager through a BufferConfig object.

Parameters
_bufferConfig in The struct containing the configuration parameters.
Returns true on success, false otherwise.

BufferConfig robometry::BufferManager::getBufferConfig() const

Get the BufferConfig object representing the actual configuration.

Returns The BufferConfig object.

void robometry::BufferManager::setFileName(const std::string& filename)

Set the file name that will be created by the BufferManager.

Parameters
filename in The file name to be set.

void robometry::BufferManager::setDefaultPath(const std::string& path)

Set the path where the files will be saved.

Parameters
path in The path to be set.

void robometry::BufferManager::resize(size_t new_size)

Resize the Buffer/s.

Parameters
new_size in The new size to be resized to.

void robometry::BufferManager::set_capacity(size_t new_size)

Set the capacity of Buffer/s.

Parameters
new_size in The new size.

bool robometry::BufferManager::addChannel(const ChannelInfo& channel)

Add a channel(variable) to the BufferManager.

Parameters
channel in Pair representing the channel to be added.
Returns true on success, false otherwise.

The channels have to be unique in the BufferManager.

bool robometry::BufferManager::addChannels(const std::vector<ChannelInfo>& channels)

Add a list of channels(variables) to the BufferManager.

Parameters
channels in List of pair representing the channels to be added.
Returns true on success, false otherwise.

The channels have to be unique in the BufferManager.

template<typename T>
void robometry::BufferManager::push_back(matioCpp::Span<const T> elem, double ts, const std::string& var_name)

Push a new element in the var_name channel.

Parameters
elem in The element to be pushed(via copy) in the channel.
ts in The timestamp of the element to be pushed.
var_name in The name of the channel.

The var_name channels must exist, otherwise an exception is thrown.

template<typename T>
void robometry::BufferManager::push_back(const std::initializer_list<T>& elem, double ts, const std::string& var_name)

Push a new element in the var_name channel.

Parameters
elem in The element to be pushed(via copy) in the channel.
ts in The timestamp of the element to be pushed.
var_name in The name of the channel.

The var_name channels must exist, otherwise an exception is thrown.

template<typename T>
void robometry::BufferManager::push_back(matioCpp::Span<const T> elem, const std::string& var_name)

Push a new element in the var_name channel.

Parameters
elem in The element to be pushed(via copy) in the channel.
var_name in The name of the channel.

The var_name channels must exist, otherwise an exception is thrown.

template<typename T>
void robometry::BufferManager::push_back(const std::initializer_list<T>& elem, const std::string& var_name)

Push a new element in the var_name channel.

Parameters
elem in The element to be pushed(via copy) in the channel.
var_name in The name of the channel.

The var_name channels must exist, otherwise an exception is thrown.

template<typename T>
void robometry::BufferManager::push_back(const T& elem, double ts, const std::string& var_name)

Push a new element in the var_name channel.

Parameters
elem in The element to be pushed in the channel.
ts in The timestamp of the element to be pushed.
var_name in The name of the channel.

The var_name channels must exist, otherwise an exception is thrown.

template<typename T>
void robometry::BufferManager::push_back(const T& elem, const std::string& var_name)

Push a new element in the var_name channel.

Parameters
elem in The element to be pushed in the channel.
var_name in The name of the channel.

The var_name channels must exist, otherwise an exception is thrown.

bool robometry::BufferManager::saveToFile(bool flush_all = true)

Save the content of all the channels into a file.

Parameters
flush_all in Flag for forcing the save of whatever is contained in the channels.
Returns true on success, false otherwise.

If flush_all is set to false, it saves only the content of the channels that have a number of samples greater than the robometry::BufferConfig::data_threshold. If robometry::BufferConfig::data_threshold is greater than robometry::BufferConfig::n_samples this check is skipped.

bool robometry::BufferManager::saveToFile(std::string& file_name_path, bool flush_all = true)

Save the content of all the channels into a file.

Parameters
file_name_path out path name of the matfile without the suffix .mat
flush_all in Flag for forcing the save of whatever is contained in the channels.
Returns true on success, false otherwise.

If flush_all is set to false, it saves only the content of the channels that have a number of samples greater than the robometry::BufferConfig::data_threshold. If robometry::BufferConfig::data_threshold is greater than robometry::BufferConfig::n_samples this check is skipped.

bool robometry::BufferManager::setNowFunction(std::function<double(void)> now)

Set the now function, by default is std::chrono::duration<double>(std::chrono::system_clock::now().time_since_epoch()).count().

Parameters
now in The now function
Returns true on success, false otherwise.

bool robometry::BufferManager::setSaveCallback(std::function<bool(const std::string&, const SaveCallbackSaveMethod&method)> saveCallback)

Set the saveCallback function.

Parameters
saveCallback in The saveCallback function
Returns true on success, false otherwise.

Thanks to this function you can save additional data type along with the matfile salve by telemetry