mirror of
https://github.com/mariusgreuel/avrdude.git
synced 2025-09-28 23:15:27 +00:00
Review and overhaul AVRDUDE's messaging system (#1126)
* Change avrdude_message(MSG_XYZ, ...) to msg_xyz(...) * Define and use pmsg_xyz(...) instead of msg_xyz("%s: ...", progname, ...) * Review and change avrdude_message() levels - Introduce new levels warning, error and ext_error - Distribute info level to info, warning, error, ext_error - Assign levels (more) consistently - Unify grammar, punctuation and style of messages * Use imsg_xyz() to print indented messages * Show function name in errors and warnings on -v * Reduce effective verbosity level by number of -q above one
This commit is contained in:
103
src/usb_libusb.c
103
src/usb_libusb.c
@@ -97,8 +97,7 @@ static int usbdev_open(const char *port, union pinfo pinfo, union filedescriptor
|
||||
|
||||
if (strlen(serno) > 12)
|
||||
{
|
||||
avrdude_message(MSG_INFO, "%s: usbdev_open(): invalid serial number \"%s\"\n",
|
||||
progname, serno);
|
||||
pmsg_error("invalid serial number %s\n", serno);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -126,8 +125,7 @@ static int usbdev_open(const char *port, union pinfo pinfo, union filedescriptor
|
||||
dev->descriptor.iSerialNumber,
|
||||
string, sizeof(string)) < 0)
|
||||
{
|
||||
avrdude_message(MSG_INFO, "%s: usb_open(): cannot read serial number \"%s\"\n",
|
||||
progname, usb_strerror());
|
||||
pmsg_error("cannot read serial number: %s\n", usb_strerror());
|
||||
/*
|
||||
* On some systems, libusb appears to have
|
||||
* problems sending control messages. Catch the
|
||||
@@ -145,8 +143,7 @@ static int usbdev_open(const char *port, union pinfo pinfo, union filedescriptor
|
||||
dev->descriptor.iProduct,
|
||||
product, sizeof(product)) < 0)
|
||||
{
|
||||
avrdude_message(MSG_INFO, "%s: usb_open(): cannot read product name \"%s\"\n",
|
||||
progname, usb_strerror());
|
||||
pmsg_error("cannot read product name: %s\n", usb_strerror());
|
||||
strcpy(product, "[unnamed product]");
|
||||
}
|
||||
/*
|
||||
@@ -172,8 +169,7 @@ static int usbdev_open(const char *port, union pinfo pinfo, union filedescriptor
|
||||
fd->usb.wep = 0x02;
|
||||
}
|
||||
|
||||
avrdude_message(MSG_NOTICE, "%s: usbdev_open(): Found %s, serno: %s\n",
|
||||
progname, product, string);
|
||||
pmsg_notice("usbdev_open(): found %s, serno: %s\n", product, string);
|
||||
if (serno != NULL)
|
||||
{
|
||||
/*
|
||||
@@ -184,8 +180,7 @@ static int usbdev_open(const char *port, union pinfo pinfo, union filedescriptor
|
||||
x = strlen(string) - strlen(serno);
|
||||
if (strcasecmp(string + x, serno) != 0)
|
||||
{
|
||||
avrdude_message(MSG_DEBUG, "%s: usbdev_open(): serial number doesn't match\n",
|
||||
progname);
|
||||
pmsg_debug("usbdev_open(): serial number does not match\n");
|
||||
usb_close(udev);
|
||||
continue;
|
||||
}
|
||||
@@ -193,16 +188,14 @@ static int usbdev_open(const char *port, union pinfo pinfo, union filedescriptor
|
||||
|
||||
if (dev->config == NULL)
|
||||
{
|
||||
avrdude_message(MSG_INFO, "%s: usbdev_open(): USB device has no configuration\n",
|
||||
progname);
|
||||
pmsg_warning("USB device has no configuration\n");
|
||||
goto trynext;
|
||||
}
|
||||
|
||||
if (usb_set_configuration(udev, dev->config[0].bConfigurationValue))
|
||||
{
|
||||
avrdude_message(MSG_INFO, "%s: usbdev_open(): WARNING: failed to set configuration %d: %s\n",
|
||||
progname, dev->config[0].bConfigurationValue,
|
||||
usb_strerror());
|
||||
pmsg_warning("unable to set configuration %d: %s\n",
|
||||
dev->config[0].bConfigurationValue, usb_strerror());
|
||||
/* let's hope it has already been configured */
|
||||
// goto trynext;
|
||||
}
|
||||
@@ -221,8 +214,8 @@ static int usbdev_open(const char *port, union pinfo pinfo, union filedescriptor
|
||||
#endif
|
||||
if (usb_claim_interface(udev, usb_interface))
|
||||
{
|
||||
avrdude_message(MSG_INFO, "%s: usbdev_open(): error claiming interface %d: %s\n",
|
||||
progname, usb_interface, usb_strerror());
|
||||
pmsg_error("unable to claim interface %d: %s\n",
|
||||
usb_interface, usb_strerror());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -239,8 +232,7 @@ static int usbdev_open(const char *port, union pinfo pinfo, union filedescriptor
|
||||
}
|
||||
if (iface == dev->config[0].bNumInterfaces)
|
||||
{
|
||||
avrdude_message(MSG_INFO, "%s: usbdev_open(): no usable interface found\n",
|
||||
progname);
|
||||
pmsg_warning("no usable interface found\n");
|
||||
goto trynext;
|
||||
}
|
||||
|
||||
@@ -255,16 +247,15 @@ static int usbdev_open(const char *port, union pinfo pinfo, union filedescriptor
|
||||
|
||||
if ((possible_ep & USB_ENDPOINT_DIR_MASK) != 0)
|
||||
{
|
||||
avrdude_message(MSG_NOTICE2, "%s: usbdev_open(): using read endpoint 0x%02x\n",
|
||||
progname, possible_ep);
|
||||
pmsg_notice2("usbdev_open(): using read endpoint 0x%02x\n", possible_ep);
|
||||
fd->usb.rep = possible_ep;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (fd->usb.rep == 0)
|
||||
{
|
||||
avrdude_message(MSG_INFO, "%s: usbdev_open(): cannot find a read endpoint, using 0x%02x\n",
|
||||
progname, USBDEV_BULK_EP_READ_MKII);
|
||||
pmsg_error("cannot find a read endpoint, using 0x%02x\n",
|
||||
USBDEV_BULK_EP_READ_MKII);
|
||||
fd->usb.rep = USBDEV_BULK_EP_READ_MKII;
|
||||
}
|
||||
}
|
||||
@@ -274,34 +265,31 @@ static int usbdev_open(const char *port, union pinfo pinfo, union filedescriptor
|
||||
dev->config[0].interface[iface].altsetting[0].endpoint[i].bEndpointAddress == fd->usb.wep) &&
|
||||
dev->config[0].interface[iface].altsetting[0].endpoint[i].wMaxPacketSize < fd->usb.max_xfer)
|
||||
{
|
||||
avrdude_message(MSG_NOTICE, "%s: max packet size expected %d, but found %d due to EP 0x%02x's wMaxPacketSize\n",
|
||||
progname,
|
||||
fd->usb.max_xfer,
|
||||
dev->config[0].interface[iface].altsetting[0].endpoint[i].wMaxPacketSize,
|
||||
dev->config[0].interface[iface].altsetting[0].endpoint[i].bEndpointAddress);
|
||||
fd->usb.max_xfer = dev->config[0].interface[iface].altsetting[0].endpoint[i].wMaxPacketSize;
|
||||
pmsg_notice("max packet size expected %d, but found %d due to EP 0x%02x's wMaxPacketSize\n",
|
||||
fd->usb.max_xfer,
|
||||
dev->config[0].interface[iface].altsetting[0].endpoint[i].wMaxPacketSize,
|
||||
dev->config[0].interface[iface].altsetting[0].endpoint[i].bEndpointAddress);
|
||||
fd->usb.max_xfer = dev->config[0].interface[iface].altsetting[0].endpoint[i].wMaxPacketSize;
|
||||
}
|
||||
}
|
||||
if (pinfo.usbinfo.flags & PINFO_FL_USEHID)
|
||||
{
|
||||
if (usb_control_msg(udev, 0x21, 0x0a /* SET_IDLE */, 0, 0, NULL, 0, 100) < 0)
|
||||
avrdude_message(MSG_INFO, "%s: usbdev_open(): SET_IDLE failed\n", progname);
|
||||
pmsg_error("SET_IDLE failed\n");
|
||||
}
|
||||
return 0;
|
||||
trynext:
|
||||
usb_close(udev);
|
||||
}
|
||||
else
|
||||
avrdude_message(MSG_INFO, "%s: usbdev_open(): cannot open device: %s\n",
|
||||
progname, usb_strerror());
|
||||
pmsg_error("cannot open device: %s\n", usb_strerror());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((pinfo.usbinfo.flags & PINFO_FL_SILENT) == 0)
|
||||
avrdude_message(MSG_NOTICE, "%s: usbdev_open(): did not find any%s USB device \"%s\" (0x%04x:0x%04x)\n",
|
||||
progname, serno? " (matching)": "", port,
|
||||
(unsigned)pinfo.usbinfo.vid, (unsigned)pinfo.usbinfo.pid);
|
||||
pmsg_notice("usbdev_open(): did not find any%s USB device \"%s\" (0x%04x:0x%04x)\n",
|
||||
serno? " (matching)": "", port, (unsigned)pinfo.usbinfo.vid, (unsigned)pinfo.usbinfo.pid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -353,8 +341,7 @@ static int usbdev_send(const union filedescriptor *fd, const unsigned char *bp,
|
||||
rv = usb_bulk_write(udev, fd->usb.wep, (char *)bp, tx_size, 10000);
|
||||
if (rv != tx_size)
|
||||
{
|
||||
avrdude_message(MSG_INFO, "%s: usbdev_send(): wrote %d out of %d bytes, err = %s\n",
|
||||
progname, rv, tx_size, usb_strerror());
|
||||
pmsg_error("wrote %d out of %d bytes, err = %s\n", rv, tx_size, usb_strerror());
|
||||
return -1;
|
||||
}
|
||||
bp += tx_size;
|
||||
@@ -363,22 +350,22 @@ static int usbdev_send(const union filedescriptor *fd, const unsigned char *bp,
|
||||
|
||||
if (verbose > 3)
|
||||
{
|
||||
avrdude_message(MSG_TRACE, "%s: Sent: ", progname);
|
||||
pmsg_trace("sent: ");
|
||||
|
||||
while (i) {
|
||||
unsigned char c = *p;
|
||||
if (isprint(c)) {
|
||||
avrdude_message(MSG_TRACE, "%c ", c);
|
||||
msg_trace("%c ", c);
|
||||
}
|
||||
else {
|
||||
avrdude_message(MSG_TRACE, ". ");
|
||||
msg_trace(". ");
|
||||
}
|
||||
avrdude_message(MSG_TRACE, "[%02x] ", c);
|
||||
msg_trace("[%02x] ", c);
|
||||
|
||||
p++;
|
||||
i--;
|
||||
}
|
||||
avrdude_message(MSG_TRACE, "\n");
|
||||
msg_trace("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -402,9 +389,8 @@ usb_fill_buf(usb_dev_handle *udev, int maxsize, int ep, int use_interrupt_xfer)
|
||||
rv = usb_bulk_read(udev, ep, usbbuf, maxsize, 10000);
|
||||
if (rv < 0)
|
||||
{
|
||||
avrdude_message(MSG_NOTICE2, "%s: usb_fill_buf(): usb_%s_read() error %s\n",
|
||||
progname, (use_interrupt_xfer? "interrupt": "bulk"),
|
||||
usb_strerror());
|
||||
pmsg_notice2("usb_fill_buf(): usb_%s_read() error: %s\n",
|
||||
use_interrupt_xfer? "interrupt": "bulk", usb_strerror());
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -439,22 +425,22 @@ static int usbdev_recv(const union filedescriptor *fd, unsigned char *buf, size_
|
||||
|
||||
if (verbose > 4)
|
||||
{
|
||||
avrdude_message(MSG_TRACE2, "%s: Recv: ", progname);
|
||||
pmsg_trace2("recv: ");
|
||||
|
||||
while (i) {
|
||||
unsigned char c = *p;
|
||||
if (isprint(c)) {
|
||||
avrdude_message(MSG_TRACE2, "%c ", c);
|
||||
msg_trace2("%c ", c);
|
||||
}
|
||||
else {
|
||||
avrdude_message(MSG_TRACE2, ". ");
|
||||
msg_trace2(". ");
|
||||
}
|
||||
avrdude_message(MSG_TRACE2, "[%02x] ", c);
|
||||
msg_trace2("[%02x] ", c);
|
||||
|
||||
p++;
|
||||
i--;
|
||||
}
|
||||
avrdude_message(MSG_TRACE2, "\n");
|
||||
msg_trace2("\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -493,7 +479,7 @@ static int usbdev_recv_frame(const union filedescriptor *fd, unsigned char *buf,
|
||||
}
|
||||
else if (rv > 0)
|
||||
{
|
||||
avrdude_message(MSG_INFO, "Short event len = %d, ignored.\n", rv);
|
||||
pmsg_warning("short event len = %d, ignored\n", rv);
|
||||
/* fallthrough */
|
||||
}
|
||||
}
|
||||
@@ -509,9 +495,8 @@ static int usbdev_recv_frame(const union filedescriptor *fd, unsigned char *buf,
|
||||
fd->usb.max_xfer, 10000);
|
||||
if (rv < 0)
|
||||
{
|
||||
avrdude_message(MSG_NOTICE2, "%s: usbdev_recv_frame(): usb_%s_read(): %s\n",
|
||||
progname, (fd->usb.use_interrupt_xfer? "interrupt": "bulk"),
|
||||
usb_strerror());
|
||||
pmsg_notice2("usbdev_recv_frame(): usb_%s_read(): %s\n",
|
||||
fd->usb.use_interrupt_xfer? "interrupt": "bulk", usb_strerror());
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -549,22 +534,22 @@ static int usbdev_recv_frame(const union filedescriptor *fd, unsigned char *buf,
|
||||
if (verbose > 3)
|
||||
{
|
||||
i = n & USB_RECV_LENGTH_MASK;
|
||||
avrdude_message(MSG_TRACE, "%s: Recv: ", progname);
|
||||
pmsg_trace("recv: ");
|
||||
|
||||
while (i) {
|
||||
unsigned char c = *p;
|
||||
if (isprint(c)) {
|
||||
avrdude_message(MSG_TRACE, "%c ", c);
|
||||
msg_trace("%c ", c);
|
||||
}
|
||||
else {
|
||||
avrdude_message(MSG_TRACE, ". ");
|
||||
msg_trace(". ");
|
||||
}
|
||||
avrdude_message(MSG_TRACE, "[%02x] ", c);
|
||||
msg_trace("[%02x] ", c);
|
||||
|
||||
p++;
|
||||
i--;
|
||||
}
|
||||
avrdude_message(MSG_TRACE, "\n");
|
||||
msg_trace("\n");
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
Reference in New Issue
Block a user