From 5cb96fd96f51e949c5311db3080c58d851b7c2e1 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 8 Feb 2015 21:29:47 +0100 Subject: o Initial import of Linux code for talking to Bluetooth devices. --- Bluetooth.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Bluetooth.cpp (limited to 'Bluetooth.cpp') diff --git a/Bluetooth.cpp b/Bluetooth.cpp new file mode 100644 index 0000000..22f67ec --- /dev/null +++ b/Bluetooth.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include "Bluetooth.h" + +namespace trygvis { + using namespace std; + + // ----------------------------------------------------------------------- + // Mac + // ----------------------------------------------------------------------- + + string Mac::str() const { + std::ostringstream buf; + + buf + << setw(2) << hex << setfill('0') << (int)bytes[5] << ":" + << setw(2) << hex << setfill('0') << (int)bytes[4] << ":" + << setw(2) << hex << setfill('0') << (int)bytes[3] << ":" + << setw(2) << hex << setfill('0') << (int)bytes[2] << ":" + << setw(2) << hex << setfill('0') << (int)bytes[1] << ":" + << setw(2) << hex << setfill('0') << (int)bytes[0]; + + return buf.str(); + } + + + bool Mac::operator==(Mac &other) const { + return memcmp(bytes, other.bytes, sizeof(bytes)) == 0; + } + + void Mac::copy(uint8_t &_0, uint8_t &_1, uint8_t &_2, uint8_t &_3, uint8_t &_4, uint8_t &_5) const { + _0 = bytes[0]; + _1 = bytes[1]; + _2 = bytes[2]; + _3 = bytes[3]; + _4 = bytes[4]; + _5 = bytes[5]; + } + + Mac *Mac::parseMac(string s) { + uint8_t bytes[6]; + sscanf("%02x:%02x:%02x:%02x:%02x:%02x", s.c_str(), + &bytes[0], &bytes[1], &bytes[2], &bytes[3], &bytes[4], &bytes[5]); + + return new Mac(bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5]); + } + + // ----------------------------------------------------------------------- + // Adapter + // ----------------------------------------------------------------------- + + BluetoothAdapter::~BluetoothAdapter() { + } +}; -- cgit v1.2.3