nodeset_testing.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env python
  2. ### This Source Code Form is subject to the terms of the Mozilla Public
  3. ### License, v. 2.0. If a copy of the MPL was not distributed with this
  4. ### file, You can obtain one at http://mozilla.org/MPL/2.0/.
  5. ### Copyright 2014-2015 (c) TU-Dresden (Author: Chris Iatrou)
  6. ### Copyright 2014-2017 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
  7. ### Copyright 2016-2017 (c) Stefan Profanter, fortiss GmbH
  8. import codecs
  9. from nodeset import *
  10. class testing:
  11. def __init__(self):
  12. self.ns = NodeSet("testing")
  13. logger.debug("Phase 1: Reading XML file nodessets")
  14. self.ns.parseXML("Opc.Ua.NodeSet2.xml")
  15. # self.ns.parseXML("Opc.Ua.NodeSet2.Part4.xml")
  16. # self.ns.parseXML("Opc.Ua.NodeSet2.Part5.xml")
  17. # self.ns.parseXML("Opc.Ua.SimulationNodeSet2.xml")
  18. logger.debug("Phase 2: Linking address space references and datatypes")
  19. self.ns.linkOpenPointers()
  20. self.ns.sanitize()
  21. logger.debug("Phase 3: Allocating variable value data")
  22. self.ns.allocateVariables()
  23. bin = self.ns.buildBinary()
  24. f = codecs.open("binary.base64", "w+", encoding='utf-8')
  25. f.write(bin.encode("base64"))
  26. f.close()
  27. allnodes = self.ns.nodes
  28. ns = [self.ns.getRoot()]
  29. i = 0
  30. # print "Starting depth search on " + str(len(allnodes)) + " nodes starting
  31. # with from " + str(ns)
  32. while (len(ns) < len(allnodes)):
  33. i = i + 1
  34. tmp = []
  35. print("Iteration: " + str(i))
  36. for n in ns:
  37. tmp.append(n)
  38. for r in n.getReferences():
  39. if (not r.target() in tmp):
  40. tmp.append(r.target())
  41. print("...tmp, " + str(len(tmp)) + " nodes discovered")
  42. ns = []
  43. for n in tmp:
  44. ns.append(n)
  45. print("...done, " + str(len(ns)) + " nodes discovered")
  46. class testing_open62541_header:
  47. def __init__(self):
  48. self.ns = opcua_ns("testing")
  49. logger.debug("Phase 1: Reading XML file nodessets")
  50. self.ns.parseXML("Opc.Ua.NodeSet2.xml")
  51. # self.ns.parseXML("Opc.Ua.NodeSet2.Part4.xml")
  52. # self.ns.parseXML("Opc.Ua.NodeSet2.Part5.xml")
  53. # self.ns.parseXML("Opc.Ua.SimulationNodeSet2.xml")
  54. logger.debug("Phase 2: Linking address space references and datatypes")
  55. self.ns.linkOpenPointers()
  56. self.ns.sanitize()
  57. logger.debug("Phase 3: Calling C Printers")
  58. code = self.ns.printOpen62541Header()
  59. codeout = codecs.open("./open62541_nodeset.c", "w+", encoding='utf-8')
  60. for line in code:
  61. codeout.write(line + "\n")
  62. codeout.close()
  63. return
  64. if __name__ == '__main__':
  65. tst = testing_open62541_header()