56 ENTRY_ATTRIBUTES = {"SUBNUMBER" : is_integer, "PARAMETERNAME" : is_string, |
56 ENTRY_ATTRIBUTES = {"SUBNUMBER" : is_integer, "PARAMETERNAME" : is_string, |
57 "OBJECTTYPE" : lambda x: x in (7, 8, 9), "DATATYPE" : is_integer, |
57 "OBJECTTYPE" : lambda x: x in (7, 8, 9), "DATATYPE" : is_integer, |
58 "LOWLIMIT" : is_integer, "HIGHLIMIT" : is_integer, |
58 "LOWLIMIT" : is_integer, "HIGHLIMIT" : is_integer, |
59 "ACCESSTYPE" : lambda x: x.upper() in ACCESS_TRANSLATE.keys(), |
59 "ACCESSTYPE" : lambda x: x.upper() in ACCESS_TRANSLATE.keys(), |
60 "DEFAULTVALUE" : lambda x: True, "PDOMAPPING" : is_boolean, |
60 "DEFAULTVALUE" : lambda x: True, "PDOMAPPING" : is_boolean, |
61 "OBJFLAGS" : is_integer} |
61 "OBJFLAGS" : is_integer, "PARAMETERVALUE" : lambda x: True,} |
62 |
62 |
63 # Define entry parameters by entry ObjectType number |
63 # Define entry parameters by entry ObjectType number |
64 ENTRY_TYPES = {7 : {"name" : " VAR", |
64 ENTRY_TYPES = {7 : {"name" : " VAR", |
65 "require" : ["PARAMETERNAME", "DATATYPE", "ACCESSTYPE"], |
65 "require" : ["PARAMETERNAME", "DATATYPE", "ACCESSTYPE"], |
66 "optional" : ["OBJECTTYPE", "DEFAULTVALUE", "PDOMAPPING", "LOWLIMIT", "HIGHLIMIT", "OBJFLAGS"]}, |
66 "optional" : ["OBJECTTYPE", "DEFAULTVALUE", "PDOMAPPING", "LOWLIMIT", "HIGHLIMIT", "OBJFLAGS", "PARAMETERVALUE"]}, |
67 8 : {"name" : "n ARRAY", |
67 8 : {"name" : "n ARRAY", |
68 "require" : ["PARAMETERNAME", "OBJECTTYPE", "SUBNUMBER"], |
68 "require" : ["PARAMETERNAME", "OBJECTTYPE", "SUBNUMBER"], |
69 "optional" : ["OBJFLAGS"]}, |
69 "optional" : ["OBJFLAGS"]}, |
70 9 : {"name" : " RECORD", |
70 9 : {"name" : " RECORD", |
71 "require" : ["PARAMETERNAME", "OBJECTTYPE", "SUBNUMBER"], |
71 "require" : ["PARAMETERNAME", "OBJECTTYPE", "SUBNUMBER"], |
376 if len(unsupported) > 1: |
376 if len(unsupported) > 1: |
377 attributes = "Attributes %s are"%", ".join(["\"%s\""%attribute for attribute in unsupported]) |
377 attributes = "Attributes %s are"%", ".join(["\"%s\""%attribute for attribute in unsupported]) |
378 else: |
378 else: |
379 attributes = "Attribute \"%s\" is"%unsupported[0] |
379 attributes = "Attribute \"%s\" is"%unsupported[0] |
380 raise SyntaxError, "Error on section \"[%s]\":\n%s unsupported for a%s entry"%(section_name, attributes, ENTRY_TYPES[objecttype]["name"]) |
380 raise SyntaxError, "Error on section \"[%s]\":\n%s unsupported for a%s entry"%(section_name, attributes, ENTRY_TYPES[objecttype]["name"]) |
|
381 |
|
382 if "PARAMETERVALUE" in values: |
|
383 try: |
|
384 if values["DATATYPE"] in (0x09, 0x0A, 0x0B, 0x0F): |
|
385 values["PARAMETERVALUE"] = str(values["PARAMETERVALUE"]) |
|
386 elif values["DATATYPE"] in (0x08, 0x11): |
|
387 values["PARAMETERVALUE"] = float(values["PARAMETERVALUE"]) |
|
388 elif values["DATATYPE"] == 0x01: |
|
389 values["PARAMETERVALUE"] = {0 : True, 1 : False}[values["PARAMETERVALUE"]] |
|
390 else: |
|
391 if type(values["PARAMETERVALUE"]) != IntType and values["PARAMETERVALUE"].find("$NODEID") == -1: |
|
392 raise |
|
393 except: |
|
394 raise SyntaxError, "Error on section \"[%s]\":\nParameterValue incompatible with DataType"%section_name |
381 |
395 |
382 if "DEFAULTVALUE" in values: |
396 if "DEFAULTVALUE" in values: |
383 try: |
397 try: |
384 if values["DATATYPE"] in (0x09, 0x0A, 0x0B, 0x0F): |
398 if values["DATATYPE"] in (0x09, 0x0A, 0x0B, 0x0F): |
385 values["DEFAULTVALUE"] = str(values["DEFAULTVALUE"]) |
399 values["DEFAULTVALUE"] = str(values["DEFAULTVALUE"]) |
711 # Define entry for the new node |
725 # Define entry for the new node |
712 |
726 |
713 # First case, entry is a VAR |
727 # First case, entry is a VAR |
714 if values["OBJECTTYPE"] == 7: |
728 if values["OBJECTTYPE"] == 7: |
715 # Take default value if it is defined |
729 # Take default value if it is defined |
716 if "DEFAULTVALUE" in values: |
730 if "PARAMETERVALUE" in values: |
|
731 value = values["PARAMETERVALUE"] |
|
732 elif "DEFAULTVALUE" in values: |
717 value = values["DEFAULTVALUE"] |
733 value = values["DEFAULTVALUE"] |
718 # Find default value for value type of the entry |
734 # Find default value for value type of the entry |
719 else: |
735 else: |
720 value = GetDefaultValue(entry) |
736 value = GetDefaultValue(entry) |
721 Node.AddEntry(entry, 0, value) |
737 Node.AddEntry(entry, 0, value) |
733 #raise SyntaxError, "Error on entry 0x%4.4X:\nSubindex 0 must be defined for an ARRAY or a RECORD entry"%entry |
749 #raise SyntaxError, "Error on entry 0x%4.4X:\nSubindex 0 must be defined for an ARRAY or a RECORD entry"%entry |
734 Node.AddEntry(entry, value = []) |
750 Node.AddEntry(entry, value = []) |
735 # Define value for all subindexes except the first |
751 # Define value for all subindexes except the first |
736 for subindex in xrange(1, int(max_subindex) + 1): |
752 for subindex in xrange(1, int(max_subindex) + 1): |
737 # Take default value if it is defined and entry is defined |
753 # Take default value if it is defined and entry is defined |
738 if subindex in values["subindexes"] and "DEFAULTVALUE" in values["subindexes"][subindex]: |
754 if subindex in values["subindexes"] and "PARAMETERVALUE" in values["subindexes"][subindex]: |
|
755 value = values["subindexes"][subindex]["PARAMETERVALUE"] |
|
756 elif subindex in values["subindexes"] and "DEFAULTVALUE" in values["subindexes"][subindex]: |
739 value = values["subindexes"][subindex]["DEFAULTVALUE"] |
757 value = values["subindexes"][subindex]["DEFAULTVALUE"] |
740 # Find default value for value type of the subindex |
758 # Find default value for value type of the subindex |
741 elif subindex in values["subindexes"] or not consecutive: |
759 elif subindex in values["subindexes"] or not consecutive: |
742 value = GetDefaultValue(entry, subindex) |
760 value = GetDefaultValue(entry, subindex) |
743 else: |
761 else: |