@aircast-4g/mavlink 1.0.1
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/LICENSE +21 -0
- package/README.md +632 -0
- package/dist/batch-processor.d.ts +17 -0
- package/dist/batch-processor.d.ts.map +1 -0
- package/dist/batch-processor.js +141 -0
- package/dist/batch-processor.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +174 -0
- package/dist/cli.js.map +1 -0
- package/dist/generator/batch-processor.d.ts +17 -0
- package/dist/generator/batch-processor.d.ts.map +1 -0
- package/dist/generator/batch-processor.js +141 -0
- package/dist/generator/batch-processor.js.map +1 -0
- package/dist/generator/generator.d.ts +15 -0
- package/dist/generator/generator.d.ts.map +1 -0
- package/dist/generator/generator.js +92 -0
- package/dist/generator/generator.js.map +1 -0
- package/dist/generator/template-engine.d.ts +13 -0
- package/dist/generator/template-engine.d.ts.map +1 -0
- package/dist/generator/template-engine.js +220 -0
- package/dist/generator/template-engine.js.map +1 -0
- package/dist/generator/type-converter.d.ts +15 -0
- package/dist/generator/type-converter.d.ts.map +1 -0
- package/dist/generator/type-converter.js +179 -0
- package/dist/generator/type-converter.js.map +1 -0
- package/dist/generator/xml-parser.d.ts +13 -0
- package/dist/generator/xml-parser.d.ts.map +1 -0
- package/dist/generator/xml-parser.js +170 -0
- package/dist/generator/xml-parser.js.map +1 -0
- package/dist/generator.d.ts +15 -0
- package/dist/generator.d.ts.map +1 -0
- package/dist/generator.js +92 -0
- package/dist/generator.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/parser/crc.d.ts +7 -0
- package/dist/parser/crc.d.ts.map +1 -0
- package/dist/parser/crc.js +182 -0
- package/dist/parser/crc.js.map +1 -0
- package/dist/parser/frame-parser.d.ts +15 -0
- package/dist/parser/frame-parser.d.ts.map +1 -0
- package/dist/parser/frame-parser.js +82 -0
- package/dist/parser/frame-parser.js.map +1 -0
- package/dist/parser/index.d.ts +6 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +28 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/mavlink-parser.d.ts +35 -0
- package/dist/parser/mavlink-parser.d.ts.map +1 -0
- package/dist/parser/mavlink-parser.js +204 -0
- package/dist/parser/mavlink-parser.js.map +1 -0
- package/dist/parser/message-decoder.d.ts +11 -0
- package/dist/parser/message-decoder.d.ts.map +1 -0
- package/dist/parser/message-decoder.js +247 -0
- package/dist/parser/message-decoder.js.map +1 -0
- package/dist/parser/types.d.ts +59 -0
- package/dist/parser/types.d.ts.map +1 -0
- package/dist/parser/types.js +13 -0
- package/dist/parser/types.js.map +1 -0
- package/dist/template-engine.d.ts +13 -0
- package/dist/template-engine.d.ts.map +1 -0
- package/dist/template-engine.js +220 -0
- package/dist/template-engine.js.map +1 -0
- package/dist/type-converter.d.ts +15 -0
- package/dist/type-converter.d.ts.map +1 -0
- package/dist/type-converter.js +179 -0
- package/dist/type-converter.js.map +1 -0
- package/dist/types.d.ts +110 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/xml-parser.d.ts +13 -0
- package/dist/xml-parser.d.ts.map +1 -0
- package/dist/xml-parser.js +170 -0
- package/dist/xml-parser.js.map +1 -0
- package/package.json +105 -0
- package/types/ardupilotmega/enums.d.ts +2427 -0
- package/types/ardupilotmega/enums.d.ts.map +1 -0
- package/types/ardupilotmega/enums.js +4636 -0
- package/types/ardupilotmega/enums.js.map +1 -0
- package/types/ardupilotmega/enums.ts +4631 -0
- package/types/ardupilotmega/index.d.ts +4 -0
- package/types/ardupilotmega/index.d.ts.map +1 -0
- package/types/ardupilotmega/index.js +22 -0
- package/types/ardupilotmega/index.js.map +1 -0
- package/types/ardupilotmega/index.ts +6 -0
- package/types/ardupilotmega/messages.d.ts +3719 -0
- package/types/ardupilotmega/messages.d.ts.map +1 -0
- package/types/ardupilotmega/messages.js +1281 -0
- package/types/ardupilotmega/messages.js.map +1 -0
- package/types/ardupilotmega/messages.ts +8088 -0
- package/types/ardupilotmega/types.d.ts +221 -0
- package/types/ardupilotmega/types.d.ts.map +1 -0
- package/types/ardupilotmega/types.js +5 -0
- package/types/ardupilotmega/types.js.map +1 -0
- package/types/ardupilotmega/types.ts +2833 -0
- package/types/common/enums.d.ts +1843 -0
- package/types/common/enums.d.ts.map +1 -0
- package/types/common/enums.js +3636 -0
- package/types/common/enums.js.map +1 -0
- package/types/common/enums.ts +3632 -0
- package/types/common/index.d.ts +4 -0
- package/types/common/index.d.ts.map +1 -0
- package/types/common/index.js +21 -0
- package/types/common/index.js.map +1 -0
- package/types/common/index.ts +6 -0
- package/types/common/messages.d.ts +2805 -0
- package/types/common/messages.d.ts.map +1 -0
- package/types/common/messages.js +920 -0
- package/types/common/messages.js.map +1 -0
- package/types/common/messages.ts +6114 -0
- package/types/common/types.d.ts +157 -0
- package/types/common/types.d.ts.map +1 -0
- package/types/common/types.js +4 -0
- package/types/common/types.js.map +1 -0
- package/types/common/types.ts +2159 -0
- package/types/minimal/enums.d.ts +244 -0
- package/types/minimal/enums.d.ts.map +1 -0
- package/types/minimal/enums.js +496 -0
- package/types/minimal/enums.js.map +1 -0
- package/types/minimal/enums.ts +494 -0
- package/types/minimal/index.d.ts +4 -0
- package/types/minimal/index.d.ts.map +1 -0
- package/types/minimal/index.js +21 -0
- package/types/minimal/index.js.map +1 -0
- package/types/minimal/index.ts +6 -0
- package/types/minimal/messages.d.ts +25 -0
- package/types/minimal/messages.d.ts.map +1 -0
- package/types/minimal/messages.js +12 -0
- package/types/minimal/messages.js.map +1 -0
- package/types/minimal/messages.ts +62 -0
- package/types/minimal/types.d.ts +14 -0
- package/types/minimal/types.d.ts.map +1 -0
- package/types/minimal/types.js +4 -0
- package/types/minimal/types.js.map +1 -0
- package/types/minimal/types.ts +272 -0
- package/types/paparazzi/enums.ts +3632 -0
- package/types/paparazzi/index.ts +6 -0
- package/types/paparazzi/messages.ts +6185 -0
- package/types/paparazzi/types.ts +2159 -0
- package/types/python_array_test/enums.ts +3632 -0
- package/types/python_array_test/index.ts +6 -0
- package/types/python_array_test/messages.ts +6258 -0
- package/types/python_array_test/types.ts +2159 -0
- package/types/standard/enums.d.ts +248 -0
- package/types/standard/enums.d.ts.map +1 -0
- package/types/standard/enums.js +505 -0
- package/types/standard/enums.js.map +1 -0
- package/types/standard/enums.ts +502 -0
- package/types/standard/index.d.ts +4 -0
- package/types/standard/index.d.ts.map +1 -0
- package/types/standard/index.js +22 -0
- package/types/standard/index.js.map +1 -0
- package/types/standard/index.ts +6 -0
- package/types/standard/messages.d.ts +25 -0
- package/types/standard/messages.d.ts.map +1 -0
- package/types/standard/messages.js +13 -0
- package/types/standard/messages.js.map +1 -0
- package/types/standard/messages.ts +63 -0
- package/types/standard/types.d.ts +15 -0
- package/types/standard/types.d.ts.map +1 -0
- package/types/standard/types.js +5 -0
- package/types/standard/types.js.map +1 -0
- package/types/standard/types.ts +278 -0
- package/types/test/enums.ts +2 -0
- package/types/test/index.ts +6 -0
- package/types/test/messages.ts +69 -0
- package/types/test/types.ts +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Aircast MAVLink
|
|
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,632 @@
|
|
|
1
|
+
# Aircast MAVLink
|
|
2
|
+
|
|
3
|
+
A comprehensive Node.js tool for working with MAVLink protocols, providing both TypeScript type generation from XML dialect files and real-time MAVLink message parsing.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
### Type Generation
|
|
8
|
+
- Generate TypeScript interfaces from MAVLink XML dialects
|
|
9
|
+
- Support for all MAVLink data types and enums
|
|
10
|
+
- Type-safe enum definitions with numeric values (not string literals)
|
|
11
|
+
- Batch processing of multiple dialects
|
|
12
|
+
- CLI interface for easy integration
|
|
13
|
+
|
|
14
|
+
### MAVLink Parser
|
|
15
|
+
- Real-time MAVLink v1 and v2 message parsing
|
|
16
|
+
- CRC validation for data integrity
|
|
17
|
+
- Streaming data support with buffer management
|
|
18
|
+
- Browser and Node.js compatibility
|
|
19
|
+
- Web Worker and WebRTC integration examples
|
|
20
|
+
- TCP/UDP connection handling
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
### From GitHub Packages
|
|
25
|
+
|
|
26
|
+
Since this is a public repository, you can install the package directly without authentication:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Global installation
|
|
30
|
+
npm install -g @pavliha/aircast-mavlink --registry=https://npm.pkg.github.com
|
|
31
|
+
|
|
32
|
+
# Local installation
|
|
33
|
+
npm install @pavliha/aircast-mavlink --registry=https://npm.pkg.github.com
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**Alternative: Configure npm scope (one-time setup)**
|
|
37
|
+
```bash
|
|
38
|
+
# Configure npm to use GitHub Packages for @pavliha scope
|
|
39
|
+
npm config set @pavliha:registry https://npm.pkg.github.com
|
|
40
|
+
|
|
41
|
+
# Then install normally
|
|
42
|
+
npm install @pavliha/aircast-mavlink
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Global Installation (Alternative)
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm install -g aircast-mavlink
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Local Development
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
git clone <repository>
|
|
55
|
+
cd aircast-mavlink
|
|
56
|
+
npm install
|
|
57
|
+
npm run build
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
61
|
+
|
|
62
|
+
### CLI Usage
|
|
63
|
+
|
|
64
|
+
#### Generate Single Dialect
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# Using the global CLI
|
|
68
|
+
aircast-mavlink generate -i https://raw.githubusercontent.com/mavlink/mavlink/master/message_definitions/v1.0/common.xml -o ./types
|
|
69
|
+
|
|
70
|
+
# Using local installation
|
|
71
|
+
node dist/cli.js generate -i https://raw.githubusercontent.com/mavlink/mavlink/master/message_definitions/v1.0/common.xml -o ./types
|
|
72
|
+
|
|
73
|
+
# Generate from local file
|
|
74
|
+
aircast-mavlink generate -i ./dialect.xml -o ./types
|
|
75
|
+
|
|
76
|
+
# Specify dialect name and format
|
|
77
|
+
aircast-mavlink generate -i common.xml -o ./types -n common -f separate
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### Batch Generate Multiple Dialects
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# Generate all available dialects
|
|
84
|
+
aircast-mavlink batch -o ./mavlink-types
|
|
85
|
+
|
|
86
|
+
# Generate specific dialects
|
|
87
|
+
aircast-mavlink batch -d "common,minimal,ardupilotmega" -o ./mavlink-types
|
|
88
|
+
|
|
89
|
+
# Generate with package.json
|
|
90
|
+
aircast-mavlink batch -o ./mavlink-types --package
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
#### List Available Dialects
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
aircast-mavlink list
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
#### CLI Options
|
|
100
|
+
|
|
101
|
+
**Generate Command:**
|
|
102
|
+
- `-i, --input <path>` - Input XML file path or URL
|
|
103
|
+
- `-o, --output <path>` - Output directory (default: "./types")
|
|
104
|
+
- `-n, --name <name>` - Dialect name (auto-detected if not provided)
|
|
105
|
+
- `-f, --format <format>` - Output format: "single" or "separate" (default: "separate")
|
|
106
|
+
- `--no-enums` - Skip enum generation
|
|
107
|
+
- `--no-type-guards` - Skip type guard generation
|
|
108
|
+
|
|
109
|
+
**Batch Command:**
|
|
110
|
+
- `-o, --output <path>` - Output directory (default: "./mavlink-types")
|
|
111
|
+
- `-d, --dialects <dialects>` - Comma-separated dialect names
|
|
112
|
+
- `-f, --format <format>` - Output format: "single" or "separate" (default: "separate")
|
|
113
|
+
- `--no-enums` - Skip enum generation
|
|
114
|
+
- `--no-type-guards` - Skip type guard generation
|
|
115
|
+
- `--package` - Generate package.json and tsconfig.json
|
|
116
|
+
|
|
117
|
+
### Local Development Examples
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
# Build the project
|
|
121
|
+
npm run build
|
|
122
|
+
|
|
123
|
+
# Generate common dialect types
|
|
124
|
+
node dist/cli.js generate -i https://raw.githubusercontent.com/mavlink/mavlink/master/message_definitions/v1.0/common.xml -o ./output/common
|
|
125
|
+
|
|
126
|
+
# Generate minimal dialect types
|
|
127
|
+
node dist/cli.js generate -i https://raw.githubusercontent.com/mavlink/mavlink/master/message_definitions/v1.0/minimal.xml -o ./output/minimal
|
|
128
|
+
|
|
129
|
+
# Generate all dialects
|
|
130
|
+
node dist/cli.js batch -o ./output/all-dialects
|
|
131
|
+
|
|
132
|
+
# List available dialects
|
|
133
|
+
node dist/cli.js list
|
|
134
|
+
|
|
135
|
+
# Generate from local XML file
|
|
136
|
+
node dist/cli.js generate -i ./my-dialect.xml -o ./output/custom
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Programmatic Usage
|
|
140
|
+
|
|
141
|
+
#### Type Generation
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
import { MAVLinkGenerator, generateTypesFromXML } from 'aircast-mavlink';
|
|
145
|
+
|
|
146
|
+
// Generate from XML string
|
|
147
|
+
const files = await generateTypesFromXML(xmlContent, {
|
|
148
|
+
dialectName: 'common',
|
|
149
|
+
outputFormat: 'separate', // or 'single'
|
|
150
|
+
includeEnums: true,
|
|
151
|
+
includeTypeGuards: true
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// files is an object with filename -> content mappings
|
|
155
|
+
console.log(files['types.ts']);
|
|
156
|
+
console.log(files['messages.ts']);
|
|
157
|
+
console.log(files['index.ts']);
|
|
158
|
+
|
|
159
|
+
// Generate from URL or file
|
|
160
|
+
const generator = new MAVLinkGenerator();
|
|
161
|
+
|
|
162
|
+
// From URL
|
|
163
|
+
await generator.generateFromURL(
|
|
164
|
+
'https://raw.githubusercontent.com/mavlink/mavlink/master/message_definitions/v1.0/common.xml',
|
|
165
|
+
'./output',
|
|
166
|
+
{
|
|
167
|
+
dialectName: 'common',
|
|
168
|
+
outputFormat: 'separate',
|
|
169
|
+
includeEnums: true,
|
|
170
|
+
includeTypeGuards: true
|
|
171
|
+
}
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
// From local file
|
|
175
|
+
await generator.generateFromFile('./dialect.xml', './output', {
|
|
176
|
+
dialectName: 'custom',
|
|
177
|
+
outputFormat: 'single',
|
|
178
|
+
includeEnums: true,
|
|
179
|
+
includeTypeGuards: false
|
|
180
|
+
});
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
#### MAVLink Parsing
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
import {
|
|
187
|
+
MAVLinkParser,
|
|
188
|
+
MAVLinkFrameParser,
|
|
189
|
+
MAVLinkMessageDecoder,
|
|
190
|
+
CRCCalculator
|
|
191
|
+
} from 'aircast-mavlink';
|
|
192
|
+
|
|
193
|
+
// Import pre-generated dialect types separately
|
|
194
|
+
import * as CommonTypes from 'aircast-mavlink/types/common';
|
|
195
|
+
import * as MinimalTypes from 'aircast-mavlink/types/minimal';
|
|
196
|
+
import * as ArduPilotMegaTypes from 'aircast-mavlink/types/ardupilotmega';
|
|
197
|
+
import * as StandardTypes from 'aircast-mavlink/types/standard';
|
|
198
|
+
|
|
199
|
+
// Basic message parsing
|
|
200
|
+
const parser = new MAVLinkParser({ validateCRC: true });
|
|
201
|
+
|
|
202
|
+
// Parse incoming data (Buffer or Uint8Array)
|
|
203
|
+
const messages = parser.parseBytes(incomingData);
|
|
204
|
+
messages.forEach(message => {
|
|
205
|
+
console.log(`Message: ${message.message_name}`);
|
|
206
|
+
console.log(`From: ${message.system_id}:${message.component_id}`);
|
|
207
|
+
console.log(`Payload:`, message.payload);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// Advanced frame-by-frame parsing
|
|
211
|
+
const frameParser = new MAVLinkFrameParser();
|
|
212
|
+
const decoder = new MAVLinkMessageDecoder();
|
|
213
|
+
|
|
214
|
+
frameParser.on('frame', (frame) => {
|
|
215
|
+
const message = decoder.decode(frame);
|
|
216
|
+
if (message) {
|
|
217
|
+
console.log('Decoded message:', message);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// Process streaming data
|
|
222
|
+
frameParser.process(dataBuffer);
|
|
223
|
+
|
|
224
|
+
// WebSocket integration example
|
|
225
|
+
websocket.onmessage = (event) => {
|
|
226
|
+
const data = new Uint8Array(event.data);
|
|
227
|
+
const messages = parser.parseBytes(data);
|
|
228
|
+
|
|
229
|
+
messages.forEach(msg => {
|
|
230
|
+
switch (msg.message_name) {
|
|
231
|
+
case 'HEARTBEAT':
|
|
232
|
+
updateConnectionStatus(msg.payload);
|
|
233
|
+
break;
|
|
234
|
+
case 'GPS_RAW_INT':
|
|
235
|
+
updatePosition(msg.payload);
|
|
236
|
+
break;
|
|
237
|
+
case 'ATTITUDE':
|
|
238
|
+
updateAttitude(msg.payload);
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// Using pre-generated types with parser
|
|
245
|
+
function processMessage(msg: MAVLinkMessage) {
|
|
246
|
+
switch (msg.message_name) {
|
|
247
|
+
case 'HEARTBEAT':
|
|
248
|
+
// Type-safe access with CommonTypes
|
|
249
|
+
const heartbeat = msg.payload as CommonTypes.MessageHeartbeat;
|
|
250
|
+
console.log(`System type: ${heartbeat.type}`);
|
|
251
|
+
break;
|
|
252
|
+
case 'GPS_RAW_INT':
|
|
253
|
+
const gps = msg.payload as CommonTypes.MessageGpsRawInt;
|
|
254
|
+
console.log(`Lat: ${gps.lat / 1e7}, Lon: ${gps.lon / 1e7}`);
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Pre-generated Types
|
|
261
|
+
|
|
262
|
+
The package includes pre-generated TypeScript types for common MAVLink dialects:
|
|
263
|
+
|
|
264
|
+
### Available Dialects
|
|
265
|
+
- **CommonTypes** - Standard MAVLink common dialect (most widely used)
|
|
266
|
+
- **MinimalTypes** - Minimal MAVLink dialect for basic functionality
|
|
267
|
+
- **ArduPilotMegaTypes** - ArduPilot-specific extensions
|
|
268
|
+
- **StandardTypes** - Full standard MAVLink dialect
|
|
269
|
+
|
|
270
|
+
### Usage Examples
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
import * as CommonTypes from 'aircast-mavlink/types/common';
|
|
274
|
+
import * as ArduPilotMegaTypes from 'aircast-mavlink/types/ardupilotmega';
|
|
275
|
+
|
|
276
|
+
// Type-safe message handling
|
|
277
|
+
function handleHeartbeat(msg: CommonTypes.MessageHeartbeat) {
|
|
278
|
+
if (msg.autopilot === CommonTypes.MAV_AUTOPILOTEnum.MAV_AUTOPILOT_ARDUPILOTMEGA) {
|
|
279
|
+
console.log('ArduPilot detected');
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Type guards
|
|
284
|
+
function isHeartbeat(msg: any): msg is CommonTypes.MessageHeartbeat {
|
|
285
|
+
return CommonTypes.isHeartbeat(msg);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Enum usage
|
|
289
|
+
const systemType: CommonTypes.MAV_TYPE = CommonTypes.MAV_TYPEEnum.MAV_TYPE_QUADROTOR;
|
|
290
|
+
const flightMode: ArduPilotMegaTypes.COPTER_MODE = ArduPilotMegaTypes.COPTER_MODEEnum.COPTER_MODE_STABILIZE;
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### Type Structure
|
|
294
|
+
|
|
295
|
+
Each dialect export includes:
|
|
296
|
+
- **Message interfaces** - Typed message payload structures
|
|
297
|
+
- **Enum types** - Union types with numeric values
|
|
298
|
+
- **Enum objects** - Runtime enum values
|
|
299
|
+
- **Type guards** - Runtime type checking functions
|
|
300
|
+
- **Type maps** - Message name to type mappings
|
|
301
|
+
|
|
302
|
+
```typescript
|
|
303
|
+
// Example from CommonTypes
|
|
304
|
+
interface MessageHeartbeat {
|
|
305
|
+
type: MAV_TYPE;
|
|
306
|
+
autopilot: MAV_AUTOPILOT;
|
|
307
|
+
base_mode: MAV_MODE_FLAG;
|
|
308
|
+
system_status: MAV_STATE;
|
|
309
|
+
mavlink_version: number;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
type MAV_TYPE = 0 | 1 | 2 | 3 | number; // Union type
|
|
313
|
+
|
|
314
|
+
enum MAV_TYPEEnum { // Runtime enum
|
|
315
|
+
MAV_TYPE_GENERIC = 0,
|
|
316
|
+
MAV_TYPE_FIXED_WING = 1,
|
|
317
|
+
MAV_TYPE_QUADROTOR = 2,
|
|
318
|
+
MAV_TYPE_COAXIAL = 3,
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function isHeartbeat(msg: any): msg is MessageHeartbeat; // Type guard
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
## Parser API Reference
|
|
325
|
+
|
|
326
|
+
### MAVLinkParser
|
|
327
|
+
|
|
328
|
+
Main parser class for processing MAVLink data streams.
|
|
329
|
+
|
|
330
|
+
```typescript
|
|
331
|
+
interface ParserOptions {
|
|
332
|
+
validateCRC?: boolean; // Enable CRC validation (default: true)
|
|
333
|
+
bufferSize?: number; // Internal buffer size (default: 4096)
|
|
334
|
+
resetOnError?: boolean; // Reset parser state on errors (default: true)
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
class MAVLinkParser {
|
|
338
|
+
constructor(options?: ParserOptions);
|
|
339
|
+
|
|
340
|
+
// Parse bytes and return complete messages
|
|
341
|
+
parseBytes(data: Buffer | Uint8Array): MAVLinkMessage[];
|
|
342
|
+
|
|
343
|
+
// Reset parser state
|
|
344
|
+
reset(): void;
|
|
345
|
+
|
|
346
|
+
// Get parser statistics
|
|
347
|
+
getStats(): ParserStats;
|
|
348
|
+
}
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
### MAVLinkFrameParser
|
|
352
|
+
|
|
353
|
+
Low-level frame parser with event-based API.
|
|
354
|
+
|
|
355
|
+
```typescript
|
|
356
|
+
class MAVLinkFrameParser extends EventEmitter {
|
|
357
|
+
constructor(options?: ParserOptions);
|
|
358
|
+
|
|
359
|
+
// Process incoming data
|
|
360
|
+
process(data: Buffer | Uint8Array): void;
|
|
361
|
+
|
|
362
|
+
// Events:
|
|
363
|
+
// 'frame' - Complete frame received
|
|
364
|
+
// 'error' - Parse error occurred
|
|
365
|
+
}
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### MAVLinkMessageDecoder
|
|
369
|
+
|
|
370
|
+
Decodes frames into structured messages.
|
|
371
|
+
|
|
372
|
+
```typescript
|
|
373
|
+
class MAVLinkMessageDecoder {
|
|
374
|
+
// Decode a frame into a message
|
|
375
|
+
decode(frame: MAVLinkFrame): MAVLinkMessage | null;
|
|
376
|
+
}
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
### Message Structure
|
|
380
|
+
|
|
381
|
+
```typescript
|
|
382
|
+
interface MAVLinkMessage {
|
|
383
|
+
sequence: number;
|
|
384
|
+
system_id: number;
|
|
385
|
+
component_id: number;
|
|
386
|
+
message_id: number;
|
|
387
|
+
message_name: string;
|
|
388
|
+
payload: Record<string, any>;
|
|
389
|
+
timestamp: number;
|
|
390
|
+
crc_ok: boolean;
|
|
391
|
+
}
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
## Examples
|
|
395
|
+
|
|
396
|
+
The `examples/` directory contains comprehensive usage examples:
|
|
397
|
+
|
|
398
|
+
### Browser Examples
|
|
399
|
+
- **WebRTC Integration** (`webrtc-integration.html`) - Complete web demo with real-time parsing
|
|
400
|
+
- **Web Worker** (`web-worker-example.js`) - Non-blocking parsing in web workers
|
|
401
|
+
- **Basic Web Usage** (`test-web.html`) - Simple browser integration
|
|
402
|
+
|
|
403
|
+
### Node.js Examples
|
|
404
|
+
- **Basic Parser** (`basic-parser.js`) - Fundamental parsing concepts
|
|
405
|
+
- **Streaming Data** (`nodejs-stream.js`) - TCP/UDP connections and file replay
|
|
406
|
+
- **Production Usage** - Advanced patterns for real applications
|
|
407
|
+
|
|
408
|
+
### Running Examples
|
|
409
|
+
|
|
410
|
+
```bash
|
|
411
|
+
# Build the project first
|
|
412
|
+
npm run build
|
|
413
|
+
|
|
414
|
+
# Run basic Node.js example
|
|
415
|
+
node examples/basic-parser.js
|
|
416
|
+
|
|
417
|
+
# Run streaming example with different modes
|
|
418
|
+
node examples/nodejs-stream.js test # Run tests
|
|
419
|
+
node examples/nodejs-stream.js tcp localhost 5760 # Connect to TCP source
|
|
420
|
+
node examples/nodejs-stream.js udp 14550 # Start UDP server
|
|
421
|
+
node examples/nodejs-stream.js file data.mavlink # Replay file
|
|
422
|
+
|
|
423
|
+
# Serve web examples
|
|
424
|
+
python3 -m http.server 8000
|
|
425
|
+
# Then open http://localhost:8000/examples/
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
### Common Integration Patterns
|
|
429
|
+
|
|
430
|
+
#### Real-time Telemetry Processing
|
|
431
|
+
```typescript
|
|
432
|
+
const parser = new MAVLinkParser({ validateCRC: true });
|
|
433
|
+
|
|
434
|
+
// WebRTC data channel
|
|
435
|
+
dataChannel.onmessage = (event) => {
|
|
436
|
+
const messages = parser.parseBytes(new Uint8Array(event.data));
|
|
437
|
+
messages.forEach(processMessage);
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
// WebSocket connection
|
|
441
|
+
websocket.onmessage = (event) => {
|
|
442
|
+
const messages = parser.parseBytes(new Uint8Array(event.data));
|
|
443
|
+
messages.forEach(processMessage);
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
// TCP/UDP streams (Node.js)
|
|
447
|
+
socket.on('data', (data) => {
|
|
448
|
+
const messages = parser.parseBytes(data);
|
|
449
|
+
messages.forEach(processMessage);
|
|
450
|
+
});
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
#### Message Filtering and Routing
|
|
454
|
+
```typescript
|
|
455
|
+
function processMessage(msg: MAVLinkMessage) {
|
|
456
|
+
switch (msg.message_name) {
|
|
457
|
+
case 'HEARTBEAT':
|
|
458
|
+
updateSystemStatus(msg.system_id, msg.payload);
|
|
459
|
+
break;
|
|
460
|
+
case 'GPS_RAW_INT':
|
|
461
|
+
updatePosition(msg.payload.lat / 1e7, msg.payload.lon / 1e7);
|
|
462
|
+
break;
|
|
463
|
+
case 'ATTITUDE':
|
|
464
|
+
updateAttitude(msg.payload.roll, msg.payload.pitch, msg.payload.yaw);
|
|
465
|
+
break;
|
|
466
|
+
case 'VFR_HUD':
|
|
467
|
+
updateHUD(msg.payload);
|
|
468
|
+
break;
|
|
469
|
+
case 'STATUSTEXT':
|
|
470
|
+
displayStatusMessage(msg.payload.text, msg.payload.severity);
|
|
471
|
+
break;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
#### Error Handling and Recovery
|
|
477
|
+
```typescript
|
|
478
|
+
try {
|
|
479
|
+
const messages = parser.parseBytes(incomingData);
|
|
480
|
+
messages.forEach(processMessage);
|
|
481
|
+
} catch (error) {
|
|
482
|
+
console.error('Parse error:', error.message);
|
|
483
|
+
|
|
484
|
+
// Reset parser state if needed
|
|
485
|
+
if (error.code === 'INVALID_CHECKSUM') {
|
|
486
|
+
parser.reset();
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// Implement reconnection logic
|
|
490
|
+
scheduleReconnect();
|
|
491
|
+
}
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
## Generated Types
|
|
495
|
+
|
|
496
|
+
The tool generates TypeScript files with the following structure:
|
|
497
|
+
|
|
498
|
+
### File Structure
|
|
499
|
+
|
|
500
|
+
When using `separate` format, the generator creates:
|
|
501
|
+
- `types.ts` - Base interfaces and type definitions
|
|
502
|
+
- `enums.ts` - Enum object definitions
|
|
503
|
+
- `messages.ts` - Message interfaces, type maps, and type guards
|
|
504
|
+
- `index.ts` - Main export file
|
|
505
|
+
|
|
506
|
+
### Example Output
|
|
507
|
+
|
|
508
|
+
**types.ts**
|
|
509
|
+
```typescript
|
|
510
|
+
export interface MAVLinkMessage<Content = unknown> {
|
|
511
|
+
timestamp: number;
|
|
512
|
+
system_id: number;
|
|
513
|
+
component_id: number;
|
|
514
|
+
type: string;
|
|
515
|
+
content: Content;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
export type MAV_STATE =
|
|
519
|
+
| 0 // MAV_STATE_UNINIT - Uninitialized system
|
|
520
|
+
| 1 // MAV_STATE_BOOT - System is booting up
|
|
521
|
+
| 2 // MAV_STATE_STANDBY - System is standby
|
|
522
|
+
| 3 // MAV_STATE_ACTIVE - System is active
|
|
523
|
+
| number;
|
|
524
|
+
|
|
525
|
+
export type MAV_TYPE =
|
|
526
|
+
| 0 // MAV_TYPE_GENERIC - Generic micro air vehicle
|
|
527
|
+
| 1 // MAV_TYPE_FIXED_WING - Fixed wing aircraft
|
|
528
|
+
| 2 // MAV_TYPE_QUADROTOR - Quadrotor
|
|
529
|
+
| number;
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
**enums.ts**
|
|
533
|
+
```typescript
|
|
534
|
+
export enum MAV_STATEEnum {
|
|
535
|
+
MAV_STATE_UNINIT = 0,
|
|
536
|
+
MAV_STATE_BOOT = 1,
|
|
537
|
+
MAV_STATE_STANDBY = 2,
|
|
538
|
+
MAV_STATE_ACTIVE = 3,
|
|
539
|
+
}
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
**messages.ts**
|
|
543
|
+
```typescript
|
|
544
|
+
export interface MessageHeartbeat {
|
|
545
|
+
type: MAV_TYPE;
|
|
546
|
+
autopilot: MAV_AUTOPILOT;
|
|
547
|
+
base_mode: MAV_MODE_FLAG;
|
|
548
|
+
system_status: MAV_STATE;
|
|
549
|
+
mavlink_version: number;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
export interface MessageTypeMap {
|
|
553
|
+
HEARTBEAT: MessageHeartbeat;
|
|
554
|
+
// ... other messages
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
export type AnyMessage =
|
|
558
|
+
| MAVLinkMessage<MessageHeartbeat>
|
|
559
|
+
| MAVLinkMessage<MessageSysStatus>;
|
|
560
|
+
|
|
561
|
+
// Type guard functions
|
|
562
|
+
export function isHeartbeat(msg: MAVLinkMessage): msg is MAVLinkMessage<MessageHeartbeat> {
|
|
563
|
+
return msg.type === 'HEARTBEAT';
|
|
564
|
+
}
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
## Output Formats
|
|
568
|
+
|
|
569
|
+
### Separate Files (Default)
|
|
570
|
+
- `types.ts` - Type definitions and interfaces
|
|
571
|
+
- `enums.ts` - Enum object definitions
|
|
572
|
+
- `messages.ts` - Message interfaces and utilities
|
|
573
|
+
- `index.ts` - Main export file
|
|
574
|
+
|
|
575
|
+
### Single File
|
|
576
|
+
All definitions combined into a single `index.ts` file.
|
|
577
|
+
|
|
578
|
+
## Development
|
|
579
|
+
|
|
580
|
+
```bash
|
|
581
|
+
# Setup
|
|
582
|
+
npm install
|
|
583
|
+
npm run build
|
|
584
|
+
|
|
585
|
+
# Development workflow
|
|
586
|
+
npm run dev # Run in development mode with tsx
|
|
587
|
+
npm run build # Build TypeScript to JavaScript
|
|
588
|
+
npm run test # Run Jest tests
|
|
589
|
+
npm run lint # Run ESLint
|
|
590
|
+
npm run clean # Clean build artifacts
|
|
591
|
+
|
|
592
|
+
# Test the CLI locally
|
|
593
|
+
node dist/cli.js --help
|
|
594
|
+
|
|
595
|
+
# Generate test types
|
|
596
|
+
node dist/cli.js generate -i https://raw.githubusercontent.com/mavlink/mavlink/master/message_definitions/v1.0/minimal.xml -o ./test-output
|
|
597
|
+
```
|
|
598
|
+
|
|
599
|
+
## Project Structure
|
|
600
|
+
|
|
601
|
+
```
|
|
602
|
+
├── src/
|
|
603
|
+
│ ├── cli.ts # Command line interface
|
|
604
|
+
│ ├── index.ts # Main export file
|
|
605
|
+
│ ├── types.ts # Shared type definitions
|
|
606
|
+
│ ├── generator/ # Type generation components
|
|
607
|
+
│ │ ├── generator.ts # Main generator class
|
|
608
|
+
│ │ ├── template-engine.ts # Handlebars template engine
|
|
609
|
+
│ │ ├── type-converter.ts # XML to TypeScript conversion
|
|
610
|
+
│ │ ├── xml-parser.ts # MAVLink XML parser
|
|
611
|
+
│ │ └── batch-processor.ts # Batch processing utilities
|
|
612
|
+
│ └── parser/ # MAVLink parsing components
|
|
613
|
+
│ ├── index.ts # Parser exports
|
|
614
|
+
│ ├── mavlink-parser.ts # Main parser class
|
|
615
|
+
│ ├── frame-parser.ts # Frame-level parsing
|
|
616
|
+
│ ├── message-decoder.ts # Message decoding
|
|
617
|
+
│ ├── crc.ts # CRC calculation utilities
|
|
618
|
+
│ └── types.ts # Parser type definitions
|
|
619
|
+
├── examples/ # Usage examples and demos
|
|
620
|
+
│ ├── README.md # Examples documentation
|
|
621
|
+
│ ├── basic-parser.js # Basic Node.js usage
|
|
622
|
+
│ ├── nodejs-stream.js # Advanced streaming patterns
|
|
623
|
+
│ ├── web-worker-example.js # Web Worker integration
|
|
624
|
+
│ ├── webrtc-integration.html # Complete web demo
|
|
625
|
+
│ └── test-web.html # Simple browser test
|
|
626
|
+
├── tests/ # Jest test files
|
|
627
|
+
└── dist/ # Compiled JavaScript output
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
## License
|
|
631
|
+
|
|
632
|
+
MIT
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface BatchProcessorOptions {
|
|
2
|
+
outputDir: string;
|
|
3
|
+
dialectFormat: 'single' | 'separate';
|
|
4
|
+
includeEnums: boolean;
|
|
5
|
+
includeTypeGuards: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare class BatchProcessor {
|
|
8
|
+
private generator;
|
|
9
|
+
private static readonly MAVLINK_DIALECTS_URL;
|
|
10
|
+
private static readonly MAVLINK_RAW_BASE_URL;
|
|
11
|
+
constructor();
|
|
12
|
+
processAllDialects(options: BatchProcessorOptions): Promise<void>;
|
|
13
|
+
processSpecificDialects(dialectNames: string[], options: BatchProcessorOptions): Promise<void>;
|
|
14
|
+
private generateMainIndex;
|
|
15
|
+
generatePackageJson(outputDir: string, version?: string): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=batch-processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-processor.d.ts","sourceRoot":"","sources":["../src/batch-processor.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,QAAQ,GAAG,UAAU,CAAC;IACrC,YAAY,EAAE,OAAO,CAAC;IACtB,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,SAAS,CAAmB;IACpC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,CAAoF;IAChI,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,CAAuF;;IAM7H,kBAAkB,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAiDjE,uBAAuB,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;YAsCtF,iBAAiB;IAczB,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,MAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;CAoDvF"}
|