Finally got this to work (mostly).
I edited the signalk seatalk java script index.js file to add a 0x86.js feature. I then created a 0x86.js program in the same directory as the other seatalk java script code as shown below. This code will not work with openplotter version 4 because the pypilot_client is not installed in the /usr/local/bin directory in version 4. Using pypilot turned out to be the easiest way for me to get the current command heading value so I could add or subtract according to the function button I push.
I said this works mostly because I believe there is some basic bug in the seatalk code. When I press the -1 button the first time nothing comes through. On the second push of the button, the command comes through. If I then press -10, the prior -1 command comes through. If I press -10 a second time, then the -10 comes through. In other words, the basic seatalk code seems to be buffering the command and it takes a second push for the first push to be sent through to my code. I can see this when I look at the Signalk server log file for the pigpio so I don't think it is my code. I am using the MacArthur HAT for the interface so I guess it is possible that the HAT is doing the buffering. Unfortunately I do not have any other seatlk devices so I cannot trouble shoot the issue beyond the SignalK log file.
Here is the program code (and I'm sure those with deep java script experience could be somewhat more efficient).
/**
* Copyright 2024 Signal K <info@signalk.org> and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict'
const utils = require('@signalk/nmea0183-utilities')
/*
86 11 XX YY Raymarine Autohelm Wired Remote Control
-1 = 86 11 05 fa
-10 = 86 11 06 f9
+1 = 86 11 07 f8
+10 = 86 11 08 f7
tack port = 86 11 21 de
tack stbd = 86 11 22 dd
*/
module.exports = function (input) {
const { id, sentence, parts, tags } = input
if (parts.length != 4) {
return null
}
var auto = parseInt(parts[1], 16)
var a1 = parseInt(parts[2], 16)
var a2 = parseInt(parts[3], 16)
var pathValues = []
if (auto != 0x11) {
return null
}
var exec = require('child_process').exec
const execSync = require('child_process').execSync
var apheading = execSync('/usr/local/bin/pypilot_client ap.heading_command')
const ahresult = '' + apheading
var end = ahresult.length
end--
var start = -1
start = ahresult.indexOf('=')
if (start > 0) {
start = start + 2
var oldheading = ahresult.substring(start,end)
var newheading = Number(oldheading)
if (a1 == 0x05 && a2 == 0xfa) {
newheading--
}
if (a1 == 0x06 && a2 == 0xf9) {
newheading = newheading -10
}
if (a1 == 0x07 && a2 == 0xf8) {
newheading++
}
if (a1 == 0x08 && a2 == 0xf7) {
newheading = newheading + 10
}
if (a1 == 0x21 && a2 == 0xde) {
newheading = newheading - 110
}
if (a1 == 0x22 && a2 == 0xdd) {
newheading = newheading + 110
}
if (newheading > 359) {
newheading = newheading - 360
}
if (newheading < 0) {
newheading = newheading + 360
}
var nhstring = '/usr/local/bin/pypilot_client ap.heading_command='
nhstring = nhstring + newheading
execSync(nhstring)
}
pathValues.push({
path: 'steering/autopilot/target/headingTrue',
value: utils.transform(utils.float(newheading),'deg', 'rad'),
})
return {
updates: [
{
source: tags.source,
timestamp: tags.timestamp,
values: pathValues,
},
],
}
}