From 406b99737448e45a9884b7fc09d9e8889abdf064 Mon Sep 17 00:00:00 2001 From: TIM ANDERSON Date: Wed, 18 Nov 2026 09:50:01 +1000 Subject: [PATCH] Fix integer granularity in EDS device information MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Import Granularity using the existing integer conversion path instead of reducing nonzero values to a Boolean. This preserves Granularity=8 through both EDS and DCF export. Add integer/missing-field import cases, both export formats, and Boolean-flag controls. Prepared with OpenAI Codex assistance and independent inspection. Timothy Anderson — Spotted Ridge Engineering / OC Labs Independent software verification · GDN (Global Decision Network) timothyanderson096@gmail.com · https://github.com/timothyanderson096-ocdealcheck/gdn-engineering-benchmarks --- canopen/objectdictionary/eds.py | 2 +- test/test_eds.py | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/canopen/objectdictionary/eds.py b/canopen/objectdictionary/eds.py index 608024f3..1be85e7a 100644 --- a/canopen/objectdictionary/eds.py +++ b/canopen/objectdictionary/eds.py @@ -72,7 +72,7 @@ def import_eds(source, node_id): (str, "OrderCode", "order_code"), (bool, "SimpleBootUpMaster", "simple_boot_up_master"), (bool, "SimpleBootUpSlave", "simple_boot_up_slave"), - (bool, "Granularity", "granularity"), + (int, "Granularity", "granularity"), (bool, "DynamicChannelsSupported", "dynamic_channels_supported"), (bool, "GroupMessaging", "group_messaging"), (int, "NrOfRXPDO", "nr_of_RXPDO"), diff --git a/test/test_eds.py b/test/test_eds.py index 4241d1e8..6c243240 100644 --- a/test/test_eds.py +++ b/test/test_eds.py @@ -92,6 +92,40 @@ def test_load_baudrate(self): od = canopen.import_od(SAMPLE_EDS) self.assertEqual(od.bitrate, 500_000) + def test_load_granularity(self): + for raw_value, expected in [("0", 0), ("1", 1), ("8", 8), ("0x08", 8), (None, None)]: + with self.subTest(raw_value=raw_value): + data = "[DeviceInfo]\n" + if raw_value is not None: + data += f"Granularity={raw_value}\n" + with io.StringIO(data) as source: + source.name = "mock.eds" + od = canopen.import_od(source) + self.assertEqual(od.device_information.granularity, expected) + if expected is not None: + self.assertIs(type(od.device_information.granularity), int) + + def test_export_granularity(self): + # The sample declares Granularity=8; exporting must not turn it into 1. + for doc_type in "eds", "dcf": + with self.subTest(doc_type=doc_type): + with io.StringIO() as dest: + canopen.export_od(self.od, dest, doc_type) + eds = RawConfigParser() + eds.read_string(dest.getvalue()) + self.assertEqual(eds.getint("DeviceInfo", "Granularity"), 8) + + def test_load_device_information_boolean_flags(self): + for name, expected in [ + ("simple_boot_up_master", False), + ("simple_boot_up_slave", True), + ("dynamic_channels_supported", False), + ("group_messaging", False), + ("LSS_supported", False), + ]: + with self.subTest(name=name): + self.assertIs(getattr(self.od.device_information, name), expected) + def test_load_baudrate_fallback(self): # Remove the Baudrate option. with open(SAMPLE_EDS) as f: