Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: some ais info is not sent when deltas do not contain all needed values #101

Merged
merged 4 commits into from
Jul 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading