Skip to content

Commit

Permalink
chore: changes for ios/wilhelmsk support
Browse files Browse the repository at this point in the history
  • Loading branch information
sbender9 committed Aug 5, 2023
1 parent d008c4a commit 4bb6528
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
7 changes: 5 additions & 2 deletions ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

const venusToDeltas = require('./venusToDeltas')

var vd = venusToDeltas({}, {usePosition:true})
//var vd = venusToDeltas({}, {usePosition:true})

global.toDelta = vd.toDelta
//global.toDelta = vd.toDelta

global.getToDelta = (putRegistrar) => {
return venusToDeltas({ supportsMetaDeltas: true }, {usePosition:true}, {}, putRegistrar).toDelta
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
"debug": "^3.1.0",
"lodash": "^4.17.4",
"mqtt": "^4.2.6",
"promise-retry": "^1.1.1"
"promise-retry": "^1.1.1",
"webpack-cli": "^5.1.4"
},
"devDependencies": {
"@signalk/github-create-release": "^1.2.1",
"@signalk/signalk-schema": "0.0.1-12",
"chai": "^4.1.2",
"chai-things": "0.2",
"mocha": "^4.0.1",
"webpack": "^4.42.1",
"webpack-cli": "^3.3.11"
"mocha": "^4.0.1"
},
"scripts": {
"test": "mocha",
"create-release": "github-create-release --owner sbender9 --repository signalk-venus-plugin",
"release": "git tag -d v$npm_package_version ; git tag v$npm_package_version && git push --tags && git push && npm run create-release",
"build_ios": "webpack ios.js -o ios_venus.js"
"build_ios": "webpack --mode development ./ios.js -o ios_venus.js",
"build_prod_ios": "webpack --mode production ./ios.js -o ios_venus.js"
},
"keywords": [
"signalk-node-server-plugin"
Expand Down
44 changes: 26 additions & 18 deletions venusToDeltas.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const { isArray, isFunction, isUndefined, values, forIn } = require('lodash')
const _ = require('lodash')

var lastLat, lastLon
var knownPaths = []
var sentModeMeta = false

module.exports = function (app, options, putRegistrar) {
module.exports = function (app, options, state, putRegistrar) {
const debug = app && app.debug ? app.debug.extend('venusToDeltas') : () => {}

state.knownPaths = []
state.sentModeMeta = false

const venusToSignalKMapping = {
'/Dc/0/Voltage': {
Expand Down Expand Up @@ -519,19 +518,19 @@ module.exports = function (app, options, putRegistrar) {
path: 'navigation.position',
requiresInstance: false,
conversion: msg => {
lastLat = msg.value
if (lastLon && (_.isUndefined(options.usePosition) || options.usePosition)) {
return { latitude: msg.value, longitude: lastLon }
state.lastLat = msg.value
if (state.lastLon && (_.isUndefined(options.usePosition) || options.usePosition)) {
return { latitude: msg.value, longitude: state.lastLon }
}
}
},
'/Position/Longitude': {
path: 'navigation.position',
requiresInstance: false,
conversion: msg => {
lastLon = msg.value
if (lastLat && (_.isUndefined(options.usePosition) || options.usePosition)) {
return { latitude: lastLat, longitude: msg.value }
state.lastLon = msg.value
if (state.lastLat && (_.isUndefined(options.usePosition) || options.usePosition)) {
return { latitude: state.lastLat, longitude: msg.value }
}
}
},
Expand Down Expand Up @@ -648,15 +647,15 @@ module.exports = function (app, options, putRegistrar) {

if (!mapping.sendNulls &&
(isUndefined(theValue) || theValue === null) &&
knownPaths.indexOf(thePath) === -1 ) {
state.knownPaths.indexOf(thePath) === -1 ) {
debug('mapping: no value')
return
}

if ( !_.isUndefined(thePath) && !_.isUndefined(theValue) ) {
if ( knownPaths.indexOf(thePath) == -1 )
if ( state.knownPaths.indexOf(thePath) == -1 )
{
knownPaths.push(thePath)
state.knownPaths.push(thePath)
if ( mapping.units && app && app.supportsMetaDeltas ) {
let meta = {updates: [ { meta: [{ path: thePath, value: {units: mapping.units} }] } ]}
deltas.push(meta)
Expand All @@ -670,14 +669,14 @@ module.exports = function (app, options, putRegistrar) {

deltas.push(delta)

if (sentModeMeta === false
if (state.sentModeMeta === false
&& m.senderName.startsWith('com.victronenergy.vebus')
&& m.path === '/Mode'
&& thePath.endsWith('modeNumber')
&& app
&& app.supportsMetaDeltas) {
deltas.push({updates: [ { meta: [{ path: thePath, value: modeMeta }] } ]})
sentModeMeta = true
state.sentModeMeta = true
}
}
}
Expand All @@ -689,7 +688,7 @@ module.exports = function (app, options, putRegistrar) {
}

function getKnownPaths() {
return knownPaths
return state.knownPaths
}

function makePath (msg, path, vebusIsInverterValue) {
Expand All @@ -716,7 +715,7 @@ module.exports = function (app, options, putRegistrar) {
if ( parts.length > 2 ) {
type = parts[2]
} else {
app.debug('no path for %s', msg.senderName)
debug('no path for %s', msg.senderName)
return null
}
}
Expand Down Expand Up @@ -746,6 +745,10 @@ module.exports = function (app, options, putRegistrar) {
function convertErrorToNotification (m, path) {
var value

if ( !app || !app.getSelfPath ) {
return
}

const existing = app.getSelfPath(path)

if (m.value == 0) {
Expand Down Expand Up @@ -780,6 +783,11 @@ module.exports = function (app, options, putRegistrar) {
function convertAlarmToNotification (m, path) {
var value
var message

if ( !app || !app.getSelfPath ) {
return
}

if (_.isString(m.value)) {
message = m.value
} else {
Expand Down

0 comments on commit 4bb6528

Please sign in to comment.