15 #ifndef PSEN_SCAN_V2_STANDALONE_SCANNER_PROTOCOL_DEF_H 16 #define PSEN_SCAN_V2_STANDALONE_SCANNER_PROTOCOL_DEF_H 25 #include <boost/optional.hpp> 27 #define BOOST_MSM_CONSTRUCTOR_ARG_SIZE 12 // see https://www.boost.org/doc/libs/1_66_0/libs/msm/doc/HTML/ch03s05.html 30 #include <boost/msm/back/state_machine.hpp> 32 #include <boost/msm/front/state_machine_def.hpp> 34 #include <boost/msm/back/tools.hpp> 35 #include <boost/msm/back/metafunctions.hpp> 62 namespace protocol_layer
64 namespace msm = boost::msm;
65 namespace mpl = boost::mpl;
70 #define STATE(state_name)\ 71 class state_name : public msm::front::state<>\ 74 template <class Event, class FSM>\ 75 void on_entry(Event const&, FSM& fsm);\ 77 template <class Event, class FSM>\ 78 void on_exit(Event const&, FSM& fsm);\ 163 STATE(WaitForStartReply);
164 STATE(WaitForMonitoringFrame);
165 STATE(WaitForStopReply);
171 void sendStartRequest(
const T& event);
174 void sendStopRequest(
const T& event);
193 template <
class FSM,
class Event>
194 void exception_caught(Event
const& event, FSM& fsm, std::exception& exception);
196 template <
class FSM,
class Event>
197 void no_transition(Event
const& event, FSM& ,
int state);
214 a_row < Idle, e::StartRequest, WaitForStartReply, &m::sendStartRequest >,
215 a_row < Idle, e::StopRequest, WaitForStopReply, &m::sendStopRequest >,
216 row < WaitForStartReply, e::RawReplyReceived, WaitForMonitoringFrame, &m::notifyUserAboutStart, &m::isAcceptedStartReply >,
217 row < WaitForStartReply, e::RawReplyReceived, Error, &m::notifyUserAboutRefusedStartReply, &m::isRefusedStartReply >,
218 row < WaitForStartReply, e::RawReplyReceived, Error, &m::notifyUserAboutUnknownStartReply, &m::isUnknownStartReply >,
219 a_irow < WaitForStartReply, e::StartTimeout, &m::handleStartRequestTimeout >,
220 a_irow < WaitForMonitoringFrame, e::RawMonitoringFrameReceived, &m::handleMonitoringFrame >,
221 a_irow < WaitForMonitoringFrame, e::MonitoringFrameTimeout, &m::handleMonitoringFrameTimeout >,
222 a_row < WaitForStartReply, e::StopRequest, WaitForStopReply, &m::sendStopRequest >,
223 a_row < WaitForMonitoringFrame, e::StopRequest, WaitForStopReply, &m::sendStopRequest >,
224 _irow < WaitForStopReply, e::RawMonitoringFrameReceived >,
225 row < WaitForStopReply, e::RawReplyReceived, Stopped, &m::notifyUserAboutStop, &m::isAcceptedStopReply >,
226 row < WaitForStopReply, e::RawReplyReceived, Error, &m::notifyUserAboutRefusedStopReply, &m::isRefusedStopReply >,
227 row < WaitForStopReply, e::RawReplyReceived, Error, &m::notifyUserAboutUnknownStopReply, &m::isUnknownStopReply >,
228 _irow < Stopped, e::RawMonitoringFrameReceived >
270 sendMessageWithMeasurements(
const std::vector<data_conversion_layer::monitoring_frame::MessageStamped>& stamped_msg);
276 framesContainMeasurements(
const std::vector<data_conversion_layer::monitoring_frame::MessageStamped>& stamped_msg);
281 std::unique_ptr<util::Watchdog> start_reply_watchdog_{};
283 std::unique_ptr<util::Watchdog> monitoring_frame_watchdog_{};
319 #endif // PSEN_SCAN_V2_STANDALONE_SCANNER_PROTOCOL_DEF_H
Helper for asynchronously sending and receiving data via UDP.
Watchdog factory implementation for scanner interaction timeouts.
std::function< void(const std::string &)> ErrorCallback
Higher level data type representing a single monitoring frame.
std::function< void(const data_conversion_layer::RawDataConstPtr &, const std::size_t &, const int64_t ×tamp)> NewMessageCallback
msm::back::state_machine< ScannerProtocolDef > ScannerStateMachine
State machine handling all events according to the scanner protocol and error handling specification...
const std::chrono::high_resolution_clock::duration Timeout
std::function< void()> ScannerStartedCallback
std::function< void(const LaserScan &)> InformUserAboutLaserScanCallback
std::function< void(const std::string &)> StopErrorCallback
Table describing the state machine which is specified in the scanner protocol.
Contains the events needed to define and implement the scanner protocol.
std::function< void()> TimeoutCallback
communication_layer::UdpClientImpl data_client_
const ScannerStoppedCallback scanner_stopped_callback_
const StartErrorCallback start_error_callback_
const StopErrorCallback stop_error_callback_
Exception thrown when something goes wrong with the scanner reply.
Higher level data type storing the configuration details of the scanner like scanner IP...
const ScannerStartedCallback scanner_started_callback_
Wrapping class for a Message and its corresponding timestamp.
Timeout while waiting for MonitoringFrame.
const InformUserAboutLaserScanCallback inform_user_about_laser_scan_callback_
Root namespace in which the software components to communicate with the scanner (firmware-version: 2)...
Received Start- or Stop-Reply message from scanner device.
Interface to create event timeout callbacks.
communication_layer::UdpClientImpl control_client_
Timeout while waiting for scanner device to start.
static constexpr std::chrono::milliseconds WATCHDOG_TIMEOUT
Definition of the scanner protocol. It is initialized using the StateMachineArgs class.
std::function< void(const std::string &)> StartErrorCallback
const std::function< void()> start_timeout_callback_
ScannerConfiguration config_
const std::function< void()> monitoring_frame_timeout_callback_
virtual ~IWatchdogFactory()=default
std::function< void()> ScannerStoppedCallback
virtual std::unique_ptr< util::Watchdog > create(const util::Watchdog::Timeout &timeout, const TimeoutCallback &timeout_callback)=0
boost::optional< data_conversion_layer::monitoring_frame::Message > zoneset_reference_msg_
#define STATE(state_name)
Higher level data type representing a reply message from the scanner.
Buffers and validates monitoring frames for a scan round.
Received monitoring frame from scanner device.
static constexpr uint32_t DEFAULT_NUM_MSG_PER_ROUND