702 "access" : ACCESS_TRANSLATE[values["ACCESSTYPE"].upper()], |
702 "access" : ACCESS_TRANSLATE[values["ACCESSTYPE"].upper()], |
703 "pdo" : values.get("PDOMAPPING", 0) == 1}) |
703 "pdo" : values.get("PDOMAPPING", 0) == 1}) |
704 # Second case, entry is an ARRAY or RECORD |
704 # Second case, entry is an ARRAY or RECORD |
705 elif values["OBJECTTYPE"] in [8, 9]: |
705 elif values["OBJECTTYPE"] in [8, 9]: |
706 # Extract maximum subindex number defined |
706 # Extract maximum subindex number defined |
707 try: |
707 max_subindex = max(values["subindexes"].keys()) |
708 max_subindex = values["subindexes"][0]["DEFAULTVALUE"] |
|
709 except: |
|
710 max_subindex = max(*values["subindexes"].keys()) |
|
711 #raise SyntaxError, "Error on entry 0x%4.4X:\nSubindex 0 must be defined for an ARRAY or RECORD entry"%entry |
|
712 # Add mapping for entry |
708 # Add mapping for entry |
713 Node.AddMappingEntry(entry, name = values["PARAMETERNAME"], struct = 3) |
709 Node.AddMappingEntry(entry, name = values["PARAMETERNAME"], struct = 3) |
714 # Add mapping for first subindex |
710 # Add mapping for first subindex |
715 Node.AddMappingEntry(entry, 0, values = {"name" : "Number of Entries", "type" : 0x05, "access" : "ro", "pdo" : False}) |
711 Node.AddMappingEntry(entry, 0, values = {"name" : "Number of Entries", "type" : 0x05, "access" : "ro", "pdo" : False}) |
716 # Add mapping for other subindexes |
712 # Add mapping for other subindexes |
758 Node.AddEntry(entry, 0, value) |
754 Node.AddEntry(entry, 0, value) |
759 # Second case, entry is an ARRAY or a RECORD |
755 # Second case, entry is an ARRAY or a RECORD |
760 elif values["OBJECTTYPE"] in [8, 9]: |
756 elif values["OBJECTTYPE"] in [8, 9]: |
761 # Verify that "Subnumber" attribute is defined and has a valid value |
757 # Verify that "Subnumber" attribute is defined and has a valid value |
762 if "SUBNUMBER" in values and values["SUBNUMBER"] > 0: |
758 if "SUBNUMBER" in values and values["SUBNUMBER"] > 0: |
763 consecutive = False |
|
764 # Extract maximum subindex number defined |
759 # Extract maximum subindex number defined |
765 try: |
760 max_subindex = max(values["subindexes"].keys()) |
766 max_subindex = values["subindexes"][0]["DEFAULTVALUE"] |
|
767 except: |
|
768 max_subindex = values["SUBNUMBER"] - 1 |
|
769 consecutive = True |
|
770 #raise SyntaxError, "Error on entry 0x%4.4X:\nSubindex 0 must be defined for an ARRAY or a RECORD entry"%entry |
|
771 Node.AddEntry(entry, value = []) |
761 Node.AddEntry(entry, value = []) |
772 # Define value for all subindexes except the first |
762 # Define value for all subindexes except the first |
773 for subindex in xrange(1, int(max_subindex) + 1): |
763 for subindex in xrange(1, int(max_subindex) + 1): |
774 # Take default value if it is defined and entry is defined |
764 # Take default value if it is defined and entry is defined |
775 if subindex in values["subindexes"] and "PARAMETERVALUE" in values["subindexes"][subindex]: |
765 if subindex in values["subindexes"] and "PARAMETERVALUE" in values["subindexes"][subindex]: |
776 value = values["subindexes"][subindex]["PARAMETERVALUE"] |
766 value = values["subindexes"][subindex]["PARAMETERVALUE"] |
777 elif subindex in values["subindexes"] and "DEFAULTVALUE" in values["subindexes"][subindex]: |
767 elif subindex in values["subindexes"] and "DEFAULTVALUE" in values["subindexes"][subindex]: |
778 value = values["subindexes"][subindex]["DEFAULTVALUE"] |
768 value = values["subindexes"][subindex]["DEFAULTVALUE"] |
779 # Find default value for value type of the subindex |
769 # Find default value for value type of the subindex |
780 elif subindex in values["subindexes"] or not consecutive: |
770 else: |
781 value = GetDefaultValue(Node, entry, subindex) |
771 value = GetDefaultValue(Node, entry, subindex) |
782 else: |
|
783 raise SyntaxError, "Error on entry 0x%4.4X:\nCan't recompose implemented subindexes in this ARRAY or RECORD entry"%entry |
|
784 Node.AddEntry(entry, subindex, value) |
772 Node.AddEntry(entry, subindex, value) |
785 else: |
773 else: |
786 raise SyntaxError, "Array or Record entry 0x%4.4X must have a \"SubNumber\" attribute"%entry |
774 raise SyntaxError, "Array or Record entry 0x%4.4X must have a \"SubNumber\" attribute"%entry |
787 return Node |
775 return Node |
788 except SyntaxError, message: |
776 except SyntaxError, message: |