SBB Host
Host communication with the self balancing bike.
Loading...
Searching...
No Matches
SBBHostCore Class Reference

A class for the core of the SBB Host application. More...

#include <SBBHostCore.h>

Public Member Functions

 SBBHostCore ()
 Constructor. More...
 
 ~SBBHostCore ()
 Desctructor. More...
 
void set_params (Params *params)
 Set the parameters. More...
 
void reset_stream ()
 Reset the data streaming. More...
 
int stream (bool writeFlag)
 Perform a stream step. More...
 
void beginlog (std::string path)
 Begin the data logging. More...
 
int connect (bool logdata=false, std::string log_path="")
 Connect the host port. More...
 
void disconnect ()
 Disconnect the host port. More...
 
int save (int id)
 Save a log as a *.sbb file. More...
 
int save (int id, std::string name, std::string path)
 Save a log as a *.sbb file. More...
 
int save_dat (int id, std::string str)
 Save a log as *.dat file. More...
 
int save_mat (int id, std::string str)
 Save a log as *.csv file. More...
 
int open (std::string str)
 Open a log from a *.sbb file. More...
 
int find (int id)
 Find a log using the ID. More...
 
int get_lastUnsaved (int *id)
 Get the ID of the last unsaved log. More...
 
bool check_allSaved ()
 Check if all log are saved. More...
 
void set_path_logs (std::string folder)
 Set the default path of all logs. More...
 
bool delete_log (int id)
 Delete a log. More...
 

Public Attributes

Paramsp_params
 Pointer to the parameters structure created in SBBHostApp. More...
 
unsigned int numOfMissingPackets = 0
 Number of current missing packets. More...
 
int id_count = 0
 Counter of logged-data ID. More...
 
long long samples = -1
 Number of current logged sample. More...
 
bool dolog = false
 true if do data logging. More...
 
std::string tmp_name = ""
 Temporary name for the logged-data. More...
 
HostPort hostPort
 HostPort object. More...
 
HostPortTCP hostPortTCP
 HostPortTCP object. More...
 
HostPortUDP hostPortUDP
 HostPortUDP object. More...
 
Packet< float, PACKET_SIZErx_packet
 Rx Packet object. More...
 
Packet< float, PACKET_SIZEtx_packet
 Tx Packet object. More...
 
Time time
 Time object. More...
 
std::vector< LogData< float > * > logData
 Vector of pointers to LogData with base type float. More...
 
Filep_file = { nullptr }
 Pointer to File object. More...
 

Private Member Functions

size_t save_dat_private (File *p_file, LogData< float > *p_logData)
 Private routine to save *.csv format. More...
 
bool save_mat_private (std::string filename, LogData< float > *p_logData)
 Private routine to save *.mat file. More...
 

Detailed Description

A class for the core of the SBB Host application.

Class for the core management of the SBB Host Application. This class is used for signal streaming and logging via the the host port, and to store, save and open the logged-data files.

See also
SBBHostApp
Author
Stefano Lovato
Date
2022

Constructor & Destructor Documentation

◆ SBBHostCore()

SBBHostCore::SBBHostCore ( )

Constructor.

Default constractor.

◆ ~SBBHostCore()

SBBHostCore::~SBBHostCore ( )

Desctructor.

Default destructor. It automatically destroies the host port.

Member Function Documentation

◆ beginlog()

void SBBHostCore::beginlog ( std::string  path)

Begin the data logging.

Function to begin the data logging with a given path. The log name is automatically generated from the current system time.

Parameters
pathThe default path where to save the log when necessary.

◆ check_allSaved()

bool SBBHostCore::check_allSaved ( )

Check if all log are saved.

Function to check if are logged data are saved.

Returns
true if all logs have been saved, false otherwise.

◆ connect()

int SBBHostCore::connect ( bool  logdata = false,
std::string  log_path = "" 
)

Connect the host port.

Function to connect the host port and begin the data streaming.

Parameters
logdataThe flag to enable the data logging.
log_pathThe string og the default path where to save the log when necessary,
Returns
An exit flag (see config.h for details).

◆ delete_log()

bool SBBHostCore::delete_log ( int  id)

Delete a log.

Function to a log by specifying its ID.

Parameters
idThe ID of the log to delete.
Returns
true if success, false otherwise.

◆ disconnect()

void SBBHostCore::disconnect ( )

Disconnect the host port.

Function to disconnect the host port and stop the data streaming.

◆ find()

int SBBHostCore::find ( int  id)

Find a log using the ID.

Function to find a log by specifying its ID.

Parameters
idThe ID of the log to find.
Returns
The corresponding index in the logData vector (NULL_ID if not found).

◆ get_lastUnsaved()

int SBBHostCore::get_lastUnsaved ( int *  id)

