Touchbot: Fix a parsing problem in error.py

The error parsing module used "lstrip()" to extract the error codes from
the messages sent over the robot's serial connection.  The problem was
that if the error code included 1's or 2's they could be stripped to.

ie: if the error message was "ST1=11" and we wanted to get the "11"
using message.lstrip("ST1=") would return an empty string since the code
consisted of 1's which were in the set of characters to strip.

I replaced the lstrips with split()'s to divide it on the '=' so it
doesn't matter what numbers are in the error code

BUG=chromium-os:39369
TEST=Manually ran it, and forced an error with code "11" and it was
parsed correctly.  Other errors work fine as well.

Change-Id: I2fdb931273b547852eb98a2cec5aea7160e9db5c
Signed-off-by: Charlie Mooney <charliemooney@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/44299
diff --git a/roibot/error.py b/roibot/error.py
index cf4812d..e68ec2d 100644
--- a/roibot/error.py
+++ b/roibot/error.py
@@ -212,12 +212,12 @@
     # SNO=0 status
     element = []
     report0 = roibot.modeRequestStatus(0)
-    report0status1 = int(str(report0[1][1]).lstrip("ST1="),16)
+    report0status1 = roibot.parseStatusCode(report0[1][1])
     if report0status1 & 0x01:
         # SNO=1 error code and optional amplifier alarm code
         report1 = roibot.modeRequestStatus(1)
-        report1status1 = str(report1[1][1]).lstrip("ST1=")
-        report1status2 = str(report1[1][2]).lstrip("ST2=")
+        report1status1 = roibot.parseStatusCode(report1[1][1])
+        report1status2 = roibot.parseStatusCode(report1[1][2])
         element.append("error=" + translate(report1status1, report1status2))
     for bit, message in ((0x02, "in execution"),
                          (0x04, "paused"),
@@ -234,7 +234,7 @@
     # SNO=2 Robot mode
     element = []
     report2 = roibot.modeRequestStatus(2)
-    report2status1 = int(str(report2[1][1]).lstrip("ST1="),16)
+    report2status1 = roibot.parseStatusCode(report2[1][1])
     # bits 0 1
     for value, message in ((0x00, "Sequential mode"),
                            (0x01, "Palletizing mode"),
@@ -264,7 +264,7 @@
     # SNO=3 Servo, slave, and card status (if memory card option is installed)
     element = []
     report3 = roibot.modeRequestStatus(3)
-    report3status1 = int(str(report3[1][1]).lstrip("ST1="),16)
+    report3status1 = roibot.parseStatusCode(report3[1][1])
     # bits 0 1 2 3
     for bit, message in ((0x01, "Servo ON"),
                          (0x02, "Reserved SNO=3 bit 0x02"),
@@ -288,7 +288,7 @@
     # SNO=4 Input and output status
     element = []
     report4 = roibot.modeRequestStatus(4)
-    report4status1 = int(str(report4[1][1]).lstrip("ST1="),16)
+    report4status1 = roibot.parseStatusCode(report4[1][1])
     for bit, message in ((0x01, "Escape input ON"),
                          (0x02, "Continuous input ON"),
                          (0x04, "INPUT wait"),
diff --git a/roibot/motion.py b/roibot/motion.py
index dccbaaa..1ecdbf2 100644
--- a/roibot/motion.py
+++ b/roibot/motion.py
@@ -90,7 +90,7 @@
        operations which clear the execution bit on completion, such as
        returning all axes to their origin position."""
     report0 = roibot.modeRequestStatus(0)
-    report0status1 = int(str(report0[1][1]).lstrip("ST1="),16)
+    report0status1 = roibot.parseStatusCode(report0[1][1])
     # still in execution?
     if report0status1 & 0x02:
         return False;
diff --git a/roibot/roibot.py b/roibot/roibot.py
index 894fac3..e6cc0fd 100644
--- a/roibot/roibot.py
+++ b/roibot/roibot.py
@@ -210,6 +210,12 @@
         """
         return self.sendCommand("STAS", "SNO=" + str(statusNumber))
 
+    def parseStatusCode(self, response):
+        """ Parse out the status code from a raw response.  Takes a string of
+            the form 'STR1=13' and returns the status code
+        """
+        return int(str(response).split("=")[1], 16)
+
     def modeHostON(self):
         """Enter host mode.  This mode is required to use most commands."""
         result = self.TFResult(self.sendCommand("HSON"))