Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 import concert_msgs.msg as concert_msgs
00010 import gateway_msgs.msg as gateway_msgs
00011
00012
00013
00014
00015
00016
00017 class ConcertClient(object):
00018
00019
00020
00021
00022
00023
00024
00025
00026 def __init__(self, msg):
00027 self.msg = msg
00028 self.is_new = True
00029 self.is_checked = True
00030 self.link_type = self._set_link_string()
00031
00032 def _set_link_string(self):
00033 '''
00034 Returns the link type in string format from those in
00035 gateway_msgs.ConnectionStatus constants or 'unknown'.
00036
00037 :returns: link type string
00038 :rtype: str
00039 '''
00040 if self.msg.is_local_client:
00041 return 'local'
00042 elif self.msg.conn_stats.network_type == gateway_msgs.ConnectionStatistics.WIRED:
00043 return 'wired'
00044 elif self.msg.conn_stats.network_type == gateway_msgs.ConnectionStatistics.WIRELESS:
00045 return 'wireless'
00046 else:
00047 return 'unknown'
00048
00049 def get_rapp_context(self):
00050 '''
00051 Generate a html string used to display the rapp context of this client.
00052 '''
00053
00054 context = "<html>"
00055 context += "<p>-------------------------------------------</p>"
00056 context += "<p><b>concert_alias: </b>" + self.msg.name + "</p>"
00057 context += "<p><b>gateway_name: </b>" + self.msg.gateway_name + "</p>"
00058 context += "<p><b>rocon_uri: </b>" + self.msg.platform_info.uri + "</p>"
00059 context += "<p><b>state: </b>" + self.msg.state + "</p>"
00060 for rapp in self.msg.rapps:
00061 context += "<p>-------------------------------------------</p>"
00062 context += "<p><b>app_name: </b>" + rapp.name + "</p>"
00063 context += "<p><b>app_display_name: </b>" + rapp.display_name + "</p>"
00064 context += "<p><b>app_description: </b>" + rapp.description + "</p>"
00065 context += "<p><b>app_compatibility: </b>" + rapp.compatibility + "</p>"
00066 context += "<p><b>app_status: </b>" + rapp.status + "</p>"
00067 context += "</html>"
00068 return context
00069
00070 def get_connection_strength(self):
00071 if self.msg.is_local_client == True:
00072 return 'very_strong'
00073 elif self.msg.state == concert_msgs.ConcertClientState.MISSING:
00074 return 'missing'
00075 else:
00076 link_quality_percent = (float(self.msg.conn_stats.wireless_link_quality) / 70) * 100
00077 if 80 < link_quality_percent and 100 >= link_quality_percent:
00078 return 'very_strong'
00079 elif 60 < link_quality_percent and 80 >= link_quality_percent:
00080 return 'strong'
00081 elif 40 < link_quality_percent and 60 >= link_quality_percent:
00082 return 'normal'
00083 elif 20 < link_quality_percent and 40 >= link_quality_percent:
00084 return 'weak'
00085 elif 0 <= link_quality_percent and 20 >= link_quality_percent:
00086 return 'very_weak'
00087 else:
00088 return None
00089
00090 def update(self, msg):
00091 '''
00092 Update with new information that gets periodically published by the concert
00093 conductor. This currently includes the platform info (which can highlight
00094 the rapp that is running), the connection statistics and the state.
00095 '''
00096
00097 old_msg = self.msg
00098 self.msg = msg
00099 if (
00100 old_msg.is_local_client != msg.is_local_client or
00101 old_msg.conn_stats.network_type != msg.conn_stats.network_type
00102 ):
00103 self.link_type = self._set_link_string()
00104
00105
00106
00107
00108
00109 @property
00110 def concert_alias(self):
00111 return self.msg.name
00112
00113 @concert_alias.setter
00114 def concert_alias(self, value):
00115 self.msg.name = value
00116
00117 @property
00118 def state(self):
00119 return self.msg.state
00120
00121 @property
00122 def ip(self):
00123 return self.msg.ip.replace('.', '_')
00124
00125 @property
00126 def gateway_name(self):
00127 return self.msg.gateway_name
00128
00129 @gateway_name.setter
00130 def gateway_name(self, value):
00131 self.msg.gateway_name = value