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];
int urg_start_time_stamp_mode(urg_t *urg)
const char * urg_sensor_vendor(urg_t *urg)
returns the vendor name
static char scip_checksum(const char buffer[], int size)
チェックサムの計算
int urg_get_multiecho(urg_t *urg, long data_multi[], long *time_stamp, unsigned long long *system_time_stamp)
static int parse_parameter(const char *parameter, int size)
static urg_measurement_type_t parse_distance_parameter(urg_t *urg, const char echoback[])
urg_error_handler error_handler
long urg_scip_decode(const char data[], int size)
SCIP 文字列のデコード.
void connection_close(urg_connection_t *connection)
切断
int urg_reboot(urg_t *urg)
int urg_stop_time_stamp_mode(urg_t *urg)
void urg_sleep(urg_t *urg)
static const char NOT_CONNECTED_MESSAGE[]
int scanning_remain_times
int connection_readline(urg_connection_t *connection, char *data, int max_size, int timeout)
改行文字までの受信
static void ignore_receive_data_with_qt(urg_t *urg, int timeout)
static int receive_data(urg_t *urg, long data[], unsigned short intensity[], long *time_stamp, unsigned long long *system_time_stamp)
距離データの取得
urg_connection_t connection
static int scip_response(urg_t *urg, const char *command, const int expected_ret[], int timeout, char *receive_buffer, int receive_buffer_max_size)
static int connect_urg_device(urg_t *urg, long baudrate)
static int set_errno_and_return(urg_t *urg, int urg_errno)
int urg_start_measurement(urg_t *urg, urg_measurement_type_t type, int scan_times, int skip_scan)
static int change_sensor_baudrate(urg_t *urg, long current_baudrate, long next_baudrate)
void urg_set_error_handler(urg_t *urg, urg_error_handler handler)
static char * copy_token(char *dest, char *receive_buffer, const char *start_str, const char *end_ch, int lines)
urg_connection_type_t
通信タイプ
int urg_stop_measurement(urg_t *urg)
int urg_get_multiecho_intensity(urg_t *urg, long data_multi[], unsigned short intensity_multi[], long *time_stamp, unsigned long long *system_time_stamp)
static int receive_length_data(urg_t *urg, long length[], unsigned short intensity[], urg_measurement_type_t type, char buffer[])
urg_range_data_byte_t range_data_byte
static int receive_parameter(urg_t *urg)
void urg_get_walltime(unsigned long long *nsecs)
int connection_write(urg_connection_t *connection, const char *data, int size)
送信
long urg_time_stamp(urg_t *urg)
int urg_set_scanning_parameter(urg_t *urg, int first_step, int last_step, int skip_step)
const char * urg_sensor_firmware_date(urg_t *urg)
urg_measurement_type_t(* urg_error_handler)(const char *status, void *urg)
static void ignore_receive_data(urg_t *urg, int timeout)
int urg_laser_off(urg_t *urg)
void urg_close(urg_t *urg)
const char * urg_sensor_status(urg_t *urg)
int urg_open(urg_t *urg, urg_connection_type_t connection_type, const char *device_or_address, long baudrate_or_port)
int connection_set_baudrate(urg_connection_t *connection, long baudrate)
const char * urg_sensor_product_type(urg_t *urg)
static const char * receive_command_response(urg_t *urg, char *buffer, int buffer_size, const char *command, int response_lines)
const char * urg_sensor_firmware_version(urg_t *urg)
static const char RECEIVE_ERROR_MESSAGE[]
int urg_get_distance(urg_t *urg, long data[], long *time_stamp, unsigned long long *system_time_stamp)
int connection_open(urg_connection_t *connection, urg_connection_type_t connection_type, const char *device, long baudrate_or_port)
接続
int urg_laser_on(urg_t *urg)
void urg_set_timeout_msec(urg_t *urg, int msec)
タイムアウト時間の設定
int urg_get_distance_intensity(urg_t *urg, long data[], unsigned short intensity[], long *time_stamp, unsigned long long *system_time_stamp)
static int send_distance_command(urg_t *urg, int scan_times, int skip_scan, char single_scan_ch, char continuous_scan_ch, char scan_type_ch)
void urg_wakeup(urg_t *urg)
urg_range_data_byte_t received_range_data_byte
static urg_measurement_type_t parse_distance_echoback(urg_t *urg, const char echoback[])
const char * urg_sensor_serial_id(urg_t *urg)
const char * urg_sensor_protocol_version(urg_t *urg)
returns the protocol version
int urg_set_connection_data_size(urg_t *urg, urg_range_data_byte_t data_byte)
int urg_is_stable(urg_t *urg)
const char * urg_sensor_state(urg_t *urg)