19 #define snprintf _snprintf
49 unsigned char sum = 0x00;
52 for (i = 0; i < size; ++i) {
57 return (sum & 0x3f) + 0x30;
70 const int expected_ret[],
int timeout,
71 char *receive_buffer,
int receive_buffer_max_size)
73 char *p = receive_buffer;
79 int write_size = (int)strlen(command);
82 if (n != write_size) {
95 }
else if (p && (line_number > 0)
96 && (n < (receive_buffer_max_size - filled_size))) {
104 if (line_number == 0) {
106 if (strncmp(buffer, command, write_size - 1)) {
111 char checksum = buffer[n - 1];
119 if (line_number == 1) {
129 int actual_ret = strtol(buffer, NULL, 10);
131 if (expected_ret[i] == actual_ret) {
142 return (ret < 0) ? ret : (line_number - 1);
178 long current_baudrate,
long next_baudrate)
180 enum { SS_COMMAND_SIZE = 10 };
181 char buffer[SS_COMMAND_SIZE];
185 if (current_baudrate == next_baudrate) {
191 snprintf(buffer, SS_COMMAND_SIZE,
"SS%06ld\n", next_baudrate);
215 long try_baudrate[] = { 19200, 38400, 115200 };
216 int try_times =
sizeof(try_baudrate) /
sizeof(try_baudrate[0]);
220 for (i = 0; i < try_times; ++i) {
221 if (try_baudrate[i] == baudrate) {
222 try_baudrate[i] = try_baudrate[0];
223 try_baudrate[0] = baudrate;
228 for (i = 0; i < try_times; ++i) {
229 enum { RECEIVE_BUFFER_SIZE = 4 };
231 char receive_buffer[RECEIVE_BUFFER_SIZE + 1];
238 receive_buffer, RECEIVE_BUFFER_SIZE);
240 if (!strcmp(receive_buffer,
"E")) {
256 }
else if (!strcmp(receive_buffer,
"0Ee")) {
282 }
else if (!strcmp(
"00P", receive_buffer)) {
297 char receive_buffer[RECEIVE_BUFFER_SIZE];
299 unsigned short received_bits = 0x0000;
304 receive_buffer, RECEIVE_BUFFER_SIZE);
313 for (i = 0; i < (ret - 1); ++i) {
315 if (!strncmp(p,
"DMIN:", 5)) {
317 received_bits |= 0x0001;
319 }
else if (!strncmp(p,
"DMAX:", 5)) {
321 received_bits |= 0x0002;
323 }
else if (!strncmp(p,
"ARES:", 5)) {
325 received_bits |= 0x0004;
327 }
else if (!strncmp(p,
"AMIN:", 5)) {
329 received_bits |= 0x0008;
331 }
else if (!strncmp(p,
"AMAX:", 5)) {
333 received_bits |= 0x0010;
335 }
else if (!strncmp(p,
"AFRT:", 5)) {
337 received_bits |= 0x0020;
339 }
else if (!strncmp(p,
"SCAN:", 5)) {
340 int rpm = strtol(p + 5, NULL, 10);
344 received_bits |= 0x0040;
350 if (received_bits != 0x007f) {
366 const char* p = data;
367 const char* last_p = p + size;
373 value |= *p++ - 0x30;
383 memcpy(buffer, parameter, size);
386 return strtol(buffer, NULL, 10);
391 const char echoback[])
396 if (echoback[1] ==
'S') {
400 }
else if (echoback[1] ==
'D') {
401 if ((echoback[0] ==
'G') || (echoback[0] ==
'M')) {
403 }
else if ((echoback[0] ==
'H') || (echoback[0] ==
'N')) {
406 }
else if (echoback[1] ==
'E') {
407 if ((echoback[0] ==
'G') || (echoback[0] ==
'M')) {
409 }
else if ((echoback[0] ==
'H') || (echoback[0] ==
'N')) {
426 const char echoback[])
431 if (!strcmp(
"QT", echoback)) {
435 line_length = strlen(echoback);
436 if ((line_length == 12) &&
437 ((echoback[0] ==
'G') || (echoback[0] ==
'H'))) {
440 }
else if ((line_length == 15) &&
441 ((echoback[0] ==
'M') || (echoback[0] ==
'N'))) {
449 unsigned short intensity[],
455 int multiecho_index = 0;
459 int data_size = each_size;
462 int multiecho_max_size = 1;
483 if (buffer[line_filled + n - 1] !=
491 line_filled += n - 1;
493 last_p = p + line_filled;
495 while ((last_p - p) >= data_size) {
501 if ((last_p - (p + 1)) < data_size) {
516 index = (step_filled * multiecho_max_size) + multiecho_index;
526 if (is_multiecho && (multiecho_index == 0)) {
530 for (i = 1; i < multiecho_max_size; ++i) {
531 length[index + i] = 0;
535 for (i = 1; i < multiecho_max_size; ++i) {
536 intensity[index + i] = 0;
556 line_filled -= data_size;
560 memmove(buffer, p, line_filled);
569 long *time_stamp,
unsigned long long *system_time_stamp)
575 int extended_timeout = urg->
timeout
613 if (!strncmp(buffer,
"00", 2)) {
623 return receive_data(urg, data, intensity, time_stamp, system_time_stamp);
649 if (system_time_stamp) {
685 const char *device_or_address,
long baudrate_or_port)
688 long baudrate = baudrate_or_port;
699 device_or_address, baudrate_or_port);
702 switch (connection_type) {
798 if (strcmp(buffer,
"00P")) {
803 if (strlen(p) != 5) {
833 char single_scan_ch,
char continuous_scan_ch,
844 if (scan_times >= 100) {
853 write_size = snprintf(buffer,
BUFFER_SIZE,
"%c%c%04d%04d%02d\n",
854 single_scan_ch, scan_type_ch,
859 write_size = snprintf(buffer,
BUFFER_SIZE,
"%c%c%04d%04d%02d%01d%02d\n",
860 continuous_scan_ch, scan_type_ch,
869 if (n != write_size) {
878 int scan_times,
int skip_scan)
887 if ((skip_scan < 0) || (skip_scan > 9)) {
903 'G',
'M', range_byte_ch);
939 return receive_data(urg, data, NULL, time_stamp, system_time_stamp);
944 long data[],
unsigned short intensity[],
945 long *time_stamp,
unsigned long long *system_time_stamp)
951 return receive_data(urg, data, intensity, time_stamp, system_time_stamp);
961 return receive_data(urg, data_multi, NULL, time_stamp, system_time_stamp);
967 unsigned short intensity_multi[],
968 long *time_stamp,
unsigned long long *system_time_stamp)
974 return receive_data(urg, data_multi, intensity_multi, time_stamp, system_time_stamp);
980 enum { MAX_READ_TIMES = 3 };
995 for (i = 0; i < MAX_READ_TIMES; ++i) {
1013 if (((skip_step < 0) || (skip_step >= 100)) ||
1014 (first_step > last_step) ||
1015 (first_step < -urg->front_data_index) ||
1087 for (i = 0; i < 2; ++i) {
1103 enum { RECEIVE_BUFFER_SIZE = 4 };
1105 char receive_buffer[RECEIVE_BUFFER_SIZE];
1112 receive_buffer, RECEIVE_BUFFER_SIZE);
1125 return strncmp(
"Stable", stat, 6) ? 0 : 1;
1130 const char *start_str,
const char *end_ch,
int lines)
1132 size_t start_str_len = strlen(start_str);
1133 size_t end_ch_len = strlen(end_ch);
1137 for (j = 0; j < end_ch_len; ++j) {
1138 const char *p = receive_buffer;
1140 for (i = 0; i < lines; ++i) {
1141 if (!strncmp(p, start_str, start_str_len)) {
1143 char *last_p = strchr(p + start_str_len, end_ch[j]);
1146 memcpy(dest, p + start_str_len,
1147 last_p - (p + start_str_len) + 1);
1159 char *buffer,
int buffer_size,
1160 const char* command,
1171 buffer, buffer_size);
1172 if (ret < response_lines) {
1185 char receive_buffer[RECEIVE_BUFFER_SIZE];
1206 char receive_buffer[RECEIVE_BUFFER_SIZE];
1225 char receive_buffer[RECEIVE_BUFFER_SIZE];
1249 char receive_buffer[RECEIVE_BUFFER_SIZE];
1273 char receive_buffer[RECEIVE_BUFFER_SIZE];
1282 char firmware_version[50];
1284 strcat(firmware_version,
"(");
1305 char receive_buffer[RECEIVE_BUFFER_SIZE];
1330 char receive_buffer[RECEIVE_BUFFER_SIZE];
1355 char receive_buffer[RECEIVE_BUFFER_SIZE];