CANopenNode / CANopenEditor

CANopen Object Dictionary Editor
GNU General Public License v3.0
120 stars 60 forks source link

Subobjects without default value won't appear in OD.h/.c #53

Closed HamedJafarzadeh closed 1 year ago

HamedJafarzadeh commented 1 year ago

Hi,

Thanks for all your efforts on this repo.

I just noticed that I couldn't get couple of subobjects of a record to show up in the OD.h and .c, after a debugging for a while I figured that if you have not provided a default value, those subobjects wouldn't appear in the OD files. I believe there should be sort of warning in that case to remind the user about that.

Here is the code line that checks for default value I believe. image

trojanobelix commented 1 year ago

Can not reproduce. Can you provide the xdd and the object index that is missing.

HamedJafarzadeh commented 1 year ago

Here is a sample. Object x2000 does not add subobject 0x02 to the generated files. MissingValuesXdd.zip

trojanobelix commented 1 year ago

Do you expect more than this (from your file)?

.x2000_testrecord = {
        .highestSub_indexSupported = 0x02, <===========
        .testsubwithvalue = 0x00000000
    }

   OD_obj_record_t o_2000_testrecord[3]; <================== SUM(Subs 0,1,2) =3

  .o_2000_testrecord = {
        {
            .dataOrig = &OD_RAM.x2000_testrecord.highestSub_indexSupported,
            .subIndex = 0,
            .attribute = ODA_SDO_R,
            .dataLength = 1
        },
        {
            .dataOrig = &OD_RAM.x2000_testrecord.testsubwithvalue,
            .subIndex = 1,
            .attribute = ODA_SDO_RW | ODA_MB,
            .dataLength = 4
        },
        {
            .dataOrig = NULL,
            .subIndex = 2, <===================
            .attribute = ODA_SDO_RW | ODA_MB,
            .dataLength = 4
        }
    }
HamedJafarzadeh commented 1 year ago

Thanks for your response.

According these sub objects, should we see .testsubwithoutvalue somewhere ? and be able to access it like OD_RAM.testrecord.testsubwithoutvalue ? image

trojanobelix commented 1 year ago

Try bugfix branch c1212916eedb4d906589f499a5de5a03cf865561

HamedJafarzadeh commented 1 year ago

Thanks @trojanobelix . I can confirm that this commit fixes the problem. Although user should note that a variable without default value might have any random values if they use them before assigning a value first.

CANopenNode commented 9 months ago

Sorry, I missed that issue. CANopenNode V4 actually does not require data storage for a variable. Instead application may define own callbacks for reading or writing OD entry. See also https://github.com/CANopenNode/CANopenEditor/issues/73#issuecomment-1805708128