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

feature: add MTA, MWD and VWT sentences #179

Merged
merged 13 commits into from
Oct 24, 2020
Merged
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
- [HSC - Heading Steering Command](https://www.tronico.fi/OH6NT/docs/NMEA0183.pdf)
- KEP - NKE Performance data
- [MDA - Meteorological Composite](https://gpsd.gitlab.io/gpsd/NMEA.html#_mda_meteorilogical_composite)
- [MTA - Mean Temperature of Air](https://www.nmea.org/Assets/100108_nmea_0183_sentences_not_recommended_for_new_designs.pdf)
- [MTW - Mean Temperature of Water](https://gpsd.gitlab.io/gpsd/NMEA.html#_mtw_mean_temperature_of_water)
- [MWD - Wind Speed and Direction](https://lists.nongnu.org/archive/html/gpsd-dev/2012-04/msg00048.html)
- [MWV - Wind Speed and Angle](https://gpsd.gitlab.io/gpsd/NMEA.html#_mwv_wind_speed_and_angle)
- [RMB - Recommended Minimum Navigation Information](https://gpsd.gitlab.io/gpsd/NMEA.html#_rmb_recommended_minimum_navigation_information)
- [RMC - Recommended Minimum Navigation Information](https://gpsd.gitlab.io/gpsd/NMEA.html#_rmc_recommended_minimum_navigation_information)
Expand All @@ -38,6 +40,7 @@
- [VPW - Speed - Measured Parallel to Wind](https://gpsd.gitlab.io/gpsd/NMEA.html#_vpw_speed_measured_parallel_to_wind)
- [VTG - Track Made Good and Ground Speed](https://gpsd.gitlab.io/gpsd/NMEA.html#_vtg_track_made_good_and_ground_speed)
- [VWR - Relative Wind Speed and Angle](https://gpsd.gitlab.io/gpsd/NMEA.html#_vwr_relative_wind_speed_and_angle)
- [VWT - True Wind Angle and Speed](https://lists.nongnu.org/archive/html/gpsd-dev/2012-04/msg00048.html)
- [ZDA - UTC day, month, and year, and local time zone offset](https://gpsd.gitlab.io/gpsd/NMEA.html#_zda_time_amp_date_utc_day_month_year_and_local_time_zone)
- [XTE - Cross-track Error](https://www.tronico.fi/OH6NT/docs/NMEA0183.pdf)
- [ZDA - UTC day, month, and year, and local time zone offset](http://www.trimble.com/oem_receiverhelp/v4.44/en/NMEA-0183messages_ZDA.html)
Expand Down
55 changes: 55 additions & 0 deletions hooks/MTA.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Copyright 2016 Signal K <info@signalk.org> and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict'

const utils = require('@signalk/nmea0183-utilities')

/*
* MTA - Mean Temperature of Air
*
* 0 1 2
* | | |
* $--MTA,x.x,C*hh<CR><LF>
pbfulmar marked this conversation as resolved.
Show resolved Hide resolved
*
* Field Number:
* 0. Degrees
* 1. Unit of Measurement, Celcius
* 2. Checksum
*
*/

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

const delta = {
updates: [
{
source: tags.source,
timestamp: tags.timestamp,
values: [
{
path: 'environment.outside.temperature',
value: utils.transform(utils.float(parts[0]), 'c', 'k')
//returns raw value, no transformation done
}
]
}
],
}

return delta
}
71 changes: 71 additions & 0 deletions hooks/MWD.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
'use strict'

/**
* Copyright 2016 Signal K and Fabian Tollenaar <fabian@signalk.org>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const debug = require('debug')('signalk-parser-nmea0183/MWD')
const utils = require('@signalk/nmea0183-utilities')

/*
* $WIMWD,<0>,<1>,<2>,<3>,<4>,<5>,<6>,<7>*hh
*
* NMEA 0183 standard Wind Direction and Speed, with respect to north.
*
* <0> Wind direction, 0.0 to 359.9 degrees True, to the nearest 0.1 degree
* <1> T = True
* <2> Wind direction, 0.0 to 359.9 degrees Magnetic, to the nearest 0.1 degree
* <3> M = Magnetic
* <4> Wind speed, knots, to the nearest 0.1 knot.
* <5> N = Knots
* <6> Wind speed, meters/second, to the nearest 0.1 m/s.
* <7> M = Meters/second
*/

module.exports = function(input) {
const { id, sentence, parts, tags } = input
var pathValues = []

if(parts[0] != ''){
pbfulmar marked this conversation as resolved.
Show resolved Hide resolved
pathValues.push({
'path': 'environment.wind.directionTrue',
'value': utils.transform(utils.float(parts[0]), 'deg', 'rad')
})
}
if(parts[2] != ''){
pathValues.push({
'path': 'environment.wind.directionMagnetic',
'value': utils.transform(utils.float(parts[2]), 'deg', 'rad')
})
}
if(parts[4] != ''){
pathValues.push({
'path': 'environment.wind.speedTrue',
'value': utils.transform(utils.float(parts[4]), 'knots', 'ms')
})
}

const delta = {
updates: [
{
source: tags.source,
timestamp: tags.timestamp,
values: pathValues
}
],
}

return delta
}
102 changes: 102 additions & 0 deletions hooks/VWT.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
'use strict'

/**
* Copyright 2016 Signal K and Fabian Tollenaar <fabian@signalk.org>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const debug = require('debug')('signalk-parser-nmea0183/VWT')
const utils = require('@signalk/nmea0183-utilities')

/*
* $WIVWT,<0>,<1>,<2>,<3>,<4>,<5>,<6>,<7>*hh
*
* NMEA 0183 True wind angle in relation to the vessel's heading, and true wind
* speed referenced to the water. True wind is the vector sum of the Relative
* (apparent) wind vector and the vessel's velocity vector relative to the water along
* the heading line of the vessel. It represents the wind at the vessel if it were
* stationary relative to the water and heading in the same direction.
*
* <0> Calculated wind angle relative to the vessel, 0 to 180°, left/right of
* vessel heading, to the nearest 0.1 degree
* <1> L = left, or R = right
* <2> Calculated wind speed, knots, to the nearest 0.1 knot
* <3> N = knots
* <4> Wind speed, meters per second, to the nearest 0.1 m/s
* <5> M = meters per second
* <6> Wind speed, km/h, to the nearest km/h
* <7> K = km/h
*/

// $IIVWT,030.,R,10.1,N,05.2,M,018.7,K*75


function convertToWindAngle(angle) {
const numAngle = utils.float(angle) % 360
if (numAngle > 180 && numAngle <= 360) {
return numAngle - 360
}
return numAngle
}

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

if(!parts[0]) {
return null;
}
var angle = convertToWindAngle(parts[0]);


if(!parts[1]) {
return null;
}
switch( parts[1].toUpperCase() ) {
case 'L':
angle = -1 * utils.transform( angle, 'deg', 'rad');
break;
case 'R':
angle = utils.transform( angle, 'deg', 'rad');
break;
default:
return null;
}


if(!parts[2] || parts[3].toUpperCase() !== "N") {
return null;
}
const speed = utils.transform(parts[2], 'knots', 'ms')

const delta = {
updates: [
{
source: tags.source,
timestamp: tags.timestamp,
values: [
{
path: 'environment.wind.speedTrue',
value: speed
},
{
path: 'environment.wind.angleTrueWater',
value: angle
}
]
}
],
}

return delta
}
3 changes: 3 additions & 0 deletions hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ module.exports = {
'PBVE': require('./proprietary/PBVE.js'),
'PNKEP': require('./proprietary/PNKEP.js'),
'MDA': require('./MDA.js'),
'MTA': require('./MTA.js'),
'MTW': require('./MTW.js'),
'MWD': require('./MWD.js'),
'MWV': require('./MWV.js'),
'RMB': require('./RMB.js'),
'RMC': require('./RMC.js'),
Expand All @@ -29,6 +31,7 @@ module.exports = {
'VPW': require('./VPW.js'),
'VTG': require('./VTG.js'),
'VWR': require('./VWR.js'),
'VWT': require('./VWT.js'),
'ZDA': require('./ZDA.js'),
'XTE': require('./XTE.js'),
'BOD': require('./BOD.js'),
Expand Down
32 changes: 32 additions & 0 deletions test/MTA.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright 2016 Signal K and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict'

const Parser = require('../lib')
const chai = require('chai')

chai.Should()
chai.use(require('chai-things'))

describe('MTA', () => {
it('Converts OK using individual parser', () => {
const delta = new Parser().parse('$IIMTA,26.,C*31')

delta.updates[0].values.should.contain.an.item.with.property('path', 'environment.outside.temperature')
delta.updates[0].values[0].value.should.be.closeTo(299.15, 0.005)
})
})
36 changes: 36 additions & 0 deletions test/MWD.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright 2016 Signal K and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict'

const Parser = require('../lib')
const chai = require('chai')
const should = chai.Should()

chai.use(require('chai-things'))

describe('MWD', () => {

it('speed & direction data', () => {
const delta = new Parser().parse('$IIMWD,,,046.,M,10.1,N,05.2,M*0B')

delta.updates[0].values.should.contain.an.item.with.property('path', 'environment.wind.speedTrue')
pbfulmar marked this conversation as resolved.
Show resolved Hide resolved
delta.updates[0].values[1].value.should.be.closeTo(5.19585, 0.00005)
pbfulmar marked this conversation as resolved.
Show resolved Hide resolved
delta.updates[0].values.should.contain.an.item.with.property('path', 'environment.wind.directionMagnetic')
delta.updates[0].values[0].value.should.be.closeTo(0.802851, 0.00005)
})

})
25 changes: 25 additions & 0 deletions test/VWT.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict'

const Parser = require('../lib')
const chai = require('chai')
const should = chai.Should()

chai.use(require('chai-things'))

describe('VWT', () => {
it('True wind converts ok', () => {
const delta = new Parser().parse('$IIVWT,030.,R,10.1,N,05.2,M,018.7,K*75')
//'$IIMWV,074,T,05.85,N,A*2E'
// $IIVWT,030.,R,10.1,N,05.2,M,018.7,K*75
pbfulmar marked this conversation as resolved.
Show resolved Hide resolved

delta.updates[0].values.should.contain.an.item.with.property('path', 'environment.wind.angleTrueWater')
delta.updates[0].values[1].value.should.be.closeTo(0.523599, 0.005)
})


it('Doesn\'t choke on empty sentences', () => {
const delta = new Parser().parse('$IIVWT,,,,*55')
should.equal(delta, null)
})

})