... | ... | @@ -9,9 +9,6 @@ |
|
|
## 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 and hash files,
|
|
|
creates a dictionary with all available data types, resolves data types by
|
... | ... | @@ -20,8 +17,16 @@ name or by hash, performs encoding and decoding of the messages.</p> |
|
|
<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>
|
|
|
<dt><a href="#RequestAsync">RequestAsync</a></dt>
|
|
|
<dd><p>Request/Reply communication is used to send commands to a motorcortex server.</p>
|
|
|
</dd>
|
|
|
<dt><a href="#ConnectionData">ConnectionData</a></dt>
|
|
|
<dd><p>Container for the session parameters</p>
|
|
|
</dd>
|
|
|
<dt><a href="#SessionManager">SessionManager</a></dt>
|
|
|
<dd><p>SessionManager manages a communication session for Request and Subscribe.
|
|
|
SessionManager monitors if the connection is alive and tries to recover
|
|
|
if the connection is lost.</p>
|
|
|
</dd>
|
|
|
<dt><a href="#Parameter">Parameter</a></dt>
|
|
|
<dd><p>Parameter value with a timestamp</p>
|
... | ... | @@ -37,6 +42,14 @@ Subscribe class simplifies creating and removing subscription groups.</p> |
|
|
</dd>
|
|
|
</dl>
|
|
|
|
|
|
## Constants
|
|
|
|
|
|
<dl>
|
|
|
<dt><a href="#SessionState">SessionState</a></dt>
|
|
|
<dd><p>Enumerator of possible session states</p>
|
|
|
</dd>
|
|
|
</dl>
|
|
|
|
|
|
## Typedefs
|
|
|
|
|
|
<dl>
|
... | ... | @@ -53,313 +66,158 @@ Subscribe class simplifies creating and removing subscription groups.</p> |
|
|
## 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)
|
|
|
* [.MessageTypes](#module_motorcortex.MessageTypes)
|
|
|
* [.Subscribe](#module_motorcortex.Subscribe)
|
|
|
* [.Request](#module_motorcortex.Request)
|
|
|
* [.getParameterFlag](#module_motorcortex.getParameterFlag) ⇒ <code>number</code>
|
|
|
* [.getParameterType](#module_motorcortex.getParameterType) ⇒ <code>number</code>
|
|
|
* [.getPermission](#module_motorcortex.getPermission) ⇒ <code>number</code>
|
|
|
* [.getStatusCode](#module_motorcortex.getStatusCode) ⇒ <code>number</code>
|
|
|
* [.getUserGroup](#module_motorcortex.getUserGroup) ⇒ <code>number</code>
|
|
|
* [.getDataType](#module_motorcortex.getDataType) ⇒ <code>number</code>
|
|
|
* [.statusToStr](#module_motorcortex.statusToStr) ⇒ <code>string</code>
|
|
|
* [.name](#module_motorcortex.name)
|
|
|
|
|
|
<a name="module_motorcortex.MessageTypes"></a>
|
|
|
|
|
|
### motorcortex.MessageTypes
|
|
|
Class MessageTypes is responsible for encoding/decoding motorcortex messages.
|
|
|
|
|
|
**Kind**: static property of [<code>motorcortex</code>](#module_motorcortex)
|
|
|
**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.Subscribe"></a>
|
|
|
* [module.exports](#exp_module_motorcortex--module.exports) ⏏
|
|
|
* [.statusToStr(code)](#module_motorcortex--module.exports.statusToStr) ⇒ <code>string</code>
|
|
|
* [.getDataType(name)](#module_motorcortex--module.exports.getDataType) ⇒ <code>number</code>
|
|
|
* [.getParameterFlag(name)](#module_motorcortex--module.exports.getParameterFlag) ⇒ <code>number</code>
|
|
|
* [.getParameterType(name)](#module_motorcortex--module.exports.getParameterType) ⇒ <code>number</code>
|
|
|
* [.getPermission(name)](#module_motorcortex--module.exports.getPermission) ⇒ <code>number</code>
|
|
|
* [.getStatusCode(name)](#module_motorcortex--module.exports.getStatusCode) ⇒ <code>number</code>
|
|
|
* [.getUserGroup(name)](#module_motorcortex--module.exports.getUserGroup) ⇒ <code>number</code>
|
|
|
|
|
|
### motorcortex.Subscribe
|
|
|
Class Subscribe is responsible for parameter and group subscriptions.
|
|
|
|
|
|
**Kind**: static property of [<code>motorcortex</code>](#module_motorcortex)
|
|
|
**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.Request"></a>
|
|
|
<a name="exp_module_motorcortex--module.exports"></a>
|
|
|
|
|
|
### motorcortex.Request
|
|
|
Class Request is responsible for sending commands to motorcortex core:
|
|
|
for example set/get parameter value commands.
|
|
|
### module.exports ⏏
|
|
|
motorcortex namespace.
|
|
|
|
|
|
**Kind**: static property of [<code>motorcortex</code>](#module_motorcortex)
|
|
|
**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.getParameterFlag"></a>
|
|
|
**Kind**: Exported member
|
|
|
<a name="module_motorcortex--module.exports.statusToStr"></a>
|
|
|
|
|
|
### motorcortex.getParameterFlag ⇒ <code>number</code>
|
|
|
Returns properties of the parameter in tree, like overwrite or linked, etc.
|
|
|
#### module.exports.statusToStr(code) ⇒ <code>string</code>
|
|
|
Returns description of the Motorcortex Status Code. Status codes are defined
|
|
|
in the StatusCode enumerator in msg/motorcortex.proto.
|
|
|
|
|
|
**Kind**: static property of [<code>motorcortex</code>](#module_motorcortex)
|
|
|
**Returns**: <code>number</code> - Id of the flags. Multiple flags could be encoded in the return value.
|
|
|
**See**: ./msg/motorcortex.proto
|
|
|
**Kind**: static method of [<code>module.exports</code>](#exp_module_motorcortex--module.exports)
|
|
|
**Returns**: <code>string</code> - Text description of the status
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| name | <code>string</code> | Name of the flag/property. |
|
|
|
| code | <code>number</code> | Code of the status. |
|
|
|
|
|
|
**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');
|
|
|
}
|
|
|
motorcortex.statusToStr(0x2100);
|
|
|
```
|
|
|
<a name="module_motorcortex.getParameterType"></a>
|
|
|
<a name="module_motorcortex--module.exports.getDataType"></a>
|
|
|
|
|
|
### motorcortex.getParameterType ⇒ <code>number</code>
|
|
|
Returns type of the parameter in tree: input, output or parameter.
|
|
|
#### module.exports.getDataType(name) ⇒ <code>number</code>
|
|
|
Returns a сode of the Parameter Data Type. Сodes are defined
|
|
|
in the DataType enumerator in msg/motorcortex.proto.
|
|
|
|
|
|
**Kind**: static property of [<code>motorcortex</code>](#module_motorcortex)
|
|
|
**Returns**: <code>number</code> - Id of the type
|
|
|
**See**: ./msg/motorcortex.proto
|
|
|
**Kind**: static method of [<code>module.exports</code>](#exp_module_motorcortex--module.exports)
|
|
|
**Returns**: <code>number</code> - Code of the data dype
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| name | <code>string</code> | Name of the type. |
|
|
|
| name | <code>string</code> | Name of the data 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');
|
|
|
if (parameterDataType === motorcortex.getDataType('UINT8')) {
|
|
|
// do something
|
|
|
}
|
|
|
```
|
|
|
<a name="module_motorcortex.getPermission"></a>
|
|
|
|
|
|
### motorcortex.getPermission ⇒ <code>number</code>
|
|
|
Returns type of the parameter permission. Different users/groups may require
|
|
|
access to different and/or protected parts of the parameter tree.
|
|
|
Permission flags allow fine-tuning access levels of the groups.
|
|
|
The Motorcortex permissions structure is similar to that of Unix file permissions.
|
|
|
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)
|
|
|
<a name="module_motorcortex--module.exports.getParameterFlag"></a>
|
|
|
|
|
|
-rwxrwx--- (0770): read, write, & execute for owner and group
|
|
|
(Note: execute flag is used as a permission to open folders)
|
|
|
#### module.exports.getParameterFlag(name) ⇒ <code>number</code>
|
|
|
Returns a сode of the Parameter Flag. Сodes are defined
|
|
|
in the ParameterFlag enumerator in msg/motorcortex.proto.
|
|
|
|
|
|
-rwxrwxr-x (0775): read, write, & execute for owner and group,
|
|
|
read & execute for all others.
|
|
|
|
|
|
-rwxrwxrwx (0777): full access
|
|
|
|
|
|
**Kind**: static property of [<code>motorcortex</code>](#module_motorcortex)
|
|
|
**Returns**: <code>number</code> - Id of the permission
|
|
|
**See**: ./msg/motorcortex.proto
|
|
|
**Kind**: static method of [<code>module.exports</code>](#exp_module_motorcortex--module.exports)
|
|
|
**Returns**: <code>number</code> - Code of the parameter flag
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| name | <code>string</code> | Name of the permission. |
|
|
|
| name | <code>string</code> | Name of the flag. |
|
|
|
|
|
|
**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');
|
|
|
if (parameterFlag === motorcortex.getParameterFlag('OVERWRITE_IS_ACTIVE')) {
|
|
|
// do something
|
|
|
}
|
|
|
```
|
|
|
<a name="module_motorcortex.getStatusCode"></a>
|
|
|
<a name="module_motorcortex--module.exports.getParameterType"></a>
|
|
|
|
|
|
### motorcortex.getStatusCode ⇒ <code>number</code>
|
|
|
Returns a status code of the requested operation.
|
|
|
#### module.exports.getParameterType(name) ⇒ <code>number</code>
|
|
|
Returns a сode of the Parameter Type. Сodes are defined
|
|
|
in the ParameterType enumerator in msg/motorcortex.proto.
|
|
|
|
|
|
**Kind**: static property of [<code>motorcortex</code>](#module_motorcortex)
|
|
|
**Returns**: <code>number</code> - Id of status.
|
|
|
**See**: ./msg/motorcortex.proto
|
|
|
**Kind**: static method of [<code>module.exports</code>](#exp_module_motorcortex--module.exports)
|
|
|
**Returns**: <code>number</code> - Code of the parameter type
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| name | <code>string</code> | Name of status. |
|
|
|
| name | <code>string</code> | Name of the flag. |
|
|
|
|
|
|
**Example**
|
|
|
```js
|
|
|
if (msg.status === motorcortex.getStatusCode('READ_ONLY_MODE')) {
|
|
|
console.log('User is logged-in, read only mode.');
|
|
|
if (parameterType === motorcortex.getParameterType('INPUT')) {
|
|
|
// do something
|
|
|
}
|
|
|
```
|
|
|
<a name="module_motorcortex.getUserGroup"></a>
|
|
|
<a name="module_motorcortex--module.exports.getPermission"></a>
|
|
|
|
|
|
### motorcortex.getUserGroup ⇒ <code>number</code>
|
|
|
Returns a user group.
|
|
|
#### module.exports.getPermission(name) ⇒ <code>number</code>
|
|
|
Returns a сode of the Permision Type. Сodes are defined
|
|
|
in the Permission enumerator in msg/motorcortex.proto.
|
|
|
|
|
|
**Kind**: static property of [<code>motorcortex</code>](#module_motorcortex)
|
|
|
**Returns**: <code>number</code> - Id of group.
|
|
|
**See**: ./msg/motorcortex.proto
|
|
|
**Kind**: static method of [<code>module.exports</code>](#exp_module_motorcortex--module.exports)
|
|
|
**Returns**: <code>number</code> - Code of the permission type
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| name | <code>string</code> | Name of the group. |
|
|
|
| name | <code>string</code> | Name of the permission type. |
|
|
|
|
|
|
**Example**
|
|
|
```js
|
|
|
if (parameter.info.group_id === motorcortex.getUserGroup('ADMINISTRATOR')) {
|
|
|
console.log('Parameter belongs to administrator user group');
|
|
|
if (parameterDataType | motorcortex.getPermission('USER_WRITE')) {
|
|
|
// user has a write access
|
|
|
}
|
|
|
```
|
|
|
<a name="module_motorcortex.getDataType"></a>
|
|
|
<a name="module_motorcortex--module.exports.getStatusCode"></a>
|
|
|
|
|
|
### motorcortex.getDataType ⇒ <code>number</code>
|
|
|
Returns a data type of the item in the parameter tree.
|
|
|
#### module.exports.getStatusCode(name) ⇒ <code>number</code>
|
|
|
Returns a сode of the Status. Сodes are defined
|
|
|
in the StatusCode enumerator in msg/motorcortex.proto.
|
|
|
|
|
|
**Kind**: static property of [<code>motorcortex</code>](#module_motorcortex)
|
|
|
**Returns**: <code>number</code> - id of the data type.
|
|
|
**See**: ./msg/motorcortex.proto
|
|
|
**Kind**: static method of [<code>module.exports</code>](#exp_module_motorcortex--module.exports)
|
|
|
**Returns**: <code>number</code> - Code of the status
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| name | <code>string</code> | Type name of the parameter (see motorcortex.proto, enum DataType). |
|
|
|
| name | <code>string</code> | Name of the status code. |
|
|
|
|
|
|
**Example**
|
|
|
```js
|
|
|
let type_id = parameter.info.dataType;
|
|
|
if (type_id === motorcortex.getDataType('STRING')) {
|
|
|
console.log('Parameter has type string');
|
|
|
if (replyCode === motorcortex.getStatusCode('OK')) {
|
|
|
// all good
|
|
|
console.log(motorcortex.statusToStr(motorcortex.getStatusCode('OK')));
|
|
|
}
|
|
|
```
|
|
|
<a name="module_motorcortex.statusToStr"></a>
|
|
|
<a name="module_motorcortex--module.exports.getUserGroup"></a>
|
|
|
|
|
|
### motorcortex.statusToStr ⇒ <code>string</code>
|
|
|
Converts a status and error codes to a string description
|
|
|
#### module.exports.getUserGroup(name) ⇒ <code>number</code>
|
|
|
Returns a сode of the User Group. Сodes are defined
|
|
|
in the UserGroup enumerator in msg/motorcortex.proto.
|
|
|
|
|
|
**Kind**: static property of [<code>motorcortex</code>](#module_motorcortex)
|
|
|
**Returns**: <code>string</code> - Error description.
|
|
|
**See**: ./msg/motorcortex.proto
|
|
|
**Kind**: static method of [<code>module.exports</code>](#exp_module_motorcortex--module.exports)
|
|
|
**Returns**: <code>number</code> - Code of the user group
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| code | <code>number</code> | An error code. |
|
|
|
| name | <code>string</code> | Name of the user group. |
|
|
|
|
|
|
**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));
|
|
|
});
|
|
|
if (userGroup === motorcortex.getUserGroup('OPERATOR')) {
|
|
|
// operator has an access
|
|
|
}
|
|
|
```
|
|
|
<a name="module_motorcortex.name"></a>
|
|
|
|
|
|
### motorcortex.name
|
|
|
The name of the module
|
|
|
|
|
|
**Kind**: static constant of [<code>motorcortex</code>](#module_motorcortex)
|
|
|
<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
|
... | ... | @@ -404,8 +262,8 @@ let type_load_done = motorcortex_types.load([{ |
|
|
hash: 'msg/motionSL_hash.json'
|
|
|
}]);
|
|
|
|
|
|
type_load_done.then(function () {
|
|
|
console.log('Loaded all data types');}).catch(function (reason) {
|
|
|
type_load_done.then(() => {
|
|
|
console.log('Loaded all data types');}).catch((reason) => {
|
|
|
console.error('Failed to load data types: ' + reason);
|
|
|
});
|
|
|
```
|
... | ... | @@ -454,21 +312,25 @@ Request/Reply communication is used to send commands to a motorcortex server. |
|
|
|
|
|
* [Request](#Request)
|
|
|
* [new exports.Request(protobuf_types)](#new_Request_new)
|
|
|
* [.getMessageTypes()](#Request+getMessageTypes)
|
|
|
* [.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>
|
|
|
* [.encode(msg)](#Request+encode) ⇒ <code>Uint8Array</code>
|
|
|
* [.send(encoded_msg, timeout_ms)](#Request+send) ⇒ <code>Promise.<Object></code>
|
|
|
* [.sendMsg(msg)](#Request+sendMsg) ⇒ <code>Promise.<Object></code>
|
|
|
* [.login(login, password)](#Request+login) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
* [.getSessionTokenMsg()](#Request+getSessionTokenMsg)
|
|
|
* [.restoreSessionMsg()](#Request+restoreSessionMsg)
|
|
|
* [.logout()](#Request+logout) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
* [.getParameterTree()](#Request+getParameterTree) ⇒ <code>Promise.<ParameterTreeMsg></code>
|
|
|
* [.getParameterTree(timeout_msec)](#Request+getParameterTree) ⇒ <code>Promise.<ParameterTreeManager></code>
|
|
|
* [.getParameterTreeHash()](#Request+getParameterTreeHash) ⇒ <code>Promise.<ParameterTreeHashMsg></code>
|
|
|
* [.getParameter(path)](#Request+getParameter) ⇒ <code>Promise.<ParameterMsg></code>
|
|
|
* [.setParameter(path, value, [options])](#Request+setParameter) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
* [.overwriteParameter(path, value, [force_activate], [options])](#Request+overwriteParameter) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
* [.overwriteParameter(path, value, force_activate, [options])](#Request+overwriteParameter) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
* [.releaseParameter(path)](#Request+releaseParameter) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
* [.setParameterList(param_list)](#Request+setParameterList) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
* [.getParameterList(path_list)](#Request+getParameterList) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
* [.getParameterList(path_list, timeout_ms)](#Request+getParameterList) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
* [.createGroup(path_list, group_alias, [frq_divider])](#Request+createGroup) ⇒ <code>Promise.<GroupStatusMsg></code>
|
|
|
* [.removeGroup(group_alias)](#Request+removeGroup) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
* [.save(file_name)](#Request+save) ⇒ <code>Promise.<StatusMsg></code>
|
... | ... | @@ -484,6 +346,12 @@ Creates request object |
|
|
| --- | --- | --- |
|
|
|
| protobuf_types | [<code>MessageTypes</code>](#MessageTypes) | Reference to an instance of the MessageTypes class. |
|
|
|
|
|
|
<a name="Request+getMessageTypes"></a>
|
|
|
|
|
|
### request.getMessageTypes()
|
|
|
Returns loaded message types.
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
<a name="Request+connectionState"></a>
|
|
|
|
|
|
### request.connectionState() ⇒ <code>number</code>
|
... | ... | @@ -493,10 +361,10 @@ Actual Request/reply connection state. |
|
|
**Returns**: <code>number</code> - Returns a 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 could not be opened
|
|
|
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 could not be opened
|
|
|
```
|
|
|
<a name="Request+connect"></a>
|
|
|
|
... | ... | @@ -518,10 +386,10 @@ If connection fails, a short error description is passed to the catch method. |
|
|
let req = new motorcortex.Request(motorcortex_types);
|
|
|
let req_conn_done = req.connect(`ws://${server}:5558`, 10000, 100);
|
|
|
req_conn_done
|
|
|
.then(function () {
|
|
|
.then(() => {
|
|
|
console.log('Request connection is established');
|
|
|
})
|
|
|
.catch(function (reason) {
|
|
|
.catch((reason) => {
|
|
|
console.error('Failed to establish connection: ' + reason);
|
|
|
});
|
|
|
```
|
... | ... | @@ -533,7 +401,7 @@ Closes connection to the server |
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
<a name="Request+encode"></a>
|
|
|
|
|
|
### request.encode(A) ⇒ <code>Uint8Array</code>
|
|
|
### request.encode(msg) ⇒ <code>Uint8Array</code>
|
|
|
Encodes a data type from MessageTypes to a binary wire type.
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
... | ... | @@ -541,7 +409,7 @@ Encodes a data type from MessageTypes to a binary wire type. |
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| A | <code>Object</code> | message created by MotorcortexTypes. |
|
|
|
| msg | <code>Object</code> | A message created by MotorcortexTypes. |
|
|
|
|
|
|
**Example**
|
|
|
```js
|
... | ... | @@ -552,7 +420,7 @@ req.send(encoded_msg); |
|
|
```
|
|
|
<a name="Request+send"></a>
|
|
|
|
|
|
### request.send(encoded_msg) ⇒ <code>Promise.<Object></code>
|
|
|
### request.send(encoded_msg, timeout_ms) ⇒ <code>Promise.<Object></code>
|
|
|
Sends an encoded request to the server
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
... | ... | @@ -562,6 +430,7 @@ If request fails, catch callback is triggered. |
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| encoded_msg | <code>Uint8Array</code> | A binary array with encoded message. |
|
|
|
| timeout_ms | <code>integer</code> | Timeout in milliseconds. |
|
|
|
|
|
|
**Example**
|
|
|
```js
|
... | ... | @@ -569,9 +438,32 @@ 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) {
|
|
|
reply.then((msg) => {
|
|
|
console.log('Got reply: ' + JSON.stringify(msg));
|
|
|
}).catch(function (msg) {
|
|
|
}).catch((msg) => {
|
|
|
console.error('Failed: ' + JSON.stringify(msg));
|
|
|
});
|
|
|
```
|
|
|
<a name="Request+sendMsg"></a>
|
|
|
|
|
|
### request.sendMsg(msg) ⇒ <code>Promise.<Object></code>
|
|
|
Encodes and sends a 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.
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| msg | <code>Object</code> | A 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 reply = req.encodeAndSend(motion_script);
|
|
|
reply.then((msg) => {
|
|
|
console.log('Got reply: ' + JSON.stringify(msg));
|
|
|
}).catch((msg) => {
|
|
|
console.error('Failed: ' + JSON.stringify(msg));
|
|
|
});
|
|
|
```
|
... | ... | @@ -593,12 +485,20 @@ Returned message has a status code, which indicates a status of the login. |
|
|
**Example**
|
|
|
```js
|
|
|
let login_reply = req.login('operator', 'god123');
|
|
|
login_reply.then(function (reply) {
|
|
|
login_reply.then((reply) => {
|
|
|
console.log('Logged-in successful: ' + motorcortex.statusToStr(reply.status));
|
|
|
}).catch( function(reply) {
|
|
|
}).catch((reply) => {
|
|
|
console.log('Failed to login: ' + motorcortex.statusToStr(reply.status));
|
|
|
});
|
|
|
```
|
|
|
<a name="Request+getSessionTokenMsg"></a>
|
|
|
|
|
|
### request.getSessionTokenMsg()
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
<a name="Request+restoreSessionMsg"></a>
|
|
|
|
|
|
### request.restoreSessionMsg()
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
<a name="Request+logout"></a>
|
|
|
|
|
|
### request.logout() ⇒ <code>Promise.<StatusMsg></code>
|
... | ... | @@ -610,27 +510,32 @@ Sends logout request to the server |
|
|
**Example**
|
|
|
```js
|
|
|
let logout_reply = req.logout();
|
|
|
logout_reply.then(function (reply) {
|
|
|
logout_reply.then((reply) => {
|
|
|
console.log('Logged-out successful: ' + motorcortex.statusToStr(reply.status));
|
|
|
}).catch( function(reply) {
|
|
|
}).catch((reply) => {
|
|
|
console.log('Failed to logout: ' + motorcortex.statusToStr(reply.status));
|
|
|
});
|
|
|
```
|
|
|
<a name="Request+getParameterTree"></a>
|
|
|
|
|
|
### request.getParameterTree() ⇒ <code>Promise.<ParameterTreeMsg></code>
|
|
|
Requests a parameter tree from the cache or from the server
|
|
|
### request.getParameterTree(timeout_msec) ⇒ <code>Promise.<ParameterTreeManager></code>
|
|
|
Requests a parameter tree manager to update its structure from the cache or from the server
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
**Returns**: <code>Promise.<ParameterTreeMsg></code> - Returns a Promise, which resolves when parameter tree is received or fails
|
|
|
otherwise. ParameterTreeMsg message has a status files to check the status of the operation.
|
|
|
**See**: motorcortex.proto, ParameterTreeMsg, StatusCode
|
|
|
**Returns**: <code>Promise.<ParameterTreeManager></code> - Returns a Promise, which resolves when the parameter tree is received or fails
|
|
|
otherwise.
|
|
|
**See**: ParameterTreeManager
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| timeout_msec | <code>integer</code> | Timeout in milliseconds. |
|
|
|
|
|
|
**Example**
|
|
|
```js
|
|
|
let param_tree_reply = req.getParameterTree();
|
|
|
param_tree_reply.then(function (param_tree) {
|
|
|
console.log('Got parameter tree msg: ' + JSON.stringify(param_tree));
|
|
|
}).catch( function(param_tree) {
|
|
|
param_tree_reply.then((param_tree_manager) => {
|
|
|
console.log('Got parameter tree msg: ' + JSON.stringify(param_tree_manager.getList()));
|
|
|
}).catch((param_tree) => {
|
|
|
console.log('Failed to get parameter tree: ' + motorcortex.statusToStr(param_tree.status));
|
|
|
});
|
|
|
```
|
... | ... | @@ -646,9 +551,9 @@ fails otherwise. |
|
|
**Example**
|
|
|
```js
|
|
|
let tree_hash_reply = req.getParameterTreeHash();
|
|
|
tree_hash_reply.then(function (tree_hash) {
|
|
|
tree_hash_reply.then((tree_hash) => {
|
|
|
console.log('Got parameter tree hash: ' + tree_hash.hash);
|
|
|
}).catch( function(tree_hash) {
|
|
|
}).catch((tree_hash) => {
|
|
|
console.log('Failed to get tree hash: ' + motorcortex.statusToStr(tree_hash.status));
|
|
|
});
|
|
|
```
|
... | ... | @@ -669,10 +574,10 @@ fails otherwise. |
|
|
**Example**
|
|
|
```js
|
|
|
let param_reply = req.getParameter('root/Control/actualActuatorPositions');
|
|
|
param_reply.then(function (param) {
|
|
|
param_reply.then((param) => {
|
|
|
console.log('Got parameter: ' + JSON.stringify(param));
|
|
|
}).catch( function(param) {
|
|
|
console.log('Failed to get parameter: ' + motorcortex.statusToStr(param.status));
|
|
|
}).catch((param) => {
|
|
|
console.log('Failed to get parameter: ' + motorcortexs.statusToStr(param.status));
|
|
|
});
|
|
|
```
|
|
|
<a name="Request+setParameter"></a>
|
... | ... | @@ -694,7 +599,7 @@ Sets new value to a parameter with given path. |
|
|
```js
|
|
|
// updates a value of a simple parameter
|
|
|
let reply_handle = req.setParameter('root/Motorcontroller/actualmode', 2);
|
|
|
reply_handle.catch( function(reply) {
|
|
|
reply_handle.catch((reply) => {
|
|
|
console.log('Failed to set parameter: ' + motorcortex.statusToStr(reply.status));
|
|
|
});
|
|
|
|
... | ... | @@ -707,7 +612,7 @@ req.setParameter('root/Control/dummyDoubleArray6', [10.0, 20.0], {offset: 4, len |
|
|
```
|
|
|
<a name="Request+overwriteParameter"></a>
|
|
|
|
|
|
### request.overwriteParameter(path, value, [force_activate], [options]) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
### request.overwriteParameter(path, value, force_activate, [options]) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
Overwrites actual value of the parameter and depending on the flag forces this value to stay active.
|
|
|
This method of setting values is useful during debug and installation process, it is not recommended to use
|
|
|
this method during normal operation.
|
... | ... | @@ -720,14 +625,14 @@ this method during normal operation. |
|
|
| --- | --- | --- | --- |
|
|
|
| path | <code>string</code> | | Parameter path in the tree. |
|
|
|
| value | <code>any</code> | | New parameter value. |
|
|
|
| [force_activate] | <code>bool</code> | <code>false</code> | Forces new value to stay active. By default is set to 'false'. |
|
|
|
| force_activate | <code>boolean</code> | <code>false</code> | Forces new value to stay active. By default is set to 'false'. |
|
|
|
| [options] | <code>Object</code> | | Various options to parametrize Set operation. For example 'offset' and 'length' could be used to set an element offset and number of the elements to update in the destination array. |
|
|
|
|
|
|
**Example**
|
|
|
```js
|
|
|
// overwrite and force to stay active a value of a simple parameter
|
|
|
let reply_handle = req.overwriteParameter('root/Motorcontroller/actualmode', 2, true);
|
|
|
reply_handle.catch( function(reply) {
|
|
|
reply_handle.catch((reply) => {
|
|
|
console.log('Failed to set parameter: ' + motorcortex.statusToStr(reply.status));
|
|
|
});
|
|
|
|
... | ... | @@ -755,7 +660,7 @@ otherwise. |
|
|
**Example**
|
|
|
```js
|
|
|
let reply_handle = releaseParameter('root/Motorcontroller/actualmode');
|
|
|
reply_handle.catch( function(reply) {
|
|
|
reply_handle.catch((reply) => {
|
|
|
console.log('Failed to release overwrite of the parameter: ' + motorcortex.statusToStr(reply.status));
|
|
|
});
|
|
|
```
|
... | ... | @@ -778,13 +683,13 @@ otherwise fails. |
|
|
let reply_handle = req.setParameterList([{path: 'root/Motorcontroller/actualmode', value: 2},
|
|
|
{path: 'root/Control/dummyDoubleArray6', value: [1.1,1.2,1.3,1.4,1.5,1.6]},
|
|
|
{path: 'root/Control/dummyDoubleArray6', value: [10.0, 20.0], options: {offset: 4, length: 2}}]);
|
|
|
reply_handle.catch( function(reply) {
|
|
|
reply_handle.catch((reply) => {
|
|
|
console.log('Failed to set list of parameter: ' + motorcortex.statusToStr(reply.status));
|
|
|
});
|
|
|
```
|
|
|
<a name="Request+getParameterList"></a>
|
|
|
|
|
|
### request.getParameterList(path_list) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
### request.getParameterList(path_list, timeout_ms) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
Get info and values of requested parameters.
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
... | ... | @@ -795,13 +700,14 @@ otherwise fails. |
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| path_list | <code>Array.<string></code> | List of parameter paths. |
|
|
|
| timeout_ms | <code>number</code> | Reply timeout in milliseconds. |
|
|
|
|
|
|
**Example**
|
|
|
```js
|
|
|
let reply_handle = req.getParameterList(['root/Motorcontroller/actualmode, 'root/Control/dummyDoubleArray6']);
|
|
|
reply_handle.then( function(param_list) {
|
|
|
reply_handle.then((param_list) => {
|
|
|
console.log('Got parameter list: ' + JSON.stringify(param_list));
|
|
|
}).catch( function(param_list) {
|
|
|
}).catch((param_list) => {
|
|
|
console.log('Failed to get parameter list: ' + motorcortex.statusToStr(param_list.status));
|
|
|
});
|
|
|
```
|
... | ... | @@ -827,9 +733,9 @@ otherwise. |
|
|
// creates a group with two signals, which is published every 10th cycle.
|
|
|
let group_handle = req.createGroup(['root/Motorcontroller/actualmode, 'root/Control/dummyDoubleArray6'],
|
|
|
'myGroup1', 10);
|
|
|
reply_handle.then( function(group) {
|
|
|
reply_handle.then((group) => {
|
|
|
console.log('Group layout: ' + JSON.stringify(group));
|
|
|
}).catch( function(group) {
|
|
|
}).catch((group) => {
|
|
|
console.log('Failed to create group: ' + motorcortex.statusToStr(group.status));
|
|
|
});
|
|
|
```
|
... | ... | @@ -851,7 +757,7 @@ fails otherwise. |
|
|
**Example**
|
|
|
```js
|
|
|
let group_handle = req.removeGroup('myGroup1');
|
|
|
group_handle.catch( function(group) {
|
|
|
group_handle.catch((group) => {
|
|
|
console.log('Failed to remove group: ' + motorcortex.statusToStr(group.status));
|
|
|
});
|
|
|
```
|
... | ... | @@ -872,7 +778,7 @@ fails otherwise. |
|
|
**Example**
|
|
|
```js
|
|
|
let reply = req.save('controls.xml');
|
|
|
reply.catch( function(save) {
|
|
|
reply.catch((save) => {
|
|
|
console.log('Failed to save parameters:' + motorcortex.statusToStr(save.status));
|
|
|
});
|
|
|
```
|
... | ... | @@ -893,84 +799,646 @@ fails otherwise. |
|
|
**Example**
|
|
|
```js
|
|
|
let reply = req.load('controls.xml');
|
|
|
reply.catch( function(load) {
|
|
|
reply.catch((load) => {
|
|
|
console.log('Failed to load parameters:' + motorcortex.statusToStr(load.status));
|
|
|
});
|
|
|
```
|
|
|
<a name="Timestamp"></a>
|
|
|
<a name="RequestAsync"></a>
|
|
|
|
|
|
## Timestamp
|
|
|
Timestamp of the parameter
|
|
|
## RequestAsync
|
|
|
Request/Reply communication is used to send commands to a motorcortex server.
|
|
|
|
|
|
**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>
|
|
|
* [RequestAsync](#RequestAsync)
|
|
|
* [new exports.RequestAsync(protobuf_types)](#new_RequestAsync_new)
|
|
|
* [.getMessageTypes()](#RequestAsync+getMessageTypes)
|
|
|
* [.connectionState()](#RequestAsync+connectionState) ⇒ <code>number</code>
|
|
|
* [.close()](#RequestAsync+close)
|
|
|
* [.login(login, password)](#RequestAsync+login) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
* [.logout()](#RequestAsync+logout) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
* [.getSessionTokenMsg()](#RequestAsync+getSessionTokenMsg)
|
|
|
* [.restoreSessionMsg()](#RequestAsync+restoreSessionMsg)
|
|
|
* [.getParameterTree(timeout_msec)](#RequestAsync+getParameterTree) ⇒ <code>Promise.<ParameterTreeManager></code>
|
|
|
* [.getParameterTreeHash()](#RequestAsync+getParameterTreeHash) ⇒ <code>Promise.<ParameterTreeHashMsg></code>
|
|
|
* [.getParameter(path)](#RequestAsync+getParameter) ⇒ <code>Promise.<ParameterMsg></code>
|
|
|
* [.setParameter(path, value, [options])](#RequestAsync+setParameter) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
* [.overwriteParameter(path, value, force_activate, [options])](#RequestAsync+overwriteParameter) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
* [.releaseParameter(path)](#RequestAsync+releaseParameter) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
* [.setParameterList(param_list)](#RequestAsync+setParameterList) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
* [.getParameterList(path_list, timeout_ms)](#RequestAsync+getParameterList) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
* [.save(file_name)](#RequestAsync+save) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
* [.encode(msg)](#RequestAsync+encode) ⇒ <code>Uint8Array</code>
|
|
|
* [.send(encoded_msg, timeout_ms)](#RequestAsync+send) ⇒ <code>Promise.<Object></code>
|
|
|
* [.sendMsg(msg)](#RequestAsync+sendMsg) ⇒ <code>Promise.<Object></code>
|
|
|
* [.load(file_name)](#RequestAsync+load) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
|
|
|
<a name="new_RequestAsync_new"></a>
|
|
|
|
|
|
### new exports.RequestAsync(protobuf_types)
|
|
|
Creates request object
|
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| protobuf_types | [<code>MessageTypes</code>](#MessageTypes) | Reference to an instance of the MessageTypes class. |
|
|
|
|
|
|
<a name="RequestAsync+getMessageTypes"></a>
|
|
|
|
|
|
### requestAsync.getMessageTypes()
|
|
|
Returns loaded message types.
|
|
|
|
|
|
**Kind**: instance method of [<code>RequestAsync</code>](#RequestAsync)
|
|
|
<a name="RequestAsync+connectionState"></a>
|
|
|
|
|
|
### requestAsync.connectionState() ⇒ <code>number</code>
|
|
|
Actual Request/reply connection state.
|
|
|
|
|
|
**Kind**: instance method of [<code>RequestAsync</code>](#RequestAsync)
|
|
|
**Returns**: <code>number</code> - Returns a 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 could not be opened
|
|
|
```
|
|
|
<a name="RequestAsync+close"></a>
|
|
|
|
|
|
<a name="new_Timestamp_new"></a>
|
|
|
### requestAsync.close()
|
|
|
Closes connection to the server
|
|
|
|
|
|
### new Timestamp(sec, nsec)
|
|
|
Creates a timestamp
|
|
|
**Kind**: instance method of [<code>RequestAsync</code>](#RequestAsync)
|
|
|
<a name="RequestAsync+login"></a>
|
|
|
|
|
|
### requestAsync.login(login, password) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
Sends a login request to the server
|
|
|
|
|
|
**Kind**: instance method of [<code>RequestAsync</code>](#RequestAsync)
|
|
|
**Returns**: <code>Promise.<StatusMsg></code> - Returns a Promise, which resolves if login is successful and fails otherwise.
|
|
|
Returned message has a status code, which indicates a status of the login.
|
|
|
**See**: motorcortex.proto, StatusMsg, StatusCode
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| sec | <code>number</code> | seconds |
|
|
|
| nsec | <code>number</code> | nanoseconds |
|
|
|
| login | <code>string</code> | User login. |
|
|
|
| password | <code>string</code> | User password. |
|
|
|
|
|
|
**Example**
|
|
|
```js
|
|
|
let login_reply = req.login('operator', 'god123');
|
|
|
login_reply.then((reply) => {
|
|
|
console.log('Logged-in successful: ' + motorcortex.statusToStr(reply.status));
|
|
|
}).catch((reply) => {
|
|
|
console.log('Failed to login: ' + motorcortex.statusToStr(reply.status));
|
|
|
});
|
|
|
```
|
|
|
<a name="RequestAsync+logout"></a>
|
|
|
|
|
|
### requestAsync.logout() ⇒ <code>Promise.<StatusMsg></code>
|
|
|
Sends logout request to the server
|
|
|
|
|
|
**Kind**: instance method of [<code>RequestAsync</code>](#RequestAsync)
|
|
|
**Returns**: <code>Promise.<StatusMsg></code> - Returns a Promise, which resolves if login is successful and fails otherwise.
|
|
|
**See**: motorcortex.proto, StatusMsg, StatusCode
|
|
|
**Example**
|
|
|
```js
|
|
|
let logout_reply = req.logout();
|
|
|
logout_reply.then((reply) => {
|
|
|
console.log('Logged-out successful: ' + motorcortex.statusToStr(reply.status));
|
|
|
}).catch((reply) => {
|
|
|
console.log('Failed to logout: ' + motorcortex.statusToStr(reply.status));
|
|
|
});
|
|
|
```
|
|
|
<a name="RequestAsync+getSessionTokenMsg"></a>
|
|
|
|
|
|
### requestAsync.getSessionTokenMsg()
|
|
|
**Kind**: instance method of [<code>RequestAsync</code>](#RequestAsync)
|
|
|
<a name="RequestAsync+restoreSessionMsg"></a>
|
|
|
|
|
|
### requestAsync.restoreSessionMsg()
|
|
|
**Kind**: instance method of [<code>RequestAsync</code>](#RequestAsync)
|
|
|
<a name="RequestAsync+getParameterTree"></a>
|
|
|
|
|
|
### requestAsync.getParameterTree(timeout_msec) ⇒ <code>Promise.<ParameterTreeManager></code>
|
|
|
Requests a parameter tree manager to update its structure from the cache or from the server
|
|
|
|
|
|
<a name="Timestamp+getInSec"></a>
|
|
|
**Kind**: instance method of [<code>RequestAsync</code>](#RequestAsync)
|
|
|
**Returns**: <code>Promise.<ParameterTreeManager></code> - Returns a Promise, which resolves when the parameter tree is received or fails
|
|
|
otherwise.
|
|
|
**See**: ParameterTreeManager
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| timeout_msec | <code>integer</code> | Timeout in milliseconds. |
|
|
|
|
|
|
**Example**
|
|
|
```js
|
|
|
let param_tree_reply = req.getParameterTree();
|
|
|
param_tree_reply.then((param_tree_manager) => {
|
|
|
console.log('Got parameter tree msg: ' + JSON.stringify(param_tree_manager.getList()));
|
|
|
}).catch((param_tree) => {
|
|
|
console.log('Failed to get parameter tree: ' + motorcortex.statusToStr(param_tree.status));
|
|
|
});
|
|
|
```
|
|
|
<a name="RequestAsync+getParameterTreeHash"></a>
|
|
|
|
|
|
### requestAsync.getParameterTreeHash() ⇒ <code>Promise.<ParameterTreeHashMsg></code>
|
|
|
Requests a parameter tree hash from the server
|
|
|
|
|
|
**Kind**: instance method of [<code>RequestAsync</code>](#RequestAsync)
|
|
|
**Returns**: <code>Promise.<ParameterTreeHashMsg></code> - Returns a Promise, which resolves when tree hash message is received or
|
|
|
fails otherwise.
|
|
|
**See**: motorcortex.proto, ParameterTreeHashMsg, StatusCode
|
|
|
**Example**
|
|
|
```js
|
|
|
let tree_hash_reply = req.getParameterTreeHash();
|
|
|
tree_hash_reply.then((tree_hash) => {
|
|
|
console.log('Got parameter tree hash: ' + tree_hash.hash);
|
|
|
}).catch((tree_hash) => {
|
|
|
console.log('Failed to get tree hash: ' + motorcortex.statusToStr(tree_hash.status));
|
|
|
});
|
|
|
```
|
|
|
<a name="RequestAsync+getParameter"></a>
|
|
|
|
|
|
### requestAsync.getParameter(path) ⇒ <code>Promise.<ParameterMsg></code>
|
|
|
Requests a parameter with full information and value from the server
|
|
|
|
|
|
**Kind**: instance method of [<code>RequestAsync</code>](#RequestAsync)
|
|
|
**Returns**: <code>Promise.<ParameterMsg></code> - Returns a Promise, which resolves when parameter message is successfully obtained,
|
|
|
fails otherwise.
|
|
|
**See**: motorcortex.proto, ParameterMsg, StatusCode
|
|
|
|
|
|
### timestamp.getInSec() ⇒ <code>number</code>
|
|
|
Returns a timestamp in seconds
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| path | <code>string</code> | Parameter path in the tree. |
|
|
|
|
|
|
**Kind**: instance method of [<code>Timestamp</code>](#Timestamp)
|
|
|
**Returns**: <code>number</code> - Timestamp in seconds
|
|
|
<a name="Timestamp+getInMilisec"></a>
|
|
|
**Example**
|
|
|
```js
|
|
|
let param_reply = req.getParameter('root/Control/actualActuatorPositions');
|
|
|
param_reply.then((param) => {
|
|
|
console.log('Got parameter: ' + JSON.stringify(param));
|
|
|
}).catch((param) => {
|
|
|
console.log('Failed to get parameter: ' + motorcortex.statusToStr(param.status));
|
|
|
});
|
|
|
```
|
|
|
<a name="RequestAsync+setParameter"></a>
|
|
|
|
|
|
### timestamp.getInMilisec() ⇒ <code>number</code>
|
|
|
Returns a timestamp in milliseconds
|
|
|
### requestAsync.setParameter(path, value, [options]) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
Sets new value to a parameter with given path.
|
|
|
|
|
|
**Kind**: instance method of [<code>Timestamp</code>](#Timestamp)
|
|
|
**Returns**: <code>number</code> - Timestamp in milliseconds
|
|
|
<a name="Timestamp+getInMicrosec"></a>
|
|
|
**Kind**: instance method of [<code>RequestAsync</code>](#RequestAsync)
|
|
|
**Returns**: <code>Promise.<StatusMsg></code> - Returns a Promise, which resolves when parameter value is updated or fails otherwise.
|
|
|
**See**: motorcortex.proto, StatusMsg, StatusCode
|
|
|
|
|
|
### timestamp.getInMicrosec() ⇒ <code>number</code>
|
|
|
Returns a timestamp in microseconds
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| path | <code>string</code> | Parameter path in the tree. |
|
|
|
| value | <code>any</code> | New parameter value. |
|
|
|
| [options] | <code>Object</code> | Various options to parametrize Set operation. For example 'offset' and 'length' could be used to set an element offset and number of the elements to update in the destination array. |
|
|
|
|
|
|
**Kind**: instance method of [<code>Timestamp</code>](#Timestamp)
|
|
|
**Returns**: <code>number</code> - Timestamp in microseconds
|
|
|
<a name="Timestamp+getInNanosec"></a>
|
|
|
**Example**
|
|
|
```js
|
|
|
// updates a value of a simple parameter
|
|
|
let reply_handle = req.setParameter('root/Motorcontroller/actualmode', 2);
|
|
|
reply_handle.catch((reply) => {
|
|
|
console.log('Failed to set parameter: ' + motorcortex.statusToStr(reply.status));
|
|
|
});
|
|
|
|
|
|
### timestamp.getInNanosec() ⇒ <code>number</code>
|
|
|
Returns a timestamp in nanoseconds
|
|
|
// updates an array
|
|
|
req.setParameter('root/Control/dummyDoubleArray6', [1.1,1.2,1.3,1.4,1.5,1.6]);
|
|
|
// updates single element of array with the offset 2 (index 3)
|
|
|
req.setParameter('root/Control/dummyDoubleArray6', 1.0, {offset: 2});
|
|
|
// updates 2 elements of the arrays with the offset 4
|
|
|
req.setParameter('root/Control/dummyDoubleArray6', [10.0, 20.0], {offset: 4, length: 2});
|
|
|
```
|
|
|
<a name="RequestAsync+overwriteParameter"></a>
|
|
|
|
|
|
**Kind**: instance method of [<code>Timestamp</code>](#Timestamp)
|
|
|
**Returns**: <code>number</code> - Timestamp in nanoseconds
|
|
|
<a name="Timestamp+toString"></a>
|
|
|
### requestAsync.overwriteParameter(path, value, force_activate, [options]) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
Overwrites actual value of the parameter and depending on the flag forces this value to stay active.
|
|
|
This method of setting values is useful during debug and installation process, it is not recommended to use
|
|
|
this method during normal operation.
|
|
|
|
|
|
### timestamp.toString() ⇒ <code>string</code>
|
|
|
Returns a timestamp in seconds as a string
|
|
|
**Kind**: instance method of [<code>RequestAsync</code>](#RequestAsync)
|
|
|
**Returns**: <code>Promise.<StatusMsg></code> - Returns a Promise, which resolves when parameter value is updated or fails otherwise.
|
|
|
**See**: motorcortex.proto, StatusMsg, StatusCode
|
|
|
|
|
|
**Kind**: instance method of [<code>Timestamp</code>](#Timestamp)
|
|
|
**Returns**: <code>string</code> - Timestamp in seconds as a string
|
|
|
<a name="Timestamp+compare"></a>
|
|
|
| Param | Type | Default | Description |
|
|
|
| --- | --- | --- | --- |
|
|
|
| path | <code>string</code> | | Parameter path in the tree. |
|
|
|
| value | <code>any</code> | | New parameter value. |
|
|
|
| force_activate | <code>boolean</code> | <code>false</code> | Forces new value to stay active. By default is set to 'false'. |
|
|
|
| [options] | <code>Object</code> | | Various options to parametrize Set operation. For example 'offset' and 'length' could be used to set an element offset and number of the elements to update in the destination array. |
|
|
|
|
|
|
### timestamp.compare(timestamp) ⇒ <code>boolean</code>
|
|
|
Compares two timestamps
|
|
|
**Example**
|
|
|
```js
|
|
|
// overwrite and force to stay active a value of a simple parameter
|
|
|
let reply_handle = req.overwriteParameter('root/Motorcontroller/actualmode', 2, true);
|
|
|
reply_handle.catch((reply) => {
|
|
|
console.log('Failed to set parameter: ' + motorcortex.statusToStr(reply.status));
|
|
|
});
|
|
|
|
|
|
**Kind**: instance method of [<code>Timestamp</code>](#Timestamp)
|
|
|
**Returns**: <code>boolean</code> - true - if timestamps are equal, false - otherwise
|
|
|
// overwrite and force to stay active an array
|
|
|
req.overwriteParameter('root/Control/dummyDoubleArray6', [1.1,1.2,1.3,1.4,1.5,1.6], true);
|
|
|
// overwrite and release force of a single element of the array with an offset 2 (index 3)
|
|
|
req.overwriteParameter('root/Control/dummyDoubleArray6', 1.0, {offset: 2});
|
|
|
// overwrite and force to stay active 2 elements of the arrays with an offset 4
|
|
|
req.overwriteParameter('root/Control/dummyDoubleArray6', [10.0, 20.0], {offset: 4, length: 2});
|
|
|
```
|
|
|
<a name="RequestAsync+releaseParameter"></a>
|
|
|
|
|
|
| Param | Description |
|
|
|
| --- | --- |
|
|
|
| timestamp | Timestamp to compare |
|
|
|
### requestAsync.releaseParameter(path) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
Deactivate overwrite operation of the parameter.
|
|
|
|
|
|
**Kind**: instance method of [<code>RequestAsync</code>](#RequestAsync)
|
|
|
**Returns**: <code>Promise.<StatusMsg></code> - Returns a Promise, which resolves when parameter overwrite is deactivated or fails
|
|
|
otherwise.
|
|
|
**See**: motorcortex.proto, StatusMsg, StatusCode
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| path | <code>string</code> | Path to a parameter in the tree. |
|
|
|
|
|
|
**Example**
|
|
|
```js
|
|
|
let reply_handle = releaseParameter('root/Motorcontroller/actualmode');
|
|
|
reply_handle.catch((reply) => {
|
|
|
console.log('Failed to release overwrite of the parameter: ' + motorcortex.statusToStr(reply.status));
|
|
|
});
|
|
|
```
|
|
|
<a name="RequestAsync+setParameterList"></a>
|
|
|
|
|
|
### requestAsync.setParameterList(param_list) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
Sets new values to a parameter list.
|
|
|
|
|
|
**Kind**: instance method of [<code>RequestAsync</code>](#RequestAsync)
|
|
|
**Returns**: <code>Promise.<StatusMsg></code> - Returns a Promise, which resolves when parameters from the list are updated,
|
|
|
otherwise fails.
|
|
|
**See**: setParameter, motorcortex.proto, StatusMsg, StatusCode
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| param_list | <code>Array.<{path, value, options}></code> | A list of the parameters to update values. |
|
|
|
|
|
|
**Example**
|
|
|
```js
|
|
|
let reply_handle = req.setParameterList([{path: 'root/Motorcontroller/actualmode', value: 2},
|
|
|
{path: 'root/Control/dummyDoubleArray6', value: [1.1,1.2,1.3,1.4,1.5,1.6]},
|
|
|
{path: 'root/Control/dummyDoubleArray6', value: [10.0, 20.0], options: {offset: 4, length: 2}}]);
|
|
|
reply_handle.catch((reply) => {
|
|
|
console.log('Failed to set list of parameter: ' + motorcortex.statusToStr(reply.status));
|
|
|
});
|
|
|
```
|
|
|
<a name="RequestAsync+getParameterList"></a>
|
|
|
|
|
|
### requestAsync.getParameterList(path_list, timeout_ms) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
Get info and values of requested parameters.
|
|
|
|
|
|
**Kind**: instance method of [<code>RequestAsync</code>](#RequestAsync)
|
|
|
**Returns**: <code>Promise.<StatusMsg></code> - Returns a Promise, which resolves when list of the parameter values is received,
|
|
|
otherwise fails.
|
|
|
**See**: getParameter, motorcortex.proto, StatusMsg, StatusCode
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| path_list | <code>Array.<string></code> | List of parameter paths. |
|
|
|
| timeout_ms | <code>number</code> | Reply timeout in milliseconds. |
|
|
|
|
|
|
**Example**
|
|
|
```js
|
|
|
let reply_handle = req.getParameterList(['root/Motorcontroller/actualmode, 'root/Control/dummyDoubleArray6']);
|
|
|
reply_handle.then((param_list) => {
|
|
|
console.log('Got parameter list: ' + JSON.stringify(param_list));
|
|
|
}).catch((param_list) => {
|
|
|
console.log('Failed to get parameter list: ' + motorcortex.statusToStr(param_list.status));
|
|
|
});
|
|
|
```
|
|
|
<a name="RequestAsync+save"></a>
|
|
|
|
|
|
### requestAsync.save(file_name) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
Request a server to save a parameter tree in the file.
|
|
|
|
|
|
**Kind**: instance method of [<code>RequestAsync</code>](#RequestAsync)
|
|
|
**Returns**: <code>Promise.<StatusMsg></code> - Returns a Promise, which resolves when save operation is completed,
|
|
|
fails otherwise.
|
|
|
**See**: motorcortex.proto, StatusMsg, StatusCode
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| file_name | <code>string</code> | A file name where to save actual state of the parameter tree |
|
|
|
|
|
|
**Example**
|
|
|
```js
|
|
|
let reply = req.save('controls.xml');
|
|
|
reply.catch((save) => {
|
|
|
console.log('Failed to save parameters:' + motorcortex.statusToStr(save.status));
|
|
|
});
|
|
|
```
|
|
|
<a name="RequestAsync+encode"></a>
|
|
|
|
|
|
### requestAsync.encode(msg) ⇒ <code>Uint8Array</code>
|
|
|
Encodes a data type from MessageTypes to a binary wire type.
|
|
|
|
|
|
**Kind**: instance method of [<code>RequestAsync</code>](#RequestAsync)
|
|
|
**Returns**: <code>Uint8Array</code> - msg A binary array with encoded message.
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| msg | <code>Object</code> | A 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="RequestAsync+send"></a>
|
|
|
|
|
|
### requestAsync.send(encoded_msg, timeout_ms) ⇒ <code>Promise.<Object></code>
|
|
|
Sends an encoded request to the server
|
|
|
|
|
|
**Kind**: instance method of [<code>RequestAsync</code>](#RequestAsync)
|
|
|
**Returns**: <code>Promise.<Object></code> - Returns a Promise, which completes when reply from the server is received.
|
|
|
If request fails, catch callback is triggered.
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| encoded_msg | <code>Uint8Array</code> | A binary array with encoded message. |
|
|
|
| timeout_ms | <code>integer</code> | Timeout in milliseconds. |
|
|
|
|
|
|
**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((msg) => {
|
|
|
console.log('Got reply: ' + JSON.stringify(msg));
|
|
|
}).catch((msg) => {
|
|
|
console.error('Failed: ' + JSON.stringify(msg));
|
|
|
});
|
|
|
```
|
|
|
<a name="RequestAsync+sendMsg"></a>
|
|
|
|
|
|
### requestAsync.sendMsg(msg) ⇒ <code>Promise.<Object></code>
|
|
|
Encodes and sends a request to the server
|
|
|
|
|
|
**Kind**: instance method of [<code>RequestAsync</code>](#RequestAsync)
|
|
|
**Returns**: <code>Promise.<Object></code> - Returns a Promise, which completes when reply from the server is received.
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| msg | <code>Object</code> | A 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 reply = req.encodeAndSend(motion_script);
|
|
|
reply.then((msg) => {
|
|
|
console.log('Got reply: ' + JSON.stringify(msg));
|
|
|
}).catch((msg) => {
|
|
|
console.error('Failed: ' + JSON.stringify(msg));
|
|
|
});
|
|
|
```
|
|
|
<a name="RequestAsync+load"></a>
|
|
|
|
|
|
### requestAsync.load(file_name) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
Request a server to load value from the file to the parameter tree.
|
|
|
|
|
|
**Kind**: instance method of [<code>RequestAsync</code>](#RequestAsync)
|
|
|
**Returns**: <code>Promise.<StatusMsg></code> - Returns a Promise, which resolves when load operation is complete,
|
|
|
fails otherwise.
|
|
|
**See**: motorcortex.proto, StatusMsg, StatusCode
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| file_name | <code>string</code> | A file name from which to load values to the parameter tree. |
|
|
|
|
|
|
**Example**
|
|
|
```js
|
|
|
let reply = req.load('controls.xml');
|
|
|
reply.catch((load) => {
|
|
|
console.log('Failed to load parameters:' + motorcortex.statusToStr(load.status));
|
|
|
});
|
|
|
```
|
|
|
<a name="ConnectionData"></a>
|
|
|
|
|
|
## ConnectionData
|
|
|
Container for the session parameters
|
|
|
|
|
|
**Kind**: global class
|
|
|
|
|
|
* [ConnectionData](#ConnectionData)
|
|
|
* [new ConnectionData(host, req_port, sub_port, security, request_timeout_ms, tree_timeout_ms, token_update_interval_ms, queue_length)](#new_ConnectionData_new)
|
|
|
* [.getRequestUri()](#ConnectionData+getRequestUri)
|
|
|
* [.getSubscribeUri()](#ConnectionData+getSubscribeUri)
|
|
|
* [.getRequestTimeoutMs()](#ConnectionData+getRequestTimeoutMs)
|
|
|
* [.getTreeTimeoutMs()](#ConnectionData+getTreeTimeoutMs)
|
|
|
* [.getTokenUpdateIntervalMs()](#ConnectionData+getTokenUpdateIntervalMs)
|
|
|
* [.getQueueLength()](#ConnectionData+getQueueLength)
|
|
|
|
|
|
<a name="new_ConnectionData_new"></a>
|
|
|
|
|
|
### new ConnectionData(host, req_port, sub_port, security, request_timeout_ms, tree_timeout_ms, token_update_interval_ms, queue_length)
|
|
|
Creates connection data object
|
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| host | <code>string</code> | Motorcortex server URL. |
|
|
|
| req_port | <code>number</code> | Request port. |
|
|
|
| sub_port | <code>number</code> | Subscribe port. |
|
|
|
| security | <code>boolean</code> | Use secured communication. |
|
|
|
| request_timeout_ms | <code>number</code> | Request timeout in milliseconds.. |
|
|
|
| tree_timeout_ms | <code>number</code> | Request Parameter Tree timeout in milliseconds. |
|
|
|
| token_update_interval_ms | <code>number</code> | Toke update interval in milliseconds. |
|
|
|
| queue_length | <code>number</code> | Maximum size of the request queue. |
|
|
|
|
|
|
<a name="ConnectionData+getRequestUri"></a>
|
|
|
|
|
|
### connectionData.getRequestUri()
|
|
|
Returns request URI, for example wss://192.168.2.200:5568
|
|
|
|
|
|
**Kind**: instance method of [<code>ConnectionData</code>](#ConnectionData)
|
|
|
<a name="ConnectionData+getSubscribeUri"></a>
|
|
|
|
|
|
### connectionData.getSubscribeUri()
|
|
|
Returns subscribe URI, for example wss://192.168.2.200:5567
|
|
|
|
|
|
**Kind**: instance method of [<code>ConnectionData</code>](#ConnectionData)
|
|
|
<a name="ConnectionData+getRequestTimeoutMs"></a>
|
|
|
|
|
|
### connectionData.getRequestTimeoutMs()
|
|
|
Returns request timeout in milliseconds.
|
|
|
|
|
|
**Kind**: instance method of [<code>ConnectionData</code>](#ConnectionData)
|
|
|
<a name="ConnectionData+getTreeTimeoutMs"></a>
|
|
|
|
|
|
### connectionData.getTreeTimeoutMs()
|
|
|
Returns parameter tree request timeout in milliseconds.
|
|
|
|
|
|
**Kind**: instance method of [<code>ConnectionData</code>](#ConnectionData)
|
|
|
<a name="ConnectionData+getTokenUpdateIntervalMs"></a>
|
|
|
|
|
|
### connectionData.getTokenUpdateIntervalMs()
|
|
|
Returns how often session toke is updated.
|
|
|
|
|
|
**Kind**: instance method of [<code>ConnectionData</code>](#ConnectionData)
|
|
|
<a name="ConnectionData+getQueueLength"></a>
|
|
|
|
|
|
### connectionData.getQueueLength()
|
|
|
Returns maximum length of the request queue.
|
|
|
|
|
|
**Kind**: instance method of [<code>ConnectionData</code>](#ConnectionData)
|
|
|
<a name="SessionManager"></a>
|
|
|
|
|
|
## SessionManager
|
|
|
SessionManager manages a communication session for Request and Subscribe.
|
|
|
SessionManager monitors if the connection is alive and tries to recover
|
|
|
if the connection is lost.
|
|
|
|
|
|
**Kind**: global class
|
|
|
|
|
|
* [SessionManager](#SessionManager)
|
|
|
* [.open(connection_data, login_data, options)](#SessionManager+open) ⇒ <code>Promise.<string></code>
|
|
|
* [.close()](#SessionManager+close)
|
|
|
* [.ready()](#SessionManager+ready) ⇒ <code>boolean</code>
|
|
|
* [.hasError()](#SessionManager+hasError) ⇒ <code>boolean</code>
|
|
|
* [.isConnecting()](#SessionManager+isConnecting) ⇒ <code>boolean</code>
|
|
|
* [.notify(observer)](#SessionManager+notify) ⇒ <code>number</code>
|
|
|
* [.remove(id)](#SessionManager+remove)
|
|
|
* [.getState(id)](#SessionManager+getState) ⇒ [<code>SessionState</code>](#SessionState)
|
|
|
|
|
|
<a name="SessionManager+open"></a>
|
|
|
|
|
|
### sessionManager.open(connection_data, login_data, options) ⇒ <code>Promise.<string></code>
|
|
|
Opens new session.
|
|
|
|
|
|
**Kind**: instance method of [<code>SessionManager</code>](#SessionManager)
|
|
|
**Returns**: <code>Promise.<string></code> - A promise, which completes when connection is ready.
|
|
|
If connection fails, a short error description is passed to the catch method.
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| connection_data | [<code>ConnectionData</code>](#ConnectionData) | Motorcortex server URL and all necessary connection parameters. |
|
|
|
| login_data | <code>Object</code> | Login and password to access Motorcortex server. |
|
|
|
| options | <code>Object</code> | Extra option for future use. |
|
|
|
|
|
|
**Example**
|
|
|
```js
|
|
|
let motorcortex_types = new motorcortex.MessageTypes();
|
|
|
let req = new motorcortex.RequestAsync(motorcortex_types);
|
|
|
let sub = new motorcortex.Subscribe(req);
|
|
|
let session = new motorcortex.SessionManager(req, sub);
|
|
|
let open_handle = session.open({
|
|
|
host: '192.168.2.100',
|
|
|
security: true,
|
|
|
request_port: 5568,
|
|
|
subscribe_port: 5567,
|
|
|
timeout_ms: 1000,
|
|
|
queue_length: 1000
|
|
|
}, {
|
|
|
login: 'test',
|
|
|
password: 'test'
|
|
|
});
|
|
|
open_handle.then({
|
|
|
console.log('connection ready');
|
|
|
}).catch(e => {
|
|
|
console.log('connection failed:' + e.text);
|
|
|
});
|
|
|
```
|
|
|
<a name="SessionManager+close"></a>
|
|
|
|
|
|
### sessionManager.close()
|
|
|
Closes connection to the server
|
|
|
|
|
|
**Kind**: instance method of [<code>SessionManager</code>](#SessionManager)
|
|
|
<a name="SessionManager+ready"></a>
|
|
|
|
|
|
### sessionManager.ready() ⇒ <code>boolean</code>
|
|
|
Checks if connection is ready
|
|
|
|
|
|
**Kind**: instance method of [<code>SessionManager</code>](#SessionManager)
|
|
|
**Returns**: <code>boolean</code> - Returns True if connection is ready.
|
|
|
<a name="SessionManager+hasError"></a>
|
|
|
|
|
|
### sessionManager.hasError() ⇒ <code>boolean</code>
|
|
|
Checks if there are connection errors
|
|
|
|
|
|
**Kind**: instance method of [<code>SessionManager</code>](#SessionManager)
|
|
|
**Returns**: <code>boolean</code> - Returns True if connection is in the error state.
|
|
|
<a name="SessionManager+isConnecting"></a>
|
|
|
|
|
|
### sessionManager.isConnecting() ⇒ <code>boolean</code>
|
|
|
Checks if there establishing connection is in progress
|
|
|
|
|
|
**Kind**: instance method of [<code>SessionManager</code>](#SessionManager)
|
|
|
**Returns**: <code>boolean</code> - Returns True if establishing connection is in progress.
|
|
|
<a name="SessionManager+notify"></a>
|
|
|
|
|
|
### sessionManager.notify(observer) ⇒ <code>number</code>
|
|
|
Register an observer, which is notified after communcation state is changed.
|
|
|
|
|
|
**Kind**: instance method of [<code>SessionManager</code>](#SessionManager)
|
|
|
**Returns**: <code>number</code> - id Unique identifier of the registered observer.
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| observer | <code>Object</code> | A callback function, which is called after state is changed. |
|
|
|
|
|
|
**Example**
|
|
|
```js
|
|
|
let motorcortex_types = new motorcortex.MessageTypes();
|
|
|
let req = new motorcortex.RequestAsync(motorcortex_types);
|
|
|
let sub = new motorcortex.Subscribe(req);
|
|
|
let session = new motorcortex.SessionManager(req, sub);
|
|
|
session.notify(data => {
|
|
|
if (session.hasError()) {
|
|
|
console.error('Session error: ' + motorcortex.SessionState.getInfo(data.state));
|
|
|
} else {
|
|
|
console.log('Session state: ' + motorcortex.SessionState.getInfo(data.state));
|
|
|
if (session.ready()) {
|
|
|
let tree = parameter_manager.getTree();
|
|
|
console.log(tree);
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
<a name="SessionManager+remove"></a>
|
|
|
|
|
|
### sessionManager.remove(id)
|
|
|
Removes an observer from the notify list.
|
|
|
|
|
|
**Kind**: instance method of [<code>SessionManager</code>](#SessionManager)
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| id | <code>number</code> | Unique identifier of the registered observer. |
|
|
|
|
|
|
**Example**
|
|
|
```js
|
|
|
let id = session.notify(data => {});
|
|
|
session.remove(id);
|
|
|
```
|
|
|
<a name="SessionManager+getState"></a>
|
|
|
|
|
|
### sessionManager.getState(id) ⇒ [<code>SessionState</code>](#SessionState)
|
|
|
Returns an active state of the communication session.
|
|
|
|
|
|
**Kind**: instance method of [<code>SessionManager</code>](#SessionManager)
|
|
|
**Returns**: [<code>SessionState</code>](#SessionState) - Session state description
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| id | <code>number</code> | Unique identifier of the registered observer. |
|
|
|
|
|
|
**Example**
|
|
|
```js
|
|
|
if (motorcortex.session.getState() == SessionState.OK) {
|
|
|
// session is connected
|
|
|
}
|
|
|
```
|
|
|
<a name="Parameter"></a>
|
|
|
|
|
|
## Parameter
|
... | ... | @@ -980,7 +1448,7 @@ Parameter value with a timestamp |
|
|
|
|
|
* [Parameter](#Parameter)
|
|
|
* [.get()](#Parameter+get) ⇒ <code>Object</code>
|
|
|
* [.getTimestamp()](#Parameter+getTimestamp) ⇒ [<code>Timestamp</code>](#Timestamp)
|
|
|
* [.getTimestamp()](#Parameter+getTimestamp) ⇒ <code>Timestamp</code>
|
|
|
* [.getValue()](#Parameter+getValue) ⇒ <code>DataType</code>
|
|
|
* [.toString()](#Parameter+toString) ⇒ <code>string</code>
|
|
|
|
... | ... | @@ -1005,11 +1473,11 @@ for (let parameter of parameters) { |
|
|
```
|
|
|
<a name="Parameter+getTimestamp"></a>
|
|
|
|
|
|
### parameter.getTimestamp() ⇒ [<code>Timestamp</code>](#Timestamp)
|
|
|
### parameter.getTimestamp() ⇒ <code>Timestamp</code>
|
|
|
Gets parameter timestamp
|
|
|
|
|
|
**Kind**: instance method of [<code>Parameter</code>](#Parameter)
|
|
|
**Returns**: [<code>Timestamp</code>](#Timestamp) - Returns parameter timestamp.
|
|
|
**Returns**: <code>Timestamp</code> - Returns parameter timestamp.
|
|
|
**Example**
|
|
|
```js
|
|
|
// Reads latest update from the subscription
|
... | ... | @@ -1103,10 +1571,10 @@ let data_sub = sub.subscribe(["root/Control/jointReferenceGenerator/enable", |
|
|
"root/Control/jointReferenceGenerator/signalGenerator01/amplitude",
|
|
|
"root/Control/jointReferenceGenerator/signalGenerator02/amplitude"], "group1");
|
|
|
|
|
|
data_sub.then(function (subscription) {
|
|
|
data_sub.then((subscription) => {
|
|
|
console.log("Subscribed: " + subscription);
|
|
|
}).catch(function (subscription) {
|
|
|
console.log("Subscription failed: " + + motorcortex.statusToStr(subscription.status));
|
|
|
}).catch((subscription) => {
|
|
|
console.log("Subscription failed: " + motorcortex.statusToStr(subscription.status));
|
|
|
});
|
|
|
```
|
|
|
<a name="Subscription+catch"></a>
|
... | ... | @@ -1127,10 +1595,10 @@ let data_sub = sub.subscribe(["root/Control/jointReferenceGenerator/enable", |
|
|
"root/Control/jointReferenceGenerator/signalGenerator01/amplitude",
|
|
|
"root/Control/jointReferenceGenerator/signalGenerator02/amplitude"], "group1");
|
|
|
|
|
|
data_sub.then(function (subscription) {
|
|
|
data_sub.then((subscription) => {
|
|
|
console.log("Subscribed: " + subscription);
|
|
|
}).catch(function (subscription) {
|
|
|
console.log("Subscription failed: " + + motorcortex.statusToStr(subscription.status));
|
|
|
}).catch((subscription) => {
|
|
|
console.log("Subscription failed: " + motorcortex.statusToStr(subscription.status));
|
|
|
});
|
|
|
```
|
|
|
<a name="Subscription+read"></a>
|
... | ... | @@ -1153,7 +1621,7 @@ let data_sub = sub.subscribe(["root/Control/jointReferenceGenerator/enable", |
|
|
"root/Control/jointReferenceGenerator/signalGenerator01/amplitude",
|
|
|
"root/Control/jointReferenceGenerator/signalGenerator02/amplitude"], "group1");
|
|
|
|
|
|
data_sub.then(function (subscription) {
|
|
|
data_sub.then((subscription) => {
|
|
|
let group_layout = data_sub.layout();
|
|
|
console.log("Subscribed for: " + group_layout.toString());
|
|
|
});
|
... | ... | @@ -1175,8 +1643,8 @@ let data_sub = sub.subscribe(["root/Control/jointReferenceGenerator/enable", |
|
|
"root/Control/jointReferenceGenerator/signalGenerator01/amplitude",
|
|
|
"root/Control/jointReferenceGenerator/signalGenerator02/amplitude"], "group1");
|
|
|
|
|
|
data_sub.then(function (subscription) {
|
|
|
data_sub.notify(function (parameters) {
|
|
|
data_sub.then((subscription) {
|
|
|
data_sub.notify((parameters) => {
|
|
|
console.log('Received group update');
|
|
|
let layout = data_sub.layout();
|
|
|
for(let i = 0; i < layout.length; i++) {
|
... | ... | @@ -1220,10 +1688,10 @@ Actual Publish/Subscribe connection state. |
|
|
**Returns**: <code>number</code> - Returns a 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 could not be opened
|
|
|
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 could not be opened
|
|
|
```
|
|
|
<a name="Subscribe+connect"></a>
|
|
|
|
... | ... | @@ -1242,10 +1710,10 @@ If connection is failed, short error description is passed to the cathe method. |
|
|
```js
|
|
|
let sub = new motorcortex.Subscribe(req);
|
|
|
let sub_conn_done = sub.connect(`ws://${server}:5557`);
|
|
|
sub_conn_done.then(function () {
|
|
|
sub_conn_done.then(() => {
|
|
|
console.log('Subscribe connection is established');
|
|
|
})
|
|
|
.catch(function (reason) {
|
|
|
.catch((reason) => {
|
|
|
console.error('Failed to establish connection: ' + reason);
|
|
|
});
|
|
|
```
|
... | ... | @@ -1278,24 +1746,24 @@ let data_sub = sub.subscribe(["root/Control/jointReferenceGenerator/enable", |
|
|
"root/Control/jointReferenceGenerator/signalGenerator01/amplitude",
|
|
|
"root/Control/jointReferenceGenerator/signalGenerator02/amplitude"], "group1");
|
|
|
|
|
|
data_sub.then(function (subscription) {
|
|
|
data_sub.then((subscription) => {
|
|
|
console.log('Subscription is ready');
|
|
|
// when subscription is ready, setting an update callback
|
|
|
data_sub.notify(function (parameters) {
|
|
|
data_sub.notify((parameters) {
|
|
|
console.log('Received group update');
|
|
|
let layout = data_sub.layout();
|
|
|
for(let i = 0; i < layout.length; i++) {
|
|
|
console.log("Parameter: " + layout[i] + " value: " + parameters[i].toString());
|
|
|
}
|
|
|
}
|
|
|
}).catch(function (subscription) {
|
|
|
}).catch((subscription) => {
|
|
|
console.log('Failed to subscribe: ' + motorcortex.statusToStr(group.status));
|
|
|
});
|
|
|
```
|
|
|
<a name="Subscribe+unsubscribe"></a>
|
|
|
|
|
|
### subscribe.unsubscribe(group_alias) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
Unsubscribes from the group.
|
|
|
Unsubscribe from the group.
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscribe</code>](#Subscribe)
|
|
|
**Returns**: <code>Promise.<StatusMsg></code> - Returns a Promise, which resolves when the unsubscribe operation is complete,
|
... | ... | @@ -1309,10 +1777,32 @@ fails otherwise. |
|
|
**Example**
|
|
|
```js
|
|
|
let unsub_handle = req.unsubscribe('myGroup1');
|
|
|
unsub_handle.catch( function(unsubscribe) {
|
|
|
unsub_handle.catch((unsubscribe) => {
|
|
|
console.log('Failed to remove group: ' + motorcortex.statusToStr(unsubscribe.status));
|
|
|
});
|
|
|
```
|
|
|
<a name="SessionState"></a>
|
|
|
|
|
|
## SessionState
|
|
|
Enumerator of possible session states
|
|
|
|
|
|
**Kind**: global constant
|
|
|
<a name="SessionState.getInfo"></a>
|
|
|
|
|
|
### SessionState.getInfo(state) ⇒ <code>string</code>
|
|
|
Converts session state to the text
|
|
|
|
|
|
**Kind**: static method of [<code>SessionState</code>](#SessionState)
|
|
|
**Returns**: <code>string</code> - Text description of the session state.
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
| --- | --- | --- |
|
|
|
| state | <code>number</code> | Id of the session state. |
|
|
|
|
|
|
**Example**
|
|
|
```js
|
|
|
console.log('Session state: ' + motorcortex.SessionState.getInfo(motorcortex.SessionState.CONNECTION_FAILED));
|
|
|
```
|
|
|
<a name="SubscriptionClb"></a>
|
|
|
|
|
|
## SubscriptionClb : <code>function</code>
|
... | ... | |