|
|
|
## Modules
|
|
|
|
|
|
|
|
<dl>
|
|
|
|
<dt><a href="#module_motorcortex">motorcortex</a></dt>
|
|
|
|
<dd><p>Motorcortex Bindings for JavaScript</p>
|
|
|
|
</dd>
|
|
|
|
</dl>
|
|
|
|
|
|
|
|
## Classes
|
|
|
|
|
|
|
|
<dl>
|
|
|
|
<dt><a href="#Connection">Connection</a></dt>
|
|
|
|
<dd><p>Class represents a connection to motorcortex server</p>
|
|
|
|
</dd>
|
|
|
|
<dt><a href="#MessageTypes">MessageTypes</a></dt>
|
|
|
|
<dd><p>Class for handling motorcortex data types, load proto files and hash files,
|
|
|
|
creates a dictionary with all available data types, resolves data types by,
|
|
|
|
name or by hash, performs encoding and decoding of the messages.</p>
|
|
|
|
</dd>
|
|
|
|
<dt><a href="#Request">Request</a></dt>
|
|
|
|
<dd><p>Request/Reply communication is used to send commands to a motorcortex server.</p>
|
|
|
|
</dd>
|
|
|
|
<dt><a href="#Timestamp">Timestamp</a></dt>
|
|
|
|
<dd><p>Timestamp of the parameter</p>
|
|
|
|
</dd>
|
|
|
|
<dt><a href="#Parameter">Parameter</a></dt>
|
|
|
|
<dd><p>Parameter value with a timestamp</p>
|
|
|
|
</dd>
|
|
|
|
<dt><a href="#Subscription">Subscription</a></dt>
|
|
|
|
<dd><p>Subscription class receives updates from motorcortex server and decodes time and value</p>
|
|
|
|
</dd>
|
|
|
|
<dt><a href="#Subscribe">Subscribe</a></dt>
|
|
|
|
<dd><p>Subscribe class for continuously receive requested data, subscribe communication is used</p>
|
|
|
|
</dd>
|
|
|
|
</dl>
|
|
|
|
|
|
|
|
<a name="module_motorcortex"></a>
|
|
|
|
|
|
|
|
## motorcortex
|
|
|
|
Motorcortex Bindings for JavaScript
|
|
|
|
|
|
|
|
**Version**: 0.10.4
|
|
|
|
**Author**: Alexey Zakharov <zakharov@vectioneer.com>
|
|
|
|
**License**: Copyright (C) Vectioneer - All Rights Reserved
|
|
|
|
**Copyright**: Vectioneer
|
|
|
|
|
|
|
|
* [motorcortex](#module_motorcortex)
|
|
|
|
* [module.exports](#exp_module_motorcortex--module.exports) ⏏
|
|
|
|
* [.MessageTypes](#module_motorcortex--module.exports.MessageTypes)
|
|
|
|
* [.Subscribe](#module_motorcortex--module.exports.Subscribe)
|
|
|
|
* [.Request](#module_motorcortex--module.exports.Request)
|
|
|
|
* [.getParameterFlag](#module_motorcortex--module.exports.getParameterFlag) ⇒ <code>number</code>
|
|
|
|
* [.getParameterType](#module_motorcortex--module.exports.getParameterType) ⇒ <code>number</code>
|
|
|
|
* [.getPermission](#module_motorcortex--module.exports.getPermission) ⇒ <code>number</code>
|
|
|
|
* [.getStatusCode](#module_motorcortex--module.exports.getStatusCode) ⇒ <code>number</code>
|
|
|
|
* [.getUserGroup](#module_motorcortex--module.exports.getUserGroup) ⇒ <code>number</code>
|
|
|
|
* [.getDataType](#module_motorcortex--module.exports.getDataType) ⇒ <code>number</code>
|
|
|
|
* [.statusToStr](#module_motorcortex--module.exports.statusToStr) ⇒ <code>string</code>
|
|
|
|
|
|
|
|
<a name="exp_module_motorcortex--module.exports"></a>
|
|
|
|
|
|
|
|
### module.exports ⏏
|
|
|
|
Library namespace, with JS representation of the motorcortex.proto IDL.
|
|
|
|
|
|
|
|
**Kind**: Exported member
|
|
|
|
<a name="module_motorcortex--module.exports.MessageTypes"></a>
|
|
|
|
|
|
|
|
#### module.exports.MessageTypes
|
|
|
|
Class MessageTypes is responsible for encoding/decoding motorcortex messages.
|
|
|
|
|
|
|
|
**Kind**: static property of [<code>module.exports</code>](#exp_module_motorcortex--module.exports)
|
|
|
|
**See**: MessageTypes
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
let motorcortex_types = new motorcortex.MessageTypes();
|
|
|
|
let type_load_done = motorcortex_types.load([{
|
|
|
|
proto: "msg/motorcortex.proto",
|
|
|
|
hash: "msg/motorcortex_hash.json"}, {
|
|
|
|
proto: "msg/motionJS.proto",
|
|
|
|
hash: "msg/motionJS_hash.json"}, {
|
|
|
|
proto: "msg/motionSL.proto",
|
|
|
|
hash: "msg/motionSL_hash.json"
|
|
|
|
}]);
|
|
|
|
|
|
|
|
type_load_done.then(function () {
|
|
|
|
console.log("Loaded all data types");
|
|
|
|
let load_msg = motorcortex_types.createType('motorcortex.LoadMsg', { path: '', fileName: 'control.xml' });
|
|
|
|
let encoded_msg = this.encode(load_msg);
|
|
|
|
}).catch(function (reason) {
|
|
|
|
console.error("Failed to load data types: " + reason);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
<a name="module_motorcortex--module.exports.Subscribe"></a>
|
|
|
|
|
|
|
|
#### module.exports.Subscribe
|
|
|
|
Class Subscribe is responsible for parameter and group subscriptions.
|
|
|
|
|
|
|
|
**Kind**: static property of [<code>module.exports</code>](#exp_module_motorcortex--module.exports)
|
|
|
|
**See**: Subscribe
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
let sub = new motorcortex.Subscribe(req);
|
|
|
|
let sub_conn_done = sub.connect('ws://localhost:5557');
|
|
|
|
sub_conn_done.then(function () {
|
|
|
|
console.log('Subscribe connection is established');
|
|
|
|
let data_sub = sub.subscribe(['root/Control/jointReferenceGenerator/enable',
|
|
|
|
'root/Control/jointReferenceGenerator/signalGenerator01/amplitude',
|
|
|
|
'root/Control/jointReferenceGenerator/signalGenerator02/amplitude'], 'group1');
|
|
|
|
data_sub.notify(function(msg) {
|
|
|
|
console.log('Received an update: ' + msg.toString());
|
|
|
|
});
|
|
|
|
}).catch(function (reason) {
|
|
|
|
console.error("Failed to establish connection: " + reason);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
<a name="module_motorcortex--module.exports.Request"></a>
|
|
|
|
|
|
|
|
#### module.exports.Request
|
|
|
|
Class Request is responsible for sending commands to motorcortex core:
|
|
|
|
for example set/get parameter value commands.
|
|
|
|
|
|
|
|
**Kind**: static property of [<code>module.exports</code>](#exp_module_motorcortex--module.exports)
|
|
|
|
**See**: Request
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
let req = new motorcortex.Request(motorcortex_types);
|
|
|
|
let req_conn_done = req.connect(`ws://localhost:5558`, 10000, 100);
|
|
|
|
req_conn_done.then(function () {
|
|
|
|
console.log('Request connection is established');
|
|
|
|
req.setParameter('root/Control/dummyBoolArray6', [1, 2, 3, 4]).then(function (reply) {
|
|
|
|
if (reply.status === motorcortex.getStatusCode('OK')) {
|
|
|
|
console.log("Parameter set to a new value.);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
```
|
|
|
|
<a name="module_motorcortex--module.exports.getParameterFlag"></a>
|
|
|
|
|
|
|
|
#### module.exports.getParameterFlag ⇒ <code>number</code>
|
|
|
|
Returns properties of the parameter in tree, like overwrite or linked, etc.
|
|
|
|
|
|
|
|
**Kind**: static property of [<code>module.exports</code>](#exp_module_motorcortex--module.exports)
|
|
|
|
**Returns**: <code>number</code> - Id of the flags. Multiple flags could be encoded in the return value.
|
|
|
|
**See**: ./msg/motorcortex.proto
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| name | <code>string</code> | Name of the flag/property. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
let flags = parameter.info.flags
|
|
|
|
if (flags & motorcortex.getParameterFlag('OVERWRITE_IS_ACTIVE')) {
|
|
|
|
console.log('Parameter overwrite is active');
|
|
|
|
}
|
|
|
|
if (flag & motorcortex.getParameterFlag('LINK_IS_ACTIVE')) {
|
|
|
|
console.log('Parameter is linked');
|
|
|
|
}
|
|
|
|
```
|
|
|
|
<a name="module_motorcortex--module.exports.getParameterType"></a>
|
|
|
|
|
|
|
|
#### module.exports.getParameterType ⇒ <code>number</code>
|
|
|
|
Returns type of the parameter in tree: input, output or parameter.
|
|
|
|
|
|
|
|
**Kind**: static property of [<code>module.exports</code>](#exp_module_motorcortex--module.exports)
|
|
|
|
**Returns**: <code>number</code> - Id of the type
|
|
|
|
**See**: ./msg/motorcortex.proto
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| name | <code>string</code> | Name of the type. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
let type = parameter.info.param_type
|
|
|
|
switch (type) {
|
|
|
|
case motorcortex.getParameterType('INPUT'):
|
|
|
|
console.log('Parameter type is an input');
|
|
|
|
case motorcortex.getParameterType('OUTPUT'):
|
|
|
|
console.log('Parameter type is an output');
|
|
|
|
case motorcortex.getParameterType('PARAMETER'):
|
|
|
|
console.log('Parameter type is a parameter');
|
|
|
|
}
|
|
|
|
```
|
|
|
|
<a name="module_motorcortex--module.exports.getPermission"></a>
|
|
|
|
|
|
|
|
#### module.exports.getPermission ⇒ <code>number</code>
|
|
|
|
Returns type of the parameter permission. Available parameters' permissions.
|
|
|
|
There are situations when users from the different groups need access to the
|
|
|
|
protected parts of the parameter tree. Permission flags allows fine-tuning an
|
|
|
|
access level of the group. Motorcortex Permissions have similar to Unix structure.
|
|
|
|
Permissions are represented either in symbolic notation or in octal notation.
|
|
|
|
(Note: User rights are not yet implemented, instead use Group rights)
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
---------- (0000): no permission
|
|
|
|
|
|
|
|
-rwx------ (0700): read, write, & execute only for owner (Note: currently
|
|
|
|
not implemented, user group flags instead)
|
|
|
|
|
|
|
|
-rwxrwx--- (0770): read, write, & execute for owner and group
|
|
|
|
(Note: execute flag is used as a permission to open folders)
|
|
|
|
|
|
|
|
-rwxrwxr-x (0775): read, write, & execute for owner and group,
|
|
|
|
read & execute for all others.
|
|
|
|
|
|
|
|
-rwxrwxrwx (0777): full access
|
|
|
|
|
|
|
|
**Kind**: static property of [<code>module.exports</code>](#exp_module_motorcortex--module.exports)
|
|
|
|
**Returns**: <code>number</code> - Id of the permission
|
|
|
|
**See**: ./msg/motorcortex.proto
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| name | <code>string</code> | Name of the permission. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
let permissions = parameter.info.permissions
|
|
|
|
switch (type) {
|
|
|
|
case motorcortex.getParameterType('USER_READ'):
|
|
|
|
console.log('User has read access');
|
|
|
|
case motorcortex.getParameterType('USER_WRITE'):
|
|
|
|
console.log('User has write access');
|
|
|
|
case motorcortex.getParameterType('USER_EXECUTE'):
|
|
|
|
console.log('User can open parameter folder');
|
|
|
|
}
|
|
|
|
```
|
|
|
|
<a name="module_motorcortex--module.exports.getStatusCode"></a>
|
|
|
|
|
|
|
|
#### module.exports.getStatusCode ⇒ <code>number</code>
|
|
|
|
Returns a status code of the operation.
|
|
|
|
|
|
|
|
**Kind**: static property of [<code>module.exports</code>](#exp_module_motorcortex--module.exports)
|
|
|
|
**Returns**: <code>number</code> - Id of status.
|
|
|
|
**See**: ./msg/motorcortex.proto
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| name | <code>string</code> | Name of status. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
if (msg.status === motorcortex.getStatusCode('READ_ONLY_MODE')) {
|
|
|
|
console.log('User is logged-in, read only mode.');
|
|
|
|
}
|
|
|
|
```
|
|
|
|
<a name="module_motorcortex--module.exports.getUserGroup"></a>
|
|
|
|
|
|
|
|
#### module.exports.getUserGroup ⇒ <code>number</code>
|
|
|
|
Returns a user group.
|
|
|
|
|
|
|
|
**Kind**: static property of [<code>module.exports</code>](#exp_module_motorcortex--module.exports)
|
|
|
|
**Returns**: <code>number</code> - Id of group.
|
|
|
|
**See**: ./msg/motorcortex.proto
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| name | <code>string</code> | Name of the group. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
if (parameter.info.group_id === motorcortex.getUserGroup('ADMINISTRATOR')) {
|
|
|
|
console.log('Parameter belongs to administrator user group');
|
|
|
|
}
|
|
|
|
```
|
|
|
|
<a name="module_motorcortex--module.exports.getDataType"></a>
|
|
|
|
|
|
|
|
#### module.exports.getDataType ⇒ <code>number</code>
|
|
|
|
Returns a data type of the item in the parameter tree.
|
|
|
|
|
|
|
|
**Kind**: static property of [<code>module.exports</code>](#exp_module_motorcortex--module.exports)
|
|
|
|
**Returns**: <code>number</code> - id of the data type.
|
|
|
|
**See**: ./msg/motorcortex.proto
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| name | <code>string</code> | Type name of the parameter (see motorcortex.proto, enum DataType). |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
let type_id = parameter.info.dataType;
|
|
|
|
if (type_id === motorcortex.getDataType('STRING')) {
|
|
|
|
console.log('Parameter has type string');
|
|
|
|
}
|
|
|
|
```
|
|
|
|
<a name="module_motorcortex--module.exports.statusToStr"></a>
|
|
|
|
|
|
|
|
#### module.exports.statusToStr ⇒ <code>string</code>
|
|
|
|
Converts a status and error codes to a string description
|
|
|
|
|
|
|
|
**Kind**: static property of [<code>module.exports</code>](#exp_module_motorcortex--module.exports)
|
|
|
|
**Returns**: <code>string</code> - Error desciprion.
|
|
|
|
**See**: ./msg/motorcortex.proto
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| code | <code>number</code> | An error code. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
let login_reply = req.login("operator", "operator123");
|
|
|
|
login_reply.then(function (reply) { console.log('Success!') }).catch(function (reply) {
|
|
|
|
console.log('Failed: ' + motorcortex.statusToStr(reply.status));
|
|
|
|
});
|
|
|
|
```
|
|
|
|
<a name="Connection"></a>
|
|
|
|
|
|
|
|
## Connection
|
|
|
|
Class represents a connection to motorcortex server
|
|
|
|
|
|
|
|
**Kind**: global class
|
|
|
|
|
|
|
|
* [Connection](#Connection)
|
|
|
|
* [new Connection(request_obj, subscribe_obj)](#new_Connection_new)
|
|
|
|
* [.start(watchdog_parameter, [connection_timeout])](#Connection+start)
|
|
|
|
* [.stop()](#Connection+stop)
|
|
|
|
|
|
|
|
<a name="new_Connection_new"></a>
|
|
|
|
|
|
|
|
### new Connection(request_obj, subscribe_obj)
|
|
|
|
Creates a connection
|
|
|
|
|
|
|
|
|
|
|
|
| Param | Description |
|
|
|
|
| --- | --- |
|
|
|
|
| request_obj | request |
|
|
|
|
| subscribe_obj | subscribe |
|
|
|
|
|
|
|
|
<a name="Connection+start"></a>
|
|
|
|
|
|
|
|
### connection.start(watchdog_parameter, [connection_timeout])
|
|
|
|
Start connection
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Connection</code>](#Connection)
|
|
|
|
|
|
|
|
| Param | Type | Default | Description |
|
|
|
|
| --- | --- | --- | --- |
|
|
|
|
| watchdog_parameter | | | |
|
|
|
|
| [connection_timeout] | <code>number</code> | <code>500</code> | timeout value, |
|
|
|
|
|
|
|
|
<a name="Connection+stop"></a>
|
|
|
|
|
|
|
|
### connection.stop()
|
|
|
|
Stop connection
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Connection</code>](#Connection)
|
|
|
|
<a name="MessageTypes"></a>
|
|
|
|
|
|
|
|
## MessageTypes
|
|
|
|
Class for handling motorcortex data types, load proto files and hash files,
|
|
|
|
creates a dictionary with all available data types, resolves data types by,
|
|
|
|
name or by hash, performs encoding and decoding of the messages.
|
|
|
|
|
|
|
|
**Kind**: global class
|
|
|
|
|
|
|
|
* [MessageTypes](#MessageTypes)
|
|
|
|
* [new exports.MessageTypes()](#new_MessageTypes_new)
|
|
|
|
* [.load(proto_hash_pair_list)](#MessageTypes+load) ⇒ <code>Promise.<string></code>
|
|
|
|
* [.createType(type_name, [payload])](#MessageTypes+createType) ⇒ <code>object</code>
|
|
|
|
* [.getTypeByName(type_name)](#MessageTypes+getTypeByName) ⇒ <code>object</code>
|
|
|
|
|
|
|
|
<a name="new_MessageTypes_new"></a>
|
|
|
|
|
|
|
|
### new exports.MessageTypes()
|
|
|
|
Creates message types object
|
|
|
|
|
|
|
|
<a name="MessageTypes+load"></a>
|
|
|
|
|
|
|
|
### messageTypes.load(proto_hash_pair_list) ⇒ <code>Promise.<string></code>
|
|
|
|
Loads an array of .proto and .json file pairs.
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>MessageTypes</code>](#MessageTypes)
|
|
|
|
**Returns**: <code>Promise.<string></code> - Returns a Promise, which is resolved when loading is complete.
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| proto_hash_pair_list | <code>Array.<object></code> | a list of corresponding proto message files and hash files. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
let motorcortex_types = new motorcortex.MessageTypes();
|
|
|
|
let type_load_done = motorcortex_types.load([{
|
|
|
|
proto: 'msg/motorcortex.proto',
|
|
|
|
hash: 'msg/motorcortex_hash.json'}, {
|
|
|
|
proto: 'msg/motionJS.proto',
|
|
|
|
hash: 'msg/motionJS_hash.json'}, {
|
|
|
|
proto: 'msg/motionSL.proto',
|
|
|
|
hash: 'msg/motionSL_hash.json'
|
|
|
|
}]);
|
|
|
|
|
|
|
|
type_load_done.then(function () {
|
|
|
|
console.log('Loaded all data types');}).catch(function (reason) {
|
|
|
|
console.error('Failed to load data types: ' + reason);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
<a name="MessageTypes+createType"></a>
|
|
|
|
|
|
|
|
### messageTypes.createType(type_name, [payload]) ⇒ <code>object</code>
|
|
|
|
Returns an instance of the loaded data type and filles it with payload.
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>MessageTypes</code>](#MessageTypes)
|
|
|
|
**Returns**: <code>object</code> - Instance of the requested type, filled with payload.
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| type_name | <code>string</code> | Type name from the proto files. |
|
|
|
|
| [payload] | <code>object</code> | Payload data to fill. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
let load_msg = motorcortex_types.createType('motorcortex.LoadMsg', { path: '', fileName: 'control.xml' });
|
|
|
|
let encoded_msg = this.encode(load_msg);
|
|
|
|
```
|
|
|
|
<a name="MessageTypes+getTypeByName"></a>
|
|
|
|
|
|
|
|
### messageTypes.getTypeByName(type_name) ⇒ <code>object</code>
|
|
|
|
Returns type with given name
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>MessageTypes</code>](#MessageTypes)
|
|
|
|
**Returns**: <code>object</code> - Returns a Protobuf Type
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| type_name | <code>string</code> | Name of the message type from the proto files. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
let ErrorList = motorcortex_types.getTypeByName('motorcortex.ErrorList');
|
|
|
|
let error_list = ErrorList.decode(encoded_msg);
|
|
|
|
console.log('Error list: ', error_list);
|
|
|
|
```
|
|
|
|
<a name="Request"></a>
|
|
|
|
|
|
|
|
## Request
|
|
|
|
Request/Reply communication is used to send commands to a motorcortex server.
|
|
|
|
|
|
|
|
**Kind**: global class
|
|
|
|
|
|
|
|
* [Request](#Request)
|
|
|
|
* [new exports.Request(protobuf_types)](#new_Request_new)
|
|
|
|
* [.connectionState()](#Request+connectionState) ⇒ <code>number</code>
|
|
|
|
* [.connect(url, timeout_ms, max_request_queue_size)](#Request+connect) ⇒ <code>Promise.<string></code>
|
|
|
|
* [.close()](#Request+close)
|
|
|
|
* [.encode(A)](#Request+encode) ⇒ <code>Uint8Array</code>
|
|
|
|
* [.send(encoded_msg)](#Request+send) ⇒ <code>Promise.<Object></code>
|
|
|
|
* [.login(login, password)](#Request+login) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
|
* [.logout()](#Request+logout) ⇒ <code>Promise</code>
|
|
|
|
* [.getParameterTree()](#Request+getParameterTree) ⇒ <code>Promise.<any></code>
|
|
|
|
* [.getParameterTreeHash()](#Request+getParameterTreeHash) ⇒ <code>Promise</code>
|
|
|
|
* [.getParameter(path)](#Request+getParameter) ⇒ <code>Promise</code>
|
|
|
|
* [.setParameter(path, value, options)](#Request+setParameter) ⇒ <code>Promise</code>
|
|
|
|
* [.overwriteParameter(path, value, force_activate, options)](#Request+overwriteParameter) ⇒ <code>Promise</code>
|
|
|
|
* [.releaseParameter(path)](#Request+releaseParameter) ⇒ <code>Promise</code>
|
|
|
|
* [.setParameterList(param_list)](#Request+setParameterList) ⇒ <code>Promise</code>
|
|
|
|
* [.getParameterList(path_list)](#Request+getParameterList) ⇒ <code>Promise</code>
|
|
|
|
* [.createGroup(path_list, group_alias, frq_divider)](#Request+createGroup) ⇒ <code>Promise</code>
|
|
|
|
* [.removeGroup(group_alias)](#Request+removeGroup) ⇒ <code>Promise</code>
|
|
|
|
* [.save(path)](#Request+save) ⇒ <code>Promise</code>
|
|
|
|
* [.load(path)](#Request+load) ⇒ <code>Promise</code>
|
|
|
|
|
|
|
|
<a name="new_Request_new"></a>
|
|
|
|
|
|
|
|
### new exports.Request(protobuf_types)
|
|
|
|
Creates request object
|
|
|
|
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| protobuf_types | [<code>MessageTypes</code>](#MessageTypes) | Reference to an instance of the MessageTypes class. |
|
|
|
|
|
|
|
|
<a name="Request+connectionState"></a>
|
|
|
|
|
|
|
|
### request.connectionState() ⇒ <code>number</code>
|
|
|
|
Connection state
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
**Returns**: <code>number</code> - returns connection state
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
CONNECTING 0 The connection is not yet open
|
|
|
|
OPEN 1 The connection is open and ready to communicate
|
|
|
|
CLOSING 2 The connection is in the process of closing
|
|
|
|
CLOSED 3 The connection is closed or couldn't be opened
|
|
|
|
```
|
|
|
|
<a name="Request+connect"></a>
|
|
|
|
|
|
|
|
### request.connect(url, timeout_ms, max_request_queue_size) ⇒ <code>Promise.<string></code>
|
|
|
|
Opens a request connection.
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
**Returns**: <code>Promise.<string></code> - A promise, which completes when connection is ready.
|
|
|
|
If connection is failed, short error description is passed to the cathe method.
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| url | <code>string</code> | Motorcortex server URL. |
|
|
|
|
| timeout_ms | <code>number</code> | Reply timeout in milliseconds. |
|
|
|
|
| max_request_queue_size | <code>number</code> | Maximum size of the request queue. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
let req = new motorcortex.Request(motorcortex_types);
|
|
|
|
let req_conn_done = req.connect(`ws://${server}:5558`, 10000, 100);
|
|
|
|
req_conn_done
|
|
|
|
.then(function () {
|
|
|
|
console.log("Request connection is established");
|
|
|
|
})
|
|
|
|
.catch(function (reason) {
|
|
|
|
console.error("Failed to establish connection: " + reason);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
<a name="Request+close"></a>
|
|
|
|
|
|
|
|
### request.close()
|
|
|
|
Closes connection to the server
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
<a name="Request+encode"></a>
|
|
|
|
|
|
|
|
### request.encode(A) ⇒ <code>Uint8Array</code>
|
|
|
|
Encodes a data type from MessageTypes to a binary wire type.
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
**Returns**: <code>Uint8Array</code> - A binary array with encoded message.
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| A | <code>Object</code> | message created by MotorcortexTypes. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
let motion_script = motorcortex_types.createType('motion_spec.MotionScript', {.id = 1, name = 'Test script'});
|
|
|
|
motion_script.script = `print('Hello world');`;
|
|
|
|
let encoded_msg = req.encode(motion_script);
|
|
|
|
req.send(encoded_msg);
|
|
|
|
```
|
|
|
|
<a name="Request+send"></a>
|
|
|
|
|
|
|
|
### request.send(encoded_msg) ⇒ <code>Promise.<Object></code>
|
|
|
|
Sends an encoded request to the server
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
**Returns**: <code>Promise.<Object></code> - Returns a Promise, which completes when reply from the server is received.
|
|
|
|
If request fails, cache callback is triggered.
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| encoded_msg | <code>Uint8Array</code> | A binary array with encoded message. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
let joint2cart = calcJointToCart({
|
|
|
|
cartpose: [0, 0, 0, 0, 0, 0],
|
|
|
|
jointpose: [0, 0, 1.57, 0, 1.57, 0] });
|
|
|
|
let reply = req.send(req.encode(joint2cart));
|
|
|
|
reply.then(function (msg) {
|
|
|
|
console.log('Got reply: ' + JSON.stringify(msg));
|
|
|
|
}).catch(function (msg) {
|
|
|
|
console.error('Failed: ' + JSON.stringify(msg));
|
|
|
|
});
|
|
|
|
```
|
|
|
|
<a name="Request+login"></a>
|
|
|
|
|
|
|
|
### request.login(login, password) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
|
Sends a login request to a server
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
**Returns**: <code>Promise.<StatusMsg></code> - Returns a Promise, which resolves if login is successful and fails otherwise.
|
|
|
|
Return message has a status code, which indicates a status of the login.
|
|
|
|
**See**: motorcortex.proto, StatusMsg, StatusCode
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| login | <code>string</code> | User login. |
|
|
|
|
| password | <code>string</code> | User password. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
let login_reply = req.login("operator", "god123");
|
|
|
|
login_reply.then(function (reply) {
|
|
|
|
console.log('Logged-in successful: ' + motorcortex.statusToStr(reply.status));
|
|
|
|
}).catch( function(reply) {
|
|
|
|
console.log('Failed to login: ' + motorcortex.statusToStr(reply.status));
|
|
|
|
});
|
|
|
|
```
|
|
|
|
<a name="Request+logout"></a>
|
|
|
|
|
|
|
|
### request.logout() ⇒ <code>Promise</code>
|
|
|
|
Send logout message
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
<a name="Request+getParameterTree"></a>
|
|
|
|
|
|
|
|
### request.getParameterTree() ⇒ <code>Promise.<any></code>
|
|
|
|
Request a parameter tree from the cache or the server
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
<a name="Request+getParameterTreeHash"></a>
|
|
|
|
|
|
|
|
### request.getParameterTreeHash() ⇒ <code>Promise</code>
|
|
|
|
Request a parameter tree hash from the server
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
<a name="Request+getParameter"></a>
|
|
|
|
|
|
|
|
### request.getParameter(path) ⇒ <code>Promise</code>
|
|
|
|
Request a parameter from the server
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| path | <code>string</code> | parameter path |
|
|
|
|
|
|
|
|
<a name="Request+setParameter"></a>
|
|
|
|
|
|
|
|
### request.setParameter(path, value, options) ⇒ <code>Promise</code>
|
|
|
|
Set parameter value
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| path | <code>string</code> | parameter path |
|
|
|
|
| value | <code>string</code> | parameter value |
|
|
|
|
| options | | |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
options {offset:, length:}
|
|
|
|
```
|
|
|
|
<a name="Request+overwriteParameter"></a>
|
|
|
|
|
|
|
|
### request.overwriteParameter(path, value, force_activate, options) ⇒ <code>Promise</code>
|
|
|
|
Overwrite parameter value with a new value
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
|
|
|
|
| Param | Type | Default | Description |
|
|
|
|
| --- | --- | --- | --- |
|
|
|
|
| path | <code>string</code> | | parameter path |
|
|
|
|
| value | <code>string</code> | | parameter value |
|
|
|
|
| force_activate | <code>boolean</code> | <code>false</code> | activate force overwrite |
|
|
|
|
| options | | | |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
options {offset:, length:}
|
|
|
|
```
|
|
|
|
<a name="Request+releaseParameter"></a>
|
|
|
|
|
|
|
|
### request.releaseParameter(path) ⇒ <code>Promise</code>
|
|
|
|
Deactivate forced value overwrite
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| path | <code>string</code> | parameter path |
|
|
|
|
|
|
|
|
<a name="Request+setParameterList"></a>
|
|
|
|
|
|
|
|
### request.setParameterList(param_list) ⇒ <code>Promise</code>
|
|
|
|
Set parameter value list
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
|
|
|
|
| Param |
|
|
|
|
| --- |
|
|
|
|
| param_list |
|
|
|
|
|
|
|
|
<a name="Request+getParameterList"></a>
|
|
|
|
|
|
|
|
### request.getParameterList(path_list) ⇒ <code>Promise</code>
|
|
|
|
Get parameter value list
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
|
|
|
|
| Param |
|
|
|
|
| --- |
|
|
|
|
| path_list |
|
|
|
|
|
|
|
|
<a name="Request+createGroup"></a>
|
|
|
|
|
|
|
|
### request.createGroup(path_list, group_alias, frq_divider) ⇒ <code>Promise</code>
|
|
|
|
Create subscription, path can be a single string or an array of strings, group is optional
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
|
|
|
|
| Param |
|
|
|
|
| --- |
|
|
|
|
| path_list |
|
|
|
|
| group_alias |
|
|
|
|
| frq_divider |
|
|
|
|
|
|
|
|
<a name="Request+removeGroup"></a>
|
|
|
|
|
|
|
|
### request.removeGroup(group_alias) ⇒ <code>Promise</code>
|
|
|
|
Remove subscription
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
|
|
|
|
| Param |
|
|
|
|
| --- |
|
|
|
|
| group_alias |
|
|
|
|
|
|
|
|
<a name="Request+save"></a>
|
|
|
|
|
|
|
|
### request.save(path) ⇒ <code>Promise</code>
|
|
|
|
Save parameters at server
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
|
|
|
|
| Param |
|
|
|
|
| --- |
|
|
|
|
| path |
|
|
|
|
|
|
|
|
<a name="Request+load"></a>
|
|
|
|
|
|
|
|
### request.load(path) ⇒ <code>Promise</code>
|
|
|
|
Load parameters at server
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
|
|
|
|
| Param |
|
|
|
|
| --- |
|
|
|
|
| path |
|
|
|
|
|
|
|
|
<a name="Timestamp"></a>
|
|
|
|
|
|
|
|
## Timestamp
|
|
|
|
Timestamp of the parameter
|
|
|
|
|
|
|
|
**Kind**: global class
|
|
|
|
|
|
|
|
* [Timestamp](#Timestamp)
|
|
|
|
* [new Timestamp(sec, nsec)](#new_Timestamp_new)
|
|
|
|
* [.getInSec()](#Timestamp+getInSec) ⇒ <code>number</code>
|
|
|
|
* [.getInMilisec()](#Timestamp+getInMilisec) ⇒ <code>number</code>
|
|
|
|
* [.getInMicrosec()](#Timestamp+getInMicrosec) ⇒ <code>number</code>
|
|
|
|
* [.getInNanosec()](#Timestamp+getInNanosec) ⇒ <code>number</code>
|
|
|
|
* [.toString()](#Timestamp+toString) ⇒ <code>string</code>
|
|
|
|
* [.compare(timestamp)](#Timestamp+compare) ⇒ <code>boolean</code>
|
|
|
|
|
|
|
|
<a name="new_Timestamp_new"></a>
|
|
|
|
|
|
|
|
### new Timestamp(sec, nsec)
|
|
|
|
Creates a timestamp
|
|
|
|
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| sec | <code>number</code> | seconds |
|
|
|
|
| nsec | <code>number</code> | nanoseconds |
|
|
|
|
|
|
|
|
<a name="Timestamp+getInSec"></a>
|
|
|
|
|
|
|
|
### timestamp.getInSec() ⇒ <code>number</code>
|
|
|
|
Returns a timestamp in seconds
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Timestamp</code>](#Timestamp)
|
|
|
|
**Returns**: <code>number</code> - timestamp in seconds
|
|
|
|
<a name="Timestamp+getInMilisec"></a>
|
|
|
|
|
|
|
|
### timestamp.getInMilisec() ⇒ <code>number</code>
|
|
|
|
Returns a timestamp in milliseconds
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Timestamp</code>](#Timestamp)
|
|
|
|
**Returns**: <code>number</code> - timestamp in milliseconds
|
|
|
|
<a name="Timestamp+getInMicrosec"></a>
|
|
|
|
|
|
|
|
### timestamp.getInMicrosec() ⇒ <code>number</code>
|
|
|
|
Returns a timestamp in microseconds
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Timestamp</code>](#Timestamp)
|
|
|
|
**Returns**: <code>number</code> - timestamp in microseconds
|
|
|
|
<a name="Timestamp+getInNanosec"></a>
|
|
|
|
|
|
|
|
### timestamp.getInNanosec() ⇒ <code>number</code>
|
|
|
|
Returns a timestamp in nanoseconds
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Timestamp</code>](#Timestamp)
|
|
|
|
**Returns**: <code>number</code> - timestamp in nanoseconds
|
|
|
|
<a name="Timestamp+toString"></a>
|
|
|
|
|
|
|
|
### timestamp.toString() ⇒ <code>string</code>
|
|
|
|
Returns a timestamp in seconds as a string
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Timestamp</code>](#Timestamp)
|
|
|
|
**Returns**: <code>string</code> - timestamp in seconds as a string
|
|
|
|
<a name="Timestamp+compare"></a>
|
|
|
|
|
|
|
|
### timestamp.compare(timestamp) ⇒ <code>boolean</code>
|
|
|
|
Compares two timestamps
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Timestamp</code>](#Timestamp)
|
|
|
|
**Returns**: <code>boolean</code> - true - if timestamps are equal, false - otherwise
|
|
|
|
|
|
|
|
| Param | Description |
|
|
|
|
| --- | --- |
|
|
|
|
| timestamp | timestamp to compare |
|
|
|
|
|
|
|
|
<a name="Parameter"></a>
|
|
|
|
|
|
|
|
## Parameter
|
|
|
|
Parameter value with a timestamp
|
|
|
|
|
|
|
|
**Kind**: global class
|
|
|
|
|
|
|
|
* [Parameter](#Parameter)
|
|
|
|
* [new Parameter(timestamp, value)](#new_Parameter_new)
|
|
|
|
* [.get()](#Parameter+get) ⇒
|
|
|
|
* [.getTimestamp()](#Parameter+getTimestamp) ⇒ [<code>Timestamp</code>](#Timestamp)
|
|
|
|
* [.getValue()](#Parameter+getValue) ⇒ <code>\*</code>
|
|
|
|
* [.toString()](#Parameter+toString) ⇒ <code>string</code>
|
|
|
|
|
|
|
|
<a name="new_Parameter_new"></a>
|
|
|
|
|
|
|
|
### new Parameter(timestamp, value)
|
|
|
|
Creates a parameter
|
|
|
|
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| timestamp | [<code>Timestamp</code>](#Timestamp) | parameter timestamp |
|
|
|
|
| value | <code>\*</code> | parameter value |
|
|
|
|
|
|
|
|
<a name="Parameter+get"></a>
|
|
|
|
|
|
|
|
### parameter.get() ⇒
|
|
|
|
Gets a parameter
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Parameter</code>](#Parameter)
|
|
|
|
**Returns**: [] array with parameter timestamp and value
|
|
|
|
<a name="Parameter+getTimestamp"></a>
|
|
|
|
|
|
|
|
### parameter.getTimestamp() ⇒ [<code>Timestamp</code>](#Timestamp)
|
|
|
|
Gets a parameter's timestamp
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Parameter</code>](#Parameter)
|
|
|
|
**Returns**: [<code>Timestamp</code>](#Timestamp) - timestamp
|
|
|
|
<a name="Parameter+getValue"></a>
|
|
|
|
|
|
|
|
### parameter.getValue() ⇒ <code>\*</code>
|
|
|
|
Gets a parameter value
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Parameter</code>](#Parameter)
|
|
|
|
**Returns**: <code>\*</code> - value
|
|
|
|
<a name="Parameter+toString"></a>
|
|
|
|
|
|
|
|
### parameter.toString() ⇒ <code>string</code>
|
|
|
|
Gets a parameter as a string
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Parameter</code>](#Parameter)
|
|
|
|
**Returns**: <code>string</code> - string formatted as 'timestamp: parameter'
|
|
|
|
<a name="Subscription"></a>
|
|
|
|
|
|
|
|
## Subscription
|
|
|
|
Subscription class receives updates from motorcortex server and decodes time and value
|
|
|
|
|
|
|
|
**Kind**: global class
|
|
|
|
|
|
|
|
* [Subscription](#Subscription)
|
|
|
|
* [new Subscription(group_alias, protobuf_types)](#new_Subscription_new)
|
|
|
|
* [.id()](#Subscription+id)
|
|
|
|
* [.alias()](#Subscription+alias) ⇒ <code>\*</code>
|
|
|
|
* [.then(clb)](#Subscription+then) ⇒ <code>Promise.<any></code>
|
|
|
|
* [.catch(clb)](#Subscription+catch) ⇒ <code>Promise.<any></code>
|
|
|
|
* [.read()](#Subscription+read) ⇒ <code>\*</code>
|
|
|
|
* [.layout()](#Subscription+layout) ⇒ <code>\*</code>
|
|
|
|
* [.notify(observer)](#Subscription+notify)
|
|
|
|
|
|
|
|
<a name="new_Subscription_new"></a>
|
|
|
|
|
|
|
|
### new Subscription(group_alias, protobuf_types)
|
|
|
|
Create subscription
|
|
|
|
|
|
|
|
|
|
|
|
| Param | Description |
|
|
|
|
| --- | --- |
|
|
|
|
| group_alias | subscription group (created by the Subscriber class) |
|
|
|
|
| protobuf_types | |
|
|
|
|
|
|
|
|
<a name="Subscription+id"></a>
|
|
|
|
|
|
|
|
### subscription.id()
|
|
|
|
Return subscription identifier
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscription</code>](#Subscription)
|
|
|
|
<a name="Subscription+alias"></a>
|
|
|
|
|
|
|
|
### subscription.alias() ⇒ <code>\*</code>
|
|
|
|
Return group alias
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscription</code>](#Subscription)
|
|
|
|
<a name="Subscription+then"></a>
|
|
|
|
|
|
|
|
### subscription.then(clb) ⇒ <code>Promise.<any></code>
|
|
|
|
Returns Promise interface (then)
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscription</code>](#Subscription)
|
|
|
|
|
|
|
|
| Param |
|
|
|
|
| --- |
|
|
|
|
| clb |
|
|
|
|
|
|
|
|
<a name="Subscription+catch"></a>
|
|
|
|
|
|
|
|
### subscription.catch(clb) ⇒ <code>Promise.<any></code>
|
|
|
|
Returns Promise interface (catch)
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscription</code>](#Subscription)
|
|
|
|
|
|
|
|
| Param |
|
|
|
|
| --- |
|
|
|
|
| clb |
|
|
|
|
|
|
|
|
<a name="Subscription+read"></a>
|
|
|
|
|
|
|
|
### subscription.read() ⇒ <code>\*</code>
|
|
|
|
Read complete group
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscription</code>](#Subscription)
|
|
|
|
<a name="Subscription+layout"></a>
|
|
|
|
|
|
|
|
### subscription.layout() ⇒ <code>\*</code>
|
|
|
|
Get layout
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscription</code>](#Subscription)
|
|
|
|
<a name="Subscription+notify"></a>
|
|
|
|
|
|
|
|
### subscription.notify(observer)
|
|
|
|
Set listener
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscription</code>](#Subscription)
|
|
|
|
|
|
|
|
| Param |
|
|
|
|
| --- |
|
|
|
|
| observer |
|
|
|
|
|
|
|
|
<a name="Subscribe"></a>
|
|
|
|
|
|
|
|
## Subscribe
|
|
|
|
Subscribe class for continuously receive requested data, subscribe communication is used
|
|
|
|
|
|
|
|
**Kind**: global class
|
|
|
|
|
|
|
|
* [Subscribe](#Subscribe)
|
|
|
|
* [new exports.Subscribe(request)](#new_Subscribe_new)
|
|
|
|
* [.connectionState()](#Subscribe+connectionState) ⇒ <code>number</code>
|
|
|
|
* [.connect(url)](#Subscribe+connect) ⇒ <code>Promise.<any></code>
|
|
|
|
* [.connectionClosed()](#Subscribe+connectionClosed) ⇒ <code>Promise</code>
|
|
|
|
* [.close()](#Subscribe+close)
|
|
|
|
* [.subscribe(param_list, group_alias, frq_divider)](#Subscribe+subscribe) ⇒ [<code>Subscription</code>](#Subscription)
|
|
|
|
* [.unsubscribe(group_alias)](#Subscribe+unsubscribe) ⇒ <code>Promise</code>
|
|
|
|
|
|
|
|
<a name="new_Subscribe_new"></a>
|
|
|
|
|
|
|
|
### new exports.Subscribe(request)
|
|
|
|
Create subscribe
|
|
|
|
|
|
|
|
|
|
|
|
| Param | Type |
|
|
|
|
| --- | --- |
|
|
|
|
| request | [<code>Request</code>](#Request) |
|
|
|
|
|
|
|
|
<a name="Subscribe+connectionState"></a>
|
|
|
|
|
|
|
|
### subscribe.connectionState() ⇒ <code>number</code>
|
|
|
|
Get connection state
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscribe</code>](#Subscribe)
|
|
|
|
**Returns**: <code>number</code> - connection state
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
CONNECTING 0 the connection is not yet open
|
|
|
|
OPEN 1 the connection is open and ready to communicate
|
|
|
|
CLOSING 2 the connection is in the process of closing
|
|
|
|
CLOSED 3 the connection is closed or couldn't be opened
|
|
|
|
```
|
|
|
|
<a name="Subscribe+connect"></a>
|
|
|
|
|
|
|
|
### subscribe.connect(url) ⇒ <code>Promise.<any></code>
|
|
|
|
Connect to the server
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscribe</code>](#Subscribe)
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| url | <code>string</code> | path to the motorcortex server |
|
|
|
|
|
|
|
|
<a name="Subscribe+connectionClosed"></a>
|
|
|
|
|
|
|
|
### subscribe.connectionClosed() ⇒ <code>Promise</code>
|
|
|
|
**Kind**: instance method of [<code>Subscribe</code>](#Subscribe)
|
|
|
|
<a name="Subscribe+close"></a>
|
|
|
|
|
|
|
|
### subscribe.close()
|
|
|
|
Close connection
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscribe</code>](#Subscribe)
|
|
|
|
<a name="Subscribe+subscribe"></a>
|
|
|
|
|
|
|
|
### subscribe.subscribe(param_list, group_alias, frq_divider) ⇒ [<code>Subscription</code>](#Subscription)
|
|
|
|
Create subscription
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscribe</code>](#Subscribe)
|
|
|
|
|
|
|
|
| Param |
|
|
|
|
| --- |
|
|
|
|
| param_list |
|
|
|
|
| group_alias |
|
|
|
|
| frq_divider |
|
|
|
|
|
|
|
|
<a name="Subscribe+unsubscribe"></a>
|
|
|
|
|
|
|
|
### subscribe.unsubscribe(group_alias) ⇒ <code>Promise</code>
|
|
|
|
Remove subscription
|
|
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscribe</code>](#Subscribe)
|
|
|
|
|
|
|
|
| Param |
|
|
|
|
| --- |
|
|
|
|
| group_alias | |