Skip to content

Commit ef92244

Browse files
committed
refactor(bacnet-asn1): rework all ASN1 variable names to adhere the styleguide
1 parent b31bc00 commit ef92244

4 files changed

Lines changed: 76 additions & 76 deletions

File tree

lib/bacnet-asn1.js

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -195,20 +195,20 @@ var encodeApplicationDouble = function(buffer, value) {
195195

196196
var bitstringBytesUsed = function(bitString) {
197197
var len = 0;
198-
if (bitString.bits_used > 0) {
199-
var lastBit = bitString.bits_used - 1;
198+
if (bitString.bitsUsed > 0) {
199+
var lastBit = bitString.bitsUsed - 1;
200200
var usedBytes = (lastBit / 8) + 1;
201201
len = Math.floor(usedBytes);
202202
}
203203
return len;
204204
};
205205

206-
var encodeApplicationObjectId = module.exports.encodeApplicationObjectId = function(buffer, object_type, instance) {
206+
var encodeApplicationObjectId = module.exports.encodeApplicationObjectId = function(buffer, objectType, instance) {
207207
var tmp = {
208208
buffer: Buffer.alloc(1472),
209209
offset: 0
210210
};
211-
encodeBacnetObjectId(tmp, object_type, instance);
211+
encodeBacnetObjectId(tmp, objectType, instance);
212212
encodeTag(buffer, baEnum.BacnetApplicationTags.BACNET_APPLICATION_TAG_OBJECT_ID, false, tmp.offset);
213213
tmp.buffer.copy(buffer.buffer, buffer.offset, 0, tmp.offset);
214214
buffer.offset += tmp.offset;
@@ -287,11 +287,11 @@ var bitstringOctet = function(bitString, octetIndex) {
287287
};
288288

289289
var encodeBitstring = function(buffer, bitString) {
290-
if (bitString.bits_used === 0) {
290+
if (bitString.bitsUsed === 0) {
291291
buffer.buffer[buffer.offset++] = 0;
292292
} else {
293293
var usedBytes = bitstringBytesUsed(bitString);
294-
var remainingUsedBits = bitString.bits_used - ((usedBytes - 1) * 8);
294+
var remainingUsedBits = bitString.bitsUsed - ((usedBytes - 1) * 8);
295295
buffer.buffer[buffer.offset++] = 8 - remainingUsedBits;
296296
for (var i = 0; i < usedBytes; i++) {
297297
buffer.buffer[buffer.offset++] = byteReverseBits(bitstringOctet(bitString, i));
@@ -720,8 +720,8 @@ var encodeReadAccessResult = module.exports.encodeReadAccessResult = function(bu
720720
}
721721
if (item.value && item.value[0].Value.type === 'BacnetError') {
722722
encodeOpeningTag(buffer, 5);
723-
encodeApplicationEnumerated(buffer, item.value[0].Value.error_class);
724-
encodeApplicationEnumerated(buffer, item.value[0].Value.error_code);
723+
encodeApplicationEnumerated(buffer, item.value[0].Value.errorClass);
724+
encodeApplicationEnumerated(buffer, item.value[0].Value.errorCode);
725725
encodeClosingTag(buffer, 5);
726726
} else {
727727
encodeOpeningTag(buffer, 4);
@@ -748,9 +748,9 @@ var decodeReadAccessResult = module.exports.decodeReadAccessResult = function(bu
748748
if (!decodeIsOpeningTagNumber(buffer, offset + len, 1)) return -1;
749749
len++;
750750

751-
var _value_list = [];
751+
var valueList = [];
752752
while ((apduLen - len) > 0) {
753-
var new_entry = {};
753+
var newEntry = {};
754754
if (decodeIsClosingTagNumber(buffer, offset + len, 1)) {
755755
len++;
756756
break;
@@ -759,24 +759,24 @@ var decodeReadAccessResult = module.exports.decodeReadAccessResult = function(bu
759759
len += result.len;
760760
if (result.tagNumber !== 2) return;
761761
result = decodeEnumerated(buffer, offset + len, result.value);
762-
new_entry.propertyIdentifier = result.value;
762+
newEntry.propertyIdentifier = result.value;
763763
len += result.len;
764764

765765
result = decodeTagNumberAndValue(buffer, offset + len);
766766
if (result.tagNumber === 3) {
767767
len += result.len;
768768
result = decodeUnsigned(buffer, offset + len, result.value);
769-
new_entry.propertyArrayIndex = result.value;
769+
newEntry.propertyArrayIndex = result.value;
770770
len += result.len;
771771
} else {
772-
new_entry.propertyArrayIndex = BACNET_ARRAY_ALL;
772+
newEntry.propertyArrayIndex = BACNET_ARRAY_ALL;
773773
}
774774
result = decodeTagNumberAndValue(buffer, offset + len);
775775
len += result.len;
776776
if (result.tagNumber === 4) {
777777
var localValues = [];
778778
while ((len + offset) <= buffer.length && !decodeIsClosingTagNumber(buffer, offset + len, 4)) {
779-
var localResult = bacappDecodeApplicationData(buffer, offset + len, apduLen + offset - 1, value.objectIdentifier.type, new_entry.propertyIdentifier);
779+
var localResult = bacappDecodeApplicationData(buffer, offset + len, apduLen + offset - 1, value.objectIdentifier.type, newEntry.propertyIdentifier);
780780
if (!localResult) return;
781781
len += localResult.len;
782782
localValues.push({value: localResult.value, type: localResult.type});
@@ -786,11 +786,11 @@ var decodeReadAccessResult = module.exports.decodeReadAccessResult = function(bu
786786
var date = localValues[0].value;
787787
var time = localValues[1].value;
788788
var bdatetime = new Date(date.year, date.month, date.day, time.hour, time.minute, time.second, time.millisecond);
789-
new_entry.value = [
789+
newEntry.value = [
790790
{type: baEnum.BacnetApplicationTags.BACNET_APPLICATION_TAG_DATETIME, value: bdatetime}
791791
];
792792
} else {
793-
new_entry.value = localValues;
793+
newEntry.value = localValues;
794794
}
795795
len++;
796796
} else if (result.tagNumber === 5) {
@@ -804,17 +804,17 @@ var decodeReadAccessResult = module.exports.decodeReadAccessResult = function(bu
804804
len += result.len;
805805
result = decodeEnumerated(buffer, offset + len, result.value);
806806
len += result.len;
807-
err.error_code = result.value;
807+
err.errorCode = result.value;
808808
if (!decodeIsClosingTagNumber(buffer, offset + len, 5)) return;
809809
len++;
810-
new_entry.value = {
810+
newEntry.value = {
811811
type: baEnum.BacnetApplicationTags.BACNET_APPLICATION_TAG_ERROR,
812812
value: err
813813
};
814814
}
815-
_value_list.push(new_entry);
815+
valueList.push(newEntry);
816816
}
817-
value.values = _value_list;
817+
value.values = valueList;
818818
return {
819819
len: len,
820820
value: value
@@ -931,8 +931,8 @@ var bitstringSetOctet = function(bitString, index, octet) {
931931
};
932932

933933
var bitstringSetBitsUsed = function(bitString, bytesUsed, unusedBits) {
934-
bitString.bits_used = bytesUsed * 8;
935-
bitString.bits_used -= unusedBits;
934+
bitString.bitsUsed = bytesUsed * 8;
935+
bitString.bitsUsed -= unusedBits;
936936
};
937937

938938
var decodeBitstring = function(buffer, offset, lenValue) {
@@ -1291,33 +1291,33 @@ var decodeReadAccessSpecification = module.exports.decodeReadAccessSpecification
12911291
len += decodedValue.len;
12921292
if (!decodeIsOpeningTagNumber(buffer, offset + len, 1)) return;
12931293
len++;
1294-
var property_id_and_array_index = [];
1294+
var propertyIdAndArrayIndex = [];
12951295
while ((apduLen - len) > 1 && !decodeIsClosingTagNumber(buffer, offset + len, 1)) {
1296-
var p_ref = {};
1296+
var propertyRef = {};
12971297
if (!isContextSpecific(buffer[offset + len])) return;
12981298
var result = decodeTagNumberAndValue(buffer, offset + len);
12991299
len += result.len;
13001300
if (result.tagNumber !== 0) return;
13011301
if ((len + result.value) >= apduLen) return;
13021302
decodedValue = decodeEnumerated(buffer, offset + len, result.value);
1303-
p_ref.propertyIdentifier = decodedValue.value;
1303+
propertyRef.propertyIdentifier = decodedValue.value;
13041304
len += decodedValue.len;
1305-
p_ref.propertyArrayIndex = BACNET_ARRAY_ALL;
1305+
propertyRef.propertyArrayIndex = BACNET_ARRAY_ALL;
13061306
if (isContextSpecific(buffer[offset + len]) && !isClosingTag(buffer[offset + len])) {
13071307
var tmp = decodeTagNumberAndValue(buffer, offset + len);
13081308
if (tmp.tagNumber === 1) {
13091309
len += tmp.len;
13101310
if ((len + tmp.value) >= apduLen) return;
13111311
decodedValue = decodeUnsigned(buffer, offset + len, tmp.value);
1312-
p_ref.propertyArrayIndex = decodedValue.value;
1312+
propertyRef.propertyArrayIndex = decodedValue.value;
13131313
len += decodedValue.len;
13141314
}
13151315
}
1316-
property_id_and_array_index.push(p_ref);
1316+
propertyIdAndArrayIndex.push(propertyRef);
13171317
}
13181318
if (!decodeIsClosingTagNumber(buffer, offset + len, 1)) return;
13191319
len++;
1320-
value.propertyReferences = property_id_and_array_index;
1320+
value.propertyReferences = propertyIdAndArrayIndex;
13211321
return {
13221322
len: len,
13231323
value: value
@@ -1478,51 +1478,51 @@ var decodeCalendar = function(buffer, offset, apduLen) {
14781478
}
14791479
};
14801480

1481-
var bacappDecodeContextApplicationData = function(buffer, offset, max_offset, objectType, property_id) {
1481+
var bacappDecodeContextApplicationData = function(buffer, offset, maxOffset, objectType, propertyId) {
14821482
var len = 0;
14831483
var result;
14841484
if (isContextSpecific(buffer[offset])) {
1485-
if (property_id === baEnum.BacnetPropertyIds.PROP_LIST_OF_GROUP_MEMBERS) {
1486-
result = decodeReadAccessSpecification(buffer, offset, max_offset);
1485+
if (propertyId === baEnum.BacnetPropertyIds.PROP_LIST_OF_GROUP_MEMBERS) {
1486+
result = decodeReadAccessSpecification(buffer, offset, maxOffset);
14871487
if (!result) return;
14881488
return {
14891489
type: baEnum.BacnetApplicationTags.BACNET_APPLICATION_TAG_READ_ACCESS_SPECIFICATION,
14901490
value: result.value,
14911491
len: result.len
14921492
};
1493-
} else if (property_id === baEnum.BacnetPropertyIds.PROP_ACTIVE_COV_SUBSCRIPTIONS) {
1494-
result = decodeCovSubscription(buffer, offset, max_offset);
1493+
} else if (propertyId === baEnum.BacnetPropertyIds.PROP_ACTIVE_COV_SUBSCRIPTIONS) {
1494+
result = decodeCovSubscription(buffer, offset, maxOffset);
14951495
if (!result) return;
14961496
return {
14971497
type: baEnum.BacnetApplicationTags.BACNET_APPLICATION_TAG_COV_SUBSCRIPTION,
14981498
value: result.value,
14991499
len: result.len
15001500
};
1501-
} else if (objectType === baEnum.BacnetObjectTypes.OBJECT_GROUP && property_id === baEnum.acnetPropertyIds.PROP_PRESENT_VALUE) {
1502-
result = decodeReadAccessResult(buffer, offset, max_offset);
1501+
} else if (objectType === baEnum.BacnetObjectTypes.OBJECT_GROUP && propertyId === baEnum.acnetPropertyIds.PROP_PRESENT_VALUE) {
1502+
result = decodeReadAccessResult(buffer, offset, maxOffset);
15031503
if (!result) return;
15041504
return {
15051505
type: baEnum.BacnetApplicationTags.BACNET_APPLICATION_TAG_READ_ACCESS_RESULT,
15061506
value: result.value,
15071507
len: result.len
15081508
};
1509-
} else if (property_id === baEnum.BacnetPropertyIds.PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES || property_id === baEnum.BacnetPropertyIds.PROP_LOG_DEVICE_OBJECT_PROPERTY || property_id === baEnum.BacnetPropertyIds.PROP_OBJECT_PROPERTY_REFERENCE) {
1510-
result = decodeDeviceObjPropertyRef(buffer, offset, max_offset);
1509+
} else if (propertyId === baEnum.BacnetPropertyIds.PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES || propertyId === baEnum.BacnetPropertyIds.PROP_LOG_DEVICE_OBJECT_PROPERTY || propertyId === baEnum.BacnetPropertyIds.PROP_OBJECT_PROPERTY_REFERENCE) {
1510+
result = decodeDeviceObjPropertyRef(buffer, offset, maxOffset);
15111511
if (!result) return;
15121512
return {
15131513
type: baEnum.BacnetApplicationTags.BACNET_APPLICATION_TAG_OBJECT_PROPERTY_REFERENCE,
15141514
value: result.value,
15151515
len: result.len
15161516
};
1517-
} else if (property_id === baEnum.BacnetPropertyIds.PROP_DATE_LIST) {
1518-
result = decodeCalendar(buffer, offset, max_offset);
1517+
} else if (propertyId === baEnum.BacnetPropertyIds.PROP_DATE_LIST) {
1518+
result = decodeCalendar(buffer, offset, maxOffset);
15191519
if (!result) return;
15201520
return {
15211521
type: baEnum.BacnetApplicationTags.BACNET_APPLICATION_TAG_CONTEXT_SPECIFIC_DECODED,
15221522
value: result.value,
15231523
len: result.len
15241524
};
1525-
} else if (property_id === baEnum.BacnetPropertyIds.PROP_EVENT_TIME_STAMPS) {
1525+
} else if (propertyId === baEnum.BacnetPropertyIds.PROP_EVENT_TIME_STAMPS) {
15261526
var subEvtResult;
15271527
var evtResult = decodeTagNumberAndValue(buffer, offset + len);
15281528
len += 1;
@@ -1554,21 +1554,21 @@ var bacappDecodeContextApplicationData = function(buffer, offset, max_offset, ob
15541554
var list = [];
15551555
var tagResult = decodeTagNumberAndValue(buffer, offset + len);
15561556
var multipleValues = isOpeningTag(buffer[offset + len]);
1557-
while (((len + offset) <= max_offset) && !isClosingTag(buffer[offset + len])) {
1557+
while (((len + offset) <= maxOffset) && !isClosingTag(buffer[offset + len])) {
15581558
var subResult = decodeTagNumberAndValue(buffer, offset + len);
15591559
if (!subResult) return;
15601560
if (subResult.value === 0) {
15611561
len += subResult.len;
1562-
result = bacappDecodeApplicationData(buffer, offset + len, max_offset, baEnum.BacnetObjectTypes.MAX_BACNET_OBJECT_TYPE, baEnum.BacnetPropertyIds.MAX_BACNET_PROPERTY_ID);
1562+
result = bacappDecodeApplicationData(buffer, offset + len, maxOffset, baEnum.BacnetObjectTypes.MAX_BACNET_OBJECT_TYPE, baEnum.BacnetPropertyIds.MAX_BACNET_PROPERTY_ID);
15631563
if (!result) return;
15641564
list.push(result);
15651565
len += result.len;
15661566
} else {
1567-
var override_tag_number = bacappContextTagType(property_id, subResult.tagNumber);
1568-
if (override_tag_number !== baEnum.BacnetApplicationTags.MAX_BACNET_APPLICATION_TAG) {
1569-
subResult.tagNumber = override_tag_number;
1567+
var overrideTagNumber = bacappContextTagType(propertyId, subResult.tagNumber);
1568+
if (overrideTagNumber !== baEnum.BacnetApplicationTags.MAX_BACNET_APPLICATION_TAG) {
1569+
subResult.tagNumber = overrideTagNumber;
15701570
}
1571-
var bacappResult = bacappDecodeData(buffer, offset + len + subResult.len, max_offset, subResult.tagNumber, subResult.value);
1571+
var bacappResult = bacappDecodeData(buffer, offset + len + subResult.len, maxOffset, subResult.tagNumber, subResult.value);
15721572
if (!bacappResult) return;
15731573
if (bacappResult.len === subResult.value) {
15741574
list.push({
@@ -1592,7 +1592,7 @@ var bacappDecodeContextApplicationData = function(buffer, offset, max_offset, ob
15921592
};
15931593
}
15941594
}
1595-
if ((len + offset) > max_offset) return;
1595+
if ((len + offset) > maxOffset) return;
15961596
if (decodeIsClosingTagNumber(buffer, offset + len, tagResult.tagNumber)) {
15971597
len++;
15981598
}

lib/bacnet-services.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ module.exports.DecodeAtomicWriteFile = function(buffer, offset, apduLen) {
323323
blocks[0] = new byte[len_value_type];
324324
counts = new int[] { len_value_type };*/
325325

326-
len += baAsn1.decode_octet_string(buffer, offset + len, apduLen, blocks[0], 0, result.value);
326+
len += baAsn1.decodeOctetString(buffer, offset + len, apduLen, blocks[0], 0, result.value);
327327

328328
if (!baAsn1.decodeIsClosingTagNumber(buffer, offset + len, 0)) return;
329329
len++;
@@ -353,7 +353,7 @@ module.exports.DecodeAtomicWriteFile = function(buffer, offset, apduLen) {
353353
/*blocks[i] = new byte[len_value_type];
354354
counts[i] = len_value_type;*/
355355
if (result.tagNumber !== baEnum.BacnetApplicationTags.BACNET_APPLICATION_TAG_OCTET_STRING) return;
356-
len += baAsn1.decode_octet_string(buffer, offset + len, apduLen, blocks[i], 0, result.value);
356+
len += baAsn1.decodeOctetString(buffer, offset + len, apduLen, blocks[i], 0, result.value);
357357

358358
}
359359
if (!baAsn1.decodeIsClosingTagNumber(buffer, offset + len, 1)) return;
@@ -1361,7 +1361,7 @@ module.exports.DecodeReadRangeAcknowledge = function(buffer, offset, apduLen) {
13611361
len += decodedValue.len;
13621362
property.propertyArrayIndex = decodedValue.value;
13631363
} else {
1364-
decodedValue = baAsn1.decode_bitstring(buffer, offset + len, 2);
1364+
decodedValue = baAsn1.decodeBitstring(buffer, offset + len, 2);
13651365
len += decodedValue.len;
13661366
resultFlag = decodedValue.value;
13671367
}
@@ -1390,7 +1390,7 @@ module.exports.EncodeWriteObjectMultiple = function(buffer, valueList) {
13901390
module.exports.EncodeIhaveBroadcast = function(buffer, deviceId, objectId, objectName) {
13911391
baAsn1.encodeApplicationObjectId(buffer, deviceId.type, deviceId.instance);
13921392
baAsn1.encodeApplicationObjectId(buffer, objectId.type, objectId.instance);
1393-
baAsn1.encode_application_character_string(buffer, objectName);
1393+
baAsn1.encodeApplicationCharacterString(buffer, objectName);
13941394
};
13951395

13961396
module.exports.EncodeAlarmAcknowledge = function(buffer, ackProcessIdentifier, eventObjectIdentifier, eventStateAcked, ackSource, eventTimeStamp, ackTimeStamp) {
@@ -1440,7 +1440,7 @@ module.exports.EncodeAddListElement = function(buffer, objectId, propertyId, arr
14401440
module.exports.EncodeAlarmSummary = function(buffer, objectIdentifier, alarmState, acknowledgedTransitions) {
14411441
baAsn1.encodeApplicationObjectId(buffer, objectIdentifier.type, objectIdentifier.instance);
14421442
baAsn1.encodeApplicationEnumerated(buffer, alarmState);
1443-
baAsn1.encode_application_bitstring(buffer, acknowledgedTransitions);
1443+
baAsn1.encodeApplicationBitstring(buffer, acknowledgedTransitions);
14441444
};
14451445

14461446
module.exports.EncodeGetEventInformation = function(buffer, sendLast, lastReceivedObjectIdentifier) {
@@ -1458,7 +1458,7 @@ module.exports.EncodeGetEventInformationAcknowledge = function(buffer, events, m
14581458
baAsn1.encodeContextBitstring(buffer, 2, eventData.acknowledgedTransitions);
14591459
baAsn1.encodeOpeningTag(buffer, 3);
14601460
for (i = 0; i < 3; i++) {
1461-
baAsn1.bacapp_encode_timestamp(buffer, eventData.eventTimeStamps[i]);
1461+
baAsn1.bacappEncodeTimestamp(buffer, eventData.eventTimeStamps[i]);
14621462
}
14631463
baAsn1.encodeClosingTag(buffer, 3);
14641464
baAsn1.encodeContextEnumerated(buffer, 4, eventData.notifyType);

test/integration/read-property-multiple.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ describe('bacstack - readPropertyMultiple integration', function() {
4545
expect(object[5030]).to.deep.equal([{value: 0, type: 2}]);
4646
expect(object[5053]).to.deep.equal([{value: 0, type: 9}]);
4747
expect(object[5086]).to.deep.equal([
48-
{value: {value: [1], bits_used: 1}, type: 8},
49-
{value: {value: [0], bits_used: 1}, type: 8}
48+
{value: {value: [1], bitsUsed: 1}, type: 8},
49+
{value: {value: [0], bitsUsed: 1}, type: 8}
5050
]);
5151
expect(object[5102]).to.deep.equal([{value: 41, type: 9}]);
5252
client.close();
@@ -84,7 +84,7 @@ describe('bacstack - readPropertyMultiple integration', function() {
8484
{value: 'Missing or wrong configuration', type: 7},
8585
{value: 'Searching', type: 7},
8686
]);
87-
expect(object[111]).to.deep.equal([{value: {value: [0], bits_used: 4}, type: 8}]);
87+
expect(object[111]).to.deep.equal([{value: {value: [0], bitsUsed: 4}, type: 8}]);
8888
expect(object[168]).to.deep.equal([{value: '7-BA-RDS1-024-SBCv13.20', type: 7}]);
8989
expect(object[4930]).to.deep.equal([{value: 0, type: 9}]);
9090
expect(object[4941]).to.deep.equal([{value: 5, type: 9}]);

0 commit comments

Comments
 (0)