diff options
| author | Electric-Blue <Electric-Blue@users.noreply.github.com> | 2016-02-01 00:03:45 +0300 |
|---|---|---|
| committer | Electric-Blue <Electric-Blue@users.noreply.github.com> | 2016-02-01 00:03:45 +0300 |
| commit | f626934b2115cfbeb18fb372ac340c47848da443 (patch) | |
| tree | a5e93eeab5d235835e596a9e4dd239a793ebde34 | |
| parent | 48c3a10ccf6ddb82d2dffa063032f9c6e47d238f (diff) | |
| download | NimBluez-f626934b2115cfbeb18fb372ac340c47848da443.tar.gz NimBluez-f626934b2115cfbeb18fb372ac340c47848da443.zip | |
Class of device for bluez.
| -rw-r--r-- | examples/discovery.nim | 6 | ||||
| -rw-r--r-- | nimbluez/bluetooth.nim | 2 | ||||
| -rw-r--r-- | nimbluez/bluetoothbluez.nim | 20 | ||||
| -rw-r--r-- | nimbluez/bluetoothmsbt.nim | 8 |
4 files changed, 28 insertions, 8 deletions
diff --git a/examples/discovery.nim b/examples/discovery.nim index 530c7ca..fb42837 100644 --- a/examples/discovery.nim +++ b/examples/discovery.nim @@ -11,17 +11,17 @@ echo "Local devices:" for localDevice in getLocalDevices(): echo "$1 - $2 - $3" % [localDevice.address, localDevice.name, - localDevice.classRaw.int.toBin(32)] + localDevice.classOfDevice.int.toBin(32)] echo " Remote devices:" for remoteDevice in localDevice.getRemoteDevices(): echo "$1 - $2 - $3" % [remoteDevice.address, remoteDevice.name, - remoteDevice.classRaw.int.toBin(32)] + remoteDevice.classOfDevice.int.toBin(32)] echo "" echo "All remote devices:" for remoteDevice in getRemoteDevices(): echo "$1 - $2 - $3" % [remoteDevice.address, remoteDevice.name, - remoteDevice.classRaw.int.toBin(32)] + remoteDevice.classOfDevice.int.toBin(32)] diff --git a/nimbluez/bluetooth.nim b/nimbluez/bluetooth.nim index 95a9a06..54c7c22 100644 --- a/nimbluez/bluetooth.nim +++ b/nimbluez/bluetooth.nim @@ -22,4 +22,4 @@ export BluetoothDeviceLocalImpl, BluetoothDeviceLocal export BluetoothDeviceRemoteImpl, BluetoothDeviceRemote export getLocalDevice, getLocalDevices export getRemoteDevice, getRemoteDevices -export address, name, classRaw +export address, name, classOfDevice 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] diff --git a/nimbluez/bluetoothmsbt.nim b/nimbluez/bluetoothmsbt.nim index 35cdb14..ca0edbe 100644 --- a/nimbluez/bluetoothmsbt.nim +++ b/nimbluez/bluetoothmsbt.nim @@ -223,11 +223,11 @@ proc name*(device: BluetoothDeviceRemote): string = return cast[WideCString](addr(buf)) $ BLUETOOTH_MAX_NAME_SIZE -proc classRaw*(device: BluetoothDeviceLocal): uint32 = - ## Returns raw class of remote Bluetooth device. +proc classOfDevice*(device: BluetoothDeviceLocal): uint32 = + ## Returns class of local Bluetooth device. result = device.fRadioInfo.ulClassofDevice -proc classRaw*(device: BluetoothDeviceRemote): uint32 = - ## Returns raw class of remote Bluetooth device. +proc classOfDevice*(device: BluetoothDeviceRemote): uint32 = + ## Returns class of remote Bluetooth device. result = device.fDeviceInfo.ulClassofDevice |
