How Can I Combine two datareader's data into one data

2 posts / 0 new
Last post
Offline
Last seen: 1 year 7 months ago
Joined: 09/01/2022
Posts: 1
How Can I Combine two datareader's data into one data

------ IDL --------------------

@mutable @autoid
struct A{
long x;
};
@mutable @autoid
struct B{
string msg;
};
@mutable @autoid
struct Both{
@optional long x;
@optional string msg;
};

---------------------------------

type struct A 1 Publisher, type struct B 1 Publisher, type struct Both 1 Subscriber

I send A data and B data each Publishers and Receive thier eache datas type struct Both 1 Subscriber. ( Their Topic is same )

Using @mutable annotation, Subscribers can receive A or B data types as Both data types.

But on_data_available event each A, B publisher. Subscribers can only receive A or B data. 

If Subscriber receive A data, B data is NULL. On the contrary, Subscriber receive B data, A data is NULL.

I want to recieve once both A and B data or combine each publisher data.

How Can I do this? 

One more Q.

If I send many topic datas once  every four seconds and subscriber combined received topic datas, Is there any way to distinguish from previously received data?

I did think of two ways.

1. "each topic data has ID value" 

2. "Pub send Topic_Data_Send data => finished sending topic data => send Topic_Data_Send_Fin to Subscriber" 

Howard's picture
Offline
Last seen: 3 hours 16 min ago
Joined: 11/29/2012
Posts: 570

Your scenario that you have a publisher (in DDS this is a DataWriter) of datatype A, a publisher of datatype B and a subscriber (in DDS this is a DataReader) of datatype but both publishers and subscriber use the same topic is not supported in DDS,   It cannot happen.

When you define a DDS Topic, "T" in DDS, it is defined with one datatype "S".  A Topic should not have more than DataType defined.  DDS uses both the Topic Name and Type Name to connect a DataWriter to a DataReader.

A datatype "S" can be quite flexible, so that DataWriters don't have to send all parts of a data structure, for example using @optional members

struct S {

    @optional long x;

    @optional string msg;

};

which will map to a struct

struct S {
    long *x;
    char *msg;
};

 

in code.

Then you can define a topic "T" using "S", and a DataWriter of "T" can write data and only send "x" or only send "msg".  A DataReader of "T" will receive data samples, and if an optional member was not sent, then the pointer for the member will be NULL.

HOWEVER, no, DDS will not merge or otherwise combine the values of different data samples together for you.  If you think about it, this is not easy to define on how to do it.  Your own application will have to wait for the data to arrive and merge the data from multiple data samples into what the application needs.

For your second question:

If I send many topic datas once  every four seconds and subscriber combined received topic datas, Is there any way to distinguish from previously received data?

I don't understand what you mean by "distinguish" from previously received data?  DDS will not give you the same data multiple times (if you are using the DataReader::take() API to access data).

If you are saying that the individual data samples sent by DataWriters need to be grouped together or otherwise correlated, then yes, either you have to use some sort of ID, so that every related data sample has the same ID, or you have to send "cntrl" messages that indicated the beginning of a group of data samples and the end of a group of data samples.