Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* AstriPacketGeneric.cpp
*
* Created on: Jan 26, 2023
* Author: valerio
*/
#include <AstriHornGeneric.h>
#include <AstriHornRecognizedPacket.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 << "Error: cannot access index 5 to get payload size." << std::endl;
exit(EXIT_FAILURE);
}
}
uint AstriHornGeneric::getTailSize() const {
return 2;
}
bool AstriHornGeneric::isRecognizedHeader() const {
size_t type = this->operator []("type").value();
size_t subtype = this->operator []("subtype").value();
ssize_t length = this->operator []("length").value();
ssize_t totLength = this->getHeaderSize() + length + 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;
}
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] -1;
ssize_t totLength = this->getHeaderSize() + length + 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;
}