nodeset_testing.py 2.9 KB

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