diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2020-03-14 17:12:52 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-03-16 07:58:20 -0700 |
commit | c2077992ff6e896e6b68df3d8b539a912b0fc325 (patch) | |
tree | 7eef149bfd5aee976405ed3a781bd27267ca93df /core | |
parent | d953c645e96aea092952653adb92280fe4c225f8 (diff) | |
download | subsurface-c2077992ff6e896e6b68df3d8b539a912b0fc325.tar.gz |
android/usb: guess the actual manufacturer and product
For a small number of dive computers we can actually figure out the
real information which we can then later show to the user.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/serial_usb_android.cpp | 47 | ||||
-rw-r--r-- | core/serial_usb_android.h | 2 |
2 files changed, 43 insertions, 6 deletions
diff --git a/core/serial_usb_android.cpp b/core/serial_usb_android.cpp index df371e32a..764977f12 100644 --- a/core/serial_usb_android.cpp +++ b/core/serial_usb_android.cpp @@ -204,6 +204,35 @@ dc_status_t serial_usb_android_open(dc_iostream_t **iostream, dc_context_t *cont return dc_custom_open(iostream, context, DC_TRANSPORT_SERIAL, &callbacks, device); } +static void guessVendorProduct(android_usb_serial_device_descriptor &descriptor) +{ + // for a couple of devices we get enough information that we can guess which dive computer this is + QString product = QString::fromStdString(descriptor.usbProduct); + int vid = descriptor.vid; + int pid = descriptor.pid; + + if (product.contains("HeinrichsWeikamp OSTC3")) { + descriptor.manufacturer = "Heinrichs Weikamp"; + descriptor.product = "OSTC 3"; + } else if (product.contains("HeinrichsWeikamp OSTC 2N")) { + descriptor.manufacturer = "Heinrichs Weikamp"; + descriptor.product = "OSTC 2N"; + } else if (vid == 0x0403 && pid == 0xf460) { + // some form of Oceanic + descriptor.manufacturer = "Oceanic"; + } else if (vid == 0x0403 && pid == 0xf680) { + // some form of Suunto + descriptor.manufacturer = "Suunto"; + } else if (vid == 0x0403 && pid == 0x87d0) { + // some form of Cressi + descriptor.manufacturer = "Cressi"; + } else if (vid == 0xffff && pid == 0x0005) { + // Mares Icon HD + descriptor.manufacturer = "Mares"; + descriptor.product = "Icon HD"; + } +} + android_usb_serial_device_descriptor getDescriptor(QAndroidJniObject usbDevice) { QAndroidJniEnvironment env; @@ -218,7 +247,7 @@ android_usb_serial_device_descriptor getDescriptor(QAndroidJniObject usbDevice) QAndroidJniObject usbManufacturerName = usbDevice.callObjectMethod<jstring>("getManufacturerName"); if (usbManufacturerName.isValid()) { const char *charArray = env->GetStringUTFChars(usbManufacturerName.object<jstring>(), nullptr); - descriptor.manufacturer = std::string(charArray); + descriptor.usbManufacturer = std::string(charArray); env->ReleaseStringUTFChars(usbManufacturerName.object<jstring>(), charArray); } @@ -226,10 +255,13 @@ android_usb_serial_device_descriptor getDescriptor(QAndroidJniObject usbDevice) QAndroidJniObject usbProductName = usbDevice.callObjectMethod<jstring>("getProductName"); if (usbManufacturerName.isValid()) { const char *charArray = env->GetStringUTFChars(usbProductName.object<jstring>(), nullptr); - descriptor.product = std::string(charArray); + descriptor.usbProduct = std::string(charArray); env->ReleaseStringUTFChars(usbProductName.object<jstring>(), charArray); } + // guess the actual manufacturer / product if we happen to be able to guess + guessVendorProduct(descriptor); + // Get busnum and portnum QAndroidJniObject usbDeviceNameString = usbDevice.callObjectMethod<jstring>("getDeviceName"); const char *charArray = env->GetStringUTFChars(usbDeviceNameString.object<jstring>(), nullptr); @@ -241,12 +273,15 @@ android_usb_serial_device_descriptor getDescriptor(QAndroidJniObject usbDevice) // The ui representation char buffer[128]; - if (descriptor.manufacturer.empty()) { - sprintf(buffer, "USB Device [%i:%i]", busnum, portnum); - } else if (descriptor.manufacturer.size() <= 16) { + if (!descriptor.manufacturer.empty()) { + // Heinrichs Weikamp is the longest, so let's just take the name sprintf(buffer, "%s [%i:%i]", descriptor.manufacturer.c_str(), busnum, portnum); + } else if (descriptor.usbManufacturer.empty()) { + sprintf(buffer, "USB Device [%i:%i]", busnum, portnum); + } else if (descriptor.usbManufacturer.size() <= 16) { + sprintf(buffer, "%s [%i:%i]", descriptor.usbManufacturer.c_str(), busnum, portnum); } else { - sprintf(buffer, "%.16s… [%i:%i]", descriptor.manufacturer.c_str(), busnum, portnum); + sprintf(buffer, "%.16s… [%i:%i]", descriptor.usbManufacturer.c_str(), busnum, portnum); } descriptor.uiRepresentation = buffer; diff --git a/core/serial_usb_android.h b/core/serial_usb_android.h index f2c124712..37083c7cf 100644 --- a/core/serial_usb_android.h +++ b/core/serial_usb_android.h @@ -11,6 +11,8 @@ struct android_usb_serial_device_descriptor { std::string uiRepresentation; /* The string that can be used for the user interface. */ // Device information + std::string usbManufacturer; + std::string usbProduct; std::string manufacturer; std::string product; uint16_t pid; |