@v5x/serial 0.5.5 → 0.5.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 +7 -9
- package/dist/VexCRC.d.ts +0 -11
- package/dist/VexConnection.d.ts +30 -8
- package/dist/VexDevice.d.ts +11 -2
- package/dist/VexDeviceState.d.ts +23 -14
- package/dist/VexError.d.ts +4 -1
- package/dist/VexEvent.d.ts +15 -10
- package/dist/VexFirmware.d.ts +4 -2
- package/dist/VexFirmwareVersion.d.ts +4 -43
- package/dist/VexIniConfig.d.ts +0 -1
- package/dist/VexPacketBase.d.ts +5 -2
- package/dist/VexPacketEncoder.d.ts +11 -30
- package/dist/VexPacketModels.d.ts +0 -11
- package/dist/VexPacketView.d.ts +2 -0
- package/dist/index.cjs +680 -1046
- package/dist/index.cjs.map +16 -16
- package/dist/index.js +672 -1039
- package/dist/index.js.map +16 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,9 +4,8 @@ TypeScript implementation of the VEX V5 serial protocol.
|
|
|
4
4
|
|
|
5
5
|
See the [serial library documentation](https://docs.v5x.dev/serial/overview) for browser setup, guides, and high-level API reference.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
packets.
|
|
7
|
+
It covers connecting to V5 devices over the Web Serial API, reading device
|
|
8
|
+
state, transferring files, and working with protocol packets.
|
|
10
9
|
|
|
11
10
|
## Install
|
|
12
11
|
|
|
@@ -47,7 +46,7 @@ can open.
|
|
|
47
46
|
The package ships ESM, CommonJS, and TypeScript declarations. Packet and version
|
|
48
47
|
utilities work in Bun or Node.js, but direct browser device connections require
|
|
49
48
|
the Web Serial API. The `@v5x/cli` package is separate and currently supports
|
|
50
|
-
Linux
|
|
49
|
+
Linux and macOS. Windows requires a different CLI serial backend.
|
|
51
50
|
|
|
52
51
|
## Common Exports
|
|
53
52
|
|
|
@@ -64,10 +63,9 @@ Linux only.
|
|
|
64
63
|
|
|
65
64
|
## Result-returning async APIs
|
|
66
65
|
|
|
67
|
-
All public async methods return `ResultAsync<T, VexSerialError
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
report errors through the result channel:
|
|
66
|
+
All public async methods return `ResultAsync<T, VexSerialError>`, so failures
|
|
67
|
+
are explicit in the type system rather than thrown. State-changing operations
|
|
68
|
+
are awaitable and report errors through the result channel:
|
|
71
69
|
|
|
72
70
|
```ts
|
|
73
71
|
const r = await device.setMatchMode("disabled");
|
|
@@ -97,7 +95,7 @@ transfer is active by default.
|
|
|
97
95
|
Protocol requests default to a 1,000 ms response timeout. Individual transfer
|
|
98
96
|
phases use longer timeouts where erase, write, or exit operations need them.
|
|
99
97
|
`reconnect(0)` waits indefinitely, while a positive reconnect timeout is a total
|
|
100
|
-
deadline in milliseconds. A timeout or NACK
|
|
98
|
+
deadline in milliseconds. A timeout or NACK surfaces as a `VexProtocolError`
|
|
101
99
|
(or a related `VexSerialError` subclass) through the `Result` error channel; it
|
|
102
100
|
does not cancel work already running on the device.
|
|
103
101
|
|
package/dist/VexCRC.d.ts
CHANGED
|
@@ -2,17 +2,6 @@ export declare class CrcGenerator {
|
|
|
2
2
|
crc32Table: Uint32Array;
|
|
3
3
|
static POLYNOMIAL_CRC32: number;
|
|
4
4
|
static POLYNOMIAL_CRC16: number;
|
|
5
|
-
constructor();
|
|
6
|
-
/**
|
|
7
|
-
* Calculate CRC16 for buffer
|
|
8
|
-
*/
|
|
9
5
|
crc16(buf: Uint8Array, initValue: number): number;
|
|
10
|
-
/**
|
|
11
|
-
* Generate CRC32 reverse table
|
|
12
|
-
*/
|
|
13
|
-
crc32GenTable(): void;
|
|
14
|
-
/**
|
|
15
|
-
* Calculate CRC32 for buffer
|
|
16
|
-
*/
|
|
17
6
|
crc32(buf: Uint8Array, initValue: number): number;
|
|
18
7
|
}
|
package/dist/VexConnection.d.ts
CHANGED
|
@@ -5,11 +5,30 @@ import { type ProgramIniConfig } from "./VexIniConfig.js";
|
|
|
5
5
|
import { Result, ResultAsync } from "neverthrow";
|
|
6
6
|
import { MatchStatusReplyD2HPacket, DeviceBoundPacket, MatchModeReplyD2HPacket, GetSystemStatusReplyD2HPacket, type HostBoundPacket, Query1ReplyD2HPacket, LoadFileActionReplyD2HPacket, GetSystemFlagsReplyD2HPacket, GetRadioStatusReplyD2HPacket, GetDeviceStatusReplyD2HPacket, SendDashTouchReplyD2HPacket, SelectDashReplyD2HPacket, ScreenCaptureReplyD2HPacket } from "./VexPacket.js";
|
|
7
7
|
import { type VexFirmwareVersion } from "./VexFirmwareVersion.js";
|
|
8
|
+
type HostBoundPacketType<T extends HostBoundPacket> = {
|
|
9
|
+
new (data: ArrayBuffer | Uint8Array): T;
|
|
10
|
+
name: string;
|
|
11
|
+
};
|
|
12
|
+
/** Outcome of {@link VexSerialConnection.open}. */
|
|
13
|
+
export type OpenResult = "opened" | "busy" | "no-port";
|
|
14
|
+
/**
|
|
15
|
+
* Payload of the `warning` event: a non-fatal condition the library
|
|
16
|
+
* recovered from, surfaced so embedders can log or ignore it.
|
|
17
|
+
*/
|
|
18
|
+
export interface ConnectionWarning {
|
|
19
|
+
message: string;
|
|
20
|
+
details?: unknown;
|
|
21
|
+
}
|
|
22
|
+
export interface VexSerialConnectionEvents {
|
|
23
|
+
connected: undefined;
|
|
24
|
+
disconnected: undefined;
|
|
25
|
+
warning: ConnectionWarning;
|
|
26
|
+
}
|
|
8
27
|
/**
|
|
9
28
|
* A connection to a V5 device.
|
|
10
|
-
* Emit events: connected, disconnected
|
|
29
|
+
* Emit events: connected, disconnected, warning
|
|
11
30
|
*/
|
|
12
|
-
export declare class VexSerialConnection extends VexEventTarget {
|
|
31
|
+
export declare class VexSerialConnection extends VexEventTarget<VexSerialConnectionEvents> {
|
|
13
32
|
filters: SerialPortFilter[];
|
|
14
33
|
writer: WritableStreamDefaultWriter<unknown> | undefined;
|
|
15
34
|
reader: ReadableStreamDefaultReader<unknown> | undefined;
|
|
@@ -24,19 +43,21 @@ export declare class VexSerialConnection extends VexEventTarget {
|
|
|
24
43
|
get isConnected(): boolean;
|
|
25
44
|
get isFileTransferring(): boolean;
|
|
26
45
|
constructor(serial: Serial);
|
|
46
|
+
protected reportWarning(message: string, details?: unknown): void;
|
|
27
47
|
close(): Promise<void>;
|
|
28
48
|
private _hasOpenResources;
|
|
29
49
|
private _doClose;
|
|
30
50
|
/**
|
|
31
|
-
* Open a port.
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
51
|
+
* Open a port. Resolves `"opened"` when a connection is established,
|
|
52
|
+
* `"busy"` when the matching port is already held elsewhere, and
|
|
53
|
+
* `"no-port"` when no matching port was selected. The result is `Err`
|
|
54
|
+
* when a connection is already open (programmer error) or when the
|
|
55
|
+
* port fails to open (permissions, dead device, ...).
|
|
35
56
|
*/
|
|
36
|
-
open(use?: number
|
|
57
|
+
open(use?: number, askUser?: boolean): ResultAsync<OpenResult, VexSerialError>;
|
|
37
58
|
private _open;
|
|
38
|
-
writeData(rawData: DeviceBoundPacket | Uint8Array, resolve: (data: HostBoundPacket | ArrayBuffer | AckType) => void, timeout?: number): void;
|
|
39
59
|
writeDataAsync(rawData: DeviceBoundPacket | Uint8Array, timeout?: number): Promise<HostBoundPacket | ArrayBuffer | AckType>;
|
|
60
|
+
request<T extends HostBoundPacket>(packet: DeviceBoundPacket, ReplyType: HostBoundPacketType<T>, timeout?: number): ResultAsync<T, VexSerialError>;
|
|
40
61
|
protected readData(cache: Uint8Array, expectedSize: number): Promise<Uint8Array>;
|
|
41
62
|
protected startReader(): Promise<void>;
|
|
42
63
|
query1(): ResultAsync<Query1ReplyD2HPacket, VexSerialError>;
|
|
@@ -101,3 +122,4 @@ export declare class V5SerialConnection extends VexSerialConnection {
|
|
|
101
122
|
mockTouch(x: number, y: number, press: boolean): ResultAsync<SendDashTouchReplyD2HPacket, VexSerialError>;
|
|
102
123
|
openScreen(screen: number | SelectDashScreen, port: number): ResultAsync<SelectDashReplyD2HPacket, VexSerialError>;
|
|
103
124
|
}
|
|
125
|
+
export {};
|
package/dist/VexDevice.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ export { VexSerialDevice, V5Brain, V5Battery, V5BrainButton, V5BrainSettings, V5
|
|
|
7
7
|
export { sleep, sleepUntil, sleepUntilAsync, downloadFileFromInternet, uploadFirmware, } from "./VexFirmware.js";
|
|
8
8
|
export declare class V5SerialDevice extends VexSerialDevice {
|
|
9
9
|
autoReconnect: boolean;
|
|
10
|
-
autoRefresh: boolean;
|
|
11
10
|
pauseRefreshOnFileTransfer: boolean;
|
|
12
11
|
protected _isReconnecting: boolean;
|
|
13
12
|
private _isDisconnecting;
|
|
@@ -15,7 +14,17 @@ export declare class V5SerialDevice extends VexSerialDevice {
|
|
|
15
14
|
state: V5SerialDeviceState;
|
|
16
15
|
private _disposed;
|
|
17
16
|
private _refreshGeneration;
|
|
18
|
-
|
|
17
|
+
private _autoRefresh;
|
|
18
|
+
private _isLastRefreshComplete;
|
|
19
|
+
private readonly _brain;
|
|
20
|
+
private readonly _controllers;
|
|
21
|
+
private readonly _radio;
|
|
22
|
+
private readonly _deviceFacades;
|
|
23
|
+
constructor(defaultSerial: Serial, autoRefresh?: boolean);
|
|
24
|
+
get autoRefresh(): boolean;
|
|
25
|
+
set autoRefresh(value: boolean);
|
|
26
|
+
private _startRefreshInterval;
|
|
27
|
+
private _stopRefreshInterval;
|
|
19
28
|
get isV5Controller(): boolean;
|
|
20
29
|
get brain(): V5Brain;
|
|
21
30
|
get controllers(): [V5Controller, V5Controller];
|
package/dist/VexDeviceState.d.ts
CHANGED
|
@@ -6,7 +6,11 @@ import { type ProgramIniConfig } from "./VexIniConfig.js";
|
|
|
6
6
|
import { VexSerialError } from "./VexError.js";
|
|
7
7
|
import { ResultAsync } from "neverthrow";
|
|
8
8
|
import type { V5SerialDevice } from "./VexDevice.js";
|
|
9
|
-
export
|
|
9
|
+
export interface VexSerialDeviceEvents {
|
|
10
|
+
disconnected: undefined;
|
|
11
|
+
error: unknown;
|
|
12
|
+
}
|
|
13
|
+
export declare abstract class VexSerialDevice extends VexEventTarget<VexSerialDeviceEvents> {
|
|
10
14
|
connection: V5SerialConnection | undefined;
|
|
11
15
|
defaultSerial: Serial;
|
|
12
16
|
get isConnected(): boolean;
|
|
@@ -19,18 +23,24 @@ export declare class V5SerialDeviceState {
|
|
|
19
23
|
_instance: V5SerialDevice;
|
|
20
24
|
/**
|
|
21
25
|
* Counter used only to pause automatic refresh while a file transfer
|
|
22
|
-
* is in flight. This is not a mutex:
|
|
23
|
-
* operations lives on the {@link V5SerialConnection} transaction
|
|
24
|
-
* queue. The counter is exposed via {@link isFileTransferring} so the
|
|
25
|
-
* refresh loop can skip work during transfers.
|
|
26
|
+
* is in flight. This is not a mutex: serialization of transfer
|
|
27
|
+
* operations lives on the {@link V5SerialConnection} transaction queue.
|
|
26
28
|
*/
|
|
27
29
|
private refreshPauseDepth;
|
|
30
|
+
get isRefreshPaused(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Use {@link isRefreshPaused}. This flag only means that
|
|
33
|
+
* automatic refresh is paused, not that transfer operations are locked.
|
|
34
|
+
*/
|
|
28
35
|
get isFileTransferring(): boolean;
|
|
29
36
|
/**
|
|
30
37
|
* Increment the refresh-pause depth, run the operation, and decrement
|
|
31
|
-
* the depth again. The actual transfer mutex lives on the connection
|
|
32
|
-
|
|
33
|
-
|
|
38
|
+
* the depth again. The actual transfer mutex lives on the connection.
|
|
39
|
+
*/
|
|
40
|
+
withRefreshPaused<T>(operation: () => PromiseLike<T>): Promise<T>;
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated Use {@link withRefreshPaused}. This only pauses automatic
|
|
43
|
+
* refresh and does not lock file transfers.
|
|
34
44
|
*/
|
|
35
45
|
withFileTransfer<T>(operation: () => PromiseLike<T>): Promise<T>;
|
|
36
46
|
brain: {
|
|
@@ -54,15 +64,11 @@ export declare class V5SerialDeviceState {
|
|
|
54
64
|
systemVersion: VexFirmwareVersion;
|
|
55
65
|
uniqueId: number;
|
|
56
66
|
};
|
|
57
|
-
controllers:
|
|
67
|
+
controllers: {
|
|
58
68
|
battery: number;
|
|
59
69
|
isAvailable: boolean;
|
|
60
70
|
isCharging: boolean;
|
|
61
|
-
}
|
|
62
|
-
battery: number;
|
|
63
|
-
isAvailable: boolean;
|
|
64
|
-
isCharging?: undefined;
|
|
65
|
-
})[];
|
|
71
|
+
}[];
|
|
66
72
|
devices: Array<ISmartDeviceInfo | undefined>;
|
|
67
73
|
isFieldControllerConnected: boolean;
|
|
68
74
|
matchMode: MatchMode;
|
|
@@ -80,6 +86,9 @@ export declare class V5SerialDeviceState {
|
|
|
80
86
|
}
|
|
81
87
|
export declare class V5Brain {
|
|
82
88
|
private readonly state;
|
|
89
|
+
private readonly batteryFacade;
|
|
90
|
+
private readonly buttonFacade;
|
|
91
|
+
private readonly settingsFacade;
|
|
83
92
|
constructor(state: V5SerialDeviceState);
|
|
84
93
|
get isRunningProgram(): boolean;
|
|
85
94
|
get activeProgram(): number;
|
package/dist/VexError.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type AckType } from "./Vex.js";
|
|
1
2
|
/**
|
|
2
3
|
* Typed error hierarchy for the serial protocol package.
|
|
3
4
|
*
|
|
@@ -10,6 +11,7 @@ export type VexSerialErrorKind = "not-connected" | "invalid-argument" | "protoco
|
|
|
10
11
|
/** Base class for every failure surfaced by the serial package. */
|
|
11
12
|
export declare class VexSerialError extends Error {
|
|
12
13
|
readonly kind: VexSerialErrorKind;
|
|
14
|
+
readonly ackType: AckType | undefined;
|
|
13
15
|
constructor(kind: VexSerialErrorKind, message: string);
|
|
14
16
|
}
|
|
15
17
|
/** No connection is currently open to a device. */
|
|
@@ -22,7 +24,8 @@ export declare class VexInvalidArgumentError extends VexSerialError {
|
|
|
22
24
|
}
|
|
23
25
|
/** The device refused, timed out, or replied unexpectedly to a command. */
|
|
24
26
|
export declare class VexProtocolError extends VexSerialError {
|
|
25
|
-
|
|
27
|
+
readonly ackType: AckType | undefined;
|
|
28
|
+
constructor(message: string, ackType?: AckType);
|
|
26
29
|
}
|
|
27
30
|
/** A file-transfer handshake, read, write, or exit failed. */
|
|
28
31
|
export declare class VexTransferError extends VexSerialError {
|
package/dist/VexEvent.d.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type EventName = string | symbol;
|
|
2
|
+
type EventMapKey<TEvents> = Extract<keyof TEvents, EventName>;
|
|
3
|
+
type EventListener<TValue> = (data: TValue) => void;
|
|
4
|
+
export declare class VexEventEmitter<TEvents extends object = Record<EventName, unknown>> {
|
|
5
|
+
handlerMap: Map<EventName, Array<EventListener<unknown>>>;
|
|
3
6
|
constructor();
|
|
4
|
-
on(eventName:
|
|
5
|
-
remove(eventName:
|
|
6
|
-
emit(eventName:
|
|
7
|
+
on<K extends EventMapKey<TEvents>>(eventName: K, listener: EventListener<TEvents[K]>): void;
|
|
8
|
+
remove<K extends EventMapKey<TEvents>>(eventName: K, listener: EventListener<TEvents[K]>): void;
|
|
9
|
+
emit<K extends EventMapKey<TEvents>>(eventName: K, data: TEvents[K]): void;
|
|
7
10
|
clearListeners(): void;
|
|
8
11
|
}
|
|
9
|
-
export declare class VexEventTarget {
|
|
10
|
-
emitter: VexEventEmitter
|
|
12
|
+
export declare class VexEventTarget<TEvents extends object = Record<EventName, unknown>> {
|
|
13
|
+
emitter: VexEventEmitter<TEvents>;
|
|
11
14
|
constructor();
|
|
12
|
-
emit(eventName:
|
|
13
|
-
on(eventName:
|
|
14
|
-
remove(eventName:
|
|
15
|
+
emit<K extends EventMapKey<TEvents>>(eventName: K, data: TEvents[K]): void;
|
|
16
|
+
on<K extends EventMapKey<TEvents>>(eventName: K, listener: EventListener<TEvents[K]>): void;
|
|
17
|
+
remove<K extends EventMapKey<TEvents>>(eventName: K, listener: EventListener<TEvents[K]>): void;
|
|
15
18
|
clearListeners(): void;
|
|
19
|
+
private normalizeEventName;
|
|
16
20
|
}
|
|
21
|
+
export {};
|
package/dist/VexFirmware.d.ts
CHANGED
|
@@ -36,10 +36,12 @@ export declare function sleepUntil(f: () => boolean, timeout: number, interval?:
|
|
|
36
36
|
* when `ms` is negative.
|
|
37
37
|
*/
|
|
38
38
|
export declare function sleep(ms: number): ResultAsync<void, VexSerialError>;
|
|
39
|
+
type FirmwareProgressCallback = (state: string, current: number, total: number) => void;
|
|
39
40
|
/**
|
|
40
41
|
* Upload a VEXos firmware archive to a connected brain. Network and
|
|
41
42
|
* archive validation failures are returned as {@link VexSerialError}
|
|
42
43
|
* values rather than thrown; a device that refuses a step or a missing
|
|
43
|
-
* connection surfaces as {@link
|
|
44
|
+
* connection surfaces as {@link VexFirmwareError} / {@link VexNotConnectedError}.
|
|
44
45
|
*/
|
|
45
|
-
export declare function uploadFirmware(state: V5SerialDeviceState, publicUrl?: string, usingVersion?: string, progressCallback?:
|
|
46
|
+
export declare function uploadFirmware(state: V5SerialDeviceState, publicUrl?: string, usingVersion?: string, progressCallback?: FirmwareProgressCallback): ResultAsync<boolean, VexSerialError>;
|
|
47
|
+
export {};
|
|
@@ -1,55 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is a class to make it easier to handle passing the VEXos version
|
|
3
|
-
* information around in the application. This provides ways to get any
|
|
4
|
-
* form of the string representation and quickly compare versions.
|
|
5
|
-
*/
|
|
6
1
|
export declare class VexFirmwareVersion {
|
|
7
|
-
major: number;
|
|
8
|
-
minor: number;
|
|
9
|
-
build: number;
|
|
10
|
-
beta: number;
|
|
2
|
+
readonly major: number;
|
|
3
|
+
readonly minor: number;
|
|
4
|
+
readonly build: number;
|
|
5
|
+
readonly beta: number;
|
|
11
6
|
constructor(major: number, minor: number, build: number, beta: number);
|
|
12
|
-
/**
|
|
13
|
-
* Take a a string of MAJOR.MINOR.BUILD.bBETA and converts it to a
|
|
14
|
-
* VexFirmwareVersion instance
|
|
15
|
-
* @param version the string to process
|
|
16
|
-
* @returns a VexFirmwareVersion representing the provided string
|
|
17
|
-
*/
|
|
18
7
|
static fromString(version: string): VexFirmwareVersion;
|
|
19
|
-
/**
|
|
20
|
-
* Take a a Uint8Array and converts it to a VexFirmwareVersion instance
|
|
21
|
-
* @param data the array to process
|
|
22
|
-
* @param offset the offset to start at
|
|
23
|
-
* @returns a VexFirmwareVersion representing the provided string
|
|
24
|
-
*/
|
|
25
8
|
static fromUint8Array(data: Uint8Array, offset?: number, reverse?: boolean): VexFirmwareVersion;
|
|
26
9
|
static allZero(): VexFirmwareVersion;
|
|
27
|
-
/**
|
|
28
|
-
* Take a a string of MAJOR_MINOR_BUILD_BETA and converts it to a
|
|
29
|
-
* VexFirmwareVersion instance
|
|
30
|
-
* @param version the string to process
|
|
31
|
-
* @returns a VexFirmwareVersion representing the provided string
|
|
32
|
-
*/
|
|
33
10
|
static fromCatalogString(version: string): VexFirmwareVersion;
|
|
34
11
|
isBeta(): boolean;
|
|
35
|
-
/**
|
|
36
|
-
* returns version as Uint Array
|
|
37
|
-
*/
|
|
38
12
|
toUint8Array(reverse?: boolean): Uint8Array;
|
|
39
|
-
/**
|
|
40
|
-
* returns version as major.minor.build
|
|
41
|
-
*/
|
|
42
13
|
toUserString(): string;
|
|
43
|
-
/**
|
|
44
|
-
* returns version as ${major}.${minor}.{build}.b${beta}
|
|
45
|
-
*/
|
|
46
14
|
toInternalString(): string;
|
|
47
|
-
/**
|
|
48
|
-
* compares this version to the provided version.
|
|
49
|
-
* * if this < b: negative
|
|
50
|
-
* * if this = b: 0
|
|
51
|
-
* * if this > b: positive
|
|
52
|
-
* @param that the version to compare again
|
|
53
|
-
*/
|
|
54
15
|
compare(that: VexFirmwareVersion): number;
|
|
55
16
|
}
|
package/dist/VexIniConfig.d.ts
CHANGED
|
@@ -20,7 +20,6 @@ export declare class ProgramIniConfig {
|
|
|
20
20
|
config: Record<number, string>;
|
|
21
21
|
controller1: Record<string, string>;
|
|
22
22
|
controller2: Record<string, string>;
|
|
23
|
-
constructor();
|
|
24
23
|
setProgramDate(date: Date): void;
|
|
25
24
|
createIni(): string;
|
|
26
25
|
dec2(value: number): string;
|
package/dist/VexPacketBase.d.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { AckType, type DataArray } from "./Vex.js";
|
|
2
2
|
import type { PacketEncoder } from "./VexPacketEncoder.js";
|
|
3
3
|
export declare abstract class Packet {
|
|
4
|
+
/** Raw bytes sent to or received from the device. */
|
|
4
5
|
data: Uint8Array;
|
|
5
6
|
static ENCODER: PacketEncoder;
|
|
6
7
|
constructor(rawData: DataArray);
|
|
7
8
|
}
|
|
8
9
|
export declare class DeviceBoundPacket extends Packet {
|
|
9
|
-
get commandId(): number;
|
|
10
|
-
get commandExtendedId(): number | undefined;
|
|
11
10
|
static COMMAND_ID: number;
|
|
12
11
|
static COMMAND_EXTENDED_ID: number | undefined;
|
|
12
|
+
get commandId(): number;
|
|
13
|
+
get commandExtendedId(): number | undefined;
|
|
13
14
|
constructor(payload?: Uint8Array);
|
|
14
15
|
}
|
|
15
16
|
export declare class HostBoundPacket extends Packet {
|
|
17
|
+
static COMMAND_ID: number;
|
|
18
|
+
static COMMAND_EXTENDED_ID: number | undefined;
|
|
16
19
|
ack: AckType;
|
|
17
20
|
payloadSize: number;
|
|
18
21
|
ackIndex: number;
|
|
@@ -8,46 +8,27 @@ export declare class PacketEncoder {
|
|
|
8
8
|
static J2000_EPOCH: number;
|
|
9
9
|
vexVersion: number;
|
|
10
10
|
crcgen: CrcGenerator;
|
|
11
|
-
allPacketsTable:
|
|
11
|
+
allPacketsTable: Map<number, Map<number | undefined, typeof HostBoundPacket>>;
|
|
12
12
|
static getInstance(): PacketEncoder;
|
|
13
13
|
private constructor();
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*/
|
|
14
|
+
/** Look up the reply class registered for a command ID pair. */
|
|
15
|
+
getPacketType(commandId: number | undefined, commandExtendedId: number | undefined): typeof HostBoundPacket | undefined;
|
|
16
|
+
/** Create the vex CDC header. */
|
|
18
17
|
createHeader(buf: ArrayBuffer | undefined): Uint8Array;
|
|
19
|
-
/**
|
|
20
|
-
* Create the vex CDC simple message
|
|
21
|
-
* @param cmd the CDC command byte
|
|
22
|
-
*/
|
|
18
|
+
/** Create a simple CDC message. */
|
|
23
19
|
cdcCommand(cmd: number): Uint8Array;
|
|
24
|
-
/**
|
|
25
|
-
* Create the vex CDC simple message
|
|
26
|
-
* @param cmd the CDC command byte
|
|
27
|
-
* @param data the data to send
|
|
28
|
-
*/
|
|
20
|
+
/** Create a simple CDC message carrying data. */
|
|
29
21
|
cdcCommandWithData(cmd: number, data: Uint8Array): Uint8Array;
|
|
30
|
-
/**
|
|
31
|
-
* Create the vex CDC extended message
|
|
32
|
-
* @param cmd the CDC command byte
|
|
33
|
-
* @param ext the CDC extended command byte
|
|
34
|
-
* @return a message
|
|
35
|
-
*/
|
|
22
|
+
/** Create a CDC2 (extended) message with no payload. */
|
|
36
23
|
cdc2Command(cmd: number, ext: number): Uint8Array;
|
|
37
24
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* @returns the required buffer length of the command message
|
|
25
|
+
* Buffer length for a CDC2 command: header + command byte + function
|
|
26
|
+
* byte + length byte (two bytes when payload > 127) + payload + CRC16.
|
|
41
27
|
*/
|
|
42
28
|
cdc2CommandBufferLength(data: Uint8Array): number;
|
|
43
|
-
/**
|
|
44
|
-
* Create the vex CDC extended message with some data
|
|
45
|
-
* @param cmd the CDC command byte
|
|
46
|
-
* @param ext the CDC extended command byte
|
|
47
|
-
* @param data the CDC extended command payload
|
|
48
|
-
* @return a message
|
|
49
|
-
*/
|
|
29
|
+
/** Create a CDC2 (extended) message carrying a payload. */
|
|
50
30
|
cdc2CommandWithData(cmd: number, ext: number, data: Uint8Array): Uint8Array;
|
|
31
|
+
private appendCrc16;
|
|
51
32
|
validateHeader(data: Uint8Array): boolean;
|
|
52
33
|
validateMessageCdc(data: Uint8Array): boolean;
|
|
53
34
|
getPayloadSize(data: Uint8Array): number;
|
|
@@ -4,12 +4,10 @@ import { DeviceBoundPacket, HostBoundPacket } from "./VexPacketBase.js";
|
|
|
4
4
|
export declare class Query1H2DPacket extends DeviceBoundPacket {
|
|
5
5
|
static COMMAND_ID: number;
|
|
6
6
|
static COMMAND_EXTENDED_ID: undefined;
|
|
7
|
-
constructor();
|
|
8
7
|
}
|
|
9
8
|
export declare class SystemVersionH2DPacket extends DeviceBoundPacket {
|
|
10
9
|
static COMMAND_ID: number;
|
|
11
10
|
static COMMAND_EXTENDED_ID: undefined;
|
|
12
|
-
constructor();
|
|
13
11
|
}
|
|
14
12
|
export declare class UpdateMatchModeH2DPacket extends DeviceBoundPacket {
|
|
15
13
|
static COMMAND_ID: number;
|
|
@@ -19,7 +17,6 @@ export declare class UpdateMatchModeH2DPacket extends DeviceBoundPacket {
|
|
|
19
17
|
export declare class GetMatchStatusH2DPacket extends DeviceBoundPacket {
|
|
20
18
|
static COMMAND_ID: number;
|
|
21
19
|
static COMMAND_EXTENDED_ID: number;
|
|
22
|
-
constructor();
|
|
23
20
|
}
|
|
24
21
|
export declare class GetRadioModeH2DPacket extends DeviceBoundPacket {
|
|
25
22
|
static COMMAND_ID: number;
|
|
@@ -103,22 +100,18 @@ export declare class GetSystemFlagsH2DPacket extends DeviceBoundPacket {
|
|
|
103
100
|
export declare class GetDeviceStatusH2DPacket extends DeviceBoundPacket {
|
|
104
101
|
static COMMAND_ID: number;
|
|
105
102
|
static COMMAND_EXTENDED_ID: number;
|
|
106
|
-
constructor();
|
|
107
103
|
}
|
|
108
104
|
export declare class GetSystemStatusH2DPacket extends DeviceBoundPacket {
|
|
109
105
|
static COMMAND_ID: number;
|
|
110
106
|
static COMMAND_EXTENDED_ID: number;
|
|
111
|
-
constructor();
|
|
112
107
|
}
|
|
113
108
|
export declare class GetFdtStatusH2DPacket extends DeviceBoundPacket {
|
|
114
109
|
static COMMAND_ID: number;
|
|
115
110
|
static COMMAND_EXTENDED_ID: number;
|
|
116
|
-
constructor();
|
|
117
111
|
}
|
|
118
112
|
export declare class GetLogCountH2DPacket extends DeviceBoundPacket {
|
|
119
113
|
static COMMAND_ID: number;
|
|
120
114
|
static COMMAND_EXTENDED_ID: number;
|
|
121
|
-
constructor();
|
|
122
115
|
}
|
|
123
116
|
export declare class ReadLogPageH2DPacket extends DeviceBoundPacket {
|
|
124
117
|
static COMMAND_ID: number;
|
|
@@ -128,7 +121,6 @@ export declare class ReadLogPageH2DPacket extends DeviceBoundPacket {
|
|
|
128
121
|
export declare class GetRadioStatusH2DPacket extends DeviceBoundPacket {
|
|
129
122
|
static COMMAND_ID: number;
|
|
130
123
|
static COMMAND_EXTENDED_ID: number;
|
|
131
|
-
constructor();
|
|
132
124
|
}
|
|
133
125
|
export declare class ScreenCaptureH2DPacket extends DeviceBoundPacket {
|
|
134
126
|
static COMMAND_ID: number;
|
|
@@ -158,12 +150,10 @@ export declare class WriteKeyValueH2DPacket extends DeviceBoundPacket {
|
|
|
158
150
|
export declare class GetSlot1to4InfoH2DPacket extends DeviceBoundPacket {
|
|
159
151
|
static COMMAND_ID: number;
|
|
160
152
|
static COMMAND_EXTENDED_ID: number;
|
|
161
|
-
constructor();
|
|
162
153
|
}
|
|
163
154
|
export declare class GetSlot5to8InfoH2DPacket extends DeviceBoundPacket {
|
|
164
155
|
static COMMAND_ID: number;
|
|
165
156
|
static COMMAND_EXTENDED_ID: number;
|
|
166
|
-
constructor();
|
|
167
157
|
}
|
|
168
158
|
export declare class FactoryStatusH2DPacket extends DeviceBoundPacket {
|
|
169
159
|
static COMMAND_ID: number;
|
|
@@ -247,7 +237,6 @@ export declare class ReadFileReplyD2HPacket extends HostBoundPacket {
|
|
|
247
237
|
length: number;
|
|
248
238
|
buf: ArrayBuffer;
|
|
249
239
|
constructor(data: DataArray);
|
|
250
|
-
static isValidPacket(data: Uint8Array, n: number): boolean;
|
|
251
240
|
}
|
|
252
241
|
export declare class LinkFileReplyD2HPacket extends HostBoundPacket {
|
|
253
242
|
static COMMAND_ID: number;
|
package/dist/VexPacketView.d.ts
CHANGED
|
@@ -12,7 +12,9 @@ export declare class PacketView extends DataView<ArrayBuffer> {
|
|
|
12
12
|
nextInt32(littleEndian?: boolean): number;
|
|
13
13
|
nextUint32(littleEndian?: boolean): number;
|
|
14
14
|
nextString(length: number): string;
|
|
15
|
+
/** Read a null-terminated string from a fixed-width `length`-byte field. */
|
|
15
16
|
nextNTBS(length: number): string;
|
|
17
|
+
/** Read a null-terminated string of at most `length` bytes. */
|
|
16
18
|
nextVarNTBS(length: number): string;
|
|
17
19
|
nextVersion(reverse?: boolean): VexFirmwareVersion;
|
|
18
20
|
}
|