]> rtime.felk.cvut.cz Git - eurobot/public.git/blobdiff - src/hokuyo/lib/serial_ctrl_lin.c
Merge branch 'maint-demo'
[eurobot/public.git] / src / hokuyo / lib / serial_ctrl_lin.c
index 11d818d86420ad10e38b4ceb2184a429159f6c11..212ccd5b0178d64d74f5a26f7fe817cb76cbef1b 100644 (file)
@@ -1,8 +1,8 @@
 /*!
   \file
-  \brief \83V\83\8a\83A\83\8b\92Ê\90M (Linux, Mac \8eÀ\91\95)
+  \brief �V���A���ʐM (Linux, Mac ���)
 
-  Serial Communication Interface \90§\8cä
+  Serial Communication Interface ����
 
 
   \author Satofumi KAMIMURA
 #include <fcntl.h>
 #include <errno.h>
 #include <string.h>
+#include <sys/select.h>
+#include <time.h>
+#include <sys/types.h>
+
 
 //#include <ctype.h>
 
@@ -41,7 +45,7 @@ void serial_initialize(serial_t *serial)
 }
 
 
-/* \90Ú\91± */
+/* �ڑ� */
 int serial_connect(serial_t *serial, const char *device, long baudrate)
 {
   int flags = 0;
@@ -50,11 +54,11 @@ int serial_connect(serial_t *serial, const char *device, long baudrate)
   serial_initialize(serial);
 
 #ifndef MAC_OS
-  enum { O_EXLOCK = 0x0 }; /* Linux \82Å\82Í\8eg\82¦\82È\82¢\82Ì\82Å\83_\83~\81[\82ð\8dì\90¬\82µ\82Ä\82¨\82­ */
+  enum { O_EXLOCK = 0x0 }; /* Linux �ł͎g���Ȃ��̂Ń_�~�[���쐬���Ă��� */
 #endif
   serial->fd_ = open(device, O_RDWR | O_EXLOCK | O_NONBLOCK | O_NOCTTY);
   if (serial->fd_ < 0) {
-    /* \90Ú\91±\82É\8e¸\94s */
+    /* �ڑ��Ɏ��s */
     strerror_r(errno, serial->error_string_, SerialErrorStringSize);
     return SerialConnectionFail;
   }
@@ -62,7 +66,7 @@ int serial_connect(serial_t *serial, const char *device, long baudrate)
   flags = fcntl(serial->fd_, F_GETFL, 0);
   fcntl(serial->fd_, F_SETFL, flags & ~O_NONBLOCK);
 
-  /* \83V\83\8a\83A\83\8b\92Ê\90M\82Ì\8f\89\8aú\89» */
+  /* �V���A���ʐM�̏����� */
   tcgetattr(serial->fd_, &serial->sio_);
   serial->sio_.c_iflag = 0;
   serial->sio_.c_oflag = 0;
@@ -73,20 +77,20 @@ int serial_connect(serial_t *serial, const char *device, long baudrate)
   serial->sio_.c_cc[VMIN] = 0;
   serial->sio_.c_cc[VTIME] = 0;
 
-  /* \83{\81[\83\8c\81[\83g\82̕ύX */
+  /* �{�[���[�g�̕ύX */
   ret = serial_setBaudrate(serial, baudrate);
   if (ret < 0) {
     return ret;
   }
 
-  /* \83V\83\8a\83A\83\8b\90§\8cä\8d\\91¢\91Ì\82Ì\8f\89\8aú\89» */
+  /* �V���A�������\���̂̏����� */
   serial->has_last_ch_ = False;
 
   return 0;
 }
 
 
-/* \90ؒf */
+/* ؒf */
 void serial_disconnect(serial_t *serial)
 {
   if (serial->fd_ >= 0) {
@@ -102,7 +106,7 @@ int serial_isConnected(const serial_t *serial)
 }
 
 
-/* \83{\81[\83\8c\81[\83g\82Ì\90Ý\92è */
+/* �{�[���[�g�̐ݒ� */
 int serial_setBaudrate(serial_t *serial, long baudrate)
 {
   long baudrate_value = -1;
@@ -136,7 +140,7 @@ int serial_setBaudrate(serial_t *serial, long baudrate)
     return SerialSetBaudrateFail;
   }
 
-  /* \83{\81[\83\8c\81[\83g\95ύX */
+  /* �{�[���[�g�ύX */
   cfsetospeed(&serial->sio_, baudrate_value);
   cfsetispeed(&serial->sio_, baudrate_value);
   tcsetattr(serial->fd_, TCSADRAIN, &serial->sio_);
@@ -146,7 +150,7 @@ int serial_setBaudrate(serial_t *serial, long baudrate)
 }
 
 
