Skip to main content

api

Classes

Device

The base class for all devices, holds some information about the device and provides basic functionality

Transceiver

The base transceiver class. Polls for VFO frequencies by default. Subclasses need to implement VFO get/set commands as that is what defines a transceiver.

Driver

A driver connects a device to a real physical device. This is the base class for all drivers.

WebUSBDriver

Drivers for the WebUSB API supported by chromium based browsers

CP210xWebUSBDriver

A rudimentary WebUSB based driver for CP210x devices by Silicon Labs used e.g. in some Yaesu transceivers.

WebSerialDriver

A WebSerial based driver for Chromium browsers.

DummyDriver

A dummy driver that never reads any data and that doesn't write anything.

LogDriver

An internal driver that wraps another driver and decorates the write function and data observable to capture logs.

SerialPortDriver

A driver for the Node SerialPort library.

WebSocketDriver

A driver that receives data from websockets and writes to websockets as well.

Members

DeviceType

The different device types implemented in ham-js, currently only Transceiver is really in use.

AGCAttack

A value for the AGC attack time.

AntennaTunerState

The state of the antenna tuner, can be on/off and tuning.

Direction

A generic direction enum, used e.g. for navigating device menus via commands.

TransceiverEventType

The different types of transceiver events

TransceiverVendor

The different vendors of transceivers

VFOType

The different VFO types of transceivers

DriverType

The different driver types. Every driver class uses its own type. It is used for introspection and validation of supported drivers on devices at runtime.

Constants

Bands

The amateur radio bands supported by devices.

CTCSSFrequencies

All available CTCSS frequencies.

Functions

command(schemaShape)function

Declare a method on a Device as a command: handles logging, input validation and introspection.

device(schemaShape)object

This decorator is useful for devices which receive a second (object) parameter when constructed (e.g. ICOM devices need a controller and device address).

supportedDrivers(supportedDrivers)object

This decorator allows to define the drivers this device supports. For introspection reasons we use an enum here. If not used the device supports all available drivers. Hint: You can use the convenience arrays of drivers, such as DeviceAgnosticDriverTypes.

delimiterParser(source, delimiter)Observable

A utility that groups emissions of a source observable which are delimited by a certain delimiter.

fromLittleEndianBCD(input)number

Convert an input in little endian BCD to number

getDigit(input, n)number

Get the n-th digit of a (integer) number

getNumberOfDigits(input)number

Get the number of digits of an integer number

padBytesEnd(input, length)Uint8Array

Pad an input with zero bytes until it reaches a certain length

parseResponse(input, parser, formatter, distinctKey)Observable

Parses an input observable into some kind of value, formats it iff it's not null/undefined, optionally only emits distinct elements and sets a timestamp on its emissions. This is mostly used for device events, e.g. VFO frequency changes coming from a transceiver "event bus" which potentially contains different events.

poll(observableFactory, distinctKey, interval)Observable

Polls an observable factory (usually a function returning a promise) every n ms and emits values including a timestamp Note: The observable returned by this utility wait for calls to the factory to return. It is not guaranteed to return a value every n ms.

toLittleEndianBCD(input)Uint8Array

Converts an input number to BCD in little endian byte order.

invertMap(input)Map

A type safe utility to invert a JavaScript Map.

oneOf(ary)z.Schema

a zod utility to validate inclusion of a value in an array

Device

The base class for all devices, holds some information about the device and provides basic functionality

Kind: global class

new Device(driver, parameter)

The constructor for devices, which always (also in subclasses) takes this shape to allow for introspection and type-safety at runtime and buildtime.

ParamTypeDescription
driverDriver

The driver this device uses to communicate with a real physical device.

parameterobject

Optional additional parameters this device needs to function properly, such as target device addresses etc.. This is described using the @device decorater and can be introspected at runtime using deviceSchema.

device.responseTimeout

The response timeout used by readResponse

Kind: instance property of Device

device.data

The optional device data from which readResponse reads after writing a command to the driver.

Kind: instance property of Device

device.events

