How to use node-opcua-utils - 10 common examples

To help you get started, we’ve selected a few node-opcua-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-opcua / node-opcua / packages / node-opcua-address-space / test_helpers / boiler_system.ts View on Github external
context: SessionContext,
                callback: (err: Error | null, callMethodResult: CallMethodResultOptions) => void
            ) {
                const stateMachineW = this.parent! as StateMachine;
                // tslint:disable-next-line:no-console
                console.log("Boiler System :  " + methodName + " about to process");
                stateMachineW.setState(toState);
                callback(null, {
                    outputArguments: [],
                    statusCode: StatusCodes.Good,
                });
            });

        assert(programStateMachine.getMethodByName(methodName) !== null,
            "Method " + methodName + " should be added to parent object (checked with getMethodByName)");
        const lc_name = lowerFirstLetter(methodName);
    }
github node-opcua / node-opcua / packages / node-opcua-address-space / src / base_node.ts View on Github external
public uninstall_extra_properties(reference: Reference) {

        const addressSpace = this.addressSpace;

        if (addressSpace.isFrugal) {
            // skipping
            return;
        }
        const childNode = resolveReferenceNode(addressSpace, reference);

        const name = lowerFirstLetter(childNode.browseName.name!.toString());
        if (reservedNames.hasOwnProperty(name)) {
            if (doDebug) {
                // tslint:disable-next-line:no-console
                console.log(chalk.bgWhite.red("Ignoring reserved keyword                                     " + name));
            }
            return;
        }
        /* istanbul ignore next */
        if (!this.hasOwnProperty(name)) {
            return;
        }

        Object.defineProperty(this, name, {
            value: undefined
        });
    }
github node-opcua / node-opcua / packages / node-opcua-server / src / server_session.js View on Github external
ServerSession.prototype.incrementRequestTotalCounter = function (counterName) {
    const session = this;
    if (session._sessionDiagnostics) {
        const propName = lowerFirstLetter(counterName + "Count");
        if (!session._sessionDiagnostics.hasOwnProperty(propName)) {
            console.log(" cannot find", propName);
            //xx return;
        }
        //   console.log(self._sessionDiagnostics.toString());
        session._sessionDiagnostics[propName].totalCount = session._sessionDiagnostics[propName].totalCount + 1;
    }
};
ServerSession.prototype.incrementRequestErrorCounter = function (counterName) {
github node-opcua / node-opcua / packages / node-opcua-address-space / src / address_space_add_event_type.js View on Github external
}
                // ignore also methods
                if (node instanceof UAMethod) {
                    //xx console.log(" skipping method ", node.browseName.toString());
                    return;
                }


                _process_var(self,"",node);

                // also store value in index
                //xx eventData.__nodes[node.nodeId.toString()] = eventData[lowerName];

                const children =node.getAggregates();
                if (children.length >0) {
                    const lowerName =lowerFirstLetter(node.browseName.name);
                    //xx console.log(" Children to visit = ",lowerName,children.map(function(a){ return a.browseName.toString();}).join(" "));
                    children.map(function(child) {
                        _process_var(self,lowerName + ".",child);
                    });

                }
            });
        }
github node-opcua / node-opcua / packages / node-opcua-secure-channel / source / server / server_secure_channel_layer.ts View on Github external
private _send_chunk(callback: ErrorCallback | undefined, messageChunk: Buffer | null) {

        if (messageChunk) {
            this.transport.write(messageChunk);
        } else {
            if (doPerfMonitoring) {
                // record tick 3 : transaction completed.
                this._tick3 = get_clock_tick();
            }

            if (callback) {
                setImmediate(callback);
            }

            if (doPerfMonitoring) {
                this._record_transaction_statistics();

                /* istanbul ignore next */
                if (doDebug) {
                    // dump some statistics about transaction ( time and sizes )
                    _dump_transaction_statistics(this.last_transaction_stats);
                }
            }
            this.emit("transaction_done");
github node-opcua / node-opcua / packages / node-opcua-transport / source / message_builder_base.ts View on Github external
this._packetAssembler.on("newMessage", (info, data) => {

            if (doPerfMonitoring) {
                // record tick 0: when the first data is received
                this._tick0 = get_clock_tick();
            }
            /**
             *
             * notify the observers that a new message is being built
             * @event start_chunk
             * @param info
             * @param data
             */
            this.emit("start_chunk", info, data);
        });
github node-opcua / node-opcua / packages / node-opcua-data-value / schemas / DataValue_schema.js View on Github external
console.log(" CANNOT FIND ENCODE METHOD ON VARIANT !!! HELP",dataValue.toString());
            }
            dataValue.value.encode(stream);
        }

        // write statusCode
        if (check_flag(encoding_mask, DataValueEncodingByte.StatusCode)) {
            //ec.encodeUInt32(dataValue.statusCode.value,stream);
            ec.encodeStatusCode(dataValue.statusCode,stream);
        }
        // write sourceTimestamp
        if (check_flag(encoding_mask, DataValueEncodingByte.SourceTimestamp)) {
            ec.encodeHighAccuracyDateTime(dataValue.sourceTimestamp,dataValue.sourcePicoseconds,stream);
        }
        // write sourcePicoseconds
        if (check_flag(encoding_mask, DataValueEncodingByte.SourcePicoseconds)) {
            assert(dataValue.sourcePicoseconds  != null );
            const sourcePicoseconds = Math.floor((dataValue.sourcePicoseconds % 100000) /10);
            ec.encodeUInt16(sourcePicoseconds,stream);
        }
        // write serverTimestamp
        if (check_flag(encoding_mask, DataValueEncodingByte.ServerTimestamp)) {
            ec.encodeHighAccuracyDateTime(dataValue.serverTimestamp,dataValue.serverPicoseconds,stream);
        }
        // write serverPicoseconds
        if (check_flag(encoding_mask, DataValueEncodingByte.ServerPicoseconds)) {
            assert(dataValue.serverPicoseconds  != null);
            const serverPicoseconds = Math.floor((dataValue.serverPicoseconds % 100000 ) / 10) ; // we encode 10-pios
            ec.encodeUInt16(serverPicoseconds,stream);
        }
    },
    decode_debug: function(dataValue,stream,options) {
github node-opcua / node-opcua / packages / node-opcua-generator / source / generate_extension_object_code.ts View on Github external
import {
    EnumerationDefinitionSchema,
    FieldCategory,
    getStandartDataTypeFactory,
    StructuredTypeSchema,
} from "node-opcua-factory";
import { EnumeratedType, parseBinaryXSD, TypeDictionary } from "node-opcua-schemas";
import { LineFile } from "node-opcua-utils";
import { promisify } from "util";
import { writeStructuredType } from "./factory_code_generator";
// Xx import * as  prettier from "prettier";

const readFile = promisify(fs.readFile);
const parseBinaryXSD2 = promisify(parseBinaryXSD);

const f = new LineFile();

function write(...args: string[]) {
    f.write.apply(f, args);
}

function writeEnumeratedType(enumerationSchema: EnumerationDefinitionSchema) {

    // make sure there is a Invalid key in the enum => else insert one
    const hasInvalid = enumerationSchema.enumValues.hasOwnProperty("Invalid");
    if (!hasInvalid) {
        // xx console.log("Adding Invalid Enum entry on ", enumeratedType.name);
        enumerationSchema.enumValues[enumerationSchema.enumValues.Invalid = 0xFFFFFFFF] = "Invalid";
    }

    const arrayValues = Object.keys(enumerationSchema.enumValues)
        .filter((a: string) => a.match("[0-9]+"))
github node-opcua / node-opcua / packages / node-opcua-generator / source / factory_code_generator.ts View on Github external
);
        } else {
            write(
              `import { ${field.fieldType} } from "../source/imports";`
            );
        }
    }

    // -------------------------------------------------------------------------
    // - insert definition of base class
    // -------------------------------------------------------------------------

    if (baseClass !== "BaseUAObject") {

        const filename = get_class_tscript_filename_local(baseClass);
        const localFilename = normalize_require_file(folderForSourceFile, filename);
        // xx console.log(" ===> filename", filename, localFilename, fs.existsSync(filename));

        if (fs.existsSync(filename)) {
            assert(!localFilename.match(/\\/));
            write("import { " + baseClass + " } from \"" + localFilename + "\";");
        } else {
            write("const " + baseClass + " = getStructureTypeConstructor(\"" + baseClass + "\");");
        }
    }

    write_expose_encoder_decoder(write, schema);

    writeStructuredType(write, schema);

    f.saveFormat(generatedTypescriptFilename, (code) => {
        const options: prettier.Options = {
github node-opcua / node-opcua / packages / node-opcua-convert-nodeset-to-javascript / src / convert_nodeset_to_types.js View on Github external
// if binaryEncodingNodeId is in the standard factory => no need to overwrite

    if (!bForce && (hasConstructor(dataType.binaryEncodingNodeId) || dataType.binaryEncodingNodeId.namespace === 0)) {
        //xx console.log(chalk.bgYellow("Skipping standard constructor") ," for dataType" ,dataType.browseName.toString());
        return getConstructor(dataType.binaryEncodingNodeId);
    }

    const schema = constructSchema(addressSpace, dataType);

    generateFileCode(namespaceUri, schema, schema_folder);

    generateStructureCode(namespaceUri, schema);

    const filename = getSchemaSourceFile(namespaceUri, schema.name, "");

    const relative_filename = normalize_require_file(__dirname, filename);

    const constructor = require(relative_filename)[schema.name];
    assert(_.isFunction(constructor), "expecting a constructor here");

    return constructor;
}