-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathparamFuncs.js
executable file
·348 lines (305 loc) · 9.24 KB
/
paramFuncs.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
module.exports = {
makeChNames: (r) => {
for (let i = 1; i <= 288; i++) {
r.chNames.push({ id: i, label: `CH${i}` })
}
return r.chNames
},
getParams: (instance, cfg) => {
var rcpNames = require('./rcpNames.json')
rcpNames.chNames = module.exports.makeChNames(rcpNames)
instance.colorCommands = []
let fname = ''
let rcpCmds
const FS = require('fs')
switch (cfg.model) {
case 'CL/QL':
fname = 'CLQL Parameters-1.txt'
break
case 'PM':
fname = 'Rivage Parameters-3.txt'
break
case 'TF':
fname = 'TF Parameters-1.txt'
break
case 'DM3':
fname = 'DM3 Parameters-2.txt'
break
case 'DM7':
fname = 'DM7 Parameters-1.txt'
break
case 'RIO':
fname = 'RIO Parameters-1.txt'
break
case 'TIO':
fname = 'TIO Parameters-1.txt'
break
case 'RSIO':
fname = 'RSio Parameters-1.txt'
}
// Read the DataFile
if (fname !== '') {
let data = FS.readFileSync(`${__dirname}/${fname}`)
rcpCmds = module.exports.parseData(data)
rcpCmds.sort((a, b) => {
// Sort the commands
let acmd = a.Address.slice(a.Address.indexOf('/') + 1)
let bcmd = b.Address.slice(b.Address.indexOf('/') + 1)
return acmd.toLowerCase().localeCompare(bcmd.toLowerCase())
})
rcpCmds.forEach((cmd) => {
let rcpName = cmd.Address.slice(cmd.Address.indexOf('/') + 1) // String after "MIXER:Current/"
if (rcpName.endsWith('Color')) {
instance.colorCommands.push(rcpName)
}
if (cmd.Type == 'integer' && cmd.Max == 1) {
cmd.Type = 'bool'
}
})
}
return rcpCmds
},
parseData: (data) => {
const RCP_PARAM_DEF_FIELDS = [
'Ok',
'Action',
'Index',
'Address',
'X',
'Y',
'Min',
'Max',
'Default',
'Unit',
'Type',
'UI',
'RW',
'Scale',
]
const RCP_METER_DEF_FIELDS = [
'Ok',
'Action',
'Index',
'Address',
'X',
'Y',
'Min',
'Max',
'Default',
'Unit',
'Type',
'UI',
'RW',
'Scale',
'Pickoff',
]
const RCP_PARAM_FIELDS = ['Status', 'Action', 'Address', 'X', 'Y', 'Val', 'TxtVal']
const RCP_DEVINFO_FIELDS = ['Status', 'Action', 'Address', 'Val']
const RCP_SCENE_FIELDS = ['Status', 'Action', 'Address', 'Val', 'ScnStatus']
const RCP_SCNINFO_FIELDS = ['Status', 'Action', 'Address', 'Val', 'TxtVal', 'ScnName', 'ScnComment', 'ScnType']
const RCP_METER_FIELDS = ['Status', 'Action', 'Address', 'Name']
let cmds = []
let line = []
const lines = data.toString().split('\x0A')
for (let i = 0; i < lines.length; i++) {
// I'm not going to even try to explain this next line,
// but it basically pulls out the space-separated values, except for spaces that are inside quotes!
line = lines[i].match(/(?:[^\s"]+|"[^"]*")+/g)
if (line !== null && line.length > 1 && ['OK', 'OKM', 'NOTIFY'].indexOf(line[0].toUpperCase()) !== -1) {
let rcpCommand = {}
let params = RCP_PARAM_DEF_FIELDS
switch (line[1].trim()) {
case 'mtrinfo':
params = RCP_METER_DEF_FIELDS
break
case 'set':
case 'get':
case 'mtrstart':
params = RCP_PARAM_FIELDS
break
case 'devinfo':
case 'devstatus':
case 'scpmode':
params = RCP_DEVINFO_FIELDS
break
case 'sscurrent_ex':
case 'sscurrentt_ex':
case 'ssrecall_ex':
case 'ssrecallt_ex':
case 'ssupdate_ex':
case 'ssupdatet_ex':
case 'event':
params = RCP_SCENE_FIELDS
break
case 'ssinfo_ex':
case 'ssinfot_ex':
params = RCP_SCNINFO_FIELDS
break
case 'mtr':
params = RCP_METER_FIELDS
for (k = 3; k < line.length; k++) {
params.push(k - 3)
}
}
for (var j = 0; j < Math.min(line.length, params.length); j++) {
rcpCommand[params[j]] = line[j].replace(/"/g, '').trim() // Add to rcpCommand object and get rid of any double quotes around the strings
}
cmds.push(rcpCommand)
}
}
return cmds
},
// Create the proper command string to send to the device
fmtCmd: (cmdToFmt) => {
if (cmdToFmt == undefined) return
let cmdName = cmdToFmt.Address
let rcpCmd = module.exports.findRcpCmd(cmdName)
let prefix = cmdToFmt.prefix
let cmdStart = prefix
let options = { X: cmdToFmt.X, Y: cmdToFmt.Y, Val: cmdToFmt.Val }
if (rcpCmd.Index >= 1000 && rcpCmd.Index < 1010) {
cmdStart = prefix == 'set' ? 'ssrecall' : 'sscurrent'
if (rcpCmd.Index == 1001) cmdStart = 'ssupdate' // store command
switch (config.model) {
case 'TF':
case 'DM3':
cmdStart = cmdStart + '_ex'
cmdName = `scene_${options.Y == 0 ? 'a' : 'b'}`
break
case 'CL/QL':
cmdStart = cmdStart + '_ex'
cmdName = 'MIXER:Lib/Scene'
break
case 'PM':
cmdStart = cmdStart + 't_ex'
cmdName = 'MIXER:Lib/Scene'
break
case 'DM7':
cmdStart = cmdStart + 't_ex'
cmdName = `scene_${options.Y == 0 ? 'a' : 'b'}`
}
options.X = ''
options.Y = ''
}
if (rcpCmd.Index >= 1010 && rcpCmd.Index < 2000) {
// RecallInc/Dec
cmdStart = 'event'
options.X = ''
options.Y = ''
}
if (rcpCmd.Index >= 2000) {
// Meters
if (!config.metering) return
cmdStart = 'mtrstart'
cmdName = cmdName.replace('/Meter', '') // Remove "Meter" from the beginning of the command
if (config.model == 'TIO' || config.model == 'RIO' || config.model == 'RSIO') {
cmdName = cmdName.replace(/\/.*Ch/, '/Dev')
}
if (rcpCmd.Pickoff) {
let pickoffs = rcpCmd.Pickoff.split('|')
cmdName += '/' + pickoffs[options.Y] // Add the Pickoff Parameter
}
options.X = config.meterSpeed
options.Y = ''
}
let cmdStr = `${cmdStart} ${cmdName}`
if (prefix == 'set' && rcpCmd.Index < 1010) {
// if it's not "set" then it's a "get" which doesn't have a Value, and RecallInc/Dec don't use a value
if (rcpCmd.Type == 'string') {
options.Val = `"${options.Val}"` // put quotes around the string
}
} else {
options.Val = '' // "get" command, so no Value
}
return `${cmdStr} ${options.X} ${options.Y} ${options.Val}`.trim() // Command string to send to device
},
// Create the proper command string for an action or feedback
parseOptions: async (context, optionsToParse) => {
try {
let parsedOptions = JSON.parse(JSON.stringify(optionsToParse)) // Deep Clone
parsedOptions.X =
optionsToParse.X == undefined ? 0 : parseInt(await context.parseVariablesInString(optionsToParse.X)) - 1
parsedOptions.Y =
optionsToParse.Y == undefined ? 0 : parseInt(await context.parseVariablesInString(optionsToParse.Y)) - 1
if (!Number.isInteger(parsedOptions.X) || !Number.isInteger(parsedOptions.Y)) return // Don't go any further if not Integers for X & Y
parsedOptions.X = Math.max(parsedOptions.X, 0)
parsedOptions.Y = Math.max(parsedOptions.Y, 0)
parsedOptions.Val = await context.parseVariablesInString(optionsToParse.Val)
parsedOptions.Val = parsedOptions.Val === undefined ? '' : parsedOptions.Val
return parsedOptions
} catch (error) {
this.log('error', `\nparseOptions: optionsToParse = ${JSON.stringify(optionsToParse)}`)
this.log('error', `parseOptions: STACK TRACE:\n${error.stack}\n`)
}
},
parseVal: (context, cmd) => {
const hpf = require('./hpf')
let val = cmd.Val
let rcpCmd = module.exports.findRcpCmd(cmd.Address)
if (rcpCmd.Type == 'string' || rcpCmd.Type == 'binary') {
return val
}
if (rcpCmd.Type == 'mtr') {
if (!isNaN(cmd.Val)) {
val = parseInt(cmd.Val) + 126
}
return val
}
if (rcpCmd.Type != 'bool') {
if (isNaN(cmd.Val)) {
if (cmd.Val.toUpperCase() == '-INF') val = rcpCmd.Min
} else {
val = parseInt(parseFloat(cmd.Val || '0') * rcpCmd.Scale)
}
}
if (!module.exports.isRelAction(cmd)) return val //Only continue if it's a relative action
let data = context.getFromDataStore(cmd)
if (data === undefined) return undefined
let curVal = parseInt(data)
if (cmd.Val == 'Toggle') {
val = 1 - curVal
return val
}
if (curVal <= -9000) {
// Handle bottom of range
if (cmd.Val < 0) val = -32768
if (cmd.Val > 0) val = -6000
} else {
if (rcpCmd.Type != 'freq') {
val = curVal + val
} else {
const index = hpf.findIndex((f) => f == curVal)
val = hpf[Math.min(Math.max(index + val / rcpCmd.Scale, 0), hpf.length - 1)]
}
}
val = Math.min(Math.max(val, rcpCmd.Min), rcpCmd.Max) // Clamp it
return val
},
findRcpCmd: (cmdName, cmdAction = '') => {
let rcpCmd = undefined
if (cmdName != undefined) {
if (cmdAction == 'mtr') {
cmdName = cmdName.replace('Current/', 'Current/Meter/')
if (config.model == 'TIO' || config.model == 'RIO') {
cmdName = cmdName.replace('/Dev/OutputLevel', '/OutCh/OutputLevel')
cmdName = cmdName.replace(/\/Dev.*/, config.model == 'TIO' ? '/InCh/InputLevel' : '/InCh')
} else if (config.model == 'RSIO') {
cmdName = cmdName.replace('/Dev', cmdName.includes('InputLevel') ? '/InCh' : '/OutCh')
} else {
let lastSlash = cmdName.lastIndexOf('/')
cmdName = cmdName.slice(0, lastSlash)
}
}
let cmdToFind = cmdName.replace(/:/g, '_')
rcpCmd = rcpCommands.find((cmd) => cmd.Address.replace(/:/g, '_').startsWith(cmdToFind))
}
return rcpCmd
},
isRelAction: (parsedCmd) => {
if (parsedCmd.Val == 'Toggle' || (parsedCmd.Rel != undefined && parsedCmd.Rel == true)) {
// Action that needs the current value from the device
return true
}
return false
},
}