projector_check_dmm.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Software License Agreement (BSD License)
00004 #
00005 # Copyright (c) 2010, 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 Willow Garage, Inc. 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 
00036 ##\author Kevin Watts
00037 ##\brief Checks if DMM is available for projector test
00038 
00039 PKG = 'qualification'
00040 
00041 import roslib
00042 roslib.load_manifest(PKG)
00043 
00044 from pr2_self_test_msgs.srv import ScriptDone, ScriptDoneRequest
00045 
00046 import rospy
00047 import traceback
00048 import socket
00049 import subprocess
00050 
00051 
00052 class ProjectorChecker:
00053     def __init__(self):
00054         self._dmm_address = rospy.get_param("~dmm_address")
00055 
00056     @property
00057     def dmm_address(self): return self._dmm_address
00058 
00059     def check_projector(self):
00060         retcode = subprocess.call('ping -c1 -W1 %s > /dev/null' % self._dmm_address, shell=True)
00061         if retcode != 0:
00062             return False
00063 
00064         try :
00065             sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
00066             lxi_port = 5025
00067             sock.settimeout(15)
00068             sock.connect((self._dmm_address, 5025))
00069             sock.close()
00070             return True
00071         except socket.error:
00072             return False
00073         except Exception, e:
00074             rospy.logerr('Caught unknown exception checking projector:\n%s' % traceback.format_exc())
00075             return False
00076         return True
00077         
00078 
00079 def main():
00080     r = ScriptDoneRequest()
00081     r.result = ScriptDoneRequest.RESULT_ERROR
00082     r.failure_msg = 'Unable to contact projector'
00083 
00084     try:
00085         rospy.init_node('projector_monitor')
00086         done_srv = rospy.ServiceProxy('prestartup_done', ScriptDone)
00087 
00088         monitor = ProjectorChecker()
00089         if not monitor.check_projector():
00090             r.failure_msg = 'Unable to contact projector at %s' % monitor.dmm_address
00091             done_srv.call(r)
00092             rospy.spin()
00093         else:
00094             r.result = ScriptDoneRequest.RESULT_OK
00095             r.failure_msg = 'Projector OK'
00096             done_srv.call(r)
00097         
00098     except Exception, e:
00099         import traceback
00100         r.failure_msg = 'Error contacting projector. Exception:\n%s' % traceback.format_exc()
00101         done_srv.call(r)
00102         
00103     rospy.spin()
00104 
00105 if __name__ == '__main__':
00106     main()


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