SBB Host
Host communication with the self balancing bike.
Loading...
Searching...
No Matches
SBBHostCore.h
Go to the documentation of this file.
1
2#ifndef SBBHOSTCORE_H
3#define SBBHOSTCORE_H
4
5#include <vector>
6#include <string>
7#include <map>
8#include <stdio.h>
9#include <stdlib.h>
10#include "config.h"
11#include "Params.h"
12#include "HostPortUDP.h"
13#include "HostPortTCP.h"
14#include "HostPort.h"
15#include "Packet.h"
16#include "LogData.h"
17#include "Timepp.h"
18#include "File.h"
19#include "tinymatwriter.h"
20#include "SBBUtils.h"
21
22#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) || defined(__WIN32__) || defined(WIN64) || defined(_WIN64) || defined(__WIN64) || defined(__WIN64__)
23#ifndef OS_WIN
24#define OS_WIN
25#endif
26#elif defined(linux) || defined(__linux) || defined(__linux__) || defined(__GNUC__) || defined(__GNUG__) || defined(unix) || defined(__unix) || defined(__unix__)
27#ifndef OS_LINUX
28#define OS_LINUX
29#endif
30#else
31#error OS not supported
32#endif
33
34#ifdef OS_LINUX
35#define sprintf_s(buf, len, ...) snprintf((buf), (len), __VA_ARGS__)
36#endif
37
47private:
54 size_t save_dat_private(File* p_file, LogData<float>* p_logData); //save csv file routing (not in LogData b/c type-dependent) - not used in SBBHostApp and thus private
55
62 bool save_mat_private(std::string filename, LogData<float>* p_logData); //save csv file routing (not in LogData b/c type-dependent) - not used in SBBHostApp and thus private
63
64public: //almost all members are public b/c SBBHostApp should have (almost) the complete access to SBBHostCore
65 //config variables - grouped in struct
67
68 //variables
69 unsigned int numOfMissingPackets = 0;
70 int id_count = 0;
71 long long samples = -1;
72 //size_t num_loggedData = 0;
73 bool dolog = false;
74 std::string tmp_name = "";
75
76 //objects
83
84 //pointers to object
85 std::vector<LogData<float>*> logData;
86 File * p_file = { nullptr };
87
88 //functions
93
98
103 void set_params(Params* params);
104
109
115 int stream(bool writeFlag);
116
122 void beginlog(std::string path);
123
130 int connect(bool logdata = false, std::string log_path = "");
131
136
142 int save(int id);
143
152 int save(int id, std::string name, std::string path);
153
161 int save_dat(int id, std::string str);
162
169 int save_mat(int id, std::string str);
170
176 int open(std::string str);
177
183 int find(int id);
184
190 int get_lastUnsaved(int *id);
191
197
201 void set_path_logs(std::string folder);
202
208 bool delete_log(int id);
209
210};
211
212
213#endif
214
A class for file reading and writing.
Definition: File.h:30
A class for host communication via TCP/IP protocol.
Definition: HostPortTCP.h:20
A class for host communication via UDP protocol using the broadcast IP.
Definition: HostPortUDP.h:20
A class for host communication via serial port.
Definition: HostPort.h:18
A templated-class for managing logged-data.
Definition: LogData.h:20
A templated-class for managing data packet.
Definition: Packet.h:17
A class for the application setting parameters.
Definition: Params.h:16
A class for the core of the SBB Host application.
Definition: SBBHostCore.h:46
bool save_mat_private(std::string filename, LogData< float > *p_logData)
Private routine to save *.mat file.
size_t save_dat_private(File *p_file, LogData< float > *p_logData)
Private routine to save *.csv format.
Packet< float, PACKET_SIZE > rx_packet
Rx Packet object.
Definition: SBBHostCore.h:80
void set_path_logs(std::string folder)
Set the default path of all logs.
~SBBHostCore()
Desctructor.
SBBHostCore()
Constructor.
unsigned int numOfMissingPackets
Number of current missing packets.
Definition: SBBHostCore.h:69
int connect(bool logdata=false, std::string log_path="")
Connect the host port.
int stream(bool writeFlag)
Perform a stream step.
bool dolog
true if do data logging.
Definition: SBBHostCore.h:73
bool delete_log(int id)
Delete a log.
HostPort hostPort
HostPort object.
Definition: SBBHostCore.h:77
std::string tmp_name
Temporary name for the logged-data.
Definition: SBBHostCore.h:74
HostPortUDP hostPortUDP
HostPortUDP object.
Definition: SBBHostCore.h:79
int open(std::string str)
Open a log from a *.sbb file.
int save(int id, std::string name, std::string path)
Save a log as a *.sbb file.
void beginlog(std::string path)
Begin the data logging.
Params * p_params
Pointer to the parameters structure created in SBBHostApp.
Definition: SBBHostCore.h:66
int save_dat(int id, std::string str)
Save a log as *.dat file.
std::vector< LogData< float > * > logData
Vector of pointers to LogData with base type float.
Definition: SBBHostCore.h:85
int save_mat(int id, std::string str)
Save a log as *.csv file.
File * p_file
Pointer to File object.
Definition: SBBHostCore.h:86
bool check_allSaved()
Check if all log are saved.
void set_params(Params *params)
Set the parameters.
int save(int id)
Save a log as a *.sbb file.
Time time
Time object.
Definition: SBBHostCore.h:82
int find(int id)
Find a log using the ID.
Packet< float, PACKET_SIZE > tx_packet
Tx Packet object.
Definition: SBBHostCore.h:81
int get_lastUnsaved(int *id)
Get the ID of the last unsaved log.
void disconnect()
Disconnect the host port.
HostPortTCP hostPortTCP
HostPortTCP object.
Definition: SBBHostCore.h:78
int id_count
Counter of logged-data ID.
Definition: SBBHostCore.h:70
long long samples
Number of current logged sample.
Definition: SBBHostCore.h:71
void reset_stream()
Reset the data streaming.
A class to get system time.
Definition: Timepp.h:37
A configuration file for the source code.