Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public _assert_valid() {
assert(this.receiveTime.readValue().value.dataType === DataType.DateTime);
assert(this.receiveTime.readValue().value.value instanceof Date);
assert(this.message.readValue().value.dataType === DataType.LocalizedText);
assert(this.severity.readValue().value.dataType === DataType.UInt16);
assert(this.time.readValue().value.dataType === DataType.DateTime);
assert(this.time.readValue().value.value instanceof Date);
assert(this.quality.readValue().value.dataType === DataType.StatusCode);
assert(this.enabledState.readValue().value.dataType === DataType.LocalizedText);
assert(this.branchId.readValue().value.dataType === DataType.NodeId);
// note localTime has been made optional in 1.04
assert(!this.localTime || this.localTime.readValue().value.dataType === DataType.ExtensionObject);
}
eventType = eventType as UAObjectTypePublic;
let eventTypeNode = eventType;
// istanbul ignore next
if (!eventTypeNode) {
throw new Error("UAObject#raiseEventType : Cannot find event type :" + eventType.toString());
}
// coerce EventType
eventTypeNode = addressSpace.findEventType(eventType) as UAObjectTypePublic;
const baseEventType = addressSpace.findEventType("BaseEventType")!;
assert(eventTypeNode.isSupertypeOf(baseEventType));
data.$eventDataSource = eventTypeNode;
data.sourceNode = data.sourceNode || { dataType: DataType.NodeId, value: this.nodeId };
const eventData1 = addressSpace.constructEventData(eventTypeNode, data);
this._bubble_up_event(eventData1);
}
function ConditionSnapshot(condition, branchId) {
const self = this;
EventEmitter.call(this);
if (condition && branchId) {
assert(branchId instanceof NodeId);
//xx self.branchId = branchId;
self.condition = condition;
self.eventData = new EventData(condition);
// a nodeId/Variant map
_record_condition_state(self, condition);
if (branchId === NodeId.nullNodeId) {
_installOnChangeEventHandlers(self, condition, "");
}
self._set_var("branchId", DataType.NodeId, branchId);
}
}
util.inherits(ConditionSnapshot, EventEmitter);
eventTypeNode = addressSpace.findEventType(eventTypeId);
}
/* istanbul ignore next */
if (!eventTypeNode) {
throw new Error(" cannot find EvenType for " + eventTypeId);
}
assert(eventTypeNode instanceof UAObjectType,"eventTypeId must represent a UAObjectType");
// eventId
assert(data.hasOwnProperty,"eventId","constructEventData : options object should not have eventId property");
data.eventId = data.eventId || addressSpace.generateEventId();
// eventType
data.eventType = { dataType: DataType.NodeId, value: eventTypeNode.nodeId};
// sourceNode
assert(data.hasOwnProperty("sourceNode"), "expecting a source node to be defined");
data.sourceNode = new Variant(data.sourceNode);
assert(data.sourceNode.dataType === DataType.NodeId);
// sourceName
const sourceNode = addressSpace.findNode(data.sourceNode.value);
data.sourceName = data.sourceName || { dataType: DataType.String, value: sourceNode.getDisplayName("en") };
const nowUTC = (new Date());
// time (UtcTime)
// TODO
data.time = data.time || { dataType: DataType.DateTime, value: nowUTC};
let conditionClassId = baseConditionClassType ? baseConditionClassType.nodeId : NodeId.nullNodeId;
let conditionClassName = baseConditionClassType ? baseConditionClassType.displayName[0] : "";
if (options.conditionClass) {
if (_.isString(options.conditionClass)) {
options.conditionClass = addressSpace.findObjectType(options.conditionClass);
}
const conditionClassNode = addressSpace._coerceNode(options.conditionClass);
if (!conditionClassNode) {
throw new Error("cannot find condition class " + options.conditionClass.toString());
}
conditionClassId = conditionClassNode.nodeId;
conditionClassName = conditionClassNode.displayName[0];
}
conditionNode.conditionClassId.setValueFromSource({
dataType: DataType.NodeId,
value: conditionClassId
});
// as per spec:
// ConditionClassName provides the display name of the ConditionClassType.
conditionNode.conditionClassName.setValueFromSource({
dataType: DataType.LocalizedText,
value: coerceLocalizedText(conditionClassName)
});
// as per spec:
/**
*
* dataType: DataType.String
*
* As per spec OPCUA 1.03 part 9:
BaseNode.prototype.readAttribute = function (context, attributeId, indexRange, dataEncoding) {
assert(context instanceof SessionContext);
const options = {};
options.statusCode = StatusCodes.Good;
switch (attributeId) {
case AttributeIds.NodeId: // NodeId
options.value = {dataType: DataType.NodeId, value: this.nodeId};
break;
case AttributeIds.NodeClass: // NodeClass
assert(_.isFinite(this.nodeClass));
options.value = {dataType: DataType.Int32, value: this.nodeClass};
break;
case AttributeIds.BrowseName: // QualifiedName
assert(this.browseName instanceof QualifiedName);
options.value = {dataType: DataType.QualifiedName, value: this.browseName};
break;
case AttributeIds.DisplayName: // LocalizedText
options.value = {dataType: DataType.LocalizedText, value: this.displayName[0]};
break;
if (!eventTypeNode) {
throw new Error(" cannot find EvenType for " + eventTypeId);
}
assert(eventTypeNode instanceof UAObjectType, "eventTypeId must represent a UAObjectType");
// eventId
assert(data.hasOwnProperty, "eventId constructEventData : options object should not have eventId property");
data.eventId = data.eventId || addressSpace.generateEventId();
// eventType
data.eventType = { dataType: DataType.NodeId, value: eventTypeNode.nodeId };
// sourceNode
assert(data.hasOwnProperty("sourceNode"), "expecting a source node to be defined");
data.sourceNode = new Variant(data.sourceNode);
assert(data.sourceNode.dataType === DataType.NodeId);
// sourceName
const sourceNode = addressSpace.findNode(data.sourceNode.value)!;
data.sourceName = data.sourceName || {
dataType: DataType.String,
value: sourceNode.getDisplayName("en")
};
const nowUTC = (new Date());
// time (UtcTime)
// TODO
data.time = data.time || { dataType: DataType.DateTime, value: nowUTC };
// receivedTime (UtcTime)
export function DeviationAlarmHelper_getSetpointNodeNode(this: DeviationStuff) {
assert(this.setpointNode.readValue().value.dataType === DataType.NodeId);
const nodeId = this.setpointNode.readValue().value.value;
const node = this.addressSpace.findNode(nodeId);
assert(node === this.setpointNodeNode);
return this.setpointNodeNode;
}
export function DeviationAlarmHelper_getSetpointValue(this: DeviationStuff): number | null {
private _readDataType(): DataValue {
assert(this.dataType instanceof NodeId);
const options = {
statusCode: StatusCodes.Good,
value: {
dataType: DataType.NodeId,
value: this.dataType
}
};
return new DataValue(options);
}
options.statusCode = StatusCodes.Good;
break;
case AttributeIds.Value:
if (this.hasOwnProperty("value") && this.value !== undefined) {
assert(this.value.schema.name === "Variant");
options.value = this.value;
options.statusCode = StatusCodes.Good;
} else {
debugLog(" warning Value not implemented");
options.value = { dataType: DataType.UInt32, value: 0 };
options.statusCode = StatusCodes.BadAttributeIdInvalid;
}
break;
case AttributeIds.DataType:
assert(this.dataType instanceof NodeId);
options.value = { dataType: DataType.NodeId, value: this.dataType };
options.statusCode = StatusCodes.Good;
break;
case AttributeIds.ValueRank:
options.value = { dataType: DataType.Int32, value: this.valueRank };
options.statusCode = StatusCodes.Good;
break;
case AttributeIds.ArrayDimensions:
assert(_.isArray(this.arrayDimensions) || this.arrayDimensions === null);
options.value = {
arrayType: VariantArrayType.Array,
dataType: DataType.UInt32,
value: this.arrayDimensions
};
options.statusCode = StatusCodes.Good;
break;
default: