@@ -41,7 +41,7 @@ def import_eds(source, node_id):
4141 od = ObjectDictionary ()
4242
4343 if eds .has_section ("FileInfo" ):
44- od .__edsFileInfo = {
44+ od .__edsFileInfo = { # type: ignore[attr-defined] # custom addition
4545 opt : eds .get ("FileInfo" , opt )
4646 for opt in eds .options ("FileInfo" )
4747 }
@@ -50,7 +50,7 @@ def import_eds(source, node_id):
5050 linecount = int (eds .get ("Comments" , "Lines" ), 0 )
5151 od .comments = '\n ' .join ([
5252 eds .get ("Comments" , f"Line{ line } " )
53- for line in range (1 , linecount + 1 )
53+ for line in range (1 , linecount + 1 )
5454 ])
5555
5656 if not eds .has_section ("DeviceInfo" ):
@@ -129,15 +129,15 @@ def import_eds(source, node_id):
129129 storage_location = None
130130
131131 if object_type in (objectcodes .VAR , objectcodes .DOMAIN ):
132- var = build_variable (eds , section , node_id , index )
132+ var = build_variable (eds , section , node_id , object_type , index )
133133 od .add_object (var )
134134 elif object_type == objectcodes .ARRAY and eds .has_option (section , "CompactSubObj" ):
135135 arr = ODArray (name , index )
136136 last_subindex = ODVariable (
137137 "Number of entries" , index , 0 )
138138 last_subindex .data_type = datatypes .UNSIGNED8
139139 arr .add_member (last_subindex )
140- arr .add_member (build_variable (eds , section , node_id , index , 1 ))
140+ arr .add_member (build_variable (eds , section , node_id , object_type , index , 1 ))
141141 arr .storage_location = storage_location
142142 arr .obj_flags = _get_obj_flags (eds , section )
143143 od .add_object (arr )
@@ -161,7 +161,11 @@ def import_eds(source, node_id):
161161 subindex = int (match .group (2 ), 16 )
162162 entry = od [index ]
163163 if isinstance (entry , (ODRecord , ODArray )):
164- var = build_variable (eds , section , node_id , index , subindex )
164+ try :
165+ object_type = int (eds .get (section , "ObjectType" ), 0 )
166+ except NoOptionError :
167+ object_type = objectcodes .VAR
168+ var = build_variable (eds , section , node_id , object_type , index , subindex )
165169 entry .add_member (var )
166170
167171 # Match [index]Name
@@ -213,7 +217,9 @@ def _calc_bit_length(data_type):
213217 elif data_type == datatypes .INTEGER64 :
214218 return 64
215219 else :
216- raise ValueError (f"Invalid data_type '{ data_type } ', expecting a signed integer data_type." )
220+ raise ValueError (
221+ f"Invalid data_type '{ data_type } ', expecting a signed integer data_type."
222+ )
217223
218224
219225def _signed_int_from_hex (hex_str , bit_length ):
@@ -264,13 +270,23 @@ def _get_obj_flags(eds, section):
264270 return 0
265271
266272
267- def build_variable (eds , section , node_id , index , subindex = 0 ):
268- """Creates a object dictionary entry.
273+ def build_variable (
274+ eds : RawConfigParser ,
275+ section : str ,
276+ node_id : int ,
277+ object_type : int ,
278+ index : int ,
279+ subindex : int = 0
280+ ) -> ODVariable :
281+ """Create a object dictionary entry.
282+
283+
269284 :param eds: String stream of the eds file
270285 :param section:
271286 :param node_id: Node ID
272287 :param index: Index of the CANOpen object
273- :param subindex: Subindex of the CANOpen object (if presente, else 0)
288+ :param subindex: Subindex of the CANOpen object (if present, else 0)
289+ :param is_domain: variable represents a DOMAIN ObjectType (if present, else False)
274290 """
275291 name = eds .get (section , "ParameterName" )
276292 var = ODVariable (name , index , subindex )
@@ -280,15 +296,19 @@ def build_variable(eds, section, node_id, index, subindex=0):
280296 var .storage_location = None
281297 var .data_type = int (eds .get (section , "DataType" ), 0 )
282298 var .access_type = eds .get (section , "AccessType" ).lower ()
299+ var .is_domain = object_type == objectcodes .DOMAIN
283300 if var .data_type > 0x1B :
284- # The object dictionary editor from CANFestival creates an optional object if min max values are used
285- # This optional object is then placed in the eds under the section [A0] (start point, iterates for more)
286- # The eds.get function gives us 0x00A0 now convert to String without hex representation and upper case
287- # The sub2 part is then the section where the type parameter stands
301+ # The object dictionary editor from CANFestival creates an optional object if min max
302+ # values are used. This optional object is then placed in the eds under the section
303+ # [A0] (start point, iterates for more). The eds.get function gives us 0x00A0 now
304+ # convert to String without hex representation and upper case. The sub2 part is then
305+ # the section where the type parameter stands.
288306 try :
289307 var .data_type = int (eds .get (f"{ var .data_type :X} sub1" , "DefaultValue" ), 0 )
290308 except NoSectionError :
291- logger .warning ("%s has an unknown or unsupported data type (0x%X)" , name , var .data_type )
309+ logger .warning (
310+ "%s has an unknown or unsupported data type (0x%X)" , name , var .data_type
311+ )
292312 # Assume DOMAIN to force application to interpret the byte data
293313 var .data_type = datatypes .DOMAIN
294314
@@ -317,16 +337,17 @@ def build_variable(eds, section, node_id, index, subindex=0):
317337 var .default_raw = eds .get (section , "DefaultValue" )
318338 if '$NODEID' in var .default_raw :
319339 var .relative = True
320- var .default = _convert_variable (node_id , var .data_type , eds . get ( section , "DefaultValue" ) )
340+ var .default = _convert_variable (node_id , var .data_type , var . default_raw )
321341 except ValueError :
322342 pass
323343 if eds .has_option (section , "ParameterValue" ):
324344 try :
325345 var .value_raw = eds .get (section , "ParameterValue" )
326- var .value = _convert_variable (node_id , var .data_type , eds . get ( section , "ParameterValue" ) )
346+ var .value = _convert_variable (node_id , var .data_type , var . value_raw )
327347 except ValueError :
328348 pass
329- # Factor, Description and Unit are not standard according to the CANopen specifications, but they are implemented in the python canopen package, so we can at least try to use them
349+ # Factor, Description and Unit are not standard according to the CANopen specifications, but
350+ # they are implemented in the python canopen package, so we can at least try to use them
330351 if eds .has_option (section , "Factor" ):
331352 try :
332353 var .factor = float (eds .get (section , "Factor" ))
@@ -385,7 +406,8 @@ def export_variable(var, eds):
385406 section = f"{ var .index :04X} sub{ var .subindex :X} "
386407
387408 export_common (var , eds , section )
388- eds .set (section , "ObjectType" , f"0x{ objectcodes .VAR :X} " )
409+ object_type = objectcodes .DOMAIN if var .is_domain else objectcodes .VAR
410+ eds .set (section , "ObjectType" , f"0x{ object_type :X} " )
389411 if var .data_type :
390412 eds .set (section , "DataType" , f"0x{ var .data_type :04X} " )
391413 if var .access_type :
0 commit comments