-
Notifications
You must be signed in to change notification settings - Fork 0
/
analogway_livecore.js
665 lines (596 loc) · 21.1 KB
/
analogway_livecore.js
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
var tcp = require('../../tcp');
var instance_skel = require('../../instance_skel');
var debug;
var log;
function instance(system, id, config) {
var self = this;
this.firmwareVersion = "0";
this.numOutputs = 0;
this.numInputs = 0;
this.modelnum;
this.modelname = '';
// super-constructor
instance_skel.apply(this, arguments);
self.actions(); // export actions
return self;
}
instance.prototype.init = function() {
var self = this;
debug = self.debug;
log = self.log;
self.init_tcp();
};
instance.prototype.init_tcp = function() {
var self = this;
var receivebuffer = '';
if (self.socket !== undefined) {
self.socket.destroy();
}
if (self.config.host) {
self.socket = new tcp(self.config.host, 10600);
self.socket.on('status_change', function (status, message) {
self.status(status, message);
});
self.socket.on('error', function (err) {
debug("Network error", err);
self.log('error',"Network error: " + err.message);
});
self.socket.on('connect', function () {
debug("Connected");
self.sendcmd("");
});
// separate buffered stream into lines with responses
self.socket.on('data', function (chunk) {
var i = 0, line = '', offset = 0;
receivebuffer += chunk;
while ( (i = receivebuffer.indexOf('\r\n', offset)) !== -1) {
line = receivebuffer.substr(offset, i - offset);
offset = i + 1;
self.socket.emit('receiveline', line.toString());
}
receivebuffer = receivebuffer.substr(offset);
});
self.socket.on('receiveline', function (line) {
debug("Received line from Livecore:", line);
if (line.match(/TPcon\d,\d+/)) {
if (line.match(/TPcon0,\d+/) == null) {
self.log('error',"Connected to "+ self.config.label +", but this is not the master of stacked configuation! Closing connection now.");
self.socket.destroy();
}
var connectedDevices = parseInt(line.match(/TPcon0,(\d)/)[1]);
if (connectedDevices < 4) {
self.log('info',self.config.label +" has " + (connectedDevices-1) + " other connected controller(s).");
self.sendcmd("?");
} else if (connectedDevices == 4) {
self.log(warn,self.config.label +" has 4 other connected controllers. Maximum reached.");
self.sendcmd("?");
} else {
self.log('error',self.config.label +" connections limit has been reached! Max 5 controllers possible, but it is " + connectedDevices + "! Closing connection now.");
self.socket.destroy(); // TODO: there should be a possibility for the user to reconnect
}
}
if (line.match(/DEV\d+/)) {
this.model = parseInt(line.match(/DEV(\d+)/)[1]);
switch (this.model) {
case 97: this.modelname = 'NeXtage 16'; break;
case 98: this.modelname = 'SmartMatriX Ultra'; break;
case 99: this.modelname = 'Ascender 32'; break;
case 100: this.modelname = 'Ascender 48'; break;
case 102: this.modelname = 'Output Expander 16'; break;
case 103: this.modelname = 'Output Expander 32'; break;
case 104: this.modelname = 'Output Expander 48'; break;
case 105: this.modelname = 'NeXtage 16 - 4K'; break;
case 106: this.modelname = 'SmartMatriX Ultra - 4K'; break;
case 107: this.modelname = 'Ascender 32 - 4K'; break;
case 108: this.modelname = 'Ascender 48 - 4K'; break;
case 112: this.modelname = 'Ascender 16'; break;
case 113: this.modelname = 'Ascender 16 - 4K'; break;
case 114: this.modelname = 'Ascender 48 - 4K - PL'; break;
case 115: this.modelname = 'Output Expander 48 - 4K - PL'; break;
case 116: this.modelname = 'NeXtage 08'; break;
case 117: this.modelname = 'NeXtage 08 - 4K'; break;
case 118: this.modelname = 'Ascender 32 - 4K -PL'; break;
case 119: this.modelname = 'Output Expander 32 - 4K - PL'; break;
default: this.modelname = 'unknown'; break;
}
self.log('info', self.config.label +" Type is "+ this.modelname);
self.sendcmd("0,TPver");
}
if (line.match(/TPver\d+/)) {
var commandSetVersion = parseInt(line.match(/TPver\d+,(\d+)/)[1]);
self.log('info', "Command set version of " + self.config.label +" is " + commandSetVersion);
// TODO: Should check the machine state now, will be implemented after feedback system is done
}
if (line.match(/TPdie0/)) {
//There is no parameter readback runnning, it can be started now
}
if (line.match(/E\d{2}/)) {
switch (parseInt(line.match(/E(\d{2})/)[1])) {
case 10: self.log('error',"Received command name error from "+ self.config.label +": "+ line); break;
case 11: self.log('error',"Received index value out of range error from "+ self.config.label +": "+ line); break;
case 12: self.log('error',"Received index count (too few or too much) error from "+ self.config.label +": "+ line); break;
case 13: self.log('error',"Received value out of range error from "+ self.config.label +": "+ line); break;
default: self.log('error',"Received unspecified error from Livecore "+ self.config.label +": "+ line);
}
}
});
}
};
// Return config fields for web config
instance.prototype.config_fields = function () {
var self = this;
return [
{
type: 'textinput',
id: 'host',
label: 'IP-Adress of Livecore Unit',
width: 6,
default: '192.168.2.140',
regex: self.REGEX_IP,
tooltip: 'Enter the IP-adress of the Livecore unit you want to control. The IP of the unit can be found on the frontpanel LCD.\nIf you want to control stacked configurations, please enter the IP of the master unit.'
},{
type: 'dropdown',
label: 'Variant',
id: 'variant',
default: '1',
choices: [
{ id: '1', label: 'ASC4806' },
{ id: '2', label: 'ASC3204' },
{ id: '3', label: 'ASC1602' },
{ id: '4', label: 'NXT1604' },
{ id: '5', label: 'NXT0802' },
{ id: '6', label: 'SMX12x4' }
]
}
]
};
// When module gets deleted
instance.prototype.destroy = function() {
var self = this;
if (self.socket !== undefined) {
self.socket.destroy();
}
debug("destroy", self.id);;
};
instance.prototype.actions = function(system) {
var self = this;
self.system.emit('instance_actions', self.id, { // Note: Options-IDs need to be 0,1,... in the order of the command (1st index, 2nd index, nth index, value) for self generating commands.
'1SPtsl': {
label: 'Take selected screens'
},
'takescreen': {
label: 'Take single screen',
options: [{
type: 'dropdown',
label: 'Screen',
id: 'screen',
default: '0',
choices: [
{ id: '0', label: '1' },
{ id: '1', label: '2' },
{ id: '2', label: '3' },
{ id: '3', label: '4' },
{ id: '4', label: '5' },
{ id: '5', label: '6' },
{ id: '6', label: '7' },
{ id: '7', label: '8' }
]
}]},
'loadpreset': {
label: 'Load Memory',
options: [{
type: 'textinput',
label: 'Memory to load',
id: 'memory',
default: '1',
tooltip: 'Enter the number of the memory you want to load from 1 to 144',
regex: '/^0*([1-9]|[1-8][0-9]|9[0-9]|1[0-3][0-9]|14[0-4])$/'
},{
type: 'textinput',
label: 'Destination screen',
id: 'destscreen',
default: '1',
tooltip: 'Enter the number of the screen where the memory schould be loaded to (1 to 8)',
regex: '/^0*[1-8]$/'
},{
type: 'dropdown',
label: 'PGM/PVW',
id: 'pgmpvw',
default: '1',
tooltip: 'Select wether the memory schould be loaded into the preview or program of the screen',
choices: [ { id: '0', label: 'Program' }, { id: '1', label: 'Preview' }]
},{
type: 'dropdown',
label: 'Scale enable',
id: 'scale',
default: '1',
tooltip: 'Select wether the layers in the memory should be scaled according to the size of the screen if it is different from the size of the screen which the memory has been saved from.',
choices: [ { id: '0', label: 'Do not scale' }, { id: '1', label: 'Enable scale' }]
}]},
'loadmaster': {
label: 'Load Master Memory',
options: [{
type: 'textinput',
label: 'Master Memory to load',
id: 'memory',
default: '1',
tooltip: 'Enter the number of the master memory you want to load from 1 to 144',
regex: '/^0*([1-9]|[1-8][0-9]|9[0-9]|1[0-3][0-9]|14[0-4])$/'
},{
type: 'dropdown',
label: 'PGM/PVW',
id: 'pgmpvw',
default: '1',
tooltip: 'Select wether the memory schould be loaded into the preview or program of the screens',
choices: [ { id: '0', label: 'Program' }, { id: '1', label: 'Preview' }]
},{
type: 'dropdown',
label: 'Scale enable',
id: 'scale',
default: '1',
tooltip: 'Select wether the layers in the memory should be scaled according to the size of the screens if it is different from the size of the screens which the memory has been saved from.',
choices: [ { id: '0', label: 'Do not scale' }, { id: '1', label: 'Enable scale' }]
}]},
'setfilter': {
label: 'Set recall filter',
options: [{
type: 'dropdown',
label: 'Layer source',
id: 'filter1',
default: '1',
tooltip: 'Select wether the layer source should be included in the memory recall.',
choices: [ { id: '0', label: 'Exclude source' }, { id: '1', label: 'Include source' }]
},{
type: 'dropdown',
label: 'Layer position and size',
id: 'filter2',
default: '1',
tooltip: 'Select wether the layer position and size should be included in the memory recall.',
choices: [ { id: '0', label: 'Exclude position and size' }, { id: '1', label: 'Include position and size' }]
},{
type: 'dropdown',
label: 'Layer transparency',
id: 'filter4',
default: '1',
tooltip: 'Select wether the layer transparency should be included in the memory recall.',
choices: [ { id: '0', label: 'Exclude transparency' }, { id: '1', label: 'Include transparency' }]
},{
type: 'dropdown',
label: 'Layer crop',
id: 'filter8',
default: '1',
tooltip: 'Select wether the layer crop should be included in the memory recall.',
choices: [ { id: '0', label: 'Exclude crop' }, { id: '1', label: 'Include crop' }]
},{
type: 'dropdown',
label: 'Layer border',
id: 'filter16',
default: '1',
tooltip: 'Select wether the layer border apperance should be included in the memory recall.',
choices: [ { id: '0', label: 'Exclude border' }, { id: '1', label: 'Include border' }]
},{
type: 'dropdown',
label: 'Layer transitions',
id: 'filter32',
default: '1',
tooltip: 'Select wether the layer opening and closing transitions should be included in the memory recall.',
choices: [ { id: '0', label: 'Exclude transitions' }, { id: '1', label: 'Include transitions' }]
},{
type: 'dropdown',
label: 'Layer effects',
id: 'filter64',
default: '1',
tooltip: 'Select wether the layer effects should be included in the memory recall.',
choices: [ { id: '0', label: 'Exclude effects' }, { id: '1', label: 'Include effects' }]
},{
type: 'dropdown',
label: 'Layer timing',
id: 'filter128',
default: '1',
tooltip: 'Select wether the layer timing should be included in the memory recall.',
choices: [ { id: '0', label: 'Exclude timing' }, { id: '1', label: 'Include timing' }]
},{
type: 'dropdown',
label: 'Layer speed',
id: 'filter256',
default: '1',
tooltip: 'Select wether the layer speed should be included in the memory recall.',
choices: [ { id: '0', label: 'Exclude speed' }, { id: '1', label: 'Include speed' }]
},{
type: 'dropdown',
label: 'Layer flying curve',
id: 'filter512',
default: '1',
tooltip: 'Select wether the layer flying curve should be included in the memory recall.',
choices: [ { id: '0', label: 'Exclude flying curve' }, { id: '1', label: 'Include flying curve' }]
},{
type: 'dropdown',
label: 'Native background',
id: 'filter1024',
default: '1',
tooltip: 'Select wether the native background should be included in the memory recall.',
choices: [ { id: '0', label: 'Exclude native background' }, { id: '1', label: 'Include native background' }]
},{
type: 'dropdown',
label: 'Layer mask',
id: 'filter2048',
default: '1',
tooltip: 'Select wether the layer mask should be included in the memory recall.',
choices: [ { id: '0', label: 'Exclude mask' }, { id: '1', label: 'Include mask' }]
}]},
'loadmonitoring': {
label: 'Recall Monitoring Memory',
options: [{
type: 'textinput',
label: 'Monitoring Memory to load',
id: 'memory',
default: '1',
tooltip: 'Enter the number of the memory you want to load from 1 to 8',
regex: '/^0*[1-8]$/'
},{
type: 'dropdown',
label: 'Device',
id: 'device',
default: '0',
tooltip: 'Select wether the monitoring memory schould be recalled on master or slave device in a stacked configuration. Leave at master for single configuration.',
choices: [ { id: '0', label: 'Master' }, { id: '1', label: 'Slave' }]
}]},
'selectscreens': {
label: 'Select screens for global take',
tooltip: 'Select the screens which schould transition with the global take command. The selection stays active until changed again.',
options: [{
type: 'dropdown',
label: 'Screen 1',
id: '0',
default: '0',
choices: [ { id: '0', label: 'No change' }, { id: '1', label: 'Add to selection' }, { id: '2', label: 'Remove from selection' }]
},{
type: 'dropdown',
label: 'Screen 2',
id: '1',
default: '0',
choices: [ { id: '0', label: 'No change' }, { id: '1', label: 'Add to selection' }, { id: '2', label: 'Remove from selection' }]
},{
type: 'dropdown',
label: 'Screen 3',
id: '2',
default: '0',
choices: [ { id: '0', label: 'No change' }, { id: '1', label: 'Add to selection' }, { id: '2', label: 'Remove from selection' }]
},{
type: 'dropdown',
label: 'Screen 4',
id: '3',
default: '0',
choices: [ { id: '0', label: 'No change' }, { id: '1', label: 'Add to selection' }, { id: '2', label: 'Remove from selection' }]
},{
type: 'dropdown',
label: 'Screen 5',
id: '4',
default: '0',
choices: [ { id: '0', label: 'No change' }, { id: '1', label: 'Add to selection' }, { id: '2', label: 'Remove from selection' }]
},{
type: 'dropdown',
label: 'Screen 6',
id: '5',
default: '0',
choices: [ { id: '0', label: 'No change' }, { id: '1', label: 'Add to selection' }, { id: '2', label: 'Remove from selection' }]
},{
type: 'dropdown',
label: 'Screen 7',
id: 'screen7',
default: '0',
choices: [ { id: '0', label: 'No change' }, { id: '1', label: 'Add to selection' }, { id: '2', label: 'Remove from selection' }]
},{
type: 'dropdown',
label: 'Screen 8',
id: 'screen8',
default: '0',
choices: [ { id: '0', label: 'No change' }, { id: '1', label: 'Add to selection' }, { id: '2', label: 'Remove from selection' }]
}]},
'loadconfidence': {
label: 'Load confidence Memory',
options: [{
type: 'textinput',
label: 'Memory',
id: 'memory',
default: '',
tooltip: 'Enter the number of the memory you want to load from 1 to 16',
regex: '/^0*([1-9]|1[0-6])$/'
},{
type: 'textinput',
label: 'Destination screen',
id: 'destscreen',
default: '1',
tooltip: 'Enter the number of the screen where the memory schould be loaded to (1 to 8)',
regex: '/^0*[1-8]$/'
}]},
'activateconfidence': {
label: 'Switch confidence mode',
options: [{
type: 'textinput',
label: 'Screen',
id: 'destscreen',
default: '1',
tooltip: 'Enter the number of the screen where confidence mode should be switched (1 to 8)',
regex: '/^0*[1-8]$/'
},{
type: 'dropdown',
label: 'Mode',
id: 'mode',
default: '0',
tooltip: 'Select wether confidence mode should be switched on or off at selected screen',
choices: [ { id: '0', label: 'Off' }, { id: '1', label: 'On' }]
}]},
'switchplug': {
label: 'Switch input plug',
tooltip: 'Note that not all inputs may be available at your system and not all plugs are available at any input.',
options: [{
type: 'textinput',
label: 'Input',
id: 'input',
default: '1',
tooltip: 'Enter the number of the input where you want to switch the input plug (1 to 12 for inputs of master device and 13 to 24 for inputs of slave device).',
regex: '/^0*([1-9]|1[0-9]|2[0-4])$/'
},{
type: 'dropdown',
label: 'Plug',
id: 'plug',
default: '0',
tooltip: 'Select the plug to use for that input',
choices: [ { id: '0', label: 'Analog HD15 connector' }, { id: '1', label: 'Analog DVI-A connector' }, { id: '2', label: 'DVI' }, { id: '3', label: 'SDI' }, { id: '4', label: 'HDMI' }, { id: '5', label: 'DisplayPort' } ]
}]},
'sendcustomcommand': {
label: 'Send custom command',
options: [{
type: 'textinput',
label: 'Command',
id: 'command',
default: '',
tooltip: "Enter any command you like in plain ASCII. Beware of correct syntax, you mustn't enter the linebreak at the end of the command.",
regex: '/^[\\w,]+$/i'
}]}
});
}
instance.prototype.action = function(action) {
var self = this;
var cmd = '';
switch(action.action) {
case 'takescreen':
cmd = '' + action.options.screen + ',1SPCtk\n';
break;
case 'setfilter':
var filterval = 0;
if (action.options.filter1 == '1') filterval += 1;
if (action.options.filter2 == '1') filterval += 2;
if (action.options.filter4 == '1') filterval += 4;
if (action.options.filter8 == '1') filterval += 8;
if (action.options.filter16 == '1') filterval += 16;
if (action.options.filter32 == '1') filterval += 32;
if (action.options.filter64 == '1') filterval += 64;
if (action.options.filter128 == '1') filterval += 128;
if (action.options.filter256 == '1') filterval += 256;
if (action.options.filter512 == '1') filterval += 512;
if (action.options.filter1024 == '1') filterval += 1024;
if (action.options.filter2048 == '1') filterval += 2048;
cmd = filterval + 'PMcat';
break;
case 'loadpreset':
// set scale
if (action.options.scale == '0') {
cmd = '0PMlse\n';
} else {
cmd = '1PMlse\n';
}
// set memory to load
cmd += '' + (parseInt(action.options.memory)-1) + 'PMmet\n';
// set destination screen
cmd += '' + (parseInt(action.options.destscreen)-1) + 'PMscf\n';
// set preview/program
if (action.options.pvwpgm == '0') {
cmd += '0PMprf\n';
} else {
cmd += '1PMprf\n';
}
// do the load
cmd += '1PMloa'; //last line break is added in sendcmd
break;
case 'loadconfidence':
// set memory to load
cmd = '' + (parseInt(action.options.memory)-1) + ',';
// set destination screen
cmd += '' + (parseInt(action.options.destscreen)-1) + ',1CMloa';
break;
case 'activateconfidence':
// select screen
cmd = '' + (parseInt(action.options.screen)-1) + ',';
// set destination screen
cmd += action.options.mode + 'SCico';
break;
case 'loadmaster':
// set scale
if (action.options.scale == '0') {
cmd = '0PSose\n';
} else {
cmd = '1PSose\n';
}
// set memory to load
cmd += '' + (parseInt(action.options.memory)-1) + ',PSmet\n';
// set preview/program
if (action.options.pvwpgm == '0') {
cmd += '0PSprf\n';
} else {
cmd += '1PSprf\n';
}
// do the load
cmd += '1PSloa'; //last line break is added in sendcmd
break;
case 'loadmonitoring':
// set memory to load
cmd = '' + (parseInt(action.options.memory)-1) + ',';
// set device
if (action.options.device == '1') {
cmd += '1,';
} else {
cmd += '0,';
}
// do the load
cmd += '1MMloa'; //last line break is added in sendcmd
break;
case 'switchplug':
// set input
cmd = '' + (parseInt(action.options.input)-1) + ',';
// set plug
cmd += action.options.plug + 'INplg';
break;
case 'sendcustomcommand':
cmd = action.options.command;
break;
case 'selectscreens':
cmd = '';
for (var option in action.options) {
if (action.options.option == '1') cmd += action.options.option +',1SPscl\n';
else if (action.options.option == '2') cmd += action.options.option +',0SPscl\n';
}
if (cmd == '') return;
else cmd.replace(/\n$/,'');
break;
default:
var optionsort = [];
for (var option in action.options) {
if (action.options.hasOwnProperty(option) && action.options[option] != '') optionsort[option] = action.options[option]; // make an array based on option ids
}
if (optionsort.length > 0) {
cmd = optionsort.join(',') + action.action; // tis works only for set-commands not for query-commands
} else {
cmd = action.action;
}
break;
}
self.sendcmd(cmd);
};
instance.prototype.sendcmd = function(cmd) {
var self = this;
cmd +="\n";
if (cmd !== undefined) {
if (self.socket === undefined) {
self.init_tcp();
}
// TODO: remove this when issue #71 is fixed
if (self.socket !== undefined && self.socket.host != self.config.host) {
self.init_tcp();
}
debug('sending tcp',cmd,"to",self.config.host);
if (self.socket !== undefined && self.socket.connected) {
self.socket.send(cmd);
} else {
debug('Socket not connected :(');
}
}
};
instance.module_info = {
label: 'Analog Way Livecore',
id: 'analogway_livecore',
version: '0.0.1'
};
instance_skel.extendedBy(instance);
exports = module.exports = instance;