@@ -86,6 +86,54 @@ int SickTimCommon::stop_scanner()
86
86
return result;
87
87
}
88
88
89
+ bool SickTimCommon::rebootScanner ()
90
+ {
91
+ /*
92
+ * Set Maintenance access mode to allow reboot to be sent
93
+ */
94
+ std::vector<unsigned char > access_reply;
95
+ int result = sendSOPASCommand (" \x02 sMN SetAccessMode 03 F4724744\x03\0 " , &access_reply);
96
+ if (result != 0 )
97
+ {
98
+ ROS_ERROR (" SOPAS - Error setting access mode" );
99
+ diagnostics_.broadcast (diagnostic_msgs::DiagnosticStatus::ERROR, " SOPAS - Error setting access mode." );
100
+ return false ;
101
+ }
102
+ std::string access_reply_str = replyToString (access_reply);
103
+ if (access_reply_str != " sAN SetAccessMode 1" )
104
+ {
105
+ ROS_ERROR_STREAM (" SOPAS - Error setting access mode, unexpected response : " << access_reply_str);
106
+ diagnostics_.broadcast (diagnostic_msgs::DiagnosticStatus::ERROR, " SOPAS - Error setting access mode." );
107
+ return false ;
108
+ }
109
+
110
+ /*
111
+ * Send reboot command
112
+ */
113
+ std::vector<unsigned char > reboot_reply;
114
+ result = sendSOPASCommand (" \x02 sMN mSCreboot\x03\0 " , &reboot_reply);
115
+ if (result != 0 )
116
+ {
117
+ ROS_ERROR (" SOPAS - Error rebooting scanner" );
118
+ diagnostics_.broadcast (diagnostic_msgs::DiagnosticStatus::ERROR, " SOPAS - Error rebooting device." );
119
+ return false ;
120
+ }
121
+ std::string reboot_reply_str = replyToString (reboot_reply);
122
+ if (reboot_reply_str != " sAN mSCreboot" )
123
+ {
124
+ ROS_ERROR_STREAM (" SOPAS - Error rebooting scanner, unexpected response : " << reboot_reply_str);
125
+ diagnostics_.broadcast (diagnostic_msgs::DiagnosticStatus::ERROR, " SOPAS - Error setting access mode." );
126
+ return false ;
127
+ }
128
+
129
+ ROS_INFO (" SOPAS - Rebooted scanner" );
130
+
131
+ // Wait a few seconds after rebooting
132
+ ros::Duration (15.0 ).sleep ();
133
+
134
+ return true ;
135
+ }
136
+
89
137
SickTimCommon::~SickTimCommon ()
90
138
{
91
139
delete diagnosticPub_;
@@ -135,20 +183,8 @@ int SickTimCommon::init_scanner()
135
183
}
136
184
137
185
// set hardware ID based on DeviceIdent and SerialNumber
138
- identReply.push_back (0 ); // add \0 to convert to string
139
- serialReply.push_back (0 );
140
- std::string identStr;
141
- for (std::vector<unsigned char >::iterator it = identReply.begin (); it != identReply.end (); it++)
142
- {
143
- if (*it > 13 ) // filter control characters for display
144
- identStr.push_back (*it);
145
- }
146
- std::string serialStr;
147
- for (std::vector<unsigned char >::iterator it = serialReply.begin (); it != serialReply.end (); it++)
148
- {
149
- if (*it > 13 )
150
- serialStr.push_back (*it);
151
- }
186
+ std::string identStr = replyToString (identReply);
187
+ std::string serialStr = replyToString (serialReply);
152
188
diagnostics_.setHardwareID (identStr + " " + serialStr);
153
189
154
190
if (!isCompatibleDevice (identStr))
@@ -165,6 +201,44 @@ int SickTimCommon::init_scanner()
165
201
diagnostics_.broadcast (diagnostic_msgs::DiagnosticStatus::ERROR, " SOPAS - Error reading variable 'FirmwareVersion'." );
166
202
}
167
203
204
+ /*
205
+ * Read Device State
206
+ */
207
+ const char requestDeviceState[] = {" \x02 sRN SCdevicestate\x03\0 " };
208
+ std::vector<unsigned char > deviceStateReply;
209
+ result = sendSOPASCommand (requestDeviceState, &deviceStateReply);
210
+ if (result != 0 )
211
+ {
212
+ ROS_ERROR (" SOPAS - Error reading variable 'devicestate'." );
213
+ diagnostics_.broadcast (diagnostic_msgs::DiagnosticStatus::ERROR, " SOPAS - Error reading variable 'devicestate'." );
214
+ }
215
+ std::string deviceStateReplyStr = replyToString (deviceStateReply);
216
+
217
+ /*
218
+ * Process device state, 0=Busy, 1=Ready, 2=Error
219
+ * If configuration parameter is set, try resetting device in error state
220
+ */
221
+ if (deviceStateReplyStr == " sRA SCdevicestate 0" )
222
+ {
223
+ ROS_WARN (" Laser is busy" );
224
+ }
225
+ else if (deviceStateReplyStr == " sRA SCdevicestate 1" )
226
+ {
227
+ ROS_DEBUG (" Laser is ready" );
228
+ }
229
+ else if (deviceStateReplyStr == " sRA SCdevicestate 2" )
230
+ {
231
+ ROS_ERROR_STREAM (" Laser reports error state : " << deviceStateReplyStr);
232
+ if (config_.auto_reboot )
233
+ {
234
+ rebootScanner ();
235
+ }
236
+ }
237
+ else
238
+ {
239
+ ROS_WARN_STREAM (" Laser reports unknown devicestate : " << deviceStateReplyStr);
240
+ }
241
+
168
242
/*
169
243
* Start streaming 'LMDscandata'.
170
244
*/
@@ -180,6 +254,19 @@ int SickTimCommon::init_scanner()
180
254
return ExitSuccess;
181
255
}
182
256
257
+ std::string sick_tim::SickTimCommon::replyToString (const std::vector<unsigned char > &reply)
258
+ {
259
+ std::string reply_str;
260
+ for (std::vector<unsigned char >::const_iterator it = reply.begin (); it != reply.end (); it++)
261
+ {
262
+ if (*it > 13 ) // filter control characters for display
263
+ {
264
+ reply_str.push_back (*it);
265
+ }
266
+ }
267
+ return reply_str;
268
+ }
269
+
183
270
bool sick_tim::SickTimCommon::isCompatibleDevice (const std::string identStr) const
184
271
{
185
272
char device_string[7 ];
0 commit comments