pypilot-autopilot-provider 1.0.0-beta.3
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/.prettierrc.json +5 -0
- package/CHANGELOG.md +17 -0
- package/LICENSE +201 -0
- package/README.md +30 -0
- package/package.json +37 -0
- package/plugin/index.d.ts +4 -0
- package/plugin/index.js +160 -0
- package/plugin/pypilot.d.ts +15 -0
- package/plugin/pypilot.js +242 -0
- package/plugin/sk-api.d.ts +45 -0
- package/plugin/sk-api.js +3 -0
package/.prettierrc.json
ADDED
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# CHANGELOG: PyPilot-Autopilot-Provider - Signal K plugin
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
## v1.0.0-beta.3
|
|
5
|
+
|
|
6
|
+
- Added support for manual steering when pilot is not engaged.
|
|
7
|
+
- Updated angle processing to use values in degrees from Signal K server interface.
|
|
8
|
+
|
|
9
|
+
## v1.0.0-beta.2
|
|
10
|
+
|
|
11
|
+
- Updated to align with [Signal K Server PR #1596](https://github.com/SignalK/signalk-server/pull/1596).
|
|
12
|
+
|
|
13
|
+
## v1.0.0-beta.1
|
|
14
|
+
|
|
15
|
+
- Initial beta release.
|
|
16
|
+
|
|
17
|
+
|
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 [yyyy] [name of copyright owner]
|
|
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
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Signal K PyPilot Autopilot Provider Plugin:
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
## About
|
|
5
|
+
|
|
6
|
+
Signal K server plugin for PyPilot that enables commands to be sent by Signal K client applications via the Autopilot API .
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## Requirements
|
|
10
|
+
|
|
11
|
+
- Signal K server that implements the `Autopilot API`
|
|
12
|
+
- `pypilot_web` process running on the PyPilot host
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## Configuration
|
|
16
|
+
|
|
17
|
+
The plugin communicates with PyPilot via the websocket connection provided by the `pypilot_web` process so you will need to ensure that it is running.
|
|
18
|
+
|
|
19
|
+
From the Signal K server `Admin` console:
|
|
20
|
+
- Select **Server** -> **Plugin Config**
|
|
21
|
+
|
|
22
|
+
- From the list of plugins select `Autopilot Provider(PyPilot)` to display the details screen.
|
|
23
|
+
|
|
24
|
+
- Enter the host name / ip address of the PyPilot host.
|
|
25
|
+
|
|
26
|
+
- Enter the port on which `pypilot_web` is listening _(default: 8000)_.
|
|
27
|
+
|
|
28
|
+
- To initiate connection **Enable** the plugin.
|
|
29
|
+
|
|
30
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pypilot-autopilot-provider",
|
|
3
|
+
"version": "1.0.0-beta.3",
|
|
4
|
+
"description": "PyPilot autopilot provider plugin for Signal K server.",
|
|
5
|
+
"main": "plugin/index.js",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"signalk-node-server-plugin",
|
|
8
|
+
"pypilot"
|
|
9
|
+
],
|
|
10
|
+
"repository": "https://github.com/panaaj/pypilot-autopilot-provider",
|
|
11
|
+
"author": "AdrianP",
|
|
12
|
+
"contributors": [
|
|
13
|
+
{
|
|
14
|
+
"name": "panaaj@hotmail.com"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"license": "Apache-20",
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"build-declaration": "tsc --declaration --allowJs false",
|
|
21
|
+
"watch": "npm run build -- -w",
|
|
22
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
23
|
+
"start": "npm run build -- -w",
|
|
24
|
+
"format": "prettier --write src/*"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"socket.io-client": "^4.4.1"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@signalk/server-api": "^2.3.0",
|
|
31
|
+
"@types/express": "^4.17.6",
|
|
32
|
+
"@types/node-fetch": "^2.5.6",
|
|
33
|
+
"prettier": "^2.5.1",
|
|
34
|
+
"typescript": "^4.5.4"
|
|
35
|
+
},
|
|
36
|
+
"signalk-plugin-enabled-by-default": false
|
|
37
|
+
}
|
package/plugin/index.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const pypilot_1 = require("./pypilot");
|
|
13
|
+
const CONFIG_SCHEMA = {
|
|
14
|
+
properties: {
|
|
15
|
+
pypilot: {
|
|
16
|
+
type: 'object',
|
|
17
|
+
title: 'PyPilot host details.',
|
|
18
|
+
description: 'Configure the PyPilot connection settings.',
|
|
19
|
+
properties: {
|
|
20
|
+
host: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
title: 'Host name / address',
|
|
23
|
+
default: 'localhost'
|
|
24
|
+
},
|
|
25
|
+
port: {
|
|
26
|
+
type: 'number',
|
|
27
|
+
title: 'Port number',
|
|
28
|
+
default: 8000
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const CONFIG_UISCHEMA = {};
|
|
35
|
+
module.exports = (server) => {
|
|
36
|
+
let subscriptions = []; // stream subscriptions
|
|
37
|
+
const plugin = {
|
|
38
|
+
id: 'pypilot-autopilot-provider',
|
|
39
|
+
name: 'Autopilot Provider (PyPilot)',
|
|
40
|
+
schema: () => CONFIG_SCHEMA,
|
|
41
|
+
uiSchema: () => CONFIG_UISCHEMA,
|
|
42
|
+
start: (options, restart) => {
|
|
43
|
+
doStartup(options);
|
|
44
|
+
},
|
|
45
|
+
stop: () => {
|
|
46
|
+
doShutdown();
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
let settings = {
|
|
50
|
+
pypilot: {
|
|
51
|
+
host: 'localhost',
|
|
52
|
+
port: 8000
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const doStartup = (options) => {
|
|
56
|
+
try {
|
|
57
|
+
server.debug(`${plugin.name} starting.......`);
|
|
58
|
+
if (options && options.pypilot) {
|
|
59
|
+
settings = options;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// save defaults if no options loaded
|
|
63
|
+
server.savePluginOptions(settings, () => {
|
|
64
|
+
server.debug(`Default configuration applied...`);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
server.debug(`Applied configuration: ${JSON.stringify(settings)}`);
|
|
68
|
+
// register as autopilot provider
|
|
69
|
+
const result = registerProvider();
|
|
70
|
+
const msg = !result ? `PyPilot` : `Provider not registered!`;
|
|
71
|
+
server.setPluginStatus(msg);
|
|
72
|
+
// initialise autopilot connection
|
|
73
|
+
initialise();
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
const msg = `Started with errors!`;
|
|
77
|
+
server.setPluginError(msg);
|
|
78
|
+
server.error('error: ' + error);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const doShutdown = () => {
|
|
82
|
+
server.debug(`${plugin.name} stopping.......`);
|
|
83
|
+
(0, pypilot_1.closePyPilot)();
|
|
84
|
+
server.debug('** Un-registering Update Handler(s) **');
|
|
85
|
+
subscriptions.forEach((b) => b());
|
|
86
|
+
subscriptions = [];
|
|
87
|
+
const msg = 'Stopped.';
|
|
88
|
+
server.setPluginStatus(msg);
|
|
89
|
+
};
|
|
90
|
+
const registerProvider = () => {
|
|
91
|
+
try {
|
|
92
|
+
server.registerAutopilotProvider({
|
|
93
|
+
getData: (deviceId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
94
|
+
return pypilot_1.apData;
|
|
95
|
+
}),
|
|
96
|
+
getState: (deviceId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
+
return pypilot_1.apData.state;
|
|
98
|
+
}),
|
|
99
|
+
setState: (state, deviceId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
100
|
+
(0, pypilot_1.apSetState)(state);
|
|
101
|
+
return;
|
|
102
|
+
}),
|
|
103
|
+
getMode: (deviceId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
104
|
+
return pypilot_1.apData.mode;
|
|
105
|
+
}),
|
|
106
|
+
setMode: (mode, deviceId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
107
|
+
return (0, pypilot_1.apSetMode)(mode);
|
|
108
|
+
}),
|
|
109
|
+
getTarget: (deviceId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
110
|
+
return pypilot_1.apData.target;
|
|
111
|
+
}),
|
|
112
|
+
setTarget: (value, deviceId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
return (0, pypilot_1.apSetTarget)(value);
|
|
114
|
+
}),
|
|
115
|
+
adjustTarget: (value, deviceId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
116
|
+
if (pypilot_1.apData.engaged) {
|
|
117
|
+
const t = typeof pypilot_1.apData.target !== 'number'
|
|
118
|
+
? 0 + value
|
|
119
|
+
: pypilot_1.apData.target + value;
|
|
120
|
+
(0, pypilot_1.apSetTarget)(t);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
(0, pypilot_1.apDodge)(value);
|
|
124
|
+
}
|
|
125
|
+
return;
|
|
126
|
+
}),
|
|
127
|
+
engage: (deviceId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
128
|
+
(0, pypilot_1.apSetState)('enabled');
|
|
129
|
+
return;
|
|
130
|
+
}),
|
|
131
|
+
disengage: (deviceId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
132
|
+
(0, pypilot_1.apSetState)('disabled');
|
|
133
|
+
return;
|
|
134
|
+
}),
|
|
135
|
+
tack: (direction, deviceId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
136
|
+
return (0, pypilot_1.apTack)(direction === 'port' ? true : false);
|
|
137
|
+
}),
|
|
138
|
+
gybe: (direction, deviceId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
139
|
+
throw new Error('Not implemented!');
|
|
140
|
+
}),
|
|
141
|
+
dodge: (value, deviceId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
142
|
+
if (value) {
|
|
143
|
+
(0, pypilot_1.apDodge)(value);
|
|
144
|
+
}
|
|
145
|
+
return;
|
|
146
|
+
})
|
|
147
|
+
}, pypilot_1.PILOTIDS);
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
// initialise autopilot connection / emit status
|
|
155
|
+
const initialise = () => {
|
|
156
|
+
server.debug('Initialising autopilot comms....');
|
|
157
|
+
(0, pypilot_1.initPyPilot)(server, plugin.id, settings.pypilot);
|
|
158
|
+
};
|
|
159
|
+
return plugin;
|
|
160
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AutopilotProviderApp } from './';
|
|
2
|
+
import { AutopilotInfo } from './sk-api';
|
|
3
|
+
export interface PYPILOT_CONFIG {
|
|
4
|
+
host: string;
|
|
5
|
+
port: number;
|
|
6
|
+
}
|
|
7
|
+
export declare const apData: AutopilotInfo;
|
|
8
|
+
export declare const PILOTIDS: string[];
|
|
9
|
+
export declare const initPyPilot: (app: AutopilotProviderApp, id: string, config: PYPILOT_CONFIG) => void;
|
|
10
|
+
export declare const closePyPilot: () => void;
|
|
11
|
+
export declare const apSetState: (state: string) => boolean;
|
|
12
|
+
export declare const apSetMode: (mode: string) => void;
|
|
13
|
+
export declare const apSetTarget: (value: number) => void;
|
|
14
|
+
export declare const apDodge: (value: number) => void;
|
|
15
|
+
export declare const apTack: (port: boolean) => void;
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.apTack = exports.apDodge = exports.apSetTarget = exports.apSetMode = exports.apSetState = exports.closePyPilot = exports.initPyPilot = exports.PILOTIDS = exports.apData = void 0;
|
|
4
|
+
const socket_io_client_1 = require("socket.io-client");
|
|
5
|
+
// autopilot data
|
|
6
|
+
exports.apData = {
|
|
7
|
+
options: {
|
|
8
|
+
states: [
|
|
9
|
+
{ name: 'enabled', engaged: true },
|
|
10
|
+
{ name: 'disabled', engaged: false }
|
|
11
|
+
],
|
|
12
|
+
modes: []
|
|
13
|
+
},
|
|
14
|
+
state: null,
|
|
15
|
+
mode: null,
|
|
16
|
+
target: null,
|
|
17
|
+
engaged: false
|
|
18
|
+
};
|
|
19
|
+
let server;
|
|
20
|
+
let pluginId;
|
|
21
|
+
let socket;
|
|
22
|
+
const degToRad = (deg) => deg * (Math.PI / 180);
|
|
23
|
+
const radToDeg = (rad) => rad * (180 / Math.PI);
|
|
24
|
+
exports.PILOTIDS = ['pypilot-d1'];
|
|
25
|
+
// initialise connection to autopilot and register pypilot_web socket listeners
|
|
26
|
+
const initPyPilot = (app, id, config) => {
|
|
27
|
+
server = app;
|
|
28
|
+
pluginId = id;
|
|
29
|
+
server.debug(`** Connecting to PyPilot **`);
|
|
30
|
+
socket = (0, socket_io_client_1.io)(`http://${config.host}:${config.port}`);
|
|
31
|
+
if (!socket) {
|
|
32
|
+
const msg = `PyPilot NOT connected @ ${config.host}:${config.port}... ensure 'pypilot_web' is running.`;
|
|
33
|
+
console.log(msg);
|
|
34
|
+
server.setPluginStatus(msg);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
initPyPilotListeners();
|
|
38
|
+
};
|
|
39
|
+
exports.initPyPilot = initPyPilot;
|
|
40
|
+
const closePyPilot = () => {
|
|
41
|
+
if (socket) {
|
|
42
|
+
socket.close();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.closePyPilot = closePyPilot;
|
|
46
|
+
// PyPilot socket event listeners
|
|
47
|
+
const initPyPilotListeners = () => {
|
|
48
|
+
socket.on('connect', () => {
|
|
49
|
+
server.debug('socket connected...');
|
|
50
|
+
let msg = `Started: Connected to PyPilot.`;
|
|
51
|
+
server.setPluginStatus(msg);
|
|
52
|
+
setTimeout(() => {
|
|
53
|
+
const period = 1;
|
|
54
|
+
//socket.emit('pypilot', `watch={"ap.heading": ${JSON.stringify(period)}}`)
|
|
55
|
+
socket.emit('pypilot', `watch={"ap.heading_command": ${JSON.stringify(period)}}`);
|
|
56
|
+
socket.emit('pypilot', `watch={"ap.enabled": ${JSON.stringify(period)}}`);
|
|
57
|
+
socket.emit('pypilot', `watch={"ap.mode": ${JSON.stringify(period)}}`);
|
|
58
|
+
}, 1000);
|
|
59
|
+
});
|
|
60
|
+
socket.on('connect_error', () => {
|
|
61
|
+
server.debug('socket connect_error!');
|
|
62
|
+
server.setPluginStatus(`Unable to connect to PyPilot!`);
|
|
63
|
+
exports.apData.state = 'off-line';
|
|
64
|
+
exports.apData.engaged = false;
|
|
65
|
+
server.autopilotUpdate(exports.PILOTIDS[0], {
|
|
66
|
+
state: exports.apData.state,
|
|
67
|
+
engaged: exports.apData.engaged
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
// pypilot updates listener (values)
|
|
71
|
+
socket.on('pypilot', (msg) => {
|
|
72
|
+
handlePyPilotUpdateMsg(JSON.parse(msg));
|
|
73
|
+
});
|
|
74
|
+
// pypilot_values listener (choices)
|
|
75
|
+
socket.on('pypilot_values', (msg) => {
|
|
76
|
+
handlePyPilotValuesMsg(JSON.parse(msg));
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
// Send values to pypilot
|
|
80
|
+
const sendToPyPilot = (path, value) => {
|
|
81
|
+
server.debug(path);
|
|
82
|
+
server.debug(value);
|
|
83
|
+
let mode = '';
|
|
84
|
+
if (path === 'mode') {
|
|
85
|
+
if (typeof value === 'string') {
|
|
86
|
+
mode = 'ap.mode';
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else if (path === 'state') {
|
|
90
|
+
if (typeof value === 'boolean') {
|
|
91
|
+
mode = 'ap.enabled';
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else if (path === 'target') {
|
|
95
|
+
if (typeof value === 'number') {
|
|
96
|
+
mode = 'ap.heading_command';
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else if (path === 'tack') {
|
|
100
|
+
if (typeof value === 'string' &&
|
|
101
|
+
(value === 'port' || value === 'starboard')) {
|
|
102
|
+
mode = 'ap.tack.direction';
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else if (path === 'dodge') {
|
|
106
|
+
server.debug('** DODGE **');
|
|
107
|
+
let servo_command = 0;
|
|
108
|
+
let servo_command_timeout = 0;
|
|
109
|
+
// update manual servo command
|
|
110
|
+
const poll_pypilot = () => {
|
|
111
|
+
server.debug(`** DODGE poll_pypilot -> timeout: ${servo_command_timeout}, cmd: ${servo_command} **`);
|
|
112
|
+
server.debug(`** mode: ${mode}`);
|
|
113
|
+
if (servo_command_timeout > 0) {
|
|
114
|
+
setTimeout(poll_pypilot, 200);
|
|
115
|
+
servo_command_timeout--;
|
|
116
|
+
if (servo_command_timeout <= 0)
|
|
117
|
+
servo_command = 0;
|
|
118
|
+
socket.emit('pypilot', mode + '=' + JSON.stringify(servo_command));
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
if (typeof value === 'number' && value !== 0) {
|
|
122
|
+
server.debug(`** DODGE value = ${value} **`);
|
|
123
|
+
const sign = value > 0 ? 1 : -1;
|
|
124
|
+
servo_command = -sign;
|
|
125
|
+
servo_command_timeout = Math.abs(value) > 5 ? 6 : 2;
|
|
126
|
+
mode = 'servo.command';
|
|
127
|
+
setTimeout(poll_pypilot, 1000);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
server.debug('Error: Invalid value!');
|
|
132
|
+
}
|
|
133
|
+
if (mode) {
|
|
134
|
+
try {
|
|
135
|
+
if (mode !== 'ap.servo_command') {
|
|
136
|
+
socket.emit('pypilot', mode + '=' + JSON.stringify(value));
|
|
137
|
+
}
|
|
138
|
+
return Promise.resolve();
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
server.debug(error.message);
|
|
142
|
+
throw new Error('Error: Sending data to autopilot!');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
throw new Error('Error: Invalid value!');
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
// process received pypilot update messages (values)
|
|
150
|
+
const handlePyPilotUpdateMsg = (data) => {
|
|
151
|
+
// compare and send delta
|
|
152
|
+
if (typeof data['ap.heading_command'] !== 'undefined') {
|
|
153
|
+
const heading = data['ap.heading_command'] === false ? null : data['ap.heading_command'];
|
|
154
|
+
if (typeof heading === 'number') {
|
|
155
|
+
const rad = degToRad(heading);
|
|
156
|
+
if (rad !== exports.apData.target) {
|
|
157
|
+
exports.apData.target = rad;
|
|
158
|
+
server.autopilotUpdate(exports.PILOTIDS[0], {
|
|
159
|
+
target: exports.apData.target
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (typeof data['ap.mode'] !== 'undefined') {
|
|
165
|
+
if (data['ap.mode'] !== exports.apData.mode) {
|
|
166
|
+
exports.apData.mode = data['ap.mode'];
|
|
167
|
+
server.autopilotUpdate(exports.PILOTIDS[0], {
|
|
168
|
+
mode: exports.apData.mode
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (typeof data['ap.enabled'] !== 'undefined') {
|
|
173
|
+
if (data['ap.enabled'] !== exports.apData.engaged) {
|
|
174
|
+
exports.apData.state = data['ap.enabled'] ? 'enabled' : 'disabled';
|
|
175
|
+
exports.apData.engaged = data['ap.enabled'];
|
|
176
|
+
server.autopilotUpdate(exports.PILOTIDS[0], {
|
|
177
|
+
state: exports.apData.state,
|
|
178
|
+
engaged: exports.apData.engaged
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
// process received pypilot_values message (choices)
|
|
184
|
+
const handlePyPilotValuesMsg = (data) => {
|
|
185
|
+
// available modes
|
|
186
|
+
if (typeof data['ap.mode'] !== undefined && data['ap.mode'].choices) {
|
|
187
|
+
exports.apData.options.modes = Array.isArray(data['ap.mode'].choices)
|
|
188
|
+
? data['ap.mode'].choices
|
|
189
|
+
: [];
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
// set autopilot state
|
|
193
|
+
const apSetState = (state) => {
|
|
194
|
+
server.debug(`${pluginId} => apSetState(${state})`);
|
|
195
|
+
let st;
|
|
196
|
+
exports.apData.options.states.forEach((i) => {
|
|
197
|
+
if (i.name === state) {
|
|
198
|
+
st = i;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
if (!st) {
|
|
202
|
+
throw new Error('Invalid state supplied!');
|
|
203
|
+
}
|
|
204
|
+
sendToPyPilot('state', st.engaged);
|
|
205
|
+
return st.engaged;
|
|
206
|
+
};
|
|
207
|
+
exports.apSetState = apSetState;
|
|
208
|
+
// set autopilot mode
|
|
209
|
+
const apSetMode = (mode) => {
|
|
210
|
+
server.debug(`${pluginId} => apsetMode(${mode})`);
|
|
211
|
+
if (exports.apData.options.modes.includes(mode)) {
|
|
212
|
+
sendToPyPilot('mode', mode);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
throw new Error('Invalid mode supplied!');
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
exports.apSetMode = apSetMode;
|
|
220
|
+
// set autopilot target
|
|
221
|
+
const apSetTarget = (value) => {
|
|
222
|
+
const deg = radToDeg(value);
|
|
223
|
+
server.debug(`${pluginId} => Setting Target value to ${value} (${deg})`);
|
|
224
|
+
sendToPyPilot('target', deg);
|
|
225
|
+
return;
|
|
226
|
+
};
|
|
227
|
+
exports.apSetTarget = apSetTarget;
|
|
228
|
+
// set autopilot target
|
|
229
|
+
const apDodge = (value) => {
|
|
230
|
+
const deg = radToDeg(value);
|
|
231
|
+
server.debug(`${pluginId} => Dodge value = ${value} (${deg})`);
|
|
232
|
+
sendToPyPilot('dodge', deg);
|
|
233
|
+
return;
|
|
234
|
+
};
|
|
235
|
+
exports.apDodge = apDodge;
|
|
236
|
+
// perform tack
|
|
237
|
+
const apTack = (port) => {
|
|
238
|
+
server.debug(`${pluginId} => apTack(${port})`);
|
|
239
|
+
sendToPyPilot('tack', port ? 'port' : 'starboard');
|
|
240
|
+
return;
|
|
241
|
+
};
|
|
242
|
+
exports.apTack = apTack;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export type AutopilotUpdateAttrib = 'mode' | 'state' | 'target' | 'engaged' | 'options';
|
|
2
|
+
export type TackGybeDirection = 'port' | 'starboard';
|
|
3
|
+
export interface AutopilotApi {
|
|
4
|
+
register(pluginId: string, provider: AutopilotProvider): void;
|
|
5
|
+
unRegister(pluginId: string): void;
|
|
6
|
+
apUpdate(pluginId: string, deviceId: string, apInfo: {
|
|
7
|
+
[path: string]: any;
|
|
8
|
+
}): void;
|
|
9
|
+
}
|
|
10
|
+
export interface AutopilotProvider {
|
|
11
|
+
getData(deviceId: string): Promise<AutopilotInfo>;
|
|
12
|
+
getState(deviceId: string): Promise<string>;
|
|
13
|
+
setState(state: string, deviceId: string): Promise<void>;
|
|
14
|
+
getMode(deviceId: string): Promise<string>;
|
|
15
|
+
setMode(mode: string, deviceId: string): Promise<void>;
|
|
16
|
+
getTarget(deviceId: string): Promise<number>;
|
|
17
|
+
setTarget(value: number, deviceId: string): Promise<void>;
|
|
18
|
+
adjustTarget(value: number, deviceId: string): Promise<void>;
|
|
19
|
+
engage(deviceId: string): Promise<void>;
|
|
20
|
+
disengage(deviceId: string): Promise<void>;
|
|
21
|
+
tack(direction: TackGybeDirection, deviceId: string): Promise<void>;
|
|
22
|
+
gybe(direction: TackGybeDirection, deviceId: string): Promise<void>;
|
|
23
|
+
dodge(direction: number | null, deviceId: string): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export interface AutopilotStateDef {
|
|
26
|
+
name: string;
|
|
27
|
+
engaged: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface AutopilotOptions {
|
|
30
|
+
states: AutopilotStateDef[];
|
|
31
|
+
modes: string[];
|
|
32
|
+
}
|
|
33
|
+
export interface AutopilotInfo {
|
|
34
|
+
options: AutopilotOptions;
|
|
35
|
+
target: number | null;
|
|
36
|
+
mode: string | null;
|
|
37
|
+
state: string | null;
|
|
38
|
+
engaged: boolean;
|
|
39
|
+
}
|
|
40
|
+
export interface AutopilotProviderRegistry {
|
|
41
|
+
registerAutopilotProvider(provider: AutopilotProvider, devices: string[]): void;
|
|
42
|
+
autopilotUpdate(deviceId: string, apInfo: {
|
|
43
|
+
[path: string]: any;
|
|
44
|
+
}): void;
|
|
45
|
+
}
|
package/plugin/sk-api.js
ADDED