new Bridge()
The base bridge class used to create a bridge.
The adapter directory should contain your adapters index.jse, commands
directory, and responses directory. See Adapter for details.
Example:
const bridge = require('k4-base-bridge');
const path = require('path');
const K4 = require('k4');
const k4 = new K4({
url: 'auto'
});
const opts = {
k4: k4,
id: 'networkId',
transport: {
name: 'udp',
protocol: 'udp6',
receiver: {
port: 10000,
protocol: 'udp6'
}
},
adapter: {
file: path.resolve('./adapter/index.jse'),
sequencer: {
max: 255,
min: 0,
start: 'random'
}
}
};
bridge.start(opts);
Members
adapter :Adapter
The adapter instance
Type:
classes :classesObj
Contains the base bridge classes
Type:
devices :Object
Contains the devices that the module found in K4Model
Type:
- Object
k4 :Object
The K4Model instance
Type:
- Object
Methods
(private) buildDevice(node)
Constructs device from K4Model device node
Parameters:
| Name | Type | Description |
|---|---|---|
node |
Object | K4Model device node |
(private) createTransport() → {Promise}
Creates the specified transport
Returns:
- Type
- Promise
(private) execute(data, callback)
Handles execute commands from device node
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Object | Data from execute command |
callback |
function | The K4Model callback |
(private) getDevice(id) → {Device}
Get a device by id
Parameters:
| Name | Type | Description |
|---|---|---|
id |
String | The device id |
Returns:
- Type
- Device
(private) loadClasses()
Loads the base bridges classes
(private) ready() → {Promise}
Ready handler for K4Model
Returns:
- Type
- Promise
(private) reloadDevices() → {Promise}
Recreates devices list when K4Model ready event fires
Returns:
- Type
- Promise
(private) restoreDeviceModelVarsFromCache() → {Promise}
Restores last-known K4Model variable values for devices
Returns:
- Type
- Promise
(private) send(address, command) → {Promise}
Forwards command instances to the transport
Parameters:
| Name | Type | Description |
|---|---|---|
address |
String | Object | Address for the transport |
command |
Command | The command to send |
Returns:
- Type
- Promise
(async) start(opts) → {Promise}
Starts the bridge
Parameters:
| Name | Type | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts |
Object |
Properties
|
Returns:
- Type
- Promise