@signalk/vedirect-serial-usb 1.5.0 → 1.6.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.
Files changed (63) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +13 -24
  3. package/dist/Parser.d.ts +50 -0
  4. package/dist/Parser.d.ts.map +1 -0
  5. package/dist/Parser.js +350 -0
  6. package/dist/Parser.js.map +1 -0
  7. package/dist/constants.d.ts +5 -0
  8. package/dist/constants.d.ts.map +1 -0
  9. package/dist/constants.js +14 -0
  10. package/dist/constants.js.map +1 -0
  11. package/dist/fields.d.ts +14 -0
  12. package/dist/fields.d.ts.map +1 -0
  13. package/dist/fields.js +438 -0
  14. package/dist/fields.js.map +1 -0
  15. package/dist/index.d.ts +4 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +209 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/productIds.d.ts +9 -0
  20. package/dist/productIds.d.ts.map +1 -0
  21. package/dist/productIds.js +95 -0
  22. package/dist/productIds.js.map +1 -0
  23. package/dist/serial.d.ts +5 -0
  24. package/dist/serial.d.ts.map +1 -0
  25. package/dist/serial.js +78 -0
  26. package/dist/serial.js.map +1 -0
  27. package/dist/standalone.d.ts +22 -0
  28. package/dist/standalone.d.ts.map +1 -0
  29. package/dist/standalone.js +69 -0
  30. package/dist/standalone.js.map +1 -0
  31. package/dist/tcp.d.ts +5 -0
  32. package/dist/tcp.d.ts.map +1 -0
  33. package/dist/tcp.js +106 -0
  34. package/dist/tcp.js.map +1 -0
  35. package/dist/types.d.ts +159 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/types.js +15 -0
  38. package/dist/types.js.map +1 -0
  39. package/dist/udp.d.ts +5 -0
  40. package/dist/udp.d.ts.map +1 -0
  41. package/dist/udp.js +67 -0
  42. package/dist/udp.js.map +1 -0
  43. package/docs/screenshots/1_config.png +0 -0
  44. package/logo.svg +46 -0
  45. package/package.json +79 -19
  46. package/.github/FUNDING.yml +0 -1
  47. package/.travis.yml +0 -13
  48. package/index.js +0 -159
  49. package/lib/Parser.js +0 -396
  50. package/lib/fields.js +0 -503
  51. package/lib/filestream.js +0 -38
  52. package/lib/productIds.json +0 -84
  53. package/lib/serial.js +0 -48
  54. package/lib/tcp.js +0 -53
  55. package/lib/udp.js +0 -26
  56. package/log/one.txt +0 -18
  57. package/log/run-log.js +0 -7
  58. package/log/sampleOutput.txt +0 -297
  59. package/migration.js +0 -57
  60. package/run.js +0 -10
  61. package/standalone.js +0 -68
  62. package/test/index.js +0 -52
  63. package/todo.md +0 -14
