4
4
#include < cstring>
5
5
#include < iostream>
6
6
#include < memory>
7
+ #include < vector>
8
+ #include < algorithm>
7
9
8
10
#include < arpa/inet.h>
9
11
#include < netdb.h>
@@ -119,7 +121,7 @@ std::shared_ptr<client> init_client(const std::string& hostname,
119
121
std::string cmd;
120
122
121
123
auto do_cmd = [&](const std::string& op, const std::string& val) {
122
- const size_t max_res_len = 64 ;
124
+ const size_t max_res_len = 4095 ;
123
125
char read_buf[max_res_len + 1 ];
124
126
125
127
ssize_t len;
@@ -165,6 +167,20 @@ std::shared_ptr<client> init_client(const std::string& hostname,
165
167
}
166
168
return res;
167
169
};
170
+
171
+ auto str_tok = [&](const std::string &str, const std::string delim) {
172
+ auto start = str.find_first_not_of (delim);
173
+ auto end = start;
174
+ std::vector<std::string> tokens;
175
+
176
+ while (start != std::string::npos){
177
+ end = str.find_first_of (delim, start);
178
+ tokens.push_back (str.substr (start, end-start));
179
+ start = str.find_first_not_of (delim, end);
180
+ }
181
+
182
+ return tokens;
183
+ };
168
184
169
185
bool success = true ;
170
186
success &= do_cmd_chk (" set_udp_port_lidar" , std::to_string (lidar_port));
@@ -176,9 +192,50 @@ std::shared_ptr<client> init_client(const std::string& hostname,
176
192
/* *
177
193
* @note Added to support advanced mode parameters configuration
178
194
*/
195
+ // read the sensor information
196
+ std::string version_str = std::string (" " );
197
+ std::string product_str = std::string (" " );
198
+ bool has_pulsemode = true ;
199
+ auto sensor_info_str = get_cmd (" get_sensor_info" , " " );
200
+ auto tokens = str_tok (sensor_info_str, std::string (" ,: \" " ));
201
+ auto pos = std::find (tokens.begin (), tokens.end (), " build_rev" );
202
+ if (pos != tokens.end ()) {
203
+ version_str = *(pos+1 );
204
+ }
205
+ pos = std::find (tokens.begin (), tokens.end (), " prod_line" );
206
+ if (pos != tokens.end ()) {
207
+ product_str = *(pos+1 );
208
+ }
209
+ if (product_str == std::string (" " ) || version_str == std::string (" " )) {
210
+ std::cout << " Error: Failed to read product name and firmware version." << std::endl;
211
+ return std::shared_ptr<client>();
212
+ }
213
+ std::cout << " Ouster model \" " << product_str << " \" , firmware version \" " << version_str << " \" " << std::endl;
214
+ // TODO: support OS-1-16 and OS-1-128
215
+ if (product_str != std::string (" OS-1-64" )) {
216
+ std::cout << " Error: this driver currently only supports Ouster model \" OS-1-64\" ." << std::endl;
217
+ return std::shared_ptr<client>();
218
+ }
219
+
220
+ auto ver_numbers = str_tok (version_str, std::string (" v." ));
221
+ // check the minor version
222
+ auto ver_major = std::stoi (ver_numbers[0 ], nullptr );
223
+ auto ver_minor = std::stoi (ver_numbers[1 ], nullptr );
224
+ if (ver_major < 1 || ver_minor < 7 ) {
225
+ std::cout << " Error: Firmware version \" " << version_str << " \" is not supported, please upgrade" << std::endl;
226
+ return std::shared_ptr<client>();
227
+ }
228
+ if (std::stoi (ver_numbers[1 ], nullptr ) >= 10 ) {
229
+ std::cout << " On firmware version \" " << version_str << " \" the \" pulse_mode\" parameter is no longer available, will ignore it." << std::endl;
230
+ has_pulsemode = false ;
231
+ }
232
+
179
233
// read the current settings
180
234
auto curr_operation_mode_str = get_cmd (" get_config_param" , " active lidar_mode" );
181
- auto curr_pulse_mode_str = get_cmd (" get_config_param" , " active pulse_mode" );
235
+ auto curr_pulse_mode_str = std::string (" " );
236
+ if (has_pulsemode) {
237
+ curr_pulse_mode_str = get_cmd (" get_config_param" , " active pulse_mode" );
238
+ }
182
239
auto curr_window_rejection_str = get_cmd (" get_config_param" , " active window_rejection_enable" );
183
240
bool do_configure = false ;
184
241
success = true ;
@@ -188,7 +245,7 @@ std::shared_ptr<client> init_client(const std::string& hostname,
188
245
success &= do_cmd_chk (" set_config_param" , " lidar_mode " + _operation_mode_str);
189
246
do_configure = true ;
190
247
}
191
- if (curr_pulse_mode_str != _pulse_mode_str) {
248
+ if (has_pulsemode && ( curr_pulse_mode_str != _pulse_mode_str) ) {
192
249
success &= do_cmd_chk (" set_config_param" , " pulse_mode " + _pulse_mode_str);
193
250
do_configure = true ;
194
251
}
0 commit comments