-/* \91\97\90M */
+/* ���M */
 int serial_send(serial_t *serial, const char *data, int data_size)
 {
   if (! serial_isConnected(serial)) {
@@ -161,7 +165,7 @@ static int waitReceive(serial_t* serial, int timeout)
   fd_set rfds;
   struct timeval tv;
 
-  // \83^\83C\83\80\83A\83E\83g\90Ý\92è
+  // �^�C���A�E�g�ݒ�
   FD_ZERO(&rfds);
   FD_SET(serial->fd_, &rfds);
 
@@ -170,7 +174,7 @@ static int waitReceive(serial_t* serial, int timeout)
 
   if (select(serial->fd_ + 1, &rfds, NULL, NULL,
              (timeout < 0) ? NULL : &tv) <= 0) {
-    /* \83^\83C\83\80\83A\83E\83g\94­\90 */
+    /* �^�C���A�E�g���� */
     return 0;
   }
   return 1;
@@ -197,7 +201,7 @@ static int internal_receive(char data[], int data_size_max,
     require_n = data_size_max - filled;
     read_n = read(serial->fd_, &data[filled], require_n);
     if (read_n <= 0) {
-      /* \93Ç\82Ý\8fo\82µ\83G\83\89\81[\81B\8c»\8dÝ\82Ü\82Å\82Ì\8eó\90M\93à\97e\82Å\96ß\82é */
+      /* �ǂݏo���G���[�B���݂܂ł̎��M���e�Ŗ߂� */
       break;
     }
     filled += read_n;
@@ -206,7 +210,7 @@ static int internal_receive(char data[], int data_size_max,
 }
 
 
-/* \8eó\90M */
+/* ���M */
 int serial_recv(serial_t *serial, char* data, int data_size_max, int timeout)
 {
   int filled;
@@ -217,7 +221,7 @@ int serial_recv(serial_t *serial, char* data, int data_size_max, int timeout)
     return 0;
   }
 
-  /* \8f\91\82«\96ß\82µ\82½\82P\95\8e\9a\82ª\82 \82ê\82Î\81A\8f\91\82«\8fo\82· */
+  /* �����߂����P�����������΁A�����o�� */
   filled = 0;
   if (serial->has_last_ch_ != False) {
     data[0] = serial->last_ch_;
@@ -235,7 +239,7 @@ int serial_recv(serial_t *serial, char* data, int data_size_max, int timeout)
   buffer_size = ring_size(&serial->ring_);
   read_n = data_size_max - filled;
   if (buffer_size < read_n) {
-    // \83\8a\83\93\83O\83o\83b\83t\83@\93à\82Ì\83f\81[\83^\82Å\91«\82è\82È\82¯\82ê\82Î\81A\83f\81[\83^\82ð\93Ç\82Ý\91«\82·
+    // �����O�o�b�t�@���̃f�[�^�ő����Ȃ����΁A�f�[�^���ǂݑ���
     char buffer[RingBufferSize];
     int n = internal_receive(buffer,
                              ring_capacity(&serial->ring_) - buffer_size,
@@ -244,7 +248,7 @@ int serial_recv(serial_t *serial, char* data, int data_size_max, int timeout)
   }
   buffer_size = ring_size(&serial->ring_);
 
-  // \83\8a\83\93\83O\83o\83b\83t\83@\93à\82Ì\83f\81[\83^\82ð\95Ô\82·
+  // �����O�o�b�t�@���̃f�[�^���Ԃ�
   if (read_n > buffer_size) {
     read_n = buffer_size;
   }
@@ -253,14 +257,14 @@ int serial_recv(serial_t *serial, char* data, int data_size_max, int timeout)
     filled += read_n;
   }
 
-  // \83f\81[\83^\82ð\83^\83C\83\80\83A\83E\83g\95t\82«\82Å\93Ç\82Ý\8fo\82·
+  // �f�[�^���^�C���A�E�g�t���œǂݏo��
   filled += internal_receive(&data[filled],
                              data_size_max - filled, serial, timeout);
   return filled;
 }
 
 
-/* \82P\95\8e\9a\8f\91\82«\96ß\82· */
+/* �P���������߂� */
 void serial_ungetc(serial_t *serial, char ch)
 {
   serial->has_last_ch_ = True;