Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// tslint:disable:readonly-keyword
import bindings from 'bindings'
import debug from 'debug'
import { promisify } from './util'
import { AbstractBinding, PortInfo, OpenOptions, ConstructorOptions, LocalState, RemoteState, SetOptions } from '@serialport/binding-abstract'
import { serialNumParser } from './win32-sn-parser'
const logger = debug('serialport/bindings/WindowsBinding')
const windowsBinding = bindings('bindings.node')
const closeAsync = promisify(windowsBinding.close) as (descriptor: number) => Promise
const drainAsync = promisify(windowsBinding.drain) as (descriptor: number) => Promise
const flushAsync = promisify(windowsBinding.flush) as (descriptor: number) => Promise
const getRemoteStateAsync = promisify(windowsBinding.getRemoteState) as (descriptor: number) => Promise
const openAsync = promisify(windowsBinding.open) as (opt: LocalState) => Promise
const setLocalStateAsync = promisify(windowsBinding.setLocalState) as (descriptor: number, opts: SetOptions) => Promise
const listAsync = promisify(windowsBinding.list) as () => Promise>
const readAsync = promisify(windowsBinding.read) as (descriptor: number, buffer: Buffer, offset: number, length: number) => Promise
const writeAsync = promisify(windowsBinding.write) as (descriptor: number, buffer: Buffer) => Promise
/**
* The Windows binding layer
*/
export class WindowsBinding implements AbstractBinding {
static async list() {
const ports = await listAsync()
import bindings from 'bindings'
import { EventEmitter } from 'events'
import fs from 'fs'
const MMapNBSPlayer = bindings('nbs_player') as MMapNBSPlayerConstructor
export type NBSPacket = {
timestamp: number
hash: Buffer
payload: Buffer
}
export class NBSPlayer {
private readonly player: MMapNBSPlayer
private readonly emitter: EventEmitter = new EventEmitter()
private constructor(private file: string) {
this.player = new MMapNBSPlayer(file, this.onNBSPacket)
}
import { unixRead } from './unix-read'
import { unixWrite } from './unix-write'
const logger = debug('serialport/bindings/DarwinBinding')
interface DarwinConstructorOptions extends ConstructorOptions {
vmin: number
vtime: number
}
interface DarwinOpenOptions extends OpenOptions {
vmin?: number
vtime?: number
}
const darwinBindings = bindings('bindings.node')
const closeAsync = promisify(darwinBindings.close) as (fd: number) => Promise
const drainAsync = promisify(darwinBindings.drain) as (fd: number) => Promise
const flushAsync = promisify(darwinBindings.flush) as (fd: number) => Promise
const getRemoteStateAsync = promisify(darwinBindings.getRemoteState) as (descriptor: number) => Promise
const openAsync = promisify(darwinBindings.open) as (opt: LocalState) => Promise
const setLocalStateAsync = promisify(darwinBindings.setLocalState) as (descriptor: number, opts: SetOptions) => Promise
const listAsync = promisify(darwinBindings.list) as () => Promise>
/**
* The Darwin binding layer for OSX
*/
export class DarwinBinding implements AbstractBinding {
static list() {
return listAsync()
}
import { unixRead } from './unix-read'
import { unixWrite } from './unix-write'
const logger = debug('serialport/bindings/LinuxBinding')
interface LinuxConstructorOptions extends ConstructorOptions {
vmin: number
vtime: number
}
interface LinuxOpenOptions extends OpenOptions {
vmin?: number
vtime?: number
}
const linuxBindings = bindings('bindings.node')
const closeAsync = promisify(linuxBindings.close) as (fd: number) => Promise
const drainAsync = promisify(linuxBindings.drain) as (fd: number) => Promise
const flushAsync = promisify(linuxBindings.flush) as (fd: number) => Promise
const getRemoteStateAsync = promisify(linuxBindings.getRemoteState) as (descriptor: number) => Promise
const openAsync = promisify(linuxBindings.open) as (opt: LocalState) => Promise
const setLocalStateAsync = promisify(linuxBindings.setLocalState) as (descriptor: number, opts: SetOptions) => Promise
/**
* The linux binding layer
*/
export class LinuxBinding implements AbstractBinding {
static list() {
return linuxList()
}
static async open(options: LinuxOpenOptions) {