Skip to content

Commit

Permalink
fix: some ais info is not sent when deltas do not contain all needed …
Browse files Browse the repository at this point in the history
…values (#101)
  • Loading branch information
sbender9 authored Jul 16, 2024
1 parent 7e38320 commit 9b43cb8
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions conversions/ais.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = (app, plugin) => {
}

var vessel = app.getPath(delta.context)
var mmsi = _.get(vessel, 'mmsi') || findDeltaValue(delta, 'mmsi');
var mmsi = findDeltaValue(vessel, delta, 'mmsi');

if ( !mmsi ) {
return null;
Expand All @@ -83,7 +83,7 @@ module.exports = (app, plugin) => {
return res
} else if ( delta.context.startsWith('atons.') ) {
var vessel = app.getPath(delta.context)
var mmsi = _.get(vessel, 'mmsi') || findDeltaValue(delta, 'mmsi');
var mmsi = findDeltaValue(vessel, delta, 'mmsi');

if ( !mmsi ) {
return
Expand Down Expand Up @@ -217,17 +217,16 @@ module.exports = (app, plugin) => {
}

function generateStatic(vessel, mmsi, delta) {
var name = _.get(vessel, "name") || findDeltaValue(delta, 'name');

var type = _.get(findDeltaValue(delta, "design.aisShipType"), "id")
var callsign = findDeltaValue(delta, "communication.callsignVhf")
var length = _.get(findDeltaValue(delta, 'design.length'), 'overall')
var beam = findDeltaValue(delta, 'design.beam')
var fromCenter = findDeltaValue(delta, 'sensors.ais.fromCenter')
var fromBow = findDeltaValue(delta, 'sensors.ais.fromBow')
var draft = _.get(findDeltaValue(delta, 'design.draft'), 'maximum')
var imo = findDeltaValue(delta, 'registrations.imo')
var dest = findDeltaValue(delta, 'navigation.destination.commonName')
var name = findDeltaValue(vessel, delta, 'name');
var type = _.get(findDeltaValue(vessel, delta, "design.aisShipType"), "id")
var callsign = findDeltaValue(vessel, delta, "communication.callsignVhf")
var length = _.get(findDeltaValue(vessel, delta, 'design.length'), 'overall')
var beam = findDeltaValue(vessel, delta, 'design.beam')
var fromCenter = findDeltaValue(vessel, delta, 'sensors.ais.fromCenter')
var fromBow = findDeltaValue(vessel, delta, 'sensors.ais.fromBow')
var draft = _.get(findDeltaValue(vessel, delta, 'design.draft'), 'maximum')
var imo = findDeltaValue(vessel, delta, 'registrations.imo')
var dest = findDeltaValue(vessel, delta, 'navigation.destination.commonName')
/*
type = _.isUndefined(type) ? 0 : type
callsign = fillASCII(callsign ? callsign : '0', 7)
Expand Down Expand Up @@ -296,14 +295,14 @@ function generateStatic(vessel, mmsi, delta) {
}

function generatePosition(vessel, mmsi, delta) {
var position = findDeltaValue(delta, 'navigation.position')
var position = findDeltaValue(vessel, delta, 'navigation.position')

if ( position && position.latitude && position.longitude ) {
var cog = findDeltaValue(delta, 'navigation.courseOverGroundTrue')
var sog = findDeltaValue(delta, 'navigation.speedOverGround')
var heading = findDeltaValue(delta, 'navigation.headingTrue');
var rot = findDeltaValue(delta, 'navigation.rateOfTurn')
var status = findDeltaValue(delta, 'navigation.state')
var cog = findDeltaValue(vessel, delta, 'navigation.courseOverGroundTrue')
var sog = findDeltaValue(vessel, delta, 'navigation.speedOverGround')
var heading = findDeltaValue(vessel, delta, 'navigation.headingTrue');
var rot = findDeltaValue(vessel, delta, 'navigation.rateOfTurn')
var status = findDeltaValue(vessel, delta, 'navigation.state')

if ( !_.isUndefined(status) ) {
status = navStatusMapping[status]
Expand Down Expand Up @@ -395,15 +394,15 @@ function generatePosition(vessel, mmsi, delta) {
}

function generateAtoN(vessel, mmsi, delta) {
var position = findDeltaValue(delta, 'navigation.position')
var position = findDeltaValue(vessel, delta, 'navigation.position')

if ( position && position.latitude && position.longitude ) {
var name = _.get(vessel, "name") || findDeltaValue(delta, 'name');
var type = _.get(findDeltaValue(delta, "atonType"), "id")
var length = _.get(findDeltaValue(delta, 'design.length'), 'overall')
var beam = findDeltaValue(delta, 'design.beam')
var fromCenter = findDeltaValue(delta, 'sensors.ais.fromCenter')
var fromBow = findDeltaValue(delta, 'sensors.ais.fromBow')
var name = _.get(vessel, "name") || findDeltaValue(vessel, delta, 'name');
var type = _.get(findDeltaValue(vessel, delta, "atonType"), "id")
var length = _.get(findDeltaValue(vessel, delta, 'design.length'), 'overall')
var beam = findDeltaValue(vessel, delta, 'design.beam')
var fromCenter = findDeltaValue(vessel, delta, 'sensors.ais.fromCenter')
var fromBow = findDeltaValue(vessel, delta, 'sensors.ais.fromBow')
var latitude = position.latitude * 10000000;
var longitude = position.longitude * 10000000;

Expand Down Expand Up @@ -516,7 +515,7 @@ function hasAnyKeys(delta, keys) {
return false
}

function findDeltaValue(delta, path) {
function findDeltaValue(vessel, delta, path) {
if ( delta.updates ) {
for ( var i = 0; i < delta.updates.length; i++ ) {
for ( var j = 0; j < delta.updates[i].values.length; j++ ) {
Expand All @@ -533,7 +532,8 @@ function findDeltaValue(delta, path) {
}
}
}
return undefined
let val = _.get(vessel, path)
return val ? val.value: undefined
}

function fillASCII(theString, len)
Expand Down

0 comments on commit 9b43cb8

Please sign in to comment.