load_firmware.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Software License Agreement (BSD License)
00004 #
00005 # Copyright (c) 2008, Willow Garage, Inc.
00006 # All rights reserved.
00007 #
00008 # Redistribution and use in source and binary forms, with or without
00009 # modification, are permitted provided that the following conditions
00010 # are met:
00011 #
00012 #  * Redistributions of source code must retain the above copyright
00013 #    notice, this list of conditions and the following disclaimer.
00014 #  * Redistributions in binary form must reproduce the above
00015 #    copyright notice, this list of conditions and the following
00016 #    disclaimer in the documentation and/or other materials provided
00017 #    with the distribution.
00018 #  * Neither the name of the Willow Garage nor the names of its
00019 #    contributors may be used to endorse or promote products derived
00020 #    from this software without specific prior written permission.
00021 #
00022 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 # POSSIBILITY OF SUCH DAMAGE.
00034 
00035 import roslib
00036 roslib.load_manifest('qualification')
00037 
00038 import sys
00039 import rospy
00040 from std_srvs.srv import *
00041 from pr2_self_test_msgs.srv import *
00042 import std_msgs
00043 import rospy
00044 import subprocess
00045 import os
00046 import os.path
00047 import wx
00048 
00049 def check_programmed(iface):
00050     args = ['rosrun', 'wge100_camera', 'discover']
00051     if iface != None:
00052         args.append(iface)
00053     p = subprocess.Popen(args, stdout=subprocess.PIPE)
00054     impactout = p.communicate()[0]
00055     return 'Found camera' in impactout
00056 
00057 rospy.init_node("load_firmware", anonymous=True)
00058 
00059 r = TestResultRequest()
00060 r.plots = []
00061 
00062 try:
00063     iface=rospy.get_param("~cam_interface")
00064 except:
00065     iface=None
00066 
00067 try:
00068     impactdir=rospy.get_param("~impactdir")
00069 except:
00070     import traceback
00071     traceback.print_exc()
00072 #if (len(sys.argv) != 2):
00073     #print >> sys.stderr, 'must specify impact directory (%i) args given'%len(sys.argv);
00074     print >> sys.stderr, 'impactdir option must indicate impact project directory';
00075     r.html_result = "<p>Bad arguments to load_firmware.py.</p>"
00076     r.text_summary = "Error in test."
00077     r.result = TestResultRequest.RESULT_HUMAN_REQUIRED
00078     print "error"
00079 else:
00080     os.chdir(impactdir);
00081     reprogram = True
00082     if check_programmed(iface):
00083         app = wx.PySimpleApp()
00084         ret = wx.MessageBox("The device is already programmed. Skip reprogramming?", "Device Programmed", wx.YES|wx.NO)
00085         if ret == wx.YES:
00086             reprogram = False
00087     if reprogram:
00088         p = subprocess.Popen(['./startimpact', '-batch', 'load_firmware.cmd'], stderr=subprocess.PIPE)
00089         impactout = p.communicate()[1]
00090 
00091         impactout = impactout.replace('\n','<br>')
00092 
00093         if '''INFO:iMPACT - '1': Flash was programmed successfully.''' in impactout:
00094             r.text_summary = "Firmware download succeeded."
00095             r.html_result = "<p>Test passed.</p><p>"+impactout+"</p>" 
00096             r.result = TestResultRequest.RESULT_PASS
00097             print "pass"
00098         else:
00099             r.text_summary = "Firmware download failed."
00100             r.result = TestResultRequest.RESULT_FAIL
00101             r.html_result = "<p>Test Failed.</p><p>"+impactout+"</p>"
00102             print "fail"
00103             print impactout
00104     else: 
00105         r.html_result = "<p>Firmware was already programmed.</p>"
00106         r.text_summary = "Firmware already programmed (Pass)." 
00107         r.result = TestResultRequest.RESULT_PASS
00108         print "pass"
00109 
00110     
00111 result_service = rospy.ServiceProxy('test_result', TestResult)
00112 
00113 rospy.sleep(5);
00114 
00115 # block until the test_result service is available
00116 rospy.wait_for_service('test_result')
00117 result_service.call(r)
00118 


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