@canboat/canboatjs
Version:
Native javascript version of canboat
46 lines • 1.62 kB
TypeScript
/**
* Minimal CAN socket wrapper using uv_poll_t-based reads.
*
* The native addon (native/canSocket.cpp) opens PF_CAN sockets in non-blocking
* mode and exposes a CanPoller class that registers a uv_poll_t watcher on the
* read fd. When frames are readable, the watcher invokes a JS callback that
* drains all available frames via a non-blocking native read. Writes also use
* a non-blocking native write so neither direction ever occupies a libuv
* threadpool worker — this keeps the threadpool free for fs operations and
* lets process.exit() terminate cleanly without hanging on a blocked syscall.
*
* Reads and writes use separate CAN sockets bound to the same interface:
* the read socket has the default (full) RX filter, the write socket has an
* empty RX filter so the kernel doesn't queue frames into a buffer nobody
* reads.
*
* 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 readFd;
private writeFd;
private poller;
private stopped;
private exitHandler;
constructor(ifname: string);
start(): void;
private onReadable;
stop(): void;
send(msg: {
id: number;
ext?: boolean;
data: Buffer;
}): void;
}
//# sourceMappingURL=canSocket.d.ts.map