diff options
Diffstat (limited to 'nimbluez')
| -rw-r--r-- | nimbluez/bluetooth.nim | 2 | ||||
| -rw-r--r-- | nimbluez/bluetoothbluez.nim | 20 | ||||
| -rw-r--r-- | nimbluez/bluetoothmsbt.nim | 8 |
3 files changed, 25 insertions, 5 deletions
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 |