The optional events coming from a device (such as Yaesu TRX which have "Auto Information" which automatically sends data to the computer when anything changes).

Kind: instance property of Device

device.driverLog ⇒ Observable | undefined

When a device is opened with logDriver: true this returns the driver log.

Kind: instance property of Device
Returns: Observable | undefined -

the driver log which contains all messages written through the driver to a real physical device

device.deviceLog ⇒ Observable | undefined

When a device is opened with logDevice: true this returns the device log.

Kind: instance property of Device
Returns: Observable | undefined -

the device log which contains all calls to commands and their parameters and timestamps.

device.isOpen ⇒ boolean

Whether the device is open. By default this delegates to the driver.

Kind: instance property of Device
Returns: boolean -

Whether this device is open for calling commands.

device.open(config)

Open the device for executing commands, reading data and subscribing to events. By defaults this delegates to the driver and handles setting up logging.

Kind: instance method of Device

ParamTypeDescription
configobject

the open configuration

config.logDriverboolean

Whether the device should log driver calls

config.logDeviceboolean

Whether the device should log command calls

config.logboolean

Whether the device should log both

device.close()

Close the device for executing commands, reading data and subscribing to events.

Kind: instance method of Device

device.getCommandSchema(command) ⇒ object

Get the command schema for a given command

Kind: instance method of Device
Returns: object -

The JSON schema describing the object parameter for that command

ParamTypeDescription
commandstring

the key of a command method

device.getCommands() ⇒ Array.<string>

Get all keys of implemented commands.

Kind: instance method of Device
Returns: Array.<string> -

An array containing all the keys of commands this device implements.

device.readResponse(command, mapFn, responseTimeout) ⇒ Promise

Convenience method to write a command and wait for a specific response from the real physical device. Handles timeouts as well. Needs the data property and DataType type parameter to be defined.

Kind: instance method of Device
Returns: Promise -

A promise that resolves with the first value the mapFn returns that is not null/undefined and rejects when a timeout happens.

ParamTypeDescription
commandUint8Array | string

the command to write

mapFnfunction

A function which is called with responses after the command was written. Should return null or undefined for responses that are not of interest.

responseTimeoutnumber

An optional response timeout in ms, overrides the responseTimeout defined on the device.

Device.deviceSchema ⇒ object

The optional device schema of the device. This is used for devices which need additional parameters to be instantiated, such as the controller/device address in the case of ICOM devices.

Kind: static property of Device
Returns: object -

The JSON schema describing the second parameter to the constructor.

Device.displayName ⇒ string

Convenience method to get the display name of the device.

Kind: static property of Device
Returns: string -

the concatenated device vendor and device name

Device.supportedDrivers ⇒ Array.<DriverType>

Get the supported driver (types) of the device, default is all members of DriverType.

Kind: static property of Device
Returns: Array.<DriverType> -

An array of driver types this device supports (trying to instantiate a device with a non-supported driver results in an error).

Transceiver

The base transceiver class. Polls for VFO frequencies by default. Subclasses need to implement VFO get/set commands as that is what defines a transceiver.

Kind: global class

transceiver.getVFOFrequency(parameter) ⇒ Promise.<number>

Get the frequency of the specified VFO.

Kind: instance method of Transceiver
Returns: Promise.<number> -

A promise resolving to the frequency of the specified VFO

ParamTypeDescription
parameterobject

The vfo configuration which which to return the frequency

parameter.vfoVFOType

The vfo for which to return the frequency

transceiver.setVFOFrequency(parameter)

Set the frequency of the specified VFO.

Kind: instance method of Transceiver

ParamTypeDescription
parameterobject

The vfo configuration which which to set the frequency

parameter.vfoVFOType

The vfo for which to set the frequency

parameter.frequencynumber

The frequency to which to set the VFO

Driver

A driver connects a device to a real physical device. This is the base class for all drivers.

Kind: global class

driver.textEncoder

The default text encoder of the driver. Overwrite this for custom string encodings.

Kind: instance property of Driver

driver.isOpen ⇒ boolean

Returns whether the driver is open for reading and writing.

