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 }
int connection_write(urg_connection_t *connection, const char *data, int size)
送信
int serial_write(urg_serial_t *serial, const char *data, int size)
データを送信する
イーサーネット接続
urg_connection_type_t
通信タイプ
int connection_read(urg_connection_t *connection, char *data, int max_size, int timeout)
受信
int tcpclient_readline(urg_tcpclient_t *cli, char *userbuf, int buf_size, int timeout)
read one line from socket.
int tcpclient_write(urg_tcpclient_t *cli, const char *userbuf, int req_size)
write to socket.
int serial_set_baudrate(urg_serial_t *serial, long baudrate)
ボーレートを設定する
void tcpclient_close(urg_tcpclient_t *cli)
destructor of tcp client module
int connection_open(urg_connection_t *connection, urg_connection_type_t connection_type, const char *device, long baudrate_or_port)
接続
void serial_close(urg_serial_t *serial)
接続を閉じる
urg_serial_t serial
シリアル接続
int connection_set_baudrate(urg_connection_t *connection, long baudrate)
通信の処理
int serial_open(urg_serial_t *serial, const char *device, long baudrate)
接続を開く
int tcpclient_read(urg_tcpclient_t *cli, char *userbuf, int req_size, int timeout)
read from socket.
int serial_readline(urg_serial_t *serial, char *data, int max_size, int timeout)
改行までのデータを受信する
Definition: urg_serial.c:40
void connection_close(urg_connection_t *connection)
切断
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
int serial_read(urg_serial_t *serial, char *data, int max_size, int timeout)
データを受信する
urg_connection_type_t type
接続タイプ
通信リソース
int connection_readline(urg_connection_t *connection, char *data, int max_size, int timeout)
改行文字までの受信
urg_tcpclient_t tcpclient
イーサーネット接続
シリアル, USB 接続


urg_c
Author(s): Satofumi Kamimura , Katsumi Kimoto, Adrian Boeing
autogenerated on Thu Jun 6 2019 19:27:49