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 {
class AstriPacketGeneric : public inaf::oasbo::PacketLib::BasePacket {
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 getPayloadSize();
size_t getTailSize();
......
......@@ -80,22 +80,14 @@ namespace inaf::oasbo::Packets {
class AstriPacketS22: public inaf::oasbo::Packets::AstriPacketGeneric {
public:
AstriPacketS22(std::vector<std::tuple<int, std::string, int>> paramsTuple) :
AstriPacketGeneric(paramsTuple) {
AstriPacketS22(inaf::oasbo::PacketLib::BasePacketStructure *structure) :
AstriPacketGeneric(structure) {
readHeader();
readDataFieldHeader();
readDataFieldHeaderExtension();
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::DataFieldHeader dataHeader = {};
......
......@@ -22,8 +22,11 @@ private:
size_t &count);
public:
PacketStructureJson(std::string filePath);
std::vector<std::tuple<int, std::string, int>> getPacketStructure(){ return structure; }
std::vector<std::tuple<int, std::string, int>> readStructureFromSource(
std::string source);
PacketStructureJson(std::string source){
updateStructure(source);
}
};
}
......
......@@ -13,17 +13,22 @@
namespace inaf::oasbo::Packets {
class PacketStructureTxt : public inaf::oasbo::PacketLib::BasePacketStructure {
class PacketStructureTxt: public inaf::oasbo::PacketLib::BasePacketStructure {
private:
std::vector<std::string> stringArrayFile;
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>> convertToTupleVector(size_t &start, size_t &count);
std::vector<std::tuple<int, std::string, int>> convertToTupleVector(
size_t &start, size_t &count);
public:
PacketStructureTxt(std::string filePath);
std::vector<std::tuple<int, std::string, int>> getPacketStructure(){ return structure; }
std::vector<std::tuple<int, std::string, int>> readStructureFromSource(
std::string source);
PacketStructureTxt(std::string source) {
updateStructure(source);
}
;
};
}
......
......@@ -9,11 +9,11 @@
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;
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;
std::cerr << "Error: Could not open file: " << source << std::endl;
exit (EXIT_FAILURE);
}
size_t count = 0;
......@@ -21,6 +21,7 @@ PacketStructureJson::PacketStructureJson(std::string filePath) {
file >> data;
this->structure = convertToTupleVector(data, count);
file.close();
return structure;
}
std::vector<std::tuple<int, std::string, int>> PacketStructureJson::convertToTupleVector(
......
......@@ -8,19 +8,15 @@
#include <PacketStructureTxt.h>
using namespace inaf::oasbo::Packets;
PacketStructureTxt::PacketStructureTxt(std::string filePath) {
std::vector<std::tuple<int, std::string, int>> PacketStructureTxt::readStructureFromSource(std::string source) {
std::ifstream file;
file.open(filePath, std::ios::in);
if (!file.is_open()) {
std::cerr << "Error: Could not open file: " << filePath << std::endl;
exit(EXIT_FAILURE);
}
file.open(source, std::ios::in);
stringArrayFile = this->toStringArray(file);
size_t start = 0;
size_t count = 0;
this->structure = convertToTupleVector(start, count);
file.close();
return structure;
}
std::vector<std::string> PacketStructureTxt::toStringArray(std::ifstream &file) {
......@@ -66,7 +62,6 @@ std::vector<std::tuple<int, std::string, int>> PacketStructureTxt::convertToTupl
std::remove_if(fieldName.begin(), fieldName.end(),
::isspace), fieldName.end());
std::transform(fieldName.begin(), fieldName.end(), fieldName.begin(), ::tolower);
out.push_back(
std::make_tuple(count, fieldName,
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