Validate data in on_data_on_readers

2 posts / 0 new
Last post
Offline
Last seen: 7 years 11 months ago
Joined: 11/28/2015
Posts: 8
Validate data in on_data_on_readers

Hi,

Take for example following is the idl:

typedef UINT_8 MFC_INDEX_IRS;

// THIS DATA ELEMENT TELLS ABOUT THE DESTINATION CSCI.
//## type CSCI_ID_IRS
typedef UINT_8 CSCI_ID_IRS;
//## type STRUCT_MSG_HEADER_TYPE
struct STRUCT_MSG_HEADER_TYPE {
    MFC_INDEX_IRS mfc_index;        //## attribute mfc_index
    CSCI_ID_IRS source_id;        //## attribute source_id
};

//## type PPI_RANGE_SCALE_IRS
typedef INT_8 PPI_RANGE_SCALE_IRS;

struct RANGE_SCALE_STRUCT {
    ////    Attributes    ////
     
    STRUCT_MSG_HEADER_TYPE struct_msg_header;        //## attribute struct_msg_header
     
    PPI_RANGE_SCALE_IRS range_scale;        //## attribute range_scale
};

//## type DMFC_STATE_ENUM
enum DMFC_STATE_ENUM {
    MFC_OFF,
    MAINTENANCE,
    COMBAT,
    SIMULATE,
    SIMULATOR,
    NOT_APPLICABLE
};

struct DMFC_STATE_STRUCT {
    ////    Attributes    ////
     
    STRUCT_MSG_HEADER_TYPE struct_msg_header;        //## attribute struct_msg_header
     
    // @key        //
    ONEB_NUMBER_IRS dmfc_id; //@key        //## attribute dmfc_id
     
    DMFC_STATE_ENUM dmfc_state;        //## attribute dmfc_state
};

Here I've mentioned only 2 topics but in my application there are around 100 topics.

Following is on_data_on_readers(DDSSubscriber *sub) method which I am using in my Qt application to handle topics like DMFC_STATE_TOPIC or RANGE_SCALE_TOPIC or any other topic:

class MMITopic
{
public:
    QString topicName;
    QString typeName;
    DDS_ReturnCode_t (*register_func)(DDSDomainParticipant *, const char *);
    const DDS_TypeCode *typeCode;
    DDSDataWriter *writer;
    DDSDataReader *reader;
    std::vector <void (*)(void *)> processingFuncList;
    DDS_DynamicDataSeq dynamicSampleDataSeq;
    DDS_SampleInfoSeq sampleInfoSeq;
    bool lock_flag;
    MMITopic():topicName(""),typeName(""), reader(NULL),writer(NULL),lock_flag(false){}
};

void MMIListener::on_data_on_readers(DDSSubscriber *sub)
{
    QString topicName;
    DDSDataReaderSeq dataReaderSeq;
    sub->get_datareaders(dataReaderSeq,DDS_NOT_READ_SAMPLE_STATE,DDS_ANY_VIEW_STATE,DDS_ALIVE_INSTANCE_STATE);

    for(quint16 a=0;a<dataReaderSeq.length();a++)
    {
        topicName = QString(dataReaderSeq[a]->get_topicdescription()->get_name());
        qDebug()<<"New topic recv on "<<topicName;
        MMITopic *topic = ddsManagerPtr->getMMITopic(topicName);

        if(topic!=NULL && topic->lock_flag == false)
        {
            DDSDynamicDataReader *dynamicDataReader = (DDSDynamicDataReader *)dataReaderSeq[a];

            dynamicDataReader->read(topic->dynamicSampleDataSeq,topic->sampleInfoSeq,DDS_LENGTH_UNLIMITED,DDS_NOT_READ_SAMPLE_STATE,DDS_ANY_VIEW_STATE,DDS_ALIVE_INSTANCE_STATE);



            topic->lock_flag=1;
            if(topic->dynamicSampleDataSeq.length()>0)
            {
                int i=0;
                for(;i<topic->dynamicSampleDataSeq.length();i++)
                      emit newSampleRead(topicName,(void *)&topic->dynamicSampleDataSeq.get_at(i),false,topic->sampleInfoSeq.get_at(i).valid_data);


                return;
            }
            else
                qDebug()<<"DDSManager:200000:Notification"<<"Length is less then zero";

            dynamicDataReader->return_loan(topic->dynamicSampleDataSeq,topic->sampleInfoSeq);
            topic->lock_flag = 0;
        }
        else
            qDebug()<<"DDSManager::Notification"<<"topic " <<topicName<<" not processed "<<(topic==NULL? "TOPIC IS NULL": "")<<(topic->lock_flag ? "TOPIC IS LOCKED":"");
    }
}

I am maintaining hash with key as (topic name) and value as (MMITopic *).
I want to emit newSampleRead(QString topicName,void *data,bool freeUpFlag,bool dataValidFlag) signal only if struct_msg_header.mfc_index is equal to 1 . How can I get STRUCT_MSG_HEADER_TYPE from the received dynamic data sequence. How can I validate the contents of STRUCT_MSG_HEADER_TYPE before emitting the signal.

Thanks

Gerardo Pardo's picture
Offline
Last seen: 4 weeks 12 hours ago
Joined: 06/02/2010
Posts: 601

Hi,

If I understood correctly your question boils down to accessing members in nested structures using the DynamicData API.  Is this right?

If so then you can take a look at this example that illustrates how it is done:  https://community.rti.com/examples/dynamic-data-nested-structures

Gerardo