18 #include <sys/types.h> 19 #include <sys/socket.h> 20 #include <netinet/in.h> 21 #include <arpa/inet.h> 42 sockDesc = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
44 struct sockaddr_in stSockAddr;
46 stSockAddr.sin_family = PF_INET;
47 stSockAddr.sin_port = htons(port);
48 Res = inet_pton(AF_INET, host.c_str(), &stSockAddr.sin_addr);
72 sprintf(buf,
"%c%s%c", 0x02,
"sMN LMCstartmeas", 0x03);
74 ssize_t res = write(
sockDesc, buf, strlen(buf));
87 sprintf(buf,
"%c%s%c", 0x02,
"sMN LMCstopmeas", 0x03);
89 ssize_t res = write(
sockDesc, buf, strlen(buf));
102 sprintf(buf,
"%c%s%c", 0x02,
"sRN STlms", 0x03);
104 ssize_t res = write(
sockDesc, buf, strlen(buf));
114 sscanf((buf + 10),
"%d", &ret);
121 sprintf(buf,
"%c%s%c", 0x02,
"sMN SetAccessMode 03 F4724744", 0x03);
123 ssize_t res = write(
sockDesc, buf, strlen(buf));
137 sprintf(buf,
"%c%s%c", 0x02,
"sRN LMPscancfg", 0x03);
139 ssize_t res = write(
sockDesc, buf, strlen(buf));
149 sscanf(buf + 1,
"%*s %*s %X %*d %X %X %X", &cfg.scaningFrequency,
150 &cfg.angleResolution, &cfg.startAngle, &cfg.stopAngle);
156 sprintf(buf,
"%c%s %X +1 %X %X %X%c", 0x02,
"sMN mLMPsetscancfg",
157 cfg.scaningFrequency, cfg.angleResolution, cfg.startAngle,
158 cfg.stopAngle, 0x03);
160 ssize_t res = write(
sockDesc, buf, strlen(buf));
169 sprintf(buf,
"%c%s %02X 00 %d %d 0 %02X 00 %d %d 0 %d +%d%c", 0x02,
170 "sWN LMDscandatacfg", cfg.outputChannel, cfg.remission ? 1 : 0,
171 cfg.resolution, cfg.encoder, cfg.position ? 1 : 0,
172 cfg.deviceName ? 1 : 0, cfg.timestamp ? 1 : 0, cfg.outputInterval, 0x03);
175 ssize_t res = write(
sockDesc, buf, strlen(buf));
183 sprintf(buf,
"%c%s %d%c", 0x02,
"sEN LMDscandata", start, 0x03);
185 ssize_t res = write(
sockDesc, buf, strlen(buf));
190 printf(
"invalid packet recieved\n");
198 for (
int i = 0; i < 10; i++)
199 ssize_t res = read(
sockDesc, buf, 100);
217 bytes_read = 0; inc = 0;
218 retval = select(
sockDesc + 1, &rfds, NULL, NULL, &tv);
221 bytes_read = read(
sockDesc, buf, 1);
228 else if(bytes_read < 1)
238 }
while(buf[0+inc] != 0x02);
243 bool bFoundEnd =
false;
244 bool bFoundStart =
false;
248 for(i = 0; i < len; i++)
256 if(bFoundEnd && buf[i] == 0x02)
264 char flushBuffer[100000];
265 int bytesFlushed = recv(
sockDesc, flushBuffer, 100000, 0);
278 retval = select(
sockDesc + 1, &rfds, NULL, NULL, &tv);
281 bytes_read = read(
sockDesc, buf + len, 20000 - len);
294 }
while ((buf[len - 1] != 0x03));
299 char* tok = strtok(buf,
" ");
300 tok = strtok(NULL,
" ");
301 tok = strtok(NULL,
" ");
302 tok = strtok(NULL,
" ");
303 tok = strtok(NULL,
" ");
304 tok = strtok(NULL,
" ");
305 tok = strtok(NULL,
" ");
306 tok = strtok(NULL,
" ");
307 tok = strtok(NULL,
" ");
308 tok = strtok(NULL,
" ");
309 tok = strtok(NULL,
" ");
310 tok = strtok(NULL,
" ");
311 tok = strtok(NULL,
" ");
312 tok = strtok(NULL,
" ");
313 tok = strtok(NULL,
" ");
314 tok = strtok(NULL,
" ");
315 tok = strtok(NULL,
" ");
316 tok = strtok(NULL,
" ");
317 tok = strtok(NULL,
" ");
319 sscanf(tok,
"%d", &NumberEncoders);
320 for (
int i = 0; i < NumberEncoders; i++) {
321 tok = strtok(NULL,
" ");
322 tok = strtok(NULL,
" ");
325 tok = strtok(NULL,
" ");
326 int NumberChannels16Bit;
327 sscanf(tok,
"%d", &NumberChannels16Bit);
329 printf(
"NumberChannels16Bit : %d\n", NumberChannels16Bit);
330 for (
int i = 0; i < NumberChannels16Bit; i++) {
333 tok = strtok(NULL,
" ");
334 sscanf(tok,
"%s", content);
335 if (!strcmp(content,
"DIST1")) {
337 }
else if (!strcmp(content,
"DIST2")) {
339 }
else if (!strcmp(content,
"RSSI1")) {
341 }
else if (!strcmp(content,
"RSSI2")) {
344 tok = strtok(NULL,
" ");
345 tok = strtok(NULL,
" ");
346 tok = strtok(NULL,
" ");
347 tok = strtok(NULL,
" ");
348 tok = strtok(NULL,
" ");
350 sscanf(tok,
"%X", &NumberData);
353 printf(
"NumberData : %d\n", NumberData);
356 data.dist_len1 = NumberData;
357 }
else if (type == 1) {
358 data.dist_len2 = NumberData;
359 }
else if (type == 2) {
360 data.rssi_len1 = NumberData;
361 }
else if (type == 3) {
362 data.rssi_len2 = NumberData;
365 for (
int i = 0; i < NumberData; i++) {
367 tok = strtok(NULL,
" ");
368 sscanf(tok,
"%X", &dat);
372 }
else if (type == 1) {
374 }
else if (type == 2) {
376 }
else if (type == 3) {
383 tok = strtok(NULL,
" ");
384 int NumberChannels8Bit;
385 sscanf(tok,
"%d", &NumberChannels8Bit);
387 printf(
"NumberChannels8Bit : %d\n", NumberChannels8Bit);
388 for (
int i = 0; i < NumberChannels8Bit; i++) {
391 tok = strtok(NULL,
" ");
392 sscanf(tok,
"%s", content);
393 if (!strcmp(content,
"DIST1")) {
395 }
else if (!strcmp(content,
"DIST2")) {
397 }
else if (!strcmp(content,
"RSSI1")) {
399 }
else if (!strcmp(content,
"RSSI2")) {
402 tok = strtok(NULL,
" ");
403 tok = strtok(NULL,
" ");
404 tok = strtok(NULL,
" ");
405 tok = strtok(NULL,
" ");
406 tok = strtok(NULL,
" ");
408 sscanf(tok,
"%X", &NumberData);
411 printf(
"NumberData : %d\n", NumberData);
414 data.dist_len1 = NumberData;
415 }
else if (type == 1) {
416 data.dist_len2 = NumberData;
417 }
else if (type == 2) {
418 data.rssi_len1 = NumberData;
419 }
else if (type == 3) {
420 data.rssi_len2 = NumberData;
422 for (
int i = 0; i < NumberData; i++) {
424 tok = strtok(NULL,
" ");
425 sscanf(tok,
"%X", &dat);
429 }
else if (type == 1) {
431 }
else if (type == 2) {
433 }
else if (type == 3) {
443 sprintf(buf,
"%c%s%c", 0x02,
"sMN mEEwriteall", 0x03);
445 ssize_t res = write(
sockDesc, buf, strlen(buf));
458 sprintf(buf,
"%c%s%c", 0x02,
"sMN Run", 0x03);
460 ssize_t res = write(
sockDesc, buf, strlen(buf));
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.
void login()
Log into LMS1xx unit. Increase privilege level, giving ability to change device configuration.
void stopMeas()
Stop measurements. After receiving this command LMS1xx unit stop spinning laser and measuring...
Structure containing single scan message.
Structure containing scan configuration.
void setScanCfg(const scanCfg &cfg)
Set scan configuration. Get scan configuration :
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...
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.
void saveConfig()
Save data permanently. Parameters are saved in the EEPROM of the LMS and will also be available after...
bool getData(scanData &data)
Receive single scan message.
Structure containing scan data configuration.