Commander

Commander

Issues commands to control a traffic light.

Constructor

new Commander(optionsopt)

Source:

Creates a new Commander instance.

Parameters:
Name Type Attributes Description
options object <optional>

Commander options.

Properties
Name Type Attributes Default Description
logger object <optional>
console

A Console-like object for logging, with a log and an error function.

formatter commands.MetaFormatter <optional>

A formatter for the help text of a command.

interpreter commands.Interpreter <optional>

The Command Interpreter to use.

selector object <optional>

The traffic light selector to use. Takes precedence over options.SelectorCtor.

SelectorCtor function <optional>

The constructor of a traffic light selector to use. Will be passed the entire options object. Ignored if options.selector is set.

Members

commandNames :Array.<string>

Source:

All supported command names.

Type:
  • Array.<string>

commands :object.<string, commands.Command>

Source:

All supported commands indexed by their names.

Type:

Methods

(static) multi(optionsopt) → {Commander}

Source:

Factory for a Commander that deals with multiple physical traffic lights. It will greedily get all available traffic lights for use.

Parameters:
Name Type Attributes Description
options object <optional>

Commander options.

Properties
Name Type Attributes Default Description
logger object <optional>
console

A Console-like object for logging, with a log and an error function.

formatter commands.MetaFormatter <optional>

A formatter for the help text of a command.

interpreter commands.Interpreter <optional>

The Command Interpreter to use.

manager physical.DeviceManager <optional>

The physical Device Manager to use.

Returns:

A multiple traffic lights commander.

Type
Commander

(static) single(optionsopt) → {Commander}

Source:

Factory for a Commander that deals with a single physical traffic light. It will get the first available traffic light for use.

Parameters:
Name Type Attributes Description
options object <optional>

Commander options.

Properties
Name Type Attributes Default Description
logger object <optional>
console

A Console-like object for logging, with a log and an error function.

formatter commands.MetaFormatter <optional>

A formatter for the help text of a command.

interpreter commands.Interpreter <optional>

The Command Interpreter to use.

manager physical.DeviceManager <optional>

The Device Manager to use.

serialNum string | number <optional>

The serial number of the traffic light to use, if available. Cleware USB traffic lights have a numeric serial number.

Returns:

A single traffic light commander.

Type
Commander

cancel()

Source:

Cancels any currently executing command.

close()

Source:

Called to close this instance. Should be done as the last operation before exiting the process.

help(commandName)

Source:

Logs the help info for the given command name.

Parameters:
Name Type Description
commandName string

Name of the command to log help info.

logInfo()

Source:

Logs information about known traffic lights.

(async) run(command, resetopt)

Source:

Executes a command asynchronously. If the same command is already running, does nothing. If another command is running, cancels it, resets the traffic light, and runs the new command. If no command is running, executes the given command, optionally resetting the traffic light based on the reset parameter. If there's no traffic light to run the command, stores it for later when one becomes available. Logs messages appropriately.

Parameters:
Name Type Attributes Default Description
command string

Command to execute.

reset boolean <optional>
false

Whether to reset the traffic light before executing the command.

(async) runDefinitions(command)

Source:

Executes a command with definitions asynchronously.

Parameters:
Name Type Description
command string

Command to execute. Should only contain command definitions (define or def).

(async) runDefinitionsFile(filePath, encodingopt)

Source:

Executes a file with command definitions asynchronously.

Parameters:
Name Type Attributes Default Description
filePath string

Path to the file to execute. Should only contain command definitions (define or def).

encoding string <optional>
'utf8'

Encoding of the file.

(async) runFile(filePath, resetopt, encodingopt)

Source:

Executes a command file asynchronously. If the same command is already running, does nothing. If another command is running, cancels it, resets the traffic light, and runs the new command. If no command is running, executes the given command, optionally resetting the traffic light based on the reset parameter. If there's no traffic light to run the command, stores it for later when one becomes available. Logs messages appropriately.

Parameters:
Name Type Attributes Default Description
filePath string

Path to the file to execute.

reset boolean <optional>
false

Whether to reset the traffic light before executing the command.

encoding string <optional>
'utf8'

Encoding of the file.