Exemplo n.º 1
0
 def start(self, qosxml, qosprofile):
     if qosxml and qosprofile:
         self._qosProfile = dds.QosProvider(qosxml, qosprofile)
         self._domainParticipant = dds.DomainParticipant(
             qos=self._qosProfile.get_participant_qos())
         self._publisher = self._domainParticipant.create_publisher(
             qos=self._qosProfile.get_publisher_qos())
         self._subscriber = self._domainParticipant.create_subscriber(
             qos=self._qosProfile.get_subscriber_qos())
     else:
         self._domainParticipant = dds.DomainParticipant()
         self._publisher = self._domainParticipant.create_publisher()
         self._subscriber = self._domainParticipant.create_subscriber()
    def test_take_cond(self):
        dp = dds.DomainParticipant()

        gci = ddsutil.get_dds_classes_from_idl(self.idl_path,
                                               self.shape_type_name)
        ShapeType = gci.get_class('ShapeType')
        Inner = gci.get_class('Inner')

        t = gci.register_topic(dp, 'ST_test_take_cond')

        rd = dp.create_datareader(t)
        wr = dp.create_datawriter(t)

        qc = rd.create_querycondition(expression='color = %0',
                                      parameters=['RED'])

        dataR = ShapeType(color='RED', x=1, y=1, z=1, t=Inner(foo=1))
        dataG = ShapeType(color='GREEN', x=1, y=1, z=1, t=Inner(foo=1))

        wr.write(dataR)
        wr.write(dataG)

        data = rd.take_cond(qc, 2)
        self.assertEqual(1, len(data))
        found = [d.color for d, _ in data]
        self.assertIn('RED', found)
    def test_read_cond(self):
        dp = dds.DomainParticipant()

        gci = ddsutil.get_dds_classes_from_idl(self.idl_path,
                                               self.shape_type_name)
        ShapeType = gci.get_class('ShapeType')
        Inner = gci.get_class('Inner')

        t = gci.register_topic(dp, 'ST_test_take_cond')

        rd = dp.create_datareader(t)
        wr = dp.create_datawriter(t)

        qc = rd.create_querycondition(expression='x = 1')

        dataR = ShapeType(color='RED', x=1, y=1, z=1, t=Inner(foo=1))
        dataG = ShapeType(color='GREEN', x=1, y=1, z=1, t=Inner(foo=1))
        dataB = ShapeType(color='BLUE', x=2, y=1, z=1, t=Inner(foo=1))

        wr.write(dataR)
        wr.write(dataG)
        wr.write(dataB)

        samples = rd.read_cond(qc, 3)
        self.assertEqual(2, len(samples))
        found = [s.data.color for s in samples]
        self.assertIn('RED', found)
        self.assertIn('GREEN', found)
Exemplo n.º 4
0
    def test_publication_matched_status(self):
        dp = dds.DomainParticipant()

        topic_name = 'ST_publication_matched_status'
        gci = ddsutil.get_dds_classes_from_idl(self.idl_path,
                                               self.shape_type_name)
        t = gci.register_topic(dp, topic_name)

        wr = dp.create_datawriter(t)

        status = wr.publication_matched_status()
        Info = namedtuple('Info', ['name', 'type'])
        attrs = [
            Info('total_count', int),
            Info('total_count_change', int),
            Info('current_count', int),
            Info('current_count_change', int),
            Info('last_subscription_handle', int)
        ]
        self.assertIsNotNone(status, 'status is None')
        self.assertIsInstance(status, dds.PublicationMatchedStatus)
        for a in attrs:
            self.assertTrue(hasattr(status, a.name))
            self.assertIsInstance(getattr(status, a.name), a.type,
                                  '{} is not a {}'.format(a.name, a.type))
