28 from types import * |
28 from types import * |
29 from time import * |
29 from time import * |
30 import os,re |
30 import os,re |
31 |
31 |
32 # Regular expression for finding index section names |
32 # Regular expression for finding index section names |
33 index_model = re.compile('([0-9A-F]{1,4})') |
33 index_model = re.compile('([0-9A-F]{1,4}$)') |
34 # Regular expression for finding subindex section names |
34 # Regular expression for finding subindex section names |
35 subindex_model = re.compile('([0-9A-F]{1,4})SUB([0-9A-F]{1,2})') |
35 subindex_model = re.compile('([0-9A-F]{1,4})SUB([0-9A-F]{1,2}$)') |
|
36 # Regular expression for finding index section names |
|
37 index_objectlinks_model = re.compile('([0-9A-F]{1,4}OBJECTLINKS$)') |
36 |
38 |
37 # Regular expression for finding NodeXPresent keynames |
39 # Regular expression for finding NodeXPresent keynames |
38 nodepresent_model = re.compile('NODE([0-9]{1,3})PRESENT') |
40 nodepresent_model = re.compile('NODE([0-9]{1,3})PRESENT$') |
39 # Regular expression for finding NodeXName keynames |
41 # Regular expression for finding NodeXName keynames |
40 nodename_model = re.compile('NODE([0-9]{1,3})NAME') |
42 nodename_model = re.compile('NODE([0-9]{1,3})NAME$') |
41 # Regular expression for finding NodeXDCFName keynames |
43 # Regular expression for finding NodeXDCFName keynames |
42 nodedcfname_model = re.compile('NODE([0-9]{1,3})DCFNAME') |
44 nodedcfname_model = re.compile('NODE([0-9]{1,3})DCFNAME$') |
43 |
45 |
44 # Dictionary for quickly translate boolean into integer value |
46 # Dictionary for quickly translate boolean into integer value |
45 BOOL_TRANSLATE = {True : "1", False : "0"} |
47 BOOL_TRANSLATE = {True : "1", False : "0"} |
46 |
48 |
47 # Dictionary for quickly translate eds access value into canfestival access value |
49 # Dictionary for quickly translate eds access value into canfestival access value |
108 |
110 |
109 # List of section names that are not index and subindex and that we can meet in |
111 # List of section names that are not index and subindex and that we can meet in |
110 # an EDS file |
112 # an EDS file |
111 SECTION_KEYNAMES = ["FILEINFO", "DEVICEINFO", "DUMMYUSAGE", "COMMENTS", |
113 SECTION_KEYNAMES = ["FILEINFO", "DEVICEINFO", "DUMMYUSAGE", "COMMENTS", |
112 "MANDATORYOBJECTS", "OPTIONALOBJECTS", "MANUFACTUREROBJECTS", |
114 "MANDATORYOBJECTS", "OPTIONALOBJECTS", "MANUFACTUREROBJECTS", |
113 "STANDARDDATATYPES"] |
115 "STANDARDDATATYPES", "SUPPORTEDMODULES"] |
114 |
116 |
115 |
117 |
116 # Function that extract sections from a file and returns a dictionary of the informations |
118 # Function that extract sections from a file and returns a dictionary of the informations |
117 def ExtractSections(file): |
119 def ExtractSections(file): |
118 return [(blocktuple[0], # EntryName : Assignements dict |
120 return [(blocktuple[0], # EntryName : Assignements dict |
247 values = {} |
249 values = {} |
248 |
250 |
249 # Search if the section name match an index or subindex expression |
251 # Search if the section name match an index or subindex expression |
250 index_result = index_model.match(section_name.upper()) |
252 index_result = index_model.match(section_name.upper()) |
251 subindex_result = subindex_model.match(section_name.upper()) |
253 subindex_result = subindex_model.match(section_name.upper()) |
|
254 index_objectlinks_result = index_objectlinks_model.match(section_name.upper()) |
252 |
255 |
253 # Compilation of the EDS information dictionary |
256 # Compilation of the EDS information dictionary |
254 |
257 |
255 is_entry = False |
258 is_entry = False |
256 # First case, section name is in SECTION_KEYNAMES |
259 # First case, section name is in SECTION_KEYNAMES |
258 # Verify that entry is not already defined |
261 # Verify that entry is not already defined |
259 if section_name.upper() not in eds_dict: |
262 if section_name.upper() not in eds_dict: |
260 eds_dict[section_name.upper()] = values |
263 eds_dict[section_name.upper()] = values |
261 else: |
264 else: |
262 raise SyntaxError, "\"[%s]\" section is defined two times"%section_name |
265 raise SyntaxError, "\"[%s]\" section is defined two times"%section_name |
263 # Second case, section name is a subindex name |
266 # Second case, section name is an index name |
264 elif subindex_result: |
|
265 # Extract index and subindex number |
|
266 index, subindex = [int(value, 16) for value in subindex_result.groups()] |
|
267 # If index hasn't been referenced before, we add an entry into the dictionary |
|
268 # that will be updated later |
|
269 if index not in eds_dict: |
|
270 eds_dict[index] = {"subindexes" : {}} |
|
271 if subindex not in eds_dict[index]["subindexes"]: |
|
272 eds_dict[index]["subindexes"][subindex] = values |
|
273 else: |
|
274 raise SyntaxError, "\"[%s]\" section is defined two times"%section_name |
|
275 is_entry = True |
|
276 # Third case, section name is an index name |
|
277 elif index_result: |
267 elif index_result: |
278 # Extract index number |
268 # Extract index number |
279 index = int(index_result.groups()[0], 16) |
269 index = int(index_result.groups()[0], 16) |
280 # If index hasn't been referenced before, we add an entry into the dictionary |
270 # If index hasn't been referenced before, we add an entry into the dictionary |
281 if index not in eds_dict: |
271 if index not in eds_dict: |
285 values["subindexes"] = eds_dict[index]["subindexes"] |
275 values["subindexes"] = eds_dict[index]["subindexes"] |
286 eds_dict[index] = values |
276 eds_dict[index] = values |
287 else: |
277 else: |
288 raise SyntaxError, "\"[%s]\" section is defined two times"%section_name |
278 raise SyntaxError, "\"[%s]\" section is defined two times"%section_name |
289 is_entry = True |
279 is_entry = True |
|
280 # Third case, section name is a subindex name |
|
281 elif subindex_result: |
|
282 # Extract index and subindex number |
|
283 index, subindex = [int(value, 16) for value in subindex_result.groups()] |
|
284 # If index hasn't been referenced before, we add an entry into the dictionary |
|
285 # that will be updated later |
|
286 if index not in eds_dict: |
|
287 eds_dict[index] = {"subindexes" : {}} |
|
288 if subindex not in eds_dict[index]["subindexes"]: |
|
289 eds_dict[index]["subindexes"][subindex] = values |
|
290 else: |
|
291 raise SyntaxError, "\"[%s]\" section is defined two times"%section_name |
|
292 is_entry = True |
|
293 # Third case, section name is a subindex name |
|
294 elif index_objectlinks_result: |
|
295 pass |
290 # In any other case, there is a syntax problem into EDS file |
296 # In any other case, there is a syntax problem into EDS file |
291 else: |
297 else: |
292 raise SyntaxError, "Section \"[%s]\" is unrecognized"%section_name |
298 raise SyntaxError, "Section \"[%s]\" is unrecognized"%section_name |
293 |
299 |
294 for assignment in assignments: |
300 for assignment in assignments: |
685 elif values["OBJECTTYPE"] in [8, 9]: |
691 elif values["OBJECTTYPE"] in [8, 9]: |
686 # Extract maximum subindex number defined |
692 # Extract maximum subindex number defined |
687 try: |
693 try: |
688 max_subindex = values["subindexes"][0]["DEFAULTVALUE"] |
694 max_subindex = values["subindexes"][0]["DEFAULTVALUE"] |
689 except: |
695 except: |
690 raise SyntaxError, "Error on entry 0x%4.4X:\nSubindex 0 must be defined for an ARRAY entry"%entry |
696 max_subindex = max(*values["subindexes"].keys()) |
|
697 #raise SyntaxError, "Error on entry 0x%4.4X:\nSubindex 0 must be defined for an ARRAY or RECORD entry"%entry |
691 # Add mapping for entry |
698 # Add mapping for entry |
692 Node.AddMappingEntry(entry, name = values["PARAMETERNAME"], struct = 3) |
699 Node.AddMappingEntry(entry, name = values["PARAMETERNAME"], struct = 3) |
693 # Add mapping for first subindex |
700 # Add mapping for first subindex |
694 Node.AddMappingEntry(entry, 0, values = {"name" : "Number of Entries", "type" : 0x05, "access" : "ro", "pdo" : False}) |
701 Node.AddMappingEntry(entry, 0, values = {"name" : "Number of Entries", "type" : 0x05, "access" : "ro", "pdo" : False}) |
695 # Add mapping for other subindexes |
702 # Add mapping for other subindexes |