Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/agents/meinberg_syncbox_agent.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ using all of the available arguments::
['--port', 161],
['--mode', 'acq'],
['--snmp-version', 1],
['--outputs', [1, 2, 3]]]},
['--outputs', [1, 2, 3]],
['--sample-period', 10]]},

.. note::
The ``--address`` argument should be the address of the syncbox on the network.
This is not the main Meinberg M1000 device.
The ``--outputs`` argument can be any of the available 3 outputs.
The ``--sample-period`` argument is the number of seconds between sampling data.

Docker Compose
``````````````
Expand Down
58 changes: 56 additions & 2 deletions socs/agents/meinberg_syncbox/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,32 @@
# For logging
txaio.use_twisted()

CONVERT_OIDS = ['mbgSyncboxN2XPtpUTCOffset',
'mbgSyncboxN2XPtpOffsetToGrandmaster',
'mbgSyncboxN2XPtpMeanPathDelay']


def _convert_oid_value(field_name, oid_value):
unit_multipliers = {
"s": 1000000, # seconds to microseconds
"sec": 1000000, # seconds to microseconds
"ms": 1000, # milliseconds to microseconds
"us": 1, # microseconds
"ns": 0.001 # nanoseconds to microseconds
}

value, unit = oid_value.split()
value = float(value)

# Normalize to microseconds
if unit in unit_multipliers:
oid_value = value * unit_multipliers[unit]

# Change the field name to differentiate from raw output
field_name = field_name + "_value"

return field_name, oid_value


def _extract_oid_field_and_value(get_result):
"""Extract field names and OID values from SNMP GET results.
Expand Down Expand Up @@ -94,6 +120,11 @@ def _build_message(get_result, time):
message['data'][field_name] = oid_value
message['data'][field_name + "_description"] = oid_description

if (field_name.split('_')[0] in CONVERT_OIDS):
field_name, oid_value = _convert_oid_value(field_name, oid_value)
message['data'][field_name] = oid_value
message['data'][field_name + "_description"] = oid_description

return message


Expand Down Expand Up @@ -143,6 +174,11 @@ def update_cache(get_result, timestamp):
'connected': True}
oid_cache['timestamp'] = timestamp

if (field_name.split('_')[0] in CONVERT_OIDS):
field_name, oid_value = _convert_oid_value(field_name, oid_value)
oid_cache[field_name] = {"status": oid_value}
oid_cache[field_name]["description"] = oid_description

return oid_cache


Expand Down Expand Up @@ -173,7 +209,7 @@ class MeinbergSyncboxAgent:
txaio logger object, created by the OCSAgent
"""

def __init__(self, agent, address, port=161, version=1, outputs=[1, 2, 3]):
def __init__(self, agent, address, port=161, version=1, outputs=[1, 2, 3], sample_period=10):
self.agent = agent
self.is_streaming = False
self.log = self.agent.log
Expand All @@ -186,7 +222,7 @@ def __init__(self, agent, address, port=161, version=1, outputs=[1, 2, 3]):
self.connected = True

self.lastGet = 0
self.sample_period = 60
self.sample_period = sample_period

# Create the list of OIDs to send get commands
oids = ['mbgSyncboxN2XSerialNumber',
Expand Down Expand Up @@ -282,6 +318,9 @@ def acq(self, session, params=None):
'mbgSyncboxN2XPtpUTCOffset_0':
{'status': '37 sec',
'description': '37 sec'},
'mbgSyncboxN2XPtpUTCOffset_0_value':
{'status': 37000000,
'description': '37 sec'},
'mbgSyncboxN2XPtpLeapSecondAnnounced_0':
{'status': 'no',
'description': 'no'},
Expand All @@ -306,9 +345,15 @@ def acq(self, session, params=None):
'mbgSyncboxN2XPtpOffsetToGrandmaster_0':
{'status': '10 ns',
'description': '10 ns'},
'mbgSyncboxN2XPtpOffsetToGrandmaster_0_value':
{'status': 0.01,
'description': '10 ns'},
'mbgSyncboxN2XPtpMeanPathDelay_0':
{'status': '875 ns',
'description': '875 ns'},
'mbgSyncboxN2XPtpMeanPathDelay_0_value':
{'status': 0.875,
'description': '875 ns'},
'mbgSyncboxN2XOutputMode_1':
{'status': 4,
'description': 'pulsePerSecond'},
Expand Down Expand Up @@ -377,6 +422,13 @@ def acq(self, session, params=None):
accurateToWithin1s(47),
accurateToWithin10s(48),
accurateToGreaterThan10s(49)
mbgSyncboxN2XPtpUTCOffset_value::
Units:: microseconds
mbgSyncboxN2XPtpOffsetToGrandmaster_value::
Units:: microseconds
mbgSyncboxN2XPtpMeanPathDelay_value::
Units:: microseconds

"""

self.is_streaming = True
Expand Down Expand Up @@ -462,6 +514,8 @@ def add_agent_args(parser=None):
pgroup.add_argument("--mode", default='acq', choices=['acq', 'test'])
pgroup.add_argument("--outputs", nargs='+', default=[1, 2, 3], type=int,
help="Syncbox outputs to monitor. Defaults to [1,2,3].")
pgroup.add_argument("--sample-period", default=10, type=int,
help="Acq sample period in seconds. Defaults to 10.")

return parser

Expand Down