... | @@ -27,10 +27,24 @@ name or by hash, performs encoding and decoding of the messages.</p> |
... | @@ -27,10 +27,24 @@ name or by hash, performs encoding and decoding of the messages.</p> |
|
<dd><p>Parameter value with a timestamp</p>
|
|
<dd><p>Parameter value with a timestamp</p>
|
|
</dd>
|
|
</dd>
|
|
<dt><a href="#Subscription">Subscription</a></dt>
|
|
<dt><a href="#Subscription">Subscription</a></dt>
|
|
<dd><p>Subscription class receives updates from motorcortex server and decodes time and value</p>
|
|
<dd><p>Subscription class represents an active subscription group. It returns latest values and timestamps of the
|
|
|
|
group parameters. Subscription class could be used as an observer, which notifies on every update or could be
|
|
|
|
used as polling.</p>
|
|
</dd>
|
|
</dd>
|
|
<dt><a href="#Subscribe">Subscribe</a></dt>
|
|
<dt><a href="#Subscribe">Subscribe</a></dt>
|
|
<dd><p>Subscribe class for continuously receive requested data, subscribe communication is used</p>
|
|
<dd><p>Subscribe class is used to receive continious parameter updates from motorcortex server.
|
|
|
|
Subscribe class simplifies creating and removing subscription groups.</p>
|
|
|
|
</dd>
|
|
|
|
</dl>
|
|
|
|
|
|
|
|
## Typedefs
|
|
|
|
|
|
|
|
<dl>
|
|
|
|
<dt><a href="#SubscriptionClb">SubscriptionClb</a> : <code>function</code></dt>
|
|
|
|
<dd><p>This callback is resolved when subscription is ready or failed.</p>
|
|
|
|
</dd>
|
|
|
|
<dt><a href="#SubscriptionUpdateClb">SubscriptionUpdateClb</a> : <code>function</code></dt>
|
|
|
|
<dd><p>This callback notifies when subscription is updated with new values.</p>
|
|
</dd>
|
|
</dd>
|
|
</dl>
|
|
</dl>
|
|
|
|
|
... | @@ -74,20 +88,20 @@ Class MessageTypes is responsible for encoding/decoding motorcortex messages. |
... | @@ -74,20 +88,20 @@ Class MessageTypes is responsible for encoding/decoding motorcortex messages. |
|
```js
|
|
```js
|
|
let motorcortex_types = new motorcortex.MessageTypes();
|
|
let motorcortex_types = new motorcortex.MessageTypes();
|
|
let type_load_done = motorcortex_types.load([{
|
|
let type_load_done = motorcortex_types.load([{
|
|
proto: "msg/motorcortex.proto",
|
|
proto: 'msg/motorcortex.proto',
|
|
hash: "msg/motorcortex_hash.json"}, {
|
|
hash: 'msg/motorcortex_hash.json'}, {
|
|
proto: "msg/motionJS.proto",
|
|
proto: 'msg/motionJS.proto',
|
|
hash: "msg/motionJS_hash.json"}, {
|
|
hash: 'msg/motionJS_hash.json'}, {
|
|
proto: "msg/motionSL.proto",
|
|
proto: 'msg/motionSL.proto',
|
|
hash: "msg/motionSL_hash.json"
|
|
hash: 'msg/motionSL_hash.json'
|
|
}]);
|
|
}]);
|
|
|
|
|
|
type_load_done.then(function () {
|
|
type_load_done.then(function () {
|
|
console.log("Loaded all data types");
|
|
console.log('Loaded all data types');
|
|
let load_msg = motorcortex_types.createType('motorcortex.LoadMsg', { path: '', fileName: 'control.xml' });
|
|
let load_msg = motorcortex_types.createType('motorcortex.LoadMsg', { path: '', fileName: 'control.xml' });
|
|
let encoded_msg = this.encode(load_msg);
|
|
let encoded_msg = this.encode(load_msg);
|
|
}).catch(function (reason) {
|
|
}).catch(function (reason) {
|
|
console.error("Failed to load data types: " + reason);
|
|
console.error('Failed to load data types: ' + reason);
|
|
});
|
|
});
|
|
```
|
|
```
|
|
<a name="module_motorcortex--module.exports.Subscribe"></a>
|
|
<a name="module_motorcortex--module.exports.Subscribe"></a>
|
... | @@ -110,7 +124,7 @@ sub_conn_done.then(function () { |
... | @@ -110,7 +124,7 @@ sub_conn_done.then(function () { |
|
console.log('Received an update: ' + msg.toString());
|
|
console.log('Received an update: ' + msg.toString());
|
|
});
|
|
});
|
|
}).catch(function (reason) {
|
|
}).catch(function (reason) {
|
|
console.error("Failed to establish connection: " + reason);
|
|
console.error('Failed to establish connection: ' + reason);
|
|
});
|
|
});
|
|
```
|
|
```
|
|
<a name="module_motorcortex--module.exports.Request"></a>
|
|
<a name="module_motorcortex--module.exports.Request"></a>
|
... | @@ -129,7 +143,7 @@ req_conn_done.then(function () { |
... | @@ -129,7 +143,7 @@ req_conn_done.then(function () { |
|
console.log('Request connection is established');
|
|
console.log('Request connection is established');
|
|
req.setParameter('root/Control/dummyBoolArray6', [1, 2, 3, 4]).then(function (reply) {
|
|
req.setParameter('root/Control/dummyBoolArray6', [1, 2, 3, 4]).then(function (reply) {
|
|
if (reply.status === motorcortex.getStatusCode('OK')) {
|
|
if (reply.status === motorcortex.getStatusCode('OK')) {
|
|
console.log("Parameter set to a new value.);
|
|
console.log('Parameter set to a new value.);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
... | @@ -300,7 +314,7 @@ Converts a status and error codes to a string description |
... | @@ -300,7 +314,7 @@ Converts a status and error codes to a string description |
|
|
|
|
|
**Example**
|
|
**Example**
|
|
```js
|
|
```js
|
|
let login_reply = req.login("operator", "operator123");
|
|
let login_reply = req.login('operator', 'operator123');
|
|
login_reply.then(function (reply) { console.log('Success!') }).catch(function (reply) {
|
|
login_reply.then(function (reply) { console.log('Success!') }).catch(function (reply) {
|
|
console.log('Failed: ' + motorcortex.statusToStr(reply.status));
|
|
console.log('Failed: ' + motorcortex.statusToStr(reply.status));
|
|
});
|
|
});
|
... | @@ -446,19 +460,19 @@ Request/Reply communication is used to send commands to a motorcortex server. |
... | @@ -446,19 +460,19 @@ Request/Reply communication is used to send commands to a motorcortex server. |
|
* [.encode(A)](#Request+encode) ⇒ <code>Uint8Array</code>
|
|
* [.encode(A)](#Request+encode) ⇒ <code>Uint8Array</code>
|
|
* [.send(encoded_msg)](#Request+send) ⇒ <code>Promise.<Object></code>
|
|
* [.send(encoded_msg)](#Request+send) ⇒ <code>Promise.<Object></code>
|
|
* [.login(login, password)](#Request+login) ⇒ <code>Promise.<StatusMsg></code>
|
|
* [.login(login, password)](#Request+login) ⇒ <code>Promise.<StatusMsg></code>
|
|
* [.logout()](#Request+logout) ⇒ <code>Promise</code>
|
|
* [.logout()](#Request+logout) ⇒ <code>Promise.<StatusMsg></code>
|
|
* [.getParameterTree()](#Request+getParameterTree) ⇒ <code>Promise.<any></code>
|
|
* [.getParameterTree()](#Request+getParameterTree) ⇒ <code>Promise.<ParameterTreeMsg></code>
|
|
* [.getParameterTreeHash()](#Request+getParameterTreeHash) ⇒ <code>Promise</code>
|
|
* [.getParameterTreeHash()](#Request+getParameterTreeHash) ⇒ <code>Promise.<ParameterTreeHashMsg></code>
|
|
* [.getParameter(path)](#Request+getParameter) ⇒ <code>Promise</code>
|
|
* [.getParameter(path)](#Request+getParameter) ⇒ <code>Promise.<ParameterMsg></code>
|
|
* [.setParameter(path, value, options)](#Request+setParameter) ⇒ <code>Promise</code>
|
|
* [.setParameter(path, value, [options])](#Request+setParameter) ⇒ <code>Promise.<StatusMsg></code>
|
|
* [.overwriteParameter(path, value, force_activate, options)](#Request+overwriteParameter) ⇒ <code>Promise</code>
|
|
* [.overwriteParameter(path, value, [force_activate], [options])](#Request+overwriteParameter) ⇒ <code>Promise.<StatusMsg></code>
|
|
* [.releaseParameter(path)](#Request+releaseParameter) ⇒ <code>Promise</code>
|
|
* [.releaseParameter(path)](#Request+releaseParameter) ⇒ <code>Promise.<StatusMsg></code>
|
|
* [.setParameterList(param_list)](#Request+setParameterList) ⇒ <code>Promise</code>
|
|
* [.setParameterList(param_list)](#Request+setParameterList) ⇒ <code>Promise.<StatusMsg></code>
|
|
* [.getParameterList(path_list)](#Request+getParameterList) ⇒ <code>Promise</code>
|
|
* [.getParameterList(path_list)](#Request+getParameterList) ⇒ <code>Promise.<StatusMsg></code>
|
|
* [.createGroup(path_list, group_alias, frq_divider)](#Request+createGroup) ⇒ <code>Promise</code>
|
|
* [.createGroup(path_list, group_alias, [frq_divider])](#Request+createGroup) ⇒ <code>Promise.<GroupStatusMsg></code>
|
|
* [.removeGroup(group_alias)](#Request+removeGroup) ⇒ <code>Promise</code>
|
|
* [.removeGroup(group_alias)](#Request+removeGroup) ⇒ <code>Promise.<StatusMsg></code>
|
|
* [.save(path)](#Request+save) ⇒ <code>Promise</code>
|
|
* [.save(file_name)](#Request+save) ⇒ <code>Promise.<StatusMsg></code>
|
|
* [.load(path)](#Request+load) ⇒ <code>Promise</code>
|
|
* [.load(file_name)](#Request+load) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
|
|
|
<a name="new_Request_new"></a>
|
|
<a name="new_Request_new"></a>
|
|
|
|
|
... | @@ -473,10 +487,10 @@ Creates request object |
... | @@ -473,10 +487,10 @@ Creates request object |
|
<a name="Request+connectionState"></a>
|
|
<a name="Request+connectionState"></a>
|
|
|
|
|
|
### request.connectionState() ⇒ <code>number</code>
|
|
### request.connectionState() ⇒ <code>number</code>
|
|
Connection state
|
|
Actual Request/reply connection state.
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
**Returns**: <code>number</code> - returns connection state
|
|
**Returns**: <code>number</code> - Returns a connection state.
|
|
**Example**
|
|
**Example**
|
|
```js
|
|
```js
|
|
CONNECTING 0 The connection is not yet open
|
|
CONNECTING 0 The connection is not yet open
|
... | @@ -505,10 +519,10 @@ let req = new motorcortex.Request(motorcortex_types); |
... | @@ -505,10 +519,10 @@ let req = new motorcortex.Request(motorcortex_types); |
|
let req_conn_done = req.connect(`ws://${server}:5558`, 10000, 100);
|
|
let req_conn_done = req.connect(`ws://${server}:5558`, 10000, 100);
|
|
req_conn_done
|
|
req_conn_done
|
|
.then(function () {
|
|
.then(function () {
|
|
console.log("Request connection is established");
|
|
console.log('Request connection is established');
|
|
})
|
|
})
|
|
.catch(function (reason) {
|
|
.catch(function (reason) {
|
|
console.error("Failed to establish connection: " + reason);
|
|
console.error('Failed to establish connection: ' + reason);
|
|
});
|
|
});
|
|
```
|
|
```
|
|
<a name="Request+close"></a>
|
|
<a name="Request+close"></a>
|
... | @@ -523,7 +537,7 @@ Closes connection to the server |
... | @@ -523,7 +537,7 @@ Closes connection to the server |
|
Encodes a data type from MessageTypes to a binary wire type.
|
|
Encodes a data type from MessageTypes to a binary wire type.
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
**Returns**: <code>Uint8Array</code> - A binary array with encoded message.
|
|
**Returns**: <code>Uint8Array</code> - msg A binary array with encoded message.
|
|
|
|
|
|
| Param | Type | Description |
|
|
| Param | Type | Description |
|
|
| --- | --- | --- |
|
|
| --- | --- | --- |
|
... | @@ -564,7 +578,7 @@ reply.then(function (msg) { |
... | @@ -564,7 +578,7 @@ reply.then(function (msg) { |
|
<a name="Request+login"></a>
|
|
<a name="Request+login"></a>
|
|
|
|
|
|
### request.login(login, password) ⇒ <code>Promise.<StatusMsg></code>
|
|
### request.login(login, password) ⇒ <code>Promise.<StatusMsg></code>
|
|
Sends a login request to a server
|
|
Sends a login request to the server
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
**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.
|
|
**Returns**: <code>Promise.<StatusMsg></code> - Returns a Promise, which resolves if login is successful and fails otherwise.
|
... | @@ -578,7 +592,7 @@ Return message has a status code, which indicates a status of the login. |
... | @@ -578,7 +592,7 @@ Return message has a status code, which indicates a status of the login. |
|
|
|
|
|
**Example**
|
|
**Example**
|
|
```js
|
|
```js
|
|
let login_reply = req.login("operator", "god123");
|
|
let login_reply = req.login('operator', 'god123');
|
|
login_reply.then(function (reply) {
|
|
login_reply.then(function (reply) {
|
|
console.log('Logged-in successful: ' + motorcortex.statusToStr(reply.status));
|
|
console.log('Logged-in successful: ' + motorcortex.statusToStr(reply.status));
|
|
}).catch( function(reply) {
|
|
}).catch( function(reply) {
|
... | @@ -587,147 +601,302 @@ login_reply.then(function (reply) { |
... | @@ -587,147 +601,302 @@ login_reply.then(function (reply) { |
|
```
|
|
```
|
|
<a name="Request+logout"></a>
|
|
<a name="Request+logout"></a>
|
|
|
|
|
|
### request.logout() ⇒ <code>Promise</code>
|
|
### request.logout() ⇒ <code>Promise.<StatusMsg></code>
|
|
Send logout message
|
|
Sends logout request to the server
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
**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.
|
|
|
|
**See**: motorcortex.proto, StatusMsg, StatusCode
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
let logout_reply = req.logout();
|
|
|
|
logout_reply.then(function (reply) {
|
|
|
|
console.log('Logged-out successful: ' + motorcortex.statusToStr(reply.status));
|
|
|
|
}).catch( function(reply) {
|
|
|
|
console.log('Failed to logout: ' + motorcortex.statusToStr(reply.status));
|
|
|
|
});
|
|
|
|
```
|
|
<a name="Request+getParameterTree"></a>
|
|
<a name="Request+getParameterTree"></a>
|
|
|
|
|
|
### request.getParameterTree() ⇒ <code>Promise.<any></code>
|
|
### request.getParameterTree() ⇒ <code>Promise.<ParameterTreeMsg></code>
|
|
Request a parameter tree from the cache or the server
|
|
Requests a parameter tree from the cache or from the server
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
**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
|
|
|
|
**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) {
|
|
|
|
console.log('Failed to get parameter tree: ' + motorcortex.statusToStr(param_tree.status));
|
|
|
|
});
|
|
|
|
```
|
|
<a name="Request+getParameterTreeHash"></a>
|
|
<a name="Request+getParameterTreeHash"></a>
|
|
|
|
|
|
### request.getParameterTreeHash() ⇒ <code>Promise</code>
|
|
### request.getParameterTreeHash() ⇒ <code>Promise.<ParameterTreeHashMsg></code>
|
|
Request a parameter tree hash from the server
|
|
Requests a parameter tree hash from the server
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
**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(function (tree_hash) {
|
|
|
|
console.log('Got parameter tree hash: ' + tree_hash.hash);
|
|
|
|
}).catch( function(tree_hash) {
|
|
|
|
console.log('Failed to get tree hash: ' + motorcortex.statusToStr(tree_hash.status));
|
|
|
|
});
|
|
|
|
```
|
|
<a name="Request+getParameter"></a>
|
|
<a name="Request+getParameter"></a>
|
|
|
|
|
|
### request.getParameter(path) ⇒ <code>Promise</code>
|
|
### request.getParameter(path) ⇒ <code>Promise.<ParameterMsg></code>
|
|
Request a parameter from the server
|
|
Requests a parameter with full information and value from the server
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
**Returns**: <code>Promise.<ParameterMsg></code> - Returns a Promise, which resolves when parameter message is successfully obtained,
|
|
|
|
fails otherwise.
|
|
|
|
**See**: motorcortex.proto, ParameterMsg, StatusCode
|
|
|
|
|
|
| Param | Type | Description |
|
|
| Param | Type | Description |
|
|
| --- | --- | --- |
|
|
| --- | --- | --- |
|
|
| path | <code>string</code> | parameter path |
|
|
| path | <code>string</code> | Parameter path in the tree. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
let param_reply = req.getParameter('root/Control/actualActuatorPositions');
|
|
|
|
param_reply.then(function (param) {
|
|
|
|
console.log('Got parameter: ' + JSON.stringify(param));
|
|
|
|
}).catch( function(param) {
|
|
|
|
console.log('Failed to get parameter: ' + motorcortex.statusToStr(param.status));
|
|
|
|
});
|
|
|
|
```
|
|
<a name="Request+setParameter"></a>
|
|
<a name="Request+setParameter"></a>
|
|
|
|
|
|
### request.setParameter(path, value, options) ⇒ <code>Promise</code>
|
|
### request.setParameter(path, value, [options]) ⇒ <code>Promise.<StatusMsg></code>
|
|
Set parameter value
|
|
Sets new value to a parameter with given path.
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
**Returns**: <code>Promise.<StatusMsg></code> - Returns a Promise, which resolves when parameter value is updated or fails otherwise.
|
|
|
|
**See**: motorcortex.proto, StatusMsg, StatusCode
|
|
|
|
|
|
| Param | Type | Description |
|
|
| Param | Type | Description |
|
|
| --- | --- | --- |
|
|
| --- | --- | --- |
|
|
| path | <code>string</code> | parameter path |
|
|
| path | <code>string</code> | Parameter path in the tree. |
|
|
| value | <code>string</code> | parameter value |
|
|
| value | <code>any</code> | New parameter value. |
|
|
| options | | |
|
|
| [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**
|
|
**Example**
|
|
```js
|
|
```js
|
|
options {offset:, length:}
|
|
// updates a value of a simple parameter
|
|
|
|
let reply_handle = req.setParameter('root/Motorcontroller/actualmode', 2);
|
|
|
|
reply_handle.catch( function(reply) {
|
|
|
|
console.log('Failed to set parameter: ' + motorcortex.statusToStr(reply.status));
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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="Request+overwriteParameter"></a>
|
|
<a name="Request+overwriteParameter"></a>
|
|
|
|
|
|
### request.overwriteParameter(path, value, force_activate, options) ⇒ <code>Promise</code>
|
|
### request.overwriteParameter(path, value, [force_activate], [options]) ⇒ <code>Promise.<StatusMsg></code>
|
|
Overwrite parameter value with a new value
|
|
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.
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
**Returns**: <code>Promise.<StatusMsg></code> - Returns a Promise, which resolves when parameter value is updated or fails otherwise.
|
|
|
|
**See**: motorcortex.proto, StatusMsg, StatusCode
|
|
|
|
|
|
| Param | Type | Default | Description |
|
|
| Param | Type | Default | Description |
|
|
| --- | --- | --- | --- |
|
|
| --- | --- | --- | --- |
|
|
| path | <code>string</code> | | parameter path |
|
|
| path | <code>string</code> | | Parameter path in the tree. |
|
|
| value | <code>string</code> | | parameter value |
|
|
| value | <code>any</code> | | New parameter value. |
|
|
| force_activate | <code>boolean</code> | <code>false</code> | activate force overwrite |
|
|
| [force_activate] | <code>bool</code> | <code>false</code> | Forces new value to stay active. By default is set to 'false'. |
|
|
| options | | | |
|
|
| [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**
|
|
**Example**
|
|
```js
|
|
```js
|
|
options {offset:, length:}
|
|
// 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) {
|
|
|
|
console.log('Failed to set parameter: ' + motorcortex.statusToStr(reply.status));
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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="Request+releaseParameter"></a>
|
|
<a name="Request+releaseParameter"></a>
|
|
|
|
|
|
### request.releaseParameter(path) ⇒ <code>Promise</code>
|
|
### request.releaseParameter(path) ⇒ <code>Promise.<StatusMsg></code>
|
|
Deactivate forced value overwrite
|
|
Deactivate overwrite operation of the parameter.
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
**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 |
|
|
| Param | Type | Description |
|
|
| --- | --- | --- |
|
|
| --- | --- | --- |
|
|
| path | <code>string</code> | parameter path |
|
|
| path | <code>string</code> | Path to a parameter in the tree. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
let reply_handle = releaseParameter('root/Motorcontroller/actualmode');
|
|
|
|
reply_handle.catch( function(reply) {
|
|
|
|
console.log('Failed to release overwrite of the parameter: ' + motorcortex.statusToStr(reply.status));
|
|
|
|
});
|
|
|
|
```
|
|
<a name="Request+setParameterList"></a>
|
|
<a name="Request+setParameterList"></a>
|
|
|
|
|
|
### request.setParameterList(param_list) ⇒ <code>Promise</code>
|
|
### request.setParameterList(param_list) ⇒ <code>Promise.<StatusMsg></code>
|
|
Set parameter value list
|
|
Sets new values to a parameter list.
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
**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 |
|
|
| Param | Type | Description |
|
|
| --- |
|
|
| --- | --- | --- |
|
|
| param_list |
|
|
| 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( function(reply) {
|
|
|
|
console.log('Failed to set list of parameter: ' + motorcortex.statusToStr(reply.status));
|
|
|
|
});
|
|
|
|
```
|
|
<a name="Request+getParameterList"></a>
|
|
<a name="Request+getParameterList"></a>
|
|
|
|
|
|
### request.getParameterList(path_list) ⇒ <code>Promise</code>
|
|
### request.getParameterList(path_list) ⇒ <code>Promise.<StatusMsg></code>
|
|
Get parameter value list
|
|
Get info and values of requested parameters.
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
**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 |
|
|
| Param | Type | Description |
|
|
| --- |
|
|
| --- | --- | --- |
|
|
| path_list |
|
|
| path_list | <code>Array.<string></code> | List of parameter paths. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
let reply_handle = req.getParameterList(['root/Motorcontroller/actualmode, 'root/Control/dummyDoubleArray6']);
|
|
|
|
reply_handle.then( function(param_list) {
|
|
|
|
console.log('Got parameter list: ' + JSON.stringify(param_list));
|
|
|
|
}).catch( function(param_list) {
|
|
|
|
console.log('Failed to get parameter list: ' + motorcortex.statusToStr(param_list.status));
|
|
|
|
});
|
|
|
|
```
|
|
<a name="Request+createGroup"></a>
|
|
<a name="Request+createGroup"></a>
|
|
|
|
|
|
### request.createGroup(path_list, group_alias, frq_divider) ⇒ <code>Promise</code>
|
|
### request.createGroup(path_list, group_alias, [frq_divider]) ⇒ <code>Promise.<GroupStatusMsg></code>
|
|
Create subscription, path can be a single string or an array of strings, group is optional
|
|
Create a subscription group for a list of the parameters. This method is used inside Subscription class, use
|
|
|
|
subscription class instead.
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
**Returns**: <code>Promise.<GroupStatusMsg></code> - Returns a Promise, which resolves when subscription is complete, fails
|
|
|
|
otherwise.
|
|
|
|
**See**: Subscription, motorcortex.proto, GroupStatusMsg, StatusCode
|
|
|
|
|
|
| Param |
|
|
| Param | Type | Description |
|
|
| --- |
|
|
| --- | --- | --- |
|
|
| path_list |
|
|
| path_list | <code>Array.<string></code> | List of the parameters to subscribe to. |
|
|
| group_alias |
|
|
| group_alias | <code>string</code> | Name of the group. |
|
|
| frq_divider |
|
|
| [frq_divider] | <code>number</code> | Frequency divider is downscaling factor of the group publish rate. Default value is 1, every cycle of the publisher. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
// 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) {
|
|
|
|
console.log('Group layout: ' + JSON.stringify(group));
|
|
|
|
}).catch( function(group) {
|
|
|
|
console.log('Failed to create group: ' + motorcortex.statusToStr(group.status));
|
|
|
|
});
|
|
|
|
```
|
|
<a name="Request+removeGroup"></a>
|
|
<a name="Request+removeGroup"></a>
|
|
|
|
|
|
### request.removeGroup(group_alias) ⇒ <code>Promise</code>
|
|
### request.removeGroup(group_alias) ⇒ <code>Promise.<StatusMsg></code>
|
|
Remove subscription
|
|
Unsubscribes from the group. This method is used inside Subscription class, use
|
|
|
|
subscription class instead.
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
**Returns**: <code>Promise.<StatusMsg></code> - Returns a Promise, which resolves when the unsubscribe operation is complete,
|
|
|
|
fails otherwise.
|
|
|
|
**See**: motorcortex.proto, StatusMsg, StatusCode
|
|
|
|
|
|
| Param |
|
|
| Param | Type | Description |
|
|
| --- |
|
|
| --- | --- | --- |
|
|
| group_alias |
|
|
| group_alias | <code>string</code> | Name of the group to unsubscribe from. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
let group_handle = req.removeGroup('myGroup1');
|
|
|
|
group_handle.catch( function(group) {
|
|
|
|
console.log('Failed to remove group: ' + motorcortex.statusToStr(group.status));
|
|
|
|
});
|
|
|
|
```
|
|
<a name="Request+save"></a>
|
|
<a name="Request+save"></a>
|
|
|
|
|
|
### request.save(path) ⇒ <code>Promise</code>
|
|
### request.save(file_name) ⇒ <code>Promise.<StatusMsg></code>
|
|
Save parameters at server
|
|
Request a server to save a parameter tree in the file.
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
**Returns**: <code>Promise.<StatusMsg></code> - Returns a Promise, which resolves when save operation is complete,
|
|
|
|
fails otherwise.
|
|
|
|
**See**: motorcortex.proto, StatusMsg, StatusCode
|
|
|
|
|
|
| Param |
|
|
| Param | Type | Description |
|
|
| --- |
|
|
| --- | --- | --- |
|
|
| path |
|
|
| 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( function(save) {
|
|
|
|
console.log('Failed to save parameters:' + motorcortex.statusToStr(save.status));
|
|
|
|
});
|
|
|
|
```
|
|
<a name="Request+load"></a>
|
|
<a name="Request+load"></a>
|
|
|
|
|
|
### request.load(path) ⇒ <code>Promise</code>
|
|
### request.load(file_name) ⇒ <code>Promise.<StatusMsg></code>
|
|
Load parameters at server
|
|
Request a server to load value from the file to the parameter tree.
|
|
|
|
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
**Kind**: instance method of [<code>Request</code>](#Request)
|
|
|
|
**Returns**: <code>Promise.<StatusMsg></code> - Returns a Promise, which resolves when load operation is complete,
|
|
|
|
fails otherwise.
|
|
|
|
**See**: motorcortex.proto, StatusMsg, StatusCode
|
|
|
|
|
|
| Param |
|
|
| Param | Type | Description |
|
|
| --- |
|
|
| --- | --- | --- |
|
|
| path |
|
|
| 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( function(load) {
|
|
|
|
console.log('Failed to load parameters:' + motorcortex.statusToStr(load.status));
|
|
|
|
});
|
|
|
|
```
|
|
<a name="Timestamp"></a>
|
|
<a name="Timestamp"></a>
|
|
|
|
|
|
## Timestamp
|
|
## Timestamp
|
... | @@ -761,35 +930,35 @@ Creates a timestamp |
... | @@ -761,35 +930,35 @@ Creates a timestamp |
|
Returns a timestamp in seconds
|
|
Returns a timestamp in seconds
|
|
|
|
|
|
**Kind**: instance method of [<code>Timestamp</code>](#Timestamp)
|
|
**Kind**: instance method of [<code>Timestamp</code>](#Timestamp)
|
|
**Returns**: <code>number</code> - timestamp in seconds
|
|
**Returns**: <code>number</code> - Timestamp in seconds
|
|
<a name="Timestamp+getInMilisec"></a>
|
|
<a name="Timestamp+getInMilisec"></a>
|
|
|
|
|
|
### timestamp.getInMilisec() ⇒ <code>number</code>
|
|
### timestamp.getInMilisec() ⇒ <code>number</code>
|
|
Returns a timestamp in milliseconds
|
|
Returns a timestamp in milliseconds
|
|
|
|
|
|
**Kind**: instance method of [<code>Timestamp</code>](#Timestamp)
|
|
**Kind**: instance method of [<code>Timestamp</code>](#Timestamp)
|
|
**Returns**: <code>number</code> - timestamp in milliseconds
|
|
**Returns**: <code>number</code> - Timestamp in milliseconds
|
|
<a name="Timestamp+getInMicrosec"></a>
|
|
<a name="Timestamp+getInMicrosec"></a>
|
|
|
|
|
|
### timestamp.getInMicrosec() ⇒ <code>number</code>
|
|
### timestamp.getInMicrosec() ⇒ <code>number</code>
|
|
Returns a timestamp in microseconds
|
|
Returns a timestamp in microseconds
|
|
|
|
|
|
**Kind**: instance method of [<code>Timestamp</code>](#Timestamp)
|
|
**Kind**: instance method of [<code>Timestamp</code>](#Timestamp)
|
|
**Returns**: <code>number</code> - timestamp in microseconds
|
|
**Returns**: <code>number</code> - Timestamp in microseconds
|
|
<a name="Timestamp+getInNanosec"></a>
|
|
<a name="Timestamp+getInNanosec"></a>
|
|
|
|
|
|
### timestamp.getInNanosec() ⇒ <code>number</code>
|
|
### timestamp.getInNanosec() ⇒ <code>number</code>
|
|
Returns a timestamp in nanoseconds
|
|
Returns a timestamp in nanoseconds
|
|
|
|
|
|
**Kind**: instance method of [<code>Timestamp</code>](#Timestamp)
|
|
**Kind**: instance method of [<code>Timestamp</code>](#Timestamp)
|
|
**Returns**: <code>number</code> - timestamp in nanoseconds
|
|
**Returns**: <code>number</code> - Timestamp in nanoseconds
|
|
<a name="Timestamp+toString"></a>
|
|
<a name="Timestamp+toString"></a>
|
|
|
|
|
|
### timestamp.toString() ⇒ <code>string</code>
|
|
### timestamp.toString() ⇒ <code>string</code>
|
|
Returns a timestamp in seconds as a string
|
|
Returns a timestamp in seconds as a string
|
|
|
|
|
|
**Kind**: instance method of [<code>Timestamp</code>](#Timestamp)
|
|
**Kind**: instance method of [<code>Timestamp</code>](#Timestamp)
|
|
**Returns**: <code>string</code> - timestamp in seconds as a string
|
|
**Returns**: <code>string</code> - Timestamp in seconds as a string
|
|
<a name="Timestamp+compare"></a>
|
|
<a name="Timestamp+compare"></a>
|
|
|
|
|
|
### timestamp.compare(timestamp) ⇒ <code>boolean</code>
|
|
### timestamp.compare(timestamp) ⇒ <code>boolean</code>
|
... | @@ -800,7 +969,7 @@ Compares two timestamps |
... | @@ -800,7 +969,7 @@ Compares two timestamps |
|
|
|
|
|
| Param | Description |
|
|
| Param | Description |
|
|
| --- | --- |
|
|
| --- | --- |
|
|
| timestamp | timestamp to compare |
|
|
| timestamp | Timestamp to compare |
|
|
|
|
|
|
<a name="Parameter"></a>
|
|
<a name="Parameter"></a>
|
|
|
|
|
... | @@ -810,151 +979,227 @@ Parameter value with a timestamp |
... | @@ -810,151 +979,227 @@ Parameter value with a timestamp |
|
**Kind**: global class
|
|
**Kind**: global class
|
|
|
|
|
|
* [Parameter](#Parameter)
|
|
* [Parameter](#Parameter)
|
|
* [new Parameter(timestamp, value)](#new_Parameter_new)
|
|
* [.get()](#Parameter+get) ⇒ <code>Object</code>
|
|
* [.get()](#Parameter+get) ⇒
|
|
|
|
* [.getTimestamp()](#Parameter+getTimestamp) ⇒ [<code>Timestamp</code>](#Timestamp)
|
|
* [.getTimestamp()](#Parameter+getTimestamp) ⇒ [<code>Timestamp</code>](#Timestamp)
|
|
* [.getValue()](#Parameter+getValue) ⇒ <code>\*</code>
|
|
* [.getValue()](#Parameter+getValue) ⇒ <code>DataType</code>
|
|
* [.toString()](#Parameter+toString) ⇒ <code>string</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>
|
|
<a name="Parameter+get"></a>
|
|
|
|
|
|
### parameter.get() ⇒
|
|
### parameter.get() ⇒ <code>Object</code>
|
|
Gets a parameter
|
|
Gets a parameter timestamp and a value
|
|
|
|
|
|
**Kind**: instance method of [<code>Parameter</code>](#Parameter)
|
|
**Kind**: instance method of [<code>Parameter</code>](#Parameter)
|
|
**Returns**: [] array with parameter timestamp and value
|
|
**Returns**: <code>Object</code> - Returns an object with parameter timestamp and value.
|
|
|
|
**See**: motorcortex.proto DataType
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
// Reads latest update from the subscription
|
|
|
|
let parameters = subscription.read();
|
|
|
|
// Iterates through all the parameters
|
|
|
|
for (let parameter of parameters) {
|
|
|
|
// Gets time and value
|
|
|
|
let time_value_pair = parameter.get();
|
|
|
|
console.log('Parameter timestamp: ' + time_value_pair.timestamp + ' value: ', time_value_pair.value);
|
|
|
|
}
|
|
|
|
```
|
|
<a name="Parameter+getTimestamp"></a>
|
|
<a name="Parameter+getTimestamp"></a>
|
|
|
|
|
|
### parameter.getTimestamp() ⇒ [<code>Timestamp</code>](#Timestamp)
|
|
### parameter.getTimestamp() ⇒ [<code>Timestamp</code>](#Timestamp)
|
|
Gets a parameter's timestamp
|
|
Gets parameter timestamp
|
|
|
|
|
|
**Kind**: instance method of [<code>Parameter</code>](#Parameter)
|
|
**Kind**: instance method of [<code>Parameter</code>](#Parameter)
|
|
**Returns**: [<code>Timestamp</code>](#Timestamp) - timestamp
|
|
**Returns**: [<code>Timestamp</code>](#Timestamp) - Returns parameter timestamp.
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
// Reads latest update from the subscription
|
|
|
|
let parameters = subscription.read();
|
|
|
|
// Iterates through all the parameters
|
|
|
|
for (let parameter of parameters) {
|
|
|
|
// Gets time
|
|
|
|
console.log('Parameter timestamp: ' + parameter.getTimestamp());
|
|
|
|
}
|
|
|
|
```
|
|
<a name="Parameter+getValue"></a>
|
|
<a name="Parameter+getValue"></a>
|
|
|
|
|
|
### parameter.getValue() ⇒ <code>\*</code>
|
|
### parameter.getValue() ⇒ <code>DataType</code>
|
|
Gets a parameter value
|
|
Gets parameter value/
|
|
|
|
|
|
**Kind**: instance method of [<code>Parameter</code>](#Parameter)
|
|
**Kind**: instance method of [<code>Parameter</code>](#Parameter)
|
|
**Returns**: <code>\*</code> - value
|
|
**Returns**: <code>DataType</code> - Returns parameter value.
|
|
|
|
**See**: motorcortex.proto DataType
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
Reads latest update from the subscription
|
|
|
|
let parameters = subscription.read();
|
|
|
|
// Iterates through all the parameters
|
|
|
|
for (let parameter of parameters) {
|
|
|
|
// Gets value
|
|
|
|
console.log('Parameter value: ', parameter.getValue());
|
|
|
|
}
|
|
|
|
```
|
|
<a name="Parameter+toString"></a>
|
|
<a name="Parameter+toString"></a>
|
|
|
|
|
|
### parameter.toString() ⇒ <code>string</code>
|
|
### parameter.toString() ⇒ <code>string</code>
|
|
Gets a parameter as a string
|
|
Gets parameter as a string
|
|
|
|
|
|
**Kind**: instance method of [<code>Parameter</code>](#Parameter)
|
|
**Kind**: instance method of [<code>Parameter</code>](#Parameter)
|
|
**Returns**: <code>string</code> - string formatted as 'timestamp: parameter'
|
|
**Returns**: <code>string</code> - String formatted as 'timestamp: parameter'.
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
Reads latest update from the subscription
|
|
|
|
let parameters = subscription.read();
|
|
|
|
// Iterates through all the parameters
|
|
|
|
for (let parameter of parameters) {
|
|
|
|
// Gets value
|
|
|
|
console.log('Parameter value: ', parameter.toString());
|
|
|
|
}
|
|
|
|
```
|
|
<a name="Subscription"></a>
|
|
<a name="Subscription"></a>
|
|
|
|
|
|
## Subscription
|
|
## Subscription
|
|
Subscription class receives updates from motorcortex server and decodes time and value
|
|
Subscription class represents an active subscription group. It returns latest values and timestamps of the
|
|
|
|
group parameters. Subscription class could be used as an observer, which notifies on every update or could be
|
|
|
|
used as polling.
|
|
|
|
|
|
**Kind**: global class
|
|
**Kind**: global class
|
|
|
|
|
|
* [Subscription](#Subscription)
|
|
* [Subscription](#Subscription)
|
|
* [new Subscription(group_alias, protobuf_types)](#new_Subscription_new)
|
|
* [.id()](#Subscription+id) ⇒ <code>number</code>
|
|
* [.id()](#Subscription+id)
|
|
* [.alias()](#Subscription+alias) ⇒ <code>string</code>
|
|
* [.alias()](#Subscription+alias) ⇒ <code>\*</code>
|
|
* [.then(subscription_complete)](#Subscription+then) ⇒ <code>Promise.<GroupStatusMsg></code>
|
|
* [.then(clb)](#Subscription+then) ⇒ <code>Promise.<any></code>
|
|
* [.catch(subscription_failed)](#Subscription+catch) ⇒ <code>Promise.<GroupStatusMsg></code>
|
|
* [.catch(clb)](#Subscription+catch) ⇒ <code>Promise.<any></code>
|
|
* [.read()](#Subscription+read) ⇒ [<code>Array.<Parameter></code>](#Parameter)
|
|
* [.read()](#Subscription+read) ⇒ <code>\*</code>
|
|
* [.layout()](#Subscription+layout) ⇒ <code>Array.<string></code>
|
|
* [.layout()](#Subscription+layout) ⇒ <code>\*</code>
|
|
|
|
* [.notify(observer)](#Subscription+notify)
|
|
* [.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>
|
|
<a name="Subscription+id"></a>
|
|
|
|
|
|
### subscription.id()
|
|
### subscription.id() ⇒ <code>number</code>
|
|
Return subscription identifier
|
|
Returns subscription identifier
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscription</code>](#Subscription)
|
|
**Kind**: instance method of [<code>Subscription</code>](#Subscription)
|
|
<a name="Subscription+alias"></a>
|
|
<a name="Subscription+alias"></a>
|
|
|
|
|
|
### subscription.alias() ⇒ <code>\*</code>
|
|
### subscription.alias() ⇒ <code>string</code>
|
|
Return group alias
|
|
Return group alias
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscription</code>](#Subscription)
|
|
**Kind**: instance method of [<code>Subscription</code>](#Subscription)
|
|
<a name="Subscription+then"></a>
|
|
<a name="Subscription+then"></a>
|
|
|
|
|
|
### subscription.then(clb) ⇒ <code>Promise.<any></code>
|
|
### subscription.then(subscription_complete) ⇒ <code>Promise.<GroupStatusMsg></code>
|
|
Returns Promise interface (then)
|
|
Returns a Promise which is resolved when subscription request is complete.
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscription</code>](#Subscription)
|
|
**Kind**: instance method of [<code>Subscription</code>](#Subscription)
|
|
|
|
**See**: motorcortex.proto GroupStatusMsg
|
|
|
|
|
|
| Param |
|
|
| Param | Type | Description |
|
|
| --- |
|
|
| --- | --- | --- |
|
|
| clb |
|
|
| subscription_complete | [<code>SubscriptionClb</code>](#SubscriptionClb) | A callback which is resolved when subscription is complete. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
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) {
|
|
|
|
console.log("Subscribed: " + subscription);
|
|
|
|
}).catch(function (subscription) {
|
|
|
|
console.log("Subscription failed: " + + motorcortex.statusToStr(subscription.status));
|
|
|
|
});
|
|
|
|
```
|
|
<a name="Subscription+catch"></a>
|
|
<a name="Subscription+catch"></a>
|
|
|
|
|
|
### subscription.catch(clb) ⇒ <code>Promise.<any></code>
|
|
### subscription.catch(subscription_failed) ⇒ <code>Promise.<GroupStatusMsg></code>
|
|
Returns Promise interface (catch)
|
|
Returns a Promise which is resolved when subscription request fails.
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscription</code>](#Subscription)
|
|
**Kind**: instance method of [<code>Subscription</code>](#Subscription)
|
|
|
|
**See**: motorcortex.proto GroupStatusMsg
|
|
|
|
|
|
| Param |
|
|
| Param | Type | Description |
|
|
| --- |
|
|
| --- | --- | --- |
|
|
| clb |
|
|
| subscription_failed | [<code>SubscriptionClb</code>](#SubscriptionClb) | A callback which is resolved when subscription fails. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
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) {
|
|
|
|
console.log("Subscribed: " + subscription);
|
|
|
|
}).catch(function (subscription) {
|
|
|
|
console.log("Subscription failed: " + + motorcortex.statusToStr(subscription.status));
|
|
|
|
});
|
|
|
|
```
|
|
<a name="Subscription+read"></a>
|
|
<a name="Subscription+read"></a>
|
|
|
|
|
|
### subscription.read() ⇒ <code>\*</code>
|
|
### subscription.read() ⇒ [<code>Array.<Parameter></code>](#Parameter)
|
|
Read complete group
|
|
Reads the latest values of the parameters in the group
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscription</code>](#Subscription)
|
|
**Kind**: instance method of [<code>Subscription</code>](#Subscription)
|
|
|
|
**Returns**: [<code>Array.<Parameter></code>](#Parameter) - Returns a list of parameters.
|
|
<a name="Subscription+layout"></a>
|
|
<a name="Subscription+layout"></a>
|
|
|
|
|
|
### subscription.layout() ⇒ <code>\*</code>
|
|
### subscription.layout() ⇒ <code>Array.<string></code>
|
|
Get layout
|
|
Gets a layout of the group.
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscription</code>](#Subscription)
|
|
**Kind**: instance method of [<code>Subscription</code>](#Subscription)
|
|
|
|
**Returns**: <code>Array.<string></code> - Returns ordered list of the parameters in the group.
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
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) {
|
|
|
|
let group_layout = data_sub.layout();
|
|
|
|
console.log("Subscribed for: " + group_layout.toString());
|
|
|
|
});
|
|
|
|
```
|
|
<a name="Subscription+notify"></a>
|
|
<a name="Subscription+notify"></a>
|
|
|
|
|
|
### subscription.notify(observer)
|
|
### subscription.notify(observer)
|
|
Set listener
|
|
Sets an observer, which is notified on every group update.
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscription</code>](#Subscription)
|
|
**Kind**: instance method of [<code>Subscription</code>](#Subscription)
|
|
|
|
|
|
| Param |
|
|
| Param | Type | Description |
|
|
| --- |
|
|
| --- | --- | --- |
|
|
| observer |
|
|
| observer | [<code>SubscriptionUpdateClb</code>](#SubscriptionUpdateClb) | A callback to notify when new values are available. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
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) {
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
<a name="Subscribe"></a>
|
|
<a name="Subscribe"></a>
|
|
|
|
|
|
## Subscribe
|
|
## Subscribe
|
|
Subscribe class for continuously receive requested data, subscribe communication is used
|
|
Subscribe class is used to receive continious parameter updates from motorcortex server.
|
|
|
|
Subscribe class simplifies creating and removing subscription groups.
|
|
|
|
|
|
**Kind**: global class
|
|
**Kind**: global class
|
|
|
|
|
|
* [Subscribe](#Subscribe)
|
|
* [Subscribe](#Subscribe)
|
|
* [new exports.Subscribe(request)](#new_Subscribe_new)
|
|
* [new exports.Subscribe(request)](#new_Subscribe_new)
|
|
* [.connectionState()](#Subscribe+connectionState) ⇒ <code>number</code>
|
|
* [.connectionState()](#Subscribe+connectionState) ⇒ <code>number</code>
|
|
* [.connect(url)](#Subscribe+connect) ⇒ <code>Promise.<any></code>
|
|
* [.connect(url)](#Subscribe+connect) ⇒ <code>Promise.<string></code>
|
|
* [.connectionClosed()](#Subscribe+connectionClosed) ⇒ <code>Promise</code>
|
|
|
|
* [.close()](#Subscribe+close)
|
|
* [.close()](#Subscribe+close)
|
|
* [.subscribe(param_list, group_alias, frq_divider)](#Subscribe+subscribe) ⇒ [<code>Subscription</code>](#Subscription)
|
|
* [.subscribe(path_list, group_alias, [frq_divider])](#Subscribe+subscribe) ⇒ <code>Subscription.<GroupStatusMsg></code>
|
|
* [.unsubscribe(group_alias)](#Subscribe+unsubscribe) ⇒ <code>Promise</code>
|
|
* [.unsubscribe(group_alias)](#Subscribe+unsubscribe) ⇒ <code>Promise.<StatusMsg></code>
|
|
|
|
|
|
<a name="new_Subscribe_new"></a>
|
|
<a name="new_Subscribe_new"></a>
|
|
|
|
|
... | @@ -969,58 +1214,123 @@ Create subscribe |
... | @@ -969,58 +1214,123 @@ Create subscribe |
|
<a name="Subscribe+connectionState"></a>
|
|
<a name="Subscribe+connectionState"></a>
|
|
|
|
|
|
### subscribe.connectionState() ⇒ <code>number</code>
|
|
### subscribe.connectionState() ⇒ <code>number</code>
|
|
Get connection state
|
|
Actual Publish/Subscribe connection state.
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscribe</code>](#Subscribe)
|
|
**Kind**: instance method of [<code>Subscribe</code>](#Subscribe)
|
|
**Returns**: <code>number</code> - connection state
|
|
**Returns**: <code>number</code> - Returns a connection state.
|
|
**Example**
|
|
**Example**
|
|
```js
|
|
```js
|
|
CONNECTING 0 the connection is not yet open
|
|
CONNECTING 0 The connection is not yet open
|
|
OPEN 1 the connection is open and ready to communicate
|
|
OPEN 1 The connection is open and ready to communicate
|
|
CLOSING 2 the connection is in the process of closing
|
|
CLOSING 2 The connection is in the process of closing
|
|
CLOSED 3 the connection is closed or couldn't be opened
|
|
CLOSED 3 The connection is closed or couldn't be opened
|
|
```
|
|
```
|
|
<a name="Subscribe+connect"></a>
|
|
<a name="Subscribe+connect"></a>
|
|
|
|
|
|
### subscribe.connect(url) ⇒ <code>Promise.<any></code>
|
|
### subscribe.connect(url) ⇒ <code>Promise.<string></code>
|
|
Connect to the server
|
|
Opens a subscribe connection.
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscribe</code>](#Subscribe)
|
|
**Kind**: instance method of [<code>Subscribe</code>](#Subscribe)
|
|
|
|
**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 |
|
|
| Param | Type | Description |
|
|
| --- | --- | --- |
|
|
| --- | --- | --- |
|
|
| url | <code>string</code> | path to the motorcortex server |
|
|
| url | <code>string</code> | Motorcortex server URL. |
|
|
|
|
|
|
<a name="Subscribe+connectionClosed"></a>
|
|
|
|
|
|
|
|
### subscribe.connectionClosed() ⇒ <code>Promise</code>
|
|
**Example**
|
|
**Kind**: instance method of [<code>Subscribe</code>](#Subscribe)
|
|
```js
|
|
|
|
let sub = new motorcortex.Subscribe(req);
|
|
|
|
let sub_conn_done = sub.connect(`ws://${server}:5557`);
|
|
|
|
sub_conn_done.then(function () {
|
|
|
|
console.log('Subscribe connection is established');
|
|
|
|
})
|
|
|
|
.catch(function (reason) {
|
|
|
|
console.error('Failed to establish connection: ' + reason);
|
|
|
|
});
|
|
|
|
```
|
|
<a name="Subscribe+close"></a>
|
|
<a name="Subscribe+close"></a>
|
|
|
|
|
|
### subscribe.close()
|
|
### subscribe.close()
|
|
Close connection
|
|
Closes connection to the server
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscribe</code>](#Subscribe)
|
|
**Kind**: instance method of [<code>Subscribe</code>](#Subscribe)
|
|
<a name="Subscribe+subscribe"></a>
|
|
<a name="Subscribe+subscribe"></a>
|
|
|
|
|
|
### subscribe.subscribe(param_list, group_alias, frq_divider) ⇒ [<code>Subscription</code>](#Subscription)
|
|
### subscribe.subscribe(path_list, group_alias, [frq_divider]) ⇒ <code>Subscription.<GroupStatusMsg></code>
|
|
Create subscription
|
|
Create a subscription group for a list of the parameters.
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscribe</code>](#Subscribe)
|
|
**Kind**: instance method of [<code>Subscribe</code>](#Subscribe)
|
|
|
|
**Returns**: <code>Subscription.<GroupStatusMsg></code> - Returns a Subsciption handle. It acts as a Promise, it is resolved
|
|
|
|
when subscription is ready or failed. After subscription is ready the Subscription handle is used to retrieve
|
|
|
|
the latest data.
|
|
|
|
**See**: Subscription, motorcortex.proto, GroupStatusMsg, StatusCode
|
|
|
|
|
|
| Param |
|
|
| Param | Type | Description |
|
|
| --- |
|
|
| --- | --- | --- |
|
|
| param_list |
|
|
| path_list | <code>Array.<string></code> | List of the parameters to subscribe to. |
|
|
| group_alias |
|
|
| group_alias | <code>string</code> | Name of the group. |
|
|
| frq_divider |
|
|
| [frq_divider] | <code>number</code> | Frequency divider is downscaling factor of the group publish rate. Default value is 1, every cycle of the publisher. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
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) {
|
|
|
|
console.log('Subscription is ready');
|
|
|
|
// when subscription is ready, setting an update callback
|
|
|
|
data_sub.notify(function (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) {
|
|
|
|
console.log('Failed to subscribe: ' + motorcortex.statusToStr(group.status));
|
|
|
|
});
|
|
|
|
```
|
|
<a name="Subscribe+unsubscribe"></a>
|
|
<a name="Subscribe+unsubscribe"></a>
|
|
|
|
|
|
### subscribe.unsubscribe(group_alias) ⇒ <code>Promise</code>
|
|
### subscribe.unsubscribe(group_alias) ⇒ <code>Promise.<StatusMsg></code>
|
|
Remove subscription
|
|
Unsubscribes from the group.
|
|
|
|
|
|
**Kind**: instance method of [<code>Subscribe</code>](#Subscribe)
|
|
**Kind**: instance method of [<code>Subscribe</code>](#Subscribe)
|
|
|
|
**Returns**: <code>Promise.<StatusMsg></code> - Returns a Promise, which resolves when the unsubscribe operation is complete,
|
|
|
|
fails otherwise.
|
|
|
|
**See**: motorcortex.proto, StatusMsg, StatusCode
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| group_alias | <code>string</code> | Name of the group to unsubscribe from. |
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
```js
|
|
|
|
let unsub_handle = req.unsubscribe('myGroup1');
|
|
|
|
unsub_handle.catch( function(unsubscribe) {
|
|
|
|
console.log('Failed to remove group: ' + motorcortex.statusToStr(unsubscribe.status));
|
|
|
|
});
|
|
|
|
```
|
|
|
|
<a name="SubscriptionClb"></a>
|
|
|
|
|
|
|
|
## SubscriptionClb : <code>function</code>
|
|
|
|
This callback is resolved when subscription is ready or failed.
|
|
|
|
|
|
|
|
**Kind**: global typedef
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| status | <code>GroupStatusMsg</code> | A status and layout of the subscribe request. |
|
|
|
|
|
|
| Param |
|
|
<a name="SubscriptionUpdateClb"></a>
|
|
| --- |
|
|
|
|
| group_alias | |
|
## SubscriptionUpdateClb : <code>function</code>
|
|
|
|
This callback notifies when subscription is updated with new values.
|
|
|
|
|
|
|
|
**Kind**: global typedef
|
|
|
|
|
|
|
|
| Param | Type | Description |
|
|
|
|
| --- | --- | --- |
|
|
|
|
| parameters | [<code>Array.<Parameter></code>](#Parameter) | A list of values and timestamps, ordered according to the group layout. | |