aboutsummaryrefslogtreecommitdiff
path: root/nimbluez/bluetoothbluez.nim
diff options
context:
space:
mode:
authorElectric-Blue <Electric-Blue@users.noreply.github.com>2016-02-01 00:03:45 +0300
committerElectric-Blue <Electric-Blue@users.noreply.github.com>2016-02-01 00:03:45 +0300
commitf626934b2115cfbeb18fb372ac340c47848da443 (patch)
treea5e93eeab5d235835e596a9e4dd239a793ebde34 /nimbluez/bluetoothbluez.nim
parent48c3a10ccf6ddb82d2dffa063032f9c6e47d238f (diff)
downloadNimBluez-f626934b2115cfbeb18fb372ac340c47848da443.tar.gz
NimBluez-f626934b2115cfbeb18fb372ac340c47848da443.zip
Class of device for bluez.
Diffstat (limited to 'nimbluez/bluetoothbluez.nim')
-rw-r--r--nimbluez/bluetoothbluez.nim20
1 files changed, 20 insertions, 0 deletions
diff --git a/nimbluez/bluetoothbluez.nim b/nimbluez/bluetoothbluez.nim
index c11107d..2ca50c3 100644
--- a/nimbluez/bluetoothbluez.nim
+++ b/nimbluez/bluetoothbluez.nim
@@ -161,3 +161,23 @@ proc name*(device: BluetoothDeviceRemote,
finally:
if hci_close_dev(socket) < 0:
raiseOSError(osLastError())
+
+proc classOfDevice*(device: BluetoothDeviceLocal): uint32 =
+ ## Returns class of local Bluetooth device.
+ var socket = hci_open_dev(cint(device.fDevId))
+ if socket < 0:
+ raiseOSError(osLastError())
+ try:
+ var c: array[3, uint8]
+ if hci_read_class_of_dev(socket, addr(c[0]), 0) < 0:
+ raiseOSError(osLastError())
+ result = (c[2].uint32 shl 16) or (c[1].uint32 shl 8) or c[0]
+ finally:
+ if hci_close_dev(socket) < 0:
+ raiseOSError(osLastError())
+
+
+proc classOfDevice*(device: BluetoothDeviceRemote): uint32 =
+ ## Returns class of remote Bluetooth device.
+ let c = device.fInquiryInfo.dev_class
+ result = (c[2].uint32 shl 16) or (c[1].uint32 shl 8) or c[0]