Exemplo n.º 5
0
    def __init__(self) -> None:
        self.isopen = True
        self.user_host = base.get_user_host()
        self.default_identity = self.user_host

        # Accumulators for verifying that close is working.
        self.num_read_loops = 0

        self.done_task: asyncio.Future = asyncio.Future()

        # Set of SalInfo.
        self._salinfo_set: weakref.WeakSet[SalInfo] = weakref.WeakSet()

        self.origin = os.getpid()
        self.idl_dir = idl.get_idl_dir()

        qos_path = ddsconfig.get_qos_path()
        self.ackcmd_qos_set = QosSet(qos_path=qos_path,
                                     profile_name="AckcmdProfile")
        self.command_qos_set = QosSet(qos_path=qos_path,
                                      profile_name="CommandProfile")
        self.event_qos_set = QosSet(qos_path=qos_path,
                                    profile_name="EventProfile")
        self.telemetry_qos_set = QosSet(qos_path=qos_path,
                                        profile_name="TelemetryProfile")

        # Any of the three qos providers is fine for the participant qos.
        participant_qos = self.command_qos_set.qos_provider.get_participant_qos(
        )
        self.participant = dds.DomainParticipant(qos=participant_qos)
    def testDDSTopic(self):
        data = SimpleTypes.basic.module_SimpleTypes.SimpleTypes_struct(
            string1='Hello World!',
            char1='X',
            bool1=True,
            octet1=127,
            long1=1123)

        dp = dds.DomainParticipant()
        qos = None
        topic = dds.Topic(
            dp, 'SimpleTypes',
            SimpleTypes.basic.module_SimpleTypes.SimpleTypes_struct.
            get_type_support())

        self.assertIsNotNone(topic, 'Returned topic must not be None')

        pub = dp.create_publisher()
        sub = dp.create_subscriber()

        wr = pub.create_datawriter(topic)
        rd = sub.create_datareader(topic)

        wr.write(data)

        rs = rd.take(1)
        self.assertEqual(len(rs), 1)

        self.assertEqual(str(rs[0][0]), str(data))
Exemplo n.º 7
0
    def test_liveliness_changed_status(self):
        dp = dds.DomainParticipant()

        topic_name = 'ST_liveliness_changed_status'
        gci = ddsutil.get_dds_classes_from_idl(self.idl_path,
                                               self.shape_type_name)
        t = gci.register_topic(dp, topic_name)

        rd = dp.create_datareader(t)

        status = rd.liveliness_changed_status()
        Info = namedtuple('Info', ['name', 'type'])
        attrs = [
            Info('alive_count', int),
            Info('not_alive_count', int),
            Info('alive_count_change', int),
            Info('not_alive_count_change', int),
            Info('last_publication_handle', int)
        ]
        self.assertIsNotNone(status, 'status is None')
        self.assertIsInstance(status, dds.LivelinessChangedStatus)
        for a in attrs:
            self.assertTrue(hasattr(status, a.name))
            self.assertIsInstance(getattr(status, a.name), a.type,
                                  '{} is not a {}'.format(a.name, a.type))
Exemplo n.º 8
0
def demo_over_the_wire_topics():
    print('Connecting to DDS domain...')
    dp = dds.DomainParticipant()

    print('Finding HelloWorldTopic...')
    found_topic = dp.find_topic('HelloWorldData_Msg')

    print('Registering HelloWorldData_Msg locally')
    local_topic = ddsutil.register_found_topic_as_local(found_topic)

    print('Getting Python classes for the found topic...')
    gen_info = ddsutil.get_dds_classes_for_found_topic(found_topic)
    OsplTestTopic = gen_info.get_class(found_topic.type_name)

    print('Creating sample data to write...')
    data = OsplTestTopic(userID=1, message='Hello World')

    print('Creating writers...')
    pub = dp.create_publisher()
    wr = pub.create_datawriter(local_topic, found_topic.qos)
    # data = gen_info.topic_data_class(userID=1, message='Hello World')

    print('Writing sample data...')
    wr.write(data)
    print('Wrote: %s' % (str(data)))
    print('All Done!!!')
Exemplo n.º 9
0
    def __init__(self, qos_path):
        self.participant = None
        self._component_set = set()

        self.qos_path = pathlib.Path(qos_path).resolve()
        if not self.qos_path.is_file():
            raise ValueError(f"qos_path={qos_path} is not a file")
        self.qos_provider = dds.QosProvider(self.qos_path.as_uri(), 'DDS DefaultQosProfile')

        participant_qos = self.qos_provider.get_participant_qos()
        self.participant = dds.DomainParticipant(qos=participant_qos)

        self.topic_qos = self.qos_provider.get_topic_qos()

        read_queue_policy = dds.HistoryQosPolicy(depth=DDS_READ_QUEUE_LEN,
                                                 kind=dds.DDSHistoryKind.KEEP_LAST)
        self.reader_qos = self.qos_provider.get_reader_qos()
        # QoS for readers that want late-joiner data
        self.reader_qos.set_policies([read_queue_policy])

        self.volatilereader_qos = self.qos_provider.get_reader_qos()
        volatile_policy = dds.DurabilityQosPolicy(dds.DDSDurabilityKind.VOLATILE)
        # QoS for readers that do not want late-joiner data
        self.volatilereader_qos.set_policies([read_queue_policy, volatile_policy])

        self.writer_qos = self.qos_provider.get_writer_qos()
