From 7026c0125888bee60b81ce4c23f1547084e322de Mon Sep 17 00:00:00 2001 From: joabakk Date: Tue, 2 Feb 2021 10:50:02 +0100 Subject: [PATCH] Update seatalk.js --- test/seatalk.js | 164 +++++++++++++++++++++++------------------------- 1 file changed, 79 insertions(+), 85 deletions(-) diff --git a/test/seatalk.js b/test/seatalk.js index b54d2638..4f32f761 100644 --- a/test/seatalk.js +++ b/test/seatalk.js @@ -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) }) @@ -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) + }) + }) })