@aircast-4g/mavlink 1.1.5 → 1.1.6

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/README.md CHANGED
@@ -186,7 +186,7 @@ await generator.generateFromFile('./dialect.xml', './output', {
186
186
  import {
187
187
  MAVLinkParser,
188
188
  MAVLinkFrameParser,
189
- MAVLinkMessageDecoder,
189
+ DialectParserFactory,
190
190
  CRCCalculator
191
191
  } from 'aircast-mavlink';
192
192
 
@@ -196,35 +196,34 @@ import * as MinimalTypes from 'aircast-mavlink/types/minimal';
196
196
  import * as ArduPilotMegaTypes from 'aircast-mavlink/types/ardupilotmega';
197
197
  import * as StandardTypes from 'aircast-mavlink/types/standard';
198
198
 
199
- // Basic message parsing
199
+ // Basic message parsing with async initialization
200
200
  const parser = new MAVLinkParser({ validateCRC: true });
201
+ await parser.initialize(); // Initialize dialect parsers
201
202
 
202
203
  // Parse incoming data (Buffer or Uint8Array)
203
- const messages = parser.parseBytes(incomingData);
204
+ const messages = await parser.parseBytes(incomingData);
204
205
  messages.forEach(message => {
205
206
  console.log(`Message: ${message.message_name}`);
206
207
  console.log(`From: ${message.system_id}:${message.component_id}`);
207
208
  console.log(`Payload:`, message.payload);
208
209
  });
209
210
 
210
- // Advanced frame-by-frame parsing
211
- const frameParser = new MAVLinkFrameParser();
212
- const decoder = new MAVLinkMessageDecoder();
211
+ // Advanced dialect-specific parsing
212
+ const dialectParser = await DialectParserFactory.createParser('common');
213
213
 
214
- frameParser.on('frame', (frame) => {
215
- const message = decoder.decode(frame);
216
- if (message) {
217
- console.log('Decoded message:', message);
218
- }
219
- });
214
+ const frame = {
215
+ magic: 0xFD, length: 9, sequence: 1, system_id: 1, component_id: 1,
216
+ message_id: 0, payload: new Uint8Array([6, 3, 196, 144, 0, 0, 4, 0, 0]),
217
+ checksum: 0x1234, protocol_version: 2
218
+ };
220
219
 
221
- // Process streaming data
222
- frameParser.process(dataBuffer);
220
+ const message = dialectParser.decode(frame);
221
+ console.log('Decoded message:', message);
223
222
 
224
223
  // WebSocket integration example
225
- websocket.onmessage = (event) => {
224
+ websocket.onmessage = async (event) => {
226
225
  const data = new Uint8Array(event.data);
227
- const messages = parser.parseBytes(data);
226
+ const messages = await parser.parseBytes(data);
228
227
 
229
228
  messages.forEach(msg => {
230
229
  switch (msg.message_name) {
@@ -337,8 +336,14 @@ interface ParserOptions {
337
336
  class MAVLinkParser {
338
337
  constructor(options?: ParserOptions);
339
338
 
339
+ // Initialize dialect parsers (call before parsing)
340
+ initialize(): Promise<void>;
341
+
340
342
  // Parse bytes and return complete messages
341
- parseBytes(data: Buffer | Uint8Array): MAVLinkMessage[];
343
+ parseBytes(data: Buffer | Uint8Array): Promise<MAVLinkMessage[]>;
344
+
345
+ // Parse single message
346
+ parseMessage(data: Uint8Array): Promise<MAVLinkMessage | null>;
342
347
 
343
348
  // Reset parser state
344
349
  reset(): void;
@@ -365,14 +370,20 @@ class MAVLinkFrameParser extends EventEmitter {
365
370
  }
366
371
  ```
367
372
 
368
- ### MAVLinkMessageDecoder
373
+ ### DialectParserFactory
369
374
 
370
- Decodes frames into structured messages.
375
+ Creates and manages dialect-specific parsers.
371
376
 
372
377
  ```typescript
373
- class MAVLinkMessageDecoder {
374
- // Decode a frame into a message
375
- decode(frame: MAVLinkFrame): MAVLinkMessage | null;
378
+ class DialectParserFactory {
379
+ // Create single dialect parser
380
+ static createParser(dialectName: SupportedDialects): Promise<DialectParser>;
381
+
382
+ // Create multi-dialect parser
383
+ static createMultipleDialectParser(dialectNames: SupportedDialects[]): Promise<MultiDialectParser>;
384
+
385
+ // Get list of supported dialects
386
+ static getSupportedDialects(): SupportedDialects[];
376
387
  }
377
388
  ```
378
389
 
@@ -432,20 +443,20 @@ python3 -m http.server 8000
432
443
  const parser = new MAVLinkParser({ validateCRC: true });
433
444
 
434
445
  // WebRTC data channel
435
- dataChannel.onmessage = (event) => {
436
- const messages = parser.parseBytes(new Uint8Array(event.data));
446
+ dataChannel.onmessage = async (event) => {
447
+ const messages = await parser.parseBytes(new Uint8Array(event.data));
437
448
  messages.forEach(processMessage);
438
449
  };
439
450
 
440
451
  // WebSocket connection
441
- websocket.onmessage = (event) => {
442
- const messages = parser.parseBytes(new Uint8Array(event.data));
452
+ websocket.onmessage = async (event) => {
453
+ const messages = await parser.parseBytes(new Uint8Array(event.data));
443
454
  messages.forEach(processMessage);
444
455
  };
445
456
 
446
457
  // TCP/UDP streams (Node.js)
447
- socket.on('data', (data) => {
448
- const messages = parser.parseBytes(data);
458
+ socket.on('data', async (data) => {
459
+ const messages = await parser.parseBytes(data);
449
460
  messages.forEach(processMessage);
450
461
  });
451
462
  ```
@@ -476,7 +487,7 @@ function processMessage(msg: MAVLinkMessage) {
476
487
  #### Error Handling and Recovery
477
488
  ```typescript
478
489
  try {
479
- const messages = parser.parseBytes(incomingData);
490
+ const messages = await parser.parseBytes(incomingData);
480
491
  messages.forEach(processMessage);
481
492
  } catch (error) {
482
493
  console.error('Parse error:', error.message);