Initial commit

This commit is contained in:
Marcelo
2025-11-20 15:27:34 -06:00
commit cc72c9fc5d
3221 changed files with 737477 additions and 0 deletions

21
node_modules/@serialport/parser-slip-encoder/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright 2010 Christopher Williams. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.

View File

@@ -0,0 +1,3 @@
# @serialport/parser-slip-encoder
See our api docs https://serialport.io/docs/api-parser-slip-encoder

View File

@@ -0,0 +1,39 @@
/// <reference types="node" />
/// <reference types="node" />
import { Transform, TransformCallback, TransformOptions } from 'stream';
export interface SlipDecoderOptions extends TransformOptions {
/** Custom start byte */
START?: number;
/** Custom start escape byte */
ESC_START?: number;
/** custom escape byte */
ESC?: number;
/** custom end byte */
END?: number;
/** custom escape end byte */
ESC_END?: number;
/** custom escape escape byte */
ESC_ESC?: number;
}
/**
* A transform stream that decodes slip encoded data.
* @extends Transform
*
* Runs in O(n) time, stripping out slip encoding and emitting decoded data. Optionally custom slip escape and delimiters can be provided.
*/
export declare class SlipDecoder extends Transform {
opts: {
START: number | undefined;
ESC: number;
END: number;
ESC_START: number | undefined;
ESC_END: number;
ESC_ESC: number;
};
buffer: Buffer;
escape: boolean;
start: boolean;
constructor(options?: SlipDecoderOptions);
_transform(chunk: Buffer, encoding: BufferEncoding, cb: TransformCallback): void;
_flush(cb: TransformCallback): void;
}

View File

@@ -0,0 +1,83 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SlipDecoder = void 0;
const stream_1 = require("stream");
/**
* A transform stream that decodes slip encoded data.
* @extends Transform
*
* Runs in O(n) time, stripping out slip encoding and emitting decoded data. Optionally custom slip escape and delimiters can be provided.
*/
class SlipDecoder extends stream_1.Transform {
opts;
buffer;
escape;
start;
constructor(options = {}) {
super(options);
const { START, ESC = 0xdb, END = 0xc0, ESC_START, ESC_END = 0xdc, ESC_ESC = 0xdd } = options;
this.opts = {
START,
ESC,
END,
ESC_START,
ESC_END,
ESC_ESC,
};
this.buffer = Buffer.alloc(0);
this.escape = false;
this.start = false;
}
_transform(chunk, encoding, cb) {
for (let ndx = 0; ndx < chunk.length; ndx++) {
let byte = chunk[ndx];
if (byte === this.opts.START) {
this.start = true;
continue;
}
else if (undefined == this.opts.START) {
this.start = true;
}
if (this.escape) {
if (byte === this.opts.ESC_START && this.opts.START) {
byte = this.opts.START;
}
else if (byte === this.opts.ESC_ESC) {
byte = this.opts.ESC;
}
else if (byte === this.opts.ESC_END) {
byte = this.opts.END;
}
else {
this.escape = false;
this.push(this.buffer);
this.buffer = Buffer.alloc(0);
}
}
else {
if (byte === this.opts.ESC) {
this.escape = true;
continue;
}
if (byte === this.opts.END) {
this.push(this.buffer);
this.buffer = Buffer.alloc(0);
this.escape = false;
this.start = false;
continue;
}
}
this.escape = false;
if (this.start) {
this.buffer = Buffer.concat([this.buffer, Buffer.from([byte])]);
}
}
cb();
}
_flush(cb) {
this.push(this.buffer);
this.buffer = Buffer.alloc(0);
cb();
}
}
exports.SlipDecoder = SlipDecoder;

View File

