Constructor
new SignalKPlugin(app, id, name, description)
Constuctor for the base SignalK Plugin class. This may be called the normal way by using
parameter positions to specify the plugin definition,
or alternatively using a pseudo 'call by name' where
the first parameter is an object, and each property name of the object matches
the corresponding parameter name.
Parameters:
Name | Type | Description |
---|---|---|
app |
object | The ExpressJS app object that was passed from the SignalK server to the plugin factory function |
id |
string | Uniquely identifies this plugin. Usually in the form "signalk-some-plugin" |
name |
string | Human readable name/title of this plugin |
description |
string | A brief description of what this plugin does |
- Source:
Methods
debug(msg)
Outputs a debug message for this plugin. The message will be visible on the
console if DEBUG environment variable is set to this plugin's id.
Parameters:
Name | Type | Description |
---|---|---|
msg |
string | The message to display on the console output |
- Source:
elapsedSecs(t1, t2opt)
Returns the number of whole seconds that have elapsed between
time t1 and time t2 (both assumed to be the UTC time retrieved via
this.getTime()). If t2 is unspecified, the current time is assumed.
If t1 is greater than t2, a negative number will be returned.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
t1 |
number | A UTC millisecond value retrieved via this.getTime() | ||
t2 |
number |
<optional> |
this.getTime() | A UTC millisecond value retrieved via this.getTime() |
- Source:
getSKBus(skPath, allContextsopt)
Returns a BaconJS stream that produces the deltas for the specified
SignalK path. If allContexts is specified as TRUE, the bus will
be for ALL contexts. Otherwise, that data will be restricted to
"self" (i.e. data for the boat's "self" context)
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
skPath |
string | The SK path to receive, or unspecified for ALL data | ||
allContexts |
boolean |
<optional> |
false | TRUE to get ALL vessels data. unspecified or FALSE implies you want just the data for the current vessel. |
- Source:
getSKValues(skPath)
Similar to getSKBus() except the data producsed by the BaconJS stream
will be limited to the "value" property of the data, vs. the entire delta.
Parameters:
Name | Type | Description |
---|---|---|
skPath |
string | The SK path to receive, or unspecified for ALL data |
- Source:
getTime()
Returns the current time in milliseconds. Call this
whenever the current time is needed. External unit tests
may monkey patch this method to return a simulated time of
day while the tests are running.
- Source:
onPluginStarted()
Called once the plugin has started and all options have been resolved. Normally, this
creates the BaconJS data streams and properties used by this plugin and subscribes
to them.
- Source:
- See:
-
- start
onPluginStopped()
Called when the plugin is to stop running.
- Source:
- See:
-
- stop
optBool(propName, title, defaultValopt, isArrayopt, longDescriptionopt)
Defines a boolean configuration option that the user can set. The specified propName
will appear as a property in this._schema, and will have a default value of defaultVal.
This method may be called the normal way by using parameter positions to specify
your option definition, or alternatively using a pseudo 'call by name' where
the first parameter is an object, and each property name of the object matches
the corresponding parameter name.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
propName |
string | The name of the property variable used for this option | ||
title |
string | A label that describes this option (short form) | ||
defaultVal |
boolean |
<optional> |
false | The default value to use for this option |
isArray |
boolean |
<optional> |
false | TRUE if this option is actually an array of booleans |
longDescription |
string |
<optional> |
An optional long description of this option |
- Source:
optInt(propName, title, defaultValopt, isArrayopt, longDescriptionopt, requiredopt)
Defines an interger configuration option that the user can set. The specified propName
will appear as a property in this._schema, and will have a default value of defaultVal.
This method may be called the normal way by using parameter positions to specify
your option definition, or alternatively using a pseudo 'call by name' where
the first parameter is an object, and each property name of the object matches
the corresponding parameter name.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
propName |
string | The name of the property variable used for this option | ||
title |
string | A label that describes this option (short form) | ||
defaultVal |
integer |
<optional> |
0 | The default value to use for this option |
isArray |
boolean |
<optional> |
false | TRUE if this option is actually an array of integers |
longDescription |
string |
<optional> |
An optional long description of this option | |
required |
boolean |
<optional> |
false | If TRUE, this property must be given a positive non-zero value |
- Source:
optNum(propName, title, defaultValopt, isArrayopt, longDescriptionopt, requiredopt)
Defines a numeric configuration option that the user can set. The specified propName
will appear as a property in this._schema, and will have a default value of defaultVal.
This method may be called the normal way by using parameter positions to specify
your option definition, or alternatively using a pseudo 'call by name' where
the first parameter is an object, and each property name of the object matches
the corresponding parameter name.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
propName |
string | The name of the property variable used for this option | ||
title |
string | A label that describes this option (short form) | ||
defaultVal |
number |
<optional> |
0 | The default value to use for this option |
isArray |
boolean |
<optional> |
false | TRUE if this option is actually an array of numbers |
longDescription |
string |
<optional> |
An optional long description of this option | |
required |
boolean |
<optional> |
false | If TRUE, this property must be given a positive non-zero value |
- Source:
optObj(propName, title, isArrayopt, longDescriptionopt, itemTitleopt)
Defines configuration option that is itself an object of other properties that the user can set.
The specified propName will appear as a property in this._schema. Once this method is called,
all other calls to the optXXX() definition methods will place those properties in this
object. This will continue until optObjEnd() is called. You MUST call optObjEnd() when
the object definition has been completed.
This method may be called the normal way by using parameter positions to specify
your option definition, or alternatively using a pseudo 'call by name' where
the first parameter is an object, and each property name of the object matches
the corresponding parameter name.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
propName |
string | The name of the property variable used for this option | ||
title |
string | A label that describes this option (short form) | ||
isArray |
boolean |
<optional> |
false | TRUE if this option is actually an array of the defined object |
longDescription |
string |
<optional> |
An optional long description of this option | |
itemTitle |
string |
<optional> |
If the isArray param is TRUE, this is the optional title of an individual element in the array. |
- Source:
- See:
-
- optObjEnd
optObjEnd()
Call this method to end the definition of an object property.
- Source:
- See:
-
- optObj
optStr(propName, title, defaultValopt, isArrayopt, longDescriptionopt, requiredopt)
Defines a string configuration option that the user can set. The specified propName
will appear as a property in this._schema, and will have a default value of defaultVal.
This method may be called the normal way by using parameter positions to specify
your option definition, or alternatively using a pseudo 'call by name' where
the first parameter is an object, and each property name of the object matches
the corresponding parameter name.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
propName |
string | The name of the property variable used for this option | ||
title |
string | A label that describes this option (short form) | ||
defaultVal |
string |
<optional> |
'' | The default value to use for this option |
isArray |
boolean |
<optional> |
false | TRUE if this option is actually an array of strings |
longDescription |
string |
<optional> |
An optional long description of this option | |
required |
boolean |
<optional> |
false | If TRUE, this property must be given a non-blank value |
- Source:
restart()
Restarts this plugin by calling the "restartPlugin" function that was
passed to the start() method.
- Source:
schema()
Returns a Json Schema that defines the user configurable options that this plugin utilizes.
You can define the value of this schema by calling the various
optXXX()
methods in
this class, or you can define the Json schema manually and assign it to the
this._schema
variable. A third alternative is to override this method in your
derived class and have it return the Json Schema in any way you see fit.
- Source:
sendSK(skPath, value)
Sends a single value SignalK delta thru the server and out to all external
subscribers. To send more than one value at a time, use sendSKValues()
Parameters:
Name | Type | Description |
---|---|---|
skPath |
string | The SignalK path that corresponds to the value |
value |
any | The actual value to send out |
- Source:
- See:
sendSKValues(values)
Sends the specified array of path value objects as a SignalK delta thru the
server and out to all external subscribers.
Parameters:
Name | Type | Description |
---|---|---|
values |
array | An array of one or more objects with each element being in the format { path: "signal.k.path", value: "someValue" } |
- Source:
- See:
setError(msg)
Used to indicate an error has occurred in the pluging. The specified msg
will appear on the server admin app
Parameters:
Name | Type | Description |
---|---|---|
msg |
string |
- Source:
setStatus(msg)
Sets the status of this plugin, placing msg on the server admin app.
Parameters:
Name | Type | Description |
---|---|---|
msg |
string |
- Source:
start()
Called when the plugin starts. Descendant classes can override, but
should call super.start() if they do. Overriding is normally not necessary
as extensions to this method are generally placed in onPluginStarted()
- Source:
- See:
-
- onPluginStarted
stop()
Called when the plugin stops. Cleanup occurs here, including
unsubscribing from any data paths. If you override this, be
sure to call super.stop(). Extensions are usually instead
placed in onPluginStopped().
- Source:
- See:
-
- onPluginStopped
subscribeVal(strm, f, selfopt)
'Subscribes' function f to the stream strm, adding its 'unsubscribe' function
to the unsub list.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
strm |
Bacon.Stream | |||
f |
function | Any function or method from an object. If f is a method from an object other than 'this', be sure to pass the self parameter. | ||
self |
object |
<optional> |
this | Option parameter to specify the 'this' object that f should be bound to. Self must be specified if f is a method of an object other than 'this' plugin object. |
- Source:
wildcardEq(testVal, matchVal)
Returns TRUE if the specified test value matches the specified matchVal. An
empty matchVal is a wildcard that matches any value of testVal. This method
is useful for matching optional configuration values to stream filters.
Parameters:
Name | Type | Description |
---|---|---|
testVal |
string | The current value you are testing |
matchVal |
string | The value testVal is to match. If matchVal is empty, testvVal ALWAYS matches |
- Source:
Returns:
TRUE if testVal == matchVal, or if matchVal is empty/blank