Skip to content

Commit

Permalink
adding new codes
Browse files Browse the repository at this point in the history
  • Loading branch information
tonybentley committed Jun 15, 2014
1 parent 2b034e5 commit b2b1e33
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
43 changes: 43 additions & 0 deletions lib/codes/HDG.js
@@ -0,0 +1,43 @@
var Helper = require("../Helper.js");

/*
=== HDG - Heading, Deviation and Variation ===
------------------------------------------------------------------------------
******* 1 2 3 4 5 6
******* | | | | | |
$--HDG,x.x,x.x,x,x*hh<CR><LF>
------------------------------------------------------------------------------
Field Number:
1. Magnetic sensor heading, degrees, to the nearest 0.1 degree.
2. Magnetic deviation, degrees east or west, to the nearest 0.1 degree.
3. E if field 2 is degrees East W if field 2 is degrees West
4. Magnetic variation, degrees east or west, to the nearest 0.1 degree.
5. E if field 4 is degrees East W if field 4 is degrees West
6. Checksum
*/

exports.Decoder = function (id) {
this.id = id;
this.talker_type_id = "HDG";
this.talker_type_desc = "Heading, Deviation and Variation";

this.parse = function (tokens) {
if (tokens.length < 6) {
throw new Error('DBT : not enough tokens');
}
return {
id: tokens[0].substr(1),
talker_type_id: this.talker_type_id,
talker_type_desc: this.talker_type_desc,
heading: Helper.parseFloatX(tokens[1]),
deviation: Helper.parseFloatX(tokens[2]),
deviation_direction: tokens[3],
variation: Helper.parseFloatX(tokens[4]),
variation_direction: tokens[5]
}
};
};
52 changes: 52 additions & 0 deletions lib/codes/VHW.js
@@ -0,0 +1,52 @@

var Helper = require("../Helper.js");

/*
=== VHW – Water Speed and Heading ===
The compass heading to which the vessel is currently pointing, and the speed of the vessel through the water.
------------------------------------------------------------------------------
*******1 2 3 4 5 6 7
*******| | | | | | |
$--VHW,x.x,M,x.x,T,x.x,x.x*hh<CR><LF>
------------------------------------------------------------------------------
Field Number:
1. Heading degrees true
2. M = magnetic, T = true
3. Heading degrees magnetic
4. M = magnetic, T = true
5. Speed, Knots
6. Speed KMH
7. checksum
*/

exports.Decoder = function (id) {
this.id = id;
this.talker_type_id = "VHW";
this.talker_type_desc = "Water, Speed and Heading";
this._reference = function(char){
switch(char){
case "T" : return "true"
case "M" : return "magnetic"
}
};

this.parse = function (tokens) {
if (tokens.length < 7) {
throw new Error('VHW : not enough tokens');
}

return {
id: tokens[0].substr(1),
talker_type_id: this.talker_type_id,
talker_type_desc: this.talker_type_desc,
heading1: Helper.parseFloatX(tokens[1]),
reference1:this._reference(tokens[2]),
heading2: Helper.parseFloatX(tokens[3]),
reference2:this._reference(tokens[4]),
speed_knots: Helper.parseFloatX(tokens[5]),
speek_kph: Helper.parseFloatX(tokens[6])
}
};
};

0 comments on commit b2b1e33

Please sign in to comment.