Skip to content

Commit

Permalink
Update seatalk.js
Browse files Browse the repository at this point in the history
  • Loading branch information
joabakk committed Feb 2, 2021
1 parent c5c8ec2 commit 7026c01
Showing 1 changed file with 79 additions and 85 deletions.
164 changes: 79 additions & 85 deletions test/seatalk.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,11 @@ describe('seatalk', () => {
it(`${prefix} 0x50 Latitude and 0x51 Longitude converted`, () => {
var fullSentence = utils.appendChecksum(`${prefix}${latitudeData}`)
var delta = parser.parse(fullSentence)
console.log(delta.values)
delta.updates[0].values.should.contain.an.item.with.property('path', 'navigation.position')
delta.updates[0].values[0].value["latitude"].should.be.closeTo(33, 0.5)

fullSentence = utils.appendChecksum(`${prefix}${longitudeData}`)
delta = parser.parse(fullSentence)
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)
})

Expand All @@ -152,98 +149,95 @@ describe('seatalk', () => {

it(`${prefix} 0x54 time disabled`, () => {
const fullSentence = timeTag + utils.appendChecksum(`${prefix}${timeData}`)
should.Throw(() => {
new Parser().parse(fullSentence)
},
/Seatalk 0x54 disabled due to incomplete datetime structure/
)
})
const delta = parser.parse(fullSentence)
})

it(`${prefix} 0x56 time disabled`, () => {
const fullSentence = dateTag + utils.appendChecksum(`${prefix}${dateData}`)
should.Throw(() => {
new Parser().parse(fullSentence)
},
/Seatalk 0x56 disabled due to incomplete datetime structure/
)
})
it(`${prefix} 0x56 date disabled`, () => {
const fullSentence = dateTag + utils.appendChecksum(`${prefix}${dateData}`)
const delta = parser.parse(fullSentence)

it(`${prefix} 0x57 satelite info converted`, () => {
const fullSentence = utils.appendChecksum(`${prefix}${satInfoData}`)
const delta = new Parser().parse(fullSentence)
delta.updates[0].values.should.contain.an.item.with.property('path', 'navigation.gnss.satellites')
delta.updates[0].values[0].value.should.equal(7)
})
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(`${prefix} 0x84 heading converted`, () => {
const fullSentence = utils.appendChecksum(`${prefix}${headingData}`)
const delta = new Parser().parse(fullSentence)
delta.updates[0].values.should.contain.an.item.with.property('path', 'navigation.headingMagnetic')
delta.updates[0].values[0].value.should.be.closeTo(5.305800926062761, 0.0005)
})

it(`${prefix} 0x84 ap mode: standby converted`, () => {
const fullSentence = utils.appendChecksum(`${prefix}${standbyData}`)
const delta = new Parser().parse(fullSentence)
delta.updates[0].values.should.contain.an.item.with.property('path', 'steering.autopilot.state')
delta.updates[0].values[1].value.should.equal('standby')
})

it(`${prefix} 0x84 ap mode: auto converted`, () => {
const fullSentence = utils.appendChecksum(`${prefix}${autoData}`)
const delta = new Parser().parse(fullSentence)
delta.updates[0].values.should.contain.an.item.with.property('path', 'steering.autopilot.target.headingMagnetic')
delta.updates[0].values[1].value.should.be.closeTo(2.626720524251466, 0.0005)
it(`${prefix} 0x57 satelite info converted`, () => {
const fullSentence = utils.appendChecksum(`${prefix}${satInfoData}`)
const delta = new Parser().parse(fullSentence)
delta.updates[0].values.should.contain.an.item.with.property('path', 'navigation.gnss.satellites')
delta.updates[0].values[0].value.should.equal(7)
})

delta.updates[0].values.should.contain.an.item.with.property('path', 'steering.autopilot.state')
delta.updates[0].values[2].value.should.equal('auto')
})
it(`${prefix} 0x84 heading converted`, () => {
const fullSentence = utils.appendChecksum(`${prefix}${headingData}`)
const delta = new Parser().parse(fullSentence)
delta.updates[0].values.should.contain.an.item.with.property('path', 'navigation.headingMagnetic')
delta.updates[0].values[0].value.should.be.closeTo(5.305800926062761, 0.0005)
})

it(`${prefix} 0x84 ap mode: wind converted`, () => {
const fullSentence = utils.appendChecksum(`${prefix}${windData}`)
const delta = new Parser().parse(fullSentence)
delta.updates[0].values.should.contain.an.item.with.property('path', 'steering.autopilot.state')
delta.updates[0].values[0].value.should.equal('wind')
})
it(`${prefix} 0x84 ap mode: standby converted`, () => {
const fullSentence = utils.appendChecksum(`${prefix}${standbyData}`)
const delta = new Parser().parse(fullSentence)
delta.updates[0].values.should.contain.an.item.with.property('path', 'steering.autopilot.state')
delta.updates[0].values[1].value.should.equal('standby')
})

it(`${prefix} 0x84 ap mode: route converted`, () => {
const fullSentence = utils.appendChecksum(`${prefix}${routeData}`)
const delta = new Parser().parse(fullSentence)
delta.updates[0].values.should.contain.an.item.with.property('path', 'steering.autopilot.state')
delta.updates[0].values[0].value.should.equal('route')
})
it(`${prefix} 0x84 ap mode: auto converted`, () => {
const fullSentence = utils.appendChecksum(`${prefix}${autoData}`)
const delta = new Parser().parse(fullSentence)
delta.updates[0].values.should.contain.an.item.with.property('path', 'steering.autopilot.target.headingMagnetic')
delta.updates[0].values[1].value.should.be.closeTo(2.626720524251466, 0.0005)

it(`${prefix} 0x84 rudder angle converted`, () => {
const fullSentence = utils.appendChecksum(`${prefix}${rudderData}`)
const delta = new Parser().parse(fullSentence)
delta.updates[0].values.should.contain.an.item.with.property('path', 'steering.rudderAngle')
delta.updates[0].values[0].value.should.be.closeTo(-0.03490658503988659, 0.0005)
})
delta.updates[0].values.should.contain.an.item.with.property('path', 'steering.autopilot.state')
delta.updates[0].values[2].value.should.equal('auto')
})

it(`${prefix} 0x99 compass variation converted`, () => {
const fullSentence = utils.appendChecksum(`${prefix}${compassVariationData}`)
const delta = new Parser().parse(fullSentence)
delta.updates[0].values.should.contain.an.item.with.property('path', 'navigation.magneticVariation')
delta.updates[0].values[0].value.should.be.closeTo(1.0646508439596323, 0.0005)
})
it(`${prefix} 0x84 ap mode: wind converted`, () => {
const fullSentence = utils.appendChecksum(`${prefix}${windData}`)
const delta = new Parser().parse(fullSentence)
delta.updates[0].values.should.contain.an.item.with.property('path', 'steering.autopilot.state')
delta.updates[0].values[0].value.should.equal('wind')
})

it(`${prefix} 0x9C ap target heading converted`, () => {
const fullSentence = utils.appendChecksum(`${prefix}${heading_nineCData}`)
const delta = new Parser().parse(fullSentence)
delta.updates[0].values.should.contain.an.item.with.property('path', 'navigation.headingMagnetic')
delta.updates[0].values[0].value.should.be.closeTo(2.6529004630313806, 0.0005)
})
it(`${prefix} 0x84 ap mode: route converted`, () => {
const fullSentence = utils.appendChecksum(`${prefix}${routeData}`)
const delta = new Parser().parse(fullSentence)
delta.updates[0].values.should.contain.an.item.with.property('path', 'steering.autopilot.state')
delta.updates[0].values[0].value.should.equal('route')
})

it(`${prefix} Doesn\'t choke on empty 0x9C sentences`, () => {
const fullSentence = utils.appendChecksum(`${prefix}${empty_nineCData}`)
const delta = new Parser().parse(fullSentence)
should.equal(delta, null)
})
it(`${prefix} 0x84 rudder angle converted`, () => {
const fullSentence = utils.appendChecksum(`${prefix}${rudderData}`)
const delta = new Parser().parse(fullSentence)
delta.updates[0].values.should.contain.an.item.with.property('path', 'steering.rudderAngle')
delta.updates[0].values[0].value.should.be.closeTo(-0.03490658503988659, 0.0005)
})

it(`${prefix} Doesn\'t choke on empty 0x84 sentences`, () => {
const fullSentence = utils.appendChecksum(`${prefix}${empty_eightFourData}`)
const delta = new Parser().parse(fullSentence)
should.equal(delta, null)
})
})
it(`${prefix} 0x99 compass variation converted`, () => {
const fullSentence = utils.appendChecksum(`${prefix}${compassVariationData}`)
const delta = new Parser().parse(fullSentence)
delta.updates[0].values.should.contain.an.item.with.property('path', 'navigation.magneticVariation')
delta.updates[0].values[0].value.should.be.closeTo(1.0646508439596323, 0.0005)
})

it(`${prefix} 0x9C ap target heading converted`, () => {
const fullSentence = utils.appendChecksum(`${prefix}${heading_nineCData}`)
const delta = new Parser().parse(fullSentence)
delta.updates[0].values.should.contain.an.item.with.property('path', 'navigation.headingMagnetic')
delta.updates[0].values[0].value.should.be.closeTo(2.6529004630313806, 0.0005)
})

it(`${prefix} Doesn\'t choke on empty 0x9C sentences`, () => {
const fullSentence = utils.appendChecksum(`${prefix}${empty_nineCData}`)
const delta = new Parser().parse(fullSentence)
should.equal(delta, null)
})

it(`${prefix} Doesn\'t choke on empty 0x84 sentences`, () => {
const fullSentence = utils.appendChecksum(`${prefix}${empty_eightFourData}`)
const delta = new Parser().parse(fullSentence)
should.equal(delta, null)
})
})
})

0 comments on commit 7026c01

Please sign in to comment.