Get the ID of the last unsaved log.

Function to get the ID of the last unsaved logged data.

Parameters
idPointer to the ID of the log.
Returns
An exit flag (see config.h for details).

◆ open()

int SBBHostCore::open ( std::string  str)

Open a log from a *.sbb file.

Function to open a *.sbb file and load the logged data.

Parameters
strThe path/name string of the file to open.
Returns
An exit flag (see config.h for details).

◆ reset_stream()

void SBBHostCore::reset_stream ( )

Reset the data streaming.

Function to reset the data streaming when finished.

◆ save() [1/2]

int SBBHostCore::save ( int  id)

Save a log as a *.sbb file.

Function to save a log as a *.sbb file by specifying its ID with the default names.

Parameters
idThe ID of the logged-data to save.
Returns
An exit flag (see config.h for details).

◆ save() [2/2]

int SBBHostCore::save ( int  id,
std::string  name,
std::string  path 
)

Save a log as a *.sbb file.

Function to save a log as a *.sbb file by specifying its ID with specific name and path. Name and path are assigned to the logged-data.

Parameters
idThe ID of the logged-data to save.
nameThe name of the file to save.
pathThe path of the file to save.
Returns
An exit flag (see config.h for details).

◆ save_dat()

int SBBHostCore::save_dat ( int  id,
std::string  str 
)

Save a log as *.dat file.

Function to save a log as a *.dat file by specifying its ID. The first column is the Sample, while the other the signals. Values are separated by a comma.

Parameters
idThe ID of the logged-data to save.
strThe path/name string of the file to save
Returns
An exit flag (see config.h for details).

◆ save_dat_private()

size_t SBBHostCore::save_dat_private ( File p_file,
LogData< float > *  p_logData 
)
private

Private routine to save *.csv format.

Private function to save logged-data in *.csv format. The file must be open before and closed after.

Parameters
p_filePointer to the File object used to save the file.
p_logDataPointer to the LogData object to be saved.
Returns
The number of written char.

◆ save_mat()

int SBBHostCore::save_mat ( int  id,
std::string  str 
)

Save a log as *.csv file.

Function to save a log as a *.mat file by specifying its ID. The tinymatlibrary is used to save the *.mat file.

Parameters
idThe ID of the logged-data to save.
strThe path/name string of the file to save.
Returns
An exit flag (see config.h for details).

◆ save_mat_private()

bool SBBHostCore::save_mat_private ( std::string  filename,
LogData< float > *  p_logData 
)
private

Private routine to save *.mat file.

Private function to save logged-data in *.mat (MATLAB) format. The file must not be open before and closed after.

Parameters
filenameThe name of the file to save (including the path)
p_logDataPointet to the LogData object to be saved.
Returns
true if success, false otherwise.

◆ set_params()

void SBBHostCore::set_params ( Params params)

Set the parameters.

Function to set the pointer to the parameters structure.

Parameters
paramsPointer to the parameter struct variable.

◆ set_path_logs()

void SBBHostCore::set_path_logs ( std::string  folder)

Set the default path of all logs.

Function to set the default path of all logs.

◆ stream()

int SBBHostCore::stream ( bool  writeFlag)

Perform a stream step.

Function to perform a stream step. Must be called continously.

Parameters
writeFlagThe flag write the tx packet.
Returns
An exit flag (see config.h for details).

Member Data Documentation

◆ dolog

bool SBBHostCore::dolog = false

true if do data logging.

◆ hostPort

HostPort SBBHostCore::hostPort

HostPort object.

◆ hostPortTCP

HostPortTCP SBBHostCore::hostPortTCP

HostPortTCP object.

◆ hostPortUDP

HostPortUDP SBBHostCore::hostPortUDP

HostPortUDP object.

◆ id_count

int SBBHostCore::id_count = 0

Counter of logged-data ID.

◆ logData

std::vector<LogData<float>*> SBBHostCore::logData

Vector of pointers to LogData with base type float.

◆ numOfMissingPackets

unsigned int SBBHostCore::numOfMissingPackets = 0

Number of current missing packets.

◆ p_file

File* SBBHostCore::p_file = { nullptr }

Pointer to File object.

◆ p_params

Params* SBBHostCore::p_params

Pointer to the parameters structure created in SBBHostApp.

◆ rx_packet

Packet<float, PACKET_SIZE> SBBHostCore::rx_packet

Rx Packet object.

◆ samples

long long SBBHostCore::samples = -1

Number of current logged sample.

◆ time

Time SBBHostCore::time

Time object.

◆ tmp_name

std::string SBBHostCore::tmp_name = ""

Temporary name for the logged-data.

◆ tx_packet

Packet<float, PACKET_SIZE> SBBHostCore::tx_packet

Tx Packet object.