12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808 |
- const express = require("express");
- const execSync = require('child_process').execSync;
- var parser = require('xml2json');
- const fs = require('fs');
- var cors = require('cors');
- const bodyParser = require("body-parser");
- var mysql = require('mysql2/promise');
- const bluebird = require('bluebird');
- const app = express();
- app.use(cors());
- const port = 3001;
- app.use(bodyParser.urlencoded({ extended: false }));
- app.use(bodyParser.json());
- let conf = {
- connectionLimit : 10,
- host : '127.0.0.1',
- user : 'ds',
- password : 'EmcoAdmin!',
- database : 'modeler',
- Promise: bluebird
- }
- const jsn = require("./base.json");
- const di = require("./di.json");
- const ia = require("./ia.json");
- const mach = require("./machinery.json");
- const mt = require("./mt.json");
- let ns_array = [];
- let nsray = [];
- nsray.push(jsn);
- nsray.push(di);
- nsray.push(ia);
- nsray.push(mach);
- nsray.push(mt);
- /*
- async function gen_query(sql, params){
- const connection = await mysql.createConnection(conf);
- const [results, ] = await connection.execute(sql, params);
- //console.log(results);
- return results;
- }*/
- function database_connection() {
- pool = mysql.createPool(conf);
- pool.getConnection(function(err, connection) {
- if(err) {
- logger.error('[ERROR] Connecting to database "' + err.toString() + '"');
- setTimeout(function() { database_connection(); }, 2500);
- }
- else
- {
- pool.query('SET NAMES utf8');
- pool.query('SET CHARACTER SET utf8');
- logger.trace('[INFO] Connected to database and set utf8!');
- }
- })};
- database_connection();
- function inverse(dev){
- if("IsForward" in dev){
- if(dev.IsForward === "false"){
- return true;
-
- }else{
- return false;
- }
- }else{
- return false;
- }
- }
- function forward(dev){
- var b = true;
- if("IsForward" in dev){
- if(dev.IsForward === "false"){
- b = false;
- }
- }else{
- b = true;
- }
- return b;
- }
- function sortNS(files){
- let nsets = [];
-
- for(let x = 0; x<files.length; x++){
- if("RequiredModel" in files[x].UANodeSet.Models.Model){
- if(Array.isArray(files[x].UANodeSet.Models.Model.RequiredModel)){
- var len = files[x].UANodeSet.Models.Model.RequiredModel.length;
- for(let y = 0; y < len; y++){
- files[x].UANodeSet.Models.Model.RequiredModel[y]
- }
- }else{
-
- }
- }else{
- nsets.push(files[x].UANodeSet.Models.Model.ModelUri);
- }
- }
- }
- function get_Children(jsnob, nid, ret_obj){
- const entities = ['UAObjectType','UAObject','UAVariableType','UAVariable', 'UADataType', 'UAReferenceType', 'UAMethod'];
- const set = jsnob.UANodeSet;
- for(let y = 0; y< entities.length; y++){
- if(entities[y] in set){
- try{
- const entry = set[entities[y]];
- if(Array.isArray(entry)){
- for (let i = 0; i < entry.length;i++){
- if(Object.keys(entry[i].References).length === 0){
- }else{
- if(Array.isArray(entry[i].References.Reference)){
- for (let x = 0; x < entry[i].References.Reference.length;x++){
- if(entry[i].References.Reference[x].$t === nid){
- if(inverse(entry[i].References.Reference[x])){
- let zobj= overwriteNode(entry[i], nid, entities[y], getIndexArray(jsnob));
- if(!checkDouble(zobj,ret_obj)){
- ret_obj.push(zobj);
- }
- }
- }
- }
- }else{
- if(entry[i].References.Reference.$t === nid){
- if(inverse(entry[i].References.Reference)){
- let zobj= overwriteNode(entry[i], nid, entities[y], getIndexArray(jsnob));
- if(!checkDouble(zobj,ret_obj)){
- ret_obj.push(zobj);
- }
- }
- }
- }
- }
- }
- }else{
- if(Object.keys(entry.References).length === 0){
- }else{
- if(Array.isArray(entry.References.Reference)){
- for (let x = 0; x < entry.References.Reference.length;x++){
- if(entry.References.Reference[x].$t === nid){
- if(inverse(entry.References.Reference[x])){
- let zobj= overwriteNode(entry, nid, entities[y], getIndexArray(jsnob));
- if(!checkDouble(zobj,ret_obj)){
- ret_obj.push(zobj);
- }
- }
- }
- }
- }else{
- if(entry.References.Reference.$t === nid){
- if(inverse(entry.References.Reference)){
- let zobj= overwriteNode(entry, nid, entities[i], getIndexArray(jsnob));
- if(!checkDouble(zobj,ret_obj)){
- ret_obj.push(zobj);
- }
- }
- }
- }
- }
- }
- }catch(err){
- console.log(err);
- }
- }
- }
- }
- function getAllChildren(nid, ret_obj){
- for(let ix = 0; ix < ns_array.length; ix++){
- get_Children(ns_array[ix][0], nid, ret_obj);
- }
- }
- function getIndexObj(jsnob, ns){
- var uri = ns.UANodeSet.Models.Model.ModelUri;
- if(uri == "http://opcfoundation.org/UA/"){
- return 0;
- }
- console.log(uri);
- let uris = {};
- if(jsnob.UANodeSet.NamespaceUris != undefined){
- uris = jsnob.UANodeSet.NamespaceUris.Uri;
- console.log(uris);
- }else{
- return 0;
- }
- for(let i = 0; i < uris.length; i++){
- console.log(uris[i]);
- if(uris[i] == uri){
- return i+1;
- }
- }
- return undefined;
- }
- function getIndexName(jsnob, name){
- if(name == "http://opcfoundation.org/UA/"){
- return 0;
- }
- let uris = {};
- if(jsnob.UANodeSet.NamespaceUris != undefined){
- uris = jsnob.UANodeSet.NamespaceUris.Uri;
- }else{
- return 0;
- }
- for(let i = 0; i < uris.length; i++){
- if(uris[i] == name){
- return i+1;
- }
- }
- return undefined;
- }
- function getIndexArray(tobj){
- for(let i = 0; i < ns_array.length;i++){
- console.log(ns_array[i][1]);
- if(tobj.UANodeSet.Models.Model.ModelUri === ns_array[i][0].UANodeSet.Models.Model.ModelUri){
- return i;
- }
- }
- return undefined;
- }
- function getNode(jsnob, ns, id){
- let uris = {};
- var ns_uri = '';
- if(jsnob.UANodeSet.NamespaceUris){
- uris = jsnob.UANodeSet.NamespaceUris.Uri;
- ns_uri = uris[ns-1];
- }
- for(let i = 0; i < ns_array.length; i++){
- if(ns_array[i][0].UANodeSet.Models.Model.ModelUri == ns_uri){
- return i;
- }
- }
- return -1;
- }
- function overwriteNode(nobj, nid, nc, ns){
- var nclass = "";
- switch(nc){
- case "UAObjectType":
- case "UAObject":
- case "UAVariableType":
- case "UADataType":
- case "UAReferenceType": nclass = "Object"; break;
- case "UAVariable": nclass = "Variable"; break;
- case "UAMethod": nclass = "Method"; break;
- default: nclass = "Object";
- }
- const node = {
- id:nobj.NodeId,
- text:nobj.DisplayName,
- children: true,
- data:{
- browsename: nobj.BrowseName,
- namespace: ns,
- elementclass: nc,
- nodeclass: nclass,
- parentNode: nid,
- parentid: "ParentNodeId" in nobj ? nobj.ParentNodeId : null,
- description: "Description" in nobj ? nobj.Description : null,
- notifier: "EventNotifier" in nobj ? nobj.EventNotifier : null, //Object
- isabstract: "IsAbstract" in nobj ? nobj.IsAbstract : null, //ObjectType
- datatype: "DataType" in nobj ? nobj.DataType : null, //Variable
- value: "Value" in nobj ? nobj.Value : null, //Variable
- arraydimensions: "ArrayDimensions" in nobj ? nobj.ArrayDimensions : null, //Variable
- references: "References" in nobj ? nobj.References : null
- }
-
- }
- return node;
- }
- function searchNode(id){
- const entities = ['UAObjectType','UAObject','UAVariableType','UAVariable', 'UADataType', 'UAReferenceType', 'UAMethod']; //7
- var nid = "";
- var jsnob = {};
- if(id.includes("ns=")){
- var ns = id.substring(id.length - 4);
- const ns1 = ns.split(";");
- var nsidx = parseInt(ns1[0]);
- jsnob = ns_array[nsidx][0];
- }else{
- nid = id;
- jsnob = ns_array[0][0];
- }
- const set = jsnob.UANodeSet;
- for(let i = 0; i< entities.length; i++){
- if(entities[i] in set){
- console.log(set.Models.Model.ModelUri+" has a "+entities[i]);
- if(Array.isArray(set[entities[i]])){
- for(let x = 0; x < set[entities[i]].length;x++){
- if(set[entities[i]][x].NodeId === nid){
- let nobj = set[entities[i]][x];
- const node = overwriteNode(nobj, null, entities[i], getIndexArray(jsnob));
- return node;
- }
- }
- }
- }
- }
- return null;
- }
- function p2json(name, shorty){
- try{
- const nn = name+".xml";
- var nnn = shorty+".json";
- fs.readFile( nn, function(err, data){
- //fs.readFile( "Opc.Ua.NodeSet2.xml", function(err, data){
- let jsn = parser.toJson(data);
- fs.writeFileSync(nnn, jsn);
- });
- }catch(err){
- console.log('not work');}
- }
- /*
- function listObjType(){
- var keys = [];
- console.log("ObjectTypes:");
- let obj = jsn.UANodeSet.UAObjectType; //base
- var sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = di.UANodeSet.UAObjectType; //base
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = ia.UANodeSet.UAObjectType; //base
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = mach.UANodeSet.UAObjectType; //base
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = mt.UANodeSet.UAObjectType; //base
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- console.log(keys);
- }
- listObjType();
- function listObj(){
- var keys = [];
- console.log("Objects:");
- let obj = jsn.UANodeSet.UAObject; //base
- var sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = di.UANodeSet.UAObject; //base
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = ia.UANodeSet.UAObject; //base
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = mach.UANodeSet.UAObject; //base
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = mt.UANodeSet.UAObject; //base
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- console.log(keys);
- }
- listObj();
- function listVar(){
- var keys = [];
- console.log("Variables:");
- let obj = jsn.UANodeSet.UAVariable; //base
- var sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = di.UANodeSet.UAVariable; //base
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = ia.UANodeSet.UAVariable; //base
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = mach.UANodeSet.UAVariable; //base
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = mt.UANodeSet.UAVariable; //base
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- console.log(keys);
- }
- listVar();
- function listVarTypes(){
- var keys = [];
- console.log("VariableTypes:");
- let obj = jsn.UANodeSet.UAVariableType; //base
- var sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = di.UANodeSet.UAVariableType; //base
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = ia.UANodeSet.UAVariableType; //base
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = mach.UANodeSet.UAVariableType; //base
- if(obj !== undefined){
- if(Array.isArray(obj)){
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }}else{
- let arr = Object.keys(obj);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- }
- obj = mt.UANodeSet.UAVariableType; //base
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- console.log(keys);
- }
- listVarTypes();
- function listMethod(){
- var keys = [];
- console.log("Methods:");
- let obj = jsn.UANodeSet.UAMethod; //base
- var sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = di.UANodeSet.UAMethod; //base
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = ia.UANodeSet.UAMethod; //base
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = mach.UANodeSet.UAMethod; //base
- if(obj !== undefined){
- if(Array.isArray(obj)){
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }}else{
- let arr = Object.keys(obj);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }}
- obj = mt.UANodeSet.UAMethod; //base
- if(obj !== undefined){
- if(Array.isArray(obj)){
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }}else{
- let arr = Object.keys(obj);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }}
- console.log(keys);
- }
- listMethod();
- function listDataType(){
- var keys = [];
- console.log("DataType:");
- let obj = jsn.UANodeSet.UADataType; //base
- var sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = di.UANodeSet.UADataType; //base
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = ia.UANodeSet.UADataType; //base
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = mach.UANodeSet.UADataType; //base
- if(obj !== undefined){
- if(Array.isArray(obj)){
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }}else{
- let arr = Object.keys(obj);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }}
- obj = mt.UANodeSet.UADataType; //base
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- console.log(keys);
- }
- listDataType();
- function listRefType(){
- var keys = [];
- console.log("ReferenceTypes:");
- let obj = jsn.UANodeSet.UAReferenceType; //base
- var sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = di.UANodeSet.UAReferenceType; //base
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = ia.UANodeSet.UAReferenceType; //base
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }
- obj = mach.UANodeSet.UAReferenceType; //base
- if(obj !== undefined){
- if(Array.isArray(obj)){
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }}else{
- let arr = Object.keys(obj);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }}
- obj = mt.UANodeSet.UAReferenceType; //base
- if(obj !== undefined){
- if(Array.isArray(obj)){
- sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- let arr = Object.keys(obj[i]);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }}else{
- let arr = Object.keys(obj);
- for(let x = 0; x < arr.length; x++){
- if(!keys.includes(arr[x])){
- keys.push(arr[x]);
- }
- }
- }}
- console.log(keys);
- }
- listRefType();
- */
- let arref = [];
- async function checkRefs(obj, nid){
- try{
- var idx = 0;
- if(nid.includes('ns=')){
- var ix = nid.indexOf(';');
- var ns = nid.substring(3,ix);
- idx = parseInt(ns);
- }
- if(obj['References']){
- let refs = obj['References'].Reference;
- if(Array.isArray(refs)){
- for(let i = 0; i < refs.length; i++){
- var entry = refs[i];
- var nid_t = "";
- if(nid.includes('i=')){
- nid_t = 'Numeric';
- }else if(nid.includes('s=')){
- nid_t = 'String';
- }
- var nst = 0;
- console.log(entry);
- var target = "";
- if(entry['$t']){
- target = entry['$t'];
- if(target.includes('ns=')){
- var ix = target.indexOf(';');
- var ns = target.substring(3,ix);
- nst = parseInt(ns);
- }
- }
- var command = "INSERT INTO ns0references(nodeidorigin, nodeidtype, nsindex, referencetype, isforward, target, ns_target) VALUES ('"+nid+"', '"+nid_t+"', '"+idx+"', '"+entry['ReferenceType']+"', '"+entry['IsForward']+"', '"+target+"', '"+nst+"');";
- console.log(command);
- var ret = pool.query(command);
- }
- }else{
- var entry = refs;
- var nid_t = "";
- if(nid.includes('i=')){
- nid_t = 'Numeric';
- }else if(nid.includes('s=')){
- nid_t = 'String';
- }
- var nst = 0;
- console.log(entry);
- var target = "";
- if(entry['$t']){
- target = entry['$t'];
- if(target.includes('ns=')){
- var ix = target.indexOf(';');
- var ns = target.substring(3,ix);
- nst = parseInt(ns);
- }
- }
- var command = "INSERT INTO ns0references(nodeidorigin, nodeidtype, nsindex, referencetype, isforward, target, ns_target) VALUES ('"+nid+"', '"+nid_t+"', '"+idx+"', '"+entry['ReferenceType']+"', '"+entry['IsForward']+"', '"+target+"', '"+nst+"');";
- console.log(command);
- var ret = pool.query(command);
- }
- }
- }catch(err){
- console.log(err);
- }
- }
- app.get('/obj', async function(req, res){
- try{
- var key = req.body;
- let obj = jsn.UANodeSet.UAObject; //base
- if(Array.isArray(obj)){
- var sz = obj.length;
- for(let i = 0; i < sz; i++){
- var entry = obj[i];
- var nid = entry['NodeId'];
- var idx = 0;
- if(nid.includes('ns=')){
- var ix = nid.indexOf(';');
- var ns = nid.substring(3,ix);
- idx = parseInt(ns);
- }
- checkRefs(entry, nid);
- var nid_t = "";
- if(nid.includes('i=')){
- nid_t = 'Numeric';
- }else if(nid.includes('s=')){
- nid_t = 'String';
- }
- var eventnot = 0;
- if(entry['EventNotifier']){
- eventnot = parseInt(entry['EventNotifier']);
- }
- var command = "INSERT INTO ns0objects(nodeid, nodeidtype, nsindex, name, displayname, browsename, typedefinition, description, eventnotifier, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', 'TBD','"+entry['Description']+"', '"+eventnot+"', '"+entry['Documentation']+"');";
- console.log(command);
- var ret = pool.query(command);
- }
-
- }else{
- var entry = obj;
- var nid = entry['NodeId'];
- var idx = 0;
- if(nid.includes('ns=')){
- var ix = nid.indexOf(';');
- var ns = nid.substring(3,ix);
- idx = parseInt(ns);
- }
- checkRefs(entry, nid);
- var nid_t = "";
- if(nid.includes('i=')){
- nid_t = 'Numeric';
- }else if(nid.includes('s=')){
- nid_t = 'String';
- }
- var eventnot = 0;
- if(entry['EventNotifier']){
- eventnot = parseInt(entry['EventNotifier']);
- }
- var command = "INSERT INTO ns0objects(nodeid, nodeidtype, nsindex, name, displayname, browsename, typedefinition, description, eventnotifier, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', 'TBD','"+entry['Description']+"', '"+eventnot+"', '"+entry['Documentation']+"');";
- console.log(command);
- var ret = pool.query(command);
- }
- res.json({result:'OK',success:true});
- }catch(err){
- console.log(err);
- res.json({result:"NOK"});
- }
- })
- app.get('/objtypes', async function(req, res){
- try{
- var key = req.body;
- let obj = jsn.UANodeSet.UAObjectType; //base
- if(Array.isArray(obj)){
- var sz = obj.length;
- console.log(sz);
- for(let i = 0; i < sz; i++){
- var entry = obj[i];
- var nid = entry['NodeId'];
- var idx = 0;
- if(nid.includes('ns=')){
- var ix = nid.indexOf(';');
- var ns = nid.substring(3,ix);
- idx = parseInt(ns);
- }
- checkRefs(entry, nid);
- var nid_t = "";
- if(nid.includes('i=')){
- nid_t = 'Numeric';
- }else if(nid.includes('s=')){
- nid_t = 'String';
- }
- var isabstr = "TBD";
- if(entry['IsAbstract']){
- isabstr = entry['IsAbstract'];
- }
- var command = "INSERT INTO ns0objecttypes(nodeid, nodeidtype, nsindex, name, displayname, browsename, isabstract, description, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"','"+isabstr+"', '"+entry['Description']+"', '"+entry['Documentation']+"');";
- var ret = pool.query(command);
- }
- res.json({result:'OK',success:true});
- }else{
- var entry = obj;
- var nid = entry['NodeId'];
- var idx = 0;
- if(nid.includes('ns=')){
- var ix = nid.indexOf(';');
- var ns = nid.substring(3,ix);
- idx = parseInt(ns);
- }
- checkRefs(entry, nid);
- var nid_t = "";
- if(nid.includes('i=')){
- nid_t = 'Numeric';
- }else if(nid.includes('s=')){
- nid_t = 'String';
- }
- var isabstr = "TBD";
- if(entry['IsAbstract']){
- isabstr = entry['IsAbstract'];
- }
- var command = "INSERT INTO ns0objecttypes(nodeid, nodeidtype, nsindex, name, displayname, browsename, isabstract, description, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"','"+isabstr+"', '"+entry['Description']+"', '"+entry['Documentation']+"');";
- var ret = pool.query(command);
- res.json({result:'OK',success:true});
- }
-
- }catch(err){
- console.log(err);
- res.json({result:"NOK"});
- }
- })
- app.get('/var', async function(req, res){
- try{
- var key = req.body;
- let obj = jsn.UANodeSet.UAVariable; //base
- if(Array.isArray(obj)){
- var sz = obj.length;
- for(let i = 0; i < sz; i++){
- var entry = obj[i];
- var nid = entry['NodeId'];
- var idx = 0;
- if(nid.includes('ns=')){
- var ix = nid.indexOf(';');
- var ns = nid.substring(3,ix);
- idx = parseInt(ns);
- }
- checkRefs(entry, nid);
- var nid_t = "";
- if(nid.includes('i=')){
- nid_t = 'Numeric';
- }else if(nid.includes('s=')){
- nid_t = 'String';
- }
- var valrank = 0;
- if(entry['ValueRank']){
- valrank = entry['ValueRank'];
- }
- var arrdim = 0;
- if(entry['ArrayDimensions']){
- arrdim = entry['ArrayDimensions'];
- }
- var acclev = 0;
- if(entry['AccessLevel']){
- acclev = entry['AccessLevel'];
- }
- var minsamp = 0;
- if(entry['MinimumSamplingInterval']){
- minsamp = entry['MinimumSamplingInterval'];
- }
- var command = "INSERT INTO ns0variables(nodeid, nodeidtype, nsindex, name, displayname, browsename, parentid, description, datatype, valuerank, arraydimensions, accesslevel, minsamplinginterval, releasestatus) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"','#', '"+entry['Description']+"', '"+entry['DataType']+"', '"+valrank+"', '"+arrdim+"', '"+acclev+"', '"+minsamp+"', '"+entry['ReleaseStatus']+"');";
- console.log(command);
- var ret = pool.query(command);
- }
- res.json({result:'OK',success:true});
- }else{
- var entry = obj;
- var nid = entry['NodeId'];
- var idx = 0;
- if(nid.includes('ns=')){
- var ix = nid.indexOf(';');
- var ns = nid.substring(3,ix);
- idx = parseInt(ns);
- }
- checkRefs(entry, nid);
- var nid_t = "";
- if(nid.includes('i=')){
- nid_t = 'Numeric';
- }else if(nid.includes('s=')){
- nid_t = 'String';
- }
- var valrank = 0;
- if(entry['ValueRank']){
- valrank = entry['ValueRank'];
- }
- var arrdim = 0;
- if(entry['ArrayDimensions']){
- arrdim = entry['ArrayDimensions'];
- }
- var acclev = 0;
- if(entry['AccessLevel']){
- acclev = entry['AccessLevel'];
- }
- var minsamp = 0;
- if(entry['MinimumSamplingInterval']){
- minsamp = entry['MinimumSamplingInterval'];
- }
- var command = "INSERT INTO ns0variables(nodeid, nodeidtype, nsindex, name, displayname, browsename, parentid, description, datatype, valuerank, arraydimensions, accesslevel, minsamplinginterval, releasestatus) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"','#', '"+entry['Description']+"', '"+entry['DataType']+"', '"+valrank+"', '"+arrdim+"', '"+acclev+"', '"+minsamp+"', '"+entry['ReleaseStatus']+"');";
- console.log(command);
- var ret = pool.query(command);
- res.json({result:'OK',success:true});
- }
- }catch(err){
- console.log(err);
- res.json({result:"NOK"});
- }
- })
- app.get('/vartypes', async function(req, res){
- try{
- var key = req.body;
- let obj = jsn.UANodeSet.UAVariableType; //base
- if(Array.isArray(obj)){
- var sz = obj.length;
- for(let i = 0; i < sz; i++){
- console.log(obj[i]);
- var entry = obj[i];
- var nid = entry['NodeId'];
- var idx = 0;
- if(nid.includes('ns=')){
- var ix = nid.indexOf(';');
- var ns = nid.substring(3,ix);
- idx = parseInt(ns);
- }
- checkRefs(entry, nid);
- var nid_t = "";
- if(nid.includes('i=')){
- nid_t = 'Numeric';
- }else if(nid.includes('s=')){
- nid_t = 'String';
- }
- var valrank = 0;
- if(entry['ValueRank']){
- valrank = entry['ValueRank'];
- }
- var arrdim = 0;
- if(entry['ArrayDimensions']){
- console.log('Here');
- console.log(entry['ArrayDimensions']);
- arrdim = entry['ArrayDimensions'];
- }
- var isabstr = "TBD";
- if(entry['IsAbstract']){
- isabstr = entry['IsAbstract'];
- }
- var command = "INSERT INTO ns0variabletypes(nodeid, nodeidtype, nsindex, name, displayname, browsename, parentid, description, datatype, valuerank, arraydimensions, isabstract, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"','#', '"+entry['Description']+"', '"+entry['DataType']+"', '"+valrank+"', '"+arrdim+"', '"+isabstr+"', '"+entry['Documentation']+"');";
- console.log(command);
- var ret = pool.query(command);
- }
- }else{
- var entry = obj;
- var nid = entry['NodeId'];
- var idx = 0;
- if(nid.includes('ns=')){
- var ix = nid.indexOf(';');
- var ns = nid.substring(3,ix);
- idx = parseInt(ns);
- }
- checkRefs(entry, nid);
- var nid_t = "";
- if(nid.includes('i=')){
- nid_t = 'Numeric';
- }else if(nid.includes('s=')){
- nid_t = 'String';
- }
- var valrank = 0;
- if(entry['ValueRank']){
- valrank = entry['ValueRank'];
- }
- var arrdim = 0;
- if(entry['ArrayDimensions']){
- console.log('Here');
- console.log(entry['ArrayDimensions']);
- arrdim = entry['ArrayDimensions'];
- }
- var isabstr = "TBD";
- if(entry['IsAbstract']){
- isabstr = entry['IsAbstract'];
- }
- var command = "INSERT INTO ns0variabletypes(nodeid, nodeidtype, nsindex, name, displayname, browsename, parentid, description, datatype, valuerank, arraydimensions, isabstract, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"','#', '"+entry['Description']+"', '"+entry['DataType']+"', '"+valrank+"', '"+arrdim+"', '"+isabstr+"', '"+entry['Documentation']+"');";
- console.log(command);
- var ret = pool.query(command);
- }
- res.json({result:'OK',success:true});
- }catch(err){
- console.log(err);
- res.json({result:"NOK"});
- }
- })
- app.get('/methods', async function(req, res){
- try{
- var key = req.body;
- let obj = jsn.UANodeSet.UAMethod; //base
- if(Array.isArray(obj)){
- var sz = obj.length;
- for(let i = 0; i < sz; i++){
- var entry = obj[i];
- var nid = entry['NodeId'];
- var idx = 0;
- if(nid.includes('ns=')){
- var ix = nid.indexOf(';');
- var ns = nid.substring(3,ix);
- idx = parseInt(ns);
- }
- checkRefs(entry, nid);
- var nid_t = "";
- if(nid.includes('i=')){
- nid_t = 'Numeric';
- }else if(nid.includes('s=')){
- nid_t = 'String';
- }
- var command = "INSERT INTO ns0methods(nodeid, nodeidtype, nsindex, name, displayname, browsename, parentid, description, methoddeclarationid) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '#', '"+entry['Description']+"', '"+entry['MethodDeclarationId']+"');";
- console.log(command);
- var ret = pool.query(command);
- }
- }else{
- var entry = obj;
- var nid = entry['NodeId'];
- var idx = 0;
- if(nid.includes('ns=')){
- var ix = nid.indexOf(';');
- var ns = nid.substring(3,ix);
- idx = parseInt(ns);
- }
- checkRefs(entry, nid);
- var nid_t = "";
- if(nid.includes('i=')){
- nid_t = 'Numeric';
- }else if(nid.includes('s=')){
- nid_t = 'String';
- }
- var command = "INSERT INTO ns0methods(nodeid, nodeidtype, nsindex, name, displayname, browsename, parentid, description, methoddeclarationid) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '#', '"+entry['Description']+"', '"+entry['MethodDeclarationId']+"');";
- console.log(command);
- var ret = pool.query(command);
- }
- res.json({result:'OK',success:true});
- }catch(err){
- console.log(err);
- res.json({result:"NOK"});
- }
- })
- app.get('/datatypes', async function(req, res){
- try{
- var key = req.body;
- let obj = jsn.UANodeSet.UADataType; //base
- if(Array.isArray(obj)){
- var sz = obj.length;
- for(let i = 0; i < sz; i++){
- var entry = obj[i];
- var nid = entry['NodeId'];
- var idx = 0;
- if(nid.includes('ns=')){
- var ix = nid.indexOf(';');
- var ns = nid.substring(3,ix);
- idx = parseInt(ns);
- }
- checkRefs(entry, nid);
- var nid_t = "";
- if(nid.includes('i=')){
- nid_t = 'Numeric';
- }else if(nid.includes('s=')){
- nid_t = 'String';
- }
- var command = "INSERT INTO ns0datatypes(nodeid, nodeidtype, nsindex, name, displayname, browsename, parentid, description, isabstract, definition, releasestatus, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '#', '"+entry['Description']+"', '"+entry['IsAbstract']+"', '"+entry['Definition']+"', '"+entry['ReleaseStatus']+"', '"+entry['Documentation']+"');";
- console.log(command);
- var ret = pool.query(command);
- }
- }else{
- var entry = obj;
- var nid = entry['NodeId'];
- var idx = 0;
- if(nid.includes('ns=')){
- var ix = nid.indexOf(';');
- var ns = nid.substring(3,ix);
- idx = parseInt(ns);
- }
- checkRefs(entry, nid);
- var nid_t = "";
- if(nid.includes('i=')){
- nid_t = 'Numeric';
- }else if(nid.includes('s=')){
- nid_t = 'String';
- }
- var command = "INSERT INTO ns0datatypes(nodeid, nodeidtype, nsindex, name, displayname, browsename, parentid, description, isabstract, definition, releasestatus, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '#', '"+entry['Description']+"', '"+entry['IsAbstract']+"', '"+entry['Definition']+"', '"+entry['ReleaseStatus']+"', '"+entry['Documentation']+"');";
- console.log(command);
- var ret = pool.query(command);
- }
- res.json({result:'OK',success:true});
- }catch(err){
- console.log(err);
- res.json({result:"NOK"});
- }
- })
- app.get('/reftypes', async function(req, res){
- try{
- var key = req.body;
- var len = nsray.length;
- for(let m = 1; m < nsray.length; m++){
- var command = "CREATE TABLE IF NOT EXISTS ns"+m+"referencetypes(id INT AUTO_INCREMENT, nodeid VARCHAR(300) NOT NULL, nodeidtype VARCHAR(100) NOT NULL, name VARCHAR(300) NOT NULL, inversename VARCHAR(300), symmetric VARCHAR(10) DEFAULT 'TBD', nodeclass VARCHAR(50) DEFAULT 'ReferenceType', nsindex INT DEFAULT NULL, nsurl VARCHAR(120) DEFAULT 'http://opcfoundation.org/UA/', displayname VARCHAR(300) NOT NULL, browsename VARCHAR(300) NOT NULL, description VARCHAR(300), isabstract VARCHAR(10) DEFAULT 'TBD', parentid VARCHAR(300) DEFAULT '#', parentreference VARCHAR(300), parentinverse INT DEFAULT NULL, documentation VARCHAR(300), comment VARCHAR(300), PRIMARY KEY(id));";
- var ret = await pool.query(command);
- let obj = nsray[m].UANodeSet.UAReferenceType; //base
- if(nsray[m].UANodeSet.UAReferenceType){
- if(Array.isArray(obj)){
- var sz = obj.length;
- for(let i = 0; i < sz; i++){
- var entry = obj[i];
- var nid = entry['NodeId'];
- var idx = m;
- if(nid.includes('ns=')){
- var ix = nid.indexOf(';');
- var ns = nid.substring(3,ix);
- idx = parseInt(ns);
- }
- checkRefs(entry, nid);
- var nid_t = "";
- if(nid.includes('i=')){
- nid_t = 'Numeric';
- }else if(nid.includes('s=')){
- nid_t = 'String';
- }
- command = "INSERT INTO ns"+m+"referencetypes(nodeid, nodeidtype, nsindex, nsurl, name, displayname, browsename, parentid, description, isabstract, symmetric, inversename, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+nsray[m].UANodeSet.Models.Model.ModelUri+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '#', '"+entry['Description']+"', '"+entry['IsAbstract']+"', '"+entry['Symmetric']+"', '"+entry['InverseName']+"', '"+entry['Documentation']+"');";
- console.log(command);
- ret = pool.query(command);
- }
- }else{
- var entry = obj;
- var nid = entry['NodeId'];
- var idx = m;
- if(nid.includes('ns=')){
- var ix = nid.indexOf(';');
- var ns = nid.substring(3,ix);
- idx = parseInt(ns);
- }
- checkRefs(entry, nid);
- var nid_t = "";
- if(nid.includes('i=')){
- nid_t = 'Numeric';
- }else if(nid.includes('s=')){
- nid_t = 'String';
- }
-
- command = "INSERT INTO ns"+m+"referencetypes(nodeid, nodeidtype, nsindex, nsurl, name, displayname, browsename, parentid, description, isabstract, symmetric, inversename, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+nsray[m].UANodeSet.Models.Model.ModelUri+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '#', '"+entry['Description']+"', '"+entry['IsAbstract']+"', '"+entry['Symmetric']+"', '"+entry['InverseName']+"', '"+entry['Documentation']+"');";
- console.log(command);
- ret = pool.query(command);
- }
- }
- }
- res.json({result:'OK',success:true});
- }catch(err){
- console.log(err);
- res.json({result:"NOK"});
- }
- })
- app.get('/namesp', async function(req, res){
- try{
- var key = req.body;
- var sz = nsray.length;
- //-------ns0--------------
- var command = "CREATE TABLE IF NOT EXISTS ns0depends(id INT AUTO_INCREMENT, nsindex INT DEFAULT NULL, nsurl VARCHAR(120), publicationdate VARCHAR(120), version VARCHAR(100), PRIMARY KEY(id));";
- var ret = await pool.query(command);
- command = "INSERT INTO ns0depends(nsindex, nsurl, publicationdate, version) VALUES ('0','http://opcfoundation.org/UA/','"+jsn.UANodeSet.Models.Model['PublicationDate']+"','"+jsn.UANodeSet.Models.Model['Version']+"');";
- ret = pool.query(command);
- //----------------ns0--------------
- for(let i = 1; i < sz; i++){
- var entry0 = nsray[i].UANodeSet.NamespaceUris.Uri;
- command = "CREATE TABLE IF NOT EXISTS ns"+i+"depends(id INT AUTO_INCREMENT, nsindex INT DEFAULT NULL, nsurl VARCHAR(120), publicationdate VARCHAR(120), version VARCHAR(100), PRIMARY KEY(id));";
- ret = await pool.query(command);
- command = "INSERT INTO ns"+i+"depends(nsindex, nsurl, publicationdate, version) VALUES ('0','http://opcfoundation.org/UA/','"+jsn.UANodeSet.Models.Model['PublicationDate']+"','"+jsn.UANodeSet.Models.Model['Version']+"');";
- ret = pool.query(command);
- if(Array.isArray(entry0)){
- var szy = entry0.length;
- for(let y = 0; y < szy; y++){
- var ns = entry0[y];
- command = "INSERT INTO ns"+i+"depends(nsindex, nsurl) VALUES ('"+(y+1)+"','"+ns+"');";
- ret = pool.query(command);
- }
- }else{
- var ns = entry0;
- command = "INSERT INTO ns"+i+"depends(nsindex, nsurl) VALUES ('1','"+entry0+"');";
- ret = pool.query(command);
- }
- var entry = nsray[i].UANodeSet.Models.Model.RequiredModel;
- command = "UPDATE ns"+i+"depends SET publicationdate = '"+nsray[i].UANodeSet.Models.Model['PublicationDate']+"' WHERE nsurl = '"+nsray[i].UANodeSet.Models.Model['ModelUri']+"';";
- ret = pool.query(command);
- command = "UPDATE ns"+i+"depends SET version = '"+nsray[i].UANodeSet.Models.Model['Version']+"' WHERE nsurl = '"+nsray[i].UANodeSet.Models.Model['ModelUri']+"';";
- ret = pool.query(command);
-
- if(Array.isArray(entry)){
- var szy = entry.length;
- for(let y = 0; y < szy; y++){
- var ns0 = entry[y];
- command = "UPDATE ns"+i+"depends SET publicationdate = '"+ns0['PublicationDate']+"' WHERE nsurl = '"+ns0['ModelUri']+"';";
- ret = pool.query(command);
- command = "UPDATE ns"+i+"depends SET version = '"+ns0['Version']+"' WHERE nsurl = '"+ns0['ModelUri']+"';";
- ret = pool.query(command);
- }
- }else{
- var ns0 = entry;
- command = "UPDATE ns"+i+"depends SET publicationdate = '"+ns0['PublicationDate']+"' WHERE nsurl = '"+ns0['ModelUri']+"';";
- ret = pool.query(command);
- command = "UPDATE ns"+i+"depends SET version = '"+ns0['Version']+"' WHERE nsurl = '"+ns0['ModelUri']+"';";
- ret = pool.query(command);
- }
- }
- res.json({result:'OK',success:true});
- }catch(err){
- console.log(err);
- res.json({result:"NOK"});
- }
- })
- app.get('/allrefs', async function(req, res){
- try{
- console.log(arref);
- res.json({result:'OK',success:true});
- }catch(err){
- console.log("NOK");
- res.json({result:"NOK"});
- }
- })
- /*
- app.post('/key', async function(req, res){
- try{
- var key = req.body;
- console.log(key);
- var ret = await gen_query("SELECT name FROM mitarbeiter WHERE key_id='"+key['key_id']+"';");
- res.json({result:ret[0].name,success:true});
- }catch(err){
- console.log("NOK");
- res.json({result:"NOK"});
- }
- })
- */
- app.get('/requirejson/:ident/:name',(req, res) =>{
- try{
- var namejs = req.params["name"];
- var shorty = req.params["ident"];
- const id = "./"+namejs+".json";
- const fl = require(id);
- for(let i = 0; i < ns_array.length; i++){
- if(ns_array[i][1] === shorty){
- return res.json({result:"Array already includes element."})
- }
- }
- ns_array.push([fl, shorty, fl.UANodeSet.Models.Model.ModelUri]);
- res.json({result:"OK"});
-
- }catch(err){
- console.log("NOK");
- res.json({result:"NOK", error: "Json file may not be available. Call list json files."});
- }
- })
- app.get('/shownsarray',(req, res) =>{
- try{ let str = '';
- for(let i = 0; i < ns_array.length; i++){
- str += '('+i+': '+ns_array[i][1]+')';
- }
- res.json({result:str});
- console.log(ns_array);
- }catch(err){
- console.log("NOK");
- res.json({result:"NOK", error: "Json file may not be available. Call list json files."});
- }
- })
- app.get('/getredis',(req, res) =>{
- try{
- redis_get();
- res.json({result:"OK"});
- }catch(err){
- console.log("NOK");
- res.json({result:"NOK"});
- }
- })
- app.get('/get_root',(req, res) =>{
- try{
- let rt = jsn.UANodeSet.UAObject.find( record => record.NodeId === "i=84");
- let resj = {
- id: rt.NodeId,
- parent: "#",
- text: rt.DisplayName};
- res.json(resj);
- }catch(err){
- console.log("NOK");
- res.json({result:"NOK"});
- }
- })
- app.get('/get_children/base/:id',(req, res) =>{
- var nid = req.params["id"];
- try{
- if(Array.isArray(jsn.UANodeSet.UAObject)){
- for (let i = 0; i < jsn.UANodeSet.UAObject.length;i++){
- if(Array.isArray(jsn.UANodeSet.UAObject[i].References.Reference)){
- for (let x = 0; x < jsn.UANodeSet.UAObject[i].References.Reference.length;x++){
- if(jsn.UANodeSet.UAObject[i].References.Reference[x].$t === nid){
- console.log(jsn.UANodeSet.UAObject[i].BrowseName + inverse(jsn.UANodeSet.UAObject[i].References.Reference[x]) +jsn.UANodeSet.UAObject[i].References.Reference[x].ReferenceType);
- }
- }
- }else{
- if(jsn.UANodeSet.UAObject[i].References.Reference.$t === nid){
- console.log(jsn.UANodeSet.UAObject[i].BrowseName + inverse(jsn.UANodeSet.UAObject[i].References.Reference) +jsn.UANodeSet.UAObject[i].References.Reference.ReferenceType);
- }
- }
- }
- }else{
- if(Array.isArray(jsn.UANodeSet.UAObject.References.Reference)){
- for (let x = 0; x < jsn.UANodeSet.UAObject.References.Reference.length;x++){
- if(jsn.UANodeSet.UAObject[i].References.Reference[x].$t === nid){
- console.log(jsn.UANodeSet.UAObject[i].BrowseName + inverse(jsn.UANodeSet.UAObject.References.Reference[x]) +jsn.UANodeSet.UAObject.References.Reference[x].ReferenceType);
- }
- }
- }else{
- if(jsn.UANodeSet.UAObject.References.Reference.$t === nid){
- console.log(jsn.UANodeSet.UAObject.BrowseName + inverse(jsn.UANodeSet.UAObject.References.Reference) +jsn.UANodeSet.UAObject.References.Reference.ReferenceType);
- }
- }
- }
- console.log('');
- res.json({result:"OK"});
- }catch(err){
- console.log("NOK");
- res.json({result:"NOK"});
- }
- })
- app.get('/get_children/all/:ns/:id',(req, res) =>{
- var ret_obj = [];
- var ns = req.params["ns"];
- var id = req.params["id"];
- var nid = 'ns='+ns+';'+'i='+id;
- console.log(nid);
- get_Children(di, nid, ret_obj);
- get_Children(ia, nid, ret_obj);
- get_Children(mach, nid, ret_obj);
- get_Children(mt, nid, ret_obj);
-
- res.json(ret_obj);
- })
- app.get('/getNode/all/:ns/:id',(req, res) =>{
- var ret_obj = [];
- var ns = req.params["ns"];
- var id = req.params["id"];
- var nid = 'ns='+ns+';'+'i='+id;
- console.log(nid);
- get_Children(di, nid, ret_obj);
- get_Children(ia, nid, ret_obj);
- get_Children(mach, nid, ret_obj);
- get_Children(mt, nid, ret_obj);
- let node = {
- id:nid,
- text: "home",
- children:ret_obj
- }
- res.json(node);
- })
- app.get('/flushall',(req, res) =>{
- redis_flush();
- res.json({result:"OK"});
- })
- app.get('/p2json/:nodeset/:ident',(req, res) =>{
- var name = req.params["nodeset"];
- var shorty = req.params["ident"];
- p2json(name, shorty);
- res.json({result:"OK"});
- })
- app.get('/list_projects', (req, res) => { //reacts to requests -> /list_projects
- const output = execSync("cd .. && cd Projects && ls", { encoding: 'utf-8' });
- var out = output.split("\n");
- if(out[out.length-1] === ""){
- out.splice(-1,1);
- }
- console.log("Response: ", out);
- res.json({result:out});
- })
-
- app.get('/list_nodesets', (req, res) => { //reacts to requests -> /list_nodesets
- const output = execSync("cd .. && cd nodesets && ls", { encoding: 'utf-8' });
- var out = output.split("\n");
- var result = [];
- for(let i = 0; i < out.length; i++){
- if(out[i].includes(".xml")){
- result.push(out[i]);
- }
- }
- console.log("Response: ", result);
- res.json({result:result});
- })
- app.get('/new_project', (req, res) => { //reacts to requests -> /new_project?name=myproject
- const name = req.query.name; //project name
- const output = execSync("cd .. && cd Projects && ls", { encoding: 'utf-8' });
- var out = output.split("\n");
- var result = "";
- var err = "Error - Project already exists.";
- for(let i = 0; i < out.length; i++){
- if(out[i] === name){
- return res.json({result:err});
- }
- }
- const dir = execSync("cd .. && cd Projects && mkdir "+name, { encoding: 'utf-8' });
-
- var cp = execSync("sudo cp /home/pi/ModelingTool/nodesets/Opc.Ua.NodeSet2.xml /home/pi/ModelingTool/Projects/"+name+"/Opc.Ua.NodeSet2.xml", { encoding: 'utf-8' });
- cp = execSync("sudo cp /home/pi/ModelingTool/nodesets/Opc.Ua.NodeSet2.json /home/pi/ModelingTool/Projects/"+name+"/Opc.Ua.NodeSet2.json", { encoding: 'utf-8' });
- const cur_dir = execSync("cd .. && cd Projects && cd "+name+" && ls", { encoding: 'utf-8' });
- console.log("New Project was created.");
- res.json({result:cur_dir});
- })
-
- app.get('/save_project', (req, res) => { //reacts to requests -> /save_project?name=myproject
- const name = req.query.name; //project name
- const output = execSync("sudo cp /var/www/html/root.json /home/pi/ModelingTool/Projects/"+name+"/"+name+".json", { encoding: 'utf-8' });
- console.log("Project "+name+" was saved.");
- res.json({result:"Project saved"});
- })
-
- app.get('/load_json', (req, res) => { //reacts to requests -> /load_json?name=myproject
- const name = req.query.name; //project name
- var output = execSync("cd .. && cd Projects && ls", { encoding: 'utf-8' });
- var out = output.split("\n");
- var result = "";
- var err = "Error - Project or file not available.";
- for(let i = 0; i < out.length; i++){
- if(out[i] === name){
- var output1 = execSync("cd .. && cd Projects && cd "+name+" && ls", { encoding: 'utf-8' });
- var out1 = output1.split("\n");
- var chk = name+".json"
- for(let y = 0; y < out1.length; y++){
- if(out1[y] === chk){
- result = execSync("sudo cp /home/pi/ModelingTool/Projects/"+name+"/"+name+".json /var/www/html/root.json", { encoding: 'utf-8' });
- console.log("Project has been loaded.");
- return res.json({result:"Project loaded"});
- }
- }
- }
- }
-
- res.json({result:err});
- })
-
-
- app.get('/root', (req, res) => { //reacts to requests -> /root
- console.log("Return root.");
- res.json([{id:"i=84",text:"Root",children:[{id:"i=85",text:"Objects",children:true},{id:"i=86",text:"Types", icon : "/variable_node.svg", children:true},{id:"i=87",text:"View",children:false}]}]);
- })
- function isChildRef(obj){
- if('IsForward' in obj && obj.IsForward === 'false'){
- return false;
- }
- if('IsForward' in obj && obj.IsForward === 'true'){
- switch (obj.ReferenceType) {
- case 'Organizes': return true;
- case 'HasComponent': return true;
- case 'HasProperty': return true;
- case 'HasAddIn': return true;
- case 'HasSubtype': return true;
- default: return false;
- }
- }
- switch (obj.ReferenceType) {
- case 'Organizes': return true;
- case 'HasComponent': return true;
- case 'HasProperty': return true;
- case 'HasAddIn': return true;
- case 'HasSubtype': return true;
- default: return false;
- }
-
- return false;
- }
- function checkDouble(item, obj){
- for(let i = 0; i < obj.length; i++){
- if(item.id === obj[i].id){
- return true;
- }
- }
- return false;
- }
- app.get('/lazy', (req, res) => {
- //console.log(req);
- var ret_obj = [];
- let node = {};
- if(req.query.id == "#"){
- //res.json([{id:"i=84",text:"Root",data:{nodeclass:"Object"},children:true}]);
- res.json([{id:"i=84",text:"Root",data:{nodeclass:"Object"},children:[{id:"i=85",text:"Objects",data:{nodeclass:"Objects"},children:true},{id:"i=86",text:"Types", data:{nodeclass:"Objects"},children:true},{id:"i=87",text:"View",data:{nodeclass:"Objects"},children:true}]}]);
- }
- var nid = req.query.id;
- node = searchNode(nid);
- if(node.data.references != null){
- console.log("Here:"+node.data.references);
- if(Array.isArray(node.data.references.Reference)){
- console.log("And:"+node.data.references.Reference);
- for(let x = 0; x < node.data.references.Reference.length; x++ ){
- if(isChildRef(node.data.references.Reference[x])){
- var cnode = searchNode(node.data.references.Reference[x].$t);
- if(!checkDouble(cnode,ret_obj)){
- ret_obj.push(cnode);
- }
- }
- }
-
- }else{
- console.log("But:"+node.data.references);
- if(isChildRef(node.data.references)){
- var cnode = searchNode(node.data.references.$t);
- if(!checkDouble(cnode,ret_obj)){
- ret_obj.push(cnode);
- }
- }
- }
- }
- getAllChildren(nid, ret_obj);
- console.log(ret_obj);
- res.json(ret_obj);
- });
- app.get('/index/:ns1/:ns2', (req, res) => {
- var n1 = req.params["ns1"];
- var n2 = req.params["ns2"];
- var num = getIndexObj(ns_array[n1][0],ns_array[n2][0]);
- console.log(getNode(ns_array[3][0],2,15048));
- res.send("Index of "+ns_array[n2][1]+' in '+ns_array[n1][1]+' is '+num);
- });
- app.get('/test/:id', (req, res) => { //test
- var n1 = parseInt(req.params["id"]);
- console.log(ns_array[n1][1],);
- var ret = searchNode("i=85");
- console.log(ret);
- res.send("All good");
- //res.json([{id:"i=84",text:"Root",children:[{id:"i=85",text:"Objects",children:true},{id:"i=86",text:"Types", children:true},{id:"i=87",text:"View",children:false}]}]);
- })
- app.get('/require/all', (req, res) => { //test
- ns_array.push([jsn, "base", jsn.UANodeSet.Models.Model.ModelUri]);
- ns_array.push([di, "di", di.UANodeSet.Models.Model.ModelUri]);
- ns_array.push([ia, "ia", ia.UANodeSet.Models.Model.ModelUri]);
- ns_array.push([mach, "mach", mach.UANodeSet.Models.Model.ModelUri]);
- ns_array.push([mt, "mt", mt.UANodeSet.Models.Model.ModelUri]);
- res.json({result:"OK"});
- })
-
-
- app.listen(port, () => {
- console.log("Server listening at http://localhost:", port);
- })
|