eds: Add first-class support for CiA 306 ObjFlags and Denotation#654
eds: Add first-class support for CiA 306 ObjFlags and Denotation#654bizfsc wants to merge 1 commit intocanopen-python:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
5dff918 to
90dbe07
Compare
ObjFlags (UNSIGNED32 bitfield) and Denotation (DCF-only string) are
standard CiA 306 fields that are now parsed and exported explicitly.
Changes:
* ODVariable, ODRecord and ODArray gain an obj_flags: int = 0 attribute.
* ODVariable gains a denotation: str = '' attribute.
* _get_obj_flags() helper reads and validates the ObjFlags integer value.
* ObjFlags is parsed for VAR/DOMAIN (via build_variable), ARRAY and RECORD.
* ObjFlags is exported whenever non-zero.
* Denotation is read in build_variable() and written only in DCF mode
(device_commisioning=True), matching the CiA 306 specification.
* Adds test object 0x3060 (ObjFlags=0x1) to sample.eds and four new tests
covering read, round-trip and DCF export for both fields.
Co-authored-by: FedericoSpada <FedericoSpada@users.noreply.github.com>
90dbe07 to
bccbd5c
Compare
|
Is this YAGNI? |
|
Frankly, I never heard of it. But now that I have, I had an immediate idea where it could be used in my code, replacing a previous workaround. Some controllers have extra objects for "user variables" which can be utilized in a user-supplied small PLC program on the device. The function of this custom program defines what the variable is really used for (denotation), yet the device manufacturer can only assign a generic name of "user variable 1" in the generic device EDS. That sounds like a perfect application of this less widespread option. The ObjFlags option also seems to solve a problem I've previously worked around by hard-coding objects to skip. I'll have to take a deeper look to really judge if it works like I imagine. And get better acquainted with their definition in CiA 306. |
ObjFlags(UNSIGNED32 bitfield) andDenotation(DCF-only string) are standard CiA 306 fields that were previously silently dropped. This PR adds first-class support for both.Changes
ODVariable,ODRecordandODArraygain anobj_flags: int = 0attribute.ODVariablegains adenotation: str = ""attribute._get_obj_flags(eds, section)helper reads and validates theObjFlagsinteger value.ObjFlagsis parsed for VAR/DOMAIN (viabuild_variable()), ARRAY and RECORD top-level objects.ObjFlagsis exported whenever non-zero.Denotationis read inbuild_variable()and written only in DCF mode (device_commisioning=True), matching the CiA 306 specification.Tests
test_reading_obj_flags— VAR withObjFlags=0x1reads back correctlytest_reading_obj_flags_default— standard objects default to0test_roundtrip_obj_flags— full EDS export/import cycle preservesobj_flagstest_denotation_roundtrip_dcf—denotationsurvives a DCF round-triptest_denotation_not_exported_in_eds_mode—denotationis absent in plain EDS export