@meri-imperiumi/signalk-triplogger 1.0.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/.eslintrc.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "airbnb-base"
3
+ }
@@ -0,0 +1,11 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: npm
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ versioning-strategy: increase-if-necessary
8
+ - package-ecosystem: github-actions
9
+ directory: "/"
10
+ schedule:
11
+ interval: weekly
@@ -0,0 +1,30 @@
1
+ name: Publish Node.js Package
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "*"
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v2.3.4
13
+ - uses: actions/setup-node@v2.1.5
14
+ with:
15
+ node-version: 12
16
+ - run: npm install
17
+ - run: npm test
18
+
19
+ publish-npm:
20
+ needs: build
21
+ runs-on: ubuntu-latest
22
+ steps:
23
+ - uses: actions/checkout@v2.3.4
24
+ - uses: actions/setup-node@v2.1.5
25
+ with:
26
+ node-version: 12
27
+ registry-url: https://registry.npmjs.org/
28
+ - run: npm publish
29
+ env:
30
+ NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
@@ -0,0 +1,29 @@
1
+ name: Node CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ name: Run test suite
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ matrix:
11
+ node-version: [12.x]
12
+ steps:
13
+ - uses: actions/checkout@v2.3.4
14
+ - name: Use Node.js ${{ matrix.node-version }}
15
+ uses: actions/setup-node@v2.1.5
16
+ with:
17
+ node-version: ${{ matrix.node-version }}
18
+ - run: npm install
19
+ - run: npm test
20
+ env:
21
+ CI: true
22
+ merge-me:
23
+ name: Auto-merge dependency updates
24
+ needs: test
25
+ runs-on: ubuntu-latest
26
+ steps:
27
+ - uses: ridedott/merge-me-action@v2.9.103
28
+ with:
29
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 meri-imperiumi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # signalk-triplogger
2
+
3
+ This plugin keeps automatic track of the distance traveled on the current trip. The distance tracked is based on vessel GPS positions, so it tracks distance over ground, not distance over water like traditional paddlewheel logs.
4
+
5
+ The plugin monitors `vessel.state` as set by the [signalk-autostate](https://github.com/meri-imperiumi/signalk-autostate) plugin. Trip recording ends when vessel is detected as anchored or moored, and when vessel again gets under way, the trip log is reset to 0NM.
6
+
7
+ ## Changes
8
+
9
+ * 1.0.0 (February 18th 2022)
10
+ - Initial version, logging in-memory only
package/index.js ADDED
@@ -0,0 +1,149 @@
1
+ const { Point } = require('where');
2
+
3
+ module.exports = (app) => {
4
+ const plugin = {};
5
+ let unsubscribes = [];
6
+ const log = {
7
+ trip: 0,
8
+ inTrip: false,
9
+ lastPosition: null,
10
+ };
11
+
12
+ plugin.id = 'signalk-triplogger';
13
+ plugin.name = 'Trip logger';
14
+ plugin.description = 'Log the length of the current trip';
15
+ const setStatus = app.setPluginStatus || app.setProviderStatus;
16
+
17
+ plugin.start = (options) => {
18
+ const subscription = {
19
+ context: 'vessels.self',
20
+ subscribe: [
21
+ {
22
+ path: 'navigation.state',
23
+ period: 1000,
24
+ },
25
+ {
26
+ path: 'navigation.position',
27
+ period: options.update_interval || 10000,
28
+ },
29
+ ],
30
+ };
31
+
32
+ function resetTrip() {
33
+ const resetTime = new Date();
34
+ log.trip = 0;
35
+ log.inTrip = true;
36
+ app.handleMessage(plugin.id, {
37
+ context: `vessels.${app.selfId}`,
38
+ updates: [
39
+ {
40
+ source: {
41
+ label: plugin.id,
42
+ },
43
+ timestamp: (new Date().toISOString()),
44
+ values: [
45
+ {
46
+ path: 'navigation.trip.log',
47
+ value: 0,
48
+ },
49
+ {
50
+ path: 'navigation.trip.lastReset',
51
+ value: resetTime,
52
+ },
53
+ ],
54
+ },
55
+ ],
56
+ });
57
+ }
58
+
59
+ function appendTrip(distance) {
60
+ log.trip += distance;
61
+ app.handleMessage(plugin.id, {
62
+ context: `vessels.${app.selfId}`,
63
+ updates: [
64
+ {
65
+ source: {
66
+ label: plugin.id,
67
+ },
68
+ timestamp: (new Date().toISOString()),
69
+ values: [
70
+ {
71
+ path: 'navigation.trip.log',
72
+ value: log.trip,
73
+ },
74
+ ],
75
+ },
76
+ ],
77
+ });
78
+ }
79
+
80
+ app.subscriptionmanager.subscribe(
81
+ subscription,
82
+ unsubscribes,
83
+ (subscriptionError) => {
84
+ app.error(`Error:${subscriptionError}`);
85
+ },
86
+ (delta) => {
87
+ if (!delta.updates) {
88
+ return;
89
+ }
90
+ delta.updates.forEach((u) => {
91
+ if (!u.values) {
92
+ return;
93
+ }
94
+ u.values.forEach((v) => {
95
+ if (v.path === 'navigation.state') {
96
+ // Potential state change
97
+ if (v.value === 'sailing' || v.value === 'motoring') {
98
+ if (!log.inTrip) {
99
+ // New trip has started
100
+ resetTrip();
101
+ setStatus('New trip has started. Log reset');
102
+ }
103
+ // We can ignore switches between sailing and motoring inside trip
104
+ } else {
105
+ // Trip has ended, stop calculating log
106
+ log.inTrip = false;
107
+ }
108
+ return;
109
+ }
110
+ if (v.path === 'navigation.position') {
111
+ const newPosition = new Point(u.value.latitude, u.value.longitude);
112
+ if (log.lastPosition && log.inTrip) {
113
+ const distance = log.lastPosition.distanceTo(newPosition) * 1000;
114
+ appendTrip(distance);
115
+ }
116
+ const tripNm = log.trip / 1852;
117
+ if (log.inTrip) {
118
+ setStatus(`Trip under way, current distance ${tripNm}NM`);
119
+ } else {
120
+ setStatus(`Stopped. Last trip ${tripNm}NM`);
121
+ }
122
+ log.lastPosition = newPosition;
123
+ }
124
+ });
125
+ });
126
+ },
127
+ );
128
+
129
+ setStatus('Waiting for updates');
130
+ };
131
+
132
+ plugin.stop = () => {
133
+ unsubscribes.forEach((f) => f());
134
+ unsubscribes = [];
135
+ };
136
+
137
+ plugin.schema = {
138
+ type: 'object',
139
+ properties: {
140
+ update_interval: {
141
+ type: 'number',
142
+ default: 10000,
143
+ title: 'How often to update log, in milliseconds',
144
+ },
145
+ },
146
+ };
147
+
148
+ return plugin;
149
+ };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@meri-imperiumi/signalk-triplogger",
3
+ "version": "1.0.0",
4
+ "description": "Log the length of the current trip",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "lint": "eslint .",
8
+ "test": "npm run lint"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git://github.com/meri-imperiumi/signalk-triplogger.git"
13
+ },
14
+ "keywords": [
15
+ "signalk-node-server-plugin",
16
+ "signalk-category-utility"
17
+ ],
18
+ "signalk-plugin-enabled-by-default": true,
19
+ "author": "Henri Bergius <henri.bergius@iki.fi>",
20
+ "license": "MIT",
21
+ "bugs": {
22
+ "url": "https://github.com/meri-imperiumi/signalk-triplogger/issues"
23
+ },
24
+ "homepage": "https://github.com/meri-imperiumi/signalk-triplogger#readme",
25
+ "dependencies": {
26
+ "where": "^0.4.1"
27
+ },
28
+ "devDependencies": {
29
+ "eslint": "^7.14.0",
30
+ "eslint-config-airbnb-base": "^14.0.0",
31
+ "eslint-plugin-import": "^2.18.2"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ }
36
+ }