@@ -53,15 +53,11 @@ void DrillingMachineSimulationThread::init()
5353
5454 fawkes::MutexLocker lock2 (&drill_machine_mutex_);
5555
56- // First time
57- if (!last_status_msg_.has_state ())
58- {
59- last_status_msg_.set_state (DrillingMachineStatus::AT_TOP);
60- last_status_msg_.set_is_device_connected (true );
61- tick_ = ENCODER_MAX_;
62- last_command_msg_.set_command (DrillingMachineCommand::MOVE_UP);
63- logger->log_info (" DrillingMachineSim" , " simulation initialized to AT_TOP, tick at %d" , tick_);
64- }
56+ last_status_msg_.set_state (DrillingMachineStatus::AT_TOP);
57+ last_status_msg_.set_is_device_connected (true );
58+ tick_ = ENCODER_MAX_;
59+ last_command_msg_.set_command (DrillingMachineCommand::MOVE_UP);
60+ logger->log_info (" DrillingMachineSim" , " simulation initialized to AT_TOP, tick at %d" , tick_);
6561
6662 fawkes::MutexLocker lock (clips_mutex);
6763
@@ -80,6 +76,7 @@ void DrillingMachineSimulationThread::finalize()
8076
8177void DrillingMachineSimulationThread::loop ()
8278{
79+ fawkes::MutexLocker lock2 (&drill_machine_mutex_);
8380 if (last_command_msg_.command () == DrillingMachineCommand::MOVE_DOWN)
8481 {
8582 if (tick_ > 1 )
@@ -107,6 +104,7 @@ void DrillingMachineSimulationThread::loop()
107104
108105DrillingMachineStatus::State DrillingMachineSimulationThread::clips_get_device_state ()
109106{
107+ fawkes::MutexLocker lock2 (&drill_machine_mutex_);
110108 if (last_status_msg_.has_state ())
111109 {
112110 return last_status_msg_.state ();
@@ -116,6 +114,7 @@ DrillingMachineStatus::State DrillingMachineSimulationThread::clips_get_device_s
116114
117115int DrillingMachineSimulationThread::clips_is_device_connected ()
118116{
117+ fawkes::MutexLocker lock2 (&drill_machine_mutex_);
119118 return (last_status_msg_.has_is_device_connected () && last_status_msg_.is_device_connected ());
120119}
121120
@@ -133,11 +132,11 @@ void DrillingMachineSimulationThread::moveDrill(DrillingMachineCommand::Command
133132{
134133 // prevent sending to many messages to the device
135134 boost::posix_time::time_duration time_diff;
135+ fawkes::MutexLocker lock2 (&drill_machine_mutex_);
136136 time_diff = boost::posix_time::microsec_clock::local_time () - last_sent_command_timestamp_;
137137 if (time_diff.total_milliseconds () < 200 )
138138 return ;
139139
140- fawkes::MutexLocker lock2 (&drill_machine_mutex_);
141140 last_command_msg_.set_command (drill_command);
142141 last_sent_command_timestamp_ = boost::posix_time::microsec_clock::local_time ();
143142
0 commit comments