File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1204,5 +1204,34 @@ class Client extends EventEmitter {
12041204 close ( ) {
12051205 this . _transport . close ( ) ;
12061206 }
1207+
1208+ /**
1209+ * Helper function to take an array of enums and produce a bitstring suitable
1210+ * for inclusion as a property.
1211+ *
1212+ * @example
1213+ * [bacnet.enum.PropertyIdentifier.PROTOCOL_OBJECT_TYPES_SUPPORTED]: [
1214+ * {value: bacnet.createBitstring([
1215+ * bacnet.enum.ObjectTypesSupported.ANALOG_INPUT,
1216+ * bacnet.enum.ObjectTypesSupported.ANALOG_OUTPUT,
1217+ * ]),
1218+ * type: bacnet.enum.ApplicationTags.BIT_STRING},
1219+ * ],
1220+ */
1221+ static createBitstring ( items ) {
1222+ let value = 0 ;
1223+ items . forEach ( i => value |= 1 << i ) ;
1224+ let bytes = [ ] , bitsUsed = 0 ;
1225+ while ( value & 0xFF ) {
1226+ bytes . push ( value & 0xFF ) ;
1227+ bitsUsed += 8 ;
1228+ value >>= 8 ;
1229+ }
1230+ return {
1231+ value : bytes ,
1232+ bitsUsed : bitsUsed ,
1233+ } ;
1234+ }
1235+
12071236}
12081237module . exports = Client ;
You can’t perform that action at this time.
0 commit comments