Пример #1
0
    def _apply_point_update(point_def, point_index, value):
        """
            Set an input point in the outstation database. This may send its PointValue to the Master.

        :param point_def: A PointDefinition.
        :param point_index: A numeric index for the point.
        :param value: A value to send (unwrapped, simple data type).
        """
        data_type = point_def.data_type
        if data_type == DATA_TYPE_ANALOG_INPUT:
            wrapped_val = opendnp3.Analog(float(value))
            if isinstance(value,
                          bool) or not isinstance(value, numbers.Number):
                # Invalid data type
                raise DNP3Exception('Received {} value for {}.'.format(
                    type(value), point_def))
        elif data_type == DATA_TYPE_BINARY_INPUT:
            wrapped_val = opendnp3.Binary(value)
            if not isinstance(value, bool):
                # Invalid data type
                raise DNP3Exception('Received {} value for {}.'.format(
                    type(value), point_def))
        else:
            # The agent supports only DNP3's Analog and Binary point types at this time.
            raise DNP3Exception('Unsupported point type {}'.format(data_type))
        if wrapped_val is not None:
            DNP3Outstation.apply_update(wrapped_val, point_index)
        _log.debug('Sent DNP3 point {}, value={}'.format(
            point_def, wrapped_val.value))
Пример #2
0
 def do_b(self, line):
     """Send the Master a BinaryInput (group 2) value. Command syntax is: 'b index true' or 'b index false'"""
     index, value_string = self.index_and_value_from_line(line)
     if index and value_string:
         if value_string.lower() == 'true' or value_string.lower() == 'false':
             self.application.apply_update(opendnp3.Binary(value_string == 'true'), index)
         else:
             print('Please enter true or false as the second argument.')
Пример #3
0
    def on_message(self, simulation_id, message):
        """ This method handles incoming messages on the fncs_output_topic for the simulation_id.
        Parameters
        ----------
        headers: dict
            A dictionary of headers that could be used to determine topic of origin and
            other attributes.
        message: object

        """

        try:
            message_str = 'received message ' + str(message)

            json_msg = yaml.safe_load(str(message))

            if type(json_msg) != dict:
                raise ValueError(' is not a json formatted string.' +
                                 '\njson_msg = {0}'.format(json_msg))

            # fncs_input_message = {"{}".format(simulation_id): {}}
            measurement_values = json_msg["message"]["measurements"]

            # storing the magnitude and measurement_mRID values to publish in the dnp3 points for measurement key values
            for y in measurement_values:
                #print(y.keys())
                # print(self.processor_point_def.points_by_mrid())
                m = measurement_values[y]
                if "magnitude" in m.keys():
                    for point in self.outstation.get_agent(
                    ).point_definitions.all_points():
                        #print("point",point)
                        #print("y",y)
                        if m.get(
                                "measurement_mrid"
                        ) == point.measurement_id and point.magnitude != m.get(
                                "magnitude"):
                            point.magnitude = m.get("magnitude")
                            self.outstation.apply_update(
                                opendnp3.Analog(point.magnitude), point.index)
                elif "value" in m.keys():
                    for point in self.outstation.get_agent(
                    ).point_definitions.all_points():
                        if m.get(
                                "measurement_mrid"
                        ) == point.measurement_id and point.value != m.get(
                                "value"):
                            point.value = m.get("value")
                            self.outstation.apply_update(
                                opendnp3.Binary(point.value), point.index)
        except Exception as e:
            message_str = "An error occurred while trying to translate the  message received" + str(
                e)
Пример #4
0
 def test_Indexed(self):
     assert type(opendnp3.WithIndex(opendnp3.Binary(), 0)) == opendnp3.IndexedBinary
     assert type(opendnp3.WithIndex(opendnp3.DoubleBitBinary(), 0)) == opendnp3.IndexedDoubleBitBinary
     assert type(opendnp3.WithIndex(opendnp3.Analog(), 0)) == opendnp3.IndexedAnalog
     assert type(opendnp3.WithIndex(opendnp3.Counter(), 0)) == opendnp3.IndexedCounter
     assert type(opendnp3.WithIndex(opendnp3.FrozenCounter(), 0)) == opendnp3.IndexedFrozenCounter
     assert type(opendnp3.WithIndex(opendnp3.BinaryOutputStatus(), 0)) == opendnp3.IndexedBinaryOutputStatus
     assert type(opendnp3.WithIndex(opendnp3.AnalogOutputStatus(), 0)) == opendnp3.IndexedAnalogOutputStatus
     assert type(opendnp3.WithIndex(opendnp3.OctetString(), 0)) == opendnp3.IndexedOctetString
     assert type(opendnp3.WithIndex(opendnp3.TimeAndInterval(), 0)) == opendnp3.IndexedTimeAndInterval
     assert type(opendnp3.WithIndex(opendnp3.BinaryCommandEvent(), 0)) == opendnp3.IndexedBinaryCommandEvent
     assert type(opendnp3.WithIndex(opendnp3.AnalogCommandEvent(), 0)) == opendnp3.IndexedAnalogCommandEvent
     assert type(opendnp3.WithIndex(opendnp3.SecurityStat(), 0)) == opendnp3.IndexedSecurityStat
     assert type(opendnp3.WithIndex(opendnp3.ControlRelayOutputBlock(), 0)) == opendnp3.IndexedControlRelayOutputBlock
     assert type(opendnp3.WithIndex(opendnp3.AnalogOutputInt16(), 0)) == opendnp3.IndexedAnalogOutputInt16
     assert type(opendnp3.WithIndex(opendnp3.AnalogOutputInt32(), 0)) == opendnp3.IndexedAnalogOutputInt32
     assert type(opendnp3.WithIndex(opendnp3.AnalogOutputFloat32(), 0)) == opendnp3.IndexedAnalogOutputFloat32
     assert type(opendnp3.WithIndex(opendnp3.AnalogOutputDouble64(), 0)) == opendnp3.IndexedAnalogOutputDouble64
Пример #5
0
    def _set_point(self, point_name, value):
        """
            (Internal) Set the value of a given input point (no debug trace).

        @param point_name: The VOLTTRON point name of a DNP3 PointDefinition.
        @param value: The value to set. The value's data type must match the one in the DNP3 PointDefinition.
        """
        point_properties = self.volttron_points.get(point_name, {})
        group = point_properties.get('group', None)
        index = point_properties.get('index', None)
        point_type = PointDefinition.point_type_for_group(group)
        try:
            if point_type == POINT_TYPE_ANALOG_INPUT:
                wrapped_value = opendnp3.Analog(value)
            elif point_type == POINT_TYPE_BINARY_INPUT:
                wrapped_value = opendnp3.Binary(value)
            else:
                raise Exception('Unexpected data type for DNP3 point named {0}'.format(point_name))
            DNP3Outstation.apply_update(wrapped_value, index)
        except Exception as e:
            raise DNP3Exception(e.message)
Пример #6
0
 def test_default_constructors(self):
     """
         Create the class object with default values for instance variable and test if the object is not empty.
     """
     assert asiodnp3.ConsoleLogger() is not None
     assert asiodnp3.DefaultListenCallbacks() is not None
     assert asiodnp3.DefaultMasterApplication() is not None
     assert asiodnp3.MasterStackConfig() is not None
     assert asiodnp3.PrintingChannelListener is not None
     assert asiodnp3.PrintingSOEHandler() is not None
     assert asiodnp3.UpdateBuilder() is not None
     assert asiopal.ChannelRetry() is not None
     assert asiopal.ResourceManager() is not None
     assert asiopal.SerialSettings() is not None
     assert asiopal.steady_clock_t() is not None
     assert opendnp3.AnalogCommandEvent() is not None
     assert opendnp3.AnalogOutputInt16() is not None
     assert opendnp3.AnalogOutputInt32() is not None
     assert opendnp3.AnalogOutputFloat32() is not None
     assert opendnp3.AnalogOutputDouble64() is not None
     assert opendnp3.BinaryCommandEvent() is not None
     assert opendnp3.ClassField() is not None
     assert opendnp3.ControlRelayOutputBlock() is not None
     assert opendnp3.DNPTime() is not None
     assert opendnp3.Flags() is not None
     assert opendnp3.GroupVariationID() is not None
     assert opendnp3.IndexedBinary() is not None
     assert opendnp3.IndexedDoubleBitBinary() is not None
     assert opendnp3.IndexedAnalog() is not None
     assert opendnp3.IndexedCounter() is not None
     assert opendnp3.IndexedFrozenCounter() is not None
     assert opendnp3.IndexedBinaryOutputStatus() is not None
     assert opendnp3.IndexedAnalogOutputStatus() is not None
     assert opendnp3.IndexedOctetString() is not None
     assert opendnp3.IndexedTimeAndInterval() is not None
     assert opendnp3.IndexedBinaryCommandEvent() is not None
     assert opendnp3.IndexedAnalogCommandEvent() is not None
     assert opendnp3.IndexedSecurityStat() is not None
     assert opendnp3.IndexedControlRelayOutputBlock() is not None
     assert opendnp3.IndexedAnalogOutputInt16() is not None
     assert opendnp3.IndexedAnalogOutputInt32() is not None
     assert opendnp3.IndexedAnalogOutputFloat32() is not None
     assert opendnp3.IndexedAnalogOutputDouble64() is not None
     assert opendnp3.Binary() is not None
     assert opendnp3.DoubleBitBinary() is not None
     assert opendnp3.BinaryOutputStatus() is not None
     assert opendnp3.Analog() is not None
     assert opendnp3.Counter() is not None
     assert opendnp3.FrozenCounter() is not None
     assert opendnp3.AnalogOutputStatus() is not None
     assert opendnp3.TimeAndInterval() is not None
     assert opendnp3.OctetData() is not None
     assert opendnp3.OctetString() is not None
     assert opendnp3.SecurityStat() is not None
     assert opendnp3.LinkHeaderFields() is not None
     assert opendnp3.LinkStatistics() is not None
     assert opendnp3.CommandSet() is not None
     assert opendnp3.HeaderInfo() is not None
     assert opendnp3.StartStopRangeUint8() is not None
     assert opendnp3.StartStopRangeUint16() is not None
     assert opendnp3.CountUint8() is not None
     assert opendnp3.CountUint16() is not None
     assert opendnp3.HeaderUnion() is not None
     assert opendnp3.Header() is not None
     assert opendnp3.MasterParams() is not None
     assert opendnp3.RestartOperationResult() is not None
     assert opendnp3.TaskConfig() is not None
     assert opendnp3.ApplicationIIN() is not None
     assert opendnp3.DatabaseSizes() is not None
     assert opendnp3.EventBufferConfig() is not None
     assert opendnp3.OutstationConfig() is not None
     assert opendnp3.OutstationParams() is not None
     assert opendnp3.StaticTypeBitField() is not None
     assert opendnp3.StackStatistics() is not None
     assert opendnp3.IINField() is not None
     assert openpal.ArrayBinaryConfig() is not None
     assert openpal.ArrayDoubleBitBinaryConfig() is not None
     assert openpal.ArrayAnalogConfig() is not None
     assert openpal.ArrayCounterConfig() is not None
     assert openpal.ArrayFrozenCounterConfig() is not None
     assert openpal.ArrayBOStatusConfig() is not None
     assert openpal.ArrayAOStatusConfig() is not None
     assert openpal.ArrayTimeAndIntervalConfig() is not None
     assert openpal.ArrayBuffer() is not None
     assert openpal.ArrayViewBinaryConfig() is not None
     assert openpal.ArrayViewDoubleBitBinaryConfig() is not None
     assert openpal.ArrayViewAnalogConfig() is not None
     assert openpal.ArrayViewCounterConfig() is not None
     assert openpal.ArrayViewFrozenCounterConfig() is not None
     assert openpal.ArrayViewBOStatusConfig() is not None
     assert openpal.ArrayViewAOStatusConfig() is not None
     assert openpal.ArrayViewTimeAndIntervalConfig() is not None
     assert openpal.ArrayViewBuffer() is not None
     assert openpal.Buffer() is not None
     assert openpal.RingBuffer16() is not None
     assert openpal.RSlice() is not None
     assert openpal.SecureBuffer() is not None
     assert openpal.SettableRSlice() is not None
     assert openpal.SettableWSlice() is not None
     assert openpal.StaticBuffer4() is not None
     assert openpal.StaticBuffer14() is not None
     assert openpal.StaticBuffer100() is not None
     assert openpal.StaticBuffer292() is not None
     assert openpal.WSlice() is not None
     assert openpal.MonotonicTimestamp() is not None
     assert openpal.TimeDurationBase() is not None
     assert openpal.TimeDuration() is not None
     assert openpal.UTCTimestamp() is not None
     assert openpal.LogFilters() is not None
     assert openpal.Logger() is not None
     assert openpal.SerializerBinary() is not None
     assert openpal.SerializerDoubleBitBinary() is not None
     assert openpal.SerializerBinaryOutputStatus() is not None
     assert openpal.SerializerAnalog() is not None
     assert openpal.SerializerCounter() is not None
     assert openpal.SerializerFrozenCounter() is not None
     assert openpal.SerializerAnalogOutputStatus() is not None
     assert openpal.SerializerTimeAndInterval() is not None
     assert openpal.SerializerAnalogOutputInt16() is not None
     assert openpal.SerializerAnalogOutputInt32() is not None
     assert openpal.SerializerAnalogOutputFloat32() is not None
     assert openpal.SerializerAnalogOutputDouble64() is not None
Пример #7
0
 def test_passing_args(self):
     """
         Create the class object with defined arguments and test if the object is not empty.
     """
     assert asiodnp3.ConsoleLogger(True) is not None
     assert asiodnp3.DatabaseConfig(opendnp3.DatabaseSizes()) is not None
     assert asiodnp3.DNP3Manager(1) is not None
     assert asiodnp3.DNP3Manager(
         1,
         asiodnp3.ConsoleLogger().Create()) is not None
     assert asiodnp3.OutstationStackConfig(
         opendnp3.DatabaseSizes()) is not None
     assert asiodnp3.X509Info(1, openpal.RSlice(), "test") is not None
     assert asiopal.ChannelRetry(openpal.TimeDuration(),
                                 openpal.TimeDuration()) is not None
     assert asiopal.ChannelRetry(openpal.TimeDuration(),
                                 openpal.TimeDuration(),
                                 asiopal.IOpenDelayStrategy()) is not None
     assert asiopal.Executor(asiopal.IO()) is not None
     assert asiopal.IPEndpoint("127.0.0.1", 502) is not None
     assert asiopal.LoggingConnectionCondition(openpal.Logger()) is not None
     assert asiopal.SerialChannel(asiopal.Executor(
         asiopal.IO())) is not None
     assert asiopal.TCPClient(openpal.Logger(),
                              asiopal.Executor(asiopal.IO()),
                              asiopal.IPEndpoint("127.0.0.1", 502),
                              "adapter") is not None
     assert asiopal.ThreadPool(openpal.Logger(), asiopal.IO(),
                               1) is not None
     assert asiopal.TLSConfig("~/files/peerCert", "~/files/localCert",
                              "~/files/privateKey") is not None
     assert opendnp3.AnalogOutputInt16(
         1, opendnp3.CommandStatus.TIMEOUT) is not None
     assert opendnp3.AnalogOutputInt32(
         1, opendnp3.CommandStatus.FORMAT_ERROR) is not None
     assert opendnp3.AnalogOutputFloat32(
         1, opendnp3.CommandStatus.ALREADY_ACTIVE) is not None
     assert opendnp3.AnalogOutputDouble64(
         1, opendnp3.CommandStatus.LOCAL) is not None
     assert opendnp3.BinaryCommandEvent(opendnp3.Flags()) is not None
     assert opendnp3.BinaryCommandEvent(opendnp3.Flags(),
                                        opendnp3.DNPTime()) is not None
     assert opendnp3.BinaryCommandEvent(
         True, opendnp3.CommandStatus.TOO_MANY_OPS) is not None
     assert opendnp3.BinaryCommandEvent(
         False, opendnp3.CommandStatus.NOT_AUTHORIZED,
         opendnp3.DNPTime()) is not None
     assert opendnp3.ClassField(opendnp3.PointClass.Class0) is not None
     assert opendnp3.ClassField(1) is not None
     assert opendnp3.ClassField(True, False, True, False) is not None
     assert opendnp3.ControlRelayOutputBlock(
         opendnp3.ControlCode.LATCH_ON, 1, 100, 100,
         opendnp3.CommandStatus.AUTOMATION_INHIBIT) is not None
     assert opendnp3.ControlRelayOutputBlock(
         0x1, 1, 100, 100,
         opendnp3.CommandStatus.AUTOMATION_INHIBIT) is not None
     assert opendnp3.GroupVariationID(0x10, 0x1) is not None
     assert opendnp3.IINField(opendnp3.IINBit.ALL_STATIONS) is not None
     assert opendnp3.IndexedBinary(opendnp3.Binary(), 1) is not None
     assert opendnp3.IndexedDoubleBitBinary(opendnp3.DoubleBitBinary(),
                                            1) is not None
     assert opendnp3.IndexedAnalog(opendnp3.Analog(), 1) is not None
     assert opendnp3.IndexedCounter(opendnp3.Counter(), 1) is not None
     assert opendnp3.IndexedFrozenCounter(opendnp3.FrozenCounter(),
                                          1) is not None
     assert opendnp3.IndexedBinaryOutputStatus(
         opendnp3.BinaryOutputStatus(), 1) is not None
     assert opendnp3.IndexedAnalogOutputStatus(
         opendnp3.AnalogOutputStatus(), 1) is not None
     assert opendnp3.IndexedOctetString(opendnp3.OctetString(),
                                        1) is not None
     assert opendnp3.IndexedTimeAndInterval(opendnp3.TimeAndInterval(),
                                            1) is not None
     assert opendnp3.IndexedBinaryCommandEvent(
         opendnp3.BinaryCommandEvent(), 1) is not None
     assert opendnp3.IndexedAnalogCommandEvent(
         opendnp3.AnalogCommandEvent(), 1) is not None
     assert opendnp3.IndexedSecurityStat(opendnp3.SecurityStat(),
                                         1) is not None
     assert opendnp3.IndexedControlRelayOutputBlock(
         opendnp3.ControlRelayOutputBlock(), 1) is not None
     assert opendnp3.IndexedAnalogOutputInt16(opendnp3.AnalogOutputInt16(),
                                              1) is not None
     assert opendnp3.IndexedAnalogOutputInt32(opendnp3.AnalogOutputInt32(),
                                              1) is not None
     assert opendnp3.IndexedAnalogOutputFloat32(
         opendnp3.AnalogOutputFloat32(), 1) is not None
     assert opendnp3.IndexedAnalogOutputDouble64(
         opendnp3.AnalogOutputDouble64(), 1) is not None
     assert opendnp3.Binary(True) is not None
     assert opendnp3.Binary(opendnp3.Flags()) is not None
     assert opendnp3.Binary(opendnp3.Flags(),
                            opendnp3.DNPTime()) is not None
     assert opendnp3.Binary(False, opendnp3.Flags()) is not None
     assert opendnp3.Binary(True, opendnp3.Flags(),
                            opendnp3.DNPTime()) is not None
     assert opendnp3.DoubleBitBinary(opendnp3.DoubleBit(1),
                                     opendnp3.Flags(),
                                     opendnp3.DNPTime()) is not None
     assert opendnp3.BinaryOutputStatus(False, opendnp3.Flags(),
                                        opendnp3.DNPTime()) is not None
     assert opendnp3.Analog(1.2, opendnp3.Flags(),
                            opendnp3.DNPTime()) is not None
     assert opendnp3.Counter(100, opendnp3.Flags(),
                             opendnp3.DNPTime()) is not None
     assert opendnp3.FrozenCounter(2000, opendnp3.Flags(),
                                   opendnp3.DNPTime()) is not None
     assert opendnp3.AnalogOutputStatus(109.68, opendnp3.Flags(),
                                        opendnp3.DNPTime()) is not None
     assert opendnp3.TimeAndInterval(opendnp3.DNPTime(), 10,
                                     0x1) is not None
     assert opendnp3.TimeAndInterval(
         opendnp3.DNPTime(), 10, opendnp3.IntervalUnits.Seconds) is not None
     assert opendnp3.OctetData(openpal.RSlice()) is not None
     assert opendnp3.OctetString(openpal.RSlice()) is not None
     assert opendnp3.SecurityStat(opendnp3.SecurityStatValue(), 0x1,
                                  opendnp3.DNPTime()) is not None
     assert opendnp3.SecurityStat(0x1, 10, 100) is not None
     assert opendnp3.SecurityStat(0x1, 10, 100,
                                  opendnp3.DNPTime()) is not None
     assert opendnp3.LinkConfig(True, True) is not None
     assert opendnp3.LinkConfig(True, False, 100, 10, 10,
                                openpal.TimeDuration(),
                                openpal.TimeDuration()) is not None
     assert opendnp3.LinkHeaderFields(opendnp3.LinkFunction.INVALID, False,
                                      True, False, 10, 10) is not None
     assert opendnp3.LinkStatistics(
         opendnp3.LinkStatisticsChannel(),
         opendnp3.LinkStatisticsParser()) is not None
     assert opendnp3.CommandPointResult(
         100, 10, opendnp3.CommandPointState.INIT,
         opendnp3.CommandStatus.PROCESSING_LIMITED) is not None
     assert opendnp3.HeaderInfo(opendnp3.GroupVariation.Group10Var0,
                                opendnp3.QualifierCode.UINT8_CNT,
                                opendnp3.TimestampMode.SYNCHRONIZED,
                                100) is not None
     assert opendnp3.RestartOperationResult(
         opendnp3.TaskCompletion.SUCCESS,
         openpal.TimeDuration()) is not None
     assert opendnp3.DatabaseSizes(0, 1, 2, 3, 4, 5, 6, 7) is not None
     assert opendnp3.EventBufferConfig(0, 1, 2, 3, 4, 5, 6, 7) is not None
     assert opendnp3.OutstationConfig(
         opendnp3.OutstationParams(),
         opendnp3.EventBufferConfig()) is not None
     assert opendnp3.OutstationParams(opendnp3.IndexMode.Contiguous, 0x3,
                                      openpal.TimeDuration(),
                                      openpal.TimeDuration(),
                                      openpal.TimeDuration(),
                                      openpal.TimeDuration(), 10, 20, True,
                                      opendnp3.StaticTypeBitField(),
                                      opendnp3.ClassField()) is not None
     assert opendnp3.SimpleCommandHandler(
         opendnp3.CommandStatus.SUCCESS) is not None
     assert opendnp3.StaticTypeBitField(1) is not None
     assert opendnp3.StackStatistics(
         opendnp3.StackStatisticsLink(),
         opendnp3.StackStatisticsTransport()) is not None
     assert openpal.ArrayBinaryConfig(1) is not None
     assert openpal.ArrayDoubleBitBinaryConfig(1) is not None
     assert openpal.ArrayAnalogConfig(1) is not None
     assert openpal.ArrayCounterConfig(1) is not None
     assert openpal.ArrayFrozenCounterConfig(1) is not None
     assert openpal.ArrayBOStatusConfig(1) is not None
     assert openpal.ArrayAOStatusConfig(1) is not None
     assert openpal.ArrayTimeAndIntervalConfig(1) is not None
     assert openpal.ArrayBuffer(10) is not None
     assert openpal.Buffer(27) is not None
     assert openpal.Buffer(openpal.RSlice()) is not None
     assert openpal.LinkedListInt(5) is not None
     assert openpal.PairInt(5, 10) is not None
     assert openpal.RSlice(0xFF, 100) is not None
     assert openpal.SecureBuffer(10) is not None
     assert openpal.SecureBuffer(openpal.RSlice()) is not None
     assert openpal.WSlice(0x30, 20) is not None
     assert openpal.MonotonicTimestamp(100) is not None
     assert openpal.UTCTimestamp(900) is not None
     assert openpal.LogEntry("123", openpal.LogFilters(), "location 1",
                             "test") is not None
     assert openpal.LogFilters(20) is not None
     assert openpal.LoggerSettings("234", openpal.LogFilters())
    def test_pure_virtual_functions(self):
        """
            Call the pure virtual function and test if it throws the correct exception error.
        """
        try:
            asiodnp3.IChannel().GetStatistics()
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            asiodnp3.IChannelListener().OnStateChange(
                opendnp3.ChannelState.CLOSED)
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            asiodnp3.IListenCallbacks().AcceptConnection(123, "test")
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            asiodnp3.IMasterOperations().SetLogFilters(openpal.LogFilters())
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            asiodnp3.IMasterScan().Demand()
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            asiodnp3.IMasterSession().GetStackStatistics()
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            asiodnp3.IOutstation().SetRestartIIN()
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            asiodnp3.IStack().Enable()
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            asiopal.IOpenDelayStrategy().GetNextDelay(openpal.TimeDuration(),
                                                      openpal.TimeDuration())
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            asiopal.IResource().Shutdown()
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            opendnp3.IVisitorIndexedBinary().OnValue(opendnp3.IndexedBinary())
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            opendnp3.IVisitorDNPTime().OnValue(opendnp3.DNPTime())
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            opendnp3.IVisitorCommandPointResult().OnValue(
                opendnp3.CommandPointResult(
                    100, 10, opendnp3.CommandPointState.INIT,
                    opendnp3.CommandStatus.PROCESSING_LIMITED))
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            opendnp3.ICollectionIndexedBinary().Count()
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            opendnp3.ICollectionDNPTime().Count()
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            opendnp3.ICollectionCommandPointResult().Count()
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            opendnp3.ITransactable().Start()
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            opendnp3.ICommandCollectionControlRelayOutputBlock().Add(
                opendnp3.ControlRelayOutputBlock(), 1)
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            opendnp3.ICommandCollectionAnalogOutputDouble64().Add(
                opendnp3.AnalogOutputDouble64(), 1)
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            opendnp3.ICommandTaskResult(
                opendnp3.TaskCompletion.SUCCESS).Count()
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            opendnp3.IMasterApplication().Now()
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            opendnp3.ISOEHandler().Process(opendnp3.HeaderInfo(),
                                           opendnp3.ICollectionIndexedBinary())
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            opendnp3.ITaskCallback().OnStart()
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            opendnp3.ICommandHandler().Start()
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)

        try:
            opendnp3.IUpdateHandler().Update(opendnp3.Binary(True), 1)
        except RuntimeError as err:
            assert "Tried to call pure virtual function" in str(err)
Пример #9
0
 def test_send_binary(self, run_master):
     self.run_outstation(value=opendnp3.Binary(False))
Пример #10
0
    def create_message_updates(self, simulation_id, message):
        """ This method creates an atomic "updates" object for any outstation to consume via their .Apply method.
        ----------
        headers: dict
            A dictionary of headers that could be used to determine topic of origin and
            other attributes.
        message: object

        """
        try:
            message_str = 'received message ' + str(message)

            builder = asiodnp3.UpdateBuilder()
            json_msg = yaml.safe_load(str(message))

            if type(json_msg) != dict:
                raise ValueError(' is not a json formatted string.' +
                                 '\njson_msg = {0}'.format(json_msg))

            # fncs_input_message = {"{}".format(simulation_id): {}}
            measurement_values = json_msg["message"]["measurements"]

            # Calculate each net-phase measurement
            if (measurement_values):

                myPoints = self.outstation.get_agent(
                ).point_definitions.all_points()
                netPoints = list(
                    filter(lambda x: "net-" in x.description, myPoints))

                for point in netPoints:
                    ptMeasurements = list(
                        filter(
                            lambda m: m.get("measurement_mrid") in point.
                            measurement_id, measurement_values.values()))
                    netValue = 0.0

                    for m in ptMeasurements:
                        if "VAR" in point.name:
                            angle = math.radians(m.get("angle"))
                            netValue = netValue + math.sin(angle) * float(
                                m.get("magnitude"))

                        elif "Watts" in point.name:
                            angle = math.radians(m.get("angle"))
                            netValue += math.cos(angle) * float(
                                m.get("magnitude"))

                        else:
                            netValue += float(m.get("magnitude"))

                    point.magnitude = netValue
                    builder.Update(opendnp3.Analog(point.magnitude),
                                   point.index)

            # Calculate each measurement
            for y in measurement_values:
                # print(self.processor_point_def.points_by_mrid())
                m = measurement_values[y]

                if "magnitude" in m.keys():
                    for point in self.outstation.get_agent(
                    ).point_definitions.all_points():
                        #print("point",point.name)
                        #print("y",y)
                        if m.get("measurement_mrid") == point.measurement_id:
                            if point.magnitude != float(m.get("magnitude")):
                                point.magnitude = float(m.get("magnitude"))
                                builder.Update(
                                    opendnp3.Analog(point.magnitude),
                                    point.index)

                            if point.measurement_type == "VA":
                                if "VAR" in point.name:
                                    angle = math.radians(m.get("angle"))
                                    point.magnitude = math.sin(angle) * float(
                                        m.get("magnitude"))
                                    builder.Update(
                                        opendnp3.Analog(point.magnitude),
                                        point.index)

                                if "Watts" in point.name:
                                    angle1 = math.radians(m.get("angle"))
                                    point.magnitude = math.cos(angle1) * float(
                                        m.get("magnitude"))
                                    builder.Update(
                                        opendnp3.Analog(point.magnitude),
                                        point.index)

                                if "angle" in point.name:
                                    angle2 = math.radians(m.get("angle"))
                                    builder.Update(opendnp3.Analog(angle2),
                                                   point.index)

                elif "value" in m.keys():
                    for point in self.outstation.get_agent(
                    ).point_definitions.all_points():
                        if m.get(
                                "measurement_mrid"
                        ) == point.measurement_id and point.value != m.get(
                                "value"):
                            point.value = m.get("value")
                            builder.Update(opendnp3.Binary(point.value),
                                           point.index)

            # Return the atomic "updates" object
            print("Updates Created")
            return builder.Build()
        except Exception as e:
            message_str = "An error occurred while trying to translate the  message received" + str(
                e)
Пример #11
0
 def do_b0(self, line):
     """Send the Master a BinaryInput (group 2) value of False at index 6. Command syntax is: b0"""
     self.application.apply_update(opendnp3.Binary(False), index=6)