def testTopic_bytesData(self): myData = b'Topic Bytes Topic Data' builtinTopicName = 'DCPSTopic' sawMyData = Event() 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.topic_data.value) 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()) # Register a topic with a TopicdataQosPolicy t_qos = dds.Qos(policies=[dds.TopicdataQosPolicy(myData)]) info = ddsutil.get_dds_classes_from_idl('idl/Shapes.idl', "ShapeType") t = info.register_topic(self.dp, "T_testTopic_bytesData", t_qos) self.assertIsNotNone(t, "Topic registration failed") self.assertTrue(sawMyData.wait(10), 'Did not see expected data') builtin_reader.close()
def testParticipant_bytesData(self): myData = b'DP Bytes 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) 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()
def testSimplifiedFindAPI(self): idl_path = 'idl/' + 'Thales' + '.idl' type_info = 'test::C_TopicStruct' gen_info = ddsutil.get_dds_classes_from_idl(idl_path, type_info) dp1 = DomainParticipant() tq1 = Qos([DurabilityQosPolicy(DDSDurabilityKind.PERSISTENT)]) topic_dp1 = gen_info.register_topic(dp1, 'DP1_C_TopicStruct_2',tq1) self.assertEqual('DP1_C_TopicStruct_2', topic_dp1.name, 'Topic name not as expected') self.assertEqual(type_info, topic_dp1.type_name, 'Type name not as expected') self.assertEqual('A_ID.A_ID,A_ID.A_subID', topic_dp1.keylist, 'Key list not as expected') self.assertEqual('<MetaData version="1.0.0"><Module name="test"><Struct name="T_ID"><Member name="A_ID"><Long/></Member><Member name="A_subID"><Long/></Member></Struct><TypeDef name="T_IDList"><Sequence><Type name="T_ID"/></Sequence></TypeDef><Struct name="C_TopicStruct"><Member name="A_ID"><Type name="T_ID"/></Member><Member name="A_ForeignIDList"><Type name="T_IDList"/></Member><Member name="value"><Long/></Member></Struct></Module></MetaData>', topic_dp1.metadescriptor, 'Meta descriptor not as expected') dp2 = DomainParticipant() topic_dp2, gen_info2 = ddsutil.find_and_register_topic(dp2, 'DP1_C_TopicStruct_2') self.assertIsNotNone(topic_dp2, 'Found topic is not None') self.assertEqual('DP1_C_TopicStruct_2', topic_dp2.name, 'Found topic name not as expected') self.assertEqual(type_info, topic_dp2.type_name, 'Found type name not as expected') self.assertEqual('A_ID.A_ID,A_ID.A_subID', topic_dp2.keylist, 'Found key list not as expected') self.assertEqual('<MetaData version="1.0.0"><Module name="test"><Struct name="T_ID"><Member name="A_ID"><Long/></Member><Member name="A_subID"><Long/></Member></Struct><TypeDef name="T_IDList"><Sequence><Type name="T_ID"/></Sequence></TypeDef><Struct name="C_TopicStruct"><Member name="A_ID"><Type name="T_ID"/></Member><Member name="A_ForeignIDList"><Type name="T_IDList"/></Member><Member name="value"><Long/></Member></Struct></Module></MetaData>', topic_dp2.metadescriptor, 'Found meta descriptor not as expected') sub2 = dp2.create_subscriber() # now register the found topic locally, and test reading and writing between the participants self.assertIsNotNone(gen_info2, 'Returned gen_info2 is None') tq2 = topic_dp2.qos self.assertIsNotNone(tq2) # TODO: need get copy topic qos #local_topic_dp2 = register_topic_locally(topic_dp2) # local_topic_dp2 = gen_info2.register_topic(dp2, topic_dp2.get_name(), tq2) # Reader for dp2 result_holder = ResultHolder() event = Event() rd2 = sub2.create_datareader(topic_dp2, tq2, DataAvailableListener(result_holder, event)) # Writer for dp1 pub1 = dp1.create_publisher() wr1 = pub1.create_datawriter(topic_dp1, tq1) # create the data Outer = gen_info.get_class('test::C_TopicStruct') Inner = gen_info.get_class('test::T_ID') data1 = Outer() data1.A_ID = Inner(A_ID=21,A_subID=212) data1.A_ForeignIDList = [Inner(A_ID=22,A_subID=223),Inner(A_ID=23,A_subID=234)] data1.value = 242 wr1.write(data1) # let the listener catch up... self.assertTrue(event.wait(10.0), 'wait timed out') self.assertEqual(str(data1), result_holder.result, 'read and write results do not match')
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)
def testGroup_textData(self): myData = 'Pub Text Group Data' builtinTopicName = 'DCPSPublication' sawMyData = Event() 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.group_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()) # Register a topic with a TopicdataQosPolicy p_qos = dds.Qos(policies=[dds.GroupdataQosPolicy(myData)]) pub = self.dp.create_publisher(p_qos) info = ddsutil.get_dds_classes_from_idl('idl/Shapes.idl', "ShapeType") t = info.register_topic(self.dp, "T_testGroup_textData") self.assertIsNotNone(t, "Topic registration failed") dw = pub.create_datawriter(t) self.assertTrue(sawMyData.wait(10), 'Did not see expected data') builtin_reader.close() dw.close() pub.close()
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()