forked from fh1ch/node-bacstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbvlc.js
More file actions
45 lines (41 loc) · 1.33 KB
/
Copy pathbvlc.js
File metadata and controls
45 lines (41 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict';
const baEnum = require('./enum');
const BVLL_TYPE_BACNET_IP = 0x81;
const BVLC_HEADER_LENGTH = 4;
module.exports.encode = (buffer, func, msgLength) => {
buffer[0] = BVLL_TYPE_BACNET_IP;
buffer[1] = func;
buffer[2] = (msgLength & 0xFF00) >> 8;
buffer[3] = (msgLength & 0x00FF) >> 0;
return BVLC_HEADER_LENGTH;
};
module.exports.decode = (buffer, offset) => {
let len;
const func = buffer[1];
const msgLength = (buffer[2] << 8) | (buffer[3] << 0);
if (buffer[0] !== BVLL_TYPE_BACNET_IP || buffer.length !== msgLength) return;
switch (func) {
case baEnum.BvlcFunctions.BVLC_RESULT:
case baEnum.BvlcFunctions.BVLC_ORIGINAL_UNICAST_NPDU:
case baEnum.BvlcFunctions.BVLC_ORIGINAL_BROADCAST_NPDU:
case baEnum.BvlcFunctions.BVLC_DISTRIBUTE_BROADCAST_TO_NETWORK:
len = 4;
break;
case baEnum.BvlcFunctions.BVLC_FORWARDED_NPDU:
len = 10;
break;
case baEnum.BvlcFunctions.BVLC_REGISTER_FOREIGN_DEVICE:
case baEnum.BvlcFunctions.BVLC_READ_FOREIGN_DEVICE_TABLE:
case baEnum.BvlcFunctions.BVLC_DELETE_FOREIGN_DEVICE_TABLE_ENTRY:
case baEnum.BvlcFunctions.BVLC_READ_BROADCAST_DIST_TABLE:
case baEnum.BvlcFunctions.BVLC_WRITE_BROADCAST_DISTRIBUTION_TABLE:
return;
default:
return;
}
return {
len: len,
func: func,
msgLength: msgLength
};
};