-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbundle.js
More file actions
8907 lines (7629 loc) · 255 KB
/
Copy pathbundle.js
File metadata and controls
8907 lines (7629 loc) · 255 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (process,__filename){
/**
* Module dependencies.
*/
var fs = require('fs')
, path = require('path')
, join = path.join
, dirname = path.dirname
, exists = ((fs.accessSync && function (path) { try { fs.accessSync(path); } catch (e) { return false; } return true; })
|| fs.existsSync || path.existsSync)
, defaults = {
arrow: process.env.NODE_BINDINGS_ARROW || ' → '
, compiled: process.env.NODE_BINDINGS_COMPILED_DIR || 'compiled'
, platform: process.platform
, arch: process.arch
, version: process.versions.node
, bindings: 'bindings.node'
, try: [
// node-gyp's linked version in the "build" dir
[ 'module_root', 'build', 'bindings' ]
// node-waf and gyp_addon (a.k.a node-gyp)
, [ 'module_root', 'build', 'Debug', 'bindings' ]
, [ 'module_root', 'build', 'Release', 'bindings' ]
// Debug files, for development (legacy behavior, remove for node v0.9)
, [ 'module_root', 'out', 'Debug', 'bindings' ]
, [ 'module_root', 'Debug', 'bindings' ]
// Release files, but manually compiled (legacy behavior, remove for node v0.9)
, [ 'module_root', 'out', 'Release', 'bindings' ]
, [ 'module_root', 'Release', 'bindings' ]
// Legacy from node-waf, node <= 0.4.x
, [ 'module_root', 'build', 'default', 'bindings' ]
// Production "Release" buildtype binary (meh...)
, [ 'module_root', 'compiled', 'version', 'platform', 'arch', 'bindings' ]
]
}
/**
* The main `bindings()` function loads the compiled bindings for a given module.
* It uses V8's Error API to determine the parent filename that this function is
* being invoked from, which is then used to find the root directory.
*/
function bindings (opts) {
// Argument surgery
if (typeof opts == 'string') {
opts = { bindings: opts }
} else if (!opts) {
opts = {}
}
// maps `defaults` onto `opts` object
Object.keys(defaults).map(function(i) {
if (!(i in opts)) opts[i] = defaults[i];
});
// Get the module root
if (!opts.module_root) {
opts.module_root = exports.getRoot(exports.getFileName())
}
// Ensure the given bindings name ends with .node
if (path.extname(opts.bindings) != '.node') {
opts.bindings += '.node'
}
var tries = []
, i = 0
, l = opts.try.length
, n
, b
, err
for (; i<l; i++) {
n = join.apply(null, opts.try[i].map(function (p) {
return opts[p] || p
}))
tries.push(n)
try {
b = opts.path ? require.resolve(n) : require(n)
if (!opts.path) {
b.path = n
}
return b
} catch (e) {
if (!/not find/i.test(e.message)) {
throw e
}
}
}
err = new Error('Could not locate the bindings file. Tried:\n'
+ tries.map(function (a) { return opts.arrow + a }).join('\n'))
err.tries = tries
throw err
}
module.exports = exports = bindings
/**
* Gets the filename of the JavaScript file that invokes this function.
* Used to help find the root directory of a module.
* Optionally accepts an filename argument to skip when searching for the invoking filename
*/
exports.getFileName = function getFileName (calling_file) {
var origPST = Error.prepareStackTrace
, origSTL = Error.stackTraceLimit
, dummy = {}
, fileName
Error.stackTraceLimit = 10
Error.prepareStackTrace = function (e, st) {
for (var i=0, l=st.length; i<l; i++) {
fileName = st[i].getFileName()
if (fileName !== __filename) {
if (calling_file) {
if (fileName !== calling_file) {
return
}
} else {
return
}
}
}
}
// run the 'prepareStackTrace' function above
Error.captureStackTrace(dummy)
dummy.stack
// cleanup
Error.prepareStackTrace = origPST
Error.stackTraceLimit = origSTL
return fileName
}
/**
* Gets the root directory of a module, given an arbitrary filename
* somewhere in the module tree. The "root directory" is the directory
* containing the `package.json` file.
*
* In: /home/nate/node-native-module/lib/index.js
* Out: /home/nate/node-native-module
*/
exports.getRoot = function getRoot (file) {
var dir = dirname(file)
, prev
while (true) {
if (dir === '.') {
// Avoids an infinite loop in rare cases, like the REPL
dir = process.cwd()
}
if (exists(join(dir, 'package.json')) || exists(join(dir, 'node_modules'))) {
// Found the 'package.json' file or 'node_modules' dir; we're done
return dir
}
if (prev === dir) {
// Got to the top
throw new Error('Could not find module root given file: "' + file
+ '". Do you have a `package.json` file? ')
}
// Try the parent dir next
prev = dir
dir = join(dir, '..')
}
}
}).call(this,require('_process'),"/node_modules/bindings/bindings.js")
},{"_process":39,"fs":27,"path":37}],2:[function(require,module,exports){
/**
* Helpers.
*/
var s = 1000;
var m = s * 60;
var h = m * 60;
var d = h * 24;
var y = d * 365.25;
/**
* Parse or format the given `val`.
*
* Options:
*
* - `long` verbose formatting [false]
*
* @param {String|Number} val
* @param {Object} [options]
* @throws {Error} throw an error if val is not a non-empty string or a number
* @return {String|Number}
* @api public
*/
module.exports = function(val, options) {
options = options || {};
var type = typeof val;
if (type === 'string' && val.length > 0) {
return parse(val);
} else if (type === 'number' && isNaN(val) === false) {
return options.long ? fmtLong(val) : fmtShort(val);
}
throw new Error(
'val is not a non-empty string or a valid number. val=' +
JSON.stringify(val)
);
};
/**
* Parse the given `str` and return milliseconds.
*
* @param {String} str
* @return {Number}
* @api private
*/
function parse(str) {
str = String(str);
if (str.length > 100) {
return;
}
var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(
str
);
if (!match) {
return;
}
var n = parseFloat(match[1]);
var type = (match[2] || 'ms').toLowerCase();
switch (type) {
case 'years':
case 'year':
case 'yrs':
case 'yr':
case 'y':
return n * y;
case 'days':
case 'day':
case 'd':
return n * d;
case 'hours':
case 'hour':
case 'hrs':
case 'hr':
case 'h':
return n * h;
case 'minutes':
case 'minute':
case 'mins':
case 'min':
case 'm':
return n * m;
case 'seconds':
case 'second':
case 'secs':
case 'sec':
case 's':
return n * s;
case 'milliseconds':
case 'millisecond':
case 'msecs':
case 'msec':
case 'ms':
return n;
default:
return undefined;
}
}
/**
* Short format for `ms`.
*
* @param {Number} ms
* @return {String}
* @api private
*/
function fmtShort(ms) {
if (ms >= d) {
return Math.round(ms / d) + 'd';
}
if (ms >= h) {
return Math.round(ms / h) + 'h';
}
if (ms >= m) {
return Math.round(ms / m) + 'm';
}
if (ms >= s) {
return Math.round(ms / s) + 's';
}
return ms + 'ms';
}
/**
* Long format for `ms`.
*
* @param {Number} ms
* @return {String}
* @api private
*/
function fmtLong(ms) {
return plural(ms, d, 'day') ||
plural(ms, h, 'hour') ||
plural(ms, m, 'minute') ||
plural(ms, s, 'second') ||
ms + ' ms';
}
/**
* Pluralization helper.
*/
function plural(ms, n, name) {
if (ms < n) {
return;
}
if (ms < n * 1.5) {
return Math.floor(ms / n) + ' ' + name;
}
return Math.ceil(ms / n) + ' ' + name + 's';
}
},{}],3:[function(require,module,exports){
/* eslint-disable node/no-deprecated-api */
var buffer = require('buffer')
var Buffer = buffer.Buffer
// alternative to using Object.keys for old browsers
function copyProps (src, dst) {
for (var key in src) {
dst[key] = src[key]
}
}
if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
module.exports = buffer
} else {
// Copy properties from require('buffer')
copyProps(buffer, exports)
exports.Buffer = SafeBuffer
}
function SafeBuffer (arg, encodingOrOffset, length) {
return Buffer(arg, encodingOrOffset, length)
}
// Copy static methods from Buffer
copyProps(Buffer, SafeBuffer)
SafeBuffer.from = function (arg, encodingOrOffset, length) {
if (typeof arg === 'number') {
throw new TypeError('Argument must not be a number')
}
return Buffer(arg, encodingOrOffset, length)
}
SafeBuffer.alloc = function (size, fill, encoding) {
if (typeof size !== 'number') {
throw new TypeError('Argument must be a number')
}
var buf = Buffer(size)
if (fill !== undefined) {
if (typeof encoding === 'string') {
buf.fill(fill, encoding)
} else {
buf.fill(fill)
}
} else {
buf.fill(0)
}
return buf
}
SafeBuffer.allocUnsafe = function (size) {
if (typeof size !== 'number') {
throw new TypeError('Argument must be a number')
}
return Buffer(size)
}
SafeBuffer.allocUnsafeSlow = function (size) {
if (typeof size !== 'number') {
throw new TypeError('Argument must be a number')
}
return buffer.SlowBuffer(size)
}
},{"buffer":30}],4:[function(require,module,exports){
(function (process){
'use strict';
const debug = require('debug')('serialport:binding:auto-detect');
switch (process.platform) {
case 'win32':
debug('loading WindowsBinding');
module.exports = require('./win32');
break;
case 'darwin':
debug('loading DarwinBinding');
module.exports = require('./darwin');
break;
default:
debug('loading LinuxBinding');
module.exports = require('./linux');
}
}).call(this,require('_process'))
},{"./darwin":6,"./linux":8,"./win32":13,"_process":39,"debug":24}],5:[function(require,module,exports){
(function (Buffer){
'use strict';
const debug = require('debug')('serialport:bindings');
/**
* @name module:serialport.Binding
* @type {module:serialport~BaseBinding}
* @since 5.0.0
* @description The `Binding` is how Node-SerialPort talks to the underlying system. By default, we auto detect Windows, Linux and OS X, and load the appropriate module for your system. You can assign `SerialPort.Binding` to any binding you like. Find more by searching at [npm](https://npmjs.org/).
Prevent auto loading the default bindings by requiring SerialPort with:
```js
var SerialPort = require('serialport/lib/serialport');
SerialPort.Binding = MyBindingClass;
```
*/
/**
* You never have to use `Binding` objects directly. SerialPort uses them to access the underlying hardware. This documentation is geared towards people who are making bindings for different platforms. This class can be inherited from to get type checking for each method.
* @class BaseBinding
* @param {object} options
* @property {boolean} isOpen Required property. `true` if the port is open, `false` otherwise. Should be read-only.
* @throws {TypeError} When given invalid arguments, a `TypeError` is thrown.
* @since 5.0.0
*/
class BaseBinding {
/**
* Retrieves a list of available serial ports with metadata. The `comName` must be guaranteed, and all other fields should be undefined if unavailable. The `comName` is either the path or an identifier (eg `COM1`) used to open the serialport.
* @returns {Promise} resolves to an array of port [info objects](#module_serialport--SerialPort.list).
*/
static list() {
debug('list');
return Promise.resolve();
}
constructor(opt) {
if (typeof opt !== 'object') {
throw new TypeError('"options" is not an object');
}
}
/**
* Opens a connection to the serial port referenced by the path.
* @param {string} path
* @param {module:serialport~openOptions} openOptions
* @returns {Promise} Resolves after the port is opened and configured.
* @throws {TypeError} When given invalid arguments, a `TypeError` is thrown.
*/
open(path, options) {
if (!path) {
throw new TypeError('"path" is not a valid port');
}
if (typeof options !== 'object') {
throw new TypeError('"options" is not an object');
}
debug('open');
if (this.isOpen) {
return Promise.reject(new Error('Already open'));
}
return Promise.resolve();
}
/**
* Closes an open connection
* @returns {Promise} Resolves once the connection is closed.
* @throws {TypeError} When given invalid arguments, a `TypeError` is thrown.
*/
close() {
debug('close');
if (!this.isOpen) {
return Promise.reject(new Error('Port is not open'));
}
return Promise.resolve();
}
/**
* Request a number of bytes from the SerialPort. This function is similar to Node's [`fs.read`](http://nodejs.org/api/fs.html#fs_fs_read_fd_buffer_offset_length_position_callback) except it will always return at least one byte.
The in progress reads must error when the port is closed with an error object that has the property `canceled` equal to `true`. Any other error will cause a disconnection.
* @param {buffer} data Accepts a [`Buffer`](http://nodejs.org/api/buffer.html) object.
* @param {integer} offset The offset in the buffer to start writing at.
* @param {integer} length Specifies the maximum number of bytes to read.
* @returns {Promise} Resolves with the number of bytes read after a read operation.
* @throws {TypeError} When given invalid arguments, a `TypeError` is thrown.
*/
read(buffer, offset, length) {
if (!Buffer.isBuffer(buffer)) {
throw new TypeError('"buffer" is not a Buffer');
}
if (typeof offset !== 'number') {
throw new TypeError('"offset" is not an integer');
}
if (typeof length !== 'number') {
throw new TypeError('"length" is not an integer');
}
debug('read');
if (buffer.length < offset + length) {
return Promise.reject(new Error('buffer is too small'));
}
if (!this.isOpen) {
return Promise.reject(new Error('Port is not open'));
}
return Promise.resolve();
}
/**
* Write bytes to the SerialPort. Only called when there is no pending write operation.
The in progress writes must error when the port is closed with an error object that has the property `canceled` equal to `true`. Any other error will cause a disconnection.
* @param {buffer} data - Accepts a [`Buffer`](http://nodejs.org/api/buffer.html) object.
* @returns {Promise} Resolves after the data is passed to the operating system for writing.
* @throws {TypeError} When given invalid arguments, a `TypeError` is thrown.
*/
write(buffer) {
if (!Buffer.isBuffer(buffer)) {
throw new TypeError('"buffer" is not a Buffer');
}
debug('write', buffer.length, 'bytes');
if (!this.isOpen) {
return Promise.reject(new Error('Port is not open'));
}
return Promise.resolve();
}
/**
* Changes connection settings on an open port. Only `baudRate` is supported.
* @param {object=} options Only supports `baudRate`.
* @param {number=} [options.baudRate] If provided a baud rate that the bindings do not support, it should pass an error to the callback.
* @returns {Promise} Resolves once the port's baud rate changes.
* @throws {TypeError} When given invalid arguments, a `TypeError` is thrown.
*/
update(options) {
if (typeof options !== 'object') {
throw TypeError('"options" is not an object');
}
if (typeof options.baudRate !== 'number') {
throw new TypeError('"options.baudRate" is not a number');
}
debug('update');
if (!this.isOpen) {
return Promise.reject(new Error('Port is not open'));
}
return Promise.resolve();
}
/**
* Set control flags on an open port.
* @param {object=} options All options are operating system default when the port is opened. Every flag is set on each call to the provided or default values. All options are always provided.
* @param {Boolean} [options.brk=false]
* @param {Boolean} [options.cts=false]
* @param {Boolean} [options.dsr=false]
* @param {Boolean} [options.dtr=true]
* @param {Boolean} [options.rts=true]
* @returns {Promise} Resolves once the port's flags are set.
* @throws {TypeError} When given invalid arguments, a `TypeError` is thrown.
*/
set(options) {
if (typeof options !== 'object') {
throw new TypeError('"options" is not an object');
}
debug('set');
if (!this.isOpen) {
return Promise.reject(new Error('Port is not open'));
}
return Promise.resolve();
}
/**
* Get the control flags (CTS, DSR, DCD) on the open port.
* @returns {Promise} Resolves with the retrieved flags.
* @throws {TypeError} When given invalid arguments, a `TypeError` is thrown.
*/
get() {
debug('get');
if (!this.isOpen) {
return Promise.reject(new Error('Port is not open'));
}
return Promise.resolve();
}
/**
* Flush (discard) data received but not read, and written but not transmitted.
* @returns {Promise} Resolves once the flush operation finishes.
* @throws {TypeError} When given invalid arguments, a `TypeError` is thrown.
*/
flush() {
debug('flush');
if (!this.isOpen) {
return Promise.reject(new Error('Port is not open'));
}
return Promise.resolve();
}
/**
* Drain waits until all output data is transmitted to the serial port. An in progress write should be completed before this returns.
* @returns {Promise} Resolves once the drain operation finishes.
* @throws {TypeError} When given invalid arguments, a `TypeError` is thrown.
*/
drain() {
debug('drain');
if (!this.isOpen) {
return Promise.reject(new Error('Port is not open'));
}
return Promise.resolve();
}
}
module.exports = BaseBinding;
}).call(this,{"isBuffer":require("../../../../opencvjs/opencv/emsdk-portable/node/8.9.1_64bit/lib/node_modules/browserify/node_modules/is-buffer/index.js")})
},{"../../../../opencvjs/opencv/emsdk-portable/node/8.9.1_64bit/lib/node_modules/browserify/node_modules/is-buffer/index.js":35,"debug":24}],6:[function(require,module,exports){
'use strict';
const binding = require('bindings')('serialport.node');
const BaseBinding = require('./base');
const Poller = require('./poller');
const promisify = require('../util').promisify;
const unixRead = require('./unix-read');
const unixWrite = require('./unix-write');
const defaultBindingOptions = Object.freeze({
vmin: 1,
vtime: 0
});
class DarwinBinding extends BaseBinding {
static list() {
return promisify(binding.list)();
}
constructor(opt) {
super(opt);
this.bindingOptions = Object.assign({}, defaultBindingOptions, opt.bindingOptions || {});
this.fd = null;
this.writeOperation = null;
}
get isOpen() {
return this.fd !== null;
}
open(path, options) {
return super.open(path, options)
.then(() => {
this.openOptions = Object.assign({}, this.bindingOptions, options);
return promisify(binding.open)(path, this.openOptions);
})
.then((fd) => {
this.fd = fd;
this.poller = new Poller(fd);
});
}
close() {
return super.close()
.then(() => {
const fd = this.fd;
this.poller.stop();
this.poller = null;
this.openOptions = null;
this.fd = null;
return promisify(binding.close)(fd);
});
}
read(buffer, offset, length) {
return super.read(buffer, offset, length)
.then(() => unixRead.call(this, buffer, offset, length));
}
write(buffer) {
this.writeOperation = super.write(buffer)
.then(() => unixWrite.call(this, buffer))
.then(() => {
this.writeOperation = null;
});
return this.writeOperation;
}
update(options) {
return super.update(options)
.then(() => promisify(binding.update)(this.fd, options));
}
set(options) {
return super.set(options)
.then(() => promisify(binding.set)(this.fd, options));
}
get() {
return super.get()
.then(() => promisify(binding.get)(this.fd));
}
drain() {
return super.drain()
.then(() => Promise.resolve(this.writeOperation))
.then(() => promisify(binding.drain)(this.fd));
}
flush() {
return super.flush()
.then(() => promisify(binding.flush)(this.fd));
}
}
module.exports = DarwinBinding;
},{"../util":23,"./base":5,"./poller":9,"./unix-read":10,"./unix-write":11,"bindings":1}],7:[function(require,module,exports){
'use strict';
const childProcess = require('child_process');
const Readline = require('../parsers/readline');
// get only serial port names
function checkPathOfDevice(path) {
return (/(tty(S|ACM|USB|AMA|MFD)|rfcomm)/).test(path) && path;
}
function propName(name) {
return {
'DEVNAME': 'comName',
'ID_VENDOR_ENC': 'manufacturer',
'ID_SERIAL_SHORT': 'serialNumber',
'ID_VENDOR_ID': 'vendorId',
'ID_MODEL_ID': 'productId',
'DEVLINKS': 'pnpId'
}[name.toUpperCase()];
}
function decodeHexEscape(str) {
return str.replace(/\\x([a-fA-F0-9]{2})/g, (a, b) => {
return String.fromCharCode(parseInt(b, 16));
});
}
function propVal(name, val) {
if (name === 'pnpId') {
const match = val.match(/\/by-id\/([^\s]+)/);
return (match && match[1]) || undefined;
}
if (name === 'manufacturer') {
return decodeHexEscape(val);
}
if (/^0x/.test(val)) {
return val.substr(2);
}
return val;
}
function listLinux() {
return new Promise((resolve, reject) => {
const ports = [];
const ude = childProcess.spawn('udevadm', ['info', '-e']);
const lines = ude.stdout.pipe(new Readline());
ude.on('error', reject);
lines.on('error', reject);
let port = {};
let skipPort = false;
lines.on('data', (line) => {
const lineType = line.slice(0, 1);
const data = line.slice(3);
// new port entry
if (lineType === 'P') {
port = {
manufacturer: undefined,
serialNumber: undefined,
pnpId: undefined,
locationId: undefined,
vendorId: undefined,
productId: undefined
};
skipPort = false;
return;
}
if (skipPort) { return }
// Check dev name and save port if it matches flag to skip the rest of the data if not
if (lineType === 'N') {
if (checkPathOfDevice(data)) {
ports.push(port);
} else {
skipPort = true;
}
return;
}
// parse data about each port
if (lineType === 'E') {
const keyValue = data.match(/^(.+)=(.*)/);
if (!keyValue) { return }
const key = propName(keyValue[1]);
if (!key) { return }
port[key] = propVal(key, keyValue[2]);
}
});
lines.on('finish', () => resolve(ports));
});
}
module.exports = listLinux;
},{"../parsers/readline":19,"child_process":27}],8:[function(require,module,exports){
'use strict';
const binding = require('bindings')('serialport.node');
const BaseBinding = require('./base');
const linuxList = require('./linux-list');
const Poller = require('./poller');
const promisify = require('../util').promisify;
const unixRead = require('./unix-read');
const unixWrite = require('./unix-write');
const defaultBindingOptions = Object.freeze({
vmin: 1,
vtime: 0
});
class LinuxBinding extends BaseBinding {
static list() {
return linuxList();
}
constructor(opt) {
super(opt);
this.bindingOptions = Object.assign({}, defaultBindingOptions, opt.bindingOptions || {});
this.fd = null;
this.writeOperation = null;
}
get isOpen() {
return this.fd !== null;
}
open(path, options) {
return super.open(path, options)
.then(() => {
this.openOptions = Object.assign({}, this.bindingOptions, options);
return promisify(binding.open)(path, this.openOptions);
})
.then((fd) => {
this.fd = fd;
this.poller = new Poller(fd);
});
}
close() {
return super.close()
.then(() => {
const fd = this.fd;
this.poller.stop();
this.poller = null;
this.openOptions = null;
this.fd = null;
return promisify(binding.close)(fd);
});
}
read(buffer, offset, length) {
return super.read(buffer, offset, length)
.then(() => unixRead.call(this, buffer, offset, length));
}
write(buffer) {
this.writeOperation = super.write(buffer)
.then(() => unixWrite.call(this, buffer))
.then(() => {
this.writeOperation = null;
});
return this.writeOperation;
}
update(options) {
return super.update(options)
.then(() => promisify(binding.update)(this.fd, options));
}
set(options) {
return super.set(options)
.then(() => promisify(binding.set)(this.fd, options));
}
get() {
return super.get()
.then(() => promisify(binding.get)(this.fd));
}
drain() {
return super.drain()
.then(() => Promise.resolve(this.writeOperation))
.then(() => promisify(binding.drain)(this.fd));
}
flush() {
return super.flush()
.then(() => promisify(binding.flush)(this.fd));
}
}
module.exports = LinuxBinding;
},{"../util":23,"./base":5,"./linux-list":7,"./poller":9,"./unix-read":10,"./unix-write":11,"bindings":1}],9:[function(require,module,exports){
'use strict';
const debug = require('debug');
const logger = debug('serialport:poller');
const EventEmitter = require('events');
const FDPoller = require('bindings')('serialport.node').Poller;
/**
* Enum of event values
* @enum {int}
*/
const EVENTS = {
UV_READABLE: 1,
UV_WRITABLE: 2,
UV_DISCONNECT: 4
};
function handleEvent(error, eventFlag) {
if (error) {
logger('error', error);
this.emit('readable', error);
this.emit('writable', error);
this.emit('disconnect', error);
return;
}
if (eventFlag & EVENTS.UV_READABLE) {
logger('received "readable"');
this.emit('readable', null);
}
if (eventFlag & EVENTS.UV_WRITABLE) {
logger('received "writable"');
this.emit('writable', null);
}
if (eventFlag & EVENTS.UV_DISCONNECT) {
logger('received "disconnect"');
this.emit('disconnect', null);
}
}
/**
* Polls unix systems for readable or writable states of a file or serialport
*/
class Poller extends EventEmitter {
constructor(fd) {
logger('Creating poller');
super();
this.poller = new FDPoller(fd, handleEvent.bind(this));
}
/**
* Wait for the next event to occur
* @param {string} Event ('readable'|'writable'|'disconnect')
* @param {function} callback
*/
once(event) {
switch (event) {
case 'readable':
this.poll(EVENTS.UV_READABLE);
break;
case 'writable':
this.poll(EVENTS.UV_WRITABLE);
break;
case 'disconnect':
this.poll(EVENTS.UV_DISCONNECT);
break;
}
return EventEmitter.prototype.once.apply(this, arguments);
}
/**
* Ask the bindings to listen for an event
* @param {EVENTS} eventFlag
*/
poll(eventFlag) {