[Nut-upsdev] [RFC apcsmart V3 12/18] drivers/apcsmart.c: adjust upsdrv_shutdown()

Michal Soltys soltys at ziu.info
Sat Mar 5 10:38:29 UTC 2011


Adjust upsdrv_shutdown() to use upsdrv_shutdown_advanced()
and upsdrv_shutdown_simple() functions.

Signed-off-by: Michal Soltys <soltys at ziu.info>
---
 drivers/apcsmart.c |   86 +++++++--------------------------------------------
 1 files changed, 12 insertions(+), 74 deletions(-)

diff --git a/drivers/apcsmart.c b/drivers/apcsmart.c
index 3ebbc50..e8ae00a 100644
--- a/drivers/apcsmart.c
+++ b/drivers/apcsmart.c
@@ -1062,97 +1062,35 @@ static void upsdrv_shutdown_advanced(int status)
 void upsdrv_shutdown(void)
 {
 	char	temp[32];
-	int	ret, tval, sdtype = 0;
+	int	ret, status;
 
 	if (!smartmode())
-		printf("Detection failed.  Trying a shutdown command anyway.\n");
+		upsdebugx(1, "SM detection failed. Trying a shutdown command anyway");
 
 	/* check the line status */
 
 	ret = ser_send_char(upsfd, APC_STATUS);
 
 	if (ret == 1) {
-		ret = ser_get_line(upsfd, temp, sizeof(temp), ENDCHAR, 
+		ret = ser_get_line(upsfd, temp, sizeof(temp), ENDCHAR,
 			IGNCHARS, SER_WAIT_SEC, SER_WAIT_USEC);
 
 		if (ret < 1) {
-			printf("Status read failed!  Assuming on battery state\n");
-			tval = APC_STAT_LB | APC_STAT_OB;
+			upsdebugx(1, "Status read failed ! Assuming on battery state");
+			status = APC_STAT_LB | APC_STAT_OB;
 		} else {
-			tval = strtol(temp, 0, 16);
+			status = strtol(temp, 0, 16);
 		}
 
 	} else {
-		printf("Status request failed; assuming on battery state\n");
-		tval = APC_STAT_LB | APC_STAT_OB;
+		upsdebugx(1, "Status request failed; assuming on battery state");
+		status = APC_STAT_LB | APC_STAT_OB;
 	}
 
-	if (testvar("sdtype"))
-		sdtype = atoi(getval("sdtype"));
-
-	switch (sdtype) {
-
-	case 4:		/* special hack for CS 350 and similar models */
-		printf("Using CS 350 'force OB' shutdown method\n");
-
-		if (tval & APC_STAT_OL) {
-			printf("On line - forcing OB temporarily\n");
-			ser_send_char(upsfd, 'U');
-		}
-
-		ser_send_char(upsfd, 'S');
-		break;
-
-	case 3:		/* shutdown with grace period */
-		printf("Sending delayed power off command to UPS\n");
-
-		ser_send_char(upsfd, APC_CMD_SHUTDOWN);
-		usleep(CMDLONGDELAY);
-		ser_send_char(upsfd, APC_CMD_SHUTDOWN);
-
-		break;
-
-	case 2:		/* instant shutdown */
-		printf("Sending power off command to UPS\n");
-
-		ser_send_char(upsfd, APC_CMD_OFF);
-		usleep(CMDLONGDELAY);
-		ser_send_char(upsfd, APC_CMD_OFF);
-
-		break;
-
-	case 1:
-
-		/* Send a combined set of shutdown commands which can work better */
-		/* if the UPS gets power during shutdown process */
-		/* Specifically it sends both the soft shutdown 'S' */
-		/* and the powerdown after grace period - '@000' commands */
-		printf("UPS - currently %s - sending shutdown/powerdown\n",
-			(tval & APC_STAT_OL) ? "on-line" : "on battery");
-
-		ser_flush_in(upsfd, IGNCHARS, nut_debug_level);
-		ser_send_pace(upsfd, UPSDELAY, "S at 000");
-		break;
-
-	default:
-
-		/* @000 - shutdown after 'p' grace period             */
-		/*      - returns after 000 minutes (i.e. right away) */
-
-		/* S    - shutdown after 'p' grace period, only on battery */
-		/*        returns after 'e' charge % plus 'r' seconds      */
-
-		ser_flush_in(upsfd, IGNCHARS, nut_debug_level);
-
-		if (tval & APC_STAT_OL) {		/* on line */
-			printf("On line, sending shutdown+return command...\n");
-			ser_send_pace(upsfd, UPSDELAY, "@000");
-		}
-		else {
-			printf("On battery, sending normal shutdown command...\n");
-			ser_send_char(upsfd, APC_CMD_SOFTDOWN);
-		}
-	}
+	if (testvar("advorder") && strcasecmp(getval("advorder"), "no"))
+		upsdrv_shutdown_advanced(status);
+	else
+		upsdrv_shutdown_simple(status);
 }
 
 /* 940-0095B support: set DTR, lower RTS */
-- 
1.7.2.1




More information about the Nut-upsdev mailing list