Exemplo n.º 10
0
    def test_inconsistent_topic_status(self):
        dp = dds.DomainParticipant()
        t, _ = ddsutil.find_and_register_topic(dp, 'DCPSParticipant')

        status = t.inconsistent_topic_status()
        self.assertIsNotNone(status, 'status is None')
        self.assertTrue(hasattr(status, 'total_count'))
        self.assertTrue(hasattr(status, 'total_count_change'))
        self.assertIsInstance(status.total_count, int)
        self.assertIsInstance(status.total_count_change, int)
Exemplo n.º 11
0
 def __init__(self, sQualityOfServiceFile, sQualityOfServiceName,
              sDataStructureFile):
     self.__oQP = dds.QosProvider(sQualityOfServiceFile,
                                  sQualityOfServiceName)
     self.__oDP = dds.DomainParticipant(
         qos=self.__oQP.get_participant_qos())
     self.__sDataStructureFile = sDataStructureFile
     self.__oTopics = None
     self.__oPub = None
     self.DataReceived = Event()
Exemplo n.º 12
0
def demo_over_the_wire_topics():
    print('Starting OpenSplice Tester, which registers a topic we don'
          't have locally...')
    # This runs OpenSplice Tester headlessly, and runs a Tester 'scenario' to periodically
    # write data to the OsplTestTopic topic.
    subprocess.call(['ospltest', '-headless', '-e', '-s', 'PythonExample4.sd'])
    print('   Waiting 15s for it to start...')
    time.sleep(15)
    print('   Finished waiting, continuing...')

    print('Connecting to DDS domain...')
    dp = dds.DomainParticipant()

    print('Finding OsplTestTopic...')
    found_topic = dp.find_topic('OsplTestTopic')

    print('Registering OsplTestTopic locally')
    local_topic = ddsutil.register_found_topic_as_local(found_topic)

    print('Getting Python classes for the found topic...')
    gen_info = ddsutil.get_dds_classes_for_found_topic(found_topic)
    OsplTestTopic = gen_info.get_class(found_topic.type_name)
    Tstate = gen_info.get_class('ospllog::Tstate')

    print('Creating sample data to write...')
    data = OsplTestTopic(id=11,
                         index=22,
                         x=1.2,
                         y=2.3,
                         z=3.4,
                         t=9.8,
                         state=Tstate.init,
                         description='Hello from Python')

    print('Creating readers and writers...')
    pub = dp.create_publisher()
    wr = pub.create_datawriter(local_topic, found_topic.qos)
    sub = dp.create_subscriber()
    rd = sub.create_datareader(local_topic, found_topic.qos)

    print('Writing sample data...')
    wr.write(data)
    print('Wrote: %s' % (str(data)))

    print('Waiting a bit so Tester has time to see our data...')
    time.sleep(3)

    print('Reading data...')
    l = rd.take(10)
    for (sd, si) in l:
        if si.valid_data:
            print('Read: %s' % (str(sd)))

    print('All Done!!!')
