ellipsis-com 0.0.1

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.
@@ -0,0 +1,96 @@
1
+ import { ComMacro } from './ComMacro';
2
+ import { ComType } from './ComType';
3
+ export declare function enableDebug(enable?: boolean): void;
4
+ /**
5
+ * Represents a serial communication port. This class is responsible for managing the connection to the port, sending commands, and reading responses. It also
6
+ * maintains the state of the port (e.g. whether it is currently busy or available)
7
+ * and handles incoming data and errors.
8
+ *
9
+ * The port will be busy while waiting for a response to a sent command, and will be available for new commands once the response is received or an error occurs.
10
+ * While waiting for a new command, the port will be in the background state, allowing it to log incoming data without blocking.
11
+ * If an error occurs while waiting for a response, the port will return to the background state and log the error.
12
+ *
13
+ * Valid states: busy, closed, background, connecting.
14
+ */
15
+ export declare class ComPort {
16
+ path: string;
17
+ private port;
18
+ private readMatch?;
19
+ private readComplete;
20
+ private buffer;
21
+ backgroundBuffer: string[];
22
+ name: string | null;
23
+ state: 'busy' | 'closed' | 'background' | 'connecting';
24
+ type: ComType | null;
25
+ lastError: string | null;
26
+ timeout: number;
27
+ lineEnding: string;
28
+ manufacturer?: string;
29
+ serialNumber?: string;
30
+ pnpId?: string;
31
+ locationId?: string;
32
+ productId?: string;
33
+ vendorId?: string;
34
+ constructor(path: string);
35
+ toString(): string;
36
+ setType(type: ComType): Promise<boolean>;
37
+ /**
38
+ * Opens the serial port with either the given baud rate or the baud rate
39
+ * set in the ComPort's type. Once successfully open the port will be in
40
+ * the background state and may be used to write and read.
41
+ * @param baud The Baud rate.
42
+ * @returns A Promise.
43
+ */
44
+ connect(baud?: number): Promise<void>;
45
+ /**
46
+ * Read from the serial port until either the given pattern is
47
+ * matched in the read data or the ComPort's timeout is reached.
48
+ * @param match The RegExp to match against read data.
49
+ * @returns The read data.
50
+ */
51
+ read(match: RegExp): Promise<string>;
52
+ /**
53
+ * Writes the given command string to the serial port.
54
+ * @param command The command to write.
55
+ * @returns A Promise.
56
+ */
57
+ write(command: string): Promise<void>;
58
+ /**
59
+ * Closes the port. If successfully closed, the port's state will
60
+ * be closed.
61
+ * @returns A Promise.
62
+ */
63
+ close(): Promise<void>;
64
+ /**
65
+ * Attempts to set the port state to busy.
66
+ * If the port is currently closed, it will attempt to connect.
67
+ * If the port is currently connecting, it will wait until the connection is complete.
68
+ * If the port is currently busy, it will wait until the port becomes available.
69
+ * If the port does not become available within a certain time frame, an error will be thrown.
70
+ * @returns
71
+ */
72
+ lockPort(): Promise<void>;
73
+ /**
74
+ * Executes the macros for the given method while the responses are matched.
75
+ * After execution the com port's state will be 'background'.
76
+ * @param operationId The operationId name to execute.
77
+ * @param params The parameters to replace in the macro commands.
78
+ * @return An array of the responses from each command.
79
+ */
80
+ send(operationId: string, params?: {
81
+ [name: string]: any;
82
+ }): Promise<string[]>;
83
+ /**
84
+ * Executes the given macros while the responses are matched.
85
+ * After execution the com port's state will be 'background'.
86
+ * @param macros The array of macros to execute.
87
+ * @param params The parameters to replace in the macro commands.
88
+ * @return An array of the responses from each command.
89
+ */
90
+ send(macros: ComMacro[], params?: {
91
+ [name: string]: any;
92
+ }): Promise<string[]>;
93
+ receiveError(err: Error): void;
94
+ receiveData(data: Buffer): void;
95
+ }
96
+ //# sourceMappingURL=ComPort.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ComPort.d.ts","sourceRoot":"","sources":["../src/ComPort.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,wBAAgB,WAAW,CAAC,MAAM,UAAO,QAMxC;AAGD;;;;;;;;;;GAUG;AACH,qBAAa,OAAO;IAuBG,IAAI,EAAE,MAAM;IAtB/B,OAAO,CAAC,IAAI,CAA0B;IACtC,OAAO,CAAC,SAAS,CAAC,CAAQ;IAC1B,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,MAAM,CAAa;IA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AC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC;KAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IA8FpF,YAAY,CAAC,GAAG,EAAE,KAAK;IAiBvB,WAAW,CAAC,IAAI,EAAE,MAAM;CAqD3B"}
@@ -0,0 +1,365 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ComPort = void 0;
4
+ exports.enableDebug = enableDebug;
5
+ const serialport_1 = require("serialport");
6
+ const ComMacro_1 = require("./ComMacro");
7
+ // TODO: Adopt a propper logging system.
8
+ let debug;
9
+ function enableDebug(enable = true) {
10
+ if (enable) {
11
+ debug = console.log;
12
+ }
13
+ else {
14
+ debug = () => { };
15
+ }
16
+ }
17
+ enableDebug(false);
18
+ /**
19
+ * Represents a serial communication port. This class is responsible for managing the connection to the port, sending commands, and reading responses. It also
20
+ * maintains the state of the port (e.g. whether it is currently busy or available)
21
+ * and handles incoming data and errors.
22
+ *
23
+ * The port will be busy while waiting for a response to a sent command, and will be available for new commands once the response is received or an error occurs.
24
+ * While waiting for a new command, the port will be in the background state, allowing it to log incoming data without blocking.
25
+ * If an error occurs while waiting for a response, the port will return to the background state and log the error.
26
+ *
27
+ * Valid states: busy, closed, background, connecting.
28
+ */
29
+ class ComPort {
30
+ constructor(path) {
31
+ this.path = path;
32
+ this.port = null;
33
+ this.readComplete = false;
34
+ this.buffer = ''; // TODO replace with Buffer
35
+ this.backgroundBuffer = [];
36
+ this.name = null;
37
+ this.state = 'closed';
38
+ this.type = null;
39
+ this.lastError = null;
40
+ this.timeout = 5000; // TODO: Allow setting this at the service level and at the method level.
41
+ this.lineEnding = '\n'; // TODO: Allow setting this at the service level and at the method level.
42
+ }
43
+ toString() {
44
+ return `ComPort(path=${this.path}, state=${this.state}${this.type ? ', type=' : ''}${this.type ? this.type?.name : ''}${this.lastError ? ', lastError=' : ''}${this.lastError ? this.lastError : ''})`;
45
+ }
46
+ async setType(type) {
47
+ try {
48
+ await this.connect(type.baud); // throws an error if connection fails
49
+ await sleep(type.startupDelay); // wait for device to startup if needed
50
+ await this.send(type.macros.init);
51
+ if (this.readComplete) {
52
+ this.type = type;
53
+ return true;
54
+ }
55
+ else {
56
+ return false;
57
+ }
58
+ }
59
+ finally {
60
+ await this.close();
61
+ }
62
+ }
63
+ /**
64
+ * Opens the serial port with either the given baud rate or the baud rate
65
+ * set in the ComPort's type. Once successfully open the port will be in
66
+ * the background state and may be used to write and read.
67
+ * @param baud The Baud rate.
68
+ * @returns A Promise.
69
+ */
70
+ async connect(baud) {
71
+ if (!baud && !this.type) {
72
+ throw new Error('No baud rate set while trying to connect. Either pass the baud rate to the connect function or set a ComType first.');
73
+ }
74
+ if (!baud) {
75
+ baud = this.type.baud;
76
+ }
77
+ this.state = 'connecting';
78
+ this.port = new serialport_1.SerialPort({
79
+ path: this.path,
80
+ baudRate: baud,
81
+ autoOpen: false
82
+ });
83
+ this.port.on('error', this.receiveError.bind(this));
84
+ this.port.on('data', this.receiveData.bind(this));
85
+ return new Promise((resolve, reject) => {
86
+ this.port.open((err) => {
87
+ if (err) {
88
+ this.state = 'closed';
89
+ this.lastError = err.message;
90
+ reject(err);
91
+ return;
92
+ }
93
+ // this.resetResponse()
94
+ // Successfully opened:
95
+ debug(`Connected to com port ${this.path}.`);
96
+ this.state = 'background';
97
+ resolve();
98
+ });
99
+ });
100
+ }
101
+ /**
102
+ * Read from the serial port until either the given pattern is
103
+ * matched in the read data or the ComPort's timeout is reached.
104
+ * @param match The RegExp to match against read data.
105
+ * @returns The read data.
106
+ */
107
+ async read(match) {
108
+ let time = Date.now();
109
+ this.readMatch = match;
110
+ this.buffer = '';
111
+ this.lastError = null;
112
+ this.readComplete = false;
113
+ return new Promise((resolve, reject) => {
114
+ const checkCompletion = () => {
115
+ if (this.readComplete) {
116
+ resolve(this.buffer.trim());
117
+ }
118
+ else if (Date.now() - time > this.timeout) {
119
+ reject(new Error(`Timeout after ${this.timeout}ms while reading from port ${this.path}.`)); // TODO: Create custom timeout error class.
120
+ }
121
+ else if (this.lastError) {
122
+ reject(new Error(this.lastError));
123
+ }
124
+ else {
125
+ setTimeout(() => {
126
+ checkCompletion();
127
+ }, 100);
128
+ }
129
+ };
130
+ checkCompletion();
131
+ });
132
+ }
133
+ /**
134
+ * Writes the given command string to the serial port.
135
+ * @param command The command to write.
136
+ * @returns A Promise.
137
+ */
138
+ async write(command) {
139
+ if (!this.port || !this.port.isOpen) {
140
+ throw new Error('Port not open. Please open the port via the connect function before attempting to write.');
141
+ }
142
+ // Asynchronously write data to the port:
143
+ return new Promise((resolve, reject) => {
144
+ this.port.write(command + this.lineEnding, (err) => {
145
+ if (err) {
146
+ this.lastError = err.message;
147
+ reject(err);
148
+ return;
149
+ }
150
+ resolve();
151
+ });
152
+ });
153
+ }
154
+ /**
155
+ * Closes the port. If successfully closed, the port's state will
156
+ * be closed.
157
+ * @returns A Promise.
158
+ */
159
+ async close() {
160
+ return new Promise((resolve, reject) => {
161
+ this.port?.close((err) => {
162
+ if (!this.port.isOpen) {
163
+ this.port = null;
164
+ this.state = 'closed';
165
+ }
166
+ if (err) {
167
+ reject(err);
168
+ }
169
+ else {
170
+ resolve();
171
+ }
172
+ });
173
+ });
174
+ }
175
+ /**
176
+ * Attempts to set the port state to busy.
177
+ * If the port is currently closed, it will attempt to connect.
178
+ * If the port is currently connecting, it will wait until the connection is complete.
179
+ * If the port is currently busy, it will wait until the port becomes available.
180
+ * If the port does not become available within a certain time frame, an error will be thrown.
181
+ * @returns
182
+ */
183
+ async lockPort() {
184
+ // Already available:
185
+ if (this.state === 'background') {
186
+ this.state = 'busy';
187
+ return;
188
+ }
189
+ // If port is not connected then connect:
190
+ if (this.state === 'closed') {
191
+ debug(`Port ${this.path} is closed - connecting...`);
192
+ await this.connect();
193
+ }
194
+ // If currently connecting, first wait until connected:
195
+ let attempt = 0;
196
+ while (this.state === 'connecting' && attempt < 10) {
197
+ await new Promise(resolve => setTimeout(() => resolve(), 100));
198
+ attempt++;
199
+ }
200
+ if (this.state === 'connecting') {
201
+ throw new Error(`Timeout while waiting for connection to complete.`);
202
+ }
203
+ debug(`Port ${this.path} connected.`);
204
+ // If busy, wait until available:
205
+ const MAX_ATTEMPTS = 10;
206
+ attempt = 0;
207
+ while (this.state === 'busy' && attempt < MAX_ATTEMPTS) {
208
+ debug(`Port ${this.path} is busy - waiting...`);
209
+ await new Promise(resolve => setTimeout(() => resolve(), 500));
210
+ attempt++;
211
+ }
212
+ if (this.state === 'busy') {
213
+ throw new Error(`Timeout while waiting for port to become available.`);
214
+ }
215
+ this.state = 'busy';
216
+ debug(`Port ${this.path} is now available.`);
217
+ }
218
+ async send(macros_operationId, params) {
219
+ if (typeof macros_operationId === 'string') {
220
+ if (!this.type) {
221
+ throw new Error(`Cannot send to com port ${this.path} by operationId without a type.`);
222
+ }
223
+ debug(`Sending macros for operationId '${macros_operationId}' on port ${this.path}.`);
224
+ return this.send(this.type.macros[macros_operationId], params);
225
+ }
226
+ if (!macros_operationId || macros_operationId.length === 0) {
227
+ throw new Error(`No macros provided to send to com port ${this.path}.`);
228
+ }
229
+ let macros = macros_operationId;
230
+ // Replace parameters in each macro command:
231
+ if (params) {
232
+ macros = macros.map(m => {
233
+ let command = m.command;
234
+ // Extract all parameters in the command.
235
+ // These have the form {param}:
236
+ const paramRegex = /{([^}]+)}/gm;
237
+ let match;
238
+ const commandParams = [];
239
+ while ((match = paramRegex.exec(command)) !== null) {
240
+ // This is necessary to avoid infinite loops with zero-width matches
241
+ if (match.index === paramRegex.lastIndex) {
242
+ paramRegex.lastIndex++;
243
+ }
244
+ // The result can be accessed through the 'match'-variable.
245
+ match.forEach((m, groupIndex) => {
246
+ if (groupIndex === 1) {
247
+ commandParams.push(m);
248
+ }
249
+ });
250
+ }
251
+ // Replace each parameter with its value:
252
+ commandParams.forEach(p => {
253
+ const re = new RegExp(`{${p}}`, 'g');
254
+ let val;
255
+ // Resolve nested parameters:
256
+ if (p.includes('.')) {
257
+ val = params[p.substring(0, p.indexOf('.'))]; // get top-level value
258
+ const keys = p.split('.');
259
+ for (let key of keys) {
260
+ // Check for the property:
261
+ if (val && val.hasOwnProperty(key)) {
262
+ val = val[key];
263
+ }
264
+ // Check if the property has an array index:
265
+ else if (key.endsWith(']') && key.includes('[')) {
266
+ const arrKey = key.substring(0, key.indexOf('['));
267
+ const indexStr = key.substring(key.indexOf('[') + 1, key.length - 1);
268
+ const index = parseInt(indexStr);
269
+ if (val && val.hasOwnProperty(arrKey) && Array.isArray(val[arrKey]) && val[arrKey].length > index) {
270
+ val = val[arrKey][index];
271
+ }
272
+ }
273
+ // else not found.
274
+ }
275
+ }
276
+ else {
277
+ val = params[p];
278
+ }
279
+ command = command.replaceAll(re, val);
280
+ });
281
+ return new ComMacro_1.ComMacro(command, m.response);
282
+ });
283
+ }
284
+ // Execute each macro in turn:
285
+ const responses = [];
286
+ for (let macro of macros) {
287
+ // Wait for port the become available:
288
+ await this.lockPort();
289
+ // Write the command and wait for the response:
290
+ await this.write(macro.command);
291
+ const response = await this.read(macro.response);
292
+ responses.push(response);
293
+ }
294
+ return responses;
295
+ }
296
+ receiveError(err) {
297
+ console.error(`Error on port ${this.path}: ${err.message}`);
298
+ this.lastError = err.message;
299
+ if (this.port?.isOpen) {
300
+ // If the error did not close the port, then return to background processing:
301
+ this.state = 'background';
302
+ }
303
+ else {
304
+ // If the error closed the port, then set state to closed
305
+ // and remove the SerialPort if needed:
306
+ this.state = 'closed';
307
+ if (this.port) {
308
+ this.close();
309
+ }
310
+ }
311
+ }
312
+ receiveData(data) {
313
+ // Background Log:
314
+ if (this.state === 'background') {
315
+ const dataStr = data.toString();
316
+ const lines = dataStr.split(/\r?\n/);
317
+ if (lines.length > 0) {
318
+ // Append to the last entry to ensure incompelte lines are joined:
319
+ if (this.backgroundBuffer.length > 0) {
320
+ this.backgroundBuffer[this.backgroundBuffer.length - 1] += lines[0];
321
+ }
322
+ else {
323
+ this.backgroundBuffer.push(lines[0]);
324
+ }
325
+ // Add remaining lines as new entries:
326
+ for (let i = 1; i < lines.length; i++) {
327
+ if (lines[i].trim().length > 0) {
328
+ this.backgroundBuffer.push(lines[i]);
329
+ }
330
+ }
331
+ // If the data string ends with a line ending, then
332
+ // add an empty line to represent the new line:
333
+ if (dataStr.endsWith('\n') || dataStr.endsWith('\r')) {
334
+ this.backgroundBuffer.push('');
335
+ }
336
+ }
337
+ // Limit background buffer size:
338
+ if (this.backgroundBuffer.length > 1000) {
339
+ this.backgroundBuffer.splice(this.backgroundBuffer.length - 10, 10);
340
+ }
341
+ return;
342
+ }
343
+ // Read until pattern matched:
344
+ if (this.state === 'busy') {
345
+ if (!this.readMatch) {
346
+ this.lastError = 'State was busy reading data but no read RegExp was found to check for completion.';
347
+ this.state = 'background';
348
+ return;
349
+ }
350
+ this.buffer += data.toString();
351
+ if (this.readMatch.test(this.buffer.toString().trim())) {
352
+ this.state = 'background';
353
+ this.readComplete = true;
354
+ }
355
+ }
356
+ else {
357
+ console.error(`Port ${this.path} received data in unexpected state '${this.state}': ${data.toString()}`);
358
+ }
359
+ }
360
+ }
361
+ exports.ComPort = ComPort;
362
+ async function sleep(startupDelay) {
363
+ return new Promise(resolve => setTimeout(() => resolve(), startupDelay));
364
+ }
365
+ //# sourceMappingURL=ComPort.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ComPort.js","sourceRoot":"","sources":["../src/ComPort.ts"],"names":[],"mappings":";;;AAMA,kCAMC;AAZD,2CAAwC;AACxC,yCAAsC;AAGtC,wCAAwC;AACxC,IAAI,KAA+B,CAAA;AACnC,SAAgB,WAAW,CAAC,MAAM,GAAG,IAAI;IACrC,IAAI,MAAM,EAAE,CAAC;QACT,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC;IACxB,CAAC;SAAM,CAAC;QACJ,KAAK,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC;IACtB,CAAC;AACL,CAAC;AACD,WAAW,CAAC,KAAK,CAAC,CAAA;AAElB;;;;;;;;;;GAUG;AACH,MAAa,OAA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EAAE,EAAE,CAAC,CAAC;QAC7G,CAAC;IACL,CAAC;CACJ;AAtYD,0BAsYC;AAED,KAAK,UAAU,KAAK,CAAC,YAAoB;IACrC,OAAO,IAAI,OAAO,CAAO,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,YAAY,CAAC,CAAC,CAAC;AACnF,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { ComMacro } from './ComMacro';
2
+ export declare class ComType {
3
+ name: string;
4
+ baud: number;
5
+ macros: {
6
+ init: ComMacro[];
7
+ [operationId: string]: ComMacro[];
8
+ };
9
+ startupDelay: number;
10
+ constructor(name: string, baud: number, macros: {
11
+ init: ComMacro[];
12
+ [operationId: string]: ComMacro[];
13
+ }, startupDelay?: number);
14
+ toString(): string;
15
+ }
16
+ //# sourceMappingURL=ComType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ComType.d.ts","sourceRoot":"","sources":["../src/ComType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,qBAAa,OAAO;IAIL,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE;QACX,IAAI,EAAE,QAAQ,EAAE,CAAC;QACjB,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ,EAAE,CAAC;KACrC;IARL,YAAY,EAAE,MAAM,CAAI;gBAGb,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE;QACX,IAAI,EAAE,QAAQ,EAAE,CAAC;QACjB,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ,EAAE,CAAC;KACrC,EACD,YAAY,CAAC,EAAE,MAAM;IAOzB,QAAQ;CAMX"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ComType = void 0;
4
+ class ComType {
5
+ constructor(name, baud, macros, startupDelay) {
6
+ this.name = name;
7
+ this.baud = baud;
8
+ this.macros = macros;
9
+ this.startupDelay = 0;
10
+ if (startupDelay) {
11
+ this.startupDelay = startupDelay;
12
+ }
13
+ }
14
+ toString() {
15
+ return `ComType(name='${this.name}', baud=${this.baud})`
16
+ + `[${Object.entries(this.macros).map(([m, macros]) => (`\n\t${m}: [${macros.map(cm => cm.toString()).join(', ')}]`)).join('')}\n]`;
17
+ }
18
+ }
19
+ exports.ComType = ComType;
20
+ //# sourceMappingURL=ComType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ComType.js","sourceRoot":"","sources":["../src/ComType.ts"],"names":[],"mappings":";;;AAGA,MAAa,OAAO;IAGhB,YACW,IAAY,EACZ,IAAY,EACZ,MAGN,EACD,YAAqB;QANd,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;QACZ,WAAM,GAAN,MAAM,CAGZ;QARL,iBAAY,GAAW,CAAC,CAAA;QAWpB,IAAG,YAAY,EAAE,CAAC;YACd,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QACpC,CAAC;IACL,CAAC;IAED,QAAQ;QACJ,OAAO,iBAAiB,IAAI,CAAC,IAAI,WAAW,IAAI,CAAC,IAAI,GAAG;cAClD,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CACnD,OAAO,CAAC,MAAM,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC9D,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC;IACzB,CAAC;CACJ;AAvBD,0BAuBC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Demo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Demo.d.ts","sourceRoot":"","sources":["../../src/test/Demo.ts"],"names":[],"mappings":""}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ComManager_1 = require("../ComManager");
4
+ const ComMacro_1 = require("../ComMacro");
5
+ /**
6
+ * This demo works with the arduino-demo sketch.
7
+ */
8
+ async function demo() {
9
+ const manager = new ComManager_1.ComManager();
10
+ // Initialise the manager with a com type that has some macros.
11
+ // The init macro is required and is used to identify the type of a port when it is connected.
12
+ // The other macros are optional and can be used to define commands that can be sent to the device.
13
+ await manager.init([{
14
+ name: 'myType',
15
+ baud: 9600,
16
+ startupDelay: 2000, // optional delay to wait for device to startup after connecting and before sending init
17
+ macros: {
18
+ // Command to initialise and identify type - must have key 'init':
19
+ init: [new ComMacro_1.ComMacro('INFO', /MOCK\sDEVICE\sV\d+.?\d*[\n\r]+STATUS: OK[\n\r]+CMD DONE$/gm)], // regex to identify device as being of myType
20
+ // Basic command and response pattern - can be named anything:
21
+ getData: [new ComMacro_1.ComMacro('GET DATA', /CMD DONE$/gm)],
22
+ // Command with parameters:
23
+ setData: [new ComMacro_1.ComMacro('SET DATA {val}', /CMD DONE$/gm)],
24
+ // Command with a sequence of commands and responses:
25
+ deleteData: [
26
+ new ComMacro_1.ComMacro('DEL DATA', /Are you sure\? \(Y\/N\)$/gm),
27
+ new ComMacro_1.ComMacro('Y', /CMD DONE$/gm)
28
+ ]
29
+ }
30
+ }]);
31
+ // Send the getData command to the first port of type 'myType':
32
+ let data = await manager.send('myType', 0, 'getData');
33
+ console.log('\nGet data response - ', data[0], '\n'); // data is an array of responses matching the regex for the macro
34
+ // Send the setData command with a parameter:
35
+ await manager.send('myType', 0, 'setData', { val: 'abc123' });
36
+ data = await manager.send('myType', 0, 'getData');
37
+ console.log('\nData changed - ', data[0], '\n');
38
+ // Delete the data using the deleteData command which has a sequence of commands and responses:
39
+ await manager.send('myType', 0, 'deleteData');
40
+ data = await manager.send('myType', 0, 'getData');
41
+ console.log('\nAfter deletion - ', data[0], '\n');
42
+ }
43
+ demo();
44
+ //# sourceMappingURL=Demo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Demo.js","sourceRoot":"","sources":["../../src/test/Demo.ts"],"names":[],"mappings":";;AAAA,8CAA0C;AAC1C,0CAAsC;AAEtC;;GAEG;AACH,KAAK,UAAU,IAAI;IACf,MAAM,OAAO,GAAG,IAAI,uBAAU,EAAE,CAAA;IAEhC,+DAA+D;IAC/D,+FAA+F;IAC/F,mGAAmG;IACnG,MAAM,OAAO,CAAC,IAAI,CACd,CAAC;YACG,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,IAAI;YACV,YAAY,EAAE,IAAI,EAAE,wFAAwF;YAC5G,MAAM,EAAE;gBACJ,kEAAkE;gBAClE,IAAI,EAAE,CAAC,IAAI,mBAAQ,CAAC,MAAM,EAAE,4DAA4D,CAAC,CAAC,EAAE,8CAA8C;gBAE1I,8DAA8D;gBAC9D,OAAO,EAAE,CAAC,IAAI,mBAAQ,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;gBAElD,2BAA2B;gBAC3B,OAAO,EAAE,CAAC,IAAI,mBAAQ,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAC;gBAExD,qDAAqD;gBACrD,UAAU,EAAE;oBACR,IAAI,mBAAQ,CAAC,UAAU,EAAE,4BAA4B,CAAC;oBACtD,IAAI,mBAAQ,CAAC,GAAG,EAAE,aAAa,CAAC;iBACnC;aACJ;SACJ,CAAC,CACL,CAAA;IAED,+DAA+D;IAC/D,IAAI,IAAI,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,SAAS,CAAC,CAAA;IACrD,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA,CAAC,iEAAiE;IAEtH,6CAA6C;IAC7C,MAAM,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,SAAS,EAAE,EAAC,GAAG,EAAE,QAAQ,EAAC,CAAC,CAAA;IAC3D,IAAI,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,SAAS,CAAC,CAAA;IACjD,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;IAE/C,+FAA+F;IAC/F,MAAM,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,YAAY,CAAC,CAAA;IAC7C,IAAI,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,SAAS,CAAC,CAAA;IACjD,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;AACrD,CAAC;AAED,IAAI,EAAE,CAAA"}
package/jest.config.js ADDED
@@ -0,0 +1,18 @@
1
+ module.exports = {
2
+ preset: 'ts-jest',
3
+ testEnvironment: 'node',
4
+ roots: ['<rootDir>'],
5
+ testMatch: ['**/**/*.test.ts'],
6
+ transform: {
7
+ '^.+\\.ts$': 'ts-jest',
8
+ },
9
+ collectCoverageFrom: [
10
+ 'src/**/*.ts',
11
+ '!src/**/*.d.ts',
12
+ '!src/**/*.test.ts',
13
+ '!src/**/*.spec.ts',
14
+ ],
15
+ moduleFileExtensions: ['ts', 'js', 'json'],
16
+ coverageDirectory: 'coverage',
17
+ verbose: true,
18
+ };
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "ellipsis-com",
3
+ "version": "0.0.1",
4
+ "description": "For the management of serial communication based on commands and responses defined by regular expressions.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/ellipsistechnology/ellipsis-com.git"
10
+ },
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "test": "jest",
14
+ "test:watch": "jest --watch",
15
+ "test:coverage": "jest --coverage",
16
+ "demo": "ts-node src/test/Demo.ts",
17
+ "clean": "rm -rf dist",
18
+ "prebuild": "npm run clean"
19
+ },
20
+ "author": "Ben Millar",
21
+ "license": "ISC",
22
+ "dependencies": {
23
+ "serialport": "^13.0.0"
24
+ },
25
+ "devDependencies": {
26
+ "@types/jest": "^29.5.12",
27
+ "@types/node": "^25.2.3",
28
+ "jest": "^29.7.0",
29
+ "ts-jest": "^29.1.2",
30
+ "ts-node": "^10.9.2",
31
+ "typescript": "^5.3.3"
32
+ }
33
+ }
@@ -0,0 +1,11 @@
1
+
2
+ export class ComMacro {
3
+ constructor(
4
+ public command: string,
5
+ public response: RegExp
6
+ ) { }
7
+
8
+ toString() {
9
+ return `ComMacro(command='${this.command}', response=${this.response.toString()})`;
10
+ }
11
+ }