HDLC-Daemon
ProtocolState.h
Go to the documentation of this file.
1 
37 #ifndef PROTOCOL_STATE_H
38 #define PROTOCOL_STATE_H
39 
40 #include <vector>
41 #include <boost/asio.hpp>
42 #include <memory>
43 #include <deque>
44 #include "AliveState.h"
45 #include "HdlcFrame.h"
46 #include "FrameParser.h"
47 class ISerialPortHandler;
48 
49 class ProtocolState: public std::enable_shared_from_this<ProtocolState> {
50 public:
51  ProtocolState(std::shared_ptr<ISerialPortHandler> a_SerialPortHandler, boost::asio::io_service& a_IOService);
52 
53  void Start();
54  void Stop();
55  void Shutdown();
56 
57  void SendPayload(const std::vector<unsigned char> &a_Payload, bool a_bReliable);
58  void TriggerNextHDLCFrame();
59  void AddReceivedRawBytes(const unsigned char* a_Buffer, size_t a_Bytes);
60  void InterpretDeserializedFrame(const std::vector<unsigned char> &a_Payload, const HdlcFrame& a_HdlcFrame, bool a_bMessageInvalid);
61 
62  // Query state
63  bool IsAlive() const { return m_AliveState->IsAlive(); }
64  bool IsRunning() const { return m_bStarted; }
65 
66 private:
67  // Internal helpers
68  void Reset();
69  void OpportunityForTransmission();
70  HdlcFrame PrepareIFrame();
71  HdlcFrame PrepareSFrameRR();
72  HdlcFrame PrepareSFrameSREJ();
73  HdlcFrame PrepareUFrameUI();
74  HdlcFrame PrepareUFrameTEST();
75 
76  // Members
77  bool m_bStarted;
78  bool m_bAwaitsNextHDLCFrame;
79  unsigned char m_SSeqOutgoing; // The sequence number we are going to use for the transmission of the next packet
80  unsigned char m_RSeqIncoming; // The start of the RX window we offer our peer, defines which packets we expect
81 
82  // State of pending actions
83  bool m_bSendProbe;
84  bool m_bPeerStoppedFlow; // RNR condition
85  bool m_bPeerStoppedFlowNew; // RNR condition
86  bool m_bPeerStoppedFlowQueried; // RNR condition
87  bool m_bPeerRequiresAck;
88  bool m_bWaitForAck;
89  std::deque<unsigned char> m_SREJs;
90 
91  // Parser and generator
92  std::shared_ptr<ISerialPortHandler> m_SerialPortHandler;
93  FrameParser m_FrameParser;
94 
95  // Wait queues
96  std::deque<std::vector<unsigned char>> m_WaitQueueReliable;
97  std::deque<std::vector<unsigned char>> m_WaitQueueUnreliable;
98 
99  // Alive state
100  std::shared_ptr<AliveState> m_AliveState;
101 
102  // Timer
103  boost::asio::deadline_timer m_Timer;
104  bool m_bAliveReceivedSometing;
105 };
106 
107 #endif // PROTOCOL_STATE_H
void TriggerNextHDLCFrame()
Copyright (c) 2016, Florian Evers, florian-evers@gmx.de All rights reserved.
bool IsRunning() const
Definition: ProtocolState.h:64
void InterpretDeserializedFrame(const std::vector< unsigned char > &a_Payload, const HdlcFrame &a_HdlcFrame, bool a_bMessageInvalid)
ProtocolState(std::shared_ptr< ISerialPortHandler > a_SerialPortHandler, boost::asio::io_service &a_IOService)
Copyright (c) 2016, Florian Evers, florian-evers@gmx.de All rights reserved.
void SendPayload(const std::vector< unsigned char > &a_Payload, bool a_bReliable)
bool IsAlive() const
Definition: ProtocolState.h:63
This file contains the header declaration of class AliveState.
void AddReceivedRawBytes(const unsigned char *a_Buffer, size_t a_Bytes)