I use a wrapp scrip around pmc. - use pmc as is, for example
""" - example pmc outputs $ pmc -u -b 0 'GET CURRENT_DATA_SET' sending: GET CURRENT_DATA_SET 2c553c.fffe.0008b0-0 seq 0 RESPONSE MANAGMENT CURRENT_DATA_SET stepsRemoved 1 offsetFromMaster 11111 meanPathDelay 11197.0 $ pmc -u -b 0 'GET TIME_STATUS_NP' sending: GET TIME_STATUS_NP 2c553c.fffe.0008b0-0 seq 0 RESPONSE MANAGMENT TIME_STATUS_NP master_offset 111 ingress_time 92954226412560 cumulativeScaledRateOffset +0.000000000 scaledLastGmPhaseChange 0 gmTimeBaseIndicator 0 lastGmPhaseChange 0x0000'0000000000000000.0000 gmPresent true gmIdentity 99553c.fffe.0003c0 $ pmc -u -b 0 'GET PORT_DATA_SET' sending: GET PORT_DATA_SET 2c553c.fffe.0003c0-1 seq 0 RESPONSE MANAGMENT PORT_DATA_SET portIdentity 99553c.fffe.0003c0-1 portState MASTER logMinDelayReqInterval 0 peerMeanPathDelay 0 logAnnounceInterval 0 announceReceiptTimeout 3 logSyncInterval 1 delayMechanism 1 logMinPdelayReqInterval 0 versionNumber 2 """ - or use this script output example which can be fed to other program easily ./show-ptp SLAVE SYNC -106 994a00.fffe.040144 16878.0 -------- - cat show-ptp #! /usr/bin/env python import errno, os import os.path import time import sys import random import subprocess import time import logging """ - example pmc outputs $ pmc -u -b 0 'GET CURRENT_DATA_SET' sending: GET CURRENT_DATA_SET 2c553c.fffe.0008b0-0 seq 0 RESPONSE MANAGMENT CURRENT_DATA_SET stepsRemoved 1 offsetFromMaster 811103.0 meanPathDelay 11197.0 $ pmc -u -b 0 'GET TIME_STATUS_NP' sending: GET TIME_STATUS_NP 2c553c.fffe.0008b0-0 seq 0 RESPONSE MANAGMENT TIME_STATUS_NP master_offset 811036 ingress_time 92954226412560 cumulativeScaledRateOffset +0.000000000 scaledLastGmPhaseChange 0 gmTimeBaseIndicator 0 lastGmPhaseChange 0x0000'0000000000000000.0000 gmPresent true gmIdentity 2c553c.fffe.0003c0 $ pmc -u -b 0 'GET PORT_DATA_SET' sending: GET PORT_DATA_SET 2c553c.fffe.0003c0-1 seq 0 RESPONSE MANAGMENT PORT_DATA_SET portIdentity 2c553c.fffe.0003c0-1 portState MASTER logMinDelayReqInterval 0 peerMeanPathDelay 0 logAnnounceInterval 0 announceReceiptTimeout 3 logSyncInterval 1 delayMechanism 1 logMinPdelayReqInterval 0 versionNumber 2 """ # doesn't have to be dict, in case we need a "keyword" based retrieval in the future, so use dict instead of list ptp_oper_dict = { # [cmd, anchor keywords,...] 1: ["pmc -u -b 0 'GET PORT_DATA_SET'", 'portState'], 2: ["pmc -u -b 0 'GET TIME_STATUS_NP'", 'gmPresent', 'master_offset', 'gmIdentity'], 3: ["pmc -u -b 0 'GET CURRENT_DATA_SET'", 'meanPathDelay'] } fake_result = [ [ 'MASTER', 'MASTER', '0', '2c553c.fffe.000550', '0.0', ], [ 'SLAVE', 'UNCALIBRATED', '0', '2c553c.fffe.000550', '0.0', ] ] unknown_result = [ 'UNKNOWN', 'UNKNOWN', '0', '0', '0.0', ] # run subprocess and returns out, err, errcode def run_shell2(dir, ctx, args): cwd = os.getcwd() os.chdir(dir) process = subprocess.Popen(args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = process.communicate() errcode = process.returncode logging.debug('OK: [%s] %s' % (os.getcwd(), args)) os.chdir(cwd) return out, err, errcode def get_after_keword(s, keyword): b,k,a = s.partition(keyword) if k is '': return -1, None t = a.split('\n') t1 = t[0].split() return 0, ' '.join(t1) def check_pmc_exist(): if os.path.isfile('/usr/bin/pmc'): return 0 return 1 # # output format: '\n' separated # > getting> role/status, gmpresent, offset, gm id, pathdelay # > returning> role, status, offset, gm id, pathdelay # def show_ptp_oper(debug): result = [] r = check_pmc_exist() if r != 0: # return fake data print '\n'.join(random.choice(fake_result)) return -1 len_dic = len(ptp_oper_dict) for key in range(1,len_dic+1): cmd = ptp_oper_dict[key][0] search_word = ptp_oper_dict[key][1:] logging.debug('running %s' % cmd) out, err, errcode = run_shell2('.', None, cmd) out = out.strip() if errcode != 0: print '\n'.join(unknown_result) return -1 for item in search_word: r, word = get_after_keword(out, item) if r == -1: print '\n'.join(unknown_result) return -1 result.append(word) tmp = result[0] tmp1 = result[1] if result[1] == "false" and result[0] == "MASTER": result[0] = "MASTER" else: result[0] = "SLAVE" result[1] = tmp if tmp1 == "true": if tmp == "SLAVE": # state slave and gm present is true result[1] = "SYNC" elif tmp == "LISTENING": # listening and gm present is true result[1] = "HOLDOVER" print '\n'.join(result) return 0 if __name__ == '__main__': logging.basicConfig(level=logging.INFO) debug = 0 if len(sys.argv) > 1: debug = 1 r = show_ptp_oper(debug) sys.exit(r) ________________________________________ From: Robb <rbarr...@gmail.com> Sent: Monday, June 29, 2015 1:12 PM To: linuxptp-users@lists.sourceforge.net Subject: [Linuxptp-users] Is there a way to query ptp4l or phc2sys status? I have synced the clocks between two machines quite well and was curious if there is an easy way to query my slave machine from the command line and determine if the clocks are in sync. It is obvious to look at the logs and tell that they are currently in sync, but I was hoping to not have to write a tool to scrape the logs, also I really would prefer not to log the information anyway. Does something like this exist? Thanks. ------------------------------------------------------------------------------ Don't Limit Your Business. Reach for the Cloud. GigeNET's Cloud Solutions provide you with the tools and support that you need to offload your IT needs and focus on growing your business. Configured For All Businesses. Start Your Cloud Today. https://www.gigenetcloud.com/ _______________________________________________ Linuxptp-users mailing list Linuxptp-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-users ------------------------------------------------------------------------------ Don't Limit Your Business. Reach for the Cloud. GigeNET's Cloud Solutions provide you with the tools and support that you need to offload your IT needs and focus on growing your business. Configured For All Businesses. Start Your Cloud Today. https://www.gigenetcloud.com/ _______________________________________________ Linuxptp-users mailing list Linuxptp-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-users