38 from __future__
import with_statement
40 PKG =
'pr2_computer_monitor' 42 roslib.load_manifest(PKG)
49 from diagnostic_msgs.msg
import DiagnosticArray, DiagnosticStatus, KeyValue
50 from pr2_msgs.msg
import AccessPoint
52 DIAG_NAME =
'Wifi Status (ddwrt)' 58 stat = DiagnosticStatus()
61 stat.level = DiagnosticStatus.OK
64 stat.values.append(KeyValue(key=
'ESSID', value=msg.essid))
65 stat.values.append(KeyValue(key=
'Mac Address', value=msg.macaddr))
66 stat.values.append(KeyValue(key=
'Signal', value=str(msg.signal)))
67 stat.values.append(KeyValue(key=
'Noise', value=str(msg.noise)))
68 stat.values.append(KeyValue(key=
'Sig/Noise', value=str(msg.snr)))
69 stat.values.append(KeyValue(key=
'Channel', value=str(msg.channel)))
70 stat.values.append(KeyValue(key=
'Rate', value=msg.rate))
71 stat.values.append(KeyValue(key=
'TX Power', value=msg.tx_power))
72 stat.values.append(KeyValue(key=
'Quality', value=str(msg.quality)))
78 diag_stat = DiagnosticStatus()
79 diag_stat.message =
'No Updates' 80 diag_stat.name = DIAG_NAME
82 diag_stat.message =
'Updates Stale' 84 diag_stat.level = DiagnosticStatus.WARN
86 diag_stat.level = DiagnosticStatus.ERROR
98 self.
_diag_pub = rospy.Publisher(
'/diagnostics', DiagnosticArray, queue_size=10)
100 self.
_ddwrt_sub = rospy.Subscriber(
'ddwrt/accesspoint', AccessPoint, self.
_cb)
113 if update_diff > WARN_TIME:
118 ddwrt_stat.values.append(KeyValue(key=
'Time Since Update', value=str(update_diff)))
120 error_state = (rospy.get_time() - self.
_start_time) > ERROR_TIME
122 ddwrt_stat.values.append(KeyValue(key=
'Time Since Update', value=
"N/A"))
124 msg = DiagnosticArray()
125 msg.header.stamp = rospy.get_rostime()
126 msg.status.append(ddwrt_stat)
128 self._diag_pub.publish(msg)
131 if __name__ ==
'__main__':
133 rospy.init_node(
'ddwrt_diag')
134 except rospy.exceptions.ROSInitException:
135 print(
'Wifi monitor is unable to initialize node. Master may not be running.')
139 rate = rospy.Rate(1.0)
142 while not rospy.is_shutdown():
144 wifi_monitor.publish_stats()
145 except KeyboardInterrupt:
147 except Exception
as e:
149 traceback.print_exc()
def mark_diag_stale(diag_stat=None, error=False)