Solved Android, (classic) Bluetooth SPP - QBluetoothDeviceInfo - encode ENUMs into Bits
-
QBluetoothDeviceInfo::QBluetoothDeviceInfo(const QBluetoothAddress &address, const QString &name, quint32 classOfDevice)
My problem is with encoding classOfDevice into the following format:
Bits Size Description 0 - 1 2 Unused, set to 0. 2 - 7 6 Minor device class. 8 - 12 5 Major device class. 13 - 23 11 Service class.
I don’t have a Service class, but Minor and Major Device classes. These are the possible values (ENUMs):
MAJOR CLASS always
QBluetoothDeviceInfo::ImagingDevice (6)
MINOR CLASS - one of this:
QBluetoothDeviceInfo::UncategorizedImagingDevice (0) QBluetoothDeviceInfo::ImageScanner (0x10) QBluetoothDeviceInfo::ImagePrinter (0x20)
Now my question:
How can I encode those ENUM values into the quint32 classOfDevice ?... I’m always fighting with stuff like this ;-)
thanks for hints
-
@ekkescorner Like
if (deviceInfo == QBluetoothDeviceInfo::ImagingDevice) classOfDevice = 0x00000100; // Set bit 8 else ...
?
-
@ekkescorner Like
if (deviceInfo == QBluetoothDeviceInfo::ImagingDevice) classOfDevice = 0x00000100; // Set bit 8 else ...
?
-
@jsulm or since it's now allowed (since c++17 iirc)
if (deviceInfo == QBluetoothDeviceInfo::ImagingDevice) classOfDevice = 0b00000000000000000000000010000000; // Set bit 8 else ...
you can see it directly, admittedly for an int32 lot to type but super nice for int16 where I use it regularly
-
-