Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assert(inputArguments.length === 1);
const shelvingState = context.object as ShelvingStateMachine;
if (shelvingState.getCurrentState() !== "Unshelved") {
return callback(null, {
statusCode: StatusCodes.BadConditionAlreadyShelved
});
}
// checking duration ...
const alarmNode = shelvingState.parent;
// istanbul ignore next
if (!(alarmNode instanceof UAAlarmConditionBase)) {
return callback(null, {
statusCode: StatusCodes.BadNodeIdInvalid
});
}
const maxTimeShelved = alarmNode.getMaxTimeShelved();
assert(_.isFinite(maxTimeShelved));
assert(inputArguments[0].dataType === DataType.Double); // Duration
assert(inputArguments[0] instanceof Variant);
// xx console.log("inputArguments",inputArguments[0].toString());
const proposedDuration = inputArguments[0].value; // as double (milliseconds)
if (proposedDuration > maxTimeShelved) {
return callback(null, {
statusCode: StatusCodes.BadShelvingTimeOutOfRange
});
}
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;
const methodDeclaration = addressSpace.findNode(methodDeclarationId);
if (!methodDeclaration) {
function __validateDataChangeFilter(
filter: DataChangeFilter,
itemToMonitor: ReadValueIdOptions,
node: UAVariable
): StatusCode {
assert(itemToMonitor.attributeId === AttributeIds.Value);
if ((node.nodeClass !== NodeClass.Variable)) {
return StatusCodes.BadNodeIdInvalid;
}
assert(node.nodeClass === NodeClass.Variable);
// if node is not Numerical=> DataChangeFilter
assert(node.dataType instanceof NodeId);
const dataType = node.addressSpace.findDataType(node.dataType)!;
const dataTypeNumber = node.addressSpace.findDataType("Number")!;
if (filter.deadbandType !== DeadbandType.None) {
if (!dataType.isSupertypeOf(dataTypeNumber)) {
return StatusCodes.BadFilterNotAllowed;
}
}
if (filter.deadbandType === DeadbandType.Percent) {
function _oneShotShelve_method(inputArguments, context, callback) {
assert(inputArguments.length === 0);
const shelvingState = context.object;
if (shelvingState.getCurrentState() === "OneShotShelved") {
return callback(null, {
statusCode: StatusCodes.BadConditionAlreadyShelved
});
}
// checking duration ...
const alarmNode = context.object.parent;
// istanbul ignore next
if (!(alarmNode instanceof UAAlarmConditionBase)) {
return callback(null, {
statusCode: StatusCodes.BadNodeIdInvalid
});
}
const maxTimeShelved = alarmNode.getMaxTimeShelved();
assert(_.isFinite(maxTimeShelved));
assert(maxTimeShelved !== UAAlarmConditionBase.MaxDuration);
// set automatic unshelving timer
_clear_timer_if_any(shelvingState);
shelvingState.setState("OneShotShelved");
_start_timer_for_automatic_unshelve(shelvingState, maxTimeShelved);
return callback(null, {
statusCode: StatusCodes.Good
});
if (response.statusCode !== StatusCodes.Good) {
return callback(null, { statusCode: response.statusCode });
}
const methodDeclaration = response.methodDeclaration;
// verify input Parameters
const methodInputArguments = methodDeclaration.getInputArguments();
response = verifyArguments_ArgumentList(addressSpace, methodInputArguments, inputArguments);
if (response.statusCode !== StatusCodes.Good) {
return callback(null, response);
}
const methodObj = addressSpace.findNode(methodId) as UAMethod;
if (methodObj.nodeClass !== NodeClass.Method) {
return callback(null, { statusCode: StatusCodes.BadNodeIdInvalid });
}
// invoke method on object
const context = new SessionContext({
object: addressSpace.findNode(objectId) as UAObject,
server,
session
});
let l_extraDataTypeManager: ExtraDataTypeManager;
ensureDatatypeExtractedWithCallback(addressSpace, (err2: Error|null, extraDataTypeManager: ExtraDataTypeManager) => {
l_extraDataTypeManager = extraDataTypeManager;
// resolve opaque data structure from inputArguments
function _enable_method(
inputArguments: VariantLike[],
context: SessionContext,
callback: any
) {
assert(inputArguments.length === 0);
const conditionNode = context.object;
assert(conditionNode);
if (!(conditionNode instanceof UAConditionBase)) {
return callback(null, {
statusCode: StatusCodes.BadNodeIdInvalid
});
}
const statusCode = conditionNode._setEnabledState(true);
return callback(null, {
statusCode
});
}
function _on_node_disposed(monitoredItem) {
const node = this;
monitoredItem._on_value_changed(new DataValue({sourceTimestamp: new Date(),statusCode: StatusCodes.BadNodeIdInvalid}));
monitoredItem._stop_sampling();
}
function _enable_method(inputArguments, context, callback) {
assert(inputArguments.length === 0);
const conditionNode = context.object;
assert(conditionNode);
if (!(conditionNode instanceof UAConditionBase)) {
return callback(null, {
statusCode: StatusCodes.BadNodeIdInvalid
});
}
const statusCode = conditionNode._setEnabledState(true);
return callback(null, {
statusCode: statusCode
});
}
private _on_node_disposed(node: BaseNode) {
this._on_value_changed(new DataValue({
sourceTimestamp: new Date(),
statusCode: StatusCodes.BadNodeIdInvalid
}));
this._stop_sampling();
node.removeListener("dispose", this._on_node_disposed_listener);
this._on_node_disposed_listener = null;
}