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
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 = 'ping'
00044
00045 import os
00046 import sys
00047 from StringIO import StringIO
00048 import subprocess
00049 from optparse import OptionParser
00050
00051
00052 if __name__ == "__main__":
00053 rospy.init_node(NAME)
00054
00055 check_eula = True
00056
00057 parser = OptionParser(usage="usage: ping.py [--eula] <ip-addr>")
00058 parser.add_option("--eula", action="store_true", dest="eula")
00059
00060 (options,args) = parser.parse_args()
00061
00062 ip = args[0]
00063
00064 r = TestResultRequest()
00065 r.plots = []
00066
00067 success = False
00068
00069 for i in xrange(60):
00070 ret = subprocess.call(['ping','-c','1',ip],stdout=subprocess.PIPE, stderr=subprocess.PIPE)
00071 if ret == 0:
00072 success = True
00073 break
00074 else:
00075 if options.eula:
00076 subprocess.call(['wgeula'],stdout=subprocess.PIPE, stderr=subprocess.PIPE)
00077
00078 if success:
00079 r.html_result = "<p>Successfully pinged %s</p>"%ip
00080 r.result = TestResultRequest.RESULT_PASS
00081 r.text_summary = "Ping successful"
00082 else:
00083 r.html_result = "<p>Failed to ping %s</p>"%ip
00084 r.result = TestResultRequest.RESULT_FAIL
00085 r.text_summary = "Ping Failed"
00086
00087
00088 rospy.wait_for_service('test_result')
00089 result_service = rospy.ServiceProxy('test_result', TestResult)
00090 result_service.call(r)
00091
00092 rospy.spin()