Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
serverStatus.startTime.setValueFromSource({dataType: DataType.DateTime, value: new Date(Date.UTC(2100, 0, 1))});
serverStatus.readValue().value.value.startTime.toISOString().should.eql("2100-01-01T00:00:00.000Z");
serverStatus.startTime.readValue().value.value.toISOString().should.eql("2100-01-01T00:00:00.000Z");
//xx debugLog(serverStatus.readValue().value.toString());
serverStatus.readValue().value.value.buildInfo.productName = "productName1";
serverStatus.readValue().value.value.buildInfo.productName.should.eql("productName1");
serverStatus.buildInfo.productName.readValue().value.value.should.eql("productName1");
serverStatus.buildInfo.productName.setValueFromSource({dataType: DataType.String, value: "productName2"});
serverStatus.readValue().value.value.buildInfo.productName.should.eql("productName2");
serverStatus.buildInfo.productName.readValue().value.value.should.eql("productName2");
var async = require("async");
var StatusCodes = require("node-opcua-status-code").StatusCodes;
var write_service = require("node-opcua-service-write");
var WriteValue = write_service.WriteValue;
var makeAccessLevel = require("node-opcua-data-model").makeAccessLevel;
// now use WriteValue instead
// make sure value is writable
var rw = makeAccessLevel("CurrentRead | CurrentWrite");
serverStatus.buildInfo.productName.accessLevel = rw;
serverStatus.buildInfo.productName.userAccessLevel = rw;
serverStatus.buildInfo.accessLevel = rw;
serverStatus.buildInfo.userAccessLevel = rw;
serverStatus.accessLevel = rw;
serverStatus.userAccessLevel = rw;
const options = {
percentDataBad: 100,
percentDataGood: 100, // Therefore if all values are Good then the
// quality will be Good, or if all values are Bad then the quality will be Bad, but if there is
// some Good and some Bad then the quality will be Uncertain
stepped: false, // Therefore SlopedInterpolation is used between data points.
treatUncertainAsBad: false, // Therefore Uncertain values are included in Aggregate calls.
useSlopedExtrapolation: false, // Therefore SteppedExtrapolation is used at end boundary conditions.
};
addressSpace.installHistoricalDataNode(node, options);
installAggregateConfigurationOptions(node, options);
// 12:00:00 - BadNoData First archive entry, Point created
addHistory(node, "12:00:00", null, StatusCodes.BadNoData);
// 12:00:10 10 Raw, Good
addHistory(node, "12:00:10", 10, StatusCodes.Good);
// 12:00:20 20 Raw, Good
addHistory(node, "12:00:20", 20, StatusCodes.Good);
// 12:00:30 30 Raw, Good
addHistory(node, "12:00:30", 30, StatusCodes.Good);
// 12:00:40 40 Raw, Bad ANNOTATION: Operator 1
// Jan-02-2012 8:00:00 Scan failed, Bad data entered
// ANNOTATION:
// Jan-04-2012 7:10:00 Value cannot be verified
addHistory(node, "12:00:40", 40, StatusCodes.Bad);
// 12:00:50 50 Raw, Good ANNOTATION: Engineer1
// Jan-04-2012 7:00:00 Scanner fixed
addHistory(node, "12:00:50", 50, StatusCodes.Good);
// 12:01:00 60 Raw, Good
addHistory(node, "12:01:00", 60, StatusCodes.Good);
/* istanbul ignore if */
const errMessage1 = "EXCEPTION CAUGHT WHILE PROCESSING REQUEST !! " + request.schema.name;
console.log(chalk.red.bold(errMessage1));
console.log(request.toString());
display_trace_from_this_projet_only(err);
let additional_messages = [];
additional_messages.push("EXCEPTION CAUGHT WHILE PROCESSING REQUEST !!! " + request.schema.name);
additional_messages.push(err.message);
if (err.stack) {
additional_messages = additional_messages.concat(err.stack.split("\n"));
}
response = makeServiceFault(StatusCodes.BadInternalError, additional_messages);
channel.send_response("MSG", response, message, emptyCallback);
}
}
});
} else {
if (request.schema.name === "CloseSecureChannelRequest") {
console.log("WARNING : RECEIVED a CloseSecureChannelRequest with MSGTYPE=" + msgType);
this.close();
} else {
if (doPerfMonitoring) {
// record tick 1 : after message has been received, before message processing
this._tick1 = get_clock_tick();
}
if (this.securityToken && channelId !== this.securityToken.channelId) {
// response = new ServiceFault({responseHeader: {serviceResult: certificate_status}});
debugLog("Invalid channelId detected =", channelId, " <> ", this.securityToken.channelId);
return this.send_error_and_abort(
StatusCodes.BadCommunicationError,
"Invalid Channel Id specified " + this.securityToken.channelId,
message, () => {
});
}
/**
* notify the observer that a OPCUA message has been received.
* It is up to one observer to call send_response or send_error_and_abort to complete
* the transaction.
*
* @event message
* @param message
*/
this.emit("message", message);
}
// istanbul ignore next
if (!state) {
throw new Error("Cannot find state with name " + toStateNode);
}
assert(state.browseName.name!.toString() === toStateNode);
toStateNode = state;
}
const fromStateNode = this.currentStateNode;
toStateNode = this._coerceNode(toStateNode) as any as State;
assert(toStateNode.nodeClass === NodeClass.Object);
this.currentState.setValueFromSource({
dataType: DataType.LocalizedText,
value: coerceLocalizedText(toStateNode.browseName.toString())
}, StatusCodes.Good);
this.currentStateNode = toStateNode;
const transitionNode = this.findTransitionNode(fromStateNode, toStateNode);
if (transitionNode) {
// xx console.log("transitionNode ",transitionNode.toString());
// The inherited Property SourceNode shall be filled with the NodeId of the StateMachine instance where the
// Transition occurs. If the Transition occurs in a SubStateMachine, then the NodeId of the SubStateMachine
// has to be used. If the Transition occurs between a StateMachine and a SubStateMachine, then the NodeId of
// the StateMachine has to be used, independent of the direction of the Transition.
// Transition identifies the Transition that triggered the Event.
// FromState identifies the State before the Transition.
// ToState identifies the State after the Transition.
this.raiseEvent("TransitionEventType", {
const dataEncoding = nodeToRead.dataEncoding;
const continuationPoint = nodeToRead.continuationPoint;
assert(engine.addressSpace instanceof AddressSpace); // initialize not called
if (timestampsToReturn === TimestampsToReturn.Invalid) {
return new DataValue({statusCode: StatusCodes.BadTimestampsToReturnInvalid});
}
timestampsToReturn = (_.isObject(timestampsToReturn)) ? timestampsToReturn : TimestampsToReturn.Neither;
const obj = engine.__findObject(nodeId);
if (!obj) {
// may be return BadNodeIdUnknown in dataValue instead ?
// Object Not Found
callback(null, new HistoryReadResult({statusCode: StatusCodes.BadNodeIdUnknown}));
} else {
if (!obj.historyRead) {
// note : Object and View may also support historyRead to provide Event historical data
// todo implement historyRead for Object and View
const msg = " this node doesn't provide historyRead! probably not a UAVariable\n "
+ obj.nodeId.toString() + " " + obj.browseName.toString() + "\n"
+ "with " + nodeToRead.toString() + "\n"
+ "HistoryReadDetails " + historyReadDetails.toString();
if (doDebug) {
console.log("ServerEngine#_historyReadSingleNode ".cyan, msg.white.bold);
}
const err = new Error(msg);
// object has no historyRead method
return setImmediate(callback.bind(null, err));
}
function getMethodDeclaration_ArgumentList(addressSpace, objectId, methodId) {
assert(objectId instanceof NodeId);
assert(methodId instanceof NodeId);
// find object in address space
const obj = addressSpace.findNode(objectId);
if (!obj) {
// istanbul ignore next
if(doDebug) {
console.warn("cannot find node ",objectId.toString());
}
return {statusCode: StatusCodes.BadNodeIdUnknown};
}
if (!obj.hasMethods) {
return {statusCode: StatusCodes.BadNodeIdInvalid};
}
let objectMethod = obj.getMethodById(methodId);
if (!objectMethod) {
// the method doesn't belong to the object, nevertheless
// the method can be called
objectMethod = addressSpace.findNode(methodId);
if (!objectMethod || !(objectMethod instanceof UAMethod)) {
return {statusCode: StatusCodes.BadMethodInvalid};
}
}
const methodDeclarationId = objectMethod.methodDeclarationId;
assert(context instanceof SessionContext);
assert(callback instanceof Function);
const nodeId = nodeToRead.nodeId;
const indexRange = nodeToRead.indexRange;
const dataEncoding = nodeToRead.dataEncoding;
const continuationPoint = nodeToRead.continuationPoint;
timestampsToReturn = (_.isObject(timestampsToReturn)) ? timestampsToReturn : TimestampsToReturn.Neither;
const obj = this.__findObject(nodeId) as UAVariable;
if (!obj) {
// may be return BadNodeIdUnknown in dataValue instead ?
// Object Not Found
callback(null, new HistoryReadResult({ statusCode: StatusCodes.BadNodeIdUnknown }));
return;
} else {
if (!obj.historyRead) {
// note : Object and View may also support historyRead to provide Event historical data
// todo implement historyRead for Object and View
const msg = " this node doesn't provide historyRead! probably not a UAVariable\n "
+ obj.nodeId.toString() + " " + obj.browseName.toString() + "\n"
+ "with " + nodeToRead.toString() + "\n"
+ "HistoryReadDetails " + historyReadDetails.toString();
if (doDebug) {
console.log(chalk.cyan("ServerEngine#_historyReadSingleNode "),
chalk.white.bold(msg));
}
const err = new Error(msg);
// invalid attributes : BadNodeAttributesInvalid
// invalid range : BadIndexRangeInvalid
try {
dataValue = obj.readAttribute(context, attributeId, indexRange, dataEncoding);
assert(dataValue.statusCode instanceof StatusCode);
if(!dataValue.isValid()) {
console.log("Invalid value for node ",obj.nodeId.toString(),obj.browseName.toString());
}
}
catch (err) {
console.log(" Internal error reading NodeId ", obj.nodeId.toString());
console.log(" AttributeId ", attributeId.toString());
console.log(" ", err.message);
console.log(" ", err.stack);
return new DataValue({statusCode: StatusCodes.BadInternalError});
}
//Xx console.log(dataValue.toString());
dataValue = apply_timestamps(dataValue, timestampsToReturn, attributeId);
return dataValue;
}
};
sendInitialValues: boolean): TransferResult {
assert(session instanceof ServerSession);
assert(_.isNumber(subscriptionId));
assert(_.isBoolean(sendInitialValues));
if (subscriptionId <= 0) {
return new TransferResult({ statusCode: StatusCodes.BadSubscriptionIdInvalid });
}
const subscription = this.findSubscription(subscriptionId);
if (!subscription) {
return new TransferResult({ statusCode: StatusCodes.BadSubscriptionIdInvalid });
}
if (!subscription.$session) {
return new TransferResult({ statusCode: StatusCodes.BadInternalError });
}
// update diagnostics
subscription.subscriptionDiagnostics.transferRequestCount++;
// now check that new session has sufficient right
// if (session.authenticationToken.toString() !== subscription.authenticationToken.toString()) {
// console.log("ServerEngine#transferSubscription => BadUserAccessDenied");
// return new TransferResult({ statusCode: StatusCodes.BadUserAccessDenied });
// }
if (session.publishEngine === subscription.publishEngine) {
// subscription is already in this session !!
return new TransferResult({ statusCode: StatusCodes.BadNothingToDo });
}
if (session === subscription.$session) {
// subscription is already in this session !!