Satellite-Gateway
HdlcdClientNewStatus.h
Go to the documentation of this file.
1 
24 #ifndef HDLCD_CLIENT_DEVICE_NEW_STATUS_H
25 #define HDLCD_CLIENT_DEVICE_NEW_STATUS_H
26 
27 #include "ConfigFrame.h"
28 #include <memory>
29 
31 public:
32  static HdlcdClientNewStatus Create(uint16_t a_SerialPortNbr, bool a_bIsResumed, bool a_bIsAlive) {
33  HdlcdClientNewStatus l_HdlcdClientNewStatus;
34  l_HdlcdClientNewStatus.m_SerialPortNbr = a_SerialPortNbr;
35  l_HdlcdClientNewStatus.m_bIsResumed = a_bIsResumed;
36  l_HdlcdClientNewStatus.m_bIsAlive = a_bIsAlive;
37  return l_HdlcdClientNewStatus;
38  }
39 
40  static std::shared_ptr<HdlcdClientNewStatus> CreateDeserializedFrame() {
41  auto l_HdlcdClientNewStatus(std::shared_ptr<HdlcdClientNewStatus>(new HdlcdClientNewStatus));
42  l_HdlcdClientNewStatus->m_eDeserialize = DESERIALIZE_BODY;
43  l_HdlcdClientNewStatus->m_BytesRemaining = 4; // Next: read body including the frame type byte
44  return l_HdlcdClientNewStatus;
45  }
46 
47  // Getter
48  uint16_t GetSerialPortNbr() const {
49  assert(m_eDeserialize == DESERIALIZE_FULL);
50  return m_SerialPortNbr;
51  }
52 
53  uint16_t GetIsResumed() const {
54  assert(m_eDeserialize == DESERIALIZE_FULL);
55  return m_bIsResumed;
56  }
57 
58  uint16_t GetIsAlive() const {
59  assert(m_eDeserialize == DESERIALIZE_FULL);
60  return m_bIsAlive;
61  }
62 
63 private:
64  // Private CTOR
65  HdlcdClientNewStatus(): m_SerialPortNbr(0), m_bIsResumed(false), m_bIsAlive(false), m_eDeserialize(DESERIALIZE_FULL) {
66  }
67 
68  // Methods
69  E_CONFIG_FRAME GetConfigFrameType() const { return CONFIG_FRAME_HDLCD_CLIENT_NEW_STATUS; }
70 
71  // Serializer
72  const std::vector<unsigned char> Serialize() const {
73  assert(m_eDeserialize == DESERIALIZE_FULL);
74  std::vector<unsigned char> l_Buffer;
75  l_Buffer.emplace_back(CONFIG_FRAME_HDLCD_CLIENT_NEW_STATUS);
76  l_Buffer.emplace_back((m_SerialPortNbr >> 8) & 0xFF);
77  l_Buffer.emplace_back((m_SerialPortNbr >> 0) & 0xFF);
78  unsigned char l_Control = 0x00;
79  if (m_bIsResumed) {
80  l_Control |= 0x01;
81  } // if
82 
83  if (m_bIsAlive) {
84  l_Control |= 0x02;
85  } // if
86 
87  l_Buffer.emplace_back(l_Control);
88  return l_Buffer;
89  }
90 
91  // Deserializer
92  bool Deserialize() {
93  // All requested bytes are available
94  switch (m_eDeserialize) {
95  case DESERIALIZE_BODY: {
96  // Deserialize the body including the frame type byte
97  assert(m_Buffer.size() == 4);
99  m_SerialPortNbr = ntohs(*(reinterpret_cast<const uint16_t*>(&m_Buffer[1])));
100  const unsigned char &l_Status = m_Buffer[3];
101  m_bIsResumed = (l_Status & 0x01);
102  m_bIsAlive = (l_Status & 0x02);
103  m_eDeserialize = DESERIALIZE_FULL;
104  break;
105  }
106  case DESERIALIZE_ERROR:
107  case DESERIALIZE_FULL:
108  default:
109  assert(false);
110  } // switch
111 
112  // No error
113  return true;
114  }
115 
116  // Members
117  uint16_t m_SerialPortNbr;
118  bool m_bIsResumed;
119  bool m_bIsAlive;
120  typedef enum {
121  DESERIALIZE_ERROR = 0,
122  DESERIALIZE_BODY = 1,
123  DESERIALIZE_FULL = 2
124  } E_DESERIALIZE;
125  E_DESERIALIZE m_eDeserialize;
126 };
127 
128 #endif // HDLCD_CLIENT_DEVICE_NEW_STATUS_H
E_CONFIG_FRAME
Definition: ConfigFrame.h:29
uint16_t GetIsResumed() const
std::vector< unsigned char > m_Buffer
The buffer containing partly received frames or higher-layer payload.
Definition: Frame.h:154
uint16_t GetIsAlive() const
static std::shared_ptr< HdlcdClientNewStatus > CreateDeserializedFrame()
static HdlcdClientNewStatus Create(uint16_t a_SerialPortNbr, bool a_bIsResumed, bool a_bIsAlive)
uint16_t GetSerialPortNbr() const