10 char PC_ADDRESS_[18] =
"34:E6:AD:06:21:46";
19 server->sock = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
21 server->
locAddr.rc_family = AF_BLUETOOTH;
22 server->
locAddr.rc_bdaddr = *BDADDR_ANY;
23 server->
locAddr.rc_channel = (uint8_t)1;
25 bind(server->sock, (
struct sockaddr *)&(server->
locAddr),
sizeof(server->
locAddr));
27 for(
int i=0; i<1024; i++){
41 listen(server->sock, 1);
42 server->
client = accept(server->sock, (
struct sockaddr *)&(server->
remAddr), &server->
opt);
44 ba2str(&server->
remAddr.rc_bdaddr, server->
buf);
45 fprintf(stderr,
"accepted connection from %s\n", server->
buf);
46 memset(server->
buf, 0,
sizeof(server->
buf));
69 for(uint16_t i=0; i<bytesRead; i++){
71 printf(
"received [%i]\t", (
int)(server->
recData[i]));
75 *dst = (int)(server->
recData[0]);
89 printf(
"received [%s]", (server->
recData));
92 *dst = (char)(server->
recData[0]);
102 client->
dst = PC_ADDRESS_;
103 client->sock = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
105 client->
addr.rc_family = AF_BLUETOOTH;
106 client->
addr.rc_channel = (uint8_t)1;
107 str2ba(client->
dst, &(client->
addr.rc_bdaddr));
118 client->
status = connect(client->sock, (
struct sockaddr *)&(client->
addr),
sizeof(client->
addr));
139 client->
status = write(client->sock, data, size);
void BluetoothClient_enable(BluetoothClient_t *client)
struct sockaddr_rc remAddr
void BluetoothServer_disable(BluetoothServer_t *server)
void BluetoothClient_checkError(BluetoothClient_t *client)
void BluetoothClient_sendString(BluetoothClient_t *client, char *data, int size)
void BluetoothServer_readInt(BluetoothServer_t *server, int *dst)
void BluetoothServer_construct(BluetoothServer_t *server)
Structure for creating a Bluetooth server.
Structure for creating a Bluetooth client.
void BluetoothServer_readChar(BluetoothServer_t *server, char *dst)
struct sockaddr_rc locAddr
void BluetoothServer_enable(BluetoothServer_t *server)
void BluetoothClient_construct(BluetoothClient_t *client)
void BluetoothClient_disable(BluetoothClient_t *client)