urg_connection.c
Go to the documentation of this file.
1 
10 #include "urg_c/urg_connection.h"
11 
12 
14  urg_connection_type_t connection_type,
15  const char *device, long baudrate_or_port)
16 {
17  connection->type = connection_type;
18 
19  switch (connection_type) {
20  case URG_SERIAL:
21  return serial_open(&connection->serial, device, baudrate_or_port);
22  break;
23 
24  case URG_ETHERNET:
25  return tcpclient_open(&connection->tcpclient,
26  device, baudrate_or_port);
27  break;
28  }
29  return -1;
30 }
31 
32 
34 {
35  switch (connection->type) {
36  case URG_SERIAL:
37  serial_close(&connection->serial);
38  break;
39 
40  case URG_ETHERNET:
41  tcpclient_close(&connection->tcpclient);
42  break;
43  }
44 }
45 
46 
47 int connection_set_baudrate(urg_connection_t *connection, long baudrate)
48 {
49  int ret = -1;
50 
51  switch (connection->type) {
52  case URG_SERIAL:
53  ret = serial_set_baudrate(&connection->serial, baudrate);
54  break;
55 
56  case URG_ETHERNET:
57  ret = 0;
58  break;
59  }
60 
61  return ret;
62 }
63 
64 
66  const char *data, int size)
67 {
68  switch (connection->type) {
69  case URG_SERIAL:
70  return serial_write(&connection->serial, data, size);
71  break;
72  case URG_ETHERNET:
73  return tcpclient_write(&connection->tcpclient, data, size);
74  break;
75  }
76  return -1;
77 }
78 
79 
81  char *data, int max_size, int timeout)
82 {
83  switch (connection->type) {
84  case URG_SERIAL:
85  return serial_read(&connection->serial, data, max_size, timeout);
86  break;
87  case URG_ETHERNET:
88  return tcpclient_read(&connection->tcpclient, data, max_size, timeout);
89  break;
90  }
91  return -1;
92 }
93 
94 
96  char *data, int max_size, int timeout)
97 {
98  switch (connection->type) {
99  case URG_SERIAL:
100  return serial_readline(&connection->serial, data, max_size, timeout);
101  break;
102  case URG_ETHERNET:
103  return tcpclient_readline(&connection->tcpclient,
104  data, max_size, timeout);
105  break;
106  }
107  return -1;
108 }
serial_set_baudrate
int serial_set_baudrate(urg_serial_t *serial, long baudrate)
ボーレートを設定する
Definition: urg_serial_linux.c:91
serial_read
int serial_read(urg_serial_t *serial, char *data, int max_size, int timeout)
データを受信する
Definition: urg_serial_linux.c:193
tcpclient_close
void tcpclient_close(urg_tcpclient_t *cli)
destructor of tcp client module
Definition: urg_tcpclient.c:192
urg_connection_type_t
urg_connection_type_t
通信タイプ
Definition: urg_connection.h:32
connection_write
int connection_write(urg_connection_t *connection, const char *data, int size)
送信
Definition: urg_connection.c:65
connection_close
void connection_close(urg_connection_t *connection)
切断
Definition: urg_connection.c:33
serial_write
int serial_write(urg_serial_t *serial, const char *data, int size)
データを送信する
Definition: urg_serial_linux.c:134
urg_connection_t::serial
urg_serial_t serial
シリアル接続
Definition: urg_connection.h:44
tcpclient_read
int tcpclient_read(urg_tcpclient_t *cli, char *userbuf, int req_size, int timeout)
read from socket.
Definition: urg_tcpclient.c:206
urg_connection_t
通信リソース
Definition: urg_connection.h:41
tcpclient_open
int tcpclient_open(urg_tcpclient_t *cli, const char *server_ip_str, int port_num)
constructor of tcp client module
Definition: urg_tcpclient.c:67
connection_readline
int connection_readline(urg_connection_t *connection, char *data, int max_size, int timeout)
改行文字までの受信
Definition: urg_connection.c:95
urg_connection_t::type
urg_connection_type_t type
接続タイプ
Definition: urg_connection.h:43
serial_close
void serial_close(urg_serial_t *serial)
接続を閉じる
Definition: urg_serial_linux.c:82
connection_open
int connection_open(urg_connection_t *connection, urg_connection_type_t connection_type, const char *device, long baudrate_or_port)
接続
Definition: urg_connection.c:13
tcpclient_readline
int tcpclient_readline(urg_tcpclient_t *cli, char *userbuf, int buf_size, int timeout)
read one line from socket.
Definition: urg_tcpclient.c:292
serial_readline
int serial_readline(urg_serial_t *serial, char *data, int max_size, int timeout)
改行までのデータを受信する
Definition: urg_serial.c:40
urg_connection.h
通信の処理
urg_connection_t::tcpclient
urg_tcpclient_t tcpclient
イーサーネット接続
Definition: urg_connection.h:45
URG_SERIAL
@ URG_SERIAL
シリアル, USB 接続
Definition: urg_connection.h:33
serial_open
int serial_open(urg_serial_t *serial, const char *device, long baudrate)
接続を開く
Definition: urg_serial_linux.c:38
URG_ETHERNET
@ URG_ETHERNET
イーサーネット接続
Definition: urg_connection.h:34
connection_read
int connection_read(urg_connection_t *connection, char *data, int max_size, int timeout)
受信
Definition: urg_connection.c:80
tcpclient_write
int tcpclient_write(urg_tcpclient_t *cli, const char *userbuf, int req_size)
write to socket.
Definition: urg_tcpclient.c:273
connection_set_baudrate
int connection_set_baudrate(urg_connection_t *connection, long baudrate)
Definition: urg_connection.c:47


urg_c
Author(s): Satofumi Kamimura , Katsumi Kimoto, Adrian Boeing
autogenerated on Wed Mar 2 2022 01:08:11