import { BinaryStream , OutputBinaryStream } from "node-opcua-binary-stream" ; import { registerBasicType } from "node-opcua-factory" ; import { _accessLevelFlagToString } from "./access_level" ; import { _make_flag } from "./_make_flag" ; /**
 * from https://reference.opcfoundation.org/v104/Core/docs/Part3/8.58/:
 *
 * This is a subtype of the UInt32 DataType with the OptionSetValues Property defined.
 * It is used to indicate how the Value of a Variable can be accessed (read/write),
 * if it contains current and/or historic data and its atomicity.
 * The AccessLevelExType DataType is an extended version of the AccessLevelType DataType and
 * as such contains the 8 bits of the AccessLevelType as the first 8 bits.
 * The NonatomicRead, and NonatomicWrite Fields represent the atomicity of a Variable.
 *  In general Atomicity is expected of OPC UA read and write operations.
 * These Fields are used by systems, in particular hard-realtime controllers, which can not ensure atomicity.
 */ export enum AccessLevelExFlag { CurrentRead = 0x01 , CurrentWrite = 0x02 , HistoryRead = 0x04 , HistoryWrite = 0x08 , SemanticChange = 0x10 , StatusWrite = 0x20 , TimestampWrite = 0x40 , NonatomicRead = 0x80 , NonatomicWrite = 0x100 , WriteFullArrayOnly = 0x200 , NoSubDataTypes = 0x400 , NonVolatile = 0x800 , Constant = 0x1000 , None = 0x800 } export function makeAccessLevelExFlag ( str ) { return _make_flag ( str , AccessLevelExFlag . None , AccessLevelExFlag ) as AccessLevelExFlag ; } export function randomAccessLevelEx ( ) { return Math . ceil ( Math . random ( ) * 0x200 ) ; } export function accessLevelExFlagToString ( accessLevelFlag ) { const retVal = _accessLevelFlagToString ( accessLevelFlag ) ; if ( accessLevelFlag & AccessLevelExFlag . NonatomicRead ) { retVal . push ( "NonatomicRead" ) ; } if ( accessLevelFlag & AccessLevelExFlag . NonatomicWrite ) { retVal . push ( "NonatomicWrite" ) ; } if ( accessLevelFlag & AccessLevelExFlag . WriteFullArrayOnly ) { retVal . push ( "WriteFullArrayOnly" ) ; } if ( accessLevelFlag & AccessLevelExFlag . NoSubDataTypes ) { retVal . push ( "NoSubDataTypes" ) ; } if ( accessLevelFlag & AccessLevelExFlag . NonVolatile ) { retVal . push ( "NonVolatile" ) ; } if ( accessLevelFlag & AccessLevelExFlag . Constant ) { retVal . push ( "Constant" ) ; } if ( retVal . length === 0 ) { retVal . push ( "None" ) ; } return retVal . join ( " | " ) ; } export function encodeAccessLevelExFlag ( value , stream ) { stream . writeUInt32 ( value & 0xfffff ) ; } export function decodeAccessLevelExFlag ( stream ) { const code = stream . readUInt32 ( ) ; return code ; } registerBasicType ( { name : "AccessLevelExFlag" , subType : "UInt32" , defaultValue : AccessLevelExFlag . CurrentRead | AccessLevelExFlag . CurrentWrite , coerce : makeAccessLevelExFlag , decode : decodeAccessLevelExFlag , encode : encodeAccessLevelExFlag , random : randomAccessLevelEx } ) ;