@signalk/vedirect-serial-usb 1.4.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.
- package/LICENSE +201 -0
- package/README.md +13 -24
- package/dist/Parser.d.ts +50 -0
- package/dist/Parser.d.ts.map +1 -0
- package/dist/Parser.js +350 -0
- package/dist/Parser.js.map +1 -0
- package/dist/constants.d.ts +5 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +14 -0
- package/dist/constants.js.map +1 -0
- package/dist/fields.d.ts +14 -0
- package/dist/fields.d.ts.map +1 -0
- package/dist/fields.js +438 -0
- package/dist/fields.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +209 -0
- package/dist/index.js.map +1 -0
- package/dist/productIds.d.ts +9 -0
- package/dist/productIds.d.ts.map +1 -0
- package/dist/productIds.js +95 -0
- package/dist/productIds.js.map +1 -0
- package/dist/serial.d.ts +5 -0
- package/dist/serial.d.ts.map +1 -0
- package/dist/serial.js +78 -0
- package/dist/serial.js.map +1 -0
- package/dist/standalone.d.ts +22 -0
- package/dist/standalone.d.ts.map +1 -0
- package/dist/standalone.js +69 -0
- package/dist/standalone.js.map +1 -0
- package/dist/tcp.d.ts +5 -0
- package/dist/tcp.d.ts.map +1 -0
- package/dist/tcp.js +106 -0
- package/dist/tcp.js.map +1 -0
- package/dist/types.d.ts +159 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +15 -0
- package/dist/types.js.map +1 -0
- package/dist/udp.d.ts +5 -0
- package/dist/udp.d.ts.map +1 -0
- package/dist/udp.js +67 -0
- package/dist/udp.js.map +1 -0
- package/docs/screenshots/1_config.png +0 -0
- package/logo.svg +46 -0
- package/package.json +79 -19
- package/.github/FUNDING.yml +0 -1
- package/.travis.yml +0 -13
- package/index.js +0 -154
- package/lib/Parser.js +0 -391
- package/lib/fields.js +0 -501
- package/lib/filestream.js +0 -38
- package/lib/productIds.json +0 -84
- package/lib/serial.js +0 -48
- package/lib/tcp.js +0 -47
- package/lib/udp.js +0 -26
- package/log/one.txt +0 -18
- package/log/run-log.js +0 -7
- package/log/sampleOutput.txt +0 -297
- package/migration.js +0 -54
- package/run.js +0 -10
- package/standalone.js +0 -67
- package/test/index.js +0 -52
- package/todo.md +0 -14
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2018 Joachim Bakke, Fabian Tollenaar and Karl-Erik Gustafsson
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
[](https://travis-ci.org/SignalK/vedirect-serial-usb) [](https://greenkeeper.io/)
|
|
2
|
-
|
|
3
1
|
# vedirect-serial-usb
|
|
4
2
|
|
|
3
|
+
[](https://github.com/SignalK/vedirect-serial-usb/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/@signalk/vedirect-serial-usb)
|
|
5
|
+
[](https://github.com/SignalK/vedirect-serial-usb/blob/master/LICENSE)
|
|
6
|
+
|
|
5
7
|
This code is a [Signal K Node Server](https://github.com/SignalK/signalk-server-node) plugin. It reads and parses Victron VE.Direct data.
|
|
6
8
|
|
|
7
9
|
The common way to connect to a Victron product is with the Victron [VE.Direct to USB interface](https://www.victronenergy.com/accessories/ve-direct-to-usb-interface) cable.
|
|
@@ -27,15 +29,15 @@ https://pysselilivet.blogspot.com/2021/02/victron-vedirect-with-raspberry.html.
|
|
|
27
29
|
Lastly, note that when having a Victron GX Device, you won't be needing this
|
|
28
30
|
plugin. Details for that [here](https://github.com/sbender9/signalk-venus-plugin).
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
## Installation
|
|
31
33
|
|
|
32
34
|
Use the Signal K app store or install via NPM in the Signal K server root directory: `npm install @signalk/vedirect-serial-usb`
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
## Usage
|
|
35
37
|
|
|
36
|
-
Set up the
|
|
38
|
+
Set up the appropriate device on the settings page of this plugin in the Signal K server admin UI, for instance to `/dev/ttyUSB0` and enable the plugin. Your VE.Direct data will be available in Signal K format via various clients and apps.
|
|
37
39
|
|
|
38
|
-
|
|
40
|
+
## Connections
|
|
39
41
|
|
|
40
42
|
**Select device**
|
|
41
43
|
|
|
@@ -60,7 +62,7 @@ Set up the appropiate device on the settings page of this plugin in the Signal K
|
|
|
60
62
|
|
|
61
63
|
- Give each device unique SK paths
|
|
62
64
|
|
|
63
|
-
|
|
65
|
+
## Usage as a library
|
|
64
66
|
|
|
65
67
|
It's possible to use this plugin as a library, in other Node.js code. This feature simply wraps the plugin in an easy-to-consume manner, so functionality is identical. Example:
|
|
66
68
|
|
|
@@ -71,7 +73,7 @@ const consumer = new VEDirect({
|
|
|
71
73
|
ignoreChecksum: true,
|
|
72
74
|
mainBatt: 'House',
|
|
73
75
|
auxBatt: 'Starter',
|
|
74
|
-
solar: 'Main'
|
|
76
|
+
solar: 'Main'
|
|
75
77
|
})
|
|
76
78
|
|
|
77
79
|
consumer.on('delta', (delta) => console.log('[onDelta]', delta))
|
|
@@ -79,21 +81,8 @@ consumer.stop() // stop the plugin, destruct the connections
|
|
|
79
81
|
consumer.start() // (re-)start the plugin
|
|
80
82
|
```
|
|
81
83
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
```
|
|
85
|
-
Copyright 2018 Joachim Bakke <github@heiamoss.com>, Fabian Tollenaar <fabian@decipher.industries> and
|
|
86
|
-
Karl-Erik Gustafsson <ke.gustafsson@gmail.com>
|
|
87
|
-
|
|
88
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
89
|
-
you may not use this file except in compliance with the License.
|
|
90
|
-
You may obtain a copy of the License at
|
|
84
|
+
## License
|
|
91
85
|
|
|
92
|
-
|
|
86
|
+
Apache-2.0. See [LICENSE](LICENSE).
|
|
93
87
|
|
|
94
|
-
|
|
95
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
96
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
97
|
-
See the License for the specific language governing permissions and
|
|
98
|
-
limitations under the License.
|
|
99
|
-
```
|
|
88
|
+
Copyright 2018 Joachim Bakke, Fabian Tollenaar and Karl-Erik Gustafsson.
|
package/dist/Parser.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Debugger } from 'debug';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import type { FieldContext, FieldMap, PluginOptions, StoredField } from './types';
|
|
4
|
+
/** Parser configuration after merging caller options with defaults. */
|
|
5
|
+
interface ParserOptions extends PluginOptions {
|
|
6
|
+
productIds: Record<string, string>;
|
|
7
|
+
fields: FieldMap;
|
|
8
|
+
defaultUnitId: string;
|
|
9
|
+
mainBatt: string;
|
|
10
|
+
auxBatt: string;
|
|
11
|
+
bmv: string;
|
|
12
|
+
solar: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class VEDirectParser extends EventEmitter implements FieldContext {
|
|
15
|
+
options: ParserOptions;
|
|
16
|
+
fields: FieldMap;
|
|
17
|
+
debug: Debugger;
|
|
18
|
+
line: string[];
|
|
19
|
+
data: Record<string, StoredField>;
|
|
20
|
+
cache: string;
|
|
21
|
+
sum: number;
|
|
22
|
+
constructor(opts?: PluginOptions);
|
|
23
|
+
addChunk(buf: Buffer, connectionIndex: number): void;
|
|
24
|
+
parse(line: string): void;
|
|
25
|
+
set(key: string, value: StoredField): void;
|
|
26
|
+
get(key: string): StoredField | undefined;
|
|
27
|
+
unset(key: string): void;
|
|
28
|
+
getData(): Record<string, StoredField>;
|
|
29
|
+
private _verifyCacheAndParse;
|
|
30
|
+
private _parse;
|
|
31
|
+
getAlarmReason(alarmReason: string | number): string | undefined;
|
|
32
|
+
getErrorString(err: string | number): string | undefined;
|
|
33
|
+
getMode(mode: string | number): string | undefined;
|
|
34
|
+
getStateOfOperation(cs: string | number): string | undefined;
|
|
35
|
+
getTrackerOperationMode(mppt: string | number): string | undefined;
|
|
36
|
+
getProductLongname(pid: string): string;
|
|
37
|
+
generateDelta(connectionIndex: number): void;
|
|
38
|
+
getPath(name: string, connectionIndex: number): string | null;
|
|
39
|
+
/**
|
|
40
|
+
* Resolves a field's unit id to the configured device name. The four
|
|
41
|
+
* configurable units come from the connection; aux2Batt/inverter have no
|
|
42
|
+
* config slot and use defaultUnitId. The switch is exhaustive over UnitId,
|
|
43
|
+
* so adding a unit without handling it here is a compile error.
|
|
44
|
+
*/
|
|
45
|
+
private resolveUnitId;
|
|
46
|
+
warn(message: string): void;
|
|
47
|
+
error(err: Error): void;
|
|
48
|
+
}
|
|
49
|
+
export default VEDirectParser;
|
|
50
|
+
//# sourceMappingURL=Parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Parser.d.ts","sourceRoot":"","sources":["../src/Parser.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAGrC,OAAO,KAAK,EACV,YAAY,EACZ,QAAQ,EACR,aAAa,EAEb,WAAW,EAGZ,MAAM,SAAS,CAAA;AAGhB,uEAAuE;AACvE,UAAU,aAAc,SAAQ,aAAa;IAC3C,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAClC,MAAM,EAAE,QAAQ,CAAA;IAChB,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;CACd;AAiBD,qBAAa,cAAe,SAAQ,YAAa,YAAW,YAAY;IACtE,OAAO,EAAE,aAAa,CAAA;IACtB,MAAM,EAAE,QAAQ,CAAA;IAChB,KAAK,EAAE,QAAQ,CAAA;IACf,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;IACjC,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;gBAEC,IAAI,CAAC,EAAE,aAAa;IAWhC,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,IAAI;IA6BpD,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAQzB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI;IAM1C,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAIzC,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAYxB,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC;IAItC,OAAO,CAAC,oBAAoB;IA0B5B,OAAO,CAAC,MAAM;IAoCd,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS;IA2ChE,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS;IAgDxD,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS;IAgBlD,mBAAmB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS;IA4B5D,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS;IAgBlE,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAUvC,aAAa,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI;IAyC5C,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAyB7D;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAmBrB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAK3B,KAAK,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI;CAIxB;AAED,eAAe,cAAc,CAAA"}
|
package/dist/Parser.js
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.VEDirectParser = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* VE.Direct text-protocol parser.
|
|
9
|
+
*
|
|
10
|
+
* Accumulates raw bytes into blocks (terminated by the `Checksum` field),
|
|
11
|
+
* verifies the block checksum (a running byte sum that must be 0 mod 256),
|
|
12
|
+
* decodes each `label<TAB>value` line via the field table, and emits a Signal
|
|
13
|
+
* K delta per valid block.
|
|
14
|
+
*
|
|
15
|
+
* Block layout on the wire (one field per line, `\r\n`-separated):
|
|
16
|
+
* "\r\nPID\t0xA053\r\nV\t12340\r\n...\r\nChecksum\t<byte>"
|
|
17
|
+
*/
|
|
18
|
+
const debug_1 = __importDefault(require("debug"));
|
|
19
|
+
const events_1 = require("events");
|
|
20
|
+
const fields_1 = __importDefault(require("./fields"));
|
|
21
|
+
const productIds_1 = require("./productIds");
|
|
22
|
+
const constants_1 = require("./constants");
|
|
23
|
+
const defaults = {
|
|
24
|
+
productIds: productIds_1.productIds,
|
|
25
|
+
fields: fields_1.default,
|
|
26
|
+
defaultUnitId: 'victronDevice',
|
|
27
|
+
mainBatt: 'house',
|
|
28
|
+
auxBatt: 'starter',
|
|
29
|
+
bmv: 'bmv',
|
|
30
|
+
solar: 'solar'
|
|
31
|
+
};
|
|
32
|
+
// A VE.Direct block is well under 1 KB. If far more than that accumulates
|
|
33
|
+
// without a Checksum line, the stream is malformed or the sentinel was lost;
|
|
34
|
+
// the cache is dropped rather than left to grow unbounded from device input.
|
|
35
|
+
const MAX_CACHE_LENGTH = 8192;
|
|
36
|
+
class VEDirectParser extends events_1.EventEmitter {
|
|
37
|
+
options;
|
|
38
|
+
fields;
|
|
39
|
+
debug;
|
|
40
|
+
line;
|
|
41
|
+
data;
|
|
42
|
+
cache;
|
|
43
|
+
sum;
|
|
44
|
+
constructor(opts) {
|
|
45
|
+
super();
|
|
46
|
+
this.options = Object.assign({}, defaults, opts || {});
|
|
47
|
+
this.fields = this.options.fields;
|
|
48
|
+
this.debug = (0, debug_1.default)('signalk-vedirect-parser');
|
|
49
|
+
this.line = [];
|
|
50
|
+
this.data = {};
|
|
51
|
+
this.cache = '';
|
|
52
|
+
this.sum = 0;
|
|
53
|
+
}
|
|
54
|
+
addChunk(buf, connectionIndex) {
|
|
55
|
+
if (!Buffer.isBuffer(buf)) {
|
|
56
|
+
this.warn('addChunk: incoming data is not a buffer: ' + typeof buf);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const chunk = buf.toString('ascii');
|
|
60
|
+
buf.forEach((b) => {
|
|
61
|
+
this.sum += b;
|
|
62
|
+
});
|
|
63
|
+
this.cache += chunk;
|
|
64
|
+
if (chunk.toLowerCase().includes('checksum')) {
|
|
65
|
+
// Last line of block. Verify checksum of block in cache and parse
|
|
66
|
+
// line-by-line if checksum is correct.
|
|
67
|
+
this._verifyCacheAndParse(connectionIndex);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (this.cache.length > MAX_CACHE_LENGTH) {
|
|
71
|
+
this.warn(`block exceeded ${MAX_CACHE_LENGTH} bytes without a Checksum line; discarding`);
|
|
72
|
+
this.cache = '';
|
|
73
|
+
this.sum = 0;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
parse(line) {
|
|
77
|
+
if (typeof line !== 'string') {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this.line = line.trim().split('\t');
|
|
81
|
+
this._parse();
|
|
82
|
+
}
|
|
83
|
+
set(key, value) {
|
|
84
|
+
this.data[key] = value;
|
|
85
|
+
this.emit('change', Object.assign({}, this.data));
|
|
86
|
+
this.emit('set', { key, value });
|
|
87
|
+
}
|
|
88
|
+
get(key) {
|
|
89
|
+
return this.data[key];
|
|
90
|
+
}
|
|
91
|
+
unset(key) {
|
|
92
|
+
if (!Object.prototype.hasOwnProperty.call(this.data, key)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
this.debug(`Unsetting ${key}`);
|
|
96
|
+
this.emit('change', Object.assign({}, this.data));
|
|
97
|
+
this.emit('unset', key);
|
|
98
|
+
delete this.data[key];
|
|
99
|
+
}
|
|
100
|
+
getData() {
|
|
101
|
+
return Object.assign({}, this.data);
|
|
102
|
+
}
|
|
103
|
+
_verifyCacheAndParse(connectionIndex) {
|
|
104
|
+
const conn = this.options.vedirect?.[connectionIndex];
|
|
105
|
+
// Verify checksum unless ignoreChecksum is explicitly true.
|
|
106
|
+
if (conn?.ignoreChecksum !== true && this.sum % 256 !== 0) {
|
|
107
|
+
this.warn(`block checksum doesn't equal 0: ${this.sum % 256}`);
|
|
108
|
+
this.cache = '';
|
|
109
|
+
this.sum = 0;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
this.cache
|
|
113
|
+
.trim()
|
|
114
|
+
.split('\n')
|
|
115
|
+
.map((line) => line.trim())
|
|
116
|
+
.filter((line) => line !== '')
|
|
117
|
+
.forEach((line) => {
|
|
118
|
+
this.line = line.split('\t');
|
|
119
|
+
this._parse();
|
|
120
|
+
});
|
|
121
|
+
this.cache = '';
|
|
122
|
+
this.sum = 0;
|
|
123
|
+
this.generateDelta(connectionIndex);
|
|
124
|
+
}
|
|
125
|
+
_parse() {
|
|
126
|
+
if (!Array.isArray(this.line) || this.line.length !== 2) {
|
|
127
|
+
this.warn('_parse() called on invalid line: ' +
|
|
128
|
+
JSON.stringify({ line: this.line }));
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const rawKey = this.line[0];
|
|
132
|
+
const rawData = this.line[1];
|
|
133
|
+
if (rawKey === undefined || rawData === undefined) {
|
|
134
|
+
this.warn('Data is NULL, ignoring');
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const fieldKey = String(rawKey).toUpperCase();
|
|
138
|
+
const field = this.fields[fieldKey];
|
|
139
|
+
if (!field || typeof field !== 'object') {
|
|
140
|
+
this.warn(`No field definition for: ${fieldKey}, ignoring`);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const converted = typeof field.value === 'function' ? field.value(rawData, this) : rawData;
|
|
144
|
+
// undefined skips the field, leaving any prior value untouched; null is
|
|
145
|
+
// stored as an explicit null so it clears the value downstream in the
|
|
146
|
+
// delta (see FieldValue). Only undefined means "no update".
|
|
147
|
+
if (converted !== undefined) {
|
|
148
|
+
this.set(field.name, { ...field, value: converted });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
getAlarmReason(alarmReason) {
|
|
152
|
+
switch (parseInt(String(alarmReason), 10)) {
|
|
153
|
+
case 1:
|
|
154
|
+
return 'Low voltage';
|
|
155
|
+
case 2:
|
|
156
|
+
return 'High voltage';
|
|
157
|
+
case 4:
|
|
158
|
+
return 'Low state-of-charge';
|
|
159
|
+
case 8:
|
|
160
|
+
return 'Low starter voltage';
|
|
161
|
+
case 16:
|
|
162
|
+
return 'High starter voltage';
|
|
163
|
+
case 32:
|
|
164
|
+
return 'Low temperature';
|
|
165
|
+
case 64:
|
|
166
|
+
return 'High temperature';
|
|
167
|
+
case 128:
|
|
168
|
+
return 'Mid voltage';
|
|
169
|
+
case 256:
|
|
170
|
+
return 'Overload';
|
|
171
|
+
case 512:
|
|
172
|
+
return 'DC ripple';
|
|
173
|
+
case 1024:
|
|
174
|
+
return 'Low V AC out';
|
|
175
|
+
case 2048:
|
|
176
|
+
return 'High V AC out';
|
|
177
|
+
default:
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
getErrorString(err) {
|
|
182
|
+
switch (parseInt(String(err), 10)) {
|
|
183
|
+
case 2:
|
|
184
|
+
return 'Battery voltage too high';
|
|
185
|
+
case 17:
|
|
186
|
+
return 'Charger temperature too high';
|
|
187
|
+
case 18:
|
|
188
|
+
return 'Charger overcurrent';
|
|
189
|
+
// Can be ignored according to victron protocol
|
|
190
|
+
// case 19:
|
|
191
|
+
// return 'Charger current reversed'
|
|
192
|
+
case 20:
|
|
193
|
+
return 'Bulk time limit exceeded';
|
|
194
|
+
// Can be ignored according to victron protocol
|
|
195
|
+
// case 21:
|
|
196
|
+
// return 'Current sensor issue (sensor bias/sensor broken)'
|
|
197
|
+
case 26:
|
|
198
|
+
return 'Terminals overheated';
|
|
199
|
+
case 33:
|
|
200
|
+
return 'Input voltage too high (solar panel)';
|
|
201
|
+
case 34:
|
|
202
|
+
return 'Input current too high (solar panel)';
|
|
203
|
+
case 38:
|
|
204
|
+
return 'Input shutdown (due to excessive battery voltage)';
|
|
205
|
+
case 116:
|
|
206
|
+
return 'Factory calibration data lost';
|
|
207
|
+
case 117:
|
|
208
|
+
return 'Invalid/incompatible firmware';
|
|
209
|
+
case 119:
|
|
210
|
+
return 'User settings invalid';
|
|
211
|
+
default:
|
|
212
|
+
return undefined;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
getMode(mode) {
|
|
216
|
+
switch (parseInt(String(mode), 10)) {
|
|
217
|
+
case 2:
|
|
218
|
+
return 'on';
|
|
219
|
+
case 4:
|
|
220
|
+
return 'off';
|
|
221
|
+
case 5:
|
|
222
|
+
return 'eco';
|
|
223
|
+
default:
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
getStateOfOperation(cs) {
|
|
228
|
+
switch (parseInt(String(cs), 10)) {
|
|
229
|
+
case 0:
|
|
230
|
+
return 'off';
|
|
231
|
+
case 1:
|
|
232
|
+
return 'low power';
|
|
233
|
+
case 2:
|
|
234
|
+
return 'fault';
|
|
235
|
+
case 3:
|
|
236
|
+
return 'bulk';
|
|
237
|
+
case 4:
|
|
238
|
+
return 'absorption';
|
|
239
|
+
case 5:
|
|
240
|
+
return 'float';
|
|
241
|
+
case 9:
|
|
242
|
+
return 'inverting';
|
|
243
|
+
default:
|
|
244
|
+
return undefined;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
getTrackerOperationMode(mppt) {
|
|
248
|
+
switch (parseInt(String(mppt), 10)) {
|
|
249
|
+
case 0:
|
|
250
|
+
return 'off';
|
|
251
|
+
case 1:
|
|
252
|
+
return 'voltage or current limited';
|
|
253
|
+
case 2:
|
|
254
|
+
return 'mpp tracker active';
|
|
255
|
+
default:
|
|
256
|
+
return undefined;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
getProductLongname(pid) {
|
|
260
|
+
let key = String(pid);
|
|
261
|
+
if (!key.includes('0x')) {
|
|
262
|
+
key = `0x${key}`;
|
|
263
|
+
}
|
|
264
|
+
return this.options.productIds[key] ?? 'Unknown';
|
|
265
|
+
}
|
|
266
|
+
generateDelta(connectionIndex) {
|
|
267
|
+
const values = Object.keys(this.data)
|
|
268
|
+
.map((name) => {
|
|
269
|
+
const path = this.getPath(name, connectionIndex);
|
|
270
|
+
const entry = this.data[name];
|
|
271
|
+
if (path === null || entry === undefined) {
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
return { path, value: entry.value };
|
|
275
|
+
})
|
|
276
|
+
.filter((update) => update !== null);
|
|
277
|
+
if (values.length === 0) {
|
|
278
|
+
this.warn('No mutations in this delta');
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const delta = {
|
|
282
|
+
context: 'vessels.self',
|
|
283
|
+
updates: [
|
|
284
|
+
{
|
|
285
|
+
// Set the Signal K source ref as a bare string rather than a
|
|
286
|
+
// structured `source` object. signalk-server reads any `source.src`
|
|
287
|
+
// as an NMEA 2000 device address, so a VE.Direct delta carrying one
|
|
288
|
+
// would corrupt the server's `sources` tree with bogus
|
|
289
|
+
// `sources.*.n2k.pgns` nodes. A plain `$source` sidesteps that while
|
|
290
|
+
// keeping each connection individually addressable:
|
|
291
|
+
// `vedirect-signalk.0`, `vedirect-signalk.1`, ...
|
|
292
|
+
$source: `${constants_1.PLUGIN_ID}.${connectionIndex}`,
|
|
293
|
+
timestamp: new Date().toISOString(),
|
|
294
|
+
values
|
|
295
|
+
}
|
|
296
|
+
]
|
|
297
|
+
};
|
|
298
|
+
this.emit('delta', delta);
|
|
299
|
+
}
|
|
300
|
+
getPath(name, connectionIndex) {
|
|
301
|
+
const field = Object.values(this.fields).find((f) => f.name === name && f.path !== undefined);
|
|
302
|
+
if (!field?.path) {
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
const conn = this.options.vedirect?.[connectionIndex];
|
|
306
|
+
// On a solar charger, VE.Direct's V/I labels describe the charger's DC
|
|
307
|
+
// output rather than a battery, so those fields are reported under
|
|
308
|
+
// electrical.solar (via the field's solarCharger override) to avoid
|
|
309
|
+
// clashing with a battery monitor on the same bank.
|
|
310
|
+
const override = conn?.deviceType === 'Solar charger' ? field.solarCharger : undefined;
|
|
311
|
+
const path = override?.path ?? field.path;
|
|
312
|
+
const unitId = override?.unitId ?? field.unitId;
|
|
313
|
+
if (unitId === undefined) {
|
|
314
|
+
return path;
|
|
315
|
+
}
|
|
316
|
+
return path.replace('*', this.resolveUnitId(unitId, conn));
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Resolves a field's unit id to the configured device name. The four
|
|
320
|
+
* configurable units come from the connection; aux2Batt/inverter have no
|
|
321
|
+
* config slot and use defaultUnitId. The switch is exhaustive over UnitId,
|
|
322
|
+
* so adding a unit without handling it here is a compile error.
|
|
323
|
+
*/
|
|
324
|
+
resolveUnitId(unitId, conn) {
|
|
325
|
+
switch (unitId) {
|
|
326
|
+
case 'mainBatt':
|
|
327
|
+
return conn?.mainBatt || this.options.defaultUnitId;
|
|
328
|
+
case 'auxBatt':
|
|
329
|
+
return conn?.auxBatt || this.options.defaultUnitId;
|
|
330
|
+
case 'bmv':
|
|
331
|
+
return conn?.bmv || this.options.defaultUnitId;
|
|
332
|
+
case 'solar':
|
|
333
|
+
return conn?.solar || this.options.defaultUnitId;
|
|
334
|
+
case 'aux2Batt':
|
|
335
|
+
case 'inverter':
|
|
336
|
+
return this.options.defaultUnitId;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
warn(message) {
|
|
340
|
+
this.debug(`Warning: ${message}`);
|
|
341
|
+
this.emit('warn', message);
|
|
342
|
+
}
|
|
343
|
+
error(err) {
|
|
344
|
+
this.debug(`Error: ${err.message}`);
|
|
345
|
+
this.emit('error', err);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
exports.VEDirectParser = VEDirectParser;
|
|
349
|
+
exports.default = VEDirectParser;
|
|
350
|
+
//# sourceMappingURL=Parser.js.map
|