Skip to content

Commit

Permalink
Fix GlasgowSWDInterface serial number discovery.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Sep 11, 2018
1 parent e19e380 commit 6844146
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions GlasgowSWDInterface.cpp
Expand Up @@ -118,13 +118,16 @@ string GlasgowSWDInterface::GetSerialNumber(int index)
{
int ret;
int curr_index = 0;
char device_serial[64] = {};
string serial;

ForEachGlasgowDevice([&](libusb_device_descriptor *desc, libusb_device_handle *handle) {
if(curr_index == index) {
char serial_array[64] = {};
if((ret = libusb_get_string_descriptor_ascii(handle, desc->iSerialNumber,
(uint8_t *)device_serial, sizeof(device_serial))) != 0) {
strncpy(device_serial, "(error)", sizeof(device_serial));
(uint8_t *)serial_array, sizeof(serial_array))) < 0) {
serial = string("(error: ") + libusb_error_name(ret) + ")";
} else {
serial = string(serial_array, ret);
}

return true;
Expand All @@ -134,7 +137,7 @@ string GlasgowSWDInterface::GetSerialNumber(int index)
}
});

return device_serial;
return serial;
}

string GlasgowSWDInterface::GetDescription(int index)
Expand Down Expand Up @@ -216,15 +219,15 @@ GlasgowSWDInterface::GlasgowSWDInterface(const string& serial)

char device_serial[64];
if((ret = libusb_get_string_descriptor_ascii(device_handle, device_desc.iSerialNumber,
(uint8_t *)device_serial, sizeof(device_serial))) != 0) {
(uint8_t *)device_serial, sizeof(device_serial))) < 0) {
LogError("Cannot get serial number for Glasgow device %03d:%03d\n",
libusb_get_bus_number(device),
libusb_get_port_number(device));
libusb_close(device_handle);
continue;
}

if(serial == "" || serial == device_serial) {
if(serial == "" || serial == string(device_serial, ret)) {
m_device = libusb_ref_device(device);
m_handle = device_handle;
m_serial = device_serial;
Expand Down

0 comments on commit 6844146

Please sign in to comment.