Exemplo n.º 13
0
    def test_unregistration(self):
        dp = dds.DomainParticipant()
        
        gci = ddsutil.get_dds_classes_from_idl(self.idl_path, self.shape_type_name)
        ShapeType = gci.get_class('ShapeType')
        Inner = gci.get_class('Inner')
        
        t = gci.register_topic(dp, 'ST_test_unregistration')
        
        wr = dp.create_datawriter(t)
        #data = ShapeType(color='RED')
        data = ShapeType(color='RED',x=0,y=0,z=0,t=Inner(foo=0))
        data2 = ShapeType(color='BLUE',x=0,y=0,z=0,t=Inner(foo=0))
        data3 = ShapeType(color='YELLOW',x=0,y=0,z=0,t=Inner(foo=0))
        data4 = ShapeType(color='PINK',x=0,y=0,z=0,t=Inner(foo=0))
        dataNever = ShapeType(color='NEVER',x=0,y=0,z=0,t=Inner(foo=0))
        
        h = wr.register_instance(data)
        h2 = wr.register_instance(data2)
        h3 = wr.register_instance(data3)
        h4 = wr.register_instance(data4)
        self.assertIsNotNone(h, 'handle is None')
        self.assertIsInstance(h, int, 'handle is not int')

        # test expected success paths
        wr.unregister_instance(handle=h)
        wr.unregister_instance(data=data2)
        
        # test failure paths
        try:
            wr.unregister_instance()
            self.fail('should not succeed; unregistering inconsistent data')
        except dds.DDSException:
            pass

        # unregister something that's already unregistered
        try:
            wr.unregister_instance(handle=h)
            self.fail('should not succeed; duplicate unregistration')
        except dds.DDSException:
            pass
        
        # unregister something that was never registered
        try:
            wr.unregister_instance(data=dataNever)
            self.fail('should not succeed; instance never registered')
        except dds.DDSException:
            pass

        # The following are not failures, but will produce oslp-error.log entries  
        
        # unregister something where data does not match        
        wr.unregister_instance(dataNever, h4)
Exemplo n.º 14
0
    def test_registration(self):
        dp = dds.DomainParticipant()
        
        gci = ddsutil.get_dds_classes_from_idl(self.idl_path, self.shape_type_name)
        ShapeType = gci.get_class('ShapeType')
        Inner = gci.get_class('Inner')
        
        t = gci.register_topic(dp, 'ST_test_registration')
        
        wr = dp.create_datawriter(t)
        #data = ShapeType(color='RED')
        data = ShapeType(color='RED',x=0,y=0,z=0,t=Inner(foo=0))
        
        h = wr.register_instance(data)
        self.assertIsNotNone(h, 'handle is None')
        self.assertIsInstance(h, int, 'handle is not int')

        wr.unregister_instance(data, h)
Exemplo n.º 15
0
    def test_wr_instance_lookup(self):
        dp = dds.DomainParticipant()

        gci = ddsutil.get_dds_classes_from_idl(self.idl_path, self.shape_type_name)
        ShapeType = gci.get_class('ShapeType')
        Inner = gci.get_class('Inner')

        t = gci.register_topic(dp, 'ST_test_wr_instance_lookup')

        wr = dp.create_datawriter(t)
        #data = ShapeType(color='RED')
        data = ShapeType(color='RED',x=0,y=0,z=0,t=Inner(foo=0))
        dataUnreg = ShapeType(color='GREEN',x=0,y=0,z=0,t=Inner(foo=0))

        h = wr.register_instance(data)

        hlookup = wr.lookup_instance(data)
        self.assertEqual(hlookup, h)

        hUnreg = wr.lookup_instance(dataUnreg)
        self.assertIsNone(hUnreg)
Exemplo n.º 16
0
    def test_liveliness_lost_status(self):
        dp = dds.DomainParticipant()

        topic_name = 'ST_liveliness_lost_status'
        gci = ddsutil.get_dds_classes_from_idl(self.idl_path,
                                               self.shape_type_name)
        t = gci.register_topic(dp, topic_name)

        wr = dp.create_datawriter(t)

        status = wr.liveliness_lost_status()
        Info = namedtuple('Info', ['name', 'type'])
        attrs = [
            Info('total_count', int),
            Info('total_count_change', int),
        ]
        self.assertIsNotNone(status, 'status is None')
        self.assertIsInstance(status, dds.LivelinessLostStatus)
        for a in attrs:
            self.assertTrue(hasattr(status, a.name))
            self.assertIsInstance(getattr(status, a.name), a.type,
                                  '{} is not a {}'.format(a.name, a.type))
Exemplo n.º 17
0
    def test_requested_incompatible_qos_status(self):
        dp = dds.DomainParticipant()

        topic_name = 'ST_requested_incompatible_qos_status'
        gci = ddsutil.get_dds_classes_from_idl(self.idl_path,
                                               self.shape_type_name)
        t = gci.register_topic(dp, topic_name)

        rd = dp.create_datareader(t)

        status = rd.requested_incompatible_qos_status()
        Info = namedtuple('Info', ['name', 'type'])
        attrs = [
            Info('total_count', int),
            Info('total_count_change', int),
            Info('last_policy_id', dds.QosPolicyId),
        ]
        self.assertIsNotNone(status, 'status is None')
        self.assertIsInstance(status, dds.RequestedIncompatibleQosStatus)
        for a in attrs:
            self.assertTrue(hasattr(status, a.name))
            self.assertIsInstance(getattr(status, a.name), a.type,
                                  '{} is not a {}'.format(a.name, a.type))
