Git Product home page Git Product logo

rfcomm-cpp's Introduction

Usage of this tiny bluez CPP helper library ๐Ÿ‘๐Ÿป๐Ÿป

  • the channel interface
namespace channel {

/**
 * channel.h
 *   Establishes RFCOMM (TX) channel associated with
 *   a given UUID and MAC address.
 *
 *   @ref
 *     https://people.csail.mit.edu/albert/bluez-intro/x604.html
 *
 *   accessed
 *     18 June 2021
 */
int queryID(uint8_t* uuid, char *deviceAddress);
}
  • the client interface
namespace client {

/**
 * callServer
 *   Calls a remote server over a RFCOMM (TX) channel.
 *
 *   @ref
 *     https://people.csail.mit.edu/albert/bluez-intro/x502.html
 *
 *   accessed
 *     05:22 18 June 2021
 */
void callServer(int channel, char *deviceAddress);
}
  • the server inteface
namespace server {

/**
 * setup
 *   Uses host machine as a local server: opens an RFCOMM (RX) channel
 *   for a specified number of connections.
 *
 *   @ref
 *     https://people.csail.mit.edu/albert/bluez-intro/x502.html
 *
 *   accessed
 *     05:22 18 June 2021
 */
void setup(int channelID, int connectionCount);
}

here's an example of how to use the interfaces

// RFCOMM connection between Linux system and Android device.
//
#include <thread>

#include "channel.h"
#include "client.h"
#include "server.h"

// configure setup
//
#define SETUP_CLIENT 1 // use host machine as a client
#define SETUP_SERVER 0 // use host machine as a server

void setupClient(uint8_t *uuid, char *deviceAddress)
{
#if SETUP_CLIENT == 1
    int clientChannel = channel::queryID(uuid, deviceAddress);
    client::callServer(clientChannel, deviceAddress);
#endif
}

void setupServer(int channelID, int connectionCount)
{
#if SETUP_SERVER == 1
    server::setup(channelID, connectionCount);
#endif
}


int main()
{
    /** client config */
    // UUID: d8308c4e-9469-4051-8adc-7a2663e415e2
    //  n.b. make sure UUID on the android device is the same as this one.
    uint8_t CHANNEL_UUID[16] = { 0xd8, 0x30, 0x8c, 0x4e, 0x94, 0x69,
        0x40, 0x51, 0x8a, 0xdc, 0x7a, 0x26, 0x63, 0xe4, 0x15, 0xe2 };
    char deviceAddress[18] = "C0:8C:71:61:34:8C"; // <-- android address

    /** server config */
    const int CHANNEL_ID = 20;             // use channel 20 ...
    const int NUMBER_OF_CONNECTIONS = 1;   // ... for a single connection

    std::thread clientWorker(setupClient, CHANNEL_UUID, deviceAddress);
    std::thread serverWorker(setupServer, CHANNEL_ID, NUMBER_OF_CONNECTIONS);

    clientWorker.join();
    serverWorker.join();
    return 0;
}

rfcomm-cpp's People

Stargazers

 avatar

Watchers

 avatar

Forkers

billxw

rfcomm-cpp's Issues

server and UUID

Hello,

I don't understand why the server doesn't use an UUID ?
An other question, how to receive a message from the client and how to send a message from the server ?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.