ev3duder  0.3.0
EV3 Downloader/Uploader
tcp.h File Reference

BSD sockets/Winsock2 Input/Output wrappers. More...

#include "defs.h"

Go to the source code of this file.

Data Structures

struct  tcp_handle
 

Functions

void * tcp_open (const char *serial, unsigned timeout)
 open a bluetooth device described by device. NULL leads to default action More...
 
void tcp_close (void *)
 Closes the resource opened by bt_open. More...
 
const wchar_t * tcp_error (void *device)
 Returns an error string describing the last error occured. More...
 
const wchar_t * tcp_info (void *device)
 Returns an error string describing the last error occured. More...
 

Variables

int(* tcp_write )(void *device, const u8 *buf, size_t count)
 writes buf[1] till buf[count - 2] to device More...
 
int(* tcp_read )(void *device, u8 *buf, size_t count, int milliseconds)
 writes buf[1] till buf[count - 2] to device More...
 

Detailed Description

BSD sockets/Winsock2 Input/Output wrappers.

Author
Ahmad Fatoum

Definition in file tcp.h.

Function Documentation

void tcp_close ( void *  sock)

Closes the resource opened by bt_open.

Parameters
[in]devicehandle returned by bt_open
See also
implementation at bt-win.c and bt-unix.c

Closes the resource opened by bt_open.

Parameters
[in]devicehandle returned by tcp_open()

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
[in]devicehandle returned by bt_open
Returns
message An error string
See also
implementation at bt-win.c and bt-unix.c
Bug:
it's useless
Parameters
[in]devicehandle returned by tcp_open()
Returns
message An error string
Bug:
it's useless. Could use wprintf and strerror

Definition at line 256 of file tcp.c.

const wchar_t* tcp_info ( void *  device)

Returns an error string describing the last error occured.

Parameters
[in]devicehandle returned by bt_open
Returns
message An error string
See also
implementation at bt-win.c and bt-unix.c
Bug:
it's useless
void* tcp_open ( const char *  serial,
unsigned  timeout 
)

open a bluetooth device described by device. NULL leads to default action

Parameters
[in]serialof Ev3 to connect to
[in]timeoutfor UDP recv
Returns
handle a opaque handle for use with tcp_{read,write,close,error}
See also
implementation at bt-win.c and bt-unix.c

open a bluetooth device described by device. NULL leads to default action

Parameters
[in]serialIP-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.

Variable Documentation

int(* tcp_read) (void *device, u8 *buf, size_t count, int milliseconds)

writes buf[1] till buf[count - 2] to device

Parameters
[in]devicehandle returned by bt_open
[in]bufbuffer to write to
[in]countnumber of characters to be read
[in]millisecondsnumber 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)

writes buf[1] till buf[count - 2] to device

Parameters
[in]devicehandle returned by bt_open
[in]bufbyte string to write, the first byte is omitted
[in]countnumber 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.