nodeset_testing.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env python
  2. import codecs
  3. from nodeset import *
  4. class testing:
  5. def __init__(self):
  6. self.ns = NodeSet("testing")
  7. logger.debug("Phase 1: Reading XML file nodessets")
  8. self.ns.parseXML("Opc.Ua.NodeSet2.xml")
  9. # self.ns.parseXML("Opc.Ua.NodeSet2.Part4.xml")
  10. # self.ns.parseXML("Opc.Ua.NodeSet2.Part5.xml")
  11. # self.ns.parseXML("Opc.Ua.SimulationNodeSet2.xml")
  12. logger.debug("Phase 2: Linking address space references and datatypes")
  13. self.ns.linkOpenPointers()
  14. self.ns.sanitize()
  15. logger.debug("Phase 3: Comprehending DataType encoding rules")
  16. self.ns.buildEncodingRules()
  17. logger.debug("Phase 4: Allocating variable value data")
  18. self.ns.allocateVariables()
  19. bin = self.ns.buildBinary()
  20. f = codecs.open("binary.base64", "w+", encoding='utf-8')
  21. f.write(bin.encode("base64"))
  22. f.close()
  23. allnodes = self.ns.nodes
  24. ns = [self.ns.getRoot()]
  25. i = 0
  26. # print "Starting depth search on " + str(len(allnodes)) + " nodes starting
  27. # with from " + str(ns)
  28. while (len(ns) < len(allnodes)):
  29. i = i + 1
  30. tmp = []
  31. print("Iteration: " + str(i))
  32. for n in ns:
  33. tmp.append(n)
  34. for r in n.getReferences():
  35. if (not r.target() in tmp):
  36. tmp.append(r.target())
  37. print("...tmp, " + str(len(tmp)) + " nodes discovered")
  38. ns = []
  39. for n in tmp:
  40. ns.append(n)
  41. print("...done, " + str(len(ns)) + " nodes discovered")
  42. class testing_open62541_header:
  43. def __init__(self):
  44. self.ns = opcua_ns("testing")
  45. logger.debug("Phase 1: Reading XML file nodessets")
  46. self.ns.parseXML("Opc.Ua.NodeSet2.xml")
  47. # self.ns.parseXML("Opc.Ua.NodeSet2.Part4.xml")
  48. # self.ns.parseXML("Opc.Ua.NodeSet2.Part5.xml")
  49. # self.ns.parseXML("Opc.Ua.SimulationNodeSet2.xml")
  50. logger.debug("Phase 2: Linking address space references and datatypes")
  51. self.ns.linkOpenPointers()
  52. self.ns.sanitize()
  53. logger.debug("Phase 3: Calling C Printers")
  54. code = self.ns.printOpen62541Header()
  55. codeout = codecs.open("./open62541_nodeset.c", "w+", encoding='utf-8')
  56. for line in code:
  57. codeout.write(line + "\n")
  58. codeout.close()
  59. return
  60. if __name__ == '__main__':
  61. tst = testing_open62541_header()