Jump to content


Photo

publisher & subscriber not communicating


  • Please log in to reply
4 replies to this topic

#1 anon1234

anon1234

    Member

  • Members
  • PipPip
  • 11 posts

Posted 18 November 2010 - 12:15 AM

Hi,
I am trying to create a simple c++ dds publisher and subscriber. The code compiles fine and runs but they don't communicate even though they are in the same Domain and publishing/subscribing to the same topic. The publisher returns success after write() so I think the publisher code is good; but the subscriber's on_data_available function is never called? I'm not sure how to debug this. I've attached my code and it would be great if someone can point me in the right direction.

include "stdafx.h"
#include <stdio.h>
#include "ccpp_dds_dcps.h"
#include "ccpp_Test.h"

class TrackListener : public DDS::DataReaderListener {
public:
virtual void on_requested_deadline_missed (DDS::DataReader_ptr reader, const DDS::RequestedDeadlineMissedStatus& status){}
virtual void on_requested_incompatible_qos (DDS::DataReader_ptr reader, const DDS::RequestedIncompatibleQosStatus& status){}
virtual void on_sample_rejected (DDS::DataReader_ptr reader, const DDS::SampleRejectedStatus& status){}
virtual void on_liveliness_changed (DDS::DataReader_ptr reader, const DDS::LivelinessChangedStatus& status){}
virtual void on_subscription_matched (DDS::DataReader_ptr reader, const DDS::SubscriptionMatchedStatus& status){}
virtual void on_sample_lost (DDS::DataReader_ptr reader, const DDS::SampleLostStatus& status){}

virtual void on_data_available (DDS::DataReader_ptr reader);

};

void TrackListener::on_data_available(DDS::DataReader_ptr reader)
{
printf("on_data called");
JTCWOSDDS::TrackDataReader_ptr trackDataReader = NULL;

JTCWOSDDS::TrackSeq data_seq;
DDS::SampleInfoSeq info_seq;
DDS::ReturnCode_t retcode;
int i;

trackDataReader = JTCWOSDDS::TrackDataReader::_narrow(reader);
if (trackDataReader == NULL) {
printf("DataReader narrow error\n");
return;
}

retcode = trackDataReader->take(
data_seq, info_seq, DDS::LENGTH_UNLIMITED,
DDS::ANY_SAMPLE_STATE, DDS::ANY_VIEW_STATE, DDS::ANY_INSTANCE_STATE);

if (retcode == DDS::RETCODE_NO_DATA) {
return;
} else if (retcode != DDS::RETCODE_OK) {
printf("take error %d\n", retcode);
return;
}

for (i = 0; i < data_seq.length(); ++i) {
if (info_seq[i].valid_data) {
printf("got data %s:%s\n", data_seq[i].data, data_seq[i].uid);
}
}

retcode = trackDataReader->return_loan(data_seq, info_seq);
if (retcode != DDS::RETCODE_OK) {
printf("return loan error %d\n", retcode);
}
}

int _tmain(int argc, _TCHAR* argv[])
{
DDS::DomainId_t domainId = NULL;
DDS::DomainParticipantFactory_ptr domainParticipantFactory = NULL;
DDS::DomainParticipant_ptr domainParticipant = NULL;
DDS::Topic_ptr topic = NULL;
DDS::Subscriber_ptr subscriber = NULL;
DDS::DataReader_ptr dataReader = NULL;

char* typeName = NULL;
DDS::ReturnCode_t returnCode = DDS::RETCODE_OK;

JTCWOSDDS::TrackTypeSupport trackTypeSupport;
TrackListener* trackListener = new TrackListener();


domainParticipantFactory = DDS::DomainParticipantFactory::get_instance();
if( domainParticipantFactory != NULL )
{
domainParticipant = domainParticipantFactory->create_participant(domainId,PARTICIPANT_QOS_DEFAULT, NULL, DDS::STATUS_MASK_NONE);
if( domainParticipant != NULL )
{
subscriber = domainParticipant->create_subscriber(SUBSCRIBER_QOS_DEFAULT, NULL, DDS::STATUS_MASK_NONE);
if( subscriber != NULL )
{
typeName = trackTypeSupport.get_type_name();
returnCode = trackTypeSupport.register_type(domainParticipant,typeName);
if( returnCode == DDS::RETCODE_OK )
{
topic = domainParticipant->create_topic("MyTopicName",typeName,TOPIC_QOS_DEFAULT,NULL,DDS::STATUS_MASK_NONE);
if( topic != NULL )
{
dataReader = subscriber->create_datareader(topic,DATAREADER_QOS_DEFAULT,trackListener, DDS::STATUS_MASK_NONE);
}

if( dataReader != NULL )
{
for( int i= 0; i< 10000; i++ )
{
Sleep(1000);
}
}
}
else
{
printf("Error register type\n");
}
}
else
{
printf("Error creating publisher\n");
}
}
else
{
printf("Failed to create_participant\n");
}
}

return 0;
}


#include "stdafx.h"
#include <stdio.h>
#include "ccpp_dds_dcps.h"
#include "ccpp_Test.h"


