25 #include <sys/types.h> 26 #include <sys/socket.h> 27 #include <netinet/in.h> 28 #include <arpa/inet.h> 37 #include "console_bridge/console.h" 51 logDebug(
"Creating non-blocking socket.");
52 socket_fd_ = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
55 struct sockaddr_in stSockAddr;
56 stSockAddr.sin_family = PF_INET;
57 stSockAddr.sin_port = htons(port);
58 inet_pton(AF_INET, host.c_str(), &stSockAddr.sin_addr);
60 logDebug(
"Connecting socket to laser.");
66 logDebug(
"Connected succeeded.");
89 sprintf(buf,
"%c%s%c", 0x02,
"sMN LMCstartmeas", 0x03);
95 logWarn(
"invalid packet recieved");
97 logDebug(
"RX: %s", buf);
103 sprintf(buf,
"%c%s%c", 0x02,
"sMN LMCstopmeas", 0x03);
109 logWarn(
"invalid packet recieved");
111 logDebug(
"RX: %s", buf);
117 sprintf(buf,
"%c%s%c", 0x02,
"sRN STlms", 0x03);
123 logWarn(
"invalid packet recieved");
125 logDebug(
"RX: %s", buf);
128 sscanf((buf + 10),
"%d", &ret);
137 sprintf(buf,
"%c%s%c", 0x02,
"sMN SetAccessMode 03 F4724744", 0x03);
140 struct timeval timeout;
152 result = select(
socket_fd_ + 1, &readset, NULL, NULL, &timeout);
159 logWarn(
"invalid packet recieved");
161 logDebug(
"RX: %s", buf);
168 sprintf(buf,
"%c%s%c", 0x02,
"sRN LMPscancfg", 0x03);
174 logWarn(
"invalid packet recieved");
176 logDebug(
"RX: %s", buf);
186 sprintf(buf,
"%c%s %X +1 %X %X %X%c", 0x02,
"sMN mLMPsetscancfg",
200 sprintf(buf,
"%c%s %02X 00 %d %d 0 %02X 00 %d %d 0 %d +%d%c", 0x02,
204 logDebug(
"TX: %s", buf);
215 sprintf(buf,
"%c%s%c", 0x02,
"sRN LMPoutputRange", 0x03);
229 sprintf(buf,
"%c%s %d%c", 0x02,
"sEN LMDscandata", start, 0x03);
236 logError(
"invalid packet recieved");
239 logDebug(
"RX: %s", buf);
257 logDebug(
"entering select()", tv.tv_usec);
258 int retval = select(
socket_fd_ + 1, &rfds, NULL, NULL, &tv);
259 logDebug(
"returned %d from select()", retval);
286 char* tok = strtok(buffer,
" ");
287 tok = strtok(NULL,
" ");
288 tok = strtok(NULL,
" ");
289 tok = strtok(NULL,
" ");
290 tok = strtok(NULL,
" ");
291 tok = strtok(NULL,
" ");
292 tok = strtok(NULL,
" ");
293 tok = strtok(NULL,
" ");
294 tok = strtok(NULL,
" ");
295 tok = strtok(NULL,
" ");
296 tok = strtok(NULL,
" ");
297 tok = strtok(NULL,
" ");
298 tok = strtok(NULL,
" ");
299 tok = strtok(NULL,
" ");
300 tok = strtok(NULL,
" ");
301 tok = strtok(NULL,
" ");
302 tok = strtok(NULL,
" ");
303 tok = strtok(NULL,
" ");
304 tok = strtok(NULL,
" ");
306 sscanf(tok,
"%d", &NumberEncoders);
307 for (
int i = 0; i < NumberEncoders; i++)
309 tok = strtok(NULL,
" ");
310 tok = strtok(NULL,
" ");
313 tok = strtok(NULL,
" ");
314 int NumberChannels16Bit;
315 sscanf(tok,
"%d", &NumberChannels16Bit);
316 logDebug(
"NumberChannels16Bit : %d", NumberChannels16Bit);
318 for (
int i = 0; i < NumberChannels16Bit; i++)
322 tok = strtok(NULL,
" ");
323 sscanf(tok,
"%s", content);
324 if (!strcmp(content,
"DIST1"))
328 else if (!strcmp(content,
"DIST2"))
332 else if (!strcmp(content,
"RSSI1"))
336 else if (!strcmp(content,
"RSSI2"))
340 tok = strtok(NULL,
" ");
341 tok = strtok(NULL,
" ");
342 tok = strtok(NULL,
" ");
343 tok = strtok(NULL,
" ");
344 tok = strtok(NULL,
" ");
346 sscanf(tok,
"%X", &NumberData);
347 logDebug(
"NumberData : %d", NumberData);
366 for (
int i = 0; i < NumberData; i++)
369 tok = strtok(NULL,
" ");
370 sscanf(tok,
"%X", &dat);
374 data->
dist1[i] = dat;
378 data->
dist2[i] = dat;
382 data->
rssi1[i] = dat;
386 data->
rssi2[i] = dat;
392 tok = strtok(NULL,
" ");
393 int NumberChannels8Bit;
394 sscanf(tok,
"%d", &NumberChannels8Bit);
395 logDebug(
"NumberChannels8Bit : %d\n", NumberChannels8Bit);
397 for (
int i = 0; i < NumberChannels8Bit; i++)
401 tok = strtok(NULL,
" ");
402 sscanf(tok,
"%s", content);
403 if (!strcmp(content,
"DIST1"))
407 else if (!strcmp(content,
"DIST2"))
411 else if (!strcmp(content,
"RSSI1"))
415 else if (!strcmp(content,
"RSSI2"))
419 tok = strtok(NULL,
" ");
420 tok = strtok(NULL,
" ");
421 tok = strtok(NULL,
" ");
422 tok = strtok(NULL,
" ");
423 tok = strtok(NULL,
" ");
425 sscanf(tok,
"%X", &NumberData);
426 logDebug(
"NumberData : %d\n", NumberData);
444 for (
int i = 0; i < NumberData; i++)
447 tok = strtok(NULL,
" ");
448 sscanf(tok,
"%X", &dat);
452 data->
dist1[i] = dat;
456 data->
dist2[i] = dat;
460 data->
rssi1[i] = dat;
464 data->
rssi2[i] = dat;
473 sprintf(buf,
"%c%s%c", 0x02,
"sMN mEEwriteall", 0x03);
480 logWarn(
"invalid packet recieved");
482 logDebug(
"RX: %s", buf);
488 sprintf(buf,
"%c%s%c", 0x02,
"sMN Run", 0x03);
495 logWarn(
"invalid packet recieved");
497 logDebug(
"RX: %s", buf);
uint16_t rssi2[1082]
Remission values for the second reflected pulse.
int startAngle
Start angle. 1/10000 degree.
Structure containing single scan message.
void setScanDataCfg(const scanDataCfg &cfg)
Set scan data configuration. Set format of scan message returned by device.
scanCfg getScanCfg() const
Get current scan configuration. Get scan configuration :
status_t queryStatus()
Get current status of LMS1xx device.
scanOutputRange getScanOutputRange() const
Get current output range configuration. Get output range configuration :
uint16_t dist1[1082]
Radial distance for the first reflected pulse.
void login()
Log into LMS1xx unit. Increase privilege level, giving ability to change device configuration.
int resolution
Remission resolution. Defines whether the remission values are output with 8-bit or 16bit resolution...
bool remission
Remission. Defines whether remission values are output.
int outputInterval
Output interval. Defines which scan is output.
Structure containing scan data configuration.
int angleResolution
Scanning resolution. 1/10000 degree.
int stopAngle
Stop angle. 1/10000 degree.
int encoder
Encoders channels. Defines which output channel is activated.
int rssi_len2
Number of samples in rssi2.
void stopMeas()
Stop measurements. After receiving this command LMS1xx unit stop spinning laser and measuring...
int scaningFrequency
Scanning frequency. 1/100 Hz.
void setScanCfg(const scanCfg &cfg)
Set scan configuration. Get scan configuration :
Structure containing scan configuration.
bool getScanData(scanData *scan_data)
Receive single scan message.
int dist_len2
Number of samples in dist2.
void startDevice()
The device is returned to the measurement mode after configuration.
void scanContinous(int start)
Start or stop continuous data acquisition. After reception of this command device start or stop conti...
int outputChannel
Output channels. Defines which output channel is activated.
int angleResolution
Scanning resolution. 1/10000 degree.
int dist_len1
Number of samples in dist1.
void startMeas()
Start measurements. After receiving this command LMS1xx unit starts spinning laser and measuring...
bool isConnected()
Get status of connection.
void disconnect()
Disconnect from LMS1xx device.
void connect(std::string host, int port=2111)
Connect to LMS1xx.
int stopAngle
Stop angle. 1/10000 degree.
int startAngle
Start angle. 1/10000 degree.
Structure containing scan output range configuration.
void saveConfig()
Save data permanently. Parameters are saved in the EEPROM of the LMS and will also be available after...
bool position
Position. Defines whether position values are output.
uint16_t rssi1[1082]
Remission values for the first reflected pulse.
static void parseScanData(char *buf, scanData *data)
Receive single scan message.
int rssi_len1
Number of samples in rssi1.
bool deviceName
Device name. Determines whether the device name is to be output.
uint16_t dist2[1082]
Radial distance for the second reflected pulse.