Exemplo n.º 18
0
    def testParticipant_textData(self):
        myData = 'DP Text User Data'
        builtinTopicName = 'DCPSParticipant'
        sawMyData = Event()
        dp_qos_txt = dds.Qos(policies=[dds.UserdataQosPolicy(myData)])
        dp2 = dds.DomainParticipant(qos=dp_qos_txt)

        class L(dds.Listener):
            def on_data_available(self, reader):
                nonlocal sawMyData
                while True:
                    r = reader.take(n=1)
                    if len(r) == 0:
                        break
                    elif r[0].status.valid_data:
                        try:
                            v = bytes(
                                r[0].data.user_data.value).decode('ISO-8859-1')
                            if v == myData:
                                sawMyData.set()
                                break
                        except UnicodeError:
                            pass

        builtin_sub = self.dp.create_subscriber(
            qos=dds.Qos([dds.PartitionQosPolicy(['__BUILT-IN PARTITION__'])]))
        builtin_topic_info = ddsutil.find_and_register_topic(
            self.dp, builtinTopicName)

        builtin_reader = builtin_sub.create_datareader(
            builtin_topic_info.topic,
            qos=builtin_topic_info.topic.qos,
            listener=L())

        self.assertTrue(sawMyData.wait(10), 'Did not see expected data')
        builtin_reader.close()
        dp2.close()
Exemplo n.º 19
0
    def test_read_instance(self):
        dp = dds.DomainParticipant()
        
        gci = ddsutil.get_dds_classes_from_idl(self.idl_path, self.shape_type_name)
        ShapeType = gci.get_class('ShapeType')
        Inner = gci.get_class('Inner')
        
        t = gci.register_topic(dp, 'ST_test_read_instance')
        
        rd = dp.create_datareader(t)
        wr = dp.create_datawriter(t)
        
        dataR = ShapeType(color='RED',x=1,y=1,z=1,t=Inner(foo=1))
        dataG = ShapeType(color='GREEN',x=1,y=1,z=1,t=Inner(foo=1))
        
        keyR = ShapeType(color='RED',x=0,y=0,z=0,t=Inner(foo=0))
        
        hR = rd.lookup_instance(keyR)
        self.assertIsNone(hR)

        wr.write(dataR)
        wr.write(dataG)
        
        hR = rd.lookup_instance(keyR)
        self.assertIsInstance(hR, int)
        
        data = rd.read_instance(hR,n=2)
        self.assertEqual(1, len(data))
        found = [d.color for d, _ in data]
        self.assertIn('RED',found)
        
        #do it again
        data = rd.read_instance(hR,n=2)
        self.assertEqual(1, len(data))
        found = [d.color for d, _ in data]
        self.assertIn('RED',found)
Exemplo n.º 20
0
    def test_sample_rejected_status(self):
        dp = dds.DomainParticipant()

        topic_name = 'ST_sample_rejected_status'
        gci = ddsutil.get_dds_classes_from_idl(self.idl_path,
                                               self.shape_type_name)
        t = gci.register_topic(dp, topic_name)

        rd = dp.create_datareader(t)

        status = rd.sample_rejected_status()
        Info = namedtuple('Info', ['name', 'type'])
        attrs = [
            Info('total_count', int),
            Info('total_count_change', int),
            Info('last_reason', dds.DDSSampleRejectedStatusKind),
            Info('last_instance_handle', int),
        ]
        self.assertIsNotNone(status, 'status is None')
        self.assertIsInstance(status, dds.SampleRejectedStatus)
        for a in attrs:
            self.assertTrue(hasattr(status, a.name))
            self.assertIsInstance(getattr(status, a.name), a.type,
                                  '{} is not a {}'.format(a.name, a.type))
Exemplo n.º 21
0
 def setUpClass(cls):
     cls.dp = dds.DomainParticipant()