00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
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
00073
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
00116 rospy.wait_for_service('test_result')
00117 result_service.call(r)
00118