Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/asn1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand Down
98 changes: 79 additions & 19 deletions lib/enum.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -96,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 = {
Expand All @@ -110,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 = {
Expand Down Expand Up @@ -253,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 = {
Expand Down Expand Up @@ -307,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 = {
Expand All @@ -322,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 = {
Expand Down Expand Up @@ -356,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 = {
Expand Down Expand Up @@ -730,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
};

/**
Expand All @@ -757,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,
Expand Down Expand Up @@ -1156,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 = {
Expand Down Expand Up @@ -1187,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 = {
Expand Down
2 changes: 1 addition & 1 deletion lib/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down