aboutsummaryrefslogtreecommitdiff
path: root/Bluetooth.cpp
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-02-08 21:29:47 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-02-08 21:29:47 +0100
commit5cb96fd96f51e949c5311db3080c58d851b7c2e1 (patch)
tree99c41d3ba8e9f5dd7eb3a5250df8c8b707c7f541 /Bluetooth.cpp
downloadble-toys-5cb96fd96f51e949c5311db3080c58d851b7c2e1.tar.gz
ble-toys-5cb96fd96f51e949c5311db3080c58d851b7c2e1.tar.bz2
ble-toys-5cb96fd96f51e949c5311db3080c58d851b7c2e1.tar.xz
ble-toys-5cb96fd96f51e949c5311db3080c58d851b7c2e1.zip
o Initial import of Linux code for talking to Bluetooth devices.
Diffstat (limited to 'Bluetooth.cpp')
-rw-r--r--Bluetooth.cpp55
1 files changed, 55 insertions, 0 deletions
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 <sstream>
+#include <iomanip>
+#include <string.h>
+#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() {
+ }
+};