@@ -0,0 +1,38 @@
/// <reference types="node" />
/// <reference types="node" />
import { Transform, TransformCallback, TransformOptions } from 'stream';
export interface SlipEncoderOptions extends TransformOptions {
/** Custom start byte */
START?: number;
/** Custom start escape byte */
ESC_START?: number;
/** custom escape byte */
ESC?: number;
/** custom end byte */
END?: number;
/** custom escape end byte */
ESC_END?: number;
/** custom escape escape byte */
ESC_ESC?: number;
/** Adds an END character at the beginning of each packet per the Bluetooth Core Specification 4.0, Volume 4, Part D, Chapter 3 "SLIP Layer" and allowed by RFC 1055 */
bluetoothQuirk?: boolean;
}
/**
* A transform stream that emits SLIP-encoded data for each incoming packet.
*
* Runs in O(n) time, adding a 0xC0 character at the end of each
* received packet and escaping characters, according to RFC 1055.
*/
export declare class SlipEncoder extends Transform {
opts: {
START: number | undefined;
ESC: number;
END: number;
ESC_START: number | undefined;
ESC_END: number;
ESC_ESC: number;
bluetoothQuirk: boolean;
};
constructor(options?: SlipEncoderOptions);
_transform(chunk: Buffer, encoding: BufferEncoding, cb: TransformCallback): void;
}

View File

@@ -0,0 +1,63 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SlipEncoder = void 0;
const stream_1 = require("stream");
/**
* A transform stream that emits SLIP-encoded data for each incoming packet.
*
* Runs in O(n) time, adding a 0xC0 character at the end of each
* received packet and escaping characters, according to RFC 1055.
*/
class SlipEncoder extends stream_1.Transform {
opts;
constructor(options = {}) {
super(options);
const { START, ESC = 0xdb, END = 0xc0, ESC_START, ESC_END = 0xdc, ESC_ESC = 0xdd, bluetoothQuirk = false } = options;
this.opts = {
START,
ESC,
END,
ESC_START,
ESC_END,
ESC_ESC,
bluetoothQuirk,
};
}
_transform(chunk, encoding, cb) {
const chunkLength = chunk.length;
if (this.opts.bluetoothQuirk && chunkLength === 0) {
// Edge case: push no data. Bluetooth-quirky SLIP parsers don't like
// lots of 0xC0s together.
return cb();
}
// Allocate memory for the worst-case scenario: all bytes are escaped,
// plus start and end separators.
const encoded = Buffer.alloc(chunkLength * 2 + 2);
let j = 0;
if (this.opts.bluetoothQuirk == true) {
encoded[j++] = this.opts.END;
}
if (this.opts.START !== undefined) {
encoded[j++] = this.opts.START;
}
for (let i = 0; i < chunkLength; i++) {
let byte = chunk[i];
if (byte === this.opts.START && this.opts.ESC_START) {
encoded[j++] = this.opts.ESC;
byte = this.opts.ESC_START;
}
else if (byte === this.opts.END) {
encoded[j++] = this.opts.ESC;
byte = this.opts.ESC_END;
}
else if (byte === this.opts.ESC) {
encoded[j++] = this.opts.ESC;
byte = this.opts.ESC_ESC;
}
encoded[j++] = byte;
}
encoded[j++] = this.opts.END;
cb(null, encoded.slice(0, j));
}
}
exports.SlipEncoder = SlipEncoder;

View File

@@ -0,0 +1,2 @@
export * from './decoder';
export * from './encoder';

View File

@@ -0,0 +1,18 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./decoder"), exports);
__exportStar(require("./encoder"), exports);

View File

@@ -0,0 +1,25 @@
{
"name": "@serialport/parser-slip-encoder",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsc --build tsconfig-build.json"
},
"version": "12.0.0",
"engines": {
"node": ">=12.0.0"
},
"publishConfig": {
"access": "public"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/serialport/node-serialport.git"
},
"funding": "https://opencollective.com/serialport/donate",
"devDependencies": {
"typescript": "5.2.2"
},
"gitHead": "f7e7bd53f9578a26c4f44cc1949fef396dc064c7"
}