74 "optional" : ["OBJFLAGS"]}} |
74 "optional" : ["OBJFLAGS"]}} |
75 |
75 |
76 |
76 |
77 # Function that search into Node Mappings the informations about an index or a subindex |
77 # Function that search into Node Mappings the informations about an index or a subindex |
78 # and return the default value |
78 # and return the default value |
79 def GetDefaultValue(index, subIndex = None): |
79 def GetDefaultValue(Node, index, subIndex = None): |
80 infos = Node.GetEntryInfos(index) |
80 infos = Node.GetEntryInfos(index) |
81 if infos["struct"] & node.OD_MultipleSubindexes: |
81 if infos["struct"] & node.OD_MultipleSubindexes: |
82 # First case entry is a record |
82 # First case entry is a record |
83 if infos["struct"] & node.OD_IdenticalSubindexes: |
83 if infos["struct"] & node.OD_IdenticalSubindexes: |
84 subentry_infos = Node.GetSubentryInfos(index, 1) |
84 subentry_infos = Node.GetSubentryInfos(index, 1) |
425 # Close file |
425 # Close file |
426 cfile.close() |
426 cfile.close() |
427 |
427 |
428 |
428 |
429 # Function that generate the EDS file content for the current node in the manager |
429 # Function that generate the EDS file content for the current node in the manager |
430 def GenerateFileContent(filepath): |
430 def GenerateFileContent(Node, filepath): |
431 # Dictionary of each index contents |
431 # Dictionary of each index contents |
432 indexContents = {} |
432 indexContents = {} |
433 |
433 |
434 # Extract local time |
434 # Extract local time |
435 current_time = localtime() |
435 current_time = localtime() |
436 # Extract node informations |
436 # Extract node informations |
437 nodename, nodeid, nodetype, description = Manager.GetCurrentNodeInfos() |
437 nodename = Node.GetNodeName() |
438 |
438 nodeid = Node.GetNodeID() |
439 # Compiling lists of indexes defined |
439 nodetype = Node.GetNodeType() |
440 entries = [idx for name, idx in Manager.GetCurrentValidIndexes(0, 0xFFFF)] |
440 description = Node.GetNodeDescription() |
|
441 |
|
442 # Retreiving lists of indexes defined |
|
443 entries = Node.GetIndexes() |
441 |
444 |
442 # Generate FileInfo section |
445 # Generate FileInfo section |
443 fileContent = "[FileInfo]\n" |
446 fileContent = "[FileInfo]\n" |
444 fileContent += "FileName=%s\n"%os.path.split(filepath)[-1] |
447 fileContent += "FileName=%s\n"%os.path.split(filepath)[-1] |
445 fileContent += "FileVersion=1\n" |
448 fileContent += "FileVersion=1\n" |
465 |
468 |
466 # Generate DeviceInfo section |
469 # Generate DeviceInfo section |
467 fileContent += "\n[DeviceInfo]\n" |
470 fileContent += "\n[DeviceInfo]\n" |
468 fileContent += "VendorName=CANFestival\n" |
471 fileContent += "VendorName=CANFestival\n" |
469 # Use information typed by user in Identity entry |
472 # Use information typed by user in Identity entry |
470 fileContent += "VendorNumber=0x%8.8X\n"%Manager.GetCurrentEntry(0x1018, 1) |
473 fileContent += "VendorNumber=0x%8.8X\n"%Node.GetEntry(0x1018, 1) |
471 fileContent += "ProductName=%s\n"%nodename |
474 fileContent += "ProductName=%s\n"%nodename |
472 fileContent += "ProductNumber=0x%8.8X\n"%Manager.GetCurrentEntry(0x1018, 2) |
475 fileContent += "ProductNumber=0x%8.8X\n"%Node.GetEntry(0x1018, 2) |
473 fileContent += "RevisionNumber=0x%8.8X\n"%Manager.GetCurrentEntry(0x1018, 3) |
476 fileContent += "RevisionNumber=0x%8.8X\n"%Node.GetEntry(0x1018, 3) |
474 # CANFestival support all baudrates as soon as driver choosen support them |
477 # CANFestival support all baudrates as soon as driver choosen support them |
475 fileContent += "BaudRate_10=1\n" |
478 fileContent += "BaudRate_10=1\n" |
476 fileContent += "BaudRate_20=1\n" |
479 fileContent += "BaudRate_20=1\n" |
477 fileContent += "BaudRate_50=1\n" |
480 fileContent += "BaudRate_50=1\n" |
478 fileContent += "BaudRate_125=1\n" |
481 fileContent += "BaudRate_125=1\n" |
514 manufacturers = [] |
517 manufacturers = [] |
515 |
518 |
516 # For each entry, we generate the entry section or sections if there is subindexes |
519 # For each entry, we generate the entry section or sections if there is subindexes |
517 for entry in entries: |
520 for entry in entries: |
518 # Extract infos and values for the entry |
521 # Extract infos and values for the entry |
519 entry_infos = Manager.GetEntryInfos(entry) |
522 entry_infos = Node.GetEntryInfos(entry) |
520 values = Manager.GetCurrentEntry(entry, compute = False) |
523 values = Node.GetEntry(entry, compute = False) |
521 # Define section name |
524 # Define section name |
522 text = "\n[%X]\n"%entry |
525 text = "\n[%X]\n"%entry |
523 # If there is only one value, it's a VAR entry |
526 # If there is only one value, it's a VAR entry |
524 if type(values) != ListType: |
527 if type(values) != ListType: |
525 # Extract the informations of the first subindex |
528 # Extract the informations of the first subindex |
526 subentry_infos = Manager.GetSubentryInfos(entry, 0) |
529 subentry_infos = Node.GetSubentryInfos(entry, 0) |
527 # Generate EDS informations for the entry |
530 # Generate EDS informations for the entry |
528 text += "ParameterName=%s\n"%subentry_infos["name"] |
531 text += "ParameterName=%s\n"%subentry_infos["name"] |
529 text += "ObjectType=0x7\n" |
532 text += "ObjectType=0x7\n" |
530 text += "DataType=0x%4.4X\n"%subentry_infos["type"] |
533 text += "DataType=0x%4.4X\n"%subentry_infos["type"] |
531 text += "AccessType=%s\n"%subentry_infos["access"] |
534 text += "AccessType=%s\n"%subentry_infos["access"] |
546 subtext = "" |
549 subtext = "" |
547 # Reset number of subindex defined |
550 # Reset number of subindex defined |
548 nb_subentry = 0 |
551 nb_subentry = 0 |
549 for subentry, value in enumerate(values): |
552 for subentry, value in enumerate(values): |
550 # Extract the informations of each subindex |
553 # Extract the informations of each subindex |
551 subentry_infos = Manager.GetSubentryInfos(entry, subentry) |
554 subentry_infos = Node.GetSubentryInfos(entry, subentry) |
552 # If entry is not for the compatibility, generate informations for subindex |
555 # If entry is not for the compatibility, generate informations for subindex |
553 if subentry_infos["name"] != "Compatibility Entry": |
556 if subentry_infos["name"] != "Compatibility Entry": |
554 subtext += "\n[%Xsub%X]\n"%(entry, subentry) |
557 subtext += "\n[%Xsub%X]\n"%(entry, subentry) |
555 subtext += "ParameterName=%s\n"%subentry_infos["name"] |
558 subtext += "ParameterName=%s\n"%subentry_infos["name"] |
556 subtext += "ObjectType=0x7\n" |
559 subtext += "ObjectType=0x7\n" |
617 # Return File Content |
620 # Return File Content |
618 return fileContent |
621 return fileContent |
619 |
622 |
620 |
623 |
621 # Function that generates EDS file from current node edited |
624 # Function that generates EDS file from current node edited |
622 def GenerateEDSFile(filepath, manager): |
625 def GenerateEDSFile(filepath, node): |
623 global Manager |
|
624 Manager = manager |
|
625 try: |
626 try: |
626 # Generate file content |
627 # Generate file content |
627 content = GenerateFileContent(filepath) |
628 content = GenerateFileContent(node, filepath) |
628 # Write file |
629 # Write file |
629 WriteFile(filepath, content) |
630 WriteFile(filepath, content) |
630 return None |
631 return None |
631 except ValueError, message: |
632 except ValueError, message: |
632 return "Unable to generate EDS file\n%s"%message |
633 return "Unable to generate EDS file\n%s"%message |
648 fileContent += "EDSBaseName=eds\n" |
649 fileContent += "EDSBaseName=eds\n" |
649 return fileContent |
650 return fileContent |
650 |
651 |
651 # Function that generates Node from an EDS file |
652 # Function that generates Node from an EDS file |
652 def GenerateNode(filepath, nodeID = 0): |
653 def GenerateNode(filepath, nodeID = 0): |
653 global Node |
|
654 # Create a new node |
654 # Create a new node |
655 Node = node.Node(id = nodeID) |
655 Node = node.Node(id = nodeID) |
656 try: |
656 try: |
657 # Parse file and extract dictionary of EDS entry |
657 # Parse file and extract dictionary of EDS entry |
658 eds_dict = ParseEDSFile(filepath) |
658 eds_dict = ParseEDSFile(filepath) |
744 value = values["PARAMETERVALUE"] |
744 value = values["PARAMETERVALUE"] |
745 elif "DEFAULTVALUE" in values: |
745 elif "DEFAULTVALUE" in values: |
746 value = values["DEFAULTVALUE"] |
746 value = values["DEFAULTVALUE"] |
747 # Find default value for value type of the entry |
747 # Find default value for value type of the entry |
748 else: |
748 else: |
749 value = GetDefaultValue(entry) |
749 value = GetDefaultValue(Node, entry) |
750 Node.AddEntry(entry, 0, value) |
750 Node.AddEntry(entry, 0, value) |
751 # Second case, entry is an ARRAY or a RECORD |
751 # Second case, entry is an ARRAY or a RECORD |
752 elif values["OBJECTTYPE"] in (8, 9): |
752 elif values["OBJECTTYPE"] in (8, 9): |
753 # Verify that "Subnumber" attribute is defined and has a valid value |
753 # Verify that "Subnumber" attribute is defined and has a valid value |
754 if "SUBNUMBER" in values and values["SUBNUMBER"] > 0: |
754 if "SUBNUMBER" in values and values["SUBNUMBER"] > 0: |
768 value = values["subindexes"][subindex]["PARAMETERVALUE"] |
768 value = values["subindexes"][subindex]["PARAMETERVALUE"] |
769 elif subindex in values["subindexes"] and "DEFAULTVALUE" in values["subindexes"][subindex]: |
769 elif subindex in values["subindexes"] and "DEFAULTVALUE" in values["subindexes"][subindex]: |
770 value = values["subindexes"][subindex]["DEFAULTVALUE"] |
770 value = values["subindexes"][subindex]["DEFAULTVALUE"] |
771 # Find default value for value type of the subindex |
771 # Find default value for value type of the subindex |
772 elif subindex in values["subindexes"] or not consecutive: |
772 elif subindex in values["subindexes"] or not consecutive: |
773 value = GetDefaultValue(entry, subindex) |
773 value = GetDefaultValue(Node, entry, subindex) |
774 else: |
774 else: |
775 raise SyntaxError, "Error on entry 0x%4.4X:\nCan't recompose implemented subindexes in this ARRAY or RECORD entry"%entry |
775 raise SyntaxError, "Error on entry 0x%4.4X:\nCan't recompose implemented subindexes in this ARRAY or RECORD entry"%entry |
776 Node.AddEntry(entry, subindex, value) |
776 Node.AddEntry(entry, subindex, value) |
777 else: |
777 else: |
778 raise SyntaxError, "Array or Record entry 0x%4.4X must have a \"SubNumber\" attribute"%entry |
778 raise SyntaxError, "Array or Record entry 0x%4.4X must have a \"SubNumber\" attribute"%entry |