Skip to content

Latest commit

 

History

History
79 lines (54 loc) · 3.63 KB

README.md

File metadata and controls

79 lines (54 loc) · 3.63 KB

This directory contains NodeJS scripts for processing OPC UA Nodesets and type definitions and outputting equivalent Rust files.

You should not modify the Rust files generated by these scripts - they should compile as-is or the script is in error.

Prerequisites

  1. Install NodeJS.
  2. Within the tools/schema/ directory type npm install to fetch package dependencies.

Nodeset compiler

The tool gen_nodeset.js can be used to turn an OPC UA XML Nodeset file into a Rust module.

Example usage:

node gen_nodeset.js --nodeset Opc_Ua.EUROMAP83.NodeSet2.xml --module euromap83

This will take a locally saved copy of the EUROMAP 83 schema and output a file called euromap83.rs.

If you want to replace any non-zero namespace index in the file with another, e.g. 2 instead of 1 then add a --ns argument, e.g. --ns 2 so that if the file references a node id ns=1;i=1234 it will generate code that references it as ns=2;i=1234 instead. It ignores anything using the 0 namespace which is assumed to be OPC UA's.

Once you have a file you can incorporate it into a server with some code like this:

mod euromap83;

fn setup() {
   //... create a server and then

   let address_space = server.address_space();

   // The address space is guarded so obtain a lock to change it
   {
        let mut address_space = address_space.write().unwrap();
        let ns_idx = address_space.register_namespace("http://www.euromap.org/euromap83/");
        assert_eq!(ns_idx, 2); // Should match the code you generated!
        euromap83::populate_address_space(&mut address_space);
   }
}

Note that the namespace index you receive when you register the schema's urn should match the one in the generated file! So you may have to tweak the generator once you know what that value should be. In the default server setup, namespace index 0 is the OPC UA default nodeset, namespace index 1 is reserved for OPC UA for Rust and 2 onwards are your registered namespaces. So typically you will need to specify --ns 2 or greater.

Generate Structs and Enums from BSD file

The tool gen_datatypes.js can be used to turn an OPC UA BSD files into a Rust module containing all datastructs and enums.

Example usage:

node gen_datatypes --bsd Opc.Ua.TMC.NodeSet2.bsd --module tmc

This will take a locally saved copy of the bsd schema and output a folder called tmc which is a rust module containing alle datastructs and enums.

Internal Tools

The following scripts are used to generate Rust files which are compiled into the opcua- crates:

  1. gen_address_space.js - reads the default OPC UA Nodeset and generates code in opcua-server that populates the AddressSpace.
  2. gen_node_ids.js - reads NodeIds.csv and generates a node_ids.rs in opcua-types containing the default ObjectId, DataTypeId etc enums.
  3. gen_types.js - reads Opc.Ua.Types.bsd and generates all of the services types in opcua-types.
  4. gen_status_codes.js - reads Opc.Ua.StatusCodes.csv and generates a status_codes.rs in opcua-types with all of the StatusCode definitions.
  5. gen_supported_message.js - generates a supported_message.rs in opcua-core which contains a SupportedMessage enum that can hold any service request or response. Used by the server.

There are some helper Javascript files used by all the scripts:

  1. settings.js - holds paths to the various schema files and output folders to make it more convenient when values change.
  2. util.js - contains utility functions used by one or more scripts
  3. nodeset.js - code shared by gen_nodeset.js and gen_address_space.js.