Skip to content

Commit 83a0666

Browse files
panaajtkurki
authored andcommitted
feature : add NMEA to course API integration
- add the ability to control command source to course API - handle NMEA0183 and NMEA2000 messages that contain nextPoint data to update course API data structures
1 parent 644c88d commit 83a0666

File tree

7 files changed

+525
-89
lines changed

7 files changed

+525
-89
lines changed

docs/src/develop/rest-api/course_api.md

+76-6
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
The _Course API_ provides common course operations under the path `/signalk/v2/api/vessels/self/navigation/course` ensuring that all related Signal K data model values are maintained and consistent. This provides a set of data that can be confidently used for _course calculations_ and _autopilot operation_.
77

8+
Additionally, the Course API persists course information on the server to ensure data is not lost in the event of a server restart.
9+
810
Client applications use `HTTP` requests (`PUT`, `GET`,`DELETE`) to perform operations and retrieve course data.
911

10-
Additionally, the Course API persists course information on the server to ensure data is not lost in the event of a server restart.
12+
The Course API also listens for destination information in the NMEA stream and will set / clear the destination accordingly _(e.g. NMEA0183 RMB sentence, NMEA2000 PGN 129284)_. See [Configuration](#Configuration) for more details.
1113

1214
_Note: You can view the _Course API_ OpenAPI definition in the Admin UI (Documentation => OpenApi)._
1315

@@ -125,6 +127,7 @@ HTTP GET 'http://hostname:3000/signalk/v2/api/vessels/self/navigation/course'
125127

126128
The contents of the response will reflect the operation used to set the current course. The `nextPoint` & `previousPoint` sections will always contain values but `activeRoute` will only contain values when a route is being followed.
127129

130+
128131
#### 1. Operation: Navigate to a location _(lat, lon)_
129132

130133
_Example response:_
@@ -235,19 +238,86 @@ _Example response:_
235238

236239
## Cancelling navigation
237240

238-
To cancel the current course navigation and clear the course data
241+
To cancel the current course navigation and clear the course data.
239242

240243
```typescript
241-
HTTP DELETE 'http://hostname:3000/signalk/v2/api/vessels/self/navigation/course/'
244+
HTTP DELETE 'http://hostname:3000/signalk/v2/api/vessels/self/navigation/course'
245+
```
246+
247+
_Note: This operation will NOT change the destination information coming from the NMEA input stream! If the NMEA source device is still emitting destination data this will reappear as the current destination._
248+
249+
To ignore destination data from NMEA sources see [Configuration](#configuration) below.
250+
251+
252+
253+
## Configuration
254+
255+
The default configuration of the Course API will accept destination information from both API requests and NMEA stream data sources.
256+
257+
For NMEA sources, Course API monitors the the following Signal K paths populated by both the `nmea0183-to-signalk` and `n2k-to-signalk` plugins:
258+
- _navigation.courseRhumbline.nextPoint.position_
259+
- _navigation.courseGreatCircle.nextPoint.position_
260+
261+
HTTP requests are prioritised over NMEA data sources, so making an API request will overwrite the destination information received from and NMEA source.
262+
263+
Note: when the destination cleared using an API request, if the NMEA stream is emitting an active destination position, this will then be used by the Course API to populate course data.
264+
265+
266+
#### Ignoring NMEA Destination Information
267+
268+
The Course API can be configured to ignore destination data in the NMEA stream by enabling `apiOnly` mode.
269+
270+
In `apiOnly` mode destination information can only be set / cleared using HTTP API requests.
271+
272+
- **`apiOnly` Mode = Off _(default)_**
273+
274+
- Destination data is accepted from both _HTTP API_ and _NMEA_ sources
275+
- Setting a destination using the HTTP API will override the destination data received via NMEA
276+
- When clearing the destination using the HTTP API, if destination data is received via NMEA this will then be used as the active destination.
277+
- To clear destination sourced via NMEA, clear the destination on the source device.
278+
279+
- **`apiOnly` Mode = On**
280+
281+
- Course operations are only accepted via the HTTP API
282+
- NMEA stream data is ignored
283+
- Switching to `apiOnly` mode when an NMEA sourced destination is active will clear the destination.
284+
285+
286+
#### Retrieving Course API Configuration
287+
288+
To retrieve the Course API configuration settings, submit a HTTP `GET` request to `/signalk/v2/api/vessels/self/navigation/course/_config`.
289+
290+
```typescript
291+
HTTP GET 'http://hostname:3000/signalk/v2/api/vessels/self/navigation/course/_config'
292+
```
293+
294+
_Example response:_
295+
```JSON
296+
{
297+
"apiOnly": false
298+
}
299+
```
300+
301+
#### Enable / Disable `apiOnly` mode
302+
303+
To enable `apiOnly` mode, submit a HTTP `POST` request to `/signalk/v2/api/vessels/self/navigation/course/_config/apiOnly`.
304+
305+
_Enable apiOnly mode:_
306+
```typescript
307+
HTTP POST 'http://hostname:3000/signalk/v2/api/vessels/self/navigation/course/_config/apiOnly'
308+
```
309+
310+
To disable `apiOnly` mode, submit a HTTP `DELETE` request to `/signalk/v2/api/vessels/self/navigation/course/_config/apiOnly`.
311+
312+
_Disable apiOnly mode:_
313+
```typescript
314+
HTTP DELETE 'http://hostname:3000/signalk/v2/api/vessels/self/navigation/course/_config/apiOnly'
242315
```
243316

244-
---
245317

246318
## Course Calculations
247319

248320
Whilst not performing course calculations, the _Course API_ defines the paths to accommodate the values calculated during course navigation.
249321

250322
Click [here](./course_calculations.md) for details.
251323

252-
253-

packages/server-admin-ui/src/views/ServerConfig/Settings.js

+43
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class ServerSettings extends Component {
3636
}
3737
this.fetchSettings = fetchSettings.bind(this)
3838
this.handleChange = this.handleChange.bind(this)
39+
this.handleCourseApiChange = this.handleCourseApiChange.bind(this)
3940
this.handleOptionChange = this.handleOptionChange.bind(this)
4041
this.handleInterfaceChange = this.handleInterfaceChange.bind(this)
4142
this.handleSaveSettings = this.handleSaveSettings.bind(this)
@@ -53,6 +54,15 @@ class ServerSettings extends Component {
5354
this.setState({ [event.target.name]: value })
5455
}
5556

57+
handleCourseApiChange(event) {
58+
const value =
59+
event.target.type === 'checkbox'
60+
? event.target.checked
61+
: event.target.value
62+
this.state.courseApi[event.target.name] = value
63+
this.setState({ courseApi: this.state.courseApi })
64+
}
65+
5666
handleOptionChange(event) {
5767
const value =
5868
event.target.type === 'checkbox'
@@ -303,6 +313,39 @@ class ServerSettings extends Component {
303313
</FormText>
304314
</Col>
305315
</FormGroup>
316+
<FormGroup row>
317+
<Col md="2">
318+
<Label>
319+
API Only Mode
320+
<br />
321+
<i>(Course API)</i>
322+
</Label>
323+
</Col>
324+
<Col>
325+
<FormGroup check>
326+
<Label className="switch switch-text switch-primary">
327+
<Input
328+
type="checkbox"
329+
name="apiOnly"
330+
id="apiOnly"
331+
className="switch-input"
332+
onChange={this.handleCourseApiChange}
333+
checked={this.state.courseApi.apiOnly}
334+
/>
335+
<span
336+
className="switch-label"
337+
data-on="On"
338+
data-off="Off"
339+
/>
340+
<span className="switch-handle" />
341+
</Label>
342+
<FormText color="muted">
343+
Accept course operations only via HTTP requests.
344+
Destination data from NMEA sources is not used.
345+
</FormText>
346+
</FormGroup>
347+
</Col>
348+
</FormGroup>
306349
</Form>
307350
</CardBody>
308351
<CardFooter>

0 commit comments

Comments
 (0)