package/lib/tcp.js DELETED
@@ -1,53 +0,0 @@
1
- const Net = require('net');
2
- let client = [];
3
-
4
- function makeConnection(host, port, debug, items) {
5
- client[items] = new Net.Socket();
6
- client[items].connect({ port: port, host: host });
7
- client[items].setTimeout(5000);
8
- debug(`Connection to ${host}:${port}`);
9
- return client[items]
10
- }
11
-
12
- function onData(msg, parser, debug, items) {
13
- parser[items].addChunk(msg, items);
14
- debug(`${msg}`);
15
- }
16
-
17
- function onClose(host, port, parser, debug, items) {
18
- if(client[items]) {
19
- setTimeout(() => {
20
- debug('Trying to reconnect');
21
- module.exports.connect(host, port, parser, debug, items);
22
- }, 10000);
23
- }
24
- }
25
-
26
- module.exports = {
27
- connect: (host, port, parser, debug, items) => {
28
- client[items] = makeConnection(host, port, debug, items);
29
- client[items].on('data', (msg) => {
30
- onData(msg, parser, debug, items);
31
- });
32
- client[items].on('close', () => {
33
- debug('TCP connection closed');
34
- client[items].destroy();
35
- onClose(host, port, parser, debug, items);
36
- });
37
- client[items].on('error', () => {
38
- debug('TCP connection error');
39
- client[items].destroy();
40
- });
41
- client[items].on('timeout', () => {
42
- debug('TCP connection timeout');
43
- client[items].destroy();
44
- });
45
- },
46
- close: (debug, items) => {
47
- if (client[items]) {
48
- client[items].destroy();
49
- client[items] = null;
50
- debug(`TCP port closed`);
51
- }
52
- }
53
- }
package/lib/udp.js DELETED
@@ -1,26 +0,0 @@
1
- const dgram = require('dgram');
2
- let socket = [];
3
-
4
- module.exports = {
5
- listen: (port, parser, debug, items) => {
6
- socket[items] = dgram.createSocket({ type: 'udp4', reuseAddr: true });
7
-
8
- socket[items].on('listening', () => {
9
- debug(`listening on UDP ${port}`);
10
- })
11
-
12
- socket[items].on('message', (msg, rinfo) => {
13
- debug(`${rinfo.address}:${rinfo.port}:${msg}`);
14
- parser[items].addChunk(msg, items);
15
- })
16
-
17
- socket[items].bind(port);
18
- },
19
- close: (debug, items) => {
20
- if (socket[items]) {
21
- socket[items].close();
22
- socket[items] = null;
23
- debug(`UDP port closed`);
24
- }
25
- }
26
- }
package/log/one.txt DELETED
@@ -1,18 +0,0 @@
1
- PID 0xA04C
2
- FW 127
3
- SER# HQ1621FRG7Z
4
- V 14990
5
- I 2770
6
- VPV 20450
7
- PPV 42
8
- CS 4
9
- ERR 0
10
- LOAD OFF
11
- IL 0
12
- H19 6078
13
- H20 14
14
- H21 100
15
- H22 52
16
- H23 148
17
- HSDS 208
18
- Checksum ⸮
package/log/run-log.js DELETED
@@ -1,7 +0,0 @@
1
- const join = require('path').join
2
- const stream = require('../lib/filestream')
3
- const Parser = require('../lib/Parser')
4
- const PATH = join(__dirname, './sampleOutput.txt')
5
- const parser = new Parser()
6
-
7
- stream.open(PATH, parser)
@@ -1,297 +0,0 @@
1
- VS 5
2
- I 0
3
- P 0
4
- CE 0
5
-
6
- H5 0
7
- H6 0
8
- H7 7
9
- H8 12184
10
- V 12140TTG -1
11
- Alarm OFF
12
- Relay OFF
13
- ⸮
14
- H1 -1
15
- H2 0
16
- H3 0
17
- H4 0
18
- H50
19
- H10 0
20
- H11 0
21
- H12 0
22
- H15 3
23
- Relay OFF
24
- AR 0
25
- BMV 702
26
- FWH3 0
27
- H4 0
28
- H5 0
29
- H6 0
30
- H7 7
31
- 8 0
32
- Checksum ⸮
33
- PID 0x204
34
- V
35
- H1 -1
36
- H2 0
37
- H3 0
38
- H4 0
39
- H5 0
40
- PID 0x204
41
- V 12140
42
- VS 5
43
- IRelay OFF
44
- AR 0
45
- BMV 702
46
- FW 0308
47
- Checksum ⸮ 0
48
- H4 0
49
- H5 0
50
- H2 0
51
- H15 3
52
- H16 7
53
- H17 0
54
- H18 0
55
- Checksum ⸮0
56
- P 0
57
- CE 0
58
- SOC 1000
59
- TTG -
60
- H1 -1
61
- H2 0
62
- H3 0
63
- H4 0
64
- H0 0
65
- H11 0
66
- H12 0
67
- H15 3
68
- H16
69
- H1 -1
70
- H2 0
71
- H7 7
72
- H8 12180
73
- H9 0
74
- H10 0
75
- 40
76
- VS 5
77
- I 0
78
- P 0 1000
79
- TTG -1
80
- Alarm OFF
81
- Relay
82
- H1 -1
83
-
84
- PID 0
85
- H7 7
86
- H8 12180
87
- H9 0
88
- H10 0
89
- cksum ⸮
90
- H1 -1
91
- H2 0
92
- H3 0
93
- H4
94
- H9 0
95
- H10 0
96
- H11 0
97
- H12 0
98
-
99
- CE 0
100
- SOC 1000
101
- TTG -1
102
- Alar
103
- FW 0308
104
- Checksum ⸮
105
- H1 -1
106
- H 7
107
- H8 12180
108
- H9 0
109
- H10 0
110
- H11 S 5
111
- I 0
112
- P 0
113
- CE 0
114
- SO
115
- AR 0
116
- BMV 702
117
- FW 0308
118
- Checks9 0
119
- H10 0
120
- H11 0
121
- H12 0
122
- H154
123
- V 12140FF
124
- Relay OFF
125
- AR 0
126
- BMV 702
127
- 0
128
- H3 0
129
- H4 0
130
- H12 0
131
- H15 3
132
- H16 7
133
- H17 0
134
- PID 0x204
135
- V 12140
136
- VS TTG -1
137
- Alarm OFF
138
- Relay OFF
139
- 0
140
- H6 0
141
- H7 7
142
- H8 12180
143
- H9 H16 7
144
- H17 0
145
- H18 0
146
- Checksum ⸮
147
- H1 -1
148
- H2 0
149
- H
150
- PID 0x204
151
- V -1
152
- Alarm OFF
153
- Relay OFF
154
- AR 0
155
- H4 0
156
- H5 0
157
- H
158
- PID 0x204
159
- 7
160
- H17 0
161
- H18 0
162
- Checksum ⸮
163
- POC 1000
164
- TTG -1
165
- Alarm OFF
166
- RelID
167
- Alarm OFF
168
- Relay OFF
169
- AR 0
170
- V 702
171
- FW 0308
172
- Checksum ⸮H17 0
173
- H18 0
174
- Checksum ⸮
175
- PID 0ecksum ⸮
176
- PID 0x204
177
- V 12139
178
- 702
179
- FW 0308
180
- Checksum ⸮
181
- PID 0x204
182
- V 12140
183
- FF
184
- AR 0
185
- BMV 702
186
- FW 0308
187
- Che
188
- H1 -15 3
189
- H16 7
190
- H17 0
191
- H18 0
192
- CheckH5 0
193
- H6 0
194
- H7 7
195
- H8 12180
196
- 4
197
- V 12140E 0
198
- SOC 1000
199
- TTG -1
200
- Alarm O0
201
- H3 0
202
- H4 0
203
- H12 0
204
- H15 3
205
- H16 7
206
- H17 0
207
- PID 0x204
208
- V 12R 0
209
- BMV 702
210
- FW 0308
211
- Checksum
212
- H16 7
213
- H17 0
214
- H18 0
215
- Checksum ⸮
216
- V 12140
217
- 0308
218
- Checksum ⸮
219
- H1 -1
220
- H2 0
221
- H12 0
222
- H15 3
223
- H16 7
224
- H17 0
225
- H18
226
- BMV 702
227
- FW 0308
228
- Checksum ⸮
229
-
230
- H6 0
231
- H7 7
232
- H8 12180
233
- H9 0
234
- 08
235
- Checksum ⸮
236
- H1 -1
237
- H2 0
238
- H3
239
- PID 0x204
240
- 1
241
- Alarm OFF
242
- Relay OFF
243
- AR 01 -
244
- H17 0
245
- H18 0
246
- Checksum ⸮
247
- PIDOC 1000
248
- TTG -1
249
- Alarm OFF
250
- Re
251
- H4 0
252
- H5 0
253
- H6 0
254
- H
255
- H15 3
256
- H16 7
257
- H17 0
258
- H18 0
259
- CID Alarm OFF
260
- Relay OFF
261
- AR 0
262
- BM 1000
263
- TTG -1
264
- Alarm OFF
265
- Rel80
266
- H9 0
267
- H10 0
268
- H11 0
269
- H12 0H15 3
270
- H16 7
271
- H17 0
272
- H18 0
273
- Che 0x20
274
- H1 -1
275
- H2 0
276
- H3 0
277
- H4H11 0
278
- H12 0
279
- H15 3
280
- H16 7
281
- H
282
- VS 5
283
- I 0
284
- P 0
285
- CE
286
- H9 0
287
- H10 0
288
- H11 0
289
- H12 0
290
- H1
291
- PID
292
- CE 0
293
- SOC 1000
294
- TTG -1
295
- Alar
296
- FW 0308
297
- Checksum ⸮
package/migration.js DELETED
@@ -1,57 +0,0 @@
1
- const fs = require('fs')
2
- const path = require('path');
3
-
4
- jsonPath = __dirname + '/../../../plugin-config-data';
5
- fs.readFile(path.resolve(jsonPath, 'vedirect-signalk.json'), 'UTF-8', (err, data) => {
6
- if (err) {
7
- console.error(err)
8
- return
9
- }
10
-
11
- let obj = JSON.parse(data);
12
-
13
- if (typeof obj.configuration.vedirect == 'undefined' ) {
14
- if (obj.configuration.device) {
15
- obj.configuration.vedirect = [{
16
- 'device':'Serial',
17
- 'connection': obj.configuration.device,
18
- 'port': '',
19
- 'ignoreChecksum': obj.configuration.ignoreChecksum,
20
- 'mainBatt': obj.configuration.mainBatt,
21
- 'auxBatt': obj.configuration.auxBatt,
22
- 'bmv': obj.configuration.bmv,
23
- 'solar': obj.configuration.solar
24
- }]
25
- } else if (obj.configuration.udpPort) {
26
- obj.configuration.vedirect = [{
27
- 'device':'UDP',
28
- 'connection': 'localhost',
29
- 'port': obj.configuration.udpPort,
30
- 'ignoreChecksum': obj.configuration.ignoreChecksum,
31
- 'mainBatt': obj.configuration.mainBatt,
32
- 'auxBatt': obj.configuration.auxBatt,
33
- 'bmv': obj.configuration.bmv,
34
- 'solar': obj.configuration.solar
35
- }]
36
- } else if (obj.configuration.host) {
37
- obj.configuration.vedirect = [{
38
- 'device':'TCP',
39
- 'connection': obj.configuration.host,
40
- 'port': obj.configuration.tcpPort,
41
- 'ignoreChecksum': obj.configuration.ignoreChecksum,
42
- 'mainBatt': obj.configuration.mainBatt,
43
- 'auxBatt': obj.configuration.auxBatt,
44
- 'bmv': obj.configuration.bmv,
45
- 'solar': obj.configuration.solar
46
- }]
47
- }
48
-
49
- let dataOut = JSON.stringify(obj, null, 2)
50
- fs.writeFile(path.resolve(jsonPath, 'vedirect-signalk.json'), dataOut, 'utf8', function(err) {
51
- if (err) {
52
- console.error(err)
53
- return
54
- }
55
- });
56
- }
57
- });
package/run.js DELETED
@@ -1,10 +0,0 @@
1
- const app = {
2
- debug: (msg) => console.log(msg),
3
- handleMessage: (id, delta) => console.log(JSON.stringify(delta, null, 2))
4
- }
5
-
6
- const plugin = require('./')(app)
7
- plugin.start({
8
- udpPort: 7878,
9
- ignoreChecksum: true
10
- })
package/standalone.js DELETED
@@ -1,68 +0,0 @@
1
- /**
2
- * standalone.js
3
- *
4
- * @description exports a class that shims the Signal K server, in order to make this plugin available as a library in other software
5
- * @module @signalk/vedirect-serial-usb
6
- * @author Fabian Tollenaar <fabian@essense.ai> (https://essense.ai)
7
- * @license Apache_2.0
8
- */
9
-
10
- const EventEmitter = require('events')
11
- const SKPlugin = require('./index')
12
- class VEDirect extends EventEmitter {
13
- constructor (config = {}, _debug = false) {
14
- super()
15
-
16
- this._debug = _debug
17
- this.app = {
18
- handleMessage: (kind, data) => {
19
- if (kind === 'pluginId') {
20
- this.emit('delta', data)
21
- return
22
- }
23
- this.emit(kind, data)
24
- },
25
- debug: (args) => this.debug(args),
26
- options: {
27
- device: 'Serial',
28
- connection: '/dev/ttyUSB0',
29
- port: 7878,
30
- ignoreChecksum: true,
31
- mainBatt: 'House',
32
- auxBatt: 'Starter',
33
- bmv: 'bmv',
34
- solar: 'Main',
35
- ...(config || {}),
36
- }
37
- }
38
-
39
- this.plugin = SKPlugin(this.app)
40
- this.start()
41
- }
42
-
43
- start () {
44
- if (!this.plugin || !this.plugin.hasOwnProperty('start')) {
45
- this.debug(`Plugin not initialised, can't start`)
46
- return
47
- }
48
-
49
- this.plugin.start(this.app.options)
50
- }
51
-
52
- stop () {
53
- if (!this.plugin || !this.plugin.hasOwnProperty('stop')) {
54
- this.debug(`Plugin not initialised, can't stop`)
55
- return
56
- }
57
-
58
- this.plugin.stop()
59
- }
60
-
61
- debug (...args) {
62
- if (this._debug) {
63
- console.log.apply(console, args)
64
- }
65
- }
66
- }
67
-
68
- module.exports = VEDirect
package/test/index.js DELETED
@@ -1,52 +0,0 @@
1
- const fs = require('fs')
2
- const join = require('path').join
3
- const chai = require('chai')
4
- const Parser = require('../lib/Parser')
5
- const expect = chai.expect
6
-
7
- const parser = new Parser({
8
- vedirect: [ { device: 'UDP', connection: 'localhost', port: 7878, ignoreChecksum: true, mainBatt: 'House', auxBatt: 'Starter', solar: 'Main' } ]
9
- })
10
-
11
- let lines = []
12
-
13
- describe('VE.Direct parser', () => {
14
- before(done => {
15
- try {
16
- const text = fs.readFileSync(join(__dirname, '../log/sampleOutput.txt'), 'utf-8')
17
- lines = text.split('\n').map(line => `\n${line}`)
18
- done()
19
- } catch (err) {
20
- done(err)
21
- }
22
- })
23
-
24
- it('Reads the log file and finds multiple lines', done => {
25
- expect(lines.length).to.be.a('number')
26
- expect(lines.length).to.be.above(1)
27
- done()
28
- })
29
-
30
- it('Parses each line that has a Signal K representation withouth error', done => {
31
- try {
32
- let parsed = []
33
-
34
- const listener = delta => {
35
- parsed.push(delta)
36
- }
37
-
38
- parser.on('delta', listener)
39
-
40
- lines.forEach(line => {
41
- parser.addChunk(Buffer.from(line), 0)
42
- })
43
-
44
- parser.removeListener('delta', listener)
45
- expect(parsed.length).to.be.a('number')
46
- expect(parsed.length).to.equal(16)
47
- done()
48
- } catch (err) {
49
- done(err)
50
- }
51
- })
52
- })
package/todo.md DELETED
@@ -1,14 +0,0 @@
1
- # TODO
2
-
3
- - [x] Reformat code into a Parser class with separate field and product definition
4
- - [x] Make start on unit tests (WIP)
5
- - [x] Include log file for testing
6
- - [x] Expand list of product IDs/devices
7
- - [x] Implement all enums in the VE.direct spec
8
- - [x] Make parser run on entire block, and check checksum for each block
9
- - [x] Test checksum implementation with real Victron device (help needed)
10
- - [x] Emit deltas for entire block, if checksum checks out
11
- - [x] Pass delta on to SK server
12
- - [ ] Test on more Victron devices (help needed)
13
- - [ ] Add more unit tests
14
- - [x] Create back door to allow CI tests to complete without failing checksum