File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -484,8 +484,10 @@ const bacappEncodeApplicationData = module.exports.bacappEncodeApplicationData =
484484 case baEnum . ApplicationTags . READ_ACCESS_SPECIFICATION :
485485 encodeReadAccessSpecification ( buffer , value . value ) ;
486486 break ;
487+ case undefined :
488+ throw new Error ( 'Cannot encode a value if the type has not been specified' ) ;
487489 default :
488- throw 'Unknown type' ;
490+ throw 'Unknown ApplicationTags type: ' + baEnum . getEnumName ( baEnum . ApplicationTags , value . type ) ;
489491 }
490492} ;
491493
Original file line number Diff line number Diff line change 11'use strict' ;
22
3+ /**
4+ * Turn an enum into a string suitable for debugging.
5+ *
6+ * @param object group
7+ * Enum group, e.g. bacnet.enum.ConfirmedServiceChoice.
8+ *
9+ * @param Number value
10+ * Enum value, e.g. 1. Note that this *must* be an integer value, so you may
11+ * need to use parseInt(). Non-integer values will result in an exception.
12+ *
13+ * @example
14+ * const s = bacnet.enum.getEnumName(
15+ * bacnet.enum.PropertyIdentifier,
16+ * bacnet.enum.PropertyIdentifier.PRESENT_VALUE
17+ * );
18+ * console.log(s); // "PRESENT_VALUE(85)"
19+ */
20+ module . exports . getEnumName = function ( group , value ) {
21+ if ( ! Number . isInteger ( value ) ) {
22+ throw new Error ( 'getEnumName() can only be passed an integer value, was given "' + value + '"' ) ;
23+ }
24+ return Object . keys ( group ) . find ( key => group [ key ] === value ) + '(' + value + ')' ;
25+ }
26+
327module . exports . PDU_TYPE_MASK = 0xF0 ;
428module . exports . ASN1_MAX_OBJECT = 0x3FF ;
529module . exports . ASN1_INSTANCE_BITS = 22 ;
You can’t perform that action at this time.
0 commit comments