ev3duder  0.3.0
EV3 Downloader/Uploader
bt-unix.c File Reference

Unix bluetooth I/O wrappers. More...

#include <unistd.h>
#include <termios.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "defs.h"

Go to the source code of this file.

Macros

#define BT   "/dev/cu.EV3-SerialPort"
 default serial port name on OS X More...
 

Enumerations

enum  { READ =0, WRITE =1 }
 open(2)s serial port described by device. NULL leads to default action More...
 

Functions

void * bt_open (const char *file, const char *file2)
 open a bluetooth device described by device. NULL leads to default action More...
 
int bt_write (void *fd_, const u8 *buf, size_t count)
 writes buf[1] till buf[count - 2] to device More...
 
int bt_read (void *fd_, u8 *buf, size_t count, int milliseconds)
 writes buf[1] till buf[count - 2] to device More...
 
void bt_close (void *handle)
 Closes the file descriptor opened by bt_open() More...
 
const wchar_t * bt_error (void *fd_)
 Returns an error string describing the last error occured. More...
 

Detailed Description

Unix bluetooth I/O wrappers.

Author
Ahmad Fatoum

Definition in file bt-unix.c.

Macro Definition Documentation

#define BT   "/dev/cu.EV3-SerialPort"

default serial port name on OS X

Definition at line 20 of file bt-unix.c.

Enumeration Type Documentation

anonymous enum

open(2)s serial port described by device. NULL leads to default action

Parameters
[in]devicepath to SerialPort or NULL
Returns
&fd pointer to file descriptor for use with bt_{read,write,close,error}
Bug:
default value should be enumerating. Not hardcoded like in BT
Enumerator
READ 
WRITE 

Definition at line 28 of file bt-unix.c.

Function Documentation

void bt_close ( void *  handle)

Closes the file descriptor opened by bt_open()

Closes the resource opened by bt_open.

Parameters
[in]devicehandle returned by bt_open()

Definition at line 116 of file bt-unix.c.

const wchar_t* bt_error ( void *  fd_)

Returns an error string describing the last error occured.

Parameters
[in]devicehandle returned by bt_open()
Returns
message An error string

Definition at line 127 of file bt-unix.c.

void* bt_open ( const char *  file_in,
const char *  file_out 
)

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

Parameters
[in]file_instring describing the bluetooth device
[in]onlyfor *nix: non-NULL for cases where read/write files differ
Returns
handle a opaque handle for use with bt_{read,write,close,error}
See also
implementation at bt-win.c and bt-unix.c

Definition at line 29 of file bt-unix.c.

int bt_read ( void *  fd_,
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

Definition at line 77 of file bt-unix.c.

int bt_write ( void *  fd_,
const u8 buf,
size_t  count 
)

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

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

Definition at line 51 of file bt-unix.c.