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.
|
#define | BT "/dev/cu.EV3-SerialPort" |
| default serial port name on OS X More...
|
|
|
enum | { READ =0,
WRITE =1
} |
| open(2)s serial port described by device. NULL leads to default action More...
|
|
|
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...
|
|
Unix bluetooth I/O wrappers.
- Author
- Ahmad Fatoum
- Copyright
- (c) 2015 Ahmad Fatoum. Code available under terms of the GNU General Public License 3.0
Definition in file bt-unix.c.
#define BT "/dev/cu.EV3-SerialPort" |
default serial port name on OS X
Definition at line 20 of file bt-unix.c.
open(2)s serial port described by device. NULL
leads to default action
- Parameters
-
[in] | device | path 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
Definition at line 28 of file bt-unix.c.
void bt_close |
( |
void * |
handle | ) |
|
Closes the file descriptor opened by bt_open()
Closes the resource opened by bt_open
.
- Parameters
-
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
-
- 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_in | string describing the bluetooth device |
[in] | only | for *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] | 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
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] | handle | 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.
Definition at line 51 of file bt-unix.c.