int _tmain(int argc, _TCHAR* argv[])
{
DDS::DomainId_t domainId = NULL;
DDS::DomainParticipantFactory_ptr domainParticipantFactory = NULL;
DDS::DomainParticipant_ptr domainParticipant = NULL;
DDS::Topic_ptr topic = NULL;
DDS::Publisher_ptr publisher = NULL;
DDS::DataWriter_ptr dataWriter = NULL;

char* typeName = NULL;
DDS::ReturnCode_t returnCode = DDS::RETCODE_OK;

JTCWOSDDS::TrackTypeSupport trackTypeSupport;
JTCWOSDDS::TrackDataWriter_ptr trackDataWriter = NULL;


domainParticipantFactory = DDS::DomainParticipantFactory::get_instance();
if( domainParticipantFactory != NULL )
{
domainParticipant = domainParticipantFactory->create_participant(domainId,PARTICIPANT_QOS_DEFAULT, NULL, DDS::STATUS_MASK_NONE);
if( domainParticipant != NULL )
{
publisher = domainParticipant->create_publisher(PUBLISHER_QOS_DEFAULT, NULL,DDS::STATUS_MASK_NONE);
if( publisher != NULL )
{
typeName = trackTypeSupport.get_type_name();
returnCode = trackTypeSupport.register_type(domainParticipant,typeName);
if( returnCode == DDS::RETCODE_OK )
{
topic = domainParticipant->create_topic("MyTopicName",typeName,TOPIC_QOS_DEFAULT,NULL,DDS::STATUS_MASK_NONE);
dataWriter = publisher->create_datawriter(topic,DATAWRITER_QOS_DEFAULT,NULL,DDS::STATUS_MASK_NONE);

if( dataWriter != NULL )
{
trackDataWriter = JTCWOSDDS::TrackDataWriter::_narrow(dataWriter);
if(trackDataWriter != NULL )
{
for( int i= 0; i< 100000; i++ )
{
JTCWOSDDS::Track* track = new JTCWOSDDS::Track();
track->data = "mydata";
track->uid = "myuid";


if( trackDataWriter->write(*track, DDS::HANDLE_NIL) == DDS::RETCODE_OK )
{
printf("publish success\n");
}
else
{
printf("publish failed\n");
}

Sleep(1000);
}
}
}
}
else
{
printf("Error register type\n");
}
}
else
{
printf("Error creating publisher\n");
}
}
else
{
printf("Failed to create_participant\n");
}
}

return 0;
}

#2 Erik Hendriks

Erik Hendriks

    OpenSplice_DDS Expert

  • Members
  • PipPipPip
  • 57 posts
  • LocationHengelo, Netherlands

Posted 18 November 2010 - 12:33 PM

Hi Anon,

It seems to me like you 'forgot' to tell your DataReaderListener which events it should handle:

dataReader = subscriber->create_datareader(topic,DATAREADER_QOS_DEFAULT,trackListener, DDS::STATUS_MASK_NONE);

The last parameter of the create_datareader call represents a mask containing all statuses that the listener should handle. You passed the special constant STATUS_MASK_NONE here, which indicates that the listener should not handle any of the datareader's statuses: therefore you do net get a callback for the DATA_AVAILABLE_STATUS.

If you would substitute DDS::STATUS_MASK_NONE with DDS::DATA_AVAILABLE_STATUS, you should see that the listener starts to get callbacks to its on_data_available calls. If you want the listener to respond to more statuses, simply add them to you mask by using a logical OR. (e.g. DDS::DATA_AVAILABLE_STATUS | DDS::ON_REQUESTED_INCOMPATIBLE_QOS_STATUS).

Regards,
Erik Hendriks.

#3 anon1234

anon1234

    Member

  • Members
  • PipPip
  • 11 posts

Posted 18 November 2010 - 05:57 PM

Hi Erik,

Thank you for your help. I have modified the create_datareader call to pass in DDS::DATA_AVAILABLE_STATUS as you suggested, however, it's still not working....the moment I start the subscriber executable, it seems to freeze the publisher? Any help would be greatly appreciated.

Thanks.

#4 slewman

slewman

    Advanced Member

  • Members
  • PipPipPip
  • 51 posts

Posted 18 November 2010 - 06:48 PM

anon, i am seeing the same problems. i believe it has something to do with the domainID, it seems there is a bug somewhere that was introduced in 5.3, i have run my code with 5.1, 5.2, and in both cases, it works fine. 5.3 however, as soon as my subscriber exe starts up, i get an error log being created at about 100MB a minute, and the process gets hosed up. refer to this thread where i have been talking to someone about it... i basically have given up, waiting for a new release

http://forums.opensp...g-to-publisher/

#5 anon1234

anon1234

    Member

  • Members
  • PipPip
  • 11 posts

Posted 18 November 2010 - 06:54 PM

I've got it working now. For future reader's sake, earlier I had started opensplice using the command: ospl start file//c:\ospl.sml and modified my publisher & subscriber code to use the domain name from ospl.xml; but that caused by publisher to hang....so to fix things, I set the OSPL_URI environment variable and set the domain name in my publisher/subscriber to NULL (which will cause OpenSplice to get domain name from whatever file is in OSPL_URI)...it worked after that. Thanks for everyone's help.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users