@canboat/canboatjs
Version:
Native javascript version of canboat
40 lines • 1.31 kB
TypeScript
/**
* Minimal CAN socket wrapper using fs streams instead of uv_poll_t.
*
* The native addon (native/canSocket.cpp) opens a PF_CAN socket, binds it
* to the interface, and returns the raw fd in blocking mode.
*
* Node.js's net.Socket cannot wrap CAN fds (uv_guess_handle returns
* UV_UNKNOWN_HANDLE). Instead we use fs.createReadStream which uses libuv's
* threadpool-based uv_fs_read — works on any fd, never stalls, and does not
* use uv_poll_t. Writes use a native non-blocking writeCanFrame() to avoid
* blocking libuv threadpool workers when the CAN bus has no listeners.
*
* Copyright 2025 Signal K contributors
* Licensed under the Apache License, Version 2.0
*/
import { EventEmitter } from 'events';
export interface CanMessage {
id: number;
data: Buffer;
}
/**
* Drop-in replacement for socketcan's channel object.
* Same API: addListener('onMessage'), addListener('onStopped'),
* start(), stop(), send(), removeAllListeners().
*/
export declare class CanChannel extends EventEmitter {
private readStream;
private fd;
private remainder;
private stopped;
constructor(ifname: string);
start(): void;
stop(): void;
send(msg: {
id: number;
ext?: boolean;
data: Buffer;
}): void;
}
//# sourceMappingURL=canSocket.d.ts.map