From d75ced686f89147eaa9a1f829810749a61314dfc Mon Sep 17 00:00:00 2001
From: Mike Hibler <mike@flux.utah.edu>
Date: Mon, 4 Apr 2005 18:42:23 +0000
Subject: [PATCH] Hack to get around apparent overrun of UART causing malformed
 commands to the controller.

---
 tbsetup/power_rpc27.pm.in | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/tbsetup/power_rpc27.pm.in b/tbsetup/power_rpc27.pm.in
index da371d7d99..9770242095 100644
--- a/tbsetup/power_rpc27.pm.in
+++ b/tbsetup/power_rpc27.pm.in
@@ -17,6 +17,7 @@ use Socket;
 use IO::Handle;
 use lib "@prefix@/lib";
 use libdb;
+use POSIX qw(strftime);
 
 # A little perl module to power cycle something attached to an RPC27.
 # Thats a serially controlled, power controller.
@@ -53,6 +54,13 @@ sub rpc27ctrl {
     my($cmd, $controller, @outlets) = @_;
     my($TIP, $i, $insync);
 
+    #
+    # Check parameters
+    #
+    if (!defined($RPC27_CMD{$cmd})) {
+	print STDERR "*** Undefined command: '$cmd'\n";
+	return 1;
+    }
     if (grep {$_ < 1 || $_ > 20} @outlets) {
 	print STDERR "*** Invalid outlet '$outlet': Must be 1-20\n";
 	return 1;
@@ -157,6 +165,17 @@ sub syncandsend($$) {
 	return 1;
     }
 
+    #
+    # These things have an annoying tendency to fail sometimes by losing
+    # the command part of the string (e.g., "6" instead of "reboot 6").
+    # I think we are overrunning the UART with "\r\n" since we put out
+    # a pair after every line we read that is not a prompt and when the
+    # RPC puts out its banner, it is a good 10 lines before we see the
+    # prompt.  So allow some time for the RPC to digest everything before
+    # we feed it the command.
+    #
+    sleep(1);
+
     if ($debug) {
 	print "Sending '$cmd' to $controller\n";
     }
-- 
GitLab