Skip to content
Snippets Groups Projects
Commit 60930606 authored by Valerio Pastore's avatar Valerio Pastore
Browse files

updated txt and json impl

parent 3d5e5b9d
No related branches found
No related tags found
No related merge requests found
Subproject commit b7c86f5bcc12b795a4a56fdfff114c9e876b40ca Subproject commit 4c957e6878373a2800411f4d1e9b0dda617dda9e
...@@ -8,7 +8,7 @@ namespace inaf::oasbo::Packets { ...@@ -8,7 +8,7 @@ namespace inaf::oasbo::Packets {
class AstriPacketGeneric : public inaf::oasbo::PacketLib::BasePacket { class AstriPacketGeneric : public inaf::oasbo::PacketLib::BasePacket {
public: public:
AstriPacketGeneric(std::vector<std::tuple<int, std::string, int>> paramsTuple) : BasePacket(paramsTuple){} AstriPacketGeneric(inaf::oasbo::PacketLib::BasePacketStructure *structure) : BasePacket(structure){}
size_t getHeaderSize(); size_t getHeaderSize();
size_t getPayloadSize(); size_t getPayloadSize();
size_t getTailSize(); size_t getTailSize();
......
...@@ -80,22 +80,14 @@ namespace inaf::oasbo::Packets { ...@@ -80,22 +80,14 @@ namespace inaf::oasbo::Packets {
class AstriPacketS22: public inaf::oasbo::Packets::AstriPacketGeneric { class AstriPacketS22: public inaf::oasbo::Packets::AstriPacketGeneric {
public: public:
AstriPacketS22(std::vector<std::tuple<int, std::string, int>> paramsTuple) : AstriPacketS22(inaf::oasbo::PacketLib::BasePacketStructure *structure) :
AstriPacketGeneric(paramsTuple) { AstriPacketGeneric(structure) {
readHeader(); readHeader();
readDataFieldHeader(); readDataFieldHeader();
readDataFieldHeaderExtension(); readDataFieldHeaderExtension();
readPDMs(); readPDMs();
} }
AstriPacketS22(const AstriPacketGeneric &other, std::vector<std::tuple<int, std::string, int>> paramsTuple) :
AstriPacketGeneric(other) {
updateStructure(paramsTuple);
readHeader();
readDataFieldHeader();
readDataFieldHeaderExtension();
readPDMs();
}
AstriS22::Header header = {}; AstriS22::Header header = {};
AstriS22::DataFieldHeader dataHeader = {}; AstriS22::DataFieldHeader dataHeader = {};
......
...@@ -22,8 +22,11 @@ private: ...@@ -22,8 +22,11 @@ private:
size_t &count); size_t &count);
public: public:
PacketStructureJson(std::string filePath); std::vector<std::tuple<int, std::string, int>> readStructureFromSource(
std::vector<std::tuple<int, std::string, int>> getPacketStructure(){ return structure; } std::string source);
PacketStructureJson(std::string source){
updateStructure(source);
}
}; };
} }
......
...@@ -13,17 +13,22 @@ ...@@ -13,17 +13,22 @@
namespace inaf::oasbo::Packets { namespace inaf::oasbo::Packets {
class PacketStructureTxt : public inaf::oasbo::PacketLib::BasePacketStructure { class PacketStructureTxt: public inaf::oasbo::PacketLib::BasePacketStructure {
private: private:
std::vector<std::string> stringArrayFile; std::vector<std::string> stringArrayFile;
std::vector<std::string> toStringArray(std::ifstream &f); std::vector<std::string> toStringArray(std::ifstream &f);
std::vector<std::tuple<int, std::string, int>> structure; std::vector<std::tuple<int, std::string, int>> structure;
std::vector<std::tuple<int, std::string, int>> convertToTupleVector(size_t &start, size_t &count); std::vector<std::tuple<int, std::string, int>> convertToTupleVector(
size_t &start, size_t &count);
public: public:
PacketStructureTxt(std::string filePath); std::vector<std::tuple<int, std::string, int>> readStructureFromSource(
std::vector<std::tuple<int, std::string, int>> getPacketStructure(){ return structure; } std::string source);
PacketStructureTxt(std::string source) {
updateStructure(source);
}
;
}; };
} }
......
...@@ -9,11 +9,11 @@ ...@@ -9,11 +9,11 @@
using namespace inaf::oasbo::Packets; using namespace inaf::oasbo::Packets;
PacketStructureJson::PacketStructureJson(std::string filePath) { std::vector<std::tuple<int, std::string, int>> PacketStructureJson::readStructureFromSource(std::string source) {
std::ifstream file; std::ifstream file;
file.open(filePath, std::ios::in); file.open(source, std::ios::in);
if (!file.is_open()) { if (!file.is_open()) {
std::cerr << "Error: Could not open file: " << filePath << std::endl; std::cerr << "Error: Could not open file: " << source << std::endl;
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
size_t count = 0; size_t count = 0;
...@@ -21,6 +21,7 @@ PacketStructureJson::PacketStructureJson(std::string filePath) { ...@@ -21,6 +21,7 @@ PacketStructureJson::PacketStructureJson(std::string filePath) {
file >> data; file >> data;
this->structure = convertToTupleVector(data, count); this->structure = convertToTupleVector(data, count);
file.close(); file.close();
return structure;
} }
std::vector<std::tuple<int, std::string, int>> PacketStructureJson::convertToTupleVector( std::vector<std::tuple<int, std::string, int>> PacketStructureJson::convertToTupleVector(
......
...@@ -8,19 +8,15 @@ ...@@ -8,19 +8,15 @@
#include <PacketStructureTxt.h> #include <PacketStructureTxt.h>
using namespace inaf::oasbo::Packets; using namespace inaf::oasbo::Packets;
std::vector<std::tuple<int, std::string, int>> PacketStructureTxt::readStructureFromSource(std::string source) {
PacketStructureTxt::PacketStructureTxt(std::string filePath) {
std::ifstream file; std::ifstream file;
file.open(filePath, std::ios::in); file.open(source, std::ios::in);
if (!file.is_open()) {
std::cerr << "Error: Could not open file: " << filePath << std::endl;
exit(EXIT_FAILURE);
}
stringArrayFile = this->toStringArray(file); stringArrayFile = this->toStringArray(file);
size_t start = 0; size_t start = 0;
size_t count = 0; size_t count = 0;
this->structure = convertToTupleVector(start, count); this->structure = convertToTupleVector(start, count);
file.close(); file.close();
return structure;
} }
std::vector<std::string> PacketStructureTxt::toStringArray(std::ifstream &file) { std::vector<std::string> PacketStructureTxt::toStringArray(std::ifstream &file) {
...@@ -66,7 +62,6 @@ std::vector<std::tuple<int, std::string, int>> PacketStructureTxt::convertToTupl ...@@ -66,7 +62,6 @@ std::vector<std::tuple<int, std::string, int>> PacketStructureTxt::convertToTupl
std::remove_if(fieldName.begin(), fieldName.end(), std::remove_if(fieldName.begin(), fieldName.end(),
::isspace), fieldName.end()); ::isspace), fieldName.end());
std::transform(fieldName.begin(), fieldName.end(), fieldName.begin(), ::tolower);
out.push_back( out.push_back(
std::make_tuple(count, fieldName, std::make_tuple(count, fieldName,
std::stoi(line.substr(line.find(" "))))); std::stoi(line.substr(line.find(" ")))));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment