From 8dc59b0ec41acc85bfb631f4446701f83a69a7b8 Mon Sep 17 00:00:00 2001 From: Darrel O'Pry Date: Thu, 8 Mar 2018 17:05:45 -0500 Subject: [PATCH 1/3] feat: add enumeration metadata --- lib/enum.js | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/lib/enum.js b/lib/enum.js index 323440df..58102e91 100644 --- a/lib/enum.js +++ b/lib/enum.js @@ -1,5 +1,84 @@ 'use strict'; +// SEE: ASHRAE 135-2016, 21 FORMAL DESCRIPTION OF APPLICATION PROTOCOL DATA UNITS +// for a detailed reference of all enumerations. + +module.exports.Meta = { + // Metadata for non-exensible enumerations + Segmentations: {extensible: false, used: [{min: 0, max: 3}], reserved: [{min: 0, max: 3}], max: 3}, + ServicesSupported: {extensible: false, used: [{min: 0, max: 40}], reserved: [{min: 0, max: 40}], max: 40}, + UnconfirmedServices: {extensible: false, used: [{min: 0, max: 10}], reserved: [{min: 0, max: 10}], max: 10}, + ConfirmedServices: {extensible: false, used: [{min: 0, max: 29}], reserved: [{min: 0, max: 29}], max: 29}, + ApplicationTags: {extensible: false, used: [{min: 0, max: 16}], reserved: [{min: 0, max: 16}], max: 16}, + BvlcFunctions: {extensible: false, used: [{min: 0, max: 12}], reserved: [{min: 0, max: 12}], max: 12}, + BackupState: {extensible: false, used: [{min: 0, max: 4}], reserved: [{min: 0, max: 4}], max: 4}, + ProgramChange: {extensible: false, used: [{min: 0, max: 5}], reserved: [{min: 0, max: 5}], max: 5}, + ReasonForHalt: {extensible: false, used: [{min: 0, max: 4}], reserved: [{min: 0, max: 4}], max: 4}, + ResultFlags: {extensible: false, used: [{min: 0, max: 4}], reserved: [{min: 0, max: 4}], max: 4}, + StatusFlags: {extensible: false, used: [{min: 0, max: 8}], reserved: [{min: 0, max: 8}], max: 8}, + Units: {extensible: false, used: [{min: 0, max: 253}], reserved: [{min: 0, max: 253}], max: 253}, + Polarity: {extensible: false, used: [{min: 0, max: 1}], reserved: [{min: 0, max: 1}], max: 1}, + MaxSegments: {extensible: false, used: [{min: 0, max: 0x70}], reserved: [{min: 0, max: 0x70}], max: 0x70}, + MaxAdpu: {extensible: false, used: [{min: 0, max: 5}], reserved: [{min: 0, max: 5}], max: 5}, + NodeTypes: {extensible: false, used: [{min: 0, max: 11}], reserved: [{min: 0, max: 11}], max: 11}, + BvleResults: {extensible: false, used: [{min: 0, max: 0x0060}], reserved: [{min: 0, max: 0x0060}], max: 0x0060}, + NpduControls: {extensible: false, used: [{min: 0, max: 128}], reserved: [{min: 0, max: 128}], max: 128}, + NetworkMessageTypes: {extensible: false, used: [{min: 0, max: 9}], reserved: [{min: 0, max: 9}], max: 9}, + ReinitializedStates: {extensible: false, used: [{min: 0, max: 255}], reserved: [{min: 0, max: 255}], max: 255}, + CharacterStringEncodings: {extensible: false, used: [{min: 0, max: 5}], reserved: [{min: 0, max: 5}], max: 5}, + ReadRangeRequestTypes: {extensible: false, used: [{min: 0, max: 8}], reserved: [{min: 0, max: 8}], max: 8}, + EnableDisable: {extensible: false, used: [{min: 0, max: 2}], reserved: [{min: 0, max: 2}], max: 2}, + NotifyTypes: {extensible: false, used: [{min: 0, max: 2}], reserved: [{min: 0, max: 2}], max: 2}, + COVTypes: {extensible: false, used: [{min: 0, max: 1}], reserved: [{min: 0, max: 1}], max: 1}, + TimestampTags: {extensible: false, used: [{min: -1, max: 2}], reserved: [{min: -1, max: 2}], max: 2}, + + // MetaData for extensible enumerations. + ErrorClass: {extensible: true, used: [{min: 0, max: 7}], reserved: [{min: 0, max: 63}], max: 65535}, + ErrorCode: {extensible: true, used: [{min: 0, max: 136}], reserved: [{min: 0, max: 255}], max: 65535}, + AbortReason: {extensible: true, used: [{min: 0, max: 11}], reserved: [{min: 0, max: 63}], max: 255}, + AccessAuthenticationFactorDisable: {extensible: true, used: [{min: 0, max: 5}], reserved: [{min: 0, max: 63}], max: 65535}, + AccessCredentialDisable: {extensible: true, used: [{min: 0, max: 3}], reserved: [{min: 0, max: 63}], max: 65535}, + AccessCredentialDisableReason: {extensible: true, used: [{min: 0, max: 9}], reserved: [{min: 0, max: 63}], max: 65535}, + AccessEvent: {extensible: true, used: [{min: 0, max: 16},{min: 128, max: 164}], reserved: [{min: 0, max: 511}], max: 65535}, + AccessUserType: {extensible: true, used: [{min: 0, max: 2}], reserved: [{min: 0, max: 63}], max: 65535}, + AccessZoneOccupancyState: {extensible: true, used: [{min: 0, max: 6}], reserved: [{min: 0, max: 63}], max: 65535}, + AuthorizationExemption: {extensible: true, used: [{min: 0, max: 6}], reserved: [{min: 0, max: 63}], max: 255}, + AuthorizationMode: {extensible: true, used: [{min: 0, max: 5}], reserved: [{min: 0, max: 63}], max: 65535}, + BinaryLightingPV: {extensible: true, used: [{min: 0, max: 5}], reserved: [{min: 0, max: 63}], max: 255}, + DeviceStatus: {extensible: true, used: [{min: 0, max: 5}], reserved: [{min: 0, max: 63}], max: 65535}, + DoorAlarmState: {extensible: true, used: [{min: 0, max: 8}], reserved: [{min: 0, max: 255}], max: 65535}, + DoorStatus: {extensible: true, used: [{min: 0, max: 9}], reserved: [{min: 0, max: 1023}], max: 65535}, + EngineeringUnits: {extensible: true, used: [{min: 0, max: 254}, {min: 47808, max: 47815}], reserved: [{min: 0, max: 255}, {min: 47808, max: 49999}], max: 65535}, + EscalatorFault: {extensible: true, used: [{min: 0, max: 8}], reserved: [{min: 0, max: 1023}], max: 65535}, + EscalatorMode: {extensible: true, used: [{min: 0, max: 5}], reserved: [{min: 0, max: 1023}], max: 65535}, + EscalatorOperationDirection: {extensible: true, used: [{min: 0, max: 5}], reserved: [{min: 0, max: 1023}], max: 65535}, + EventState: {extensible: true, used: [{min: 0, max: 5}], reserved: [{min: 0, max: 63}], max: 65535}, + EventType: {extensible: true, used: [{min: 0, max: 22}], reserved: [{min: 0, max: 63}], max: 65535}, + LifeSafetyMode: {extensible: true, used: [{min: 0, max: 14}], reserved: [{min: 0, max: 255}], max: 65535}, + LifeSafetyOperation: {extensible: true, used: [{min: 0, max: 9}], reserved: [{min: 0, max: 63}], max: 65535}, + LifeSafetyState: {extensible: true, used: [{min: 0, max: 23}], reserved: [{min: 0, max: 255}], max: 65535}, + LiftCarDirection: {extensible: true, used: [{min: 0, max: 5}], reserved: [{min: 0, max: 1023}], max: 65535}, + LiftCarDriveStatus: {extensible: true, used: [{min: 0, max: 9}], reserved: [{min: 0, max: 1023}], max: 65535}, + LiftCarMode: {extensible: true, used: [{min: 0, max: 13}], reserved: [{min: 0, max: 1023}], max: 65535}, + LiftFault: {extensible: true, used: [{min: 0, max: 16}], reserved: [{min: 0, max: 1023}], max: 65535}, + LightingOperation: {extensible: true, used: [{min: 0, max: 10}], reserved: [{min: 0, max: 255}], max: 65535}, + LightingTransition: {extensible: true, used: [{min: 0, max: 2}], reserved: [{min: 0, max: 63}], max: 255}, + LoggingType: {extensible: true, used: [{min: 0, max: 2}], reserved: [{min: 0, max: 63}], max: 255}, + Maintenance: {extensible: true, used: [{min: 0, max: 3}], reserved: [{min: 0, max: 255}], max: 65535}, + NetworkPortCommand: {extensible: true, used: [{min: 0, max: 7}], reserved: [{min: 0, max: 127}], max: 255}, + NetworkType: {extensible: true, used: [{min: 0, max: 10}], reserved: [{min: 0, max: 63}], max: 255}, + ObjectType: {extensible: true, used: [{min: 0, max: 59}], reserved: [{min: 0, max: 127}], max: 1023}, + ProgramError: {extensible: true, used: [{min: 0, max: 4}], reserved: [{min: 0, max: 63}], max: 65535}, + PropertyIdentifier: {extensible: true, used: [{min: 0, max: 491}], reserved: [{min: 0, max: 511}], max: 4194303}, + PropertyStates: {extensible: true, used: [{min: 0, max: 58}], reserved: [{min: 0, max: 63}], max: 254}, + RejectReason: {extensible: true, used: [{min: 0, max: 9}], reserved: [{min: 0, max: 63}], max: 255}, + Relationship: {extensible: true, used: [{min: 0, max: 29}], reserved: [{min: 0, max: 1023}], max: 65535}, + Reliability: {extensible: true, used: [{min: 0, max: 24}], reserved: [{min: 0, max: 63}], max: 65535}, + RestartReason: {extensible: true, used: [{min: 0, max: 8}], reserved: [{min: 0, max: 63}], max: 255}, + SilencedState: {extensible: true, used: [{min: 0, max: 3}], reserved: [{min: 0, max: 63}], max: 65535}, + VTClass: {extensible: true, used: [{min: 0, max: 6}], reserved: [{min: 0, max: 63}], max: 65535}, +}; + module.exports.PduTypes = { PDU_TYPE_CONFIRMED_SERVICE_REQUEST: 0, SERVER: 1, From e17501f2a02db4685fa2eab702e87e555b517339 Mon Sep 17 00:00:00 2001 From: Darrel O'Pry Date: Thu, 8 Mar 2018 17:24:59 -0500 Subject: [PATCH 2/3] refactor: use enum.Meta --- lib/asn1.js | 6 +++--- lib/services.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/asn1.js b/lib/asn1.js index 8872a7c2..3177b5c4 100644 --- a/lib/asn1.js +++ b/lib/asn1.js @@ -1086,7 +1086,7 @@ const bacappDecodeData = (buffer, offset, maxLength, tagDataType, lenValueType) }; const bacappContextTagType = (property, tagNumber) => { - let tag = baEnum.ApplicationTags.MAX_BACNET_APPLICATION_TAG; + let tag = baEnum.Meta.ApplicationTags.max; switch (property) { case baEnum.PropertyIds.PROP_ACTUAL_SHED_LEVEL: case baEnum.PropertyIds.PROP_REQUESTED_SHED_LEVEL: @@ -1520,13 +1520,13 @@ const bacappDecodeContextApplicationData = (buffer, offset, maxOffset, objectTyp if (!subResult) return; if (subResult.value === 0) { len += subResult.len; - result = bacappDecodeApplicationData(buffer, offset + len, maxOffset, baEnum.ObjectTypes.MAX_BACNET_OBJECT_TYPE, baEnum.PropertyIds.MAX_BACNET_PROPERTY_ID); + result = bacappDecodeApplicationData(buffer, offset + len, maxOffset, baEnum.Meta.ObjectType.max, baEnum.Meta.PropertyIdentifier.max); if (!result) return; list.push(result); len += result.len; } else { const overrideTagNumber = bacappContextTagType(propertyId, subResult.tagNumber); - if (overrideTagNumber !== baEnum.ApplicationTags.MAX_BACNET_APPLICATION_TAG) { + if (overrideTagNumber !== baEnum.Meta.ApplicationTags.max) { subResult.tagNumber = overrideTagNumber; } let bacappResult = bacappDecodeData(buffer, offset + len + subResult.len, maxOffset, subResult.tagNumber, subResult.value); diff --git a/lib/services.js b/lib/services.js index cc2084cc..455465df 100644 --- a/lib/services.js +++ b/lib/services.js @@ -585,7 +585,7 @@ module.exports.encodeReadProperty = (buffer, objectType, objectInstance, propert if (objectType <= baAsn1.BACNET_MAX_OBJECT) { baAsn1.encodeContextObjectId(buffer, 0, objectType, objectInstance); } - if (propertyId <= baEnum.PropertyIds.MAX_BACNET_PROPERTY_ID) { + if (propertyId <= baEnum.Meta.PropertyIdentifier.max) { baAsn1.encodeContextEnumerated(buffer, 1, propertyId); } if (arrayIndex !== baAsn1.BACNET_ARRAY_ALL) { From b2092f0f6ac1dfbe13a6f2bf5fbf7fab431d6e60 Mon Sep 17 00:00:00 2001 From: Darrel O'Pry Date: Thu, 8 Mar 2018 17:32:13 -0500 Subject: [PATCH 3/3] chore: remove meta data from enumerations --- lib/enum.js | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/lib/enum.js b/lib/enum.js index 58102e91..59969219 100644 --- a/lib/enum.js +++ b/lib/enum.js @@ -175,9 +175,6 @@ module.exports.RejectReasons = { REJECT_REASON_TOO_MANY_ARGUMENTS: 7, REJECT_REASON_UNDEFINED_ENUMERATION: 8, REJECT_REASON_UNRECOGNIZED_SERVICE: 9, - MAX_BACNET_REJECT_REASON: 10, - REJECT_REASON_PROPRIETARY_FIRST: 64, - REJECT_REASON_PROPRIETARY_LAST: 65535 }; module.exports.ErrorClasses = { @@ -189,9 +186,6 @@ module.exports.ErrorClasses = { ERROR_CLASS_SERVICES: 5, ERROR_CLASS_VT: 6, ERROR_CLASS_COMMUNICATION: 7, - MAX_BACNET_ERROR_CLASS: 8, - ERROR_CLASS_PROPRIETARY_FIRST: 64, - ERROR_CLASS_PROPRIETARY_LAST: 65535 }; module.exports.ErrorCodes = { @@ -332,9 +326,6 @@ module.exports.ErrorCodes = { ERROR_CODE_VALUE_TOO_LONG: 134, ERROR_CODE_ABORT_INSUFFICIENT_SECURITY: 135, ERROR_CODE_ABORT_SECURITY_ERROR: 136, - MAX_BACNET_ERROR_CODE: 137, - ERROR_CODE_PROPRIETARY_FIRST: 256, - ERROR_CODE_PROPRIETARY_LAST: 65535 }; module.exports.StatusFlags = { @@ -386,7 +377,6 @@ module.exports.ServicesSupported = { SERVICE_SUPPORTED_UTC_TIME_SYNCHRONIZATION: 36, SERVICE_SUPPORTED_WHO_HAS: 33, SERVICE_SUPPORTED_WHO_IS: 34, - MAX_BACNET_SERVICES_SUPPORTED: 41 }; module.exports.UnconfirmedServices = { @@ -401,7 +391,6 @@ module.exports.UnconfirmedServices = { SERVICE_UNCONFIRMED_WHO_IS: 8, SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION: 9, SERVICE_UNCONFIRMED_WRITE_GROUP: 10, - MAX_BACNET_UNCONFIRMED_SERVICE: 11 }; module.exports.ConfirmedServices = { @@ -435,7 +424,6 @@ module.exports.ConfirmedServices = { SERVICE_CONFIRMED_VT_DATA: 23, SERVICE_CONFIRMED_AUTHENTICATE: 24, SERVICE_CONFIRMED_REQUEST_KEY: 25, - MAX_BACNET_CONFIRMED_SERVICE: 30 }; module.exports.UnitsId = { @@ -809,10 +797,6 @@ module.exports.ObjectTypes = { OBJECT_CHANNEL: 53, OBJECT_LIGHTING_OUTPUT: 54, OBJECT_BINARY_LIGHTING_OUTPUT: 55, - OBJECT_PROPRIETARY_MIN: 128, - OBJECT_PROPRIETARY_MAX: 1023, - MAX_BACNET_OBJECT_TYPE: 1024, - MAX_ASHRAE_OBJECT_TYPE: 55 }; /** @@ -836,7 +820,6 @@ module.exports.ApplicationTags = { BACNET_APPLICATION_TAG_RESERVE1: 13, BACNET_APPLICATION_TAG_RESERVE2: 14, BACNET_APPLICATION_TAG_RESERVE3: 15, - MAX_BACNET_APPLICATION_TAG: 16, BACNET_APPLICATION_TAG_EMPTYLIST: 100, BACNET_APPLICATION_TAG_WEEKNDAY: 101, BACNET_APPLICATION_TAG_DATERANGE: 102, @@ -1235,7 +1218,6 @@ module.exports.PropertyIds = { PROP_STATE_CHANGE_VALUES: 396, PROP_TIMER_RUNNING: 397, PROP_TIMER_STATE: 398, - MAX_BACNET_PROPERTY_ID: 4194303 }; module.exports.NodeTypes = { @@ -1266,7 +1248,6 @@ module.exports.BvlcFunctions = { BVLC_DISTRIBUTE_BROADCAST_TO_NETWORK: 9, BVLC_ORIGINAL_UNICAST_NPDU: 10, BVLC_ORIGINAL_BROADCAST_NPDU: 11, - MAX_BVLC_FUNCTION: 12 }; module.exports.BvlcResults = {