Kind: instance property of Driver
Returns: boolean -

Whether this driver is open

driver.stringData(encoding, options) ⇒ Observable.<string>

Get the data of the driver as utf-8 observable.

Kind: instance method of Driver
Returns: Observable.<string> -

An observable of strings based on the Uint8Array-based data property

ParamTypeDefaultDescription
encodingstring"utf-8"

The encoding of the text decoder used on emissions of the data property

optionsobject

Options for the text decoder

driver.writeString(data) ⇒ void | Promise.<void>

Convenience method to write strings instead of bytes to the real physical device. This method uses the protected textEncoder property to encode the input string to bytes.

Kind: instance method of Driver
Returns: void | Promise.<void> -

A promise that resolves after the data was written, or void if the write method doesn't return a promise

ParamTypeDescription
datastring

The data to write

WebUSBDriver

Drivers for the WebUSB API supported by chromium based browsers

Kind: global class

webUSBDriver.deviceFilters

The device filters supported by this driver. Can be handed directly to requestDevice in order to only show supported devices.

Kind: instance property of WebUSBDriver

CP210xWebUSBDriver

A rudimentary WebUSB based driver for CP210x devices by Silicon Labs used e.g. in some Yaesu transceivers.

Kind: global class

WebSerialDriver

A WebSerial based driver for Chromium browsers.

Kind: global class

new WebSerialDriver(serialPort, options)

The constructor for the web serial driver

ParamTypeDescription
serialPortobject

a serial port returned by requestPort

optionsobject

Options used for opening the serial port (such as baudRate)

DummyDriver

A dummy driver that never reads any data and that doesn't write anything.

Kind: global class

LogDriver

An internal driver that wraps another driver and decorates the write function and data observable to capture logs.

Kind: global class

SerialPortDriver

A driver for the Node SerialPort library.

Kind: global class

new SerialPortDriver(serialPort, timeout)

The constructor for the node serial port driver. Make sure to hand in a serial port that is not opened yet and has autoOpen set to false.

ParamTypeDefaultDescription
serialPortSerialPortStream

A not-yet-open serial port (make sure to set autoOpen to false.

timeoutnumber1000

A timeout used for writing to the serial port

WebSocketDriver

A driver that receives data from websockets and writes to websockets as well.

Kind: global class

DeviceType

The different device types implemented in ham-js, currently only Transceiver is really in use.

Kind: global variable

AGCAttack

A value for the AGC attack time.

Kind: global variable

AntennaTunerState

The state of the antenna tuner, can be on/off and tuning.

Kind: global variable

Direction

A generic direction enum, used e.g. for navigating device menus via commands.

Kind: global variable

TransceiverEventType

The different types of transceiver events

Kind: global variable

TransceiverVendor

The different vendors of transceivers

Kind: global variable

VFOType

The different VFO types of transceivers

Kind: global variable

DriverType

The different driver types. Every driver class uses its own type. It is used for introspection and validation of supported drivers on devices at runtime.

Kind: global variable

Bands

The amateur radio bands supported by devices.

Kind: global constant

CTCSSFrequencies

All available CTCSS frequencies.

Kind: global constant

command(schemaShape) ⇒ function

Declare a method on a Device as a command: handles logging, input validation and introspection.

Kind: global function
Returns: function -

The decorated method

ParamTypeDescription
schemaShapeobject

An object describing a zod schema (not a schema itself, but what you pass to z.object(...))

device(schemaShape) ⇒ object

This decorator is useful for devices which receive a second (object) parameter when constructed (e.g. ICOM devices need a controller and device address).

Kind: global function
Returns: object -

The decorated class

ParamTypeDescription
schemaShapeobject

An object describing a zod schema (not a schema itself, but what you pass to z.object(...))

supportedDrivers(supportedDrivers) ⇒ object

This decorator allows to define the drivers this device supports. For introspection reasons we use an enum here. If not used the device supports all available drivers. Hint: You can use the convenience arrays of drivers, such as DeviceAgnosticDriverTypes.

Kind: global function
Returns: object -

the decorated class

ParamTypeDescription
supportedDriversArray.<DriverType>

the supported drivers in form of the DriverType associated with them

delimiterParser(source, delimiter) ⇒ Observable

A utility that groups emissions of a source observable which are delimited by a certain delimiter.

Kind: global function
Returns: Observable -

A new observable which emits parsed emissions of the source observable

ParamTypeDescription
sourceObservable

The source observable

delimiterstring | number

The delimiter for which the parser looks

Example

const source = of("F", "A", "14", "350", "000;")
const parsed = delimiterParser(source, ";")
parsed.subscribe(console.log) // "FA14350000;"

fromLittleEndianBCD(input) ⇒ number

Convert an input in little endian BCD to number

Kind: global function
Returns: number -

The number described by the input data

ParamTypeDescription
inputUint8Array

data formatted in little endian BCD

getDigit(input, n) ⇒ number

Get the n-th digit of a (integer) number

Kind: global function
Returns: number -

the digit at index n of the input number

ParamTypeDescription
inputnumber

the input number

nnumber

the index of the digit to return

getNumberOfDigits(input) ⇒ number

Get the number of digits of an integer number

Kind: global function
Returns: number -

The number of digits of the input number

ParamTypeDescription
inputnumber

The input number

padBytesEnd(input, length) ⇒ Uint8Array

Pad an input with zero bytes until it reaches a certain length

Kind: global function
Returns: Uint8Array -

the input data padded with zero bytes at the end (or the input data itself if it already had the appropriate length)

ParamTypeDescription
inputUint8Array

Input data

lengthnumber

the length in bytes the output should be long

parseResponse(input, parser, formatter, distinctKey) ⇒ Observable

Parses an input observable into some kind of value, formats it iff it's not null/undefined, optionally only emits distinct elements and sets a timestamp on its emissions. This is mostly used for device events, e.g. VFO frequency changes coming from a transceiver "event bus" which potentially contains different events.

Kind: global function
Returns: Observable -

an observable which emits parsed and formatted values based on the params

ParamTypeDescription
inputObservable

an input observable

parserfunction

a function which takes an emission from the input observable and parses it into something the formatter understands or null/undefined which terminates processing of this event

formatterfunction

a function which takes in what the parser returned and formats it to be something a consumer understands

distinctKeystring

an optional key of the object the formatter returned. If two consecutive emissions have the same key the returned observable will not emit again.

Example

return trxData
.pipe(
parseResponse(
response$,
this.parseTrxEvent, // e.g. reads bytes into an object describing the device state, containing frequency, mode, ...
(trxEvent) => ({ frequency: trxEvent.frequency }),
"frequency"
)
)

poll(observableFactory, distinctKey, interval) ⇒ Observable

Polls an observable factory (usually a function returning a promise) every n ms and emits values including a timestamp Note: The observable returned by this utility wait for calls to the factory to return. It is not guaranteed to return a value every n ms.

Kind: global function
Returns: Observable -

An observable that emits with every finished poll call to observable factory

ParamTypeDefaultDescription
observableFactoryfunction

a function to poll

distinctKeystring

a key which needs to change in order for the returned observable to emit

intervalnumber500

the minimum amount of milliseconds for which to repeat the call to observableFactory

Example

const $freq = poll(async () => ({ frequency: await getFrequency() }), "frequency")
$freq.subscribe(console.log)

toLittleEndianBCD(input) ⇒ Uint8Array

Converts an input number to BCD in little endian byte order.

Kind: global function
Returns: Uint8Array -

the BCD representation of the input number in little endian byte order

ParamTypeDescription
inputnumber

The input number

invertMap(input) ⇒ Map

A type safe utility to invert a JavaScript Map.

Kind: global function
Returns: Map -

The inverted map (type-safe)

ParamTypeDescription
inputMap

The input map to invert

oneOf(ary) ⇒ z.Schema

a zod utility to validate inclusion of a value in an array

Kind: global function
Returns: z.Schema -

A zod schema describing the validation

ParamTypeDescription
aryArray

The array in which the valud should be included.