@@ -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 od .add_object (arr )
143143 elif object_type == objectcodes .ARRAY :
@@ -158,7 +158,11 @@ def import_eds(source, node_id):
158158 subindex = int (match .group (2 ), 16 )
159159 entry = od [index ]
160160 if isinstance (entry , (ODRecord , ODArray )):
161- var = build_variable (eds , section , node_id , index , subindex )
161+ try :
162+ object_type = int (eds .get (section , "ObjectType" ), 0 )
163+ except NoOptionError :
164+ object_type = objectcodes .VAR
165+ var = build_variable (eds , section , node_id , object_type , index , subindex )
162166 entry .add_member (var )
163167
164168 # Match [index]Name
@@ -210,7 +214,9 @@ def _calc_bit_length(data_type):
210214 elif data_type == datatypes .INTEGER64 :
211215 return 64
212216 else :
213- raise ValueError (f"Invalid data_type '{ data_type } ', expecting a signed integer data_type." )
217+ raise ValueError (
218+ f"Invalid data_type '{ data_type } ', expecting a signed integer data_type."
219+ )
214220
215221
216222def _signed_int_from_hex (hex_str , bit_length ):
@@ -252,13 +258,22 @@ def _revert_variable(var_type, value):
252258 return f"0x{ value :02X} "
253259
254260
255- def build_variable (eds , section , node_id , index , subindex = 0 ):
256- """Creates a object dictionary entry.
261+ def build_variable (
262+ eds : RawConfigParser ,
263+ section : str ,
264+ node_id : int ,
265+ object_type : int ,
266+ index : int ,
267+ subindex : int = 0
268+ ) -> ODVariable :
269+ """Create a object dictionary entry.
270+
257271 :param eds: String stream of the eds file
258272 :param section:
259273 :param node_id: Node ID
260274 :param index: Index of the CANOpen object
261- :param subindex: Subindex of the CANOpen object (if presente, else 0)
275+ :param subindex: Subindex of the CANOpen object (if present, else 0)
276+ :param is_domain: variable represents a DOMAIN ObjectType (if present, else False)
262277 """
263278 name = eds .get (section , "ParameterName" )
264279 var = ODVariable (name , index , subindex )
@@ -268,15 +283,19 @@ def build_variable(eds, section, node_id, index, subindex=0):
268283 var .storage_location = None
269284 var .data_type = int (eds .get (section , "DataType" ), 0 )
270285 var .access_type = eds .get (section , "AccessType" ).lower ()
286+ var .is_domain = object_type == objectcodes .DOMAIN
271287 if var .data_type > 0x1B :
272- # The object dictionary editor from CANFestival creates an optional object if min max values are used
273- # This optional object is then placed in the eds under the section [A0] (start point, iterates for more)
274- # The eds.get function gives us 0x00A0 now convert to String without hex representation and upper case
275- # The sub2 part is then the section where the type parameter stands
288+ # The object dictionary editor from CANFestival creates an optional object if min max
289+ # values are used. This optional object is then placed in the eds under the section
290+ # [A0] (start point, iterates for more). The eds.get function gives us 0x00A0 now
291+ # convert to String without hex representation and upper case. The sub2 part is then
292+ # the section where the type parameter stands.
276293 try :
277294 var .data_type = int (eds .get (f"{ var .data_type :X} sub1" , "DefaultValue" ), 0 )
278295 except NoSectionError :
279- logger .warning ("%s has an unknown or unsupported data type (0x%X)" , name , var .data_type )
296+ logger .warning (
297+ "%s has an unknown or unsupported data type (0x%X)" , name , var .data_type
298+ )
280299 # Assume DOMAIN to force application to interpret the byte data
281300 var .data_type = datatypes .DOMAIN
282301
@@ -305,16 +324,17 @@ def build_variable(eds, section, node_id, index, subindex=0):
305324 var .default_raw = eds .get (section , "DefaultValue" )
306325 if '$NODEID' in var .default_raw :
307326 var .relative = True
308- var .default = _convert_variable (node_id , var .data_type , eds . get ( section , "DefaultValue" ) )
327+ var .default = _convert_variable (node_id , var .data_type , var . default_raw )
309328 except ValueError :
310329 pass
311330 if eds .has_option (section , "ParameterValue" ):
312331 try :
313332 var .value_raw = eds .get (section , "ParameterValue" )
314- var .value = _convert_variable (node_id , var .data_type , eds . get ( section , "ParameterValue" ) )
333+ var .value = _convert_variable (node_id , var .data_type , var . value_raw )
315334 except ValueError :
316335 pass
317- # 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
336+ # Factor, Description and Unit are not standard according to the CANopen specifications, but
337+ # they are implemented in the python canopen package, so we can at least try to use them
318338 if eds .has_option (section , "Factor" ):
319339 try :
320340 var .factor = float (eds .get (section , "Factor" ))
@@ -370,7 +390,8 @@ def export_variable(var, eds):
370390 section = f"{ var .index :04X} sub{ var .subindex :X} "
371391
372392 export_common (var , eds , section )
373- eds .set (section , "ObjectType" , f"0x{ objectcodes .VAR :X} " )
393+ object_type = objectcodes .DOMAIN if var .is_domain else objectcodes .VAR
394+ eds .set (section , "ObjectType" , f"0x{ object_type :X} " )
374395 if var .data_type :
375396 eds .set (section , "DataType" , f"0x{ var .data_type :04X} " )
376397 if var .access_type :
0 commit comments