diff --git a/docs/nut-names.txt b/docs/nut-names.txt index 92613e73bb..12f0f526c8 100644 --- a/docs/nut-names.txt +++ b/docs/nut-names.txt @@ -711,6 +711,8 @@ driver: Internal driver information the stable working loop | init.starting, init.quiet, init.device, init.info, init.updateinfo (first walk), + reconnect.trying, + reconnect.updateinfo, updateinfo, quiet, dumping, cleanup.upsdrv, cleanup.exit |=============================================================================== diff --git a/drivers/adelsystem_cbi.c b/drivers/adelsystem_cbi.c index fb7b93abff..e86a16a5c9 100644 --- a/drivers/adelsystem_cbi.c +++ b/drivers/adelsystem_cbi.c @@ -1281,6 +1281,7 @@ void modbus_reconnect(void) int rval; upsdebugx(1, "modbus_reconnect, trying to reconnect to modbus server"); + dstate_setinfo("driver.state", "reconnect.trying"); /* clear current modbus context */ modbus_close(mbctx); @@ -1340,5 +1341,7 @@ void modbus_reconnect(void) } /* #elif (defined NUT_MODBUS_TIMEOUT_ARG_timeval) // some un-castable type in fields */ #endif /* NUT_MODBUS_TIMEOUT_ARG_* */ + + dstate_setinfo("driver.state", "quiet"); } diff --git a/drivers/bcmxcp_usb.c b/drivers/bcmxcp_usb.c index 50ac843e7a..b5aeabb52f 100644 --- a/drivers/bcmxcp_usb.c +++ b/drivers/bcmxcp_usb.c @@ -385,13 +385,18 @@ void upsdrv_cleanup(void) void upsdrv_reconnect(void) { + dstate_setinfo("driver.state", "reconnect.trying"); + upsdebugx(4, "=================================================="); upsdebugx(4, "= device has been disconnected, try to reconnect ="); upsdebugx(4, "=================================================="); nutusb_close(upsdev, "USB"); upsdev = NULL; + upsdrv_initups(); + + dstate_setinfo("driver.state", "quiet"); } /* USB functions */ diff --git a/drivers/blazer_usb.c b/drivers/blazer_usb.c index aa14330f7c..74d0710b84 100644 --- a/drivers/blazer_usb.c +++ b/drivers/blazer_usb.c @@ -445,11 +445,15 @@ ssize_t blazer_command(const char *cmd, char *buf, size_t buflen) ssize_t ret; if (udev == NULL) { + dstate_setinfo("driver.state", "reconnect.trying"); + ret = usb->open_dev(&udev, &usbdevice, reopen_matcher, NULL); if (ret < 1) { return ret; } + + dstate_setinfo("driver.state", "reconnect.updateinfo"); } ret = (*subdriver_command)(cmd, buf, buflen); @@ -496,6 +500,7 @@ ssize_t blazer_command(const char *cmd, char *buf, size_t buflen) case LIBUSB_ERROR_NOT_FOUND: /* No such file or directory */ fallthrough_case_reconnect: /* Uh oh, got to reconnect! */ + dstate_setinfo("driver.state", "reconnect.trying"); usb->close_dev(udev); udev = NULL; break; diff --git a/drivers/generic_modbus.c b/drivers/generic_modbus.c index 20eda551e9..ab53f0673f 100644 --- a/drivers/generic_modbus.c +++ b/drivers/generic_modbus.c @@ -1038,6 +1038,7 @@ void modbus_reconnect(void) int rval; upsdebugx(2, "modbus_reconnect, trying to reconnect to modbus server"); + dstate_setinfo("driver.state", "reconnect.trying"); /* clear current modbus context */ modbus_close(mbctx); @@ -1097,4 +1098,6 @@ void modbus_reconnect(void) } /* #elif (defined NUT_MODBUS_TIMEOUT_ARG_timeval) // some un-castable type in fields */ #endif /* NUT_MODBUS_TIMEOUT_ARG_* */ + + dstate_setinfo("driver.state", "quiet"); } diff --git a/drivers/main.c b/drivers/main.c index 5ffcaa9977..828787e5db 100644 --- a/drivers/main.c +++ b/drivers/main.c @@ -1037,6 +1037,8 @@ int main(int argc, char **argv) /* get the base data established before allowing connections */ dstate_setinfo("driver.state", "init.info"); upsdrv_initinfo(); + /* Note: a few drivers also call their upsdrv_updateinfo() during + * their upsdrv_initinfo(), possibly to impact the initialization */ dstate_setinfo("driver.state", "init.updateinfo"); upsdrv_updateinfo(); dstate_setinfo("driver.state", "init.quiet"); diff --git a/drivers/nutdrv_qx.c b/drivers/nutdrv_qx.c index bd378b647d..61400b4cce 100644 --- a/drivers/nutdrv_qx.c +++ b/drivers/nutdrv_qx.c @@ -3163,11 +3163,15 @@ static ssize_t qx_command(const char *cmd, char *buf, size_t buflen) # endif /* QX_SERIAL (&& QX_USB)*/ if (udev == NULL) { + dstate_setinfo("driver.state", "reconnect.trying"); + ret = usb->open_dev(&udev, &usbdevice, reopen_matcher, NULL); if (ret < 1) { return ret; } + + dstate_setinfo("driver.state", "reconnect.updateinfo"); } ret = (*subdriver_command)(cmd, buf, buflen); @@ -3229,6 +3233,7 @@ static ssize_t qx_command(const char *cmd, char *buf, size_t buflen) case LIBUSB_ERROR_NOT_FOUND: /* No such file or directory */ fallthrough_case_reconnect: /* Uh oh, got to reconnect! */ + dstate_setinfo("driver.state", "reconnect.trying"); usb->close_dev(udev); udev = NULL; break; diff --git a/drivers/powerman-pdu.c b/drivers/powerman-pdu.c index df4e91f3e5..d1e55bfcdd 100644 --- a/drivers/powerman-pdu.c +++ b/drivers/powerman-pdu.c @@ -191,6 +191,8 @@ static int reconnect_ups(void) { pm_err_t rv; + dstate_setinfo("driver.state", "reconnect.trying"); + upsdebugx(4, "==================================================="); upsdebugx(4, "= connection lost with Powerman, try to reconnect ="); upsdebugx(4, "==================================================="); @@ -202,6 +204,7 @@ static int reconnect_ups(void) if ((rv = pm_connect(device_path, NULL, &pm, 0)) != PM_ESUCCESS) return 0; else { + dstate_setinfo("driver.state", "quiet"); upsdebugx(4, "connection restored with Powerman"); return 1; } diff --git a/drivers/riello_usb.c b/drivers/riello_usb.c index 8430850f9a..36c451e208 100644 --- a/drivers/riello_usb.c +++ b/drivers/riello_usb.c @@ -348,13 +348,17 @@ static int riello_command(uint8_t *cmd, uint8_t *buf, uint16_t length, uint16_t int ret; if (udev == NULL) { + dstate_setinfo("driver.state", "reconnect.trying"); + ret = usb->open_dev(&udev, &usbdevice, reopen_matcher, &driver_callback); upsdebugx (3, "riello_command err udev NULL : %d ", ret); if (ret < 0) return ret; + dstate_setinfo("driver.state", "reconnect.updateinfo"); upsdrv_initinfo(); /* reconnect usb cable */ + dstate_setinfo("driver.state", "quiet"); } ret = (*subdriver_command)(cmd, buf, length, buflen); @@ -404,6 +408,7 @@ static int riello_command(uint8_t *cmd, uint8_t *buf, uint16_t length, uint16_t case LIBUSB_ERROR_NOT_FOUND: /* No such file or directory */ fallthrough_case_reconnect: /* Uh oh, got to reconnect! */ + dstate_setinfo("driver.state", "reconnect.trying"); usb->close_dev(udev); udev = NULL; break; diff --git a/drivers/tripplite_usb.c b/drivers/tripplite_usb.c index 62a8bcab9a..ceec5574f0 100644 --- a/drivers/tripplite_usb.c +++ b/drivers/tripplite_usb.c @@ -325,6 +325,8 @@ static int reconnect_ups(void) return 1; } + dstate_setinfo("driver.state", "reconnect.trying"); + upsdebugx(2, "=================================================="); upsdebugx(2, "= device has been disconnected, try to reconnect ="); upsdebugx(2, "=================================================="); @@ -337,6 +339,7 @@ static int reconnect_ups(void) } hd = &curDevice; + dstate_setinfo("driver.state", "quiet"); return ret; } @@ -563,7 +566,9 @@ static void usb_comm_fail(int res, const char *msg) if(hd) { upslogx(LOG_NOTICE, "Successfully reconnected"); try = 0; + dstate_setinfo("driver.state", "reconnect.updateinfo"); upsdrv_initinfo(); + dstate_setinfo("driver.state", "quiet"); } else { if(try > MAX_RECONNECT_TRIES) { fatalx(EXIT_FAILURE, "Too many unsuccessful reconnection attempts"); diff --git a/drivers/usbhid-ups.c b/drivers/usbhid-ups.c index d250b548b5..6ad7d048a1 100644 --- a/drivers/usbhid-ups.c +++ b/drivers/usbhid-ups.c @@ -888,6 +888,7 @@ void upsdrv_updateinfo(void) case LIBUSB_ERROR_NO_MEM: /* Insufficient memory */ fallthrough_reconnect: /* Uh oh, got to reconnect! */ + dstate_setinfo("driver.state", "reconnect.trying"); hd = NULL; return; case LIBUSB_ERROR_IO: /* I/O error */ @@ -1595,6 +1596,8 @@ static int reconnect_ups(void) char *val; int wait_before_reconnect = 0; + dstate_setinfo("driver.state", "reconnect.trying"); + /* Init time to wait before trying to reconnect (seconds) */ val = getval(HU_VAR_WAITBEFORERECONNECT); if (val) { @@ -1627,6 +1630,7 @@ static int reconnect_ups(void) return 1; } + dstate_setinfo("driver.state", "quiet"); return 0; }