[IE Myriad] "printf" methods were replaced with mvLog (#552)
This commit is contained in:
parent
d337b4ed97
commit
2012d084f2
@ -104,8 +104,7 @@ int XLinkPlatformBootRemote(deviceDesc_t* deviceDesc, const char* binaryPath)
|
||||
file = fopen(binaryPath, "rb");
|
||||
|
||||
if(file == NULL) {
|
||||
if(usb_loglevel)
|
||||
perror(binaryPath);
|
||||
mvLog(MVLOG_ERROR, "Cannot open file by path: %s", binaryPath);
|
||||
return -7;
|
||||
}
|
||||
|
||||
@ -114,15 +113,13 @@ int XLinkPlatformBootRemote(deviceDesc_t* deviceDesc, const char* binaryPath)
|
||||
rewind(file);
|
||||
if(file_size <= 0 || !(image_buffer = (char*)malloc(file_size)))
|
||||
{
|
||||
if(usb_loglevel)
|
||||
perror("buffer");
|
||||
mvLog(MVLOG_ERROR, "cannot allocate image_buffer. file_size = %ld", file_size);
|
||||
fclose(file);
|
||||
return -3;
|
||||
}
|
||||
if(fread(image_buffer, 1, file_size, file) != file_size)
|
||||
{
|
||||
if(usb_loglevel)
|
||||
perror(binaryPath);
|
||||
mvLog(MVLOG_ERROR, "cannot read file to image_buffer");
|
||||
fclose(file);
|
||||
free(image_buffer);
|
||||
return -7;
|
||||
@ -158,8 +155,8 @@ int XLinkPlatformBootRemote(deviceDesc_t* deviceDesc, const char* binaryPath)
|
||||
rc = usb_boot(deviceDesc->name, image_buffer, file_size);
|
||||
free(image_buffer);
|
||||
|
||||
if(!rc && usb_loglevel > 1) {
|
||||
fprintf(stderr, "Boot successful, device address %s\n", deviceDesc->name);
|
||||
if(!rc) {
|
||||
mvLog(MVLOG_DEBUG, "Boot successful, device address %s", deviceDesc->name);
|
||||
}
|
||||
return rc;
|
||||
} else {
|
||||
@ -249,7 +246,7 @@ libusb_device_handle *usbLinkOpen(const char *path)
|
||||
if (libusb_rc < 0)
|
||||
{
|
||||
if(last_open_dev_err[0])
|
||||
fprintf(stderr, "%s\n", last_open_dev_err);
|
||||
mvLog(MVLOG_ERROR, "Last opened device name: %s", last_open_dev_err);
|
||||
|
||||
usb_close_device(h);
|
||||
usb_free_device(dev);
|
||||
|
@ -16,6 +16,8 @@
|
||||
#include <stdint.h>
|
||||
#include "win_usb.h"
|
||||
|
||||
#define MVLOG_UNIT_NAME xLinkWinUsb
|
||||
#include "XLinkLog.h"
|
||||
#include "XLinkStringUtils.h"
|
||||
|
||||
#define USB_DIR_OUT 0
|
||||
@ -85,7 +87,7 @@ static const char *format_win32_msg(DWORD errId) {
|
||||
|
||||
static void wperror(const char *errmsg) {
|
||||
DWORD errId = GetLastError();
|
||||
fprintf(stderr, "%s: System err %d\n", errmsg, errId);
|
||||
mvLog(MVLOG_DEBUG, "%s: System err %d\n", errmsg, errId);
|
||||
}
|
||||
|
||||
static void wstrerror(char *buff, const char *errmsg) {
|
||||
@ -462,7 +464,7 @@ int usb_bulk_write(usb_hwnd han, uint8_t ep, const void *buffer, size_t sz, uint
|
||||
if(last_bulk_errcode == ERROR_SEM_TIMEOUT)
|
||||
return USB_ERR_TIMEOUT;
|
||||
wperror("WinUsb_WritePipe");
|
||||
printf("\nWinUsb_WritePipe failed with error:=%d\n", GetLastError());
|
||||
mvLog(MVLOG_ERROR, "\nWinUsb_WritePipe failed with error:=%d\n", GetLastError());
|
||||
return USB_ERR_FAILED;
|
||||
}
|
||||
last_bulk_errcode = 0;
|
||||
|
@ -33,6 +33,9 @@
|
||||
#define DEFAULT_SEND_FILE_TIMEOUT 10000
|
||||
#define USB1_CHUNKSZ 64
|
||||
|
||||
#define MVLOG_UNIT_NAME xLinkUsb
|
||||
#include "XLinkLog.h"
|
||||
|
||||
/*
|
||||
* ADDRESS_BUFF_SIZE 35 = 4*7+7.
|
||||
* '255-' x 7 (also gives us nul-terminator for last entry)
|
||||
@ -70,7 +73,6 @@ static deviceBootInfo_t supportedDevices[] = {
|
||||
// for now we'll only use the loglevel for usb boot. can bring it into
|
||||
// the rest of usblink later
|
||||
// use same levels as mvnc_loglevel for now
|
||||
int usb_loglevel = 0;
|
||||
#if (defined(_WIN32) || defined(_WIN64) )
|
||||
void initialize_usb_boot()
|
||||
{
|
||||
@ -123,9 +125,6 @@ static const char *get_pid_name(int pid)
|
||||
return supportedDevices[i].name;
|
||||
}
|
||||
|
||||
if(usb_loglevel)
|
||||
fprintf(stderr, "%s(): Error pid:=%i not supported\n", __func__, pid);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -138,10 +137,7 @@ int get_pid_by_name(const char* name)
|
||||
{
|
||||
char* p = strchr(name, '-');
|
||||
if (p == NULL) {
|
||||
if (usb_loglevel) {
|
||||
fprintf(stderr, "%s(): Error name (%s) not supported\n", __func__, name);
|
||||
}
|
||||
|
||||
mvLog(MVLOG_DEBUG, "Device name (%s) not supported", name);
|
||||
return -1;
|
||||
}
|
||||
p++; //advance to point to the name
|
||||
@ -253,7 +249,7 @@ static pthread_mutex_t globalMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
usbBootError_t usb_find_device_with_bcd(unsigned idx, char *input_addr,
|
||||
unsigned addrsize, void **device, int vid, int pid, uint16_t* bcdusb) {
|
||||
if (pthread_mutex_lock(&globalMutex)) {
|
||||
fprintf(stderr, "Mutex lock failed\n");
|
||||
mvLog(MVLOG_ERROR, "globalMutex lock failed");
|
||||
return USB_BOOT_ERROR;
|
||||
}
|
||||
int searchByName = 0;
|
||||
@ -265,10 +261,9 @@ usbBootError_t usb_find_device_with_bcd(unsigned idx, char *input_addr,
|
||||
int res;
|
||||
|
||||
if (!initialized) {
|
||||
if (usb_loglevel)
|
||||
fprintf(stderr, "Library has not been initialized when loaded\n");
|
||||
mvLog(MVLOG_ERROR, "Library has not been initialized when loaded");
|
||||
if (pthread_mutex_unlock(&globalMutex)) {
|
||||
fprintf(stderr, "Mutex unlock failed\n");
|
||||
mvLog(MVLOG_ERROR, "globalMutex unlock failed");
|
||||
}
|
||||
return USB_BOOT_ERROR;
|
||||
}
|
||||
@ -284,10 +279,9 @@ usbBootError_t usb_find_device_with_bcd(unsigned idx, char *input_addr,
|
||||
devs = 0;
|
||||
}
|
||||
if ((res = libusb_get_device_list(NULL, &devs)) < 0) {
|
||||
if (usb_loglevel)
|
||||
fprintf(stderr, "Unable to get USB device list: %s\n", libusb_strerror(res));
|
||||
mvLog(MVLOG_DEBUG, "Unable to get USB device list: %s", libusb_strerror(res));
|
||||
if (pthread_mutex_unlock(&globalMutex)) {
|
||||
fprintf(stderr, "Mutex unlock failed\n");
|
||||
mvLog(MVLOG_ERROR, "globalMutex unlock failed");
|
||||
}
|
||||
return USB_BOOT_ERROR;
|
||||
}
|
||||
@ -297,8 +291,7 @@ usbBootError_t usb_find_device_with_bcd(unsigned idx, char *input_addr,
|
||||
i = 0;
|
||||
while ((dev = devs[i++]) != NULL) {
|
||||
if ((res = libusb_get_device_descriptor(dev, &desc)) < 0) {
|
||||
if (usb_loglevel)
|
||||
fprintf(stderr, "Unable to get USB device descriptor: %s\n", libusb_strerror(res));
|
||||
mvLog(MVLOG_DEBUG, "Unable to get USB device descriptor: %s", libusb_strerror(res));
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -320,10 +313,8 @@ usbBootError_t usb_find_device_with_bcd(unsigned idx, char *input_addr,
|
||||
if (device) {
|
||||
const char *dev_addr = gen_addr(dev, get_pid_by_name(input_addr));
|
||||
if (!strcmp(dev_addr, input_addr)) {
|
||||
if (usb_loglevel > 1) {
|
||||
fprintf(stderr, "Found Address: %s - VID/PID %04x:%04x\n",
|
||||
input_addr, desc.idVendor, desc.idProduct);
|
||||
}
|
||||
mvLog(MVLOG_DEBUG, "Found Address: %s - VID/PID %04x:%04x",
|
||||
input_addr, desc.idVendor, desc.idProduct);
|
||||
|
||||
libusb_ref_device(dev);
|
||||
libusb_free_device_list(devs, 1);
|
||||
@ -333,7 +324,7 @@ usbBootError_t usb_find_device_with_bcd(unsigned idx, char *input_addr,
|
||||
devs = 0;
|
||||
|
||||
if (pthread_mutex_unlock(&globalMutex)) {
|
||||
fprintf(stderr, "Mutex unlock failed\n");
|
||||
mvLog(MVLOG_ERROR, "globalMutex unlock failed");
|
||||
}
|
||||
return USB_BOOT_SUCCESS;
|
||||
}
|
||||
@ -341,24 +332,21 @@ usbBootError_t usb_find_device_with_bcd(unsigned idx, char *input_addr,
|
||||
const char *dev_addr = gen_addr(dev, desc.idProduct);
|
||||
// If the same add as input
|
||||
if (!strcmp(dev_addr, input_addr)) {
|
||||
if (usb_loglevel > 1) {
|
||||
fprintf(stderr, "Found Address: %s - VID/PID %04x:%04x\n",
|
||||
input_addr, desc.idVendor, desc.idProduct);
|
||||
}
|
||||
mvLog(MVLOG_DEBUG, "Found Address: %s - VID/PID %04x:%04x",
|
||||
input_addr, desc.idVendor, desc.idProduct);
|
||||
|
||||
if (pthread_mutex_unlock(&globalMutex)) {
|
||||
fprintf(stderr, "Mutex unlock failed\n");
|
||||
mvLog(MVLOG_ERROR, "globalMutex unlock failed");
|
||||
}
|
||||
return USB_BOOT_SUCCESS;
|
||||
}
|
||||
} else if (idx == count) {
|
||||
const char *caddr = gen_addr(dev, desc.idProduct);
|
||||
if (usb_loglevel > 1)
|
||||
fprintf(stderr, "Device %d Address: %s - VID/PID %04x:%04x\n",
|
||||
idx, caddr, desc.idVendor, desc.idProduct);
|
||||
mvLog(MVLOG_DEBUG, "Device %d Address: %s - VID/PID %04x:%04x",
|
||||
idx, caddr, desc.idVendor, desc.idProduct);
|
||||
mv_strncpy(input_addr, addrsize, caddr, addrsize - 1);
|
||||
if (pthread_mutex_unlock(&globalMutex)) {
|
||||
fprintf(stderr, "Mutex unlock failed\n");
|
||||
mvLog(MVLOG_ERROR, "globalMutex unlock failed");
|
||||
}
|
||||
return USB_BOOT_SUCCESS;
|
||||
}
|
||||
@ -368,7 +356,7 @@ usbBootError_t usb_find_device_with_bcd(unsigned idx, char *input_addr,
|
||||
libusb_free_device_list(devs, 1);
|
||||
devs = 0;
|
||||
if (pthread_mutex_unlock(&globalMutex)) {
|
||||
fprintf(stderr, "Mutex unlock failed\n");
|
||||
mvLog(MVLOG_ERROR, "globalMutex unlock failed");
|
||||
}
|
||||
return USB_BOOT_DEVICE_NOT_FOUND;
|
||||
}
|
||||
@ -396,15 +384,13 @@ usbBootError_t usb_find_device(unsigned idx, char *addr, unsigned addrsize, void
|
||||
|
||||
if(!initialized)
|
||||
{
|
||||
if(usb_loglevel)
|
||||
fprintf(stderr, "Library has not been initialized when loaded\n");
|
||||
mvLog(MVLOG_ERROR, "Library has not been initialized when loaded");
|
||||
return USB_BOOT_ERROR;
|
||||
}
|
||||
if (devs_cnt == 0 || idx == 0) {
|
||||
devs_cnt = 0;
|
||||
if (((res = usb_list_devices(vid, pid, devs)) < 0)) {
|
||||
if (usb_loglevel)
|
||||
fprintf(stderr, "Unable to get USB device list: %s\n", libusb_strerror(res));
|
||||
mvLog(MVLOG_DEBUG, "Unable to get USB device list: %s", libusb_strerror(res));
|
||||
return USB_BOOT_ERROR;
|
||||
}
|
||||
devs_cnt = res;
|
||||
@ -436,8 +422,7 @@ usbBootError_t usb_find_device(unsigned idx, char *addr, unsigned addrsize, void
|
||||
const char *caddr = &devs[res][4];
|
||||
if (strncmp(addr, caddr, XLINK_MAX_NAME_SIZE) == 0)
|
||||
{
|
||||
if (usb_loglevel > 1)
|
||||
fprintf(stderr, "Found Address: %s - VID/PID %04x:%04x\n", caddr, (int)(devs[res][0] << 8 | devs[res][1]), (int)(devs[res][2] << 8 | devs[res][3]));
|
||||
mvLog(MVLOG_DEBUG, "Found Address: %s - VID/PID %04x:%04x", caddr, (int)(devs[res][0] << 8 | devs[res][1]), (int)(devs[res][2] << 8 | devs[res][3]));
|
||||
*device = enumerate_usb_device(vid, pid, caddr, 0);
|
||||
devs_cnt = 0;
|
||||
return USB_BOOT_SUCCESS;
|
||||
@ -447,16 +432,14 @@ usbBootError_t usb_find_device(unsigned idx, char *addr, unsigned addrsize, void
|
||||
const char *caddr = &devs[res][4];
|
||||
if (strncmp(addr, caddr, XLINK_MAX_NAME_SIZE) == 0)
|
||||
{
|
||||
if (usb_loglevel > 1)
|
||||
fprintf(stderr, "Found Address: %s - VID/PID %04x:%04x\n", caddr, (int)(devs[res][0] << 8 | devs[res][1]), (int)(devs[res][2] << 8 | devs[res][3]));
|
||||
mvLog(MVLOG_DEBUG, "Found Address: %s - VID/PID %04x:%04x", caddr, (int)(devs[res][0] << 8 | devs[res][1]), (int)(devs[res][2] << 8 | devs[res][3]));
|
||||
return USB_BOOT_SUCCESS;
|
||||
}
|
||||
}
|
||||
else if (idx == count)
|
||||
{
|
||||
const char *caddr = &devs[res][4];
|
||||
if (usb_loglevel > 1)
|
||||
fprintf(stderr, "Device %d Address: %s - VID/PID %04x:%04x\n", idx, caddr, (int)(devs[res][0] << 8 | devs[res][1]), (int)(devs[res][2] << 8 | devs[res][3]));
|
||||
mvLog(MVLOG_DEBUG, "Device %d Address: %s - VID/PID %04x:%04x", idx, caddr, (int)(devs[res][0] << 8 | devs[res][1]), (int)(devs[res][2] << 8 | devs[res][3]));
|
||||
mv_strncpy(addr, addrsize, caddr, addrsize - 1);
|
||||
return USB_BOOT_SUCCESS;
|
||||
}
|
||||
@ -503,9 +486,8 @@ static libusb_device_handle *usb_open_device(libusb_device *dev, uint8_t *endpoi
|
||||
ifdesc = cdesc->interface->altsetting;
|
||||
for(i=0; i<ifdesc->bNumEndpoints; i++)
|
||||
{
|
||||
if(usb_loglevel > 1)
|
||||
fprintf(stderr, "Found EP 0x%02x : max packet size is %u bytes\n",
|
||||
ifdesc->endpoint[i].bEndpointAddress, ifdesc->endpoint[i].wMaxPacketSize);
|
||||
mvLog(MVLOG_DEBUG, "Found EP 0x%02x : max packet size is %u bytes",
|
||||
ifdesc->endpoint[i].bEndpointAddress, ifdesc->endpoint[i].wMaxPacketSize);
|
||||
if((ifdesc->endpoint[i].bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) != LIBUSB_TRANSFER_TYPE_BULK)
|
||||
continue;
|
||||
if( !(ifdesc->endpoint[i].bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) )
|
||||
@ -542,14 +524,13 @@ static int wait_findopen(const char *device_address, int timeout, libusb_device
|
||||
}
|
||||
|
||||
usleep(100000);
|
||||
if(usb_loglevel > 1)
|
||||
{
|
||||
if(timeout == -1)
|
||||
fprintf(stderr, "Starting wait for connect, no timeout\n");
|
||||
else if(timeout == 0)
|
||||
fprintf(stderr, "Trying to connect\n");
|
||||
else fprintf(stderr, "Starting wait for connect with %ums timeout\n", timeout);
|
||||
}
|
||||
|
||||
if(timeout == -1)
|
||||
mvLog(MVLOG_DEBUG, "Starting wait for connect, no timeout");
|
||||
else if(timeout == 0)
|
||||
mvLog(MVLOG_DEBUG, "Trying to connect");
|
||||
else mvLog(MVLOG_DEBUG, "Starting wait for connect with %ums timeout", timeout);
|
||||
|
||||
last_open_dev_err[0] = 0;
|
||||
i = 0;
|
||||
for(;;)
|
||||
@ -574,8 +555,7 @@ static int wait_findopen(const char *device_address, int timeout, libusb_device
|
||||
#endif
|
||||
if(*devh != NULL)
|
||||
{
|
||||
if(usb_loglevel > 1)
|
||||
fprintf(stderr, "Found and opened device\n");
|
||||
mvLog(MVLOG_DEBUG, "Found and opened device");
|
||||
return 0;
|
||||
}
|
||||
#if (!defined(_WIN32) && !defined(_WIN64) )
|
||||
@ -588,12 +568,11 @@ static int wait_findopen(const char *device_address, int timeout, libusb_device
|
||||
|
||||
if(timeout != -1)
|
||||
{
|
||||
if(usb_loglevel)
|
||||
{
|
||||
if(last_open_dev_err[0])
|
||||
fprintf(stderr, "%s", last_open_dev_err);
|
||||
fprintf(stderr, "error: device not found!\n");
|
||||
}
|
||||
if(last_open_dev_err[0])
|
||||
mvLog(MVLOG_ERROR, "Last opened device name: %s", last_open_dev_err);
|
||||
|
||||
mvLog(MVLOG_ERROR, "error: device not found!");
|
||||
|
||||
return rc ? USB_BOOT_DEVICE_NOT_FOUND : USB_BOOT_TIMEOUT;
|
||||
} else if (elapsedTime > (double)timeout) {
|
||||
return rc ? USB_BOOT_DEVICE_NOT_FOUND : USB_BOOT_TIMEOUT;
|
||||
@ -625,8 +604,7 @@ static int send_file(libusb_device_handle *h, uint8_t endpoint, const uint8_t *t
|
||||
bulk_chunklen = USB1_CHUNKSZ;
|
||||
}
|
||||
#endif
|
||||
if(usb_loglevel > 1)
|
||||
fprintf(stderr, "Performing bulk write of %u bytes...\n", filesize);
|
||||
mvLog(MVLOG_DEBUG, "Performing bulk write of %u bytes...", filesize);
|
||||
while((unsigned)twb < filesize)
|
||||
{
|
||||
highres_gettime(&t1);
|
||||
@ -643,8 +621,7 @@ static int send_file(libusb_device_handle *h, uint8_t endpoint, const uint8_t *t
|
||||
{
|
||||
if(rc == LIBUSB_ERROR_NO_DEVICE)
|
||||
break;
|
||||
if(usb_loglevel)
|
||||
fprintf(stderr, "bulk write: %s (%d bytes written, %d bytes to write)\n", libusb_strerror(rc), wbr, wb);
|
||||
mvLog(MVLOG_WARN, "bulk write: %s (%d bytes written, %d bytes to write)", libusb_strerror(rc), wbr, wb);
|
||||
if(rc == LIBUSB_ERROR_TIMEOUT)
|
||||
return USB_BOOT_TIMEOUT;
|
||||
else return USB_BOOT_ERROR;
|
||||
@ -657,11 +634,12 @@ static int send_file(libusb_device_handle *h, uint8_t endpoint, const uint8_t *t
|
||||
twb += wbr;
|
||||
p += wbr;
|
||||
}
|
||||
if(usb_loglevel > 1)
|
||||
{
|
||||
double MBpS = ((double)filesize / 1048576.) / (elapsedTime * 0.001);
|
||||
fprintf(stderr, "Successfully sent %u bytes of data in %lf ms (%lf MB/s)\n", filesize, elapsedTime, MBpS);
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
double MBpS = ((double)filesize / 1048576.) / (elapsedTime * 0.001);
|
||||
mvLog(MVLOG_DEBUG, "Successfully sent %u bytes of data in %lf ms (%lf MB/s)", filesize, elapsedTime, MBpS);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -6,8 +6,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int usb_loglevel;
|
||||
|
||||
#define AUTO_VID 0
|
||||
#define AUTO_PID 0
|
||||
#define AUTO_UNBOOTED_PID -1
|
||||
|
Loading…
Reference in New Issue
Block a user