Skip to content

Commit

Permalink
v3.5+ add sequence increment and update dependency version
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Colbix committed Jan 1, 2025
1 parent 612f8a6 commit 0773931
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules/
.yarn/
package-lock.json
yarn.lock
/pkg
Expand Down
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
4 changes: 2 additions & 2 deletions companion/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "aver-ptz",
"shortname": "aver-ptz",
"description": "Control Aver PTZ cameras with VISCA commands over IP",
"version": "1.1.0",
"version": "1.2.0",
"license": "MIT",
"repository": "git+https://github.com/bitfocus/companion-module-aver-ptz.git",
"bugs": "https://github.com/bitfocus/companion-module-aver-ptz/issues",
Expand All @@ -14,7 +14,7 @@
}
],
"runtime": {
"type": "node18",
"type": "node22",
"api": "nodejs-ipc",
"apiVersion": "0.0.0",
"entrypoint": "../main.js"
Expand Down
26 changes: 17 additions & 9 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const UpgradeScripts = require('./upgrades.js')
const UpdateActions = require('./actions.js')
const UpdatePresets = require('./presets.js')

let sequenceNumber = 0 // initialize sequence number

class ModuleInstance extends InstanceBase {
constructor(internal) {
super(internal)
Expand Down Expand Up @@ -40,22 +42,23 @@ class ModuleInstance extends InstanceBase {
}

sendCommand(payload){
let newPayLoad, payLoadType, payloadLength, sequenceNumber, cmdBuff

let newPayLoad, payloadLength, hexSequenceNumber, cmdBuff
let payLoadType = '0100' //value 1 and value 2 for VISCA command

newPayLoad = payload

//add packet header if visca over ip enabled
if(this.config.isviscaoverip){
//value 1 and value 2 for VISCA command
payLoadType = '0100'
//convert payload length to hexadecimal
payloadLength = Number(payload.length).toString(16).padStart(4, "0")
//statically set sequence number for now
sequenceNumber = ''.padStart(8, "0")
newPayLoad = payLoadType + payloadLength + sequenceNumber + payload
//get the sequence number
hexSequenceNumber = sequenceNumber.toString(16).padStart(8, '0');
//increment the sequence number
this.incrementSequenceNumber()
newPayLoad = payLoadType + payloadLength + hexSequenceNumber + payload
}

//node.js encode from string to hex
//node.js encode from string to hexadecimal
cmdBuff = Buffer.from(newPayLoad, 'hex')

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

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

// function to increment the sequence number
incrementSequenceNumber(){
sequenceNumber = (sequenceNumber + 1) >>> 0; // increment, convert to unsigned 32-bit int, wrap around above 0xFFFFFFFF
}

updateActions() {
UpdateActions(this)
}
Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aver-ptz",
"version": "1.1.0",
"version": "1.2.0",
"main": "main.js",
"scripts": {
"format": "prettier -w .",
Expand All @@ -12,10 +12,13 @@
"url": "git+https://github.com/bitfocus/companion-module-aver-ptz.git"
},
"dependencies": {
"@companion-module/base": "~1.5.1"
"@companion-module/base": "^1.11.2"
},
"devDependencies": {
"@companion-module/tools": "^1.4.1"
"@companion-module/tools": "^2.1.1",
"eslint": "^9.17.0",
"prettier": "^3.4.2"
},
"prettier": "@companion-module/tools/.prettierrc.json"
}
"prettier": "@companion-module/tools/.prettierrc.json",
"packageManager": "[email protected]"
}

0 comments on commit 0773931

Please sign in to comment.