Skip to content

Commit 3cbf43f

Browse files
authored
Merge pull request fh1ch#94 from fh1ch/feat/enrollment-summary
Feat/enrollment summary
2 parents 8528678 + 070d407 commit 3cbf43f

11 files changed

Lines changed: 627 additions & 13 deletions

.jshintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"maxparams": 15,
1717
"maxdepth": 5,
1818
"maxstatements": 100,
19-
"maxcomplexity": 40,
19+
"maxcomplexity": 50,
2020

2121
"asi": false,
2222
"boss": false,

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ following services are already supported at this point in time:
3939
| Read Range | yes¹ | yes¹ |
4040
| Write Property | yes | yes¹ |
4141
| Write Property Multiple | yes | yes¹ |
42-
| Add List Element | yes¹ | |
43-
| Remove List Element | yes¹ | |
42+
| Add List Element | yes¹ | yes¹ |
43+
| Remove List Element | yes¹ | yes¹ |
4444
| Create Object | yes¹ | yes¹ |
4545
| Delete Object | yes¹ | yes¹ |
4646
| Subscribe COV | yes¹ | yes¹ |
@@ -49,14 +49,14 @@ following services are already supported at this point in time:
4949
| Atomic Write File | yes¹ | yes¹ |
5050
| Reinitialize Device | yes | yes¹ |
5151
| Device Communication Control | yes | yes¹ |
52-
| Get Alarm Summary | yes¹ | |
53-
| Get Event Information | yes¹ | |
54-
| Get Enrollment Summary | | |
55-
| Acknowledge Alarm | yes¹ | |
56-
| Confirmed Event Notification | | yes¹ |
57-
| Unconfirmed Event Notification | | yes¹ |
58-
| Unconfirmed Private Transfer | | |
59-
| Confirmed Private Transfer | | |
52+
| Get Alarm Summary | yes¹ | yes¹ |
53+
| Get Event Information | yes¹ | yes¹ |
54+
| Get Enrollment Summary | yes¹ | yes¹ |
55+
| Acknowledge Alarm | yes¹ | yes¹ |
56+
| Confirmed Event Notification | yes¹ | yes¹ |
57+
| Unconfirmed Event Notification | yes¹ | yes¹ |
58+
| Unconfirmed Private Transfer | yes¹ | yes¹ |
59+
| Confirmed Private Transfer | yes¹ | yes¹ |
6060

6161
¹ Support implemented as Beta (untested, undocumented, breaking interface)
6262

lib/asn1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,7 @@ const bacappDecodeContextApplicationData = (buffer, offset, maxOffset, objectTyp
15911591
}
15921592
};
15931593

1594-
const bacappEncodeTimestamp = (buffer, value) => {
1594+
const bacappEncodeTimestamp = module.exports.bacappEncodeTimestamp = (buffer, value) => {
15951595
switch (value.type) {
15961596
case baEnum.TimestampTags.TIME_STAMP_TIME:
15971597
encodeContextTime(buffer, 0, value.value);

lib/client.js

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,36 @@ class Client extends EventEmitter {
228228
result = baServices.decodeDeleteObject(buffer, offset, length);
229229
if (!result) return debug('Received invalid deleteObject message');
230230
this.emit('deleteObject', {address: address, invokeId: invokeId, request: result});
231+
} else if (service === baEnum.ConfirmedServices.SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM) {
232+
result = baServices.decodeAlarmAcknowledge(buffer, offset, length);
233+
if (!result) return debug('Received invalid alarmAcknowledge message');
234+
this.emit('alarmAcknowledge', {address: address, invokeId: invokeId, request: result});
235+
} else if (service === baEnum.ConfirmedServices.SERVICE_CONFIRMED_GET_ALARM_SUMMARY) {
236+
this.emit('getAlarmSummary', {address: address, invokeId: invokeId});
237+
} else if (service === baEnum.ConfirmedServices.SERVICE_CONFIRMED_GET_ENROLLMENT_SUMMARY) {
238+
result = baServices.decodeGetEnrollmentSummary(buffer, offset, length);
239+
if (!result) return debug('Received invalid getEntrollmentSummary message');
240+
this.emit('getEntrollmentSummary', {address: address, invokeId: invokeId, request: result});
241+
} else if (service === baEnum.ConfirmedServices.SERVICE_CONFIRMED_GET_EVENT_INFORMATION) {
242+
result = baServices.decodeGetEventInformation(buffer, offset, length);
243+
if (!result) return debug('Received invalid getEventInformation message');
244+
this.emit('getEventInformation', {address: address, invokeId: invokeId, request: result});
245+
} else if (service === baEnum.ConfirmedServices.SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION) {
246+
result = baServices.decodeLifeSafetyOperation(buffer, offset, length);
247+
if (!result) return debug('Received invalid lifeSafetyOperation message');
248+
this.emit('lifeSafetyOperation', {address: address, invokeId: invokeId, request: result});
249+
} else if (service === baEnum.ConfirmedServices.SERVICE_CONFIRMED_ADD_LIST_ELEMENT) {
250+
result = baServices.decodeAddListElement(buffer, offset, length);
251+
if (!result) return debug('Received invalid addListElement message');
252+
this.emit('addListElement', {address: address, invokeId: invokeId, request: result});
253+
} else if (service === baEnum.ConfirmedServices.SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT) {
254+
result = baServices.decodeAddListElement(buffer, offset, length);
255+
if (!result) return debug('Received invalid removeListElement message');
256+
this.emit('removeListElement', {address: address, invokeId: invokeId, request: result});
257+
} else if (service === baEnum.ConfirmedServices.SERVICE_CONFIRMED_PRIVATE_TRANSFER) {
258+
result = baServices.decodePrivateTransfer(buffer, offset, length);
259+
if (!result) return debug('Received invalid privateTransfer message');
260+
this.emit('privateTransfer', {address: address, invokeId: invokeId, request: result});
231261
} else {
232262
debug('Received unsupported confirmed service request');
233263
}
@@ -281,6 +311,14 @@ class Client extends EventEmitter {
281311
result = baServices.decodeEventNotifyData(buffer, offset, length);
282312
if (!result) return debug('Received invalid EventNotify message');
283313
this.emit('eventNotify', {address: address, eventData: result.eventData});
314+
} else if (service === baEnum.UnconfirmedServices.SERVICE_UNCONFIRMED_I_HAVE) {
315+
result = baServices.decodeIhaveBroadcast(buffer, offset, length);
316+
if (!result) return debug('Received invalid ihaveBroadcast message');
317+
this.emit('ihaveBroadcast', {address: address, eventData: result.eventData});
318+
} else if (service === baEnum.UnconfirmedServices.SERVICE_UNCONFIRMED_PRIVATE_TRANSFER) {
319+
result = baServices.decodePrivateTransfer(buffer, offset, length);
320+
if (!result) return debug('Received invalid privateTransfer message');
321+
this.emit('privateTransfer', {address: address, eventData: result.eventData});
284322
} else {
285323
debug('Received unsupported unconfirmed service request');
286324
}
@@ -962,6 +1000,83 @@ class Client extends EventEmitter {
9621000
});
9631001
}
9641002

1003+
confirmedPrivateTransfer(address, vendorId, serviceNumber, data, options, next) {
1004+
next = next || options;
1005+
const settings = {
1006+
maxSegments: options.maxSegments || baEnum.MaxSegments.MAX_SEG65,
1007+
maxAdpu: options.maxAdpu || baEnum.MaxAdpu.MAX_APDU1476,
1008+
invokeId: options.invokeId || this._getInvokeId()
1009+
};
1010+
const buffer = this._getBuffer();
1011+
baNpdu.encode(buffer, baEnum.NpduControls.PRIORITY_NORMAL_MESSAGE | baEnum.NpduControls.EXPECTING_REPLY, address);
1012+
baAdpu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.PDU_TYPE_CONFIRMED_SERVICE_REQUEST, baEnum.ConfirmedServices.SERVICE_CONFIRMED_PRIVATE_TRANSFER, settings.maxSegments, settings.maxAdpu, settings.invokeId, 0, 0);
1013+
baServices.encodePrivateTransfer(buffer, vendorId, serviceNumber, data);
1014+
baBvlc.encode(buffer.buffer, baEnum.BvlcFunctions.BVLC_ORIGINAL_UNICAST_NPDU, buffer.offset);
1015+
this._transport.send(buffer.buffer, buffer.offset, address);
1016+
this._addCallback(settings.invokeId, (err, data) => {
1017+
if (err) return next(err);
1018+
next();
1019+
});
1020+
}
1021+
1022+
unconfirmedPrivateTransfer(address, vendorId, serviceNumber, data) {
1023+
const buffer = this._getBuffer();
1024+
baNpdu.encode(buffer, baEnum.NpduControls.PRIORITY_NORMAL_MESSAGE, address);
1025+
baAdpu.encodeUnconfirmedServiceRequest(buffer, baEnum.PduTypes.PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST, baEnum.UnconfirmedServices.SERVICE_UNCONFIRMED_PRIVATE_TRANSFER);
1026+
baServices.encodePrivateTransfer(buffer, vendorId, serviceNumber, data);
1027+
baBvlc.encode(buffer.buffer, baEnum.BvlcFunctions.BVLC_ORIGINAL_UNICAST_NPDU, buffer.offset);
1028+
this._transport.send(buffer.buffer, buffer.offset, address);
1029+
}
1030+
1031+
getEnrollmentSummary(address, acknowledgmentFilter, options, next) {
1032+
next = next || options;
1033+
const settings = {
1034+
maxSegments: options.maxSegments || baEnum.MaxSegments.MAX_SEG65,
1035+
maxAdpu: options.maxAdpu || baEnum.MaxAdpu.MAX_APDU1476,
1036+
invokeId: options.invokeId || this._getInvokeId()
1037+
};
1038+
const buffer = this._getBuffer();
1039+
baNpdu.encode(buffer, baEnum.NpduControls.PRIORITY_NORMAL_MESSAGE | baEnum.NpduControls.EXPECTING_REPLY, address);
1040+
baAdpu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.PDU_TYPE_CONFIRMED_SERVICE_REQUEST, baEnum.ConfirmedServices.SERVICE_CONFIRMED_GET_ENROLLMENT_SUMMARY, settings.maxSegments, settings.maxAdpu, settings.invokeId, 0, 0);
1041+
baServices.encodeGetEnrollmentSummary(buffer, acknowledgmentFilter, options.enrollmentFilter, options.eventStateFilter, options.eventTypeFilter, options.priorityFilter, options.notificationClassFilter);
1042+
baBvlc.encode(buffer.buffer, baEnum.BvlcFunctions.BVLC_ORIGINAL_UNICAST_NPDU, buffer.offset);
1043+
this._transport.send(buffer.buffer, buffer.offset, address);
1044+
this._addCallback(settings.invokeId, (err, data) => {
1045+
if (err) return next(err);
1046+
const result = baServices.decodeGetEnrollmentSummaryAcknowledge(data.buffer, data.offset, data.length);
1047+
if (!result) return next(new Error('INVALID_DECODING'));
1048+
next(null, result);
1049+
});
1050+
}
1051+
1052+
unconfirmedEventNotification(address, eventNotification) {
1053+
const buffer = this._getBuffer();
1054+
baNpdu.encode(buffer, baEnum.NpduControls.PRIORITY_NORMAL_MESSAGE, address);
1055+
baAdpu.encodeUnconfirmedServiceRequest(buffer, baEnum.PduTypes.PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST, baEnum.UnconfirmedServices.SERVICE_UNCONFIRMED_EVENT_NOTIFICATION);
1056+
baServices.encodeEventNotifyData(buffer, eventNotification);
1057+
baBvlc.encode(buffer.buffer, baEnum.BvlcFunctions.BVLC_ORIGINAL_UNICAST_NPDU, buffer.offset);
1058+
this._transport.send(buffer.buffer, buffer.offset, address);
1059+
}
1060+
1061+
confirmedEventNotification(address, eventNotification, options, next) {
1062+
next = next || options;
1063+
const settings = {
1064+
maxSegments: options.maxSegments || baEnum.MaxSegments.MAX_SEG65,
1065+
maxAdpu: options.maxAdpu || baEnum.MaxAdpu.MAX_APDU1476,
1066+
invokeId: options.invokeId || this._getInvokeId()
1067+
};
1068+
const buffer = this._getBuffer();
1069+
baNpdu.encode(buffer, baEnum.NpduControls.PRIORITY_NORMAL_MESSAGE | baEnum.NpduControls.EXPECTING_REPLY, address);
1070+
baAdpu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.PDU_TYPE_CONFIRMED_SERVICE_REQUEST, baEnum.ConfirmedServices.SERVICE_CONFIRMED_EVENT_NOTIFICATION, settings.maxSegments, settings.maxAdpu, settings.invokeId, 0, 0);
1071+
baServices.encodeEventNotifyData(buffer, eventNotification);
1072+
baBvlc.encode(buffer.buffer, baEnum.BvlcFunctions.BVLC_ORIGINAL_UNICAST_NPDU, buffer.offset);
1073+
this._transport.send(buffer.buffer, buffer.offset, address);
1074+
this._addCallback(settings.invokeId, (err, data) => {
1075+
if (err) return next(err);
1076+
next();
1077+
});
1078+
}
1079+
9651080
// Public Device Functions
9661081
readPropertyResponse(receiver, invokeId, objectId, property, value) {
9671082
const buffer = this._getBuffer();

0 commit comments

Comments
 (0)