Skip to content

Commit 71914e6

Browse files
authored
Merge pull request #2 from phillipivan/main
Better status updates
2 parents bf4ce02 + 94a57c3 commit 71914e6

File tree

8 files changed

+125
-75
lines changed

8 files changed

+125
-75
lines changed

Diff for: companion/HELP.md

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
## Peavy RATC Control Protocol
22

3-
This module is for control of Peavy NION DSPs. The RATC v1, v2, and v2 RAW modes are supported. All testing performed against Nion's running firmware 2.0. The selected protocol must match what your DSP is configured to use. RATC v2 is a more powerful protocol offering relative (incremental) changes, multiple change groups, and a keep alive. It should be used preferentially unless RATC v1 is required for compatibility reasons. Similarly RATCv2 offers a better experience than RATCv2 RAW unless control of an arbitraily large number of aliases is required, or the system can't be changed due to other dependencies.
3+
This module is for control of Peavy NION DSPs. The RATC v1, v2, and v2 RAW modes are supported. All testing performed against Nion's running firmware 2.0. The selected protocol version must match what your DSP configuration. RATC v2 is more powerful, offering relative changes, multiple change groups, and a keep alive. It should be used preferentially unless RATC v1 is required for compatibility reasons. Similarly, RATCv2 offers a better experience than RATCv2 RAW unless control of an arbitrarily large number of aliases is required, or the system can't be changed due to other dependencies.
44

5-
This module may work with older Media Matrix units in RATCv1 mode, but this is untested and unsupported.
5+
This module may work with older Media Matrix units in RATCv1 mode, however this is untested and unsupported.
66

77
### Configuration
88

99
**Host**
1010

11-
Enter the hostname or IP address of the DSP
11+
Enter the hostname or IP address of the DSP.
1212

1313
**Port**
1414

15-
This should normally normally remain 1632.
15+
This should normally remain 1632.
1616

1717
**Username / Password**
1818

@@ -26,17 +26,17 @@ Disable to use RATC v1 commands.
2626

2727
### Actions
2828

29-
Most actions require reference to a control alias. The module will auto query and build a drop down list of the control aliases upon connection. You may enter a custom alias if working offline. Refer to Peavy's External Control User Guide for further details.
29+
Most actions require reference to a control alias. The module will auto query and build a drop-down list of the control aliases upon connection. You may enter a custom alias if working offline. Refer to Peavy's External Control User Guide for further details.
3030

3131
All control aliases in use are added to the default change group so they can be polled periodically. If you use a variable without an associated action, you should manually add it to the default control group.
3232

33-
To create a toggle button use the Control Position Invert action (RATCv2 only), and insert the variable for the controls position as its position value.
33+
To create a toggle button, use the Control Position Invert action (RATCv2 only), and insert the variable for the controls position as its position value.
3434

3535
### Variables
3636

3737
The detected control aliases, their values & positions (RATCv2) are returned as variables. Variable names for control aliases containing white space ' ' will be replaced with '_'. Values are kept as strings and retain their units; positions are converted to a number. Note: Returned strings containing whitespace will be truncated at the first whitespace.
3838

39-
Variables are not defined when in RATC v2 RAW mode to preseve system resources. They can still be referenced if you follow the pattern of (yourModuleName:controlAliasValue_rawAlias) or (yourModuleName:controlAliasPosition_rawAlias). However, in the rawAlias the '/' have been substituted with '_'. Ie, $(Nion_N3:controlAliasValue___devices_10_controls_hold_time)
39+
Variables are not defined when in RATC v2 RAW mode to preserve system resources. They can still be referenced if you follow the pattern of (yourModuleName:controlAliasValue_rawAlias) or (yourModuleName:controlAliasPosition_rawAlias). However, in the rawAlias the '/' have been substituted with '_'. I.e., $(Nion_N3:controlAliasValue___devices_10_controls_hold_time)
4040
They will not have a value assigned until used by an action.
4141

4242
### Feedbacks
@@ -45,5 +45,10 @@ No feedbacks are provided. The native Internal Variable Check Value feedback is
4545

4646
## Version History
4747

48+
### Version 1.0.1
49+
- Better status updates
50+
- Minor fixes & typos
51+
- Companion-module-base updated to 1.8.0
52+
4853
### Version 1.0.0
4954
- Initial release

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "peavy-ratc",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"main": "src/main.js",
55
"scripts": {
66
"test": "echo \"Error: no test specified\" && exit 1",
@@ -14,7 +14,7 @@
1414
"url": "git+https://github.com/bitfocus/companion-module-peavy-ratc.git"
1515
},
1616
"dependencies": {
17-
"@companion-module/base": "~1.7.0"
17+
"@companion-module/base": "~1.8.0"
1818
},
1919
"devDependencies": {
2020
"@companion-module/tools": "^1.5.0"

Diff for: src/choices.js

-3
This file was deleted.

Diff for: src/feedbacks.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const { combineRgb } = require('@companion-module/base')
2-
//const {} = require('./consts.js')
32

43
module.exports = async function (self) {
54
self.setFeedbackDefinitions({})

Diff for: src/main.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ const UpdateActions = require('./actions.js')
44
const UpdateFeedbacks = require('./feedbacks.js')
55
const UpdateVariableDefinitions = require('./variables.js')
66
const config = require('./config.js')
7-
//const choices = require('./choices.js')
87
const tcp = require('./tcp.js')
98
const processCmd = require('./processcmd.js')
10-
//const {} = require('./consts.js')
119

1210
class PEAVY_RATC extends InstanceBase {
1311
constructor(internal) {
@@ -21,6 +19,11 @@ class PEAVY_RATC extends InstanceBase {
2119
async init(config) {
2220
this.updateStatus('Starting')
2321
this.config = config
22+
if (this.config.host === undefined || this.config.port === undefined) {
23+
this.log('error', 'Host or port undefined')
24+
this.updateStatus(InstanceStatus.BadConfig)
25+
return undefined
26+
}
2427
this.initVariables()
2528
this.startTimeOut()
2629
this.updateActions() // export actions
@@ -37,7 +40,6 @@ class PEAVY_RATC extends InstanceBase {
3740
this.stopTimeOut()
3841
this.stopActionUpdateTimer()
3942
if (this.socket) {
40-
//this.sendCommand(EndSession) no clear disconnect
4143
this.socket.destroy()
4244
}
4345
this.updateStatus(InstanceStatus.Disconnected)

Diff for: src/processcmd.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { resp, cmd, alert, aliasSep, paramSep, rawAliasIdent } = require('./consts.js')
2+
const { InstanceStatus } = require('@companion-module/base')
23

34
module.exports = {
45
actionUpdate() {
@@ -71,7 +72,7 @@ module.exports = {
7172
}
7273
if (params[params.length -1] == resp.ratcV1.username) {
7374
if (this.config.v2) {
74-
this.updateStatus('error', 'Device in RATCv1 mode')
75+
this.updateStatus(InstanceStatus.BadConfig, 'Device in RATCv1 mode')
7576
this.log('error', `Device in RATCv1 mode`)
7677
return false
7778
} else {
@@ -82,7 +83,7 @@ module.exports = {
8283
case resp.ratcV1.username:
8384
//this.sendCommand(this.config.username) - doing this will get stuck in a loop if user/pass is incorrect.
8485
if (this.config.v2) {
85-
this.updateStatus('error', 'Device in RATCv1 mode')
86+
this.updateStatus(InstanceStatus.BadConfig, 'Device in RATCv1 mode')
8687
this.log('error', `Device in RATCv1 mode`)
8788
}
8889
break
@@ -93,7 +94,7 @@ module.exports = {
9394
this.log('info', `${reply}`)
9495
break
9596
case resp.ratcV1.welcome:
96-
this.updateStatus('ok', 'Logged in')
97+
this.updateStatus(InstanceStatus.Ok, 'Logged in')
9798
this.log('info', `${reply}`)
9899
this.stopTimeOut()
99100
this.startCmdQueue()
@@ -105,7 +106,7 @@ module.exports = {
105106
return true
106107
case resp.ratcV1.overflow:
107108
this.log('error', `${reply}`)
108-
this.updateStatus('error', 'Overflow')
109+
this.updateStatus(InstanceStatus.UnknownError, 'Overflow')
109110
return undefined
110111
case resp.ratcV1.statusIs:
111112
this.log('info', `${reply}`)
@@ -143,14 +144,14 @@ module.exports = {
143144
break
144145
case resp.ratcV1.notRunning:
145146
this.log('error', `${reply}`)
146-
this.updateStatus('error', 'Project not running')
147+
this.updateStatus(InstanceStatus.UnknownError, 'Project not running')
147148
break
148149
case resp.ratcV1.badCommand:
149150
this.log('warn', `${reply}`)
150151
break
151152
case resp.ratcV1.loginFailed:
152153
this.log('error', 'Password is incorrect')
153-
this.updateStatus('error', 'Username / Password is incorrect')
154+
this.updateStatus(InstanceStatus.BadConfig, 'Username / Password is incorrect')
154155
this.stopCmdQueue()
155156
this.stopKeepAlive()
156157
this.startTimeOut()
@@ -190,7 +191,7 @@ module.exports = {
190191
this.setVariableValues(aliasValues)
191192
break
192193
case resp.ratcV2.loggedIn:
193-
this.updateStatus('ok', 'Logged in')
194+
this.updateStatus(InstanceStatus.Ok, 'Logged in')
194195
this.log('info', 'OK: Logged In')
195196
this.stopTimeOut()
196197
this.startCmdQueue()
@@ -203,10 +204,12 @@ module.exports = {
203204
break
204205
case resp.ratcV2.quietModeEnabled:
205206
this.log('warn', `${reply} - Quiet Mode Should be disabled for correct operation of this module`)
207+
this.updateStatus(InstanceStatus.UnknownWarning, 'Quiet Mode Enabled')
206208
this.addCmdtoQueue(cmd.ratcV2.quietModeDisable)
207209
break
208210
case resp.ratcV2.quietModeDisabled:
209211
this.log('info', `Quiet Mode Disabled: ${reply}`)
212+
this.updateStatus(InstanceStatus.Ok, 'Quiet Mode Disabled')
210213
break
211214
case resp.ratcV2.changeGroupControlAdded:
212215
this.log('debug', `${reply}`)
@@ -228,7 +231,7 @@ module.exports = {
228231
break
229232
case resp.ratcV2.overflow:
230233
this.log('error', `${reply}`)
231-
this.updateStatus('error', 'Overflow')
234+
this.updateStatus(InstanceStatus.UnknownError, 'Overflow')
232235
return undefined
233236
case resp.ratcV2.unlistedControl:
234237
this.log('warn', `${reply}`)
@@ -244,11 +247,12 @@ module.exports = {
244247
break
245248
case resp.ratcV2.notLoggedIn:
246249
this.log('error', `${reply}`)
250+
this.updateStatus(InstanceStatus.BadConfig, `${reply}`)
247251
this.sendCommand(cmd.ratcV2.logIn + paramSep + this.config.username + paramSep + this.config.password)
248252
break
249253
case resp.ratcV2.loginFailed:
250254
this.log('error', 'Password is incorrect')
251-
this.updateStatus('error', 'Username / Password is incorrect')
255+
this.updateStatus(InstanceStatus.BadConfig, 'Username / Password is incorrect')
252256
this.stopCmdQueue()
253257
this.stopKeepAlive()
254258
this.startTimeOut()

Diff for: src/tcp.js

+22-9
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,21 @@ module.exports = {
2424
this.log('debug', 'starting cmdTimer')
2525
if (this.cmdTimer) {
2626
clearTimeout(this.cmdTimer)
27-
delete this.cmdTimer
2827
}
29-
clearTimeout(this.cmdTimer)
3028
this.cmdTimer = setTimeout(() => {
3129
this.processCmdQueue()
3230
}, msgDelay)
3331
},
3432

3533
stopCmdQueue() {
3634
this.log('debug', 'stopping cmdTimer')
37-
clearTimeout(this.cmdTimer)
38-
delete this.cmdTimer
35+
if (this.cmdTimer){
36+
clearTimeout(this.cmdTimer)
37+
delete this.cmdTimer
38+
} else {
39+
this.log('debug', 'stopCmdQueue called, but this.cmdTimer does not exist')
40+
}
41+
3942
},
4043

4144
sendCommand(msg) {
@@ -94,8 +97,12 @@ module.exports = {
9497

9598
stopKeepAlive() {
9699
this.log('debug', 'stopping keepAliveTimer')
97-
clearTimeout(this.keepAliveTimer)
98-
delete this.keepAliveTimer
100+
if (this.keepAliveTimer) {
101+
clearTimeout(this.keepAliveTimer)
102+
delete this.keepAliveTimer
103+
} else {
104+
this.log('debug', 'stopKeepAlive called, but this.keepAliveTimer does not exist')
105+
}
99106
},
100107

101108
timeOut() {
@@ -119,8 +126,12 @@ module.exports = {
119126

120127
stopTimeOut() {
121128
this.log('debug', 'stopping timeOutTimer')
122-
clearTimeout(this.timeOutTimer)
123-
delete this.timeOutTimer
129+
if (this.timeOutTimer) {
130+
clearTimeout(this.timeOutTimer)
131+
delete this.timeOutTimer
132+
} else {
133+
this.log('debug', 'stopTimeOut called, but this.timeOutTimer does not exist')
134+
}
124135
},
125136

126137
initTCP() {
@@ -137,21 +148,23 @@ module.exports = {
137148
if (this.config.host) {
138149
this.log('debug', 'Creating New Socket')
139150

140-
this.updateStatus(`Connecting to RATC Host: ${this.config.host}:${this.config.port}`)
151+
this.updateStatus(InstanceStatus.Connecting, `Connecting to Host: ${this.config.host}`)
141152
this.socket = new TCPHelper(this.config.host, this.config.port)
142153

143154
this.socket.on('status_change', (status, message) => {
144155
this.updateStatus(status, message)
145156
})
146157
this.socket.on('error', (err) => {
147158
this.log('error', `Network error: ${err.message}`)
159+
this.updateStatus(InstanceStatus.ConnectionFailure, err.message)
148160
this.stopCmdQueue()
149161
this.stopKeepAlive()
150162
this.startTimeOut()
151163
this.stopActionUpdateTimer()
152164
})
153165
this.socket.on('connect', () => {
154166
this.log('info', `Connected to ${this.config.host}:${this.config.port}`)
167+
this.updateStatus(InstanceStatus.Connecting, `Logging In`)
155168
this.receiveBuffer = ''
156169
this.queryOnConnect()
157170
})

0 commit comments

Comments
 (0)