Skip to content

Commit

Permalink
feat(bacnet-client): implement alarming and eventing
Browse files Browse the repository at this point in the history
  • Loading branch information
fh1ch committed Dec 19, 2017
1 parent c8b3f05 commit fbf120c
Show file tree
Hide file tree
Showing 8 changed files with 614 additions and 38 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ following services are already supported at this point in time:
| Atomic Write File | yes¹ | yes¹ |
| Reinitialize Device | yes | yes¹ |
| Device Communication Control | yes | yes¹ |
| Get Alarm Summary | | |
| Get Event Information | | |
| Get Alarm Summary | yes¹ | |
| Get Event Information | yes¹ | |
| Get Enrollment Summary | | |
| Acknowledge Alarm | | |
| Acknowledge Alarm | yes¹ | |
| Confirmed Event Notification | | yes¹ |
| Unconfirmed Event Notification | | yes¹ |
| Unconfirmed Private Transfer | | |
Expand Down
6 changes: 3 additions & 3 deletions lib/bacnet-asn1.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ var encodeBitstring = function(buffer, bitString) {
}
};

var encodeApplicationBitstring = function(buffer, bitString) {
var encodeApplicationBitstring = module.exports.encodeApplicationBitstring = function(buffer, bitString) {
var bitStringEncodedLength = 1;
bitStringEncodedLength += bitstringBytesUsed(bitString);
encodeTag(buffer, baEnum.BacnetApplicationTags.BACNET_APPLICATION_TAG_BIT_STRING, false, bitStringEncodedLength);
Expand Down Expand Up @@ -913,7 +913,7 @@ var bitstringSetBitsUsed = function(bitString, bytesUsed, unusedBits) {
bitString.bitsUsed -= unusedBits;
};

var decodeBitstring = function(buffer, offset, lenValue) {
var decodeBitstring = module.exports.decodeBitstring = function(buffer, offset, lenValue) {
var len = 0;
var bitString = {};
bitString.value = [];
Expand Down Expand Up @@ -1698,7 +1698,7 @@ var encodeBacnetCharacterString = function(buffer, value, encoding) {
buffer.offset += bufEncoded.copy(buffer.buffer, buffer.offset);
};

var encodeApplicationCharacterString = function(buffer, value, encoding) {
var encodeApplicationCharacterString = module.exports.encodeApplicationCharacterString = function(buffer, value, encoding) {
var tmp = getBuffer();
encodeBacnetCharacterString(tmp, value, encoding);
encodeTag(buffer, baEnum.BacnetApplicationTags.BACNET_APPLICATION_TAG_CHARACTER_STRING, false, tmp.offset);
Expand Down
49 changes: 49 additions & 0 deletions lib/bacnet-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ module.exports = function(options) {
*
* client.timeSync('192.168.1.43', new Date(), true);
*/
// TODO: Split up in UTC and non-utc
self.timeSync = function(address, dateTime, isUtc) {
var buffer = getBuffer();
baNpdu.encode(buffer, baEnum.BacnetNpduControls.PRIORITY_NORMAL_MESSAGE, address);
Expand Down Expand Up @@ -779,6 +780,54 @@ module.exports = function(options) {
});
};

self.getAlarmSummary = function(address, next) {
var maxSegments = baEnum.BacnetMaxSegments.MAX_SEG65;
var buffer = getBuffer();
var invokeId = getInvokeId();
baNpdu.encode(buffer, baEnum.BacnetNpduControls.PRIORITY_NORMAL_MESSAGE | baEnum.BacnetNpduControls.EXPECTING_REPLY, address);
baAdpu.encodeConfirmedServiceRequest(buffer, baEnum.BacnetPduTypes.PDU_TYPE_CONFIRMED_SERVICE_REQUEST, baEnum.BacnetConfirmedServices.SERVICE_CONFIRMED_GET_ALARM_SUMMARY, maxSegments, baEnum.BacnetMaxAdpu.MAX_APDU1476, invokeId, 0, 0);
baBvlc.encode(buffer.buffer, baEnum.BacnetBvlcFunctions.BVLC_ORIGINAL_UNICAST_NPDU, buffer.offset);
transport.send(buffer.buffer, buffer.offset, address);
addCallback(invokeId, function(err, data) {
if (err) return next(err);
var result = baServices.decodeAlarmSummary(data.buffer, data.offset, data.length);
if (!result) return next(new Error('INVALID_DECODING'));
next(null, result);
});
};

self.getEventInformation = function(address, objectId, next) {
var maxSegments = baEnum.BacnetMaxSegments.MAX_SEG65;
var buffer = getBuffer();
var invokeId = getInvokeId();
baNpdu.encode(buffer, baEnum.BacnetNpduControls.PRIORITY_NORMAL_MESSAGE | baEnum.BacnetNpduControls.EXPECTING_REPLY, address);
baAdpu.encodeConfirmedServiceRequest(buffer, baEnum.BacnetPduTypes.PDU_TYPE_CONFIRMED_SERVICE_REQUEST, baEnum.BacnetConfirmedServices.SERVICE_CONFIRMED_GET_EVENT_INFORMATION, maxSegments, baEnum.BacnetMaxAdpu.MAX_APDU1476, invokeId, 0, 0);
baAsn1.encodeContextObjectId(buffer, 0, objectId.type, objectId.instance);
baBvlc.encode(buffer.buffer, baEnum.BacnetBvlcFunctions.BVLC_ORIGINAL_UNICAST_NPDU, buffer.offset);
transport.send(buffer.buffer, buffer.offset, address);
addCallback(invokeId, function(err, data) {
if (err) return next(err);
var result = baServices.decodeEventInformation(data.buffer, data.offset, data.length);
if (!result) return next(new Error('INVALID_DECODING'));
next(null, result);
});
};

self.acknowledgeAlarm = function(address, objectId, eventState, ackText, evTimeStamp, ackTimeStamp, next) {
var maxSegments = baEnum.BacnetMaxSegments.MAX_SEG65;
var buffer = getBuffer();
var invokeId = getInvokeId();
baNpdu.encode(buffer, baEnum.BacnetNpduControls.PRIORITY_NORMAL_MESSAGE | baEnum.BacnetNpduControls.EXPECTING_REPLY, address);
baAdpu.encodeConfirmedServiceRequest(buffer, baEnum.BacnetPduTypes.PDU_TYPE_CONFIRMED_SERVICE_REQUEST, baEnum.BacnetConfirmedServices.SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, maxSegments, baEnum.BacnetMaxAdpu.MAX_APDU1476, invokeId, 0, 0);
baServices.encodeAlarmAcknowledge(buffer, 57, objectId, eventState, ackText, evTimeStamp, ackTimeStamp);
baBvlc.encode(buffer.buffer, baEnum.BacnetBvlcFunctions.BVLC_ORIGINAL_UNICAST_NPDU, buffer.offset);
transport.send(buffer.buffer, buffer.offset, address);
addCallback(invokeId, function(err, data) {
if (err) return next(err);
next();
});
};

// Public Device Functions
self.readPropertyResponse = function(receiver, invokeId, objectId, property, value) {
var buffer = getBuffer();
Expand Down
Loading

0 comments on commit fbf120c

Please sign in to comment.