Giter Site home page Giter Site logo

roukavici / bluetooth-serial-port Goto Github PK

View Code? Open in Web Editor NEW

This project forked from agamnentzar/bluetooth-serial-port

0.0 4.0 0.0 85 KB

multi-platform bluetooth serial port library for C++

License: Other

CMake 1.89% C++ 30.21% Objective-C++ 18.43% Objective-C 4.56% C 44.91%

bluetooth-serial-port's Introduction

Multiplatform Bluetooth serial port communication library

Based on Bluetooth serial port communication for Node.js

Prequisites on Linux

  • CMake
  • Needs Bluetooth development packages to build

apt-get install libbluetooth-dev cmake gcc-c++
zypper install bluez-devel cmake gcc-c++

Prequisites on OS X

  • CMake from MacPorts
  • Needs XCode and XCode command line tools installed.

Prequisites on Windows

  • CMake
  • Visual Studio

Documentation

Basic usage

#include <iostream>
#include <vector>
#include <memory>
#include "../src/DeviceINQ.h"

using namespace std;

void main()
{
	unique_ptr<DeviceINQ> inq(DeviceINQ::Create());
	vector<device> devices = inq->Inquire();

	for (const auto& d : devices)
	{
		cout << d.name << " " << d.address << endl;
	}

	cout << endl << "done, found " << devices.size() << " device(s)" << endl;
}

API

DeviceINQ

DeviceINQ::Create()

Returns new instance of DeviceINQ object

DeviceINQ::Inquire()

Returns list of bluetooth devices in range

struct device
{
	string address; // bluetooth address of the device
	string name; // name of the device
	time_t lastSeen; // last time device was seen in the inquiry (windows, osx)
	time_t lastUsed; // last time device was used (windows)
	bool connected; // true if device is connected (windows, osx)
	bool remembered; // true if device is remembered (windows, osx)
	bool authenticated; // true if device is authenticated (windows, osx)
	DeviceClass deviceClass; // class of device
	DeviceClass majorDeviceClass; // major class of device
	ServiceClass serviceClass; // service class flags
};

DeviceINQ::SdpSearch(address)

Returns serial port channelID for device at given address

  • address: string containing bluetooth address of the device

BTSerialPortBinding

BTSerialPortBinding::Create(address, channelID)

Returns new instance of BTSerialPortBinding object

  • address: string containint bluetooth address of the device
  • channelID: ID of the serial port channel

BTSerialPortBinding::Connect()

Connects to the device, needs to be called before any Read/Write calls

BTSerialPortBinding::Close()

Closes connection to the device

BTSerialPortBinding::Read(buffer, length)

Reads data from the device, returns numbe rof bytes read

  • buffer: pointer to buffer to hold received data
  • length: maximum namber of bytes to read

BTSerialPortBinding::Write(buffer, length)

Writes data to the device

  • buffer: pointer to buffer with data to send
  • length: number of bytes to send

BTSerialPortBinding::IsDataAvailable(buffer, length)

Returns true if there is data in the buffer ready to be read (not implemented for OSX - always returns false)

Other

GetDeviceClassString(deviceClass)

Returns text representation of deviceClass enum value

GetServiceClassString(serviceClass)

Returns text representation of serviceClass enum value

LICENSE

This module is available under a FreeBSD license, see the LICENSE file for details.

bluetooth-serial-port's People

Contributors

agamnentzar avatar atomheartother avatar sdegrande avatar rush avatar

Watchers

James Cloos avatar  avatar  avatar Pikipoo avatar

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.