Skip to content
Snippets Groups Projects
Commit 465b406e authored by Alberto Nidasio's avatar Alberto Nidasio
Browse files

[Deserializer] Fixed automatic log deconding of multiple files

parent 73ad9878
No related branches found
No related tags found
No related merge requests found
...@@ -64,19 +64,15 @@ bool deserializeAll() ...@@ -64,19 +64,15 @@ bool deserializeAll()
{ {
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
{ {
char fn[10]; char nextName[11];
char fnext[11]; sprintf(nextName, "log%02d.dat", i);
sprintf(fn, "log%02d", i);
sprintf(fnext, "log%02d.dat", i);
struct stat st; struct stat st;
if (stat(fnext, &st) != 0) if (stat(nextName, &st) != 0)
continue; // File not found continue; // File not found
// File found // File found
if (!deserialize(string(fn))) if (!deserialize(string(nextName)))
{
return false; return false;
} }
}
return true; return true;
} }
......
...@@ -99,7 +99,7 @@ private: ...@@ -99,7 +99,7 @@ private:
bool closed = false; bool closed = false;
std::vector<std::ofstream*> fileStreams; std::map<std::string, std::ofstream*> fileStreams;
tscpp::TypePoolStream tps; tscpp::TypePoolStream tps;
std::string logFilename; std::string logFilename;
...@@ -130,14 +130,18 @@ void Deserializer::registerType() ...@@ -130,14 +130,18 @@ void Deserializer::registerType()
template <typename T> template <typename T>
void Deserializer::printType(T& t, std::string path, std::string prefix) void Deserializer::printType(T& t, std::string path, std::string prefix)
{ {
static std::ofstream* stream = nullptr; std::string demangledTypeName = tscpp::demangle(typeid(T).name());
static std::ofstream* stream;
try
{
stream = fileStreams.at(demangledTypeName);
}
// If not already initialize, open the file and write the header // If not already initialize, open the file and write the header
if (stream == nullptr) catch (std::out_of_range e)
{ {
stream = new std::ofstream(); stream = new std::ofstream();
std::string filename = std::string filename = path + prefix + "_" + demangledTypeName + ".csv";
path + prefix + "_" + tscpp::demangle(typeid(T).name()) + ".csv";
std::cout << "Creating file " + filename << std::endl; std::cout << "Creating file " + filename << std::endl;
stream->open(filename); stream->open(filename);
...@@ -152,7 +156,7 @@ void Deserializer::printType(T& t, std::string path, std::string prefix) ...@@ -152,7 +156,7 @@ void Deserializer::printType(T& t, std::string path, std::string prefix)
*stream << T::header(); *stream << T::header();
// Add the file to the vector such that it will be closed // Add the file to the vector such that it will be closed
fileStreams.push_back(stream); fileStreams.emplace(demangledTypeName, stream);
} }
// Print data into the file if it is open // Print data into the file if it is open
...@@ -222,8 +226,8 @@ void Deserializer::close() ...@@ -222,8 +226,8 @@ void Deserializer::close()
closed = true; closed = true;
for (auto it = fileStreams.begin(); it != fileStreams.end(); it++) for (auto it = fileStreams.begin(); it != fileStreams.end(); it++)
{ {
(*it)->close(); it->second->close();
delete *it; delete it->second;
} }
} }
} }
......
...@@ -101,7 +101,6 @@ void registerTypes(Deserializer& ds) ...@@ -101,7 +101,6 @@ void registerTypes(Deserializer& ds)
ds.registerType<VN100Data>(); ds.registerType<VN100Data>();
ds.registerType<BatteryVoltageSensorData>(); ds.registerType<BatteryVoltageSensorData>();
ds.registerType<CurrentSensorData>(); ds.registerType<CurrentSensorData>();
ds.registerType<LoadCellData>();
ds.registerType<MPXHZ6130AData>(); ds.registerType<MPXHZ6130AData>();
ds.registerType<HSCMAND015PAData>(); ds.registerType<HSCMAND015PAData>();
ds.registerType<HSCMRNN030PAData>(); ds.registerType<HSCMRNN030PAData>();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment