Hi,
This is my first attempt in using rtiddsgen to generate code by using IDL as input file.
I had attached my IDL file here, but not sure whether i had typed correctly in terms of syntax.
Im still confused about setting key to datatype after reading the knowledge base.
Portion of the auto-generated code:
static DDS_TypeCode_Member Hums_PBit_Info_T_g_tc_members[4]= { { (char *)"resourceId",/* Member name */ { 0,/* Representation ID */ DDS_BOOLEAN_FALSE,/* Is a pointer? */ -1, /* Bitfield bits */ NULL/* Member type code is assigned later */ }, 0, /* Ignored */ 0, /* Ignored */ 0, /* Ignored */ NULL, /* Ignored */ RTI_CDR_KEY_MEMBER, /* Member flags */ DDS_PRIVATE_MEMBER,/* Ignored */ 1, NULL/* Ignored */ };
............
resourceId should be IdentifierType_T datatype as stated in my IDL file, but code stated char *
Appreciate if someone can enlighten me.
Attachment | Size |
---|---|
sample.idl | 2.03 KB |
Hi Jeslene,
The IDL is correct as far as syntax. The resourceId is indeed a
IdentifierType_T
datatype as you said. This can be seen in the generated header filesample.h
(see below).// This appears in the sample.h file:
The code you referenced from the sample.c file:
Is used con construct a runtime description of the type used for internal purposes. You do not need to be concerned by that syntax. It is not intended for you to use it directly. If you are curious what is saying there is that there is a member with name "resourceId" that has a number of properties among which the fact that it is a "key" member... But you should ignore this syntax and just look at the declaration itself in the file sample.h
Inspecting the rest of the IDL file I did find a couple things that seemed unnecessay or perhaps even undesirable.
1) The combination of a
typedef
andstruct
declaration is not needed in IDL. Therefore the IDL declaration:Can be replaced with the simpler one:
The C/C++ code generation from this latter version will already define both the type
VsiTime_T
as well as the typestruct VsiTime_T
. So the more complex IDL syntax of the top variation is not needed and may not work on other IDL compilers.2) The inclusion of the members with type
VsiTime_T
as part of the "key" for the corresponding type seems odd to me. For example you have defined the following two types:I understand that the
IdentifierType_T
would form part of the key as this looks like the kind of member that would uniquely identify a data source or some specific object in your system. However theVsiTime_T
is a timestamp so it would seem like it represents a snapshot of the value of the object. Since this it identifies a particular sample (value at a point in time) but nor the object itself it does not (generally) make sense to make it part of the key. Thus it would seem more natural to define the type as:3) It seems odd that the types
Hums_PBit_Info_T
,Hums_Bit_Info_T
andIBit_Info_T
are all identical. From the comments it looks like you want these to be Topics. Note that it is OK to have multiple Topic names with the same data-type...Just like on a programming language you can have multiple variables of the same data type, in DDS you can have multiple Topics (and multiple DataWriters and DataReaders) of the same data type. Since the Topic is different these will still be kept independent. Reusing the type saves a lot of code generation and generally also makes the code more reusable and simpler to maintain. The reasoning for this is explained in the best practice named Don't force Topic names to be the same as Type names.
-Gerardo
Hi Gerado,
Your explanation is great, i have a better understanding now. I had managed to write simple publishing and subscribing codes based on the sample.idl. It works perfectly. Thanks a lot.
Thanks & Regards,
Jeslene
Hi Gerado,
I got another question here:
I created nested structures in .IDL with 2 topic names Hums_PBit_Info_T & Hums_Parameter_Info_T
After writing publishing codes as below, my subscription software can receive the data. And from admin console, i can see the datatype of topic Hums_Parameter_Info_T.
However, if i change the code to use topic Hums_PBit_Info_T, my subscribing software is not receiving any data and at admin console i cannot see any datatype of topic Hums_PBit_Info_T.
I understand that i can have multiple writers in 1 publisher and multiple readers in 1 subscriber (which i already coded). Im just doing a quick code change and check as the prior is also not reading my Hums_PBit_Info_T too.
I had spent hours on it but cannot find what i did wrong.
Thanks & Regards,
Jeslene
Hi Gerado,
By the way, my publishing codes as follows:
..........
Thanks & Regards,
Jeslene
Hi Jeslene,
I suspect you made an error when you changed the type from Hums_Parameter_Info_T to Hums_PBit_Info_T. Perhaps on one of the two sides (publish or subscribe) you did not change the
Topic
name passed to thecreate_topic()
call. Of the type name passed to theregister_type()
call.If you run AdminConsole anf open the "Match Graph" you should be able to see the Topic names and types being published and subscribed and troubleshoot why they do not match.
I tested your IDL and the change from
Hums_Parameter_Info_T
toHums_PBit_Info_T
. I was able to change the type and see the new applications communicate as expected. I have uploaded a ZIP file to the FileExchange with a C# example that modifies what rtiddsgen created from your IDL. You can download it from here: https://community.rti.com/filedepot?cid=1&fid=34. In the comments you can see what I changed) and these work as expected. take a look at them and maybe it can help you find what you missed...On a different subject. This discussion is more appropriate for the dds community forums instead of the HOWTOs. The HOWTOs were intended for posting informal worked-out recipes/solutions to common problems/challenges... Because of this some posting features are limited (e.g. uploading files). Also the interface is not as well suited to having a dialog... Putting it in the forum will also help other members of the community find it. I have asked the RTI community admins to move this discussion from the HOWTO to the forums. Hopefully no information will be lost. I wanted to let you know so you are not susprised by the change.
Regards,
Gerardo
Update: On November 5, 2015 this discussion was moved from the HOWTO to the Technical forum.
Hi Gerado,
Thanks for the code. I know where i made the mistake.
Noted on your comments on where i should post my queries. Sorry for the trouble.
No worries :) I am glad you figured it all out!!
Gerardo