signalk-racer 0.9.2 → 0.9.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.
@@ -91,12 +91,13 @@ The plugin supports **partial line configuration**: you can set just one end (po
91
91
 
92
92
  ### 📮 API Endpoints
93
93
 
94
- | Method | Endpoint | Description |
95
- |--------|------------------------------------------|------------------------------------------------------------------------------------------------------|
96
- | `GET` | `/plugins/signalk-racer/startline/port` | Get the last known **port (pin)** end position |
97
- | `PUT` | `/plugins/signalk-racer/startline/port` | Set the **port (pin)** end of the start line to the current position of the boat plus the bow offset |
98
- | `GET` | `/plugins/signalk-racer/startline/stb` | Get the last known **starboard (boat)** end position |
99
- | `PUT` | `/plugins/signalk-racer/startline/stb` | Set the **starboard (boat)** end of the line to the current position of the boat plus the bow offset |
94
+ | Method | Endpoint | Description |
95
+ |--------|-----------------------------------------|------------------------------------------------------------------------------------------------------|
96
+ | `GET` | `/plugins/signalk-racer/startline/port` | Get the last known **port (pin)** end position |
97
+ | `PUT` | `/plugins/signalk-racer/startline/port` | Set the **port (pin)** end of the start line to the current position of the boat plus the bow offset |
98
+ | `GET` | `/plugins/signalk-racer/startline/stb` | Get the last known **starboard (boat)** end position |
99
+ | `PUT` | `/plugins/signalk-racer/startline/stb` | Set the **starboard (boat)** end of the line to the current position of the boat plus the bow offset |
100
+ | `PUT` | `/plugins/signalk-racer/timeToStart` | Set the **timeToStart** in seconds and receive the current **distanceToLine** |
100
101
 
101
102
 
102
103
  ## 🔄 Dependencies
package/ReleaseNotes.md CHANGED
@@ -4,4 +4,8 @@
4
4
  + formating for the README.TXT
5
5
  ## 0.9.2 Set Start Line
6
6
  + Added API to set the start line
7
- + Added webapp to call start line API
7
+ + Added webapp to call start line API
8
+ ## 0.9.3 KIP racer-timer integration
9
+ + added timeToStart API
10
+ ## 0.9.4 Trivial rename
11
+ + Renamed README.md for npmjs
package/index.js CHANGED
@@ -93,7 +93,7 @@ module.exports = (app) => {
93
93
  const plugin = {
94
94
  id: 'signalk-racer',
95
95
  name: 'SignalK Racing Plugin',
96
- start: (options, restartPlugin) => {
96
+ start: (options) => {
97
97
  if (!options.startLinePort || !options.startLineStb) {
98
98
  app.error('Missing waypoint names: startLinePort and/or startLineStb not configured.');
99
99
  return;
@@ -178,6 +178,32 @@ module.exports = (app) => {
178
178
  return bow;
179
179
  }
180
180
 
181
+ plugin.setTimeToStart = async (req, res) => {
182
+ try {
183
+ const body = req.body;
184
+ if (!body || typeof body.timeToStart !== 'number') {
185
+ res.status(400).json({ error: 'Missing or invalid `timeToStart`' });
186
+ return;
187
+ }
188
+
189
+ const timeToStart = body.timeToStart; // value in seconds, or whatever unit you agree on
190
+ app.debug(`Setting timeToStart to ${timeToStart}`);
191
+
192
+ sendDeltas([
193
+ {path: 'navigation.racing.timeToStart', value: timeToStart},
194
+ ]);
195
+
196
+ res.json({
197
+ message: 'OK',
198
+ timeToStart,
199
+ distanceToLine: state.distanceToLine ? state.distanceToLine : null,
200
+ });
201
+ } catch (err) {
202
+ app.error('Failed to set time to start:', err);
203
+ res.status(500).json({ error: 'Failed to set time to start' });
204
+ }
205
+ }
206
+
181
207
  plugin.setStartLineEnd = async (req, res) => {
182
208
  try {
183
209
  const end = req.params.end; // "port" or "stb"
@@ -584,6 +610,7 @@ module.exports = (app) => {
584
610
  router.get('/startline/port', (req, res) => res.json(state.startLine ? state.startLine.port : null));
585
611
  router.get('/startline/stb', (req, res) => res.json(state.startLine ? state.startLine.stb : null));
586
612
  router.put('/startline/:end', plugin.setStartLineEnd);
613
+ router.put('/timeToStart', plugin.setTimeToStart);
587
614
  },
588
615
 
589
616
  getOpenApi: () => require('./openapi.json'),
package/openapi.json CHANGED
@@ -8,13 +8,14 @@
8
8
  "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
9
9
  }
10
10
  },
11
-
12
11
  "paths": {
13
12
  "/startline/port": {
14
13
  "get": {
15
14
  "summary": "Set the port end of the start line",
16
15
  "responses": {
17
- "200": { "description": "Port end set" }
16
+ "200": {
17
+ "description": "Port end set"
18
+ }
18
19
  }
19
20
  }
20
21
  },
@@ -23,7 +24,58 @@
23
24
  "summary": "Set the starboard end of the start line",
24
25
  "description": "Set the starboard end of the start line to the boats position plus the bow offset.",
25
26
  "responses": {
26
- "200": { "description": "Starboard end set" }
27
+ "200": {
28
+ "description": "Starboard end set"
29
+ }
30
+ }
31
+ }
32
+ },
33
+ "/timeToStart": {
34
+ "put": {
35
+ "summary": "Set time to start",
36
+ "description": "Update the countdown timer value used for start line calculations.",
37
+ "requestBody": {
38
+ "required": true,
39
+ "content": {
40
+ "application/json": {
41
+ "schema": {
42
+ "type": "object",
43
+ "properties": {
44
+ "timeToStart": {
45
+ "type": "number",
46
+ "description": "Time to start in seconds"
47
+ }
48
+ },
49
+ "required": [
50
+ "timeToStart"
51
+ ]
52
+ }
53
+ }
54
+ }
55
+ },
56
+ "responses": {
57
+ "200": {
58
+ "description": "Time to start set",
59
+ "content": {
60
+ "application/json": {
61
+ "schema": {
62
+ "type": "object",
63
+ "properties": {
64
+ "message": { "type": "string" },
65
+ "timeToStart": {
66
+ "type": "number",
67
+ "description": "Time to start in seconds"
68
+ },
69
+ "distanceToLine": {
70
+ "type": "number",
71
+ "description": "Distance to the line in meters"
72
+ }
73
+ },
74
+ "required": ["message", "timeToStart"]
75
+ }
76
+ }
77
+ }
78
+ }
27
79
  }
28
80
  }
29
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "signalk-racer",
3
- "version": "0.9.2",
3
+ "version": "0.9.4",
4
4
  "description": "Signalk plugin to calculate values of interest to sail racers: such as Distance to Line; Next leg TWA.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/public/index.html CHANGED
@@ -6,7 +6,7 @@
6
6
  <style>
7
7
  body {
8
8
  font-family: sans-serif;
9
- max-width: 600px;
9
+ max-width: 100%;
10
10
  margin: 3em auto;
11
11
  text-align: center;
12
12
  }
@@ -25,8 +25,9 @@
25
25
  </head>
26
26
  <body>
27
27
  <h1>Set Start Line Ends</h1>
28
- <button onclick="setEnd('port')">Set Port End (Pin)</button>
29
- <button onclick="setEnd('stb')">Set Starboard End (Boat)</button>
28
+ <div id="buttons">
29
+ <button onclick="setEnd('port')">Set Port End (Pin)</button><button onclick="setEnd('stb')">Set Starboard End (Boat)</button>
30
+ </div>
30
31
  <div id="status"></div>
31
32
 
32
33
  <script>