Satellite-Gateway
SnetAppMessage.h
Go to the documentation of this file.
1 
37 #ifndef SNET_APP_MESSAGE_H
38 #define SNET_APP_MESSAGE_H
39 
40 #include "SnetPacket.h"
41 
42 class SnetAppMessage: public SnetPacket {
43 public:
44  SnetAppMessage(uint8_t a_SrcServiceId = 0, uint8_t a_DstServiceId = 0, uint8_t a_Token = 0, uint16_t a_SrcSSA = 0xFFFE, uint16_t a_DstSSA = 0xFFFE, bool a_OnAirARQ = true): SnetPacket(a_SrcSSA, a_DstSSA, a_OnAirARQ), m_SrcServiceId(a_SrcServiceId), m_DstServiceId(a_DstServiceId), m_Token(a_Token) {}
45 
46  // Setters and getters
47  void SetSrcServiceId(uint8_t a_SrcServiceId = 0) { m_SrcServiceId = a_SrcServiceId; }
48  uint8_t GetSrcServiceId() const { return m_SrcServiceId; }
49  void SetDstServiceId(uint8_t a_DstServiceId = 0) { m_DstServiceId = a_DstServiceId; }
50  uint8_t GetDstServiceId() const { return m_DstServiceId; }
51  void SetToken(uint8_t a_Token = 0) { m_Token = a_Token; }
52  uint16_t GetToken() const { return m_Token; }
53 
54  // Serializer
55  std::vector<unsigned char> Serialize() const {
56  std::vector<unsigned char> l_Buffer(SnetPacket::Serialize());
57  l_Buffer.emplace_back(0x00);
58  l_Buffer.emplace_back(m_SrcServiceId);
59  l_Buffer.emplace_back(m_DstServiceId);
60  l_Buffer.emplace_back(0x00);
61  l_Buffer.emplace_back(m_Token);
62  return l_Buffer;
63  }
64 
65  // Deserializer
66  size_t Deserialize(const std::vector<unsigned char>& a_Buffer) {
67  size_t l_Offset = SnetPacket::Deserialize(a_Buffer);
68  if (l_Offset) {
69  if ((a_Buffer.size() - l_Offset) < 5) { return 0; }
70  if (a_Buffer[l_Offset + 0] != 0x00) { return 0; }
71  m_SrcServiceId = a_Buffer[l_Offset + 1];
72  m_DstServiceId = a_Buffer[l_Offset + 2];
73  if (a_Buffer[l_Offset + 3] != 0x00) { return 0; }
74  m_Token = a_Buffer[l_Offset + 4];
75  l_Offset += 5;
76  } // if
77 
78  return l_Offset;
79  }
80 
81  // Dissector
82  std::string Dissect() const {
83  std::stringstream l_Output;
84  l_Output << SnetPacket::Dissect()
85  << ", SrcSrv=0x" << std::hex << std::setw(2) << std::setfill('0') << (int)m_SrcServiceId
86  << ", DstSrv=0x" << std::hex << std::setw(2) << std::setfill('0') << (int)m_DstServiceId
87  << ", Token=0x" << std::hex << std::setw(2) << std::setfill('0') << (int)m_Token;
88  return l_Output.str();
89  }
90 
91 protected:
92  // Query the size of the packet in bytes
93  size_t GetSize() const { return (SnetPacket::GetSize() + 5); }
94 
95 private:
96  uint8_t m_SrcServiceId;
97  uint8_t m_DstServiceId;
98  uint8_t m_Token;
99 };
100 
101 #endif // SNET_APP_MESSAGE_H
void SetDstServiceId(uint8_t a_DstServiceId=0)
virtual std::vector< unsigned char > Serialize() const
Definition: SnetPacket.h:60
virtual std::string Dissect() const
Definition: SnetPacket.h:104
uint8_t GetDstServiceId() const
uint16_t GetToken() const
uint8_t GetSrcServiceId() const
size_t Deserialize(const std::vector< unsigned char > &a_Buffer)
void SetSrcServiceId(uint8_t a_SrcServiceId=0)
SnetAppMessage(uint8_t a_SrcServiceId=0, uint8_t a_DstServiceId=0, uint8_t a_Token=0, uint16_t a_SrcSSA=0xFFFE, uint16_t a_DstSSA=0xFFFE, bool a_OnAirARQ=true)
virtual size_t GetSize() const
Definition: SnetPacket.h:114
virtual size_t Deserialize(const std::vector< unsigned char > &a_Buffer)
Definition: SnetPacket.h:81
std::vector< unsigned char > Serialize() const
std::string Dissect() const
void SetToken(uint8_t a_Token=0)
Copyright (c) 2016, Florian Evers, florian-evers@gmx.de All rights reserved.
size_t GetSize() const