Commit 17393c6d authored by olivier R-D's avatar olivier R-D

only check left byte to know if status code is good

parent 09861d1a
#AUTOGENERATED!!!
from opcua.common.uaerrors import UaStatusCodeError
from opcua.ua import ua_binary as uabin
class StatusCodes(object):
Good = 0
......@@ -473,4 +474,7 @@ def get_name_and_doc(val):
if val in code_to_name_doc:
return code_to_name_doc[val]
else:
return 'UnknownUaError', 'Unknown StatusCode value: {}'.format(val)
if uabin.test_bit(val, 31):
return 'Bad', 'Unknown StatusCode value: {}'.format(val)
else:
return 'Good', 'Unknown StatusCode value: {}'.format(val)
......@@ -222,16 +222,17 @@ class StatusCode(FrozenClass):
Use the is_good() method if you do not want an exception.
"""
if self.value != 0:
if not self.is_good():
raise UaStatusCodeError(self.value)
def is_good(self):
"""
return True if status is Good.
"""
if self.value == 0:
if uabin.test_bit(self.value, 31):
return False
else:
return True
return False
def __str__(self):
return 'StatusCode({})'.format(self.name)
......
......@@ -22,7 +22,8 @@ if __name__ == "__main__":
outputfile = open("../opcua/ua/status_codes.py", "w")
outputfile.write("#AUTOGENERATED!!!\n")
outputfile.write("\n")
outputfile.write("from opcua.common.uaerrors import UAStatusCodeError\n")
outputfile.write("from opcua.common.uaerrors import UaStatusCodeError\n")
outputfile.write("from opcua.ua import ua_binary as uabin\n")
#outputfile.write("from enum import Enum\n")
outputfile.write("\n")
......@@ -46,7 +47,10 @@ if __name__ == "__main__":
if val in code_to_name_doc:
return code_to_name_doc[val]
else:
return 'UnknownUaError', 'Unknown StatusCode value: {}'.format(val)
if uabin.test_bit(val, 31):
return 'Bad', 'Unknown StatusCode value: {}'.format(val)
else:
return 'Good', 'Unknown StatusCode value: {}'.format(val)
""")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment