motion-master-client 0.0.76 → 0.0.85

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/README.md +227 -138
  2. package/package.json +1 -1
  3. package/src/cli.d.ts +1 -1
  4. package/src/cli.js +160 -160
  5. package/src/index.d.ts +30 -28
  6. package/src/index.js +33 -31
  7. package/src/index.js.map +1 -1
  8. package/src/lib/cia402.d.ts +184 -182
  9. package/src/lib/cia402.js +393 -391
  10. package/src/lib/cia402.js.map +1 -1
  11. package/src/lib/config-file.d.ts +13 -13
  12. package/src/lib/config-file.js +49 -49
  13. package/src/lib/data-monitoring.d.ts +12 -12
  14. package/src/lib/data-monitoring.js +33 -33
  15. package/src/lib/device-log-line.d.ts +5 -5
  16. package/src/lib/device-log-line.js +2 -2
  17. package/src/lib/device-parameter.d.ts +56 -56
  18. package/src/lib/device-parameter.js +38 -38
  19. package/src/lib/device.d.ts +46 -9
  20. package/src/lib/device.js +166 -2
  21. package/src/lib/device.js.map +1 -1
  22. package/src/lib/encoder-register.d.ts +16 -16
  23. package/src/lib/encoder-register.js +116 -116
  24. package/src/lib/hardware-description.d.ts +46 -46
  25. package/src/lib/hardware-description.js +109 -109
  26. package/src/lib/integro-encoder-calibration.d.ts +31 -0
  27. package/src/lib/integro-encoder-calibration.js +196 -0
  28. package/src/lib/integro-encoder-calibration.js.map +1 -0
  29. package/src/lib/logger.d.ts +1 -1
  30. package/src/lib/logger.js +7 -7
  31. package/src/lib/monitoring-config.d.ts +31 -31
  32. package/src/lib/monitoring-config.js +2 -2
  33. package/src/lib/monitoring-entry.d.ts +9 -9
  34. package/src/lib/monitoring-entry.js +2 -2
  35. package/src/lib/motion-master-client.d.ts +77 -77
  36. package/src/lib/motion-master-client.js +196 -196
  37. package/src/lib/motion-master-pub-sub-client.d.ts +17 -17
  38. package/src/lib/motion-master-pub-sub-client.js +72 -72
  39. package/src/lib/motion-master-pub-sub-client.js.map +1 -1
  40. package/src/lib/motion-master-pub-sub-socket.d.ts +42 -42
  41. package/src/lib/motion-master-pub-sub-socket.js +2 -2
  42. package/src/lib/motion-master-pub-sub-web-socket.d.ts +18 -18
  43. package/src/lib/motion-master-pub-sub-web-socket.js +65 -65
  44. package/src/lib/motion-master-pub-sub-worker-socket.d.ts +18 -18
  45. package/src/lib/motion-master-pub-sub-worker-socket.js +47 -47
  46. package/src/lib/motion-master-req-res-client.d.ts +1104 -1062
  47. package/src/lib/motion-master-req-res-client.js +2137 -1992
  48. package/src/lib/motion-master-req-res-client.js.map +1 -1
  49. package/src/lib/motion-master-req-res-socket.d.ts +60 -60
  50. package/src/lib/motion-master-req-res-socket.js +2 -2
  51. package/src/lib/motion-master-req-res-web-socket.d.ts +28 -28
  52. package/src/lib/motion-master-req-res-web-socket.js +97 -97
  53. package/src/lib/motion-master-req-res-worker-socket.d.ts +24 -24
  54. package/src/lib/motion-master-req-res-worker-socket.js +71 -71
  55. package/src/lib/motion-master.proto.d.ts +5183 -5183
  56. package/src/lib/motion-master.proto.js +53218 -53218
  57. package/src/lib/operators.d.ts +20 -20
  58. package/src/lib/operators.js +82 -83
  59. package/src/lib/operators.js.map +1 -1
  60. package/src/lib/options.d.ts +10 -10
  61. package/src/lib/options.js +13 -13
  62. package/src/lib/os-command.d.ts +387 -173
  63. package/src/lib/os-command.js +555 -269
  64. package/src/lib/os-command.js.map +1 -1
  65. package/src/lib/parameter.d.ts +156 -138
  66. package/src/lib/parameter.js +377 -152
  67. package/src/lib/parameter.js.map +1 -1
  68. package/src/lib/product-id-range.d.ts +7 -7
  69. package/src/lib/product-id-range.js +11 -11
  70. package/src/lib/request-status-resolver.d.ts +4 -4
  71. package/src/lib/request-status-resolver.js +344 -344
  72. package/src/lib/somanet-product.d.ts +37 -0
  73. package/src/lib/somanet-product.js +126 -0
  74. package/src/lib/somanet-product.js.map +1 -0
  75. package/src/lib/system-log-line.d.ts +9 -9
  76. package/src/lib/system-log-line.js +2 -2
  77. package/src/lib/types.d.ts +141 -141
  78. package/src/lib/types.js +28 -28
  79. package/src/lib/urls.d.ts +3 -3
  80. package/src/lib/urls.js +9 -9
  81. package/src/lib/util.d.ts +21 -45
  82. package/src/lib/util.js +113 -379
  83. package/src/lib/util.js.map +1 -1
  84. package/src/lib/web-socket-connection-close-codes.d.ts +8 -8
  85. package/src/lib/web-socket-connection-close-codes.js +88 -88
package/README.md CHANGED
@@ -1,138 +1,227 @@
1
- # Motion Master Client
2
-
3
- Motion Master Client is a library and CLI program written in [TypeScript](https://www.typescriptlang.org). It is used for communicating with Motion Master process over [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) connections by exchanging [Protocol Buffers](https://developers.google.com/protocol-buffers) serialized messages.
4
-
5
- ## Installation
6
-
7
- ```sh
8
- npm install motion-master-client
9
- ```
10
-
11
- ## Usage
12
-
13
- ```ts
14
- const reqResSocket = new MotionMasterReqResWebSocket();
15
- const pubSubSocket = new MotionMasterPubSubWebSocket();
16
-
17
- const client = new MotionMasterClient(reqResSocket, pubSubSocket);
18
-
19
- const clientId = v4();
20
- reqResSocket.open(`ws://oblac-drives-7dc95497.local:63524?clientId=${clientId}`);
21
- pubSubSocket.open(`ws://oblac-drives-7dc95497.local:63525?clientId=${clientId}`);
22
-
23
- client.request.getDeviceInfo().subscribe(console.log);
24
- ```
25
-
26
- ## Class Diagrams
27
-
28
- ```mermaid
29
- ---
30
- title: Client & socket classes
31
- ---
32
- classDiagram
33
- class MotionMasterClient {
34
- +MotionMasterReqResClient request
35
- +MotionMasterPubSubClient monitor
36
- +startMonitoring()
37
- +stopMonitoring()
38
- }
39
-
40
- class MotionMasterReqResClient {
41
- +MotionMasterReqResSocket socket
42
- note "Has all the request methods\ncorresponding to the proto file."
43
- }
44
-
45
- class MotionMasterReqResSocket
46
- <<interface>> MotionMasterReqResSocket
47
- MotionMasterReqResSocket: +BehaviorSubject~boolean~ opened\$
48
- MotionMasterReqResSocket: +BehaviorSubject~boolean~ alive\$
49
- MotionMasterReqResSocket: +Observable~MotionMasterMessage~ message\$
50
- MotionMasterReqResSocket: +open(string url, number pingSystemInterval?, number systemAliveTimeout?)
51
- MotionMasterReqResSocket: +close()
52
- MotionMasterReqResSocket: +send(MotionMasterMessage message)
53
-
54
- class MotionMasterReqResWebSocket {
55
- note "Keeps the connection alive by\nsending the ping system messages\nin regular intervals."
56
- }
57
-
58
- class MotionMasterReqResWorkerSocket {
59
- +Worker worker
60
- note "Passes messages between\nthe UI and worker thread."
61
- }
62
-
63
- class MotionMasterPubSubClient {
64
- +MotionMasterPubSubSocket socket
65
- +Subject<[string, MotionMasterMessage[]]> data\$
66
- +Observable~MotionMasterMessage~ notification\$
67
- +Observable~MotionMasterMessage~ systemEvent\$
68
- +Observable~MotionMasterMessage~ deviceEvent\$
69
- +subscribe(MonitoringConfig config)
70
- +unsubscribe(string messageId)
71
- +unsubscribeAll()
72
- }
73
-
74
- class MotionMasterPubSubSocket
75
- <<interface>> MotionMasterPubSubSocket
76
- MotionMasterPubSubSocket: +BehaviorSubject~boolean~ opened\$
77
- MotionMasterPubSubSocket: +Observable<[string, MotionMasterMessage]> data\$
78
- MotionMasterPubSubSocket: +open(string url)
79
- MotionMasterPubSubSocket: +close()
80
-
81
- class MotionMasterPubSubWebSocket {
82
- note "Deserializes incoming data into\na tuple of topic and message."
83
- }
84
-
85
- class MotionMasterPubSubWorkerSocket {
86
- +Worker worker
87
- note "Passes messages between\nthe UI and worker thread."
88
- }
89
-
90
- MotionMasterClient *-- MotionMasterReqResClient
91
- MotionMasterClient *-- MotionMasterPubSubClient
92
-
93
- MotionMasterReqResClient *-- MotionMasterReqResSocket
94
- MotionMasterReqResWebSocket <|-- MotionMasterReqResSocket
95
- MotionMasterReqResWorkerSocket <|-- MotionMasterReqResSocket
96
-
97
- MotionMasterPubSubClient *-- MotionMasterPubSubSocket
98
- MotionMasterPubSubWebSocket <|-- MotionMasterPubSubSocket
99
- MotionMasterPubSubWorkerSocket <|-- MotionMasterPubSubSocket
100
- ```
101
-
102
- ## Communication
103
-
104
- ### Protocols
105
-
106
- ### Message Exchange
107
-
108
- ## Running unit tests
109
-
110
- ## Features
111
-
112
- ## Goals
113
-
114
- Run `nx test motion-master-client` to execute the unit tests via [Jest](https://jestjs.io).
115
-
116
- https://github.com/protocolbuffers/protobuf/issues/2497#issuecomment-267422550
117
-
118
- explain status progress completed error
119
- request timeout
120
- ping mechanism
121
- reactive and async api
122
- two sockets
123
- matching request id (message id with response)
124
-
125
- ## Build & Publish
126
-
127
- Update the `motion-master-client` version in `libs/motion-master-client/package.json`. Then, from the repository root, build the library by running:
128
-
129
- ```sh
130
- npm run build motion-master-client
131
- ```
132
-
133
- and publish the built library:
134
-
135
- ```sh
136
- cd dist/libs/motion-master-client
137
- npm publish
138
- ```
1
+ # Motion Master Client
2
+
3
+ Motion Master Client is a library and CLI program written in [TypeScript](https://www.typescriptlang.org). It is used for communicating with Motion Master process over [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) connections by exchanging [Protocol Buffers](https://developers.google.com/protocol-buffers) serialized messages.
4
+
5
+ ## Usage
6
+
7
+ The Motion Master Client library can be equally used on a server with Node.js or in browsers.
8
+
9
+ ### Server usage
10
+
11
+ Initialize a project:
12
+
13
+ ```sh
14
+ mkdir hello-somanet
15
+ cd hello-somanet
16
+ npm init --yes
17
+ ```
18
+
19
+ Install the required dependencies:
20
+
21
+ ```sh
22
+ npm install --save motion-master-client rxjs ws
23
+ npm install --save-dev ts-node typescript
24
+ ```
25
+
26
+ Create a TypeScript configuration:
27
+
28
+ ```sh
29
+ npx tsc --init
30
+ ```
31
+
32
+ Create a main program file:
33
+
34
+ ```sh
35
+ touch main.ts
36
+ ```
37
+
38
+ Add the following content to the _main.ts_ file:
39
+
40
+ ```ts
41
+ import { createMotionMasterClient } from 'motion-master-client';
42
+ import { lastValueFrom } from 'rxjs';
43
+
44
+ // Ensure that Node.js has the global WebSocket object available.
45
+ Object.assign(globalThis, { WebSocket: require('ws') });
46
+
47
+ const client = createMotionMasterClient('192.168.200.253');
48
+
49
+ client.whenReady().then(async () => {
50
+ const devices = await lastValueFrom(client.request.getDevices());
51
+ const message = JSON.stringify(devices, null, 2);
52
+ console.log(message);
53
+ client.closeSockets();
54
+ });
55
+ ```
56
+
57
+ Run the program:
58
+
59
+ ```sh
60
+ npx ts-node main.ts
61
+ ```
62
+
63
+ The program will:
64
+
65
+ 1. Create an instance of the client and connect to a Motion Master process running at 192.168.200.253.
66
+ 2. The client needs some time to connect, so it must be ready before making requests. Most of the requests are implemented and documented in the [MotionMasterReqResClient](https://synapticon.github.io/oblac/motion-master-client/classes/MotionMasterReqResClient.html) class.
67
+ 3. The client requests a list of devices, which are then printed to the console.
68
+ 4. The client closes opened sockets.
69
+
70
+ Here's another example that demonstrates how to get and set device parameter values:
71
+
72
+ ```ts
73
+ import { createMotionMasterClient } from 'motion-master-client';
74
+
75
+ // Ensure that Node.js has the global WebSocket object available.
76
+ Object.assign(globalThis, { WebSocket: require('ws') });
77
+
78
+ const client = createMotionMasterClient('192.168.200.253');
79
+
80
+ client.whenReady().then(async () => {
81
+ // Device is referenced by a position (0).
82
+ const motorRatedCurrent = await client.request.upload(0, 0x6075, 0);
83
+ console.log(`Motor rated current: ${motorRatedCurrent}`);
84
+
85
+ // The device parameter is referenced by an ID, which consists of
86
+ // the index (0x6076), subindex (0x00), and the device serial number (8504-03-0002369-2329).
87
+ const motorRatedTorque = await client.request.upload('0x6076:00.8504-03-0002369-2329');
88
+ console.log(`Motor rated current: ${motorRatedTorque}`);
89
+
90
+ // Update the Max current parameter value to 2000.
91
+ await client.request.download(0, 0x6073, 0, 2000);
92
+
93
+ client.closeSockets();
94
+ });
95
+ ```
96
+
97
+ ## Understanding requests
98
+
99
+ When the client is instantiated, it connects to the Motion Master process using the WebSocket protocol. As it is a bi-directional, full-duplex communication protocol, there needs to be a mechanism that couples requests with responses. This is solved by having a message ID that is a mandatory attribute of each request; responses produced by that request will include the same message ID.
100
+
101
+ For some requests, such as firmware installation, Motion Master will send progress messages until the firmware installation is complete. Therefore, when making a request with the client library, functions will return an Observable of request statuses. This means that you can subscribe to an Observable and receive status messages over time. These observables are asynchronous, meaning your program can continue to do other things while the request executes. For the purpose of utilizing Observables and implementing reactive programming, the client library uses [RxJs](https://rxjs.dev/).
102
+
103
+ To demonstrate the use of reactive programming, let's create a program that monitors the drive and core temperatures:
104
+
105
+ ```ts
106
+ import { createMotionMasterClient } from 'motion-master-client';
107
+ import { map, mergeMap } from 'rxjs';
108
+
109
+ // Ensure that Node.js has the global WebSocket object available.
110
+ Object.assign(globalThis, { WebSocket: require('ws') });
111
+
112
+ const client = createMotionMasterClient('192.168.200.253');
113
+
114
+ const subscription = client.onceReady$
115
+ .pipe(
116
+ mergeMap(() =>
117
+ client.startMonitoring(
118
+ [
119
+ [0, 0x2030, 1], // Core temperature
120
+ [0, 0x2031, 1], // Drive temperature
121
+ ],
122
+ 1000000, // microseconds
123
+ { topic: 'temperatures-monitoring', distinct: true }
124
+ )
125
+ ),
126
+ map((values) => `core=${values[0]} drive=${values[1]}`)
127
+ )
128
+ .subscribe(console.log);
129
+
130
+ process.on('SIGINT', function () {
131
+ console.log('\nGracefully shutting down from SIGINT (Ctrl-C).\nStopping monitoring and closing sockets.');
132
+ subscription?.unsubscribe();
133
+ client.closeSockets();
134
+ process.exit(0);
135
+ });
136
+ ```
137
+
138
+ ## Class Diagrams
139
+
140
+ ```mermaid
141
+ ---
142
+ title: Client & socket classes
143
+ ---
144
+ classDiagram
145
+ class MotionMasterClient {
146
+ +MotionMasterReqResClient request
147
+ +MotionMasterPubSubClient monitor
148
+ +startMonitoring()
149
+ +stopMonitoring()
150
+ }
151
+
152
+ class MotionMasterReqResClient {
153
+ +MotionMasterReqResSocket socket
154
+ note "Has all the request methods\ncorresponding to the proto file."
155
+ }
156
+
157
+ class MotionMasterReqResSocket
158
+ <<interface>> MotionMasterReqResSocket
159
+ MotionMasterReqResSocket: +BehaviorSubject~boolean~ opened\$
160
+ MotionMasterReqResSocket: +BehaviorSubject~boolean~ alive\$
161
+ MotionMasterReqResSocket: +Observable~MotionMasterMessage~ message\$
162
+ MotionMasterReqResSocket: +open(string url, number pingSystemInterval?, number systemAliveTimeout?)
163
+ MotionMasterReqResSocket: +close()
164
+ MotionMasterReqResSocket: +send(MotionMasterMessage message)
165
+
166
+ class MotionMasterReqResWebSocket {
167
+ note "Keeps the connection alive by\nsending the ping system messages\nin regular intervals."
168
+ }
169
+
170
+ class MotionMasterReqResWorkerSocket {
171
+ +Worker worker
172
+ note "Passes messages between\nthe UI and worker thread."
173
+ }
174
+
175
+ class MotionMasterPubSubClient {
176
+ +MotionMasterPubSubSocket socket
177
+ +Subject<[string, MotionMasterMessage[]]> data\$
178
+ +Observable~MotionMasterMessage~ notification\$
179
+ +Observable~MotionMasterMessage~ systemEvent\$
180
+ +Observable~MotionMasterMessage~ deviceEvent\$
181
+ +subscribe(MonitoringConfig config)
182
+ +unsubscribe(string messageId)
183
+ +unsubscribeAll()
184
+ }
185
+
186
+ class MotionMasterPubSubSocket
187
+ <<interface>> MotionMasterPubSubSocket
188
+ MotionMasterPubSubSocket: +BehaviorSubject~boolean~ opened\$
189
+ MotionMasterPubSubSocket: +Observable<[string, MotionMasterMessage]> data\$
190
+ MotionMasterPubSubSocket: +open(string url)
191
+ MotionMasterPubSubSocket: +close()
192
+
193
+ class MotionMasterPubSubWebSocket {
194
+ note "Deserializes incoming data into\na tuple of topic and message."
195
+ }
196
+
197
+ class MotionMasterPubSubWorkerSocket {
198
+ +Worker worker
199
+ note "Passes messages between\nthe UI and worker thread."
200
+ }
201
+
202
+ MotionMasterClient *-- MotionMasterReqResClient
203
+ MotionMasterClient *-- MotionMasterPubSubClient
204
+
205
+ MotionMasterReqResClient *-- MotionMasterReqResSocket
206
+ MotionMasterReqResWebSocket <|-- MotionMasterReqResSocket
207
+ MotionMasterReqResWorkerSocket <|-- MotionMasterReqResSocket
208
+
209
+ MotionMasterPubSubClient *-- MotionMasterPubSubSocket
210
+ MotionMasterPubSubWebSocket <|-- MotionMasterPubSubSocket
211
+ MotionMasterPubSubWorkerSocket <|-- MotionMasterPubSubSocket
212
+ ```
213
+
214
+ ## Build & Publish
215
+
216
+ To update the `motion-master-client` version, first modify the version in `libs/motion-master-client/package.json`. Then, from the repository root, build the library by executing the following command:
217
+
218
+ ```sh
219
+ npm run build motion-master-client
220
+ ```
221
+
222
+ After building the library, proceed to publish it by following these steps:
223
+
224
+ ```sh
225
+ cd dist/libs/motion-master-client
226
+ npm publish
227
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "motion-master-client",
3
- "version": "0.0.76",
3
+ "version": "0.0.85",
4
4
  "type": "commonjs",
5
5
  "description": "A library and CLI program used for communicating with Motion Master.",
6
6
  "dependencies": {
package/src/cli.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};