From e29d63b08c8a64fae848b6f8a9911f555007f09e Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Mon, 12 Apr 2021 19:01:43 -0400 Subject: [PATCH] Add Keysight branding where applicable Because there is now more than one "product name" per device type, we have a concept of a "generic product name" which singularly maps onto a device type. This change comes with a few small breaking changes within the C++ API: DeviceType::GetDeviceTypeString has been renamed to DeviceType::GetGenericProductName to denote that the returned value is not device specific and device->getProductName() is preferable. The member function DeviceType::toString has been renamed to DeviceType::getGenericProductName for the same reason. The DeviceType std::ostream& operator<< has been removed to avoid accidental use of the generic product name. --- api/icsneoc/icsneoc.cpp | 4 +-- device/device.cpp | 2 +- examples/cpp/simple/src/SimpleExample.cpp | 6 ++-- include/icsneo/device/device.h | 1 + include/icsneo/device/devicetype.h | 16 +++++---- .../device/tree/neovifire2/neovifire2.h | 23 +++++++++++++ .../icsneo/device/tree/radmoon2/radmoon2.h | 30 +++++++++++++++++ .../device/tree/radsupermoon/radsupermoon.h | 23 +++++++++++++ .../device/tree/valuecan4/valuecan4-2.h | 24 ++++++++++++++ .../device/tree/valuecan4/valuecan4-2el.h | 33 +++++++++++++++++++ .../device/tree/valuecan4/valuecan4-4.h | 33 +++++++++++++++++++ include/icsneo/icsneoc.h | 3 ++ 12 files changed, 186 insertions(+), 12 deletions(-) diff --git a/api/icsneoc/icsneoc.cpp b/api/icsneoc/icsneoc.cpp index 445afc3..700447b 100644 --- a/api/icsneoc/icsneoc.cpp +++ b/api/icsneoc/icsneoc.cpp @@ -272,7 +272,7 @@ bool icsneo_getProductName(const neodevice_t* device, char* str, size_t* maxLeng if(!icsneo_isValidNeoDevice(device)) return false; - std::string output = device->device->getType().toString(); + std::string output = device->device->getProductName(); if(str == nullptr) { *maxLength = output.length(); @@ -295,7 +295,7 @@ bool icsneo_getProductNameForType(devicetype_t type, char* str, size_t* maxLengt return false; } - std::string output = DeviceType(type).toString(); + std::string output = DeviceType(type).getGenericProductName(); if(str == nullptr) { *maxLength = output.length(); diff --git a/device/device.cpp b/device/device.cpp index e0d9141..65b45be 100644 --- a/device/device.cpp +++ b/device/device.cpp @@ -81,7 +81,7 @@ uint16_t Device::getTimestampResolution() const { std::string Device::describe() const { std::stringstream ss; - ss << getType() << ' ' << getSerial(); + ss << getProductName() << ' ' << getSerial(); return ss.str(); } diff --git a/examples/cpp/simple/src/SimpleExample.cpp b/examples/cpp/simple/src/SimpleExample.cpp index 68f4e87..17f6cf2 100644 --- a/examples/cpp/simple/src/SimpleExample.cpp +++ b/examples/cpp/simple/src/SimpleExample.cpp @@ -11,7 +11,7 @@ int main() { std::cout<< "Supported devices:" << std::endl; for(auto& dev : icsneo::GetSupportedDevices()) - std::cout << '\t' << dev << std::endl; + std::cout << '\t' << dev.getGenericProductName() << std::endl; std::cout << "\nFinding devices... " << std::flush; auto devices = icsneo::FindAllDevices(); // This is type std::vector> @@ -20,11 +20,11 @@ int main() { // List off the devices for(auto& device : devices) - std::cout << '\t' << device->getType() << " - " << device->getSerial() << " @ Handle " << device->getNeoDevice().handle << std::endl; + std::cout << '\t' << device->describe() << " @ Handle " << device->getNeoDevice().handle << std::endl; std::cout << std::endl; for(auto& device : devices) { - std::cout << "Connecting to " << device->getType() << ' ' << device->getSerial() << "... "; + std::cout << "Connecting to " << device->describe() << "... "; bool ret = device->open(); if(!ret) { // Failed to open std::cout << "FAIL" << std::endl; diff --git a/include/icsneo/device/device.h b/include/icsneo/device/device.h index c725e71..39aab48 100644 --- a/include/icsneo/device/device.h +++ b/include/icsneo/device/device.h @@ -41,6 +41,7 @@ public: std::string getSerial() const { return data.serial; } uint32_t getSerialNumber() const { return Device::SerialStringToNum(getSerial()); } const neodevice_t& getNeoDevice() const { return data; } + virtual std::string getProductName() const { return getType().getGenericProductName(); } std::string describe() const; friend std::ostream& operator<<(std::ostream& os, const Device& device) { os << device.describe(); diff --git a/include/icsneo/device/devicetype.h b/include/icsneo/device/devicetype.h index 7167842..b6011ff 100644 --- a/include/icsneo/device/devicetype.h +++ b/include/icsneo/device/devicetype.h @@ -70,7 +70,15 @@ public: VividCAN = (0x40000000), OBD2_SIM = (0x80000000) }; - static const char* GetDeviceTypeString(DeviceType::Enum type) { + + /** + * Get the generic product name for this device type. + * + * Note that device->getProductName() should always be preferred where available, + * as the product name may change based on device-specific factors, such as serial + * number. + */ + static const char* GetGenericProductName(DeviceType::Enum type) { // Adding something? Make sure you update DEVICE_TYPE_LONGEST_NAME at the top! switch(type) { case Unknown: @@ -171,11 +179,7 @@ public: DeviceType(devicetype_t netid) { value = (DeviceType::Enum)netid; } DeviceType(DeviceType::Enum netid) { value = netid; } DeviceType::Enum getDeviceType() const { return value; } - std::string toString() const { return GetDeviceTypeString(getDeviceType()); } - friend std::ostream& operator<<(std::ostream& os, const DeviceType& type) { - os << type.toString().c_str(); - return os; - } + std::string getGenericProductName() const { return GetGenericProductName(getDeviceType()); } operator devicetype_t() const { return getDeviceType(); } private: diff --git a/include/icsneo/device/tree/neovifire2/neovifire2.h b/include/icsneo/device/tree/neovifire2/neovifire2.h index 819fcb1..c0e1242 100644 --- a/include/icsneo/device/tree/neovifire2/neovifire2.h +++ b/include/icsneo/device/tree/neovifire2/neovifire2.h @@ -15,6 +15,11 @@ public: static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::FIRE2; static constexpr const char* SERIAL_START = "CY"; + enum class SKU { + Standard, + AP1200A, // Keysight Branding + }; + static const std::vector& GetSupportedNetworks() { static std::vector supportedNetworks = { Network::NetID::HSCAN, @@ -47,6 +52,24 @@ public: return supportedNetworks; } + SKU getSKU() const { + switch(getSerial().back()) { + case 'A': + return SKU::AP1200A; + default: + return SKU::Standard; + } + } + + std::string getProductName() const override { + switch(getSKU()) { + case SKU::Standard: break; + case SKU::AP1200A: + return "Keysight AP1200A"; + } + return Device::getProductName(); + } + size_t getEthernetActivationLineCount() const override { return 1; } size_t getUSBHostPowerCount() const override { return 1; } bool getBackupPowerSupported() const override { return true; } diff --git a/include/icsneo/device/tree/radmoon2/radmoon2.h b/include/icsneo/device/tree/radmoon2/radmoon2.h index 7b7c38c..e8777ab 100644 --- a/include/icsneo/device/tree/radmoon2/radmoon2.h +++ b/include/icsneo/device/tree/radmoon2/radmoon2.h @@ -16,6 +16,12 @@ public: static constexpr const uint16_t PRODUCT_ID = 0x1202; static constexpr const char* SERIAL_START = "RM"; + enum class SKU { + Standard, + APM1000E, // Keysight Branding + APM1000E_CLK, // Clock Option and Keysight Branding + }; + static std::vector> Find() { std::vector> found; @@ -25,6 +31,30 @@ public: return found; } + SKU getSKU() const { + switch(getSerial().back()) { + case 'A': + case 'B': + return SKU::APM1000E; + case 'C': + case 'D': + return SKU::APM1000E_CLK; + default: + return SKU::Standard; + } + } + + std::string getProductName() const override { + switch(getSKU()) { + case SKU::Standard: break; + case SKU::APM1000E: + return "Keysight APM1000E"; + case SKU::APM1000E_CLK: + return "Keysight APM1000E-CLK"; + } + return Device::getProductName(); + } + // RADMoon 2 does not go online, you can only set settings and // view PHY information (when supported) bool goOnline() override { diff --git a/include/icsneo/device/tree/radsupermoon/radsupermoon.h b/include/icsneo/device/tree/radsupermoon/radsupermoon.h index c92dad6..27c81f4 100644 --- a/include/icsneo/device/tree/radsupermoon/radsupermoon.h +++ b/include/icsneo/device/tree/radsupermoon/radsupermoon.h @@ -16,6 +16,11 @@ public: static constexpr const uint16_t PRODUCT_ID = 0x1201; static constexpr const char* SERIAL_START = "SM"; + enum class SKU { + Standard, + APM1000ET, // Keysight Branding + }; + static std::vector> Find() { std::vector> found; @@ -34,6 +39,24 @@ public: return supportedNetworks; } + SKU getSKU() const { + switch(getSerial().back()) { + case 'A': + return SKU::APM1000ET; + default: + return SKU::Standard; + } + } + + std::string getProductName() const override { + switch(getSKU()) { + case SKU::Standard: break; + case SKU::APM1000ET: + return "Keysight APM1000ET"; + } + return Device::getProductName(); + } + protected: RADSupermoon(neodevice_t neodevice) : Device(neodevice) { initialize(); diff --git a/include/icsneo/device/tree/valuecan4/valuecan4-2.h b/include/icsneo/device/tree/valuecan4/valuecan4-2.h index e996cec..5121938 100644 --- a/include/icsneo/device/tree/valuecan4/valuecan4-2.h +++ b/include/icsneo/device/tree/valuecan4/valuecan4-2.h @@ -16,6 +16,11 @@ public: static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::VCAN4_2; static constexpr const char* SERIAL_START = "V2"; + enum class SKU { + Standard, + AP0200A, // USB A and Keysight Branding + }; + static std::vector> Find() { std::vector> found; @@ -35,6 +40,25 @@ public: return supportedNetworks; } + SKU getSKU() const { + switch(getSerial().back()) { + case 'A': + case 'B': + return SKU::AP0200A; + default: + return SKU::Standard; + } + } + + std::string getProductName() const override { + switch(getSKU()) { + case SKU::Standard: break; + case SKU::AP0200A: + return "Keysight AP0200A"; + } + return Device::getProductName(); + } + protected: virtual void setupSupportedRXNetworks(std::vector& rxNetworks) override { for(auto& netid : GetSupportedNetworks()) diff --git a/include/icsneo/device/tree/valuecan4/valuecan4-2el.h b/include/icsneo/device/tree/valuecan4/valuecan4-2el.h index 94fb0a1..87e8e59 100644 --- a/include/icsneo/device/tree/valuecan4/valuecan4-2el.h +++ b/include/icsneo/device/tree/valuecan4/valuecan4-2el.h @@ -15,6 +15,39 @@ public: static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::VCAN4_2EL; static constexpr const char* SERIAL_START = "VE"; + enum class SKU { + Standard, + AP04E0A_D26, // HDB26, USB A, and Keysight Branding + AP04E0A_MUL, // Multi-connectors, USB A, and Keysight Branding + AP04E0A_OBD, // OBD, USB A, and Keysight Branding + }; + + SKU getSKU() const { + switch(getSerial().back()) { + case 'A': + return SKU::AP04E0A_D26; + case 'B': + return SKU::AP04E0A_MUL; + case 'C': + return SKU::AP04E0A_OBD; + default: + return SKU::Standard; + } + } + + std::string getProductName() const override { + switch(getSKU()) { + case SKU::Standard: break; + case SKU::AP04E0A_D26: + return "Keysight AP04E0A-D26"; + case SKU::AP04E0A_MUL: + return "Keysight AP04E0A-MUL"; + case SKU::AP04E0A_OBD: + return "Keysight AP04E0A-OBD"; + } + return Device::getProductName(); + } + protected: ValueCAN4_2EL(neodevice_t neodevice) : ValueCAN4(neodevice) { getWritableNeoDevice().type = DEVICE_TYPE; diff --git a/include/icsneo/device/tree/valuecan4/valuecan4-4.h b/include/icsneo/device/tree/valuecan4/valuecan4-4.h index 7c9d37d..fa7d640 100644 --- a/include/icsneo/device/tree/valuecan4/valuecan4-4.h +++ b/include/icsneo/device/tree/valuecan4/valuecan4-4.h @@ -16,6 +16,13 @@ public: static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::VCAN4_4; static constexpr const char* SERIAL_START = "V4"; + enum class SKU { + Standard, + AP0400A_D26, // HDB26, USB A, and Keysight Branding + AP0400A_DB9, // 4xDB9, USB A, and Keysight Branding + AP0400A_OBD, // OBD, USB A, and Keysight Branding + }; + static std::vector> Find() { std::vector> found; @@ -37,6 +44,32 @@ public: return supportedNetworks; } + SKU getSKU() const { + switch(getSerial().back()) { + case 'A': + return SKU::AP0400A_D26; + case 'B': + return SKU::AP0400A_DB9; + case 'C': + return SKU::AP0400A_OBD; + default: + return SKU::Standard; + } + } + + std::string getProductName() const override { + switch(getSKU()) { + case SKU::Standard: break; + case SKU::AP0400A_D26: + return "Keysight AP0400A-D26"; + case SKU::AP0400A_DB9: + return "Keysight AP0400A-DB9"; + case SKU::AP0400A_OBD: + return "Keysight AP0400A-OBD"; + } + return Device::getProductName(); + } + protected: virtual void setupSupportedRXNetworks(std::vector& rxNetworks) override { for(auto& netid : GetSupportedNetworks()) diff --git a/include/icsneo/icsneoc.h b/include/icsneo/icsneoc.h index e8db4d3..137ef35 100644 --- a/include/icsneo/icsneoc.h +++ b/include/icsneo/icsneoc.h @@ -337,6 +337,9 @@ extern bool DLLExport icsneo_getProductName(const neodevice_t* device, char* str * * In the case of a neoVI FIRE 2, this function will write a string "neoVI FIRE 2" with a NULL terminator into str. * + * Note that icsneo_getProductName should *always* be preferred where available, as the product name may change based on device-specific + * factors, such as the serial number. + * * The constant ICSNEO_DEVICETYPE_LONGEST_NAME is defined for the client application to create static buffers of the correct length. * * See also icsneo_describeDevice().