#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <netdb.h>
#include <fcntl.h>
#include <errno.h>
#include "btserial.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "defs.h"
#include "tcp.h"
Go to the source code of this file.
|
int(* | tcp_write )(void *device, const u8 *buf, size_t count) = bt_write |
| writes buf[1] till buf[count - 2] to device More...
|
|
int(* | tcp_read )(void *device, u8 *buf, size_t count, int milliseconds) = bt_read |
| writes buf[1] till buf[count - 2] to device More...
|
|
#define bailout |
( |
|
msg | ) |
perror((msg)) |
Definition at line 38 of file tcp.c.
#define closesocket close |
Definition at line 39 of file tcp.c.
#define INVALID_SOCKET (-1) |
Definition at line 36 of file tcp.c.
#define SOCKET_ERROR (-1) |
Definition at line 37 of file tcp.c.
#define socksetblock |
( |
|
sock, |
|
|
|
y_n |
|
) |
| |
Value:((y_n) ? \
fcntl((sock), F_SETFL, fcntl((sock), F_GETFL, 0) & ~O_NONBLOCK) : \
fcntl((sock), F_SETFL, O_NONBLOCK))
Definition at line 40 of file tcp.c.
#define TCP_CONNECT_TIMEOUT 1 |
Definition at line 68 of file tcp.c.
Definition at line 65 of file tcp.c.
default UDP broadcast port
Definition at line 64 of file tcp.c.
#define UDP_RECV_TIMEOUT 6 |
Definition at line 67 of file tcp.c.
BSD Sockets/Winsock2 I/O wrappers.
- Author
- Ahmad Fatoum
- Copyright
- (c) 2015 Ahmad Fatoum. Code available under terms of the GNU General Public License 3.0
Definition at line 35 of file tcp.c.
void tcp_close |
( |
void * |
sock | ) |
|
releases the socket file descriptor opened by tcp_open()
Closes the resource opened by bt_open
.
- Parameters
-
Definition at line 241 of file tcp.c.
const wchar_t* tcp_error |
( |
void * |
fd_ | ) |
|
Returns an error string describing the last error occured.
- Parameters
-
- Returns
- message An error string
- Bug:
- it's useless. Could use
wprintf
and strerror
Definition at line 256 of file tcp.c.
void* tcp_open |
( |
const char * |
serial, |
|
|
unsigned |
timeout |
|
) |
| |
connects to a ev3 device on the same subnet.
open a bluetooth device described by device. NULL
leads to default action
- Parameters
-
[in] | serial | IP-Address or Serial-Number of Ev3. NULL connects to the first available |
- Returns
- &fd pointer to file descriptor for use with tcp_{read,write,close,error} If the serial number contains a dot, a direct TCP connection is attempted. The Ev3 broadcasts a UDP-packet every 5 seconds. This functions waits 7 seconds for that to happen. It then compares the broadcasted serial number with the value set should serial be non-
NULL
. If serial is NULL
or the serial numbers match, a udp packet is sent to the source port on the ev3. Afterwards the Ev3 starts listening on the port it broadcasted. Then a GET request is sent and the VM starts listening and business is as usual
- See also
- http://www.monobrick.dk/guides/how-to-establish-a-wifi-connection-with-the-ev3-brick/
Definition at line 84 of file tcp.c.
int(* tcp_read) (void *device, u8 *buf, size_t count, int milliseconds) = bt_read |
writes buf[1] till buf[count - 2] to device
- Parameters
-
[in] | device | handle returned by bt_open |
[in] | buf | buffer to write to |
[in] | count | number of characters to be read |
[in] | milliseconds | number of milliseconds to wait at maximum. -1 is indefinitely |
- Returns
- status -1 on error. bytes read otherwise.
- Bug:
- the milliseconds part needs to be tested more throughly
- See also
- implementation at bt-win.c and bt-unix.c
Definition at line 272 of file tcp.c.
int(* tcp_write) (void *device, const u8 *buf, size_t count) = bt_write |
writes buf[1] till buf[count - 2] to device
- Parameters
-
[in] | device | handle returned by bt_open |
[in] | buf | byte string to write, the first byte is omitted |
[in] | count | number of characters to be written (including leading ignored byte) |
- Returns
- status -1 on error. bytes read otherwise.
- Bug:
- the first byte is omitted for compatiblity with the leading report byte demanded by
hid_write
. Wrapping HIDAPI could fix this. - See also
- implementation at bt-win.c and bt-unix.c
Definition at line 271 of file tcp.c.