Skip to content

Commit

Permalink
Merge pull request #3 from phillipivan/main
Browse files Browse the repository at this point in the history
better status updates
  • Loading branch information
phillipivan authored May 10, 2024
2 parents 5674e60 + 7fbffc0 commit df855c4
Show file tree
Hide file tree
Showing 7 changed files with 302 additions and 227 deletions.
10 changes: 7 additions & 3 deletions companion/HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ This module will control NTP Audio Routers that support DOT Protocol.

## Configuration
Enter the IP address of the control port of the router controller. The default port is 10005.
In the case of redundant router controllers, enter the secondary controller IP and port, and enable the redundant controllers switch.
When the module is enabled it will try and connect to the Primary, if this fails at anytime it will try and connect to the Secondary, and visa versa. This process typically takes 20 seconds or so, as it relies on the TCP connection going into error before attempting connection to the other controller.
In the case of redundant router controllers, enter the secondary controller IP and port, and enable the redundant controllers' switch.
When the module is enabled, it will try and connect to the Primary, if this fails it will try and connect to the Secondary, and visa-versa. This process typically takes 20 seconds or so, as it relies on the TCP connection going into error before attempting connection to the other controller.

Configure the Source and Destination count, this should be equal to highest index number used for each. The system will limit values entered to the specified range. Refer to the VMC-Config app, Configure>Logical Lines to identify Index values.

The alarms should match the number of configured alarm indexs in your system. Refer to VMC-Config, Configure>Messages. You can edit each entry and check/set the Number field to set the Alarm index.
The alarms should match the number of configured alarm indexes in your system. Refer to VMC-Config, Configure>Messages. You can edit each entry and check/set the Number field to set the Alarm index.

## Actions

Expand All @@ -30,6 +30,10 @@ The alarms should match the number of configured alarm indexs in your system. Re

## Version History

### Version 1.0.3
- Better status updates
- Update dependencies

### Version 1.0.2
- Minor TCP improvements & fixes

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ntp-technology-dot",
"version": "1.0.2",
"version": "1.0.3",
"main": "src/main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
Expand All @@ -14,10 +14,10 @@
"url": "git+https://github.com/bitfocus/companion-module-ntp-technology-dot.git"
},
"dependencies": {
"@companion-module/base": "~1.7.0"
"@companion-module/base": "~1.8.0"
},
"devDependencies": {
"@companion-module/tools": "^1.4.2"
"@companion-module/tools": "^1.5.0"
},
"prettier": "@companion-module/tools/.prettierrc.json"
}
11 changes: 10 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
const { Regex } = require('@companion-module/base')
const { Regex, InstanceStatus } = require('@companion-module/base')

module.exports = {
async configUpdated(config) {
this.config = config
if (this.config.redundant) {
if (this.config.hostSec == '' || this.config.portSec == '') {
this.log('error', 'Secondary host / port not defined')
this.updateStatus(InstanceStatus.BadConfig, 'Secondary not defined')
return undefined
}
}
this.useSecondary = false
this.initTCP()
this.initVariables()
Expand All @@ -19,6 +26,7 @@ module.exports = {
type: 'textinput',
id: 'hostPri',
label: 'Primary Host',
default: '',
width: 8,
regex: Regex.HOSTNAME,
required: true,
Expand All @@ -38,6 +46,7 @@ module.exports = {
type: 'textinput',
id: 'hostSec',
label: 'Secondary Host',
default: '',
width: 8,
regex: Regex.HOSTNAME,
},
Expand Down
21 changes: 16 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ class NTP_DOT_PROTOCOL extends InstanceBase {
Object.assign(this, { ...config, ...tcp, ...processCmd, ...choices })
}
async init(config) {
this.updateStatus('Starting')
this.updateStatus(InstanceStatus.Connecting)
this.config = config
if (this.config.redundant) {
if (this.config.hostSec == '' || this.config.portSec == '') {
this.log('error', 'Secondary host / port not defined')
this.updateStatus(InstanceStatus.BadConfig, 'Secondary not defined')
return undefined
}
}
this.keepAliveTimer = {}
this.useSecondary = false
this.cmdTimer = setTimeout(() => {
Expand All @@ -33,10 +40,14 @@ class NTP_DOT_PROTOCOL extends InstanceBase {
// When module gets deleted
async destroy() {
this.log('debug', `destroy. ID: ${this.id}`)
clearTimeout(this.keepAliveTimer)
clearTimeout(this.cmdTimer)
delete this.keepAliveTimer
delete this.cmdTimer
if (this.keepAliveTimer) {
clearTimeout(this.keepAliveTimer)
delete this.keepAliveTimer
}
if (this.cmdTimer) {
clearTimeout(this.cmdTimer)
delete this.cmdTimer
}
if (this.socket) {
this.sendCommand(EndSession)
this.socket.destroy()
Expand Down
1 change: 0 additions & 1 deletion src/processcmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module.exports = {
let alarmIndex = dst
let alarmState = src
let alarmText = params[2] === undefined ? '' : params[2].toString()
//this.log('debug', `control ${ctrl} tag ${tag} param 1 ${params[0]} param 2 ${params[1]} address ${address}`)
switch (ctrl) {
case control.ackSet:
switch (tag) {
Expand Down
7 changes: 5 additions & 2 deletions src/tcp.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,18 @@ module.exports = {
if (this.config.hostPri && this.config.portPri) {
this.log('debug', 'Creating New Socket')
if (this.useSecondary && this.config.hostSec && this.config.portSec) {
this.updateStatus('Connecting to Secondary')
this.updateStatus(InstanceStatus.Connecting, 'Connecting to Secondary')
this.socket = new TCPHelper(this.config.hostSec, this.config.portSec)
} else {
this.updateStatus('Connecting to Primary')
this.updateStatus(InstanceStatus.Connecting, 'Connecting to Primary')
this.socket = new TCPHelper(this.config.hostPri, this.config.portPri)
}
this.socket.on('status_change', (status, message) => {
this.updateStatus(status, message)
})
this.socket.on('error', (err) => {
this.log('error', `Network error: ${err.message}`)
this.updateStatus(InstanceStatus.ConnectionFailure, err.message)
this.clearToTx = true
clearTimeout(this.keepAliveTimer)
if (this.config.redundant) {
Expand All @@ -95,8 +96,10 @@ module.exports = {
this.socket.on('connect', () => {
if (this.useSecondary && this.config.hostSec) {
this.log('info', `Connected on Secondary ${this.config.hostSec}:${this.config.portSec}`)
this.updateStatus(InstanceStatus.Ok, `Connected to Secondary`)
} else {
this.log('info', `Connected on Primary ${this.config.hostPri}:${this.config.portPri}`)
this.updateStatus(InstanceStatus.Ok, `Connected to Primary`)
}
this.clearToTx = true
this.receiveBuffer = ''
Expand Down
Loading

0 comments on commit df855c4

Please sign in to comment.