diff options
| -rw-r--r-- | examples/discovery.nim | 12 | ||||
| -rw-r--r-- | nimbluez/bluetooth.nim | 2 | ||||
| -rw-r--r-- | nimbluez/bluetoothmsbt.nim | 13 | ||||
| -rw-r--r-- | nimbluez/bluetoothnativesockets.nim | 15 | ||||
| -rw-r--r-- | nimbluez/msbt/ms_bluetoothapis.nim | 1 | ||||
| -rw-r--r-- | nimbluez/msbt/ms_bthdef.nim | 1 | ||||
| -rw-r--r-- | nimbluez/msbt/ms_bthsdpdef.nim | 10 | ||||
| -rw-r--r-- | nimbluez/msbt/ms_ws2bth.nim | 1 |
8 files changed, 36 insertions, 19 deletions
diff --git a/examples/discovery.nim b/examples/discovery.nim index debe0a2..530c7ca 100644 --- a/examples/discovery.nim +++ b/examples/discovery.nim @@ -9,13 +9,19 @@ import ../nimbluez/bluetooth echo "Local devices:" for localDevice in getLocalDevices(): - echo "$1 - $2" % [localDevice.address, localDevice.name] + echo "$1 - $2 - $3" % [localDevice.address, + localDevice.name, + localDevice.classRaw.int.toBin(32)] echo " Remote devices:" for remoteDevice in localDevice.getRemoteDevices(): - echo " $1 - $2" % [remoteDevice.address, remoteDevice.name] + echo "$1 - $2 - $3" % [remoteDevice.address, + remoteDevice.name, + remoteDevice.classRaw.int.toBin(32)] echo "" echo "All remote devices:" for remoteDevice in getRemoteDevices(): - echo "$1 - $2" % [remoteDevice.address, remoteDevice.name] + echo "$1 - $2 - $3" % [remoteDevice.address, + remoteDevice.name, + remoteDevice.classRaw.int.toBin(32)] diff --git a/nimbluez/bluetooth.nim b/nimbluez/bluetooth.nim index 9a04cae..95a9a06 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 +export address, name, classRaw diff --git a/nimbluez/bluetoothmsbt.nim b/nimbluez/bluetoothmsbt.nim index 4d10392..35cdb14 100644 --- a/nimbluez/bluetoothmsbt.nim +++ b/nimbluez/bluetoothmsbt.nim @@ -6,7 +6,8 @@ ## services. It is based on Microsoft Bluetooth protocol stack implementation ## for Windows. -import os, strutils, algorithm, sequtils, winlean +import os, strutils, algorithm, sequtils +from winlean import WINBOOL, NO_ERROR import msbt/ms_bluetoothapis, msbt/ms_bthsdpdef, msbt/ms_bthdef export BLUETOOTH_ADDRESS, BLUETOOTH_RADIO_INFO, BLUETOOTH_DEVICE_INFO @@ -220,3 +221,13 @@ proc name*(device: BluetoothDeviceRemote): string = var buf: array[BLUETOOTH_MAX_NAME_SIZE + 1, WCHAR] copyMem(addr(buf), addr(device.fDeviceInfo.szName), BLUETOOTH_MAX_NAME_SIZE) return cast[WideCString](addr(buf)) $ BLUETOOTH_MAX_NAME_SIZE + + +proc classRaw*(device: BluetoothDeviceLocal): uint32 = + ## Returns raw class of remote Bluetooth device. + result = device.fRadioInfo.ulClassofDevice + + +proc classRaw*(device: BluetoothDeviceRemote): uint32 = + ## Returns raw class of remote Bluetooth device. + result = device.fDeviceInfo.ulClassofDevice diff --git a/nimbluez/bluetoothnativesockets.nim b/nimbluez/bluetoothnativesockets.nim index b079b42..b140106 100644 --- a/nimbluez/bluetoothnativesockets.nim +++ b/nimbluez/bluetoothnativesockets.nim @@ -126,7 +126,7 @@ else: of BTPROTO_RFCOMM: result = cint(bz_bluetooth.BTPROTO_RFCOMM) -proc htobs*(d: int16): int16 = +proc htobs*(d: uint16): uint16 = ## Converts 16-bit integers from host to Bluetooth byte order. ## On machines where the host byte order is the same as Bluetooth byte order, ## this is a no-op; otherwise, it performs a 2-byte swap operation. @@ -136,7 +136,7 @@ proc htobs*(d: int16): int16 = result = d -proc htobl*(d: int32): int32 = +proc htobl*(d: uint32): uint32 = ## Converts 32-bit integers from host to Bluetooth byte order. ## On machines where the host byte order is the same as Bluetooth byte order, ## this is a no-op; otherwise, it performs a 4-byte swap operation. @@ -146,7 +146,7 @@ proc htobl*(d: int32): int32 = result = d -proc htobll*(d: int64): int64 = +proc htobll*(d: uint64): uint64 = ## Converts 64-bit integers from host to Bluetooth byte order. ## On machines where the host byte order is the same as Bluetooth byte order, ## this is a no-op; otherwise, it performs a 8-byte swap operation. @@ -247,14 +247,13 @@ proc getAddrPort*(sockAddr: L2capAddr): L2capPort when useWinVersion: proc getRfcommAddr*(port = RfcommPort(0), address = ""): RfcommAddr = - result.addressFamily = htobs( - toInt(BluetoothDomain.AF_BLUETOOTH).int16).uint16 + result.addressFamily = htobs(toInt(BluetoothDomain.AF_BLUETOOTH).uint16) if address != nil and address != "": result.btAddr = htobll( - parseBluetoothAddress(address).ano_116103095.ullLong.int32).uint32 + parseBluetoothAddress(address).ano_116103095.ullLong) #result.serviceClassId = #TODO: use htob... proc there. - result.port = htobl(if port == 0: -1'i32 else: int32(port)) + result.port = htobl(if port == 0: cast[uint32](-1'i32) else: port) #result.port = htobl(ULONG(port)) @@ -291,7 +290,7 @@ when useWinVersion: proc getAddrString*(sockAddr: RfcommAddr): string = - result = $cast[BLUETOOTH_ADDRESS](btohll(sockAddr.btAddr.int64)) + result = $cast[BLUETOOTH_ADDRESS](btohll(sockAddr.btAddr)) proc getAddrString*(sockAddr: L2capAddr): string = diff --git a/nimbluez/msbt/ms_bluetoothapis.nim b/nimbluez/msbt/ms_bluetoothapis.nim index c895128..118cb3d 100644 --- a/nimbluez/msbt/ms_bluetoothapis.nim +++ b/nimbluez/msbt/ms_bluetoothapis.nim @@ -11,7 +11,6 @@ when not defined(windows): const libbluetooth* = "bthprops.cpl" -import winlean import ms_bthdef, ms_bthsdpdef const diff --git a/nimbluez/msbt/ms_bthdef.nim b/nimbluez/msbt/ms_bthdef.nim index 96be91d..548ab73 100644 --- a/nimbluez/msbt/ms_bthdef.nim +++ b/nimbluez/msbt/ms_bthdef.nim @@ -22,7 +22,6 @@ #Revision History: # # -- -import winlean import ms_bthsdpdef template DEFINE_GUID*(name: expr; p1: int32; p2, p3: int16; diff --git a/nimbluez/msbt/ms_bthsdpdef.nim b/nimbluez/msbt/ms_bthsdpdef.nim index 051fc44..d776db4 100644 --- a/nimbluez/msbt/ms_bthsdpdef.nim +++ b/nimbluez/msbt/ms_bthsdpdef.nim @@ -2,7 +2,9 @@ # Copyright (C) Microsoft. All rights reserved. # -import winlean +from winlean import GUID, HANDLE + +export GUID, HANDLE type WCHAR* = uint16 @@ -18,8 +20,10 @@ type CHAR* = char UCHAR* = uint8 BYTE* = byte -# ULONG* = int32 -# DWORD* = int32 + LONG* = int32 + ULONG* = uint32 + PULONG* = ptr ULONG + DWORD* = uint32 LPSTR* = cstring LPDWORD* = ptr DWORD ULONGLONG* = uint64 diff --git a/nimbluez/msbt/ms_ws2bth.nim b/nimbluez/msbt/ms_ws2bth.nim index 4afb08d..869ec37 100644 --- a/nimbluez/msbt/ms_ws2bth.nim +++ b/nimbluez/msbt/ms_ws2bth.nim @@ -17,7 +17,6 @@ #-- {.passC: "-mno-ms-bitfields".} -import winlean import ms_bthdef, ms_bthsdpdef, ms_bluetoothapis const |
