firmware_wrt.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # Software License Agreement (BSD License)
00003 #
00004 # Copyright (c) 2008, Willow Garage, Inc.
00005 # All rights reserved.
00006 #
00007 # Redistribution and use in source and binary forms, with or without
00008 # modification, are permitted provided that the following conditions
00009 # are met:
00010 #
00011 #  * Redistributions of source code must retain the above copyright
00012 #    notice, this list of conditions and the following disclaimer.
00013 #  * Redistributions in binary form must reproduce the above
00014 #    copyright notice, this list of conditions and the following
00015 #    disclaimer in the documentation and/or other materials provided
00016 #    with the distribution.
00017 #  * Neither the name of the Willow Garage nor the names of its
00018 #    contributors may be used to endorse or promote products derived
00019 #    from this software without specific prior written permission.
00020 #
00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 # POSSIBILITY OF SUCH DAMAGE.
00033 
00034 ##\author Jeremy Leibs
00035 
00036 import roslib
00037 roslib.load_manifest('qualification')
00038 
00039 from pr2_self_test_msgs.srv import TestResult, TestResultRequest
00040 
00041 import rospy 
00042 
00043 NAME = 'config_ctr'
00044 
00045 import os
00046 import sys
00047 from StringIO import StringIO
00048 import subprocess
00049 
00050 import wx
00051 from wx import xrc
00052 from wx import html
00053 
00054 from threading import Thread
00055 
00056 import time
00057 
00058 ##\brief Uses instructions panel to show how to power cycle wifi
00059 class PowerCycleFrame(wx.Frame):
00060     def __init__(self, html_file, status_cb):
00061         wx.Frame.__init__(self, None, wx.ID_ANY, 'Power Cycle WRT 610n')
00062 
00063         self._status_cb = status_cb
00064 
00065         xrc_path = os.path.join(roslib.packages.get_pkg_dir('qualification'), 'xrc/gui.xrc')
00066         xrc_res = xrc.XmlResource(xrc_path)
00067         self._panel = xrc_res.LoadPanel(self, 'instructions_panel')
00068         self._sizer = wx.BoxSizer(wx.VERTICAL)
00069         self._sizer.Add(self._panel)
00070         self.Layout()
00071 
00072         self._html_window = xrc.XRCCTRL(self._panel, 'html_window')
00073         self._html_window.LoadFile(html_file)
00074 
00075         self._cancel_button = xrc.XRCCTRL(self._panel, 'cancel_button')
00076         self._cancel_button.Bind(wx.EVT_BUTTON, self.on_cancel)
00077 
00078         self._continue_button = xrc.XRCCTRL(self._panel, 'continue_button')
00079         self._continue_button.Bind(wx.EVT_BUTTON, self.on_continue)
00080         self._continue_button.SetFocus()
00081 
00082         self._done = False
00083         self._ok = True
00084 
00085     def on_continue(self, event):
00086         self._status_cb(True)
00087         self.Close()
00088 
00089     def on_cancel(self, event):
00090         self._status_cb(False)
00091         self.Close()
00092 
00093 class DlgThread(Thread):
00094     def __init__(self, html_file):
00095         Thread.__init__(self)
00096         self.app = wx.PySimpleApp()
00097         self._frame = PowerCycleFrame(html_file, self._status_cb)
00098         self._frame.SetSize(wx.Size(550, 750))
00099         self._frame.Layout()
00100         self._frame.Show(True)
00101 
00102         self._ok = False
00103         self._done = False
00104 
00105     def _status_cb(self, ok):
00106         self._ok = ok
00107         self._done = True
00108 
00109     def is_done(self):
00110         return self._done
00111 
00112     def is_ok(self):
00113         return self._done and self._ok
00114 
00115     def run(self):
00116         self.app.MainLoop()
00117 
00118 if __name__ == "__main__":
00119     rospy.init_node(NAME)
00120 
00121     r = TestResultRequest()
00122     r.plots = []
00123     r.result = TestResultRequest.RESULT_PASS
00124 
00125     if len(rospy.myargv()) > 0 and os.path.exists(rospy.myargv()[1]):
00126         instructions_file = rospy.myargv()[1]
00127     else:
00128         print "Unable to start configuration, no instructions file loaded"
00129         rospy.wait_for_service('test_result')
00130         r.result = TestResultRequest.RESULT_FAIL
00131         r.text_summary = "Unable to load instructions file, no given"
00132         result_service = rospy.ServiceProxy('test_result', TestResult)
00133         result_service.call(r)
00134 
00135 
00136 
00137     ip = '192.168.1.1'
00138 
00139     r.html_result =  "<p>Checking firmware version...</p>\n"
00140 
00141     # Sometimes takes a little while to boot
00142     time.sleep(30)
00143 
00144     wrt610n_version_cmd = ['wrt610n','version','-i',ip]
00145     wrt610n_version = subprocess.Popen(wrt610n_version_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
00146     (o,e) = wrt610n_version.communicate()
00147     if wrt610n_version.returncode != 0:
00148         r.html_result = "<p>Invocation of %s failed with: %s</p>\n<p>Trying 10.68.0.5...</p>\n"%(wrt610n_version_cmd,e)
00149         ip = '10.68.0.5'
00150         wrt610n_version_cmd = ['wrt610n','version','-i',ip]
00151         wrt610n_version = subprocess.Popen(wrt610n_version_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
00152         (o,e) = wrt610n_version.communicate()
00153 
00154     if wrt610n_version.returncode != 0:
00155         r.html_result = r.html_result + "<p>Invocation of %s failed with: %s</p>\n"%(wrt610n_version_cmd,e)
00156         r.text_summary = "Utility failed"
00157         r.result = TestResultRequest.RESULT_FAIL
00158 
00159     elif 'Router has firmware version: DD-WRT v24-sp2 (09/30/09) big - build 13000M NEWD-2 Eko' in o:
00160         r.html_result =  r.html_result + "<pre>%s</pre>"%o
00161     else:
00162         r.html_result =  r.html_result + "<p>Upgrading firmware...</p>\n"
00163         wrt610n_firmware_cmd = ['wrt610n','--force','-i',ip,'firmware','/usr/lib/wrt610n/dd-wrt.v24-13000_big-wrt610n.bin']
00164         wrt610n_firmware = subprocess.Popen(wrt610n_firmware_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
00165         (o,e) = wrt610n_firmware.communicate()
00166 
00167         if wrt610n_firmware.returncode != 0:
00168             r.html_result = r.html_result + "<p>Invocation of %s failed with: %s</p>\n"%(wrt610n_firmware_cmd,e)
00169             r.text_summary = "Utility failed"
00170             r.result = TestResultRequest.RESULT_FAIL
00171 
00172         # We don't wait for boot anymore
00173         #elif "Router has resumed successfully on: 192.168.1.1 with firmare: 'DD-WRT v24-sp2 (09/30/09) big - build 13000M NEWD-2 Eko'" not in o:
00174         #    r.html_result =  r.html_result + "<pre>%s</pre>"%o
00175         #    r.text_summary = "Resume failed"
00176         #    r.result = TestResultRequest.RESULT_FAIL
00177 
00178     if r.result != TestResultRequest.RESULT_FAIL:
00179         ip = "192.168.1.1"
00180 
00181         r.html_result =  r.html_result + "<p>Requesting Hard Reset</p>\n"
00182 
00183         print 'Starting reset dialog'
00184         dlgthread = DlgThread(instructions_file)
00185         dlgthread.start()
00186         dlgthread.join()
00187         print 'Done with reset dialog'
00188 
00189         # Need to check return code of thread
00190         if not dlgthread.is_ok():
00191             r.result = TestResultRequest.RESULT_FAIL
00192             r.text_summary = 'Failed to restart WRT610n using reset button.'
00193             
00194     if r.result != TestResultRequest.RESULT_FAIL:
00195         wrt610n_version_cmd = ['wrt610n','-w','version','-i',ip]
00196         wrt610n_version = subprocess.Popen(wrt610n_version_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
00197         (o,e) = wrt610n_version.communicate()
00198         if wrt610n_version.returncode != 0:
00199             r.html_result =  r.html_result + "<p>Invocation of %s failed with: %s</p>\n"%(wrt610n_version_cmd,e)
00200             r.result = TestResultRequest.RESULT_FAIL
00201             r.text_summary = "Utility failed"
00202         elif "Router has resumed successfully on: 192.168.1.1 with firmare: 'DD-WRT v24-sp2 (09/30/09) big - build 13000M NEWD-2 Eko'" not in o:
00203             r.html_result =  r.html_result + "<pre>%s</pre>"%o
00204             r.text_summary = "Hard Reset Resume failed"
00205             r.result = TestResultRequest.RESULT_FAIL
00206         else:
00207             r.html_result = r.html_result +  "<pre>%s</pre>"%o
00208             r.result = TestResultRequest.RESULT_PASS
00209             r.text_summary = "Firmware Upgraded"
00210 
00211 
00212     # block until the test_result service is available
00213     rospy.wait_for_service('test_result')
00214     result_service = rospy.ServiceProxy('test_result', TestResult)
00215     result_service.call(r)
00216 
00217     rospy.spin()


qualification
Author(s): Kevin Watts (watts@willowgarage.com), Josh Faust (jfaust@willowgarage.com)
autogenerated on Sat Dec 28 2013 17:57:34