smart-bus 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/README.md +1 -1
- package/lib/bus.js +5 -5
- package/lib/command.js +1 -1
- package/lib/commands.js +198 -70
- package/package.json +7 -8
- package/test/bus.js +24 -24
- package/test/command.js +5 -5
- package/test/device.js +1 -1
- package/test/fixtures/commands.js +199 -106
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smart-bus",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Node.js implementation of HDL SmartBus protocol",
|
|
6
6
|
"repository": "caligo-mentis/smart-bus",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "mocha",
|
|
12
12
|
"lint": "eslint lib test",
|
|
13
|
-
"coverage": "
|
|
13
|
+
"coverage": "nyc mocha"
|
|
14
14
|
},
|
|
15
15
|
|
|
16
16
|
"dependencies": {
|
|
@@ -19,12 +19,11 @@
|
|
|
19
19
|
},
|
|
20
20
|
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"mocha": "
|
|
23
|
-
"eslint": "
|
|
24
|
-
"should": "
|
|
25
|
-
"
|
|
26
|
-
"simple-mock": "~0.7"
|
|
22
|
+
"mocha": "^10.0.0",
|
|
23
|
+
"eslint": "^8.57.0",
|
|
24
|
+
"should": "^13.2.3",
|
|
25
|
+
"simple-mock": "^0.8.0"
|
|
27
26
|
},
|
|
28
27
|
|
|
29
|
-
"engines": { "node": ">=0.
|
|
28
|
+
"engines": { "node": ">=12.0.0" }
|
|
30
29
|
}
|
package/test/bus.js
CHANGED
|
@@ -27,7 +27,7 @@ describe('Bus', function() {
|
|
|
27
27
|
should(bus).have.properties({
|
|
28
28
|
port: 6000,
|
|
29
29
|
gateway: '192.0.2.100',
|
|
30
|
-
address:
|
|
30
|
+
address: Buffer.from([0, 0, 0, 0])
|
|
31
31
|
});
|
|
32
32
|
});
|
|
33
33
|
|
|
@@ -266,7 +266,7 @@ describe('Bus', function() {
|
|
|
266
266
|
}, function(err) {
|
|
267
267
|
should(send.callCount).be.exactly(1);
|
|
268
268
|
|
|
269
|
-
should(send.lastCall.args[0]).eql(
|
|
269
|
+
should(send.lastCall.args[0]).eql(Buffer.from('0000000048444C4D49524' +
|
|
270
270
|
'1434C45AAAA0F0132FFFE00310128016400000803', 'hex'));
|
|
271
271
|
should(send.lastCall.args[1]).equal(0);
|
|
272
272
|
should(send.lastCall.args[2]).eql(31);
|
|
@@ -288,7 +288,7 @@ describe('Bus', function() {
|
|
|
288
288
|
}, function(err) {
|
|
289
289
|
should(send.callCount).be.exactly(1);
|
|
290
290
|
|
|
291
|
-
should(send.lastCall.args[0]).eql(
|
|
291
|
+
should(send.lastCall.args[0]).eql(Buffer.from('0000000048444C4D49524' +
|
|
292
292
|
'1434C45AAAA0F0132FFFE0031011E056400000399', 'hex'));
|
|
293
293
|
should(send.lastCall.args[1]).equal(0);
|
|
294
294
|
should(send.lastCall.args[2]).eql(31);
|
|
@@ -304,11 +304,11 @@ describe('Bus', function() {
|
|
|
304
304
|
sender: sender,
|
|
305
305
|
target: '1.23',
|
|
306
306
|
command: 0x0031,
|
|
307
|
-
data:
|
|
307
|
+
data: Buffer.from('01640000', 'hex')
|
|
308
308
|
}, function(err) {
|
|
309
309
|
should(send.callCount).be.exactly(1);
|
|
310
310
|
|
|
311
|
-
should(send.lastCall.args[0]).eql(
|
|
311
|
+
should(send.lastCall.args[0]).eql(Buffer.from('0000000048444C4D49524' +
|
|
312
312
|
'1434C45AAAA0F0132FFFE00310117016400006114', 'hex'));
|
|
313
313
|
should(send.lastCall.args[1]).equal(0);
|
|
314
314
|
should(send.lastCall.args[2]).eql(31);
|
|
@@ -324,11 +324,11 @@ describe('Bus', function() {
|
|
|
324
324
|
sender: sender,
|
|
325
325
|
target: '1.23',
|
|
326
326
|
command: 0x0031,
|
|
327
|
-
payload:
|
|
327
|
+
payload: Buffer.from('01640000', 'hex')
|
|
328
328
|
}, function(err) {
|
|
329
329
|
should(send.callCount).be.exactly(1);
|
|
330
330
|
|
|
331
|
-
should(send.lastCall.args[0]).eql(
|
|
331
|
+
should(send.lastCall.args[0]).eql(Buffer.from('0000000048444C4D49524' +
|
|
332
332
|
'1434C45AAAA0F0132FFFE00310117016400006114', 'hex'));
|
|
333
333
|
should(send.lastCall.args[1]).equal(0);
|
|
334
334
|
should(send.lastCall.args[2]).eql(31);
|
|
@@ -361,7 +361,7 @@ describe('Bus', function() {
|
|
|
361
361
|
}, function(err) {
|
|
362
362
|
should(send.callCount).be.exactly(1);
|
|
363
363
|
|
|
364
|
-
should(send.lastCall.arg).eql(
|
|
364
|
+
should(send.lastCall.arg).eql(Buffer.from('0000000048444C4D49524' +
|
|
365
365
|
'1434C45AAAA0B0132FFFE000401175360', 'hex'));
|
|
366
366
|
|
|
367
367
|
done(err);
|
|
@@ -371,11 +371,11 @@ describe('Bus', function() {
|
|
|
371
371
|
|
|
372
372
|
describe('parse', function() {
|
|
373
373
|
it('should not parse invalid message', function() {
|
|
374
|
-
should(bus.parse(
|
|
374
|
+
should(bus.parse(Buffer.from('TEST'))).equal(undefined);
|
|
375
375
|
});
|
|
376
376
|
|
|
377
377
|
it('should ignore message from another gateway by default', function() {
|
|
378
|
-
should(bus.parse(
|
|
378
|
+
should(bus.parse(Buffer.from('C0A801FA48444C4D495241434C45AAAA0E010202' +
|
|
379
379
|
'690032FFFF06F864B5A9', 'hex'))).equal(undefined);
|
|
380
380
|
});
|
|
381
381
|
|
|
@@ -385,7 +385,7 @@ describe('Bus', function() {
|
|
|
385
385
|
bus.on('listening', function() {
|
|
386
386
|
bus.setBroadcast(true);
|
|
387
387
|
|
|
388
|
-
var message =
|
|
388
|
+
var message = Buffer.from('C0A801FA48444C4D495241434C45AAAA0E0' +
|
|
389
389
|
'10202690032FFFF06F864B5A9', 'hex');
|
|
390
390
|
|
|
391
391
|
should(bus.parse(message)).have.properties({
|
|
@@ -406,7 +406,7 @@ describe('Bus', function() {
|
|
|
406
406
|
bus.on('listening', function() {
|
|
407
407
|
bus.setBroadcast(false);
|
|
408
408
|
|
|
409
|
-
should(bus.parse(
|
|
409
|
+
should(bus.parse(Buffer.from('C0A801FA48444C4D495241434C45AAAA0E0' +
|
|
410
410
|
'10202690032FFFF06F864B5A9', 'hex'))).equal(undefined);
|
|
411
411
|
|
|
412
412
|
bus.on('close', done);
|
|
@@ -420,7 +420,7 @@ describe('Bus', function() {
|
|
|
420
420
|
|
|
421
421
|
should(device.type).equal(undefined);
|
|
422
422
|
|
|
423
|
-
bus.parse(
|
|
423
|
+
bus.parse(Buffer.from('C000026448444C4D495241434C45AAAA0E010202' +
|
|
424
424
|
'690032FFFF06F864B5A9', 'hex'));
|
|
425
425
|
|
|
426
426
|
should(device.type).eql(0x0269);
|
|
@@ -434,14 +434,14 @@ describe('Bus', function() {
|
|
|
434
434
|
|
|
435
435
|
should(device.type).equal(0xFFFE);
|
|
436
436
|
|
|
437
|
-
bus.parse(
|
|
437
|
+
bus.parse(Buffer.from('C000026448444C4D495241434C45AAAA0E010202' +
|
|
438
438
|
'690032FFFF06F864B5A9', 'hex'));
|
|
439
439
|
|
|
440
440
|
should(device.type).eql(0x0269);
|
|
441
441
|
});
|
|
442
442
|
|
|
443
443
|
it('should return command object', function() {
|
|
444
|
-
var command = bus.parse(
|
|
444
|
+
var command = bus.parse(Buffer.from('C000026448444C4D495241434C45AAAA0E' +
|
|
445
445
|
'010202690032FFFF06F864B5A9', 'hex'));
|
|
446
446
|
|
|
447
447
|
should(command).be.an.instanceOf(Command);
|
|
@@ -454,7 +454,7 @@ describe('Bus', function() {
|
|
|
454
454
|
});
|
|
455
455
|
|
|
456
456
|
it('should return command object without data', function() {
|
|
457
|
-
var command = bus.parse(
|
|
457
|
+
var command = bus.parse(Buffer.from('C000026448444C4D49524' +
|
|
458
458
|
'1434C45AAAA0B0132FFFE000401175360', 'hex'));
|
|
459
459
|
|
|
460
460
|
should(command).be.an.instanceOf(Command);
|
|
@@ -486,7 +486,7 @@ describe('Bus', function() {
|
|
|
486
486
|
sender: bus.device('1.5'),
|
|
487
487
|
target: bus.device('1.4'),
|
|
488
488
|
data: { channel: 4, level: 100, time: 3 },
|
|
489
|
-
payload:
|
|
489
|
+
payload: Buffer.from('0464000300', 'hex')
|
|
490
490
|
});
|
|
491
491
|
|
|
492
492
|
should(handler.calls[1].arg).have.properties({
|
|
@@ -494,7 +494,7 @@ describe('Bus', function() {
|
|
|
494
494
|
sender: bus.device('1.2'),
|
|
495
495
|
target: bus.device('255.255'),
|
|
496
496
|
data: { channel: 6, success: true, level: 100 },
|
|
497
|
-
payload:
|
|
497
|
+
payload: Buffer.from('06F864', 'hex')
|
|
498
498
|
});
|
|
499
499
|
});
|
|
500
500
|
|
|
@@ -509,7 +509,7 @@ describe('Bus', function() {
|
|
|
509
509
|
sender: bus.device('1.2'),
|
|
510
510
|
target: bus.device('255.255'),
|
|
511
511
|
data: { channel: 6, success: true, level: 100 },
|
|
512
|
-
payload:
|
|
512
|
+
payload: Buffer.from('06F864', 'hex')
|
|
513
513
|
});
|
|
514
514
|
});
|
|
515
515
|
|
|
@@ -524,7 +524,7 @@ describe('Bus', function() {
|
|
|
524
524
|
sender: bus.device('1.5'),
|
|
525
525
|
target: bus.device('1.4'),
|
|
526
526
|
data: { channel: 4, level: 100, time: 3 },
|
|
527
|
-
payload:
|
|
527
|
+
payload: Buffer.from('0464000300', 'hex')
|
|
528
528
|
});
|
|
529
529
|
});
|
|
530
530
|
|
|
@@ -542,20 +542,20 @@ describe('Bus', function() {
|
|
|
542
542
|
sender: device,
|
|
543
543
|
target: bus.device('255.255'),
|
|
544
544
|
data: { level: 100, channel: 6, success: true },
|
|
545
|
-
payload:
|
|
545
|
+
payload: Buffer.from('06F864', 'hex')
|
|
546
546
|
});
|
|
547
547
|
});
|
|
548
548
|
|
|
549
549
|
it('should handle invalid message', function() {
|
|
550
550
|
should(function() {
|
|
551
|
-
bus.socket.emit('message',
|
|
551
|
+
bus.socket.emit('message', Buffer.from('invalid'));
|
|
552
552
|
}).not.throw();
|
|
553
553
|
});
|
|
554
554
|
|
|
555
555
|
function emitEvents() {
|
|
556
|
-
bus.socket.emit('message',
|
|
556
|
+
bus.socket.emit('message', Buffer.from('C000026448444C4D495241434C45AAA' +
|
|
557
557
|
'A10010504550031010404640003000837', 'hex'));
|
|
558
|
-
bus.socket.emit('message',
|
|
558
|
+
bus.socket.emit('message', Buffer.from('C000026448444C4D495241434C45AAA' +
|
|
559
559
|
'A0E010202690032FFFF06F864B5A9', 'hex'));
|
|
560
560
|
}
|
|
561
561
|
});
|
package/test/command.js
CHANGED
|
@@ -11,7 +11,7 @@ describe('Command', function() {
|
|
|
11
11
|
data = { level: 100 };
|
|
12
12
|
sender = { subnet: 1, id: 3 };
|
|
13
13
|
target = { subnet: 1, id: 10 };
|
|
14
|
-
payload =
|
|
14
|
+
payload = Buffer.from([1, 2, 3]);
|
|
15
15
|
|
|
16
16
|
simple.mock(sender, 'toString').returnWith('1.3');
|
|
17
17
|
simple.mock(target, 'toString').returnWith('1.10');
|
|
@@ -47,7 +47,7 @@ describe('Command', function() {
|
|
|
47
47
|
|
|
48
48
|
it('should skip empty payload', function() {
|
|
49
49
|
command = new Command(code, {
|
|
50
|
-
payload:
|
|
50
|
+
payload: Buffer.from([])
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
should(command).have.properties({
|
|
@@ -103,7 +103,7 @@ describe('Command', function() {
|
|
|
103
103
|
data: data
|
|
104
104
|
});
|
|
105
105
|
|
|
106
|
-
var message =
|
|
106
|
+
var message = Buffer.from('0E010300000031010A010203', 'hex');
|
|
107
107
|
|
|
108
108
|
should(encode.firstCall.arg).eql(data);
|
|
109
109
|
should(command.message).eql(message);
|
|
@@ -115,7 +115,7 @@ describe('Command', function() {
|
|
|
115
115
|
target: target
|
|
116
116
|
});
|
|
117
117
|
|
|
118
|
-
var message =
|
|
118
|
+
var message = Buffer.from('0B010300000031010A', 'hex');
|
|
119
119
|
|
|
120
120
|
should(command.message).eql(message);
|
|
121
121
|
});
|
|
@@ -180,7 +180,7 @@ describe('Command', function() {
|
|
|
180
180
|
payload: payload
|
|
181
181
|
});
|
|
182
182
|
|
|
183
|
-
var message =
|
|
183
|
+
var message = Buffer.from('0E010300000031010A010203', 'hex');
|
|
184
184
|
|
|
185
185
|
should(command.message).eql(message);
|
|
186
186
|
});
|
package/test/device.js
CHANGED