HDLC-Daemon
HdlcFrame.h
Go to the documentation of this file.
1 
37 #ifndef HDLC_FRAME_H
38 #define HDLC_FRAME_H
39 
40 #include <string>
41 #include <vector>
42 
43 class HdlcFrame {
44 public:
45  HdlcFrame(): m_eHDLCFrameType(HDLC_FRAMETYPE_UNSET), m_PF(false), m_RSeq(0), m_SSeq(0) {}
46 
47  void SetAddress(unsigned char a_Address) { m_Address = a_Address; }
48  unsigned char GetAddress() const { return m_Address; }
49 
50  typedef enum {
69  void SetHDLCFrameType(E_HDLC_FRAMETYPE a_eHDLCFrameType) { m_eHDLCFrameType = a_eHDLCFrameType; }
70  E_HDLC_FRAMETYPE GetHDLCFrameType() const { return m_eHDLCFrameType; }
71  bool IsEmpty() const { return m_eHDLCFrameType == HDLC_FRAMETYPE_UNSET; }
72  bool IsIFrame() const { return (m_eHDLCFrameType == HDLC_FRAMETYPE_I); }
73  bool IsSFrame() const { return ((m_eHDLCFrameType >= HDLC_FRAMETYPE_S_RR) && (m_eHDLCFrameType <= HDLC_FRAMETYPE_S_SREJ)); }
74  bool IsUFrame() const { return ((m_eHDLCFrameType >= HDLC_FRAMETYPE_U_UI) && (m_eHDLCFrameType <= HDLC_FRAMETYPE_U_XID)); }
75 
76  void SetPF(bool a_PF) { if (a_PF) { m_PF = 0x10; } else { m_PF = 0; } }
77  bool IsPF() const { return ( m_PF & 0x10); }
78 
79  void SetRSeq(unsigned char a_RSeq) { m_RSeq = a_RSeq; }
80  unsigned char GetRSeq() const { return m_RSeq; }
81 
82  void SetSSeq(unsigned char a_SSeq) { m_SSeq = a_SSeq; }
83  unsigned char GetSSeq() const { return m_SSeq; }
84 
85  void SetPayload(const std::vector<unsigned char> &a_Payload) { m_Payload = a_Payload; }
86  const std::vector<unsigned char>& GetPayload() const { return m_Payload; }
87  bool HasPayload() const { return (m_Payload.empty() == false); }
88 
89  const std::vector<unsigned char> Dissect() const;
90 
91 private:
92  // Members
93  unsigned char m_Address;
94  E_HDLC_FRAMETYPE m_eHDLCFrameType;
95  unsigned char m_PF;
96  unsigned char m_RSeq;
97  unsigned char m_SSeq;
98  std::vector<unsigned char> m_Payload;
99 };
100 
101 #endif // HDLC_FRAME_H
void SetRSeq(unsigned char a_RSeq)
Definition: HdlcFrame.h:79
HdlcFrame()
Definition: HdlcFrame.h:45
const std::vector< unsigned char > Dissect() const
Definition: HdlcFrame.cpp:41
bool HasPayload() const
Definition: HdlcFrame.h:87
void SetHDLCFrameType(E_HDLC_FRAMETYPE a_eHDLCFrameType)
Definition: HdlcFrame.h:69
E_HDLC_FRAMETYPE
Definition: HdlcFrame.h:50
void SetPayload(const std::vector< unsigned char > &a_Payload)
Definition: HdlcFrame.h:85
E_HDLC_FRAMETYPE GetHDLCFrameType() const
Definition: HdlcFrame.h:70
bool IsEmpty() const
Definition: HdlcFrame.h:71
unsigned char GetSSeq() const
Definition: HdlcFrame.h:83
unsigned char GetRSeq() const
Definition: HdlcFrame.h:80
bool IsIFrame() const
Definition: HdlcFrame.h:72
void SetAddress(unsigned char a_Address)
Definition: HdlcFrame.h:47
bool IsSFrame() const
Definition: HdlcFrame.h:73
unsigned char GetAddress() const
Definition: HdlcFrame.h:48
bool IsUFrame() const
Definition: HdlcFrame.h:74
bool IsPF() const
Definition: HdlcFrame.h:77
void SetSSeq(unsigned char a_SSeq)
Definition: HdlcFrame.h:82
void SetPF(bool a_PF)
Definition: HdlcFrame.h:76
const std::vector< unsigned char > & GetPayload() const
Definition: HdlcFrame.h:86