WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

Commit c31ec198 authored by Jack Henderson's avatar Jack Henderson
Browse files

move to diagnostic msgs

parent 152302bc
......@@ -9,8 +9,6 @@ project(ptp_monitor)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
rospy
std_msgs
message_generation
)
## System dependencies are found with CMake's conventions
......@@ -47,10 +45,9 @@ find_package(catkin REQUIRED COMPONENTS
## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)
## Generate messages in the 'msg' folder
add_message_files(
FILES
PtpStatus.msg
)
#add_message_files(
# FILES
# )
## Generate services in the 'srv' folder
# add_service_files(
......@@ -67,10 +64,10 @@ add_message_files(
# )
## Generate added messages and services with any dependencies listed here
generate_messages(
DEPENDENCIES
std_msgs
)
#generate_messages(
# DEPENDENCIES
# std_msgs
#)
################################################
## Declare ROS dynamic reconfigure parameters ##
......@@ -104,7 +101,7 @@ generate_messages(
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES ros_ptp_monitor
CATKIN_DEPENDS rospy std_msgs message_runtime
CATKIN_DEPENDS rospy
# DEPENDS system_lib
)
......
std_msgs/Header header
string local_time
string port_state
string master_IP
string offset_from_master
string path_delay
string clock_correction
#!/usr/bin/env python
#!/usr/bin/env python3
import os
import rospy
from ptp_monitor.msg import PtpStatus
import diagnostic_updater
import diagnostic_msgs
class PtpMonitor:
def __init__(self):
rospy.init_node('ptp_monitor')
self.pub = rospy.Publisher('ptp_status', PtpStatus, queue_size=5)
self.rate = rospy.Rate(1)
self.diagnostics = diagnostic_updater.Updater()
task = diagnostic_updater.CompositeDiagnosticTask("PTP")
task.addTask(diagnostic_updater.FunctionDiagnosticTask("PTP Stats", self.update_stats))
task.addTask(diagnostic_updater.FunctionDiagnosticTask("Clock sync check", self.check_sync_bounds))
task.addTask(diagnostic_updater.FunctionDiagnosticTask("Clock correction check", self.check_correction_bounds))
self.diagnostics.add(task)
self.rate = rospy.Rate(0.5)
self.file = "/var/run/ptpd2.status"
def run(self):
self.port_state = ''
self.offset = 0
self.clock_correction = 0
def check_sync_bounds(self, stat):
if abs(self.offset) > 0.01:
stat.summary(diagnostic_msgs.msg.DiagnosticStatus.ERROR, "Time is not synced")
elif abs(self.offset) > 0.005:
stat.summary(diagnostic_msgs.msg.DiagnosticStatus.WARN, "Time sync is inaccurate")
else:
stat.summary(diagnostic_msgs.msg.DiagnosticStatus.OK, "Time sync is within tolerance")
return stat
def check_correction_bounds(self, stat):
if abs(self.clock_correction) > 400:
stat.summary(diagnostic_msgs.msg.DiagnosticStatus.WARN, "Clock correction is high")
else:
stat.summary(diagnostic_msgs.msg.DiagnosticStatus.OK, "Clock correction is within tolerance")
return stat
def get_ptp_data(self):
with open(self.file, 'r') as f:
lines = f.readlines()
data = dict(map(line_to_map, lines))
return data
def update_stats(self, stat):
if os.path.exists(self.file):
with open(self.file, 'r') as f:
lines = f.readlines()
data = dict(map(line_to_map, lines))
msg = PtpStatus()
msg.header.stamp = rospy.Time.now()
msg.local_time = data['Local time']
msg.port_state = data['Port state']
msg.master_IP = data.get('Best master IP', '')
msg.offset_from_master = data.get('Offset from Master', '')
msg.clock_correction = data.get('Clock correction', '')
msg.path_delay = data.get('Mean Path Delay', '')
self.pub.publish(msg)
data = self.get_ptp_data()
stat.add('Local Time', data['Local time'])
stat.add('Port State', data['Port state'])
stat.add('Master IP', data.get('Best master IP', ''))
stat.add('Offset from Master', data.get('Offset from Master', ''))
stat.add('Clock Correction', data.get('Clock correction', ''))
stat.add('Path Delay', data.get('Mean Path Delay', ''))
if data['Port state'] == 'PTP_SLAVE':
self.port_state = data['Port state']
self.offset = float(data.get('Offset from Master', '0').split(' ')[0])
self.clock_correction = float(data.get('Clock correction', '0').split(' ')[0])
else:
stat.summary(diagnostic_msgs.msg.DiagnosticStatus.ERROR, "PTPD is not connected to master")
else:
rospy.loginfo("PTPD is not running")
stat.summary(diagnostic_msgs.msg.DiagnosticStatus.ERROR, "PTPD is not running")
return stat
def run(self):
self.diagnostics.update()
self.rate.sleep()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment