def main(): t104slave = T104Slave() t104slave.set_local_address(ip=b"localhost") connectionParameters = t104slave.get_connection_parameters() # Set up callbacks t104slave.set_connection_request_handler(connection_request_callback) t104slave.set_clock_synchronization_handler(clock_sync_callback) t104slave.set_interrogation_handler(interrogation_callback) t104slave.set_asdu_handler(asdu_callback) if not t104slave.start(): raise RuntimeError("Server not started") try: scaledValue = 0 while True: time.sleep(1) asdu = ASDU(connectionParameters, TypeID.M_ME_NB_1, False, CauseOfTransmission.PERIODIC, 0, 1, False, False) asdu.add_information_object( MeasuredValueScaled(110, scaledValue, QualityDescriptor.IEC60870_QUALITY_GOOD)) scaledValue += 1 t104slave.enqueue_asdu(asdu) except KeyboardInterrupt: pass finally: t104slave.stop()
def interrogation_callback(parameter, connection, asdu, qoi): logging.info("Received interrogation for group {}".format(qoi)) if qoi == 20: connection.send_act_con(asdu) new_asdu = ASDU(parameter, TypeID.M_ME_NB_1, False, CauseOfTransmission.INTERROGATED_BY_STATION, 0, 1) new_asdu.add_information_object( MeasuredValueScaled(100, -1, QualityDescriptor.IEC60870_QUALITY_GOOD)) new_asdu.add_information_object( MeasuredValueScaled(101, 23, QualityDescriptor.IEC60870_QUALITY_GOOD)) new_asdu.add_information_object( MeasuredValueScaled(102, 2300, QualityDescriptor.IEC60870_QUALITY_GOOD)) connection.send_asdu(new_asdu) new_asdu = ASDU(parameter, TypeID.M_SP_NA_1, False, CauseOfTransmission.INTERROGATED_BY_STATION, 0, 1) new_asdu.add_information_object( SinglePointInformation(104, True, QualityDescriptor.IEC60870_QUALITY_GOOD)) new_asdu.add_information_object( SinglePointInformation(105, False, QualityDescriptor.IEC60870_QUALITY_GOOD)) connection.send_asdu(new_asdu) new_asdu = ASDU(parameter, TypeID.M_SP_NA_1, False, CauseOfTransmission.INTERROGATED_BY_STATION, 0, 1) new_asdu.add_information_object( SinglePointInformation(301, False, QualityDescriptor.IEC60870_QUALITY_GOOD)) new_asdu.add_information_object( SinglePointInformation(302, True, QualityDescriptor.IEC60870_QUALITY_GOOD)) new_asdu.add_information_object( SinglePointInformation(303, False, QualityDescriptor.IEC60870_QUALITY_GOOD)) new_asdu.add_information_object( SinglePointInformation(304, True, QualityDescriptor.IEC60870_QUALITY_GOOD)) new_asdu.add_information_object( SinglePointInformation(305, False, QualityDescriptor.IEC60870_QUALITY_GOOD)) new_asdu.add_information_object( SinglePointInformation(306, True, QualityDescriptor.IEC60870_QUALITY_GOOD)) new_asdu.add_information_object( SinglePointInformation(307, False, QualityDescriptor.IEC60870_QUALITY_GOOD)) connection.send_asdu(new_asdu) connection.send_act_term(asdu) else: connection.send_act_con(asdu, True) return True
def test_get_element_0_does_not_exist(self): sut = ASDU() self.assertIsNone(sut.get_element(0))
def test_add_information_object(self): io = SinglePointInformation(400, True, QualityDescriptor.IEC60870_QUALITY_GOOD) sut = ASDU(None, io.get_type_id(), False, CauseOfTransmission.PERIODIC, 0, 1, False, False) value = sut.add_information_object(io) self.assertEqual(io, sut.elements[0])
def test_is_sequence(self): sut = ASDU() self.assertFalse(sut.is_sequence())
def test_get_number_of_elements(self): sut = ASDU() self.assertEqual(sut.get_number_of_elements(), 0)
def test_set_ca(self): sut = ASDU() sut.set_ca(2) self.assertEqual(sut.get_ca(), 2)
def test_get_type_id(self): sut = ASDU() self.assertEqual(sut.get_type_id(), TypeID.INVALID)
def test_set_cot(self): sut = ASDU() sut.set_cot(CauseOfTransmission.ACTIVATION) self.assertEqual(sut.get_cot(), CauseOfTransmission.ACTIVATION)
def test_get_oa(self): sut = ASDU() self.assertEqual(sut.get_oa(), 1)
def test_set_negative(self): sut = ASDU() sut.set_negative(True) self.assertTrue(sut.is_negative())
def test_set_test(self): sut = ASDU() sut.set_test(True) self.assertTrue(sut.is_test())
def test_init(self): sut = ASDU()