00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 import node
00026 from node import nosub, var, array, rec, plurivar, pluriarray, plurirec
00027 from sets import *
00028 from types import *
00029 from time import *
00030 import os,re
00031
00032
00033 index_model = re.compile('([0-9A-F]{1,4})')
00034
00035 subindex_model = re.compile('([0-9A-F]{1,4})SUB([0-9A-F]{1,2})')
00036
00037
00038 nodepresent_model = re.compile('NODE([0-9]{1,3})PRESENT')
00039
00040 nodename_model = re.compile('NODE([0-9]{1,3})NAME')
00041
00042 nodedcfname_model = re.compile('NODE([0-9]{1,3})DCFNAME')
00043
00044
00045 BOOL_TRANSLATE = {True : "1", False : "0"}
00046
00047
00048 ACCESS_TRANSLATE = {"ro" : "ro", "wo" : "wo", "rw" : "rw", "rwr" : "rw", "rww" : "rw", "const" : "ro"}
00049
00050
00051 is_integer = lambda x: type(x) in (IntType, LongType)
00052 is_string = lambda x: type(x) in (StringType, UnicodeType)
00053 is_boolean = lambda x: x in (0, 1)
00054
00055
00056 ENTRY_ATTRIBUTES = {"SUBNUMBER" : is_integer, "PARAMETERNAME" : is_string,
00057 "OBJECTTYPE" : lambda x: x in (7, 8, 9), "DATATYPE" : is_integer,
00058 "LOWLIMIT" : is_integer, "HIGHLIMIT" : is_integer,
00059 "ACCESSTYPE" : lambda x: x in ["ro","wo", "rw", "rwr", "rww", "const"],
00060 "DEFAULTVALUE" : lambda x: True, "PDOMAPPING" : is_boolean,
00061 "OBJFLAGS" : is_integer}
00062
00063
00064 ENTRY_TYPES = {7 : {"name" : " VAR",
00065 "require" : ["PARAMETERNAME", "OBJECTTYPE", "DATATYPE", "ACCESSTYPE", "PDOMAPPING"],
00066 "optional" : ["LOWLIMIT", "HIGHLIMIT", "DEFAULTVALUE", "OBJFLAGS"]},
00067 8 : {"name" : "n ARRAY",
00068 "require" : ["SUBNUMBER", "PARAMETERNAME", "OBJECTTYPE"],
00069 "optional" : ["OBJFLAGS"]},
00070 9 : {"name" : " RECORD",
00071 "require" : ["SUBNUMBER", "PARAMETERNAME", "OBJECTTYPE"],
00072 "optional" : ["OBJFLAGS"]}}
00073
00074
00075
00076
00077 def GetDefaultValue(index, subIndex = None):
00078 infos = Node.GetEntryInfos(index)
00079 if infos["struct"] & node.OD_MultipleSubindexes:
00080
00081 if infos["struct"] & node.OD_IdenticalSubindexes:
00082 subentry_infos = Node.GetSubentryInfos(index, 1)
00083
00084 else:
00085 subentry_infos = Node.GetSubentryInfos(index, subIndex)
00086
00087 if "default" in subentry_infos:
00088 return subentry_infos["default"]
00089
00090 else:
00091 return Node.GetTypeDefaultValue(subentry_infos["type"])
00092
00093 else:
00094 subentry_infos = Node.GetSubentryInfos(index, 0)
00095
00096 if "default" in subentry_infos:
00097 return subentry_infos["default"]
00098
00099 else:
00100 return Node.GetTypeDefaultValue(subentry_infos["type"])
00101 return None
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 SECTION_KEYNAMES = ["FILEINFO", "DEVICEINFO", "DUMMYUSAGE", "COMMENTS",
00112 "MANDATORYOBJECTS", "OPTIONALOBJECTS", "MANUFACTUREROBJECTS"]
00113
00114
00115
00116 def ExtractSections(file):
00117 return [(blocktuple[0],
00118 blocktuple[-1].splitlines())
00119 for blocktuple in [
00120 block.split("]")
00121 for block in
00122 file.split("[")]
00123 if blocktuple[0].isalnum()]
00124
00125
00126
00127 def ParseCPJFile(filepath):
00128 networks = []
00129
00130 cpj_file = open(filepath,'r').read()
00131 sections = ExtractSections(cpj_file)
00132
00133 for section_name, assignments in sections:
00134
00135
00136 if section_name.upper() in "TOPOLOGY":
00137
00138
00139 topology = {"Name" : "", "Nodes" : {}}
00140
00141 for assignment in assignments:
00142
00143 if assignment.startswith(";"):
00144 pass
00145
00146 elif assignment.find('=') > 0:
00147
00148
00149 try:
00150 keyname, value = assignment.split("=")
00151 except:
00152 raise SyntaxError, "\"%s\" is not a valid EDS line"%assignment.strip()
00153
00154
00155
00156 if keyname.isalnum():
00157
00158 value = value.strip()
00159
00160
00161 if value.startswith("0x"):
00162 try:
00163 computed_value = int(value, 16)
00164 except:
00165 raise SyntaxError, "\"%s\" is not a valid value for attribute \"%s\" of section \"[%s]\""%(value, keyname, section_name)
00166 elif value.isdigit():
00167
00168 if value.startswith("0"):
00169 computed_value = int(value, 8)
00170
00171 else:
00172 computed_value = int(value)
00173
00174 else:
00175 computed_value = value
00176
00177
00178 nodepresent_result = nodepresent_model.match(keyname.upper())
00179 nodename_result = nodename_model.match(keyname.upper())
00180 nodedcfname_result = nodedcfname_model.match(keyname.upper())
00181
00182 if keyname.upper() == "NETNAME":
00183 if not is_string(computed_value):
00184 raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name)
00185 topology["Name"] = computed_value
00186 elif keyname.upper() == "NODES":
00187 if not is_integer(computed_value):
00188 raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name)
00189 topology["Number"] = computed_value
00190 elif keyname.upper() == "EDSBASENAME":
00191 if not is_string(computed_value):
00192 raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name)
00193 topology["Path"] = computed_value
00194 elif nodepresent_result:
00195 if not is_boolean(computed_value):
00196 raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name)
00197 nodeid = int(nodepresent_result.groups()[0])
00198 if nodeid not in topology["Nodes"].keys():
00199 topology["Nodes"][nodeid] = {}
00200 topology["Nodes"][nodeid]["Present"] = computed_value
00201 elif nodename_result:
00202 if not is_string(value):
00203 raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name)
00204 nodeid = int(nodename_result.groups()[0])
00205 if nodeid not in topology["Nodes"].keys():
00206 topology["Nodes"][nodeid] = {}
00207 topology["Nodes"][nodeid]["Name"] = computed_value
00208 elif nodedcfname_result:
00209 if not is_string(computed_value):
00210 raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name)
00211 nodeid = int(nodedcfname_result.groups()[0])
00212 if nodeid not in topology["Nodes"].keys():
00213 topology["Nodes"][nodeid] = {}
00214 topology["Nodes"][nodeid]["DCFName"] = computed_value
00215 else:
00216 raise SyntaxError, "Keyname \"%s\" not recognised for section \"[%s]\""%(keyname, section_name)
00217
00218
00219 elif assignment.strip() != "":
00220 raise SyntaxError, "\"%s\" is not a valid CPJ line"%assignment.strip()
00221
00222 if "Number" not in topology.keys():
00223 raise SyntaxError, "\"Nodes\" keyname in \"[%s]\" section is missing"%section_name
00224
00225 if topology["Number"] != len(topology["Nodes"]):
00226 raise SyntaxError, "\"Nodes\" value not corresponding to number of nodes defined"
00227
00228 for nodeid, node in topology["Nodes"].items():
00229 if "Present" not in node.keys():
00230 raise SyntaxError, "\"Node%dPresent\" keyname in \"[%s]\" section is missing"%(nodeid, section_name)
00231
00232 networks.append(topology)
00233
00234
00235 else:
00236 raise SyntaxError, "Section \"[%s]\" is unrecognized"%section_name
00237
00238 return networks
00239
00240
00241 def ParseEDSFile(filepath):
00242 eds_dict = {}
00243
00244 eds_file = open(filepath,'r').read()
00245 sections = ExtractSections(eds_file)
00246
00247
00248 for section_name, assignments in sections:
00249
00250 values = {}
00251
00252
00253 index_result = index_model.match(section_name.upper())
00254 subindex_result = subindex_model.match(section_name.upper())
00255
00256
00257
00258 is_entry = False
00259
00260 if section_name.upper() in SECTION_KEYNAMES:
00261
00262 if section_name.upper() not in eds_dict:
00263 eds_dict[section_name.upper()] = values
00264 else:
00265 raise SyntaxError, "\"[%s]\" section is defined two times"%section_name
00266
00267 elif subindex_result:
00268
00269 index, subindex = [int(value, 16) for value in subindex_result.groups()]
00270
00271
00272 if index not in eds_dict:
00273 eds_dict[index] = {"subindexes" : {}}
00274 if subindex not in eds_dict[index]["subindexes"]:
00275 eds_dict[index]["subindexes"][subindex] = values
00276 else:
00277 raise SyntaxError, "\"[%s]\" section is defined two times"%section_name
00278 is_entry = True
00279
00280 elif index_result:
00281
00282 index = int(index_result.groups()[0], 16)
00283
00284 if index not in eds_dict:
00285 eds_dict[index] = values
00286 eds_dict[index]["subindexes"] = {}
00287 elif eds_dict[index].keys() == ["subindexes"]:
00288 values["subindexes"] = eds_dict[index]["subindexes"]
00289 eds_dict[index] = values
00290 else:
00291 raise SyntaxError, "\"[%s]\" section is defined two times"%section_name
00292 is_entry = True
00293
00294 else:
00295 raise SyntaxError, "Section \"[%s]\" is unrecognized"%section_name
00296
00297 for assignment in assignments:
00298
00299 if assignment.startswith(";"):
00300 pass
00301
00302 elif assignment.find('=') > 0:
00303
00304
00305 try:
00306 keyname, value = assignment.split("=")
00307 except:
00308 raise SyntaxError, "\"%s\" is not a valid EDS line"%assignment.strip()
00309
00310
00311 if keyname.isalnum():
00312
00313 value = value.strip()
00314
00315 if value.startswith("$NODEID"):
00316 try:
00317 test = int(value.replace("$NODEID+", ""), 16)
00318 computed_value = value.replace("$NODEID", "self.ID")
00319 except:
00320 raise SyntaxError, "\"%s\" is not a valid formula for attribute \"%s\" of section \"[%s]\""%(value, keyname, section_name)
00321
00322 elif value.startswith("0x"):
00323 try:
00324 computed_value = int(value, 16)
00325 except:
00326 raise SyntaxError, "\"%s\" is not a valid value for attribute \"%s\" of section \"[%s]\""%(value, keyname, section_name)
00327 elif value.isdigit():
00328
00329 if value.startswith("0"):
00330 computed_value = int(value, 8)
00331
00332 else:
00333 computed_value = int(value)
00334
00335 else:
00336 computed_value = value
00337
00338
00339 if computed_value != "":
00340
00341 if is_entry:
00342
00343 if keyname.upper() not in ENTRY_ATTRIBUTES:
00344 raise SyntaxError, "Keyname \"%s\" not recognised for section \"[%s]\""%(keyname, section_name)
00345
00346 elif not ENTRY_ATTRIBUTES[keyname.upper()](computed_value):
00347 raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name)
00348 else:
00349 values[keyname.upper()] = computed_value
00350 else:
00351 values[keyname.upper()] = computed_value
00352
00353 elif assignment.strip() != "":
00354 raise SyntaxError, "\"%s\" is not a valid EDS line"%assignment.strip()
00355
00356
00357 if is_entry:
00358
00359 if "OBJECTTYPE" in values.keys():
00360
00361 objecttype = values["OBJECTTYPE"]
00362
00363 keys = Set(values.keys())
00364 keys.discard("subindexes")
00365
00366 possible = Set(ENTRY_TYPES[objecttype]["require"] + ENTRY_TYPES[objecttype]["optional"])
00367 required = Set(ENTRY_TYPES[objecttype]["require"])
00368
00369 if not keys.issuperset(required):
00370 missing = required.difference(keys)._data.keys()
00371 if len(missing) > 1:
00372 attributes = "Attributes %s are"%", ".join(["\"%s\""%attribute for attribute in missing])
00373 else:
00374 attributes = "Attribute \"%s\" is"%missing[0]
00375 raise SyntaxError, "Error on section \"[%s]\":\n%s required for a%s entry"%(section_name, attributes, ENTRY_TYPES[objecttype]["name"])
00376
00377 if not keys.issubset(possible):
00378 unsupported = keys.difference(possible)._data.keys()
00379 if len(unsupported) > 1:
00380 attributes = "Attributes %s are"%", ".join(["\"%s\""%attribute for attribute in unsupported])
00381 else:
00382 attributes = "Attribute \"%s\" is"%unsupported[0]
00383 raise SyntaxError, "Error on section \"[%s]\":\n%s unsupported for a%s entry"%(section_name, attributes, ENTRY_TYPES[objecttype]["name"])
00384 else:
00385 raise SyntaxError, "Error on section \"[%s]\":\nAttribute OBJECTTYPE is required"%section_name
00386
00387 return eds_dict
00388
00389
00390
00391 def WriteFile(filepath, content):
00392
00393 cfile = open(filepath,"w")
00394
00395 cfile.write(content)
00396
00397 cfile.close()
00398
00399
00400
00401 def GenerateFileContent(filepath):
00402
00403 indexContents = {}
00404
00405
00406 current_time = localtime()
00407
00408 nodename, nodeid, nodetype, description = Manager.GetCurrentNodeInfos()
00409
00410
00411 entries = [idx for name, idx in Manager.GetCurrentValidIndexes(0, 0xFFFF)]
00412
00413
00414 fileContent = "[FileInfo]\n"
00415 fileContent += "CreatedBy=CANFestival\n"
00416 fileContent += "Description=%s\n"%description
00417 fileContent += "CreationTime=%s"%strftime("%I:%M", current_time)
00418
00419 if strftime("%I", current_time) == strftime("%H", current_time):
00420 fileContent += "AM\n"
00421 else:
00422 fileContent += "PM\n"
00423 fileContent += "CreationDate=%s\n"%strftime("%m-%d-%Y", current_time)
00424 fileContent += "FileName=%s\n"%os.path.split(filepath)[-1]
00425 fileContent += "FileVersion=1\n"
00426 fileContent += "FileRevision=1\n"
00427 fileContent += "EDSVersion=3.0\n"
00428
00429
00430 fileContent += "\n[DeviceInfo]\n"
00431 fileContent += "VendorName=CANFestival\n"
00432
00433 fileContent += "VendorNumber=0x%8.8X\n"%Manager.GetCurrentEntry(0x1018, 1)
00434 fileContent += "ProductName=%s\n"%nodename
00435 fileContent += "ProductNumber=0x%8.8X\n"%Manager.GetCurrentEntry(0x1018, 2)
00436 fileContent += "RevisionNumber=0x%8.8X\n"%Manager.GetCurrentEntry(0x1018, 3)
00437
00438 fileContent += "BaudRate_10=1\n"
00439 fileContent += "BaudRate_20=1\n"
00440 fileContent += "BaudRate_50=1\n"
00441 fileContent += "BaudRate_125=1\n"
00442 fileContent += "BaudRate_250=1\n"
00443 fileContent += "BaudRate_500=1\n"
00444 fileContent += "BaudRate_800=1\n"
00445 fileContent += "BaudRate_1000=1\n"
00446
00447 fileContent += "SimpleBootUpMaster=%s\n"%BOOL_TRANSLATE[nodetype == "master"]
00448 fileContent += "SimpleBootUpSlave=%s\n"%BOOL_TRANSLATE[nodetype == "slave"]
00449
00450 fileContent += "Granularity=8\n"
00451 fileContent += "DynamicChannelsSupported=0\n"
00452 fileContent += "CompactPDO=0\n"
00453 fileContent += "GroupMessaging=0\n"
00454
00455 fileContent += "NrOfRXPDO=%d\n"%len([idx for idx in entries if 0x1400 <= idx <= 0x15FF])
00456 fileContent += "NrOfTXPDO=%d\n"%len([idx for idx in entries if 0x1800 <= idx <= 0x19FF])
00457
00458 fileContent += "LSS_Supported=0\n"
00459
00460
00461 fileContent += "\n[DummyUsage]\n"
00462 fileContent += "Dummy0001=0\n"
00463 fileContent += "Dummy0002=1\n"
00464 fileContent += "Dummy0003=1\n"
00465 fileContent += "Dummy0004=1\n"
00466 fileContent += "Dummy0005=1\n"
00467 fileContent += "Dummy0006=1\n"
00468 fileContent += "Dummy0007=1\n"
00469
00470
00471 fileContent += "\n[Comments]\n"
00472 fileContent += "Lines=0\n"
00473
00474
00475 mandatories = []
00476 optionals = []
00477 manufacturers = []
00478
00479
00480 for entry in entries:
00481
00482 entry_infos = Manager.GetEntryInfos(entry)
00483 values = Manager.GetCurrentEntry(entry)
00484
00485 text = "\n[%X]\n"%entry
00486
00487 if type(values) != ListType:
00488
00489 subentry_infos = Manager.GetSubentryInfos(entry, 0)
00490
00491 text += "ParameterName=%s\n"%subentry_infos["name"]
00492 text += "ObjectType=0x7\n"
00493 text += "DataType=0x%4.4X\n"%subentry_infos["type"]
00494 text += "AccessType=%s\n"%subentry_infos["access"]
00495 text += "DefaultValue=%s\n"%values
00496 text += "PDOMapping=%s\n"%BOOL_TRANSLATE[subentry_infos["pdo"]]
00497 else:
00498
00499 text += "ParameterName=%s\n"%entry_infos["name"]
00500 if entry_infos["struct"] & node.OD_IdenticalSubindexes:
00501 text += "ObjectType=0x9\n"
00502 else:
00503 text += "ObjectType=0x8\n"
00504
00505
00506 subtext = ""
00507
00508 nb_subentry = 0
00509 for subentry, value in enumerate(values):
00510
00511 subentry_infos = Manager.GetSubentryInfos(entry, subentry)
00512
00513 if subentry_infos["name"] != "Compatibility Entry":
00514 subtext += "\n[%Xsub%X]\n"%(entry, subentry)
00515 subtext += "ParameterName=%s\n"%subentry_infos["name"]
00516 subtext += "ObjectType=0x7\n"
00517 subtext += "DataType=0x%4.4X\n"%subentry_infos["type"]
00518 subtext += "AccessType=%s\n"%subentry_infos["access"]
00519 subtext += "DefaultValue=%s\n"%value
00520 subtext += "PDOMapping=%s\n"%BOOL_TRANSLATE[subentry_infos["pdo"]]
00521
00522 nb_subentry += 1
00523
00524 text += "SubNumber=%d\n"%nb_subentry
00525
00526 text += subtext
00527
00528
00529
00530
00531 if 0x2000 <= entry <= 0x5FFF:
00532 manufacturers.append(entry)
00533
00534 elif entry_infos["need"]:
00535 mandatories.append(entry)
00536
00537 else:
00538 optionals.append(entry)
00539
00540 indexContents[entry] = text
00541
00542
00543 manufacturers.sort()
00544 mandatories.sort()
00545 optionals.sort()
00546
00547
00548 fileContent += "\n[MandatoryObjects]\n"
00549 fileContent += "SupportedObjects=%d\n"%len(mandatories)
00550 for idx, entry in enumerate(mandatories):
00551 fileContent += "%d=0x%4.4X\n"%(idx, entry)
00552
00553 for entry in mandatories:
00554 fileContent += indexContents[entry]
00555
00556
00557 fileContent += "\n[OptionalObjects]\n"
00558 fileContent += "SupportedObjects=%d\n"%len(optionals)
00559 for idx, entry in enumerate(optionals):
00560 fileContent += "%d=0x%4.4X\n"%(idx, entry)
00561
00562 for entry in optionals:
00563 fileContent += indexContents[entry]
00564
00565
00566 fileContent += "\n[ManufacturerObjects]\n"
00567 fileContent += "SupportedObjects=%d\n"%len(manufacturers)
00568 for idx, entry in enumerate(manufacturers):
00569 fileContent += "%d=0x%4.4X\n"%(idx, entry)
00570
00571 for entry in manufacturers:
00572 fileContent += indexContents[entry]
00573
00574
00575 return fileContent
00576
00577
00578
00579 def GenerateEDSFile(filepath, manager):
00580 global Manager
00581 Manager = manager
00582 try:
00583
00584 content = GenerateFileContent(filepath)
00585
00586 WriteFile(filepath, content)
00587 return None
00588 except ValueError, message:
00589 return "Unable to generate EDS file\n%s"%message
00590
00591
00592 def GenerateCPJContent(nodelist):
00593 nodes = nodelist.SlaveNodes.keys()
00594 nodes.sort()
00595
00596 fileContent = "[TOPOLOGY]\n"
00597 fileContent += "NetName=%s\n"%nodelist.GetNetworkName()
00598 fileContent += "Nodes=0x%2.2X\n"%len(nodes)
00599
00600 for nodeid in nodes:
00601 fileContent += "Node%dPresent=0x01\n"%nodeid
00602 fileContent += "Node%dName=%s\n"%(nodeid, nodelist.SlaveNodes[nodeid]["Name"])
00603 fileContent += "Node%dDCFName=%s\n"%(nodeid, nodelist.SlaveNodes[nodeid]["EDS"])
00604
00605 fileContent += "EDSBaseName=eds\n"
00606 return fileContent
00607
00608
00609 def GenerateNode(filepath, cwd, nodeID = 0):
00610 global Node
00611
00612 Node = node.Node(id = nodeID)
00613 try:
00614
00615 eds_dict = ParseEDSFile(filepath)
00616
00617 ProfileNb = eds_dict[0x1000]["DEFAULTVALUE"] & 0x0000ffff
00618
00619 if ProfileNb not in [301, 302]:
00620
00621 ProfileName = "DS-%d"%ProfileNb
00622 ProfilePath = os.path.join(cwd, "config/%s.prf"%ProfileName)
00623
00624 if os.path.isfile(ProfilePath):
00625 try:
00626
00627 execfile(ProfilePath)
00628 Node.SetProfileName(ProfileName)
00629 Node.SetProfile(Mapping)
00630 Node.SetSpecificMenu(AddMenuEntries)
00631 except:
00632 pass
00633
00634 for entry, values in eds_dict.items():
00635
00636 if entry in SECTION_KEYNAMES:
00637 pass
00638 else:
00639
00640 entry_infos = Node.GetEntryInfos(entry)
00641
00642
00643 if not entry_infos:
00644
00645 if values["OBJECTTYPE"] == 7:
00646
00647 Node.AddMappingEntry(entry, name = values["PARAMETERNAME"], struct = 1)
00648
00649 Node.AddMappingEntry(entry, 0, values = {"name" : values["PARAMETERNAME"],
00650 "type" : values["DATATYPE"],
00651 "access" : ACCESS_TRANSLATE[values["ACCESSTYPE"]],
00652 "pdo" : values["PDOMAPPING"] == 1})
00653
00654 elif values["OBJECTTYPE"] == 8:
00655
00656 try:
00657 max_subindex = values["subindexes"][0]["DEFAULTVALUE"]
00658 except:
00659 raise SyntaxError, "Error on entry 0x%4.4X:\nSubindex 0 must be defined for an ARRAY entry"%entry
00660
00661 Node.AddMappingEntry(entry, name = values["PARAMETERNAME"], struct = 3)
00662
00663 Node.AddMappingEntry(entry, 0, values = {"name" : "Number of Entries", "type" : 0x05, "access" : "ro", "pdo" : False})
00664
00665 for subindex in xrange(1, int(max_subindex) + 1):
00666
00667 if subindex in values["subindexes"]:
00668 Node.AddMappingEntry(entry, subindex, values = {"name" : values["subindexes"][subindex]["PARAMETERNAME"],
00669 "type" : values["subindexes"][subindex]["DATATYPE"],
00670 "access" : ACCESS_TRANSLATE[values["subindexes"][subindex]["ACCESSTYPE"]],
00671 "pdo" : values["subindexes"][subindex]["PDOMAPPING"] == 1})
00672
00673 else:
00674 Node.AddMappingEntry(entry, subindex, values = {"name" : "Compatibility Entry", "type" : 0x05, "access" : "rw", "pdo" : False})
00675
00676 elif values["OBJECTTYPE"] == 9:
00677
00678 if 0 not in values["subindexes"]:
00679 raise SyntaxError, "Error on entry 0x%4.4X:\nSubindex 0 must be defined for a RECORD entry"%entry
00680
00681 Node.AddMappingEntry(entry, name = values["PARAMETERNAME"], struct = 7)
00682
00683 Node.AddMappingEntry(entry, 0, values = {"name" : "Number of Entries", "type" : 0x05, "access" : "ro", "pdo" : False})
00684
00685 if 1 in values:
00686 Node.AddMappingEntry(entry, 1, values = {"name" : values["PARAMETERNAME"] + " %d[(sub)]",
00687 "type" : values["subindexes"][1]["DATATYPE"],
00688 "access" : ACCESS_TRANSLATE[values["subindexes"][1]["ACCESSTYPE"]],
00689 "pdo" : values["subindexes"][1]["PDOMAPPING"] == 1})
00690 else:
00691 raise SyntaxError, "Error on entry 0x%4.4X:\nA RECORD entry must have at least 2 subindexes"%entry
00692
00693
00694
00695
00696 if values["OBJECTTYPE"] == 7:
00697
00698 if "DEFAULTVALUE" in values:
00699 value = values["DEFAULTVALUE"]
00700
00701 else:
00702 value = GetDefaultValue(entry)
00703 Node.AddEntry(entry, 0, value)
00704
00705 elif values["OBJECTTYPE"] in (8, 9):
00706
00707 if "SUBNUMBER" in values and values["SUBNUMBER"] > 0:
00708
00709 try:
00710 max_subindex = values["subindexes"][0]["DEFAULTVALUE"]
00711 except:
00712 raise SyntaxError, "Error on entry 0x%4.4X:\nSubindex 0 must be defined for an ARRAY or a RECORD entry"%entry
00713
00714 for subindex in xrange(1, int(max_subindex) + 1):
00715
00716 if subindex in values["subindexes"] and "DEFAULTVALUE" in values["subindexes"][subindex]:
00717 value = values["subindexes"][subindex]["DEFAULTVALUE"]
00718
00719 else:
00720 value = GetDefaultValue(entry, subindex)
00721 Node.AddEntry(entry, subindex, value)
00722 else:
00723 raise SyntaxError, "Array or Record entry 0x%4.4X must have a \"SubNumber\" attribute"%entry
00724 return Node
00725 except SyntaxError, message:
00726 return "Unable to import EDS file\n%s"%message
00727
00728
00729
00730
00731
00732 if __name__ == '__main__':
00733 print ParseEDSFile("examples/PEAK MicroMod.eds")
00734