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.
- Install NodeJS.
- Within the
tools/schema/
directory typenpm install
to fetch package dependencies.
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.
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.
The following scripts are used to generate Rust files which are compiled into the opcua-
crates:
gen_address_space.js
- reads the default OPC UA Nodeset and generates code inopcua-server
that populates theAddressSpace
.gen_node_ids.js
- readsNodeIds.csv
and generates anode_ids.rs
inopcua-types
containing the defaultObjectId
,DataTypeId
etc enums.gen_types.js
- readsOpc.Ua.Types.bsd
and generates all of the services types inopcua-types
.gen_status_codes.js
- readsOpc.Ua.StatusCodes.csv
and generates astatus_codes.rs
inopcua-types
with all of theStatusCode
definitions.gen_supported_message.js
- generates asupported_message.rs
inopcua-core
which contains aSupportedMessage
enum that can hold any service request or response. Used by the server.
There are some helper Javascript files used by all the scripts:
settings.js
- holds paths to the various schema files and output folders to make it more convenient when values change.util.js
- contains utility functions used by one or more scriptsnodeset.js
- code shared bygen_nodeset.js
andgen_address_space.js
.