Skip to content

Commit

Permalink
getting and processing nodeset2
Browse files Browse the repository at this point in the history
  • Loading branch information
erossignon committed Feb 13, 2014
1 parent 7fb95e1 commit 1733e23
Show file tree
Hide file tree
Showing 3 changed files with 298 additions and 1 deletion.
93 changes: 93 additions & 0 deletions code_gen/fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
var request = require("request");
var fs = require("fs");
var ProgressBar = require('progress');


function wget2(url) {

var bar = new ProgressBar(':bar', { total: 10 });
var path = require("path");
var filename = path.basename(url) + path.extname(url);
request(url).pipe(fs.createWriteStream(filename));


request.on("data", function(chunk){



});
}


function wget(url) {

var http = require('http');
var path = require("path");
var filename = path.basename(url) + path.extname(url);


var stream = fs.createWriteStream(filename,"w");

var req = http.get(url, function(response) {
// handle the response
var res_data = '';
// console.log(response);
var fileBytes = parseInt(response.headers['content-length']);
var bar = new ProgressBar(' downloading ' + url + '[:bar] :percent :etas', {
complete: '='
, incomplete: ' '
, width: 20
, total: fileBytes
});

response.on('data', function(chunk) {
res_data += chunk;

bar.tick(chunk.length);
stream.write(chunk,"binary");

});
response.on('end', function() {
stream.end();
});
});
req.on('error', function(err) {
console.log("Request error: " + err.message);
});
}


/*
File Description File Name Permanent URL Alternate URL
OPC UA XML Type Definitions The XML schema for all data types defined in the OPC UA specifications. Opc.Ua.Types.xsd http://opcfoundation.org/UA/schemas/1.02/Opc.Ua.Types.xsd http://opcfoundation.org/UA/2008/02/Types.xsd
OPC UA Service Message Definitions The WSDL for all service messages defined in the OPC UA specifications. Opc.Ua.Services.wsdl http://opcfoundation.org/UA/schemas/1.02/Opc.Ua.Services.wsdl http://opcfoundation.org/UA/2008/02/Services.wsdl
OPC UA Service Interface Definitions The WSDL for logical groupings of OPC UA Services. Opc.Ua.Endpoints.wsdl http://opcfoundation.org/UA/schemas/1.02/Opc.Ua.Endpoints.wsdl http://opcfoundation.org/UA/2008/02/Endpoints.wsdl
The XML schema for all data types defined in the DI specification. Opc.Ua.Di.Types.xsd http://opcfoundation.org/UA/schemas/DI/1.00/Opc.Ua.Di.Types.xsd http://opcfoundation.org/UA/DI/Types.xsd
The XML schema for all data types defined in the ADI specification. Opc.Ua.Adi.Types.xsd http://opcfoundation.org/UA/schemas/ADI/1.00/Opc.Ua.Adi.Types.xsd http://opcfoundation.org/UA/ADI/Types.xsd
Secured Application Schema The XML schema for import/export of application configuration information. SecuredApplication.xsd http://opcfoundation.org/UA/schemas/1.02/SecuredApplication.xsd http://opcfoundation.org/UA/2011/03/SecuredApplication.xsd
UANodeSet Schema The XML schema used to persist an OPC UA information model. UANodeSet.xsd http://opcfoundation.org/UA/schemas/1.02/UANodeSet.xsd http://opcfoundation.org/UA/2011/03/UANodeSet.xsd
UANodeSet Schema A support file for the XML schema used to persist an OPC UA information model. UAVariant.xsd http://opcfoundation.org/UA/schemas/1.02/UAVariant.xsd
OPC UA Node Set (All) The UANodeSet for all Nodes defined by the OPC UA specifications. Opc.Ua.NodeSet2.xml http://opcfoundation.org/UA/schemas/1.02/Opc.Ua.NodeSet2.xml
OPC UA Node Set (Part 3) The UANodeSet for all Nodes defined by Part 3 of the OPC UA specification. Opc.Ua.NodeSet2.Part3.xml http://opcfoundation.org/UA/schemas/1.02/Opc.Ua.NodeSet2.Part3.xml
OPC UA Node Set (Part 4) The UANodeSet for all Nodes defined by Part 4 of the OPC UA specification. Opc.Ua.NodeSet2.Part4.xml http://opcfoundation.org/UA/schemas/1.02/Opc.Ua.NodeSet2.Part4.xml
OPC UA Node Set (Part 5) The UANodeSet for all Nodes defined by Part 5 of the OPC UA specification. Opc.Ua.NodeSet2.Part5.xml http://opcfoundation.org/UA/schemas/1.02/Opc.Ua.NodeSet2.Part5.xml
OPC UA Node Set (Part 8) The UANodeSet for all Nodes defined by Part 8 of the OPC UA specification. Opc.Ua.NodeSet2.Part8.xml http://opcfoundation.org/UA/schemas/Opc.Ua.NodeSet2.Part8.xml
OPC UA Node Set (Part 9) The UANodeSet for all Nodes defined by Part 9 of the OPC UA specification. Opc.Ua.NodeSet2.Part9.xml http://opcfoundation.org/UA/schemas/1.02/Opc.Ua.NodeSet2.Part9.xml
OPC UA Node Set (Part 10) The UANodeSet for all Nodes defined by Part 10 of the OPC UA specification. Opc.Ua.NodeSet2.Part10.xml http://opcfoundation.org/UA/schemas/1.02/Opc.Ua.NodeSet2.Part10.xml
OPC UA Node Set (Part 11) The UANodeSet for all Nodes defined by Part 11 of the OPC UA specification. Opc.Ua.NodeSet2.Part11.xml http://opcfoundation.org/UA/schemas/1.02/Opc.Ua.NodeSet2.Part11.xml
OPC UA Node Set (Part 13) The UANodeSet for all Nodes defined by Part 13 of the OPC UA specification. Opc.Ua.NodeSet2.Part13.xml http://opcfoundation.org/UA/schemas/1.02/Opc.Ua.NodeSet2.Part13.xml
DI NodeSet The UANodeSet for all Nodes defined by the DI specification. Opc.Ua.Di.NodeSet2.xml http://opcfoundation.org/UA/schemas/DI/1.00/Opc.Ua.Di.NodeSet2.xml
ADI NodeSet The UANodeSet for all Nodes defined by the ADI specification. Opc.Ua.Adi.NodeSet2.xml http://opcfoundation.org/UA/schemas/ADI/1.00/Opc.Ua.Adi.NodeSet2.xml
OPC Binary Type Schema The XML schema used to describe the layout of binary encoding structures. OPC BinarySchema.xsd http://opcfoundation.org/UA/schemas/1.02/OPCBinarySchema.xsd http://opcfoundation.org/BinarySchema/
OPC UA Binary Type Definitions The OPC Binary schema for all data types defined in the OPC UA specifications. Opc.Ua.Types.bsd http://opcfoundation.org/UA/schemas/1.02/Opc.Ua.Types.bsd
The OPC Binary schema for all data types defined in the DI specification. Opc.Ua.Di.Types.bsd http://opcfoundation.org/UA/schemas/DI/1.00/Opc.Ua.Di.Types.bsd http://opcfoundation.org/UA/DI/Types.bsd
The OPC Binary schema for all data types defined in the ADI specification. Opc.Ua.Adi.Types.bsd http://opcfoundation.org/UA/schemas/ADI/1.00/Opc.Ua.Adi.Types.bsd http://opcfoundation.org/UA/ADI/Types.bsd
OPC UA Attribute Ids The numeric identifier for all OPC UA Node attributes. AttributeIds.csv http://opcfoundation.org/UA/schemas/1.02/AttributeIds.csv
OPC UA Status Codes The numeric identifier for all StatusCodes defined in the OPC UA specifications. StatusCode.csv http://opcfoundation.org/UA/schemas/1.02/StatusCode.csv
OPC UA NodeIds The numeric identifier for all NodeIds defined in the OPC UA specifications. NodeIds.csv http://opcfoundation.org/UA/schemas/1.02/NodeIds.csv
*/
wget("http://opcfoundation.org/UA/schemas/1.02/Opc.Ua.NodeSet2.xml");
202 changes: 202 additions & 0 deletions code_gen/generate_address_space.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
var util = require('util');
var xml = require("node-expat");
var fs = require("fs");
//xx var csv = require("csv");
//xx var sprintf = require("sprintf").sprintf;
var assert = require("assert");

var ec = require("../lib/encode_decode");

function add_alias(alias_name,nodeid) {

console.log(" adding alias "+ alias_name + " => "+ nodeid);
}
function addUAObject(obj) {
console.log(" adding addUAObject ");
console.dir(obj);
}


function coerceReaderState(options_or_reader_state)
{
if (!(options_or_reader_state instanceof ReaderState)) {
return new ReaderState(options_or_reader_state);
}
var reader = options_or_reader_state;
for( var name in reader.parser) {
if (reader.parser.hasOwnProperty(name)) {
reader.parser[name] = coerceReaderState(reader.parser[name]);
}
}
return reader;
}

function ReaderState(options){
this.parser= options.parser || {};
this._init = options.init;
this._startElement = options.startElement;
this._endElement = options.endElement;

var reader = this;
for( var name in reader.parser) {
if (reader.parser.hasOwnProperty(name)) {
reader.parser[name] = coerceReaderState(reader.parser[name]);
}
}
}

ReaderState.prototype.init= function(name,attrs) {
this.attrs = attrs;
assert(this.attrs);
if (this._init) {
this._init(name,attrs);
}
};

ReaderState.prototype.startElement= function(name,attrs) {

if (this.parser.hasOwnProperty(name)) {
this.engine._promote(this.parser[name],name,attrs);
} else if (this._startElement) {
this._startElement(name,attrs);
}
};
ReaderState.prototype.endElement= function(name) {
assert(this.attrs);
if (this._endElement) { this._endElement(name);}
if (name==this.name) {
// this is the end
this.engine._demote(this);
}
};

ReaderState.prototype.onText = function(text){
this.text = text;
};

function Xml2Json(state) {

state = coerceReaderState(state);

this.state_stack = [];
this.current_state = null;
this._promote(state);
}

Xml2Json.prototype._promote = function (new_state,name,attr) {
attr = attr || {};
new_state.name = name;
new_state.parent = this.current_state;
new_state.engine = this;

this.state_stack.push(this.current_state);
this.current_state = new_state;
this.current_state.init(name,attr);
};

Xml2Json.prototype._demote = function(cur_state) {
assert(this.current_state===cur_state);
this.current_state = this.state_stack.pop();
};


Xml2Json.prototype.parse = function(xmlFile) {
var self = this;
var parser = new xml.Parser();
parser.on('startElement',function(name,attrs) {
self.current_state.startElement(name,attrs);
});
parser.on('endElement', function(name) {
self.current_state.endElement(name);
});
parser.on('text', function(text) {
self.current_state.onText(text);
});
parser.write(fs.readFileSync(xmlFile));
};


function generate_address_space() {

var xmlFile = "./Opc.Ua.NodeSet2.xml";


var state_Alias = { endElement: function() { add_alias(this.attrs["Alias"],this.text); } };

var references_parser = {
init: function() {
this.parent.obj.references = [];
this.array = this.parent.obj.references;
},
startElement: function(name,attrs){
// console.log("name " ,name);
},
parser: {
'Reference': {
endElement: function() {
this.parent.array.push({
referenceType: this.attrs["ReferenceType"],
isForward: this.attrs["IsForward"],
nodeId: ec.makeNodeId(this.text)
});
}
}
}
};

var state_UAObject= {
init: function(name,attrs) {
this.obj = {};
this.obj.isAbstract = attrs["IsAbstract"] || null;
this.obj.nodeId = ec.makeNodeId(attrs["NodeId"]) || null;
},
endElement: function(name) {
addUAObject(this.obj);
},
parser: {
'DisplayName': {endElement: function() { this.parent.obj.displayName = this.text; }},
'Description': {endElement: function() { this.parent.obj.description = this.text; }},
'References': references_parser
}
};
var state_UAVariable = {
init: function(name,attrs) {
this.obj = {};
this.obj.browseName = attrs["BrowseName"] || null;
this.obj.parentNodeId = attrs["ParentNodeId"] || null;
this.obj.dataType = attrs["DataType"] || null;
this.obj.valueRank = attrs["ValueRank"] || null;
this.obj.minimumSamplingInterval= attrs["MinimumSamplingInterval"] || null;
this.obj.nodeId = ec.makeNodeId(attrs["NodeId"]) || null;

},
endElement: function(name) {
addUAVariable(this.obj);
},
parser: {
'DisplayName': {endElement: function() { this.parent.obj.displayName = this.text; }},
'Description': {endElement: function() { this.parent.obj.description = this.text; }},
'References': references_parser,
'Value': {}

}

};
var state_0 = {
parser: {
'UAObject': state_UAObject,
'UAObjectType': state_UAObject,
'UAReferenceType': state_UAObject,
'UADataType': state_UAObject,
'Aliases': { parser: { 'Alias': state_Alias } },
'UAVariable': state_UAVariable,
}
};

var parser = new Xml2Json(state_0);
parser.parse(xmlFile);


}

generate_address_space();
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
"node-int64": "~0.3.0",
"easy-table": "~0.3.0",
"tracer": "~0.6.2",
"base64-js": "0.0.6"
"base64-js": "0.0.6",
"request": "~2.33.0",
"progress": "~1.1.3"
}
}

0 comments on commit 1733e23

Please sign in to comment.