62 void AliveState::Reset() {
63 m_eAliveState = ALIVESTATE_PROBING;
64 m_bFrameWasReceived =
false;
73 assert(m_SendProbeCallback);
74 assert(m_ChangeBaudrateCallback);
76 m_eAliveState = ALIVESTATE_PROBING;
77 m_bFrameWasReceived =
false;
78 m_StateTimer.cancel();
79 m_ProbeTimer.cancel();
82 m_SendProbeCallback();
90 m_StateTimer.cancel();
91 m_ProbeTimer.cancel();
102 m_SendProbeCallback = a_SendProbeCallback;
112 m_ChangeBaudrateCallback = a_ChangeBaudrateCallback;
124 m_bFrameWasReceived =
true;
125 if (m_eAliveState == ALIVESTATE_PROBING) {
127 m_eAliveState = ALIVESTATE_FOUND;
130 m_eAliveState = ALIVESTATE_FOUND;
143 return ((m_eAliveState == ALIVESTATE_FOUND) || (m_eAliveState == ALIVESTATE_REPROBING));
150 void AliveState::StartStateTimer() {
151 auto self(shared_from_this());
152 m_StateTimer.expires_from_now(boost::posix_time::seconds(15));
153 m_StateTimer.async_wait([
this,
self](
const boost::system::error_code& ec) {
166 void AliveState::StartProbeTimer() {
167 auto self(shared_from_this());
168 m_ProbeTimer.expires_from_now(boost::posix_time::milliseconds(500));
169 m_ProbeTimer.async_wait([
this,
self](
const boost::system::error_code& ec) {
182 void AliveState::OnStateTimeout() {
183 if (m_eAliveState == ALIVESTATE_FOUND) {
184 if (m_bFrameWasReceived) {
185 m_bFrameWasReceived =
false;
187 m_eAliveState = ALIVESTATE_REPROBING;
189 }
else if (m_eAliveState == ALIVESTATE_REPROBING) {
190 if (!m_bFrameWasReceived) {
191 m_eAliveState = ALIVESTATE_PROBING;
203 void AliveState::OnProbeTimeout() {
204 if (m_eAliveState == ALIVESTATE_PROBING) {
206 if ((m_ProbeCounter = ((m_ProbeCounter + 1) & 0x03)) == 0) {
207 m_ChangeBaudrateCallback();
210 m_SendProbeCallback();
211 }
else if (m_eAliveState == ALIVESTATE_REPROBING) {
212 m_SendProbeCallback();
AliveState(boost::asio::io_service &a_IOService)
The constructor of AliveState objects.
bool IsAlive() const
Query whether the related serialport is currently considered alive.
void SetSendProbeCallback(std::function< void()> a_SendProbeCallback)
Register callback method for sending a probe request via HDLC.
~AliveState()
The destructor of AliveState objects.
bool OnFrameReceived()
Indicate that a HDLC frame was received via the related serial port.
void Stop()
Stop all activities.
void SetChangeBaudrateCallback(std::function< void()> a_ChangeBaudrateCallback)
Register callback method for changing the baud rate of the related serial port.
void Start()
Start all activities.
This file contains the header declaration of class AliveState.