Logo Search packages:      
Sourcecode: nut version File versions  Download package

void usb_comm_fail ( int  res,
const char *  msg 
)

Report a USB comm failure, and reconnect if necessary.

Parameters:
[in] res Result code from libusb/libhid call
[in] msg Error message to display

Definition at line 601 of file tripplite_usb.c.

References reconnect_ups().

Referenced by debug_message().

{
      static int try = 0;

      switch(res) {
            case -EBUSY:
                  upslogx(LOG_WARNING, "%s: Device claimed by another process", msg);
                  fatalx(EXIT_FAILURE, "Terminating: EBUSY");
                  break;

            default:
                  upslogx(LOG_WARNING, "%s: Device detached? (error %d: %s)", msg, res, usb_strerror());

                  upslogx(LOG_NOTICE, "Reconnect attempt #%d", ++try);
                  hd = NULL;
                  reconnect_ups();

                  if(hd) {
                        upslogx(LOG_NOTICE, "Successfully reconnected");
                        try = 0;
                        upsdrv_initinfo();
                  } else {
                        if(try > MAX_RECONNECT_TRIES) {
                              fatalx(EXIT_FAILURE, "Too many unsuccessful reconnection attempts");
                        }
                  }
                  break;
      }
}


Generated by  Doxygen 1.6.0   Back to index