def send_function_test(self, point_def_path='', func_def_path='', func_test_path='', func_test_json=None): """ Send a function test after validating the function test (as JSON). :param point_def_path: path to point definition config :param func_def_path: path to function definition config :param func_test_path: path to function test json :param func_test_json: function test json """ ftest = FunctionTest(func_test_path, func_test_json, point_def_path=point_def_path, func_def_path=func_def_path) ftest.is_valid() pdefs = PointDefinitions(point_definitions_path=point_def_path or POINT_DEF_PATH) func_def = ftest.get_function_def() for func_step_def in func_def.steps: try: point_value = ftest.points[func_step_def.name] except KeyError: continue pdef = pdefs.point_named(func_step_def.name) # No need to test for valid point name, as that was done above if not pdef: raise MesaMasterException("Point definition not found: {}".format(func_step_def.name)) if type(point_value) == list: self.send_array(point_value, pdef) else: try: send_func = self.SEND_FUNCTIONS[func_step_def.fcodes[0] if func_step_def.fcodes else DIRECT_OPERATE] except (KeyError, IndexError): raise MesaMasterException("Unrecognized sent command function") self.send_command(send_func, pdef, point_value)
def do_function(self, line): """Send a function test after validating the function test (as JSON).""" point_defs = PointDefinitions( point_definitions_path=POINT_DEFINITIONS_PATH) ftest = FunctionTest(FUNCTION_DEFINITIONS_PATH, CURVE_JSON) ftest.is_valid() for func_step_def in ftest.get_function_def().steps: try: point_value = ftest.points[func_step_def.name] except KeyError: continue pdef = point_defs.point_named(func_step_def.name) if not pdef: raise ValueError("Point definition not found: {}".format( pdef.name)) if type(point_value) == list: self.application.send_array(point_value, pdef) else: try: send_func = self.application.SEND_FUNCTIONS[ func_step_def.fcodes[0] if func_step_def. fcodes else DIRECT_OPERATE] except (KeyError, IndexError): raise ValueError("Unrecognized sent command function") self.application.send_command(send_func, pdef, point_value)
def test_point_definition_load(): point_defs = PointDefinitions( point_definitions_path=POINT_DEFINITIONS_PATH) import pprint pprint.pprint(point_defs._points) pprint.pprint(point_defs._point_name_dict) print("_point_variations_dict") pprint.pprint(point_defs._point_variation_dict)
def __init__(self, map_file): self.c_ao = 0 self.c_do = 0 self.c_ai = 0 self.c_di = 0 self.measurements = dict() self.out_json = list() self.file_dict = map_file self.processor_point_def = PointDefinitions() self.outstation = DNP3Outstation('', 0, '')
def load_point_definitions(self): """ Load and cache a dictionary of PointDefinitions from a json list. Index the dictionary by point_type and point index. """ _log.debug('Loading DNP3 point definitions.') try: self.point_definitions = PointDefinitions() self.point_definitions.load_points(self.points) except (AttributeError, TypeError) as err: if self._local_point_definitions_path: _log.warning( "Attempting to load point definitions from local path.") self.point_definitions = PointDefinitions( point_definitions_path=self._local_point_definitions_path) else: raise DNP3Exception( "Failed to load point definitions from config store: {}". format(err))
def test_function_definitions(): point_definitions = PointDefinitions( point_definitions_path=POINT_DEFINITIONS_PATH) fdefs = FunctionDefinitions( point_definitions, function_definitions_path=FUNCTION_DEFINITIONS_PATH) fd = fdefs.function_for_id("curve") print(fd) pdef = point_definitions.get_point_named("DCHD.WinTms (out)") print(pdef) print(fdefs.step_definition_for_point(pdef))
def load_and_validate_definitions(): """ Standalone method, intended to be invoked from the command line. Load PointDefinition and FunctionDefinition files as specified in command line args, and validate their contents. """ # Grab JSON and YAML definition file paths from the command line. parser = argparse.ArgumentParser() parser.add_argument('point_defs', help='path of the point definitions file (json)') parser.add_argument('function_defs', help='path of the function definitions file (yaml)') args = parser.parse_args() point_definitions = PointDefinitions(point_definitions_path=args.point_defs) function_definitions = FunctionDefinitions(point_definitions, function_definitions_path=args.function_defs) validate_definitions(point_definitions, function_definitions)
def __init__(self, func_test_path='', func_test_json=None, func_def_path='', point_def_path=''): self.func_def_path = func_def_path or FUNCTION_DEF_PATH self.point_definitions = PointDefinitions( point_definitions_path=point_def_path or POINT_DEF_PATH) self.ftest = func_test_json or json.load(open(func_test_path)) self.function_id = self.ftest.get('function_id', self.ftest.get('id', None)) self.function_name = self.ftest.get('function_name', self.ftest.get('name', None)) self.name = self.ftest.get('name', None) self.points = { k: v for k, v in self.ftest.items() if k not in ["name", "function_id", "function_name", "id"] }
def test_load_points_from_json_file(self): try: PointDefinitions(point_definitions_path=POINT_DEFINITIONS_PATH) assert True except ValueError: assert False
import copy from dnp3.points import PointDefinitions from dnp3.mesa.functions import FunctionDefinitions, FunctionDefinition, StepDefinition from test_mesa_agent import POINT_DEFINITIONS_PATH, FUNCTION_DEFINITIONS_PATH POINT_DEFINITIONS = PointDefinitions( point_definitions_path=POINT_DEFINITIONS_PATH) enable_high_voltage_ride_through_mode = { 'id': 'enable_high_voltage_ride_through_mode', 'name': 'Enable High Volatge Ride-Through Mode', 'ref': 'AN2018 Spec section 2.5.1 Table 33', 'steps': [{ 'step_number': 1, 'description': 'Set the Reference Voltage if it is not already set', 'point_name': 'DECP.VRef.AO0', 'optional': 'I', 'fcode': ['direct_operate'], 'response': 'DECP.VRef.AI29' }, { 'step_number': 2, 'description': 'Set the Reference Voltage Offset if it is not already set', 'point_name': 'DECP.VRefOfs.AO1', 'optional': 'I', 'fcode': ['direct_operate'],