@zimo-elektronik/zcan 1.0.3 → 1.0.4
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/dist/@types/models.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { Subject } from 'rxjs';
|
|
1
2
|
import MX10 from '../MX10';
|
|
2
3
|
import { Buffer } from 'buffer';
|
|
4
|
+
import { PingResponseExtended } from 'src/@types/models';
|
|
3
5
|
export default class NetworkGroup {
|
|
6
|
+
readonly onPingResponse: Subject<PingResponseExtended>;
|
|
4
7
|
private mx10;
|
|
8
|
+
pingTimeout: NodeJS.Timeout | null;
|
|
5
9
|
constructor(mx10: MX10);
|
|
6
10
|
ping(mode?: number): void;
|
|
7
11
|
portClose(): void;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { Subject } from 'rxjs';
|
|
1
2
|
export default class NetworkGroup {
|
|
3
|
+
onPingResponse = new Subject();
|
|
2
4
|
mx10;
|
|
5
|
+
pingTimeout = null;
|
|
3
6
|
constructor(mx10) {
|
|
4
7
|
this.mx10 = mx10;
|
|
5
8
|
}
|
|
@@ -22,16 +25,31 @@ export default class NetworkGroup {
|
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
27
|
pingResponse(size, mode, nid, _buffer) {
|
|
25
|
-
if (
|
|
26
|
-
if (
|
|
27
|
-
this.mx10.mx10NID
|
|
28
|
+
if (this.onPingResponse.observed) {
|
|
29
|
+
if (size === 8) {
|
|
30
|
+
if (!this.mx10.mx10NID) {
|
|
31
|
+
this.mx10.mx10NID = nid;
|
|
32
|
+
}
|
|
33
|
+
this.mx10.connected = true;
|
|
34
|
+
this.mx10.reconnectLogic();
|
|
35
|
+
if (this.pingTimeout) {
|
|
36
|
+
clearTimeout(this.pingTimeout);
|
|
37
|
+
}
|
|
38
|
+
this.pingTimeout = setTimeout(() => {
|
|
39
|
+
this.mx10.connected = false;
|
|
40
|
+
this.onPingResponse.next({
|
|
41
|
+
connected: this.mx10.connected,
|
|
42
|
+
});
|
|
43
|
+
console.log('No ping for 5 seconds, disconnected');
|
|
44
|
+
}, 5000);
|
|
28
45
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
46
|
+
else {
|
|
47
|
+
throw new Error('LENGTH ERROR: readCmdGrp_0x0A-0x0A, read length as: ' +
|
|
48
|
+
size.toString());
|
|
49
|
+
}
|
|
50
|
+
this.onPingResponse.next({
|
|
51
|
+
connected: this.mx10.connected,
|
|
52
|
+
});
|
|
35
53
|
}
|
|
36
54
|
}
|
|
37
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"networkGroup.js","sourceRoot":"","sources":["../../src/zcan/networkGroup.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"networkGroup.js","sourceRoot":"","sources":["../../src/zcan/networkGroup.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,MAAM,CAAC;AAS7B,MAAM,CAAC,OAAO,OAAO,YAAY;IACf,cAAc,GAAG,IAAI,OAAO,EAAwB,CAAC;IAE7D,IAAI,CAAO;IACnB,WAAW,GAA0B,IAAI,CAAC;IAE1C,YAAY,IAAU;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,CAAC,IAAI,GAAG,IAAI;QACd,IAAI,CAAC,IAAI,CAAC,QAAQ,CAChB,IAAI,EACJ,IAAI,EACJ;YACE;gBACE,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO;gBACxB,MAAM,EAAE,CAAC;aACV;SACF,EACD,IAAI,CACL,CAAC;IACJ,CAAC;IAED,SAAS;QACP,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAC,C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,CAAC,IAAI,CAAC;gBACvB,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;aAC/B,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "https://github.com/ZIMO-Elektronik/zcan",
|
|
8
|
-
"version": "1.0.
|
|
8
|
+
"version": "1.0.4",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"start": "node dist/main.js",
|
|
11
11
|
"start:dev": "nodemon --ext js,ts,json,env --exec \"node --experimental-specifier-resolution=node --loader ts-node/esm\" src/main.ts",
|
package/src/@types/models.ts
CHANGED
package/src/zcan/networkGroup.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
// 0x0A
|
|
2
|
+
import {Subject} from 'rxjs';
|
|
2
3
|
import MX10 from '../MX10';
|
|
3
4
|
import {Buffer} from 'buffer';
|
|
5
|
+
import {PingResponseExtended} from 'src/@types/models';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
*
|
|
7
9
|
* @category Groups
|
|
8
10
|
*/
|
|
9
11
|
export default class NetworkGroup {
|
|
12
|
+
public readonly onPingResponse = new Subject<PingResponseExtended>();
|
|
13
|
+
|
|
10
14
|
private mx10: MX10;
|
|
15
|
+
pingTimeout: NodeJS.Timeout | null = null;
|
|
11
16
|
|
|
12
17
|
constructor(mx10: MX10) {
|
|
13
18
|
this.mx10 = mx10;
|
|
@@ -47,25 +52,42 @@ export default class NetworkGroup {
|
|
|
47
52
|
|
|
48
53
|
// 0x0A.0x00
|
|
49
54
|
pingResponse(size: number, mode: number, nid: number, _buffer: Buffer) {
|
|
50
|
-
if (
|
|
51
|
-
|
|
55
|
+
if (this.onPingResponse.observed) {
|
|
56
|
+
if (size === 8) {
|
|
57
|
+
// TODO IMPLEMENT DETAIL READOUT
|
|
52
58
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
59
|
+
if (!this.mx10.mx10NID) {
|
|
60
|
+
this.mx10.mx10NID = nid;
|
|
61
|
+
}
|
|
62
|
+
this.mx10.connected = true;
|
|
63
|
+
|
|
64
|
+
// TODO reconnect when uuid has changed
|
|
65
|
+
// const uuid = buffer.readUInt32LE(0);
|
|
57
66
|
|
|
58
|
-
|
|
59
|
-
// const uuid = buffer.readUInt32LE(0);
|
|
67
|
+
this.mx10.reconnectLogic();
|
|
60
68
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
69
|
+
if (this.pingTimeout) {
|
|
70
|
+
clearTimeout(this.pingTimeout);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
this.pingTimeout = setTimeout(() => {
|
|
74
|
+
this.mx10.connected = false;
|
|
75
|
+
this.onPingResponse.next({
|
|
76
|
+
connected: this.mx10.connected,
|
|
77
|
+
});
|
|
78
|
+
// eslint-disable-next-line no-console
|
|
79
|
+
console.log('No ping for 5 seconds, disconnected');
|
|
80
|
+
}, 5000);
|
|
81
|
+
} else {
|
|
82
|
+
throw new Error(
|
|
83
|
+
'LENGTH ERROR: readCmdGrp_0x0A-0x0A, read length as: ' +
|
|
84
|
+
size.toString(),
|
|
85
|
+
);
|
|
86
|
+
}
|
|
64
87
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
);
|
|
88
|
+
this.onPingResponse.next({
|
|
89
|
+
connected: this.mx10.connected,
|
|
90
|
+
});
|
|
69
91
|
}
|
|
70
92
|
}
|
|
71
93
|
}
|