nodeset_testing.py 2.4 KB

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