/* * AstriPacketGeneric.cpp * * Created on: Jan 26, 2023 * Author: valerio */ #include <Astri_Horn_Generic.h> #include <Astri_Horn_Recognized_Packet.h> using namespace inaf::oasbo::Packets; uint AstriHornGeneric::getHeaderSize() const { return 6; } uint AstriHornGeneric::getPayloadSize() const { auto val = this->operator [](5); if(val.has_value()) return val.value()+1; else{ std::cerr << "ASTRI HORN packet error: cannot access index 5 to get payload size." << std::endl; return -1; } } uint AstriHornGeneric::getTailSize() const { return 0; } bool AstriHornGeneric::isRecognizedHeader() const { std::optional<size_t> type = this->operator []("type"); if(!type.has_value()) return false; std::optional<size_t> subtype = this->operator []("subtype"); if(!subtype.has_value()) return false; std::optional<size_t> length = this->operator []("length"); if(!length.has_value()) return false; size_t totLength = this->getHeaderSize() + length.value()+1 + this->getTailSize(); std::tuple<size_t, size_t, size_t> target = std::make_tuple(type.value(), subtype.value(),totLength); auto it = std::find(AstriHorn::recognizedPackets.begin(), AstriHorn::recognizedPackets.end(), target); if (it != AstriHorn::recognizedPackets.end()) return true; else return false; } bool AstriHornGeneric::isRecognizedHeader(std::vector<uint8_t> buff) const { if( buff.size() != this->getHeaderSize()) return false; size_t type = buff[1] >> 4; size_t subtype = buff[1] & 0x0F; ssize_t length = (buff[4] << 8) + buff[5]; ssize_t totLength = this->getHeaderSize() + length+1 + this->getTailSize(); std::tuple<size_t, size_t, size_t> target = std::make_tuple(type, subtype,totLength); auto it = std::find(AstriHorn::recognizedPackets.begin(), AstriHorn::recognizedPackets.end(), target); if (it != AstriHorn::recognizedPackets.end()) return true; else return false; }