Go to the documentation of this file.00001
00010 #include "urg_c/urg_connection.h"
00011
00012
00013 int connection_open(urg_connection_t *connection,
00014 urg_connection_type_t connection_type,
00015 const char *device, long baudrate_or_port)
00016 {
00017 connection->type = connection_type;
00018
00019 switch (connection_type) {
00020 case URG_SERIAL:
00021 return serial_open(&connection->serial, device, baudrate_or_port);
00022 break;
00023
00024 case URG_ETHERNET:
00025 return tcpclient_open(&connection->tcpclient,
00026 device, baudrate_or_port);
00027 break;
00028 }
00029 return -1;
00030 }
00031
00032
00033 void connection_close(urg_connection_t *connection)
00034 {
00035 switch (connection->type) {
00036 case URG_SERIAL:
00037 serial_close(&connection->serial);
00038 break;
00039
00040 case URG_ETHERNET:
00041 tcpclient_close(&connection->tcpclient);
00042 break;
00043 }
00044 }
00045
00046
00047 int connection_set_baudrate(urg_connection_t *connection, long baudrate)
00048 {
00049 int ret = -1;
00050
00051 switch (connection->type) {
00052 case URG_SERIAL:
00053 ret = serial_set_baudrate(&connection->serial, baudrate);
00054 break;
00055
00056 case URG_ETHERNET:
00057 ret = 0;
00058 break;
00059 }
00060
00061 return ret;
00062 }
00063
00064
00065 int connection_write(urg_connection_t *connection,
00066 const char *data, int size)
00067 {
00068 switch (connection->type) {
00069 case URG_SERIAL:
00070 return serial_write(&connection->serial, data, size);
00071 break;
00072 case URG_ETHERNET:
00073 return tcpclient_write(&connection->tcpclient, data, size);
00074 break;
00075 }
00076 return -1;
00077 }
00078
00079
00080 int connection_read(urg_connection_t *connection,
00081 char *data, int max_size, int timeout)
00082 {
00083 switch (connection->type) {
00084 case URG_SERIAL:
00085 return serial_read(&connection->serial, data, max_size, timeout);
00086 break;
00087 case URG_ETHERNET:
00088 return tcpclient_read(&connection->tcpclient, data, max_size, timeout);
00089 break;
00090 }
00091 return -1;
00092 }
00093
00094
00095 int connection_readline(urg_connection_t *connection,
00096 char *data, int max_size, int timeout)
00097 {
00098 switch (connection->type) {
00099 case URG_SERIAL:
00100 return serial_readline(&connection->serial, data, max_size, timeout);
00101 break;
00102 case URG_ETHERNET:
00103 return tcpclient_readline(&connection->tcpclient,
00104 data, max_size, timeout);
00105 break;
00106 }
00107 return -1;
00108 }