Skip to content

Commit 0773931

Browse files
committed
v3.5+ add sequence increment and update dependency version
This commit will only work for Bitfocus version 3.5 and above due to the runtime update from node 18 to node 22. Added a sequence increment to the packet header. This will allow quicker responses for successive button pushes and conform more with the Visca protocol. Updated the dependency and yarn versions in package.json. Updated the runtime node version to 22 in manifest.json. Added .yarnrc.yml as it was needed for the newer yarn version.
1 parent 612f8a6 commit 0773931

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules/
2+
.yarn/
23
package-lock.json
34
yarn.lock
45
/pkg

.yarnrc.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

companion/manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "aver-ptz",
44
"shortname": "aver-ptz",
55
"description": "Control Aver PTZ cameras with VISCA commands over IP",
6-
"version": "1.1.0",
6+
"version": "1.2.0",
77
"license": "MIT",
88
"repository": "git+https://github.com/bitfocus/companion-module-aver-ptz.git",
99
"bugs": "https://github.com/bitfocus/companion-module-aver-ptz/issues",
@@ -14,7 +14,7 @@
1414
}
1515
],
1616
"runtime": {
17-
"type": "node18",
17+
"type": "node22",
1818
"api": "nodejs-ipc",
1919
"apiVersion": "0.0.0",
2020
"entrypoint": "../main.js"

main.js

+17-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const UpgradeScripts = require('./upgrades.js')
33
const UpdateActions = require('./actions.js')
44
const UpdatePresets = require('./presets.js')
55

6+
let sequenceNumber = 0 // initialize sequence number
7+
68
class ModuleInstance extends InstanceBase {
79
constructor(internal) {
810
super(internal)
@@ -40,22 +42,23 @@ class ModuleInstance extends InstanceBase {
4042
}
4143

4244
sendCommand(payload){
43-
let newPayLoad, payLoadType, payloadLength, sequenceNumber, cmdBuff
44-
45+
let newPayLoad, payloadLength, hexSequenceNumber, cmdBuff
46+
let payLoadType = '0100' //value 1 and value 2 for VISCA command
47+
4548
newPayLoad = payload
4649

4750
//add packet header if visca over ip enabled
4851
if(this.config.isviscaoverip){
49-
//value 1 and value 2 for VISCA command
50-
payLoadType = '0100'
5152
//convert payload length to hexadecimal
5253
payloadLength = Number(payload.length).toString(16).padStart(4, "0")
53-
//statically set sequence number for now
54-
sequenceNumber = ''.padStart(8, "0")
55-
newPayLoad = payLoadType + payloadLength + sequenceNumber + payload
54+
//get the sequence number
55+
hexSequenceNumber = sequenceNumber.toString(16).padStart(8, '0');
56+
//increment the sequence number
57+
this.incrementSequenceNumber()
58+
newPayLoad = payLoadType + payloadLength + hexSequenceNumber + payload
5659
}
5760

58-
//node.js encode from string to hex
61+
//node.js encode from string to hexadecimal
5962
cmdBuff = Buffer.from(newPayLoad, 'hex')
6063

6164
this.log('console', "Send: " + this.separateHex(cmdBuff.toString('hex')))
@@ -113,12 +116,17 @@ class ModuleInstance extends InstanceBase {
113116
]
114117
}
115118

116-
// format hex into grouped pairs for easier reading from console log
119+
// function to format hexadecimal into grouped pairs for easier reading from console log
117120
separateHex(hex) {
118121
const regex = /([A-Fa-f0-9]{2})/g;
119122
return hex.match(regex).join(' ');
120123
}
121124

125+
// function to increment the sequence number
126+
incrementSequenceNumber(){
127+
sequenceNumber = (sequenceNumber + 1) >>> 0; // increment, convert to unsigned 32-bit int, wrap around above 0xFFFFFFFF
128+
}
129+
122130
updateActions() {
123131
UpdateActions(this)
124132
}

package.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aver-ptz",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"main": "main.js",
55
"scripts": {
66
"format": "prettier -w .",
@@ -12,10 +12,13 @@
1212
"url": "git+https://github.com/bitfocus/companion-module-aver-ptz.git"
1313
},
1414
"dependencies": {
15-
"@companion-module/base": "~1.5.1"
15+
"@companion-module/base": "^1.11.2"
1616
},
1717
"devDependencies": {
18-
"@companion-module/tools": "^1.4.1"
18+
"@companion-module/tools": "^2.1.1",
19+
"eslint": "^9.17.0",
20+
"prettier": "^3.4.2"
1921
},
20-
"prettier": "@companion-module/tools/.prettierrc.json"
21-
}
22+
"prettier": "@companion-module/tools/.prettierrc.json",
23+
"packageManager": "[email protected]"
24+
}

0 commit comments

Comments
 (0)