Skip to content

Commit

Permalink
Add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahAndrews committed Nov 14, 2023
1 parent 6917751 commit 6317314
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/native/c/candlelib/candle.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,14 @@ bool __stdcall candle_list_scan(candle_list_handle *list)

GUID guid;
if (CLSIDFromString(L"{c15b4308-04d3-11e6-b3ea-6057189e6443}", &guid) != NOERROR) {
printf("CLSIDFromString() failed\n");
l->last_error = CANDLE_ERR_CLSID;
return false;
}

HDEVINFO hdi = SetupDiGetClassDevs(&guid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (hdi == INVALID_HANDLE_VALUE) {
printf("SetupDiGetClassDevs() failed\n");
l->last_error = CANDLE_ERR_GET_DEVICES;
return false;
}
Expand All @@ -143,21 +145,29 @@ bool __stdcall candle_list_scan(candle_list_handle *list)
interfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);

if (SetupDiEnumDeviceInterfaces(hdi, NULL, &guid, i, &interfaceData)) {
printf("SetupDiEnumDeviceInterfaces(%d) returned a truthy value\n", i);

if (!candle_read_di(hdi, interfaceData, &l->dev[i])) {
printf("candle_read_di() failed\n");

l->last_error = l->dev[i].last_error;
rv = false;
break;
}

} else {
printf("SetupDiEnumDeviceInterfaces(%d) returned a falsey value\n", i);

DWORD err = GetLastError();
if (err==ERROR_NO_MORE_ITEMS) {
printf("Found all available devices\n");

l->num_devices = i;
l->last_error = CANDLE_ERR_OK;
rv = true;
} else {
printf("SetupDiEnumDeviceInterfaces(%d) failed\n", i);

l->last_error = CANDLE_ERR_SETUPDI_IF_ENUM;
rv = false;
}
Expand All @@ -168,9 +178,13 @@ bool __stdcall candle_list_scan(candle_list_handle *list)
SP_DEVINFO_DATA devInfoData;
devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
if (SetupDiEnumDeviceInfo(hdi, i, &devInfoData)) {

printf("SetupDiEnumDeviceInfo(%d) succeeded\n", i);
candle_read_device_name(hdi, &devInfoData, &l->dev[i]);
}
else {
printf("SetupDiEnumDeviceInfo(%d) failed. Device name is unknown.\n", i);

sprintf(l->dev[i].name, "Unknown");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ std::vector<CANDeviceDetail> CandleWinUSBDriver::GetDevices()
candle_handle dev;
std::vector<CANDeviceDetail> retval;

std::cout << "CandleWinUSBDriver.GetDevices()" << std::endl;

if (candle_list_scan(&clist)) {
std::cout << "candle_list_scan() returned true" << std::endl;

if (candle_list_length(clist, &num_interfaces)) {
for (uint8_t i=0; i<num_interfaces; i++) {
if (candle_dev_get(clist, i, &dev)) {
Expand All @@ -59,6 +63,8 @@ std::vector<CANDeviceDetail> CandleWinUSBDriver::GetDevices()
}
}
candle_list_free(clist);
} else {
std::cout << "candle_list_scan() returned false" << std::endl;
}

return retval;
Expand Down

0 comments on commit 6317314

Please sign in to comment.