Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • bias/daqs/base-daq
1 result
Show changes
Commits on Source (1)
......@@ -22,6 +22,7 @@ namespace inaf::oasbo::PacketLib {
class BasePacketStructure {
protected:
std::string source;
std::vector<std::tuple<uint, std::string, uint>> structure;
uint byteSize;
std::vector<uint> fieldSizes;
std::unordered_map<uint, uint> indexToOffsetsMap;
......@@ -57,17 +58,27 @@ protected:
}
void updateStructure(std::string source) {
this->source = source;
std::vector<std::tuple<uint, std::string, uint>> paramsTuple =
readStructureFromSource(source);
updateFieldSizes(paramsTuple);
updateFieldOffsets(paramsTuple);
updateFieldNameAndIndexMap(paramsTuple);
this->structure = readStructureFromSource(source);
updateFieldSizes(structure);
updateFieldOffsets(structure);
updateFieldNameAndIndexMap(structure);
this->byteSize = std::accumulate(fieldSizes.begin(), fieldSizes.end(),
0) / 8 + 1; // /8 +1 for byte size
}
public:
virtual ~BasePacketStructure() = default;
BasePacketStructure(std::string source) : source(source){};
BasePacketStructure(const BasePacketStructure &other){
this->source = other.source;
this->byteSize = other.byteSize;
this->fieldSizes = other.fieldSizes;
this->indexToOffsetsMap = other.indexToOffsetsMap;
this->fieldNameToIndexMap = other.fieldNameToIndexMap;
this->indexToFieldNameMap = other.indexToFieldNameMap;
}
void changeSource(std::string source) {
updateStructure(source);
}
......@@ -255,10 +266,18 @@ public:
this->binaryPointer = new uint8_t[structure.getByteSize()];
}
BasePacketTempl(const BasePacketTempl& other) {
this->structure = new BasePacketStructure(other.getPacketStructure());
this->binaryPointer = new uint8_t[other.structure->getByteSize()];
std::memcpy(this->binaryPointer, other.binaryPointer, other.structure->getByteSize());
}
virtual ~BasePacketTempl() = default;
void updateStructure(BasePacketStructure &structure) {
size_t newSize = std::min(structure.getByteSize(), this->structure->getByteSize());
size_t newSize = std::min(structure.getByteSize(),
this->structure->getByteSize());
this->structure = &structure;
uint8_t *buff = new uint8_t[newSize];
......@@ -291,14 +310,13 @@ public:
uint max_writable = this->structure->getByteSize();
if (size > max_writable) {
std::cerr << "Error: you are trying to copy " << size
<< "byte where the max size is: "
<< max_writable << std::endl;
std::cerr << "\tI copy only until "
<< max_writable << " byte" << std::endl;
<< "byte where the max size is: " << max_writable
<< std::endl;
std::cerr << "\tI copy only until " << max_writable << " byte"
<< std::endl;
std::memcpy(binaryPointer, from, max_writable);
return max_writable;
}
else{
} else {
std::memcpy(binaryPointer, from, size);
return size;
}
......@@ -306,23 +324,22 @@ public:
int copyToBinaryPointer(const uint8_t *from, uint size, uint offset) {
uint max_writable = this->structure->getByteSize();
if(offset > max_writable){
std::cerr << "Error: you are trying to copy starting from " << offset
<< "byte where the max size is: "
<< max_writable << std::endl;
if (offset > max_writable) {
std::cerr << "Error: you are trying to copy starting from "
<< offset << "byte where the max size is: " << max_writable
<< std::endl;
return -1;
}
if (size + offset > max_writable) {
std::cerr << "Error: you are trying to copy " << size + offset
<< "byte where the max size is: "
<< max_writable << std::endl;
std::cerr << "\tI copy only until "
<< max_writable << " byte" << std::endl;
int to_write = max_writable-offset;
<< "byte where the max size is: " << max_writable
<< std::endl;
std::cerr << "\tI copy only until " << max_writable << " byte"
<< std::endl;
int to_write = max_writable - offset;
std::memcpy(&binaryPointer[offset], from, to_write);
return to_write;
}
else{
} else {
std::memcpy(&binaryPointer[offset], from, size);
return size;
}
......@@ -351,8 +368,7 @@ public:
&_readValueFromBinaryAt_);
}
std::optional<int> writeValueToBinaryAtIndex(uint index,
ValueType value) {
std::optional<int> writeValueToBinaryAtIndex(uint index, ValueType value) {
auto offset = this->structure->bitOffsetOf(index);
auto numbits = this->structure->bitSizeOf(index);
size_t min_req = minBitsRequired(value);
......@@ -387,9 +403,13 @@ public:
}
return numbits_written;
}
uint getPacketStructureByteSize() const {return structure->getByteSize();}
BasePacketStructure & getPacketStructure() const { return *(this->structure);}
uint getPacketStructureByteSize() const {
return structure->getByteSize();
}
BasePacketStructure& getPacketStructure() const {
return *(this->structure);
}
virtual bool isRecognizedHeader() const = 0;
virtual bool isRecognizedHeader(std::vector<uint8_t> buff) const = 0;
......