Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Add NMEA stream handling to Course API. #1750

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7975844
Add NMEA stream handling.
panaaj Jun 7, 2024
fa36734
use nextPoint.position
panaaj Jun 8, 2024
c9ff917
Asynchronously handle delta processing.
panaaj Jun 8, 2024
f4e8960
Add `force` param to clear destination.
panaaj Jun 10, 2024
a2fa0b4
Address review comments.
panaaj Jun 18, 2024
32de27b
handle catch.
panaaj Jun 18, 2024
ff84423
Add endpoint for clearing Command Source.
panaaj Jun 19, 2024
3d4a457
Replace delatHandler with subscription.
panaaj Jun 19, 2024
04cdf6d
add `apiMode` param to clearDestination interface method.
panaaj Jun 19, 2024
61c49c7
fix for arrivalCircle test failure.
panaaj Jun 20, 2024
425c21e
chore: formatting
panaaj Jun 20, 2024
035ef38
Add Course API config settings.
panaaj Nov 2, 2024
3bd5dff
remove erroneous typing
panaaj Nov 2, 2024
72023cc
Merge branch 'm1' into course-delta-handler
panaaj Nov 5, 2024
6e1b8cf
Update types
panaaj Nov 5, 2024
dbec29f
chore: formatting
panaaj Nov 5, 2024
1c6ebad
Add courseApi to /skServer/settings response.
panaaj Nov 5, 2024
34e0326
update deprecated types
panaaj Nov 5, 2024
ac35502
update docs
panaaj Nov 12, 2024
aedcdc0
Only persist destination for API requests.
panaaj Nov 12, 2024
b868b5c
course.nextPoint delta source set to cmdSource.id
panaaj Nov 13, 2024
b748d6b
refactor: improve sk types
tkurki Nov 13, 2024
5db9df5
refactor: sourceChange => isSourceChange
tkurki Nov 13, 2024
4797145
refactor: use SourceRef type and naming
tkurki Nov 13, 2024
fe4e84c
refactor: extract isCurrentCmdSource, naming
tkurki Nov 13, 2024
3fc9698
refactor: simplify
tkurki Nov 13, 2024
8825cfe
refactor: add isAPICmdSource
tkurki Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 76 additions & 6 deletions docs/src/develop/rest-api/course_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

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_.

Additionally, the Course API persists course information on the server to ensure data is not lost in the event of a server restart.

Client applications use `HTTP` requests (`PUT`, `GET`,`DELETE`) to perform operations and retrieve course data.

Additionally, the Course API persists course information on the server to ensure data is not lost in the event of a server restart.
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.

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

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

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.


#### 1. Operation: Navigate to a location _(lat, lon)_

_Example response:_
Expand Down Expand Up @@ -235,19 +238,86 @@ _Example response:_

## Cancelling navigation

To cancel the current course navigation and clear the course data
To cancel the current course navigation and clear the course data.

```typescript
HTTP DELETE 'http://hostname:3000/signalk/v2/api/vessels/self/navigation/course/'
HTTP DELETE 'http://hostname:3000/signalk/v2/api/vessels/self/navigation/course'
```

_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._

To ignore destination data from NMEA sources see [Configuration](#configuration) below.



## Configuration

The default configuration of the Course API will accept destination information from both API requests and NMEA stream data sources.

For NMEA sources, Course API monitors the the following Signal K paths populated by both the `nmea0183-to-signalk` and `n2k-to-signalk` plugins:
- _navigation.courseRhumbline.nextPoint.position_
- _navigation.courseGreatCircle.nextPoint.position_

HTTP requests are prioritised over NMEA data sources, so making an API request will overwrite the destination information received from and NMEA source.

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.


#### Ignoring NMEA Destination Information

The Course API can be configured to ignore destination data in the NMEA stream by enabling `apiOnly` mode.

In `apiOnly` mode destination information can only be set / cleared using HTTP API requests.

- **`apiOnly` Mode = Off _(default)_**

- Destination data is accepted from both _HTTP API_ and _NMEA_ sources
- Setting a destination using the HTTP API will override the destination data received via NMEA
- When clearing the destination using the HTTP API, if destination data is received via NMEA this will then be used as the active destination.
- To clear destination sourced via NMEA, clear the destination on the source device.

- **`apiOnly` Mode = On**

- Course operations are only accepted via the HTTP API
- NMEA stream data is ignored
- Switching to `apiOnly` mode when an NMEA sourced destination is active will clear the destination.


#### Retrieving Course API Configuration

To retrieve the Course API configuration settings, submit a HTTP `GET` request to `/signalk/v2/api/vessels/self/navigation/course/_config`.

```typescript
HTTP GET 'http://hostname:3000/signalk/v2/api/vessels/self/navigation/course/_config'
```

_Example response:_
```JSON
{
"apiOnly": false
}
```

#### Enable / Disable `apiOnly` mode

To enable `apiOnly` mode, submit a HTTP `POST` request to `/signalk/v2/api/vessels/self/navigation/course/_config/apiOnly`.

_Enable apiOnly mode:_
```typescript
HTTP POST 'http://hostname:3000/signalk/v2/api/vessels/self/navigation/course/_config/apiOnly'
```

To disable `apiOnly` mode, submit a HTTP `DELETE` request to `/signalk/v2/api/vessels/self/navigation/course/_config/apiOnly`.

_Disable apiOnly mode:_
```typescript
HTTP DELETE 'http://hostname:3000/signalk/v2/api/vessels/self/navigation/course/_config/apiOnly'
```

---

## Course Calculations

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

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



8 changes: 8 additions & 0 deletions packages/server-api/src/deltas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ export type Update = {
$source?: SourceRef
} & ({ values: PathValue[] } | { meta: Meta[] }) // require either values or meta or both

export function hasValues(u: Update): u is Update & { values: PathValue[] } {
return 'values' in u && Array.isArray(u.values)
}

export function hasMeta(u: Update): u is Update & { meta: Meta[] } {
return 'meta' in u && Array.isArray(u.meta)
}

// Update delta
export interface PathValue {
path: Path
Expand Down
Loading
Loading