Skip to content

Commit 320366a

Browse files
committed
test(read-property-multiple): add integration tests using real recorded data
1 parent a82fb58 commit 320366a

2 files changed

Lines changed: 113 additions & 0 deletions

File tree

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

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,93 @@ describe('bacstack - readPropertyMultiple integration', function() {
1414
next();
1515
});
1616
});
17+
18+
it('should successfully decode a structured view', function(next) {
19+
var transport = utils.transportStub();
20+
var client = utils.bacnetClient({transport: transport});
21+
var data = Buffer.from('810a0109010030000e0c0740001f1e291c4e752900436f6c6c656374696f6e206f66206c69676874696e672070726573656e6365206465746563746f724f294b4ec40740001f4f294d4e7531005ac3a4686c657277656727466c6f6f72203427525365675456274c6774275073634f70274c6774507363446574436f6c4f294f4e911d4f29a84e751800372d42412d524453312d3034312d5342437631332e32304f29cf4e71004f29d04e91084f29d24e750c004c67745073634465745273750a00507363446574282a294f29d34e1c014000001c00c000004f2a13424e91004f2a134d4e91064f2a13a64e21004f2a13bd4e91004f2a13de4e8207808207004f2a13ee4e91294f1f', 'hex');
22+
var requestArray = [
23+
{objectIdentifier: {type: 8, instance: 4194303}, propertyReferences: [{propertyIdentifier: 8}]}
24+
];
25+
client.readPropertyMultiple('127.0.0.1', requestArray, function(err, response) {
26+
var object = utils.propertyFormater(response.values[0].values);
27+
expect(response.values[0].objectIdentifier).to.deep.equal({type: 29, instance: 31});
28+
expect(object[28]).to.deep.equal([{value: 'Collection of lighting presence detector', type: 7}]);
29+
expect(object[75]).to.deep.equal([{value: {type: 29, instance: 31}, type: 12}]);
30+
expect(object[77]).to.deep.equal([{value: 'Zählerweg\'Floor 4\'RSegTV\'Lgt\'PscOp\'LgtPscDetCol', type: 7}]);
31+
expect(object[79]).to.deep.equal([{value: 29, type: 9}]);
32+
expect(object[168]).to.deep.equal([{value: '7-BA-RDS1-041-SBCv13.20', type: 7}]);
33+
expect(object[207]).to.deep.equal([{value: '', type: 7}]);
34+
expect(object[208]).to.deep.equal([{value: 8, type: 9}]);
35+
expect(object[210]).to.deep.equal([
36+
{value: 'LgtPscDetRs', type: 7},
37+
{value: 'PscDet(*)', type: 7}
38+
]);
39+
expect(object[211]).to.deep.equal([
40+
{value: {value: {type: 5, instance: 0}, type: 12}, type: undefined},
41+
{value: {value: {type: 3, instance: 0}, type: 12}, type: undefined}
42+
]);
43+
expect(object[4930]).to.deep.equal([{value: 0, type: 9}]);
44+
expect(object[4941]).to.deep.equal([{value: 6, type: 9}]);
45+
expect(object[5030]).to.deep.equal([{value: 0, type: 2}]);
46+
expect(object[5053]).to.deep.equal([{value: 0, type: 9}]);
47+
/*expect(object[5086]).to.deep.equal([{value: [
48+
{value: '(Bit String)'},
49+
{value: '(Bit String)'}
50+
], type: ''}]);*/
51+
expect(object[5102]).to.deep.equal([{value: 41, type: 9}]);
52+
next();
53+
});
54+
transport.handler(data, '127.0.0.1');
55+
});
56+
57+
it('should successfully decode a value object', function(next) {
58+
var transport = utils.transportStub();
59+
var client = utils.bacnetClient({transport: transport});
60+
var data = Buffer.from('810a01eb010030000e0c04c0000a1e291c4e75070053656e736f724f29244e91004f294a4e21084f294b4ec404c0000a4f294d4e7525005ac3a4686c657277656727466c6f6f722034275253656754562753656e4465762753656e4f294f4e91134f29514e104f29554e21014f29674e91004f296e4e750c004f7065726174696f6e616c750f004465766963652073746f70706564751400446576696365206e6f742061737369676e6564750f00446576696365206d697373696e67751300436f6e6669677572696e6720646576696365750700556e75736564751f004d697373696e67206f722077726f6e6720636f6e66696775726174696f6e750a00536561726368696e674f296f4e8204004f29a84e751800372d42412d524453312d3032342d5342437631332e32304f2a13424e91004f2a134d4e91054f2a13884e91004f2a13894e91004f2a13af4e750800302e322e3234394f2a13df4e750e00355747313235382d32444231324f2a13e44e750b00504c2d313a444c3d313b4f2a13e64e21034f2a13ec4e750d003030303130303433656464634f2a13ed4e752d00504c3a4444543d303538362e303030312e30302e30312e30303b46573d302e312e31333b4d4f44453d504c3b4f2a13ee4e91184f2a13ef4e71004f2a13f04e91004f2a13f34e21014f1f', 'hex');
61+
var requestArray = [
62+
{objectIdentifier: {type: 8, instance: 4194303}, propertyReferences: [{propertyIdentifier: 8}]}
63+
];
64+
client.readPropertyMultiple('127.0.0.1', requestArray, function(err, response) {
65+
expect(response.values[0].objectIdentifier).to.deep.equal({type: 19, instance: 10});
66+
var object = utils.propertyFormater(response.values[0].values);
67+
expect(object[28]).to.deep.equal([{value: 'Sensor', type: 7}]);
68+
expect(object[36]).to.deep.equal([{value: 0, type: 9}]);
69+
expect(object[74]).to.deep.equal([{value: 8, type: 2}]);
70+
expect(object[75]).to.deep.equal([{value: {type: 19, instance: 10}, type: 12}]);
71+
expect(object[77]).to.deep.equal([{value: 'Zählerweg\'Floor 4\'RSegTV\'SenDev\'Sen', type: 7}]);
72+
expect(object[79]).to.deep.equal([{value: 19, type: 9}]);
73+
expect(object[81]).to.deep.equal([{value: false, type: 1}]);
74+
expect(object[85]).to.deep.equal([{value: 1, type: 2}]);
75+
expect(object[103]).to.deep.equal([{value: 0, type: 9}]);
76+
expect(object[110]).to.deep.equal([
77+
{value: 'Operational', type: 7},
78+
{value: 'Device stopped', type: 7},
79+
{value: 'Device not assigned', type: 7},
80+
{value: 'Device missing', type: 7},
81+
{value: 'Configuring device', type: 7},
82+
{value: 'Unused', type: 7},
83+
{value: 'Missing or wrong configuration', type: 7},
84+
{value: 'Searching', type: 7},
85+
]);
86+
//expect(object[111]).to.deep.equal([{value: '(Bit String)', type: ''}]);
87+
expect(object[168]).to.deep.equal([{value: '7-BA-RDS1-024-SBCv13.20', type: 7}]);
88+
expect(object[4930]).to.deep.equal([{value: 0, type: 9}]);
89+
expect(object[4941]).to.deep.equal([{value: 5, type: 9}]);
90+
expect(object[5000]).to.deep.equal([{value: 0, type: 9}]);
91+
expect(object[5001]).to.deep.equal([{value: 0, type: 9}]);
92+
expect(object[5039]).to.deep.equal([{value: '0.2.249', type: 7}]);
93+
expect(object[5087]).to.deep.equal([{value: '5WG1258-2DB12', type: 7}]);
94+
expect(object[5092]).to.deep.equal([{value: 'PL-1:DL=1;', type: 7}]);
95+
expect(object[5094]).to.deep.equal([{value: 3, type: 2}]);
96+
expect(object[5100]).to.deep.equal([{value: '00010043eddc', type: 7}]);
97+
expect(object[5101]).to.deep.equal([{value: 'PL:DDT=0586.0001.00.01.00;FW=0.1.13;MODE=PL;', type: 7}]);
98+
expect(object[5102]).to.deep.equal([{value: 24, type: 9}]);
99+
expect(object[5103]).to.deep.equal([{value: '', type: 7}]);
100+
expect(object[5104]).to.deep.equal([{value: 0, type: 9}]);
101+
expect(object[5107]).to.deep.equal([{value: 1, type: 2}]);
102+
next();
103+
});
104+
transport.handler(data, '127.0.0.1');
105+
});
17106
});

test/integration/utils.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,27 @@ var bacnet = require('../../');
22

33
module.exports.bacnetClient = bacnet;
44
module.exports.globalBacnetClient = bacnet();
5+
6+
module.exports.transportStub = function() {
7+
var self = this;
8+
self.handler = function() {};
9+
self.setHandler = function(handler) {
10+
self.handler = handler;
11+
};
12+
self.getBroadcastAddress = function() {
13+
return '255.255.255.255';
14+
};
15+
self.getMaxPayload = function() {
16+
return 1472;
17+
};
18+
self.send = function() {};
19+
return self;
20+
};
21+
22+
module.exports.propertyFormater = function(object) {
23+
var converted = {};
24+
object.forEach((property) => {
25+
converted[property.propertyIdentifier] = property.value;
26+
});
27+
return converted;
28+
};

0 commit comments

Comments
 (0)