Skip to content

Commit

Permalink
SeaTalk composite data: implementation with session (#156)
Browse files Browse the repository at this point in the history
Fixes #154
  • Loading branch information
raffmont authored and tkurki committed Aug 20, 2019
1 parent 591c6e1 commit ec2e6d9
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 57 deletions.
4 changes: 2 additions & 2 deletions hooks/ALK.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ STALK Raymarine Seatalk1 datagram sentence

const seatalkHooks = require('./seatalk')

module.exports = function(input) {
module.exports = function(input, session) {
const { id, sentence, parts, tags } = input
const key = '0x' + (parts[0]).toUpperCase()
if (typeof seatalkHooks[key] === 'function'){
return seatalkHooks[key](input)
return seatalkHooks[key](input, session)
} else {
return null
}
Expand Down
16 changes: 9 additions & 7 deletions hooks/seatalk/0x50.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
Corresponding NMEA sentences: RMC, GAA, GLL
*/

module.exports = function (input) {
module.exports = function (input, session) {
const { id, sentence, parts, tags } = input

var Z = (parseInt(parts[1],16) & 0xF0) >> 4;
Expand All @@ -35,14 +35,16 @@ module.exports = function (input) {
var s=1;
if ((YYYY & 0x8000)!=0) { s=-1; }
var minutes=(YYYY & 0x7FFF)/100.0
var latitude=s*(XX+minutes/60);

session['latitude']=s*(XX+minutes/60);
var pathValues = []

pathValues.push({
path: 'navigation.position.latitude',
value: utils.float(latitude)
})
if (session.hasOwnProperty('latitude') && session.hasOwnProperty('longitude')) {
pathValues.push({
path: 'navigation.position',
value: { "longitude": utils.float(session['longitude']), "latitude": utils.float(session['latitude']) }
})
}

return {
updates: [
Expand Down
14 changes: 8 additions & 6 deletions hooks/seatalk/0x51.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
Corresponding NMEA sentences: RMC, GAA, GLL
*/

module.exports = function (input) {
module.exports = function (input, session) {
const { id, sentence, parts, tags } = input

var Z = (parseInt(parts[1],16) & 0xF0) >> 4;
Expand All @@ -35,14 +35,16 @@ module.exports = function (input) {
var s=1;
if ((YYYY & 0x8000)==0) { s=-1; }
var minutes=(YYYY & 0x7FFF)/100.0
var longitude=s*(XX+minutes/60);
session['longitude']=s*(XX+minutes/60.0);

var pathValues = []

pathValues.push({
path: 'navigation.position.longitude',
value: utils.float(longitude)
})
if (session.hasOwnProperty('latitude') && session.hasOwnProperty('longitude')) {
pathValues.push({
path: 'navigation.position',
value: { "longitude": utils.float(session['longitude']), "latitude": utils.float(session['latitude']) }
})
}

return {
updates: [
Expand Down
29 changes: 17 additions & 12 deletions hooks/seatalk/0x54.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
6 LSBits of RST = seconds = ST & 0x3F
*/

module.exports = function (input) {
module.exports = function (input, session) {
const { id, sentence, parts, tags } = input

var T = (parseInt(parts[1],16) & 0xF0) >> 4;
Expand All @@ -39,19 +39,24 @@ module.exports = function (input) {
var second=ST & 0x3F
var milliSecond=0

var year=parseInt(tags.timestamp.substr(0,4))
var month=parseInt(tags.timestamp.substr(5,2))-1
var day=parseInt(tags.timestamp.substr(8,2))
session["time"]={ "hour":hour, "minute":minute, "second":second, "milliSecond": milliSecond }

const d = new Date(Date.UTC(year, month, day, hour, minute, second, milliSecond ))
const ts = d.toISOString();
var pathValues = []

throw new Error('Seatalk 0x54 disabled due to incomplete datetime structure')
/*pathValues.push({
path: 'navigation.datetime',
value: ts
})
if (session.hasOwnProperty('date') && session.hasOwnProperty('time')) {

const d = new Date(
Date.UTC(
session["date"].year, session["date"].month, session["date"].day,
session["time"].hour, session["time"].minute, session["time"].second,
session["time"].milliSecond ))
const ts = d.toISOString();

pathValues.push({
path: 'navigation.datetime',
value: ts
})
}
return {
updates: [
{
Expand All @@ -60,5 +65,5 @@ module.exports = function (input) {
values: pathValues
}
]
}*/
}
}
33 changes: 19 additions & 14 deletions hooks/seatalk/0x56.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,36 @@
56 M1 DD YY Date: YY year, M month, DD day in month
*/

module.exports = function (input) {
module.exports = function (input, session) {
const { id, sentence, parts, tags } = input

var M = (parseInt(parts[1],16) & 0xF0) >> 4;
var DD = parseInt(parts[2],16);
var YY = parseInt(parts[3],16);

var year=2000+YY
var month=M-1
var month=M
var day=DD

var hour=parseInt(tags.timestamp.substr(11,2))
var minute=parseInt(tags.timestamp.substr(14,2))
var second=parseInt(tags.timestamp.substr(17,2))
var milliSecond=parseInt(tags.timestamp.substr(20,3))
session["date"]={ "year":year, "month":month, "day":day}

const d = new Date(Date.UTC(year, month, day, hour, minute, second, milliSecond ))
const ts = d.toISOString();
var pathValues = []

throw new Error('Seatalk 0x56 disabled due to incomplete datetime structure')
/*pathValues.push({
path: 'navigation.datetime',
value: ts
})
if (session.hasOwnProperty('date') && session.hasOwnProperty('time')) {

const d = new Date(
Date.UTC(
session["date"].year, session["date"].month-1, session["date"].day,
session["time"].hour, session["time"].minute, session["time"].second,
session["time"].milliSecond ))
const ts = d.toISOString();

pathValues.push({
path: 'navigation.datetime',
value: ts
})
}

return {
updates: [
{
Expand All @@ -55,5 +60,5 @@ module.exports = function (input) {
values: pathValues
}
]
}*/
}
}
30 changes: 14 additions & 16 deletions test/ALK.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,19 @@ describe('ALK', () => {
delta.updates[0].values[0].value.should.be.closeTo(288.9, 0.5)
})

const parser = new Parser()

it('0x50 Latitude converted', () => {
const delta = new Parser().parse(latitude)
delta.updates[0].values.should.contain.an.item.with.property('path', 'navigation.position.latitude')
delta.updates[0].values[0].value.should.be.closeTo(33, 0.5)
const delta = parser.parse(latitude)
})

it('0x51 Longitude converted', () => {
const delta = new Parser().parse(longitude)
delta.updates[0].values.should.contain.an.item.with.property('path', 'navigation.position.longitude')
delta.updates[0].values[0].value.should.be.closeTo(-33, 0.5)
const delta = parser.parse(longitude)

delta.updates[0].values.should.contain.an.item.with.property('path', 'navigation.position')
console.log(delta.updates[0].values[0])
delta.updates[0].values[0].value["latitude"].should.be.closeTo(33, 0.5)
delta.updates[0].values[0].value["longitude"].should.be.closeTo(-33, 0.5)
})

it('0x52 SOG converted', () => {
Expand All @@ -130,19 +133,14 @@ describe('ALK', () => {
})

it('0x54 time disabled', () => {
should.Throw(() => {
new Parser().parse(time)
},
/Seatalk 0x54 disabled due to incomplete datetime structure/
)
const delta = parser.parse(time)
})

it('0x56 time disabled', () => {
should.Throw(() => {
new Parser().parse(date)
},
/Seatalk 0x56 disabled due to incomplete datetime structure/
)
const delta = parser.parse(date)

delta.updates[0].values.should.contain.an.item.with.property('path', 'navigation.datetime')
delta.updates[0].values[0].value.should.equal( '2024-04-04T17:08:34.000Z')
})

it('0x57 satelite info converted', () => {
Expand Down

0 comments on commit ec2e6d9

Please sign in to comment.