Drivers: Ensure serial numbers are uppercase
This prevents mismatches if the device sends a lowercase serial number, which may happen due to an oversight in production.add-device-sharing
parent
00024990e9
commit
407ccccedd
|
|
@ -2,6 +2,7 @@
|
||||||
#include "icsneo/device/founddevice.h"
|
#include "icsneo/device/founddevice.h"
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <cctype>
|
||||||
#include <CoreFoundation/CoreFoundation.h>
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
#include <IOKit/IOKitLib.h>
|
#include <IOKit/IOKitLib.h>
|
||||||
#include <IOKit/usb/IOUSBLib.h>
|
#include <IOKit/usb/IOUSBLib.h>
|
||||||
|
|
@ -166,9 +167,11 @@ void CDCACM::Find(std::vector<FoundDevice>& found) {
|
||||||
if(CFGetTypeID(serialProp) != CFStringGetTypeID())
|
if(CFGetTypeID(serialProp) != CFStringGetTypeID())
|
||||||
continue;
|
continue;
|
||||||
// We can static cast here because we have verified the type to be a CFString
|
// We can static cast here because we have verified the type to be a CFString
|
||||||
const std::string serial = CFStringToString(static_cast<CFStringRef>(serialProp));
|
std::string serial = CFStringToString(static_cast<CFStringRef>(serialProp));
|
||||||
if(serial.empty())
|
if(serial.empty())
|
||||||
continue;
|
continue;
|
||||||
|
for(char& c : serial)
|
||||||
|
c = static_cast<char>(toupper(c));
|
||||||
device.serial[serial.copy(device.serial, sizeof(device.serial)-1)] = '\0';
|
device.serial[serial.copy(device.serial, sizeof(device.serial)-1)] = '\0';
|
||||||
|
|
||||||
// Add a factory to make the driver
|
// Add a factory to make the driver
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <cctype>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <libusb.h>
|
#include <libusb.h>
|
||||||
|
|
||||||
|
|
@ -24,6 +25,8 @@ void FTDI::Find(std::vector<FoundDevice>& found) {
|
||||||
FoundDevice d;
|
FoundDevice d;
|
||||||
strncpy(d.serial, serial.c_str(), deviceSerialBufferLength - 1);
|
strncpy(d.serial, serial.c_str(), deviceSerialBufferLength - 1);
|
||||||
d.serial[deviceSerialBufferLength - 1] = '\0'; // strncpy does not write a null terminator if serial is too long
|
d.serial[deviceSerialBufferLength - 1] = '\0'; // strncpy does not write a null terminator if serial is too long
|
||||||
|
for(size_t i = 0; i < deviceSerialBufferLength - 1; i++)
|
||||||
|
d.serial[i] = toupper(serial[i]);
|
||||||
std::string devHandle = serial;
|
std::string devHandle = serial;
|
||||||
auto it = std::find(handles.begin(), handles.end(), devHandle);
|
auto it = std::find(handles.begin(), handles.end(), devHandle);
|
||||||
size_t foundHandle = SIZE_MAX;
|
size_t foundHandle = SIZE_MAX;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cctype>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
@ -67,6 +68,8 @@ public:
|
||||||
try {
|
try {
|
||||||
std::ifstream reader(ss.str());
|
std::ifstream reader(ss.str());
|
||||||
std::getline(reader, serial);
|
std::getline(reader, serial);
|
||||||
|
for (auto& c : serial)
|
||||||
|
c = toupper(c);
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
succeeded = false;
|
succeeded = false;
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
#include <cwctype>
|
#include <cwctype>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
|
#include <cctype>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
@ -152,6 +153,8 @@ void VCP::Find(std::vector<FoundDevice>& found, std::vector<std::wstring> driver
|
||||||
if(serial.find_first_of('\\') != std::string::npos)
|
if(serial.find_first_of('\\') != std::string::npos)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
for(char& c : serial)
|
||||||
|
c = static_cast<char>(toupper(c));
|
||||||
strcpy_s(device.serial, sizeof(device.serial), serial.c_str());
|
strcpy_s(device.serial, sizeof(device.serial), serial.c_str());
|
||||||
|
|
||||||
// Serial number is saved, we want the COM port number now
|
// Serial number is saved, we want the COM port number now
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue