4 Commits b7164b6c39 ... e3c744f79b

Author SHA1 Message Date
  Martin Kunz e3c744f79b parse uadatatype.definition; bugfixes 1 month ago
  Martin Kunz 6b89180121 toxml: rem. ns=0 in nodeid toString 1 month ago
  Martin Kunz 0ab219958d fix: Alias is uppercase 1 month ago
  Martin Kunz 56a918ca7e xmlelem: fix add xmlelem 1 month ago
6 changed files with 71 additions and 9 deletions
  1. 45 0
      src/ua/Definition.ts
  2. 4 1
      src/ua/NodeId.ts
  3. 1 1
      src/ua/UAAlias.ts
  4. 9 6
      src/ua/UADataType.ts
  5. 9 0
      src/ua/UANodeSet.ts
  6. 3 1
      src/util/XmlElem.ts

+ 45 - 0
src/ua/Definition.ts

@@ -0,0 +1,45 @@
+import { XMLElem, type IToXML } from "@/util/XmlElem";
+import type { NamespaceTable } from "./NameSpaceTable";
+import type { IAddressSpace } from "./IAddressSpace";
+export class Definition implements IToXML {
+    public name:string;
+    public symbolicName:string|undefined;
+    public isUnion:boolean;
+    public IsOptionSet:boolean;
+    public baseType:string;
+
+    constructor(options: DefinitionOptions) {
+        this.name=options.name;
+        this.symbolicName=options.symbolicName;
+        this.isUnion=(options.isUnion===undefined?false:Boolean(options.isUnion));
+        this.IsOptionSet=(options.IsOptionSet===undefined?false:Boolean(options.IsOptionSet));
+        this.baseType=options.baseType||"";
+    }
+
+    toXML(_lnst:NamespaceTable, _gnst:NamespaceTable): XMLElem {
+        return new XMLElem("Definition")
+            .attr("Name", this.name)
+            .attr('SymbolicName', this.symbolicName)
+            .attr('IsUnion', this.isUnion)
+            .attr('IsOptionSet', this.IsOptionSet)
+            .attr('BaseType', this.baseType);
+    }
+
+    static  fromXML(xmlDefinition: any, _addressSpace: IAddressSpace): Definition{
+        return new Definition({
+            name: xmlDefinition['@_Name'],
+            symbolicName: xmlDefinition['@_SymbolicName'],
+            isUnion: xmlDefinition['@_IsUnion'],
+            IsOptionSet: xmlDefinition['@_IsOptionSet'],
+            baseType: xmlDefinition['@_BaseType']
+        });    
+    }
+}
+
+export interface DefinitionOptions{
+    name: string;
+    symbolicName?: string;
+    isUnion?: boolean;
+    IsOptionSet?: boolean;
+    baseType?:string;
+}

+ 4 - 1
src/ua/NodeId.ts

@@ -143,7 +143,10 @@ export class NodeId {
         const _this = this as INodeId;
         switch (_this.identifierType) {
             case NodeIdType.NUMERIC:
-                str = "ns=" + this.namespace + ";i=" + _this.value;
+                if(this.namespace===0)
+                    str = "i=" + _this.value;
+                else
+                    str = "ns=" + this.namespace + ";i=" + _this.value;
                 break;
             case NodeIdType.STRING:
                 str = "ns=" + this.namespace + ";s=" + _this.value;

+ 1 - 1
src/ua/UAAlias.ts

@@ -4,7 +4,7 @@ export class UAAlias implements IToXML{
                 public id: string) {
     }
     toXML(): XMLElem {
-        return new XMLElem('Alias', this.id).attr('alias', this.alias);  
+        return new XMLElem('Alias', this.id).attr('Alias', this.alias);  
     }
     static fromXML(xmlObject: any): UAAlias {
         return new UAAlias( xmlObject['@_Alias'], xmlObject['#text']);

+ 9 - 6
src/ua/UADataType.ts

@@ -3,29 +3,32 @@ import { type UABaseNodeOptions } from "./UABaseNode";
 import type { NamespaceTable } from "./NameSpaceTable";
 import type { IAddressSpace } from "./IAddressSpace";
 import { UAType } from "./UAType";
+import { Definition } from "./Definition";
 export class UADataType extends UAType implements IToXML {
-//TODO definition
+    public definition?:Definition;
 
     constructor(options: UATypeOptions) {
         super(options);
         Object.assign(this, options);  
         this.nodeClass="UADataType";
+        this.definition=options.definition;
     }
     toXML(lnst:NamespaceTable, gnst:NamespaceTable): XMLElem {
         const elem=super.toXML(lnst, gnst);
         elem.name=this.nodeClass;
         elem.attr("Purpose", this.purpose);
         elem.attr('IsAbstract', this.isAbstract);
-
+        elem.elem("Definition", this.definition?.toXML(lnst,gnst));
         return elem;    
     }
-    static  fromXML(uaObject: any, addressSpace: IAddressSpace): UADataType{
-        const bn=super.fromXML(uaObject, addressSpace) as UATypeOptions
-
+    static  fromXML(xmlObject: any, addressSpace: IAddressSpace): UADataType{
+        const bn=super.fromXML(xmlObject, addressSpace) as UADataType;
+        if(xmlObject['Definition'])
+            bn.definition = Definition.fromXML(xmlObject['Definition'], addressSpace);
         return new UADataType(bn as UATypeOptions);    
     }
 }
 
 export interface UATypeOptions extends UABaseNodeOptions{
-
+    definition?:Definition;
 }

+ 9 - 0
src/ua/UANodeSet.ts

@@ -12,6 +12,7 @@ import { UAVariableType } from './UAVariableType';
 import type { AddressSpace } from './AddressSpace';
 import type { IAddressSpace } from './IAddressSpace';
 import { UAAlias } from './UAAlias';
+import { UADataType } from './UADataType';
 
 export class UANodeSet implements IToXML{
 
@@ -121,6 +122,10 @@ export class UANodeSet implements IToXML{
                     case 'UANodeSet.UAReferenceType.Description':
                     case 'UANodeSet.UAReferenceType.Category':
                     case 'UANodeSet.UAReferenceType.RolePermissions.RolePermission':
+                    case 'UANodeSet.UADataType':
+                    case 'UANodeSet.UADataType.References.Reference':
+                    case 'UANodeSet.UADataType.DisplayName':
+                    case 'UANodeSet.UADataType.Description':
                         return true;
                     default:
                         return false;
@@ -164,6 +169,10 @@ export class UANodeSet implements IToXML{
         for(const xmlVariableType of xmlVariableTypes) {
             nodes.push(UAVariableType.fromXML(xmlVariableType, addressSpace));
         }
+        const xmlDataTypes=xmlObj['UANodeSet']['UADataType']||[];
+        for(const xmlDataType of xmlDataTypes) {
+            nodes.push(UADataType.fromXML(xmlDataType, addressSpace));
+        }
         const uaNamespaceUris=xmlObj['UANodeSet']['NamespaceUris']||[];
         const nst=new NamespaceTable();
         for(const nsUri of uaNamespaceUris['Uri']||[]) {

+ 3 - 1
src/util/XmlElem.ts

@@ -26,8 +26,10 @@ export class XMLElem {
     public elem(name:string, value: XMLElem|string|boolean|undefined|null): XMLElem {
         if(value===undefined||value===null)
             return this; //skip undefined/null values
-        if(value instanceof XMLElem)
+        if(value instanceof XMLElem) {
             this.elements.push(value);
+            return this;
+        }
         this.elements.push(new XMLElem(name, value?.toString()));
         return this;
     }