feat: 导入 NMEA-0183 GPS 协议解析库(node-nmea)
NMEA-0183 语句解析器,含 21 个语句类型 codec 与配套单元测试。 - codecs/:APB/BWC/DBT/GGA/GLL/GRMT/GSA/GSV/HDG/HDM/HDT/MWV/RDID/ RMB/RMC/ROT/RSA/TXT/VTG/VWR/ZDA - test/:各 codec 对应的 mocha 用例 - .github/workflows/:node与 npm-publish 流水线 许可证:MIT(原作者 James Penn)
This commit is contained in:
44
codecs/MWV.js
Normal file
44
codecs/MWV.js
Normal file
@@ -0,0 +1,44 @@
|
||||
var helpers = require("../helpers.js")
|
||||
/*
|
||||
=== MWV - Wind Speed and Angle ===
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*******1 2 3 4 5
|
||||
*******| | | | |
|
||||
$--MWV,x.x,a,x.x,a*hh<CR><LF>
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
Field Number:
|
||||
|
||||
1. Wind Angle, 0 to 360 degrees
|
||||
2. Reference, R = Relative, T = True
|
||||
3. Wind Speed
|
||||
4. Wind Speed Units, K/M/N
|
||||
5. Status, A = Data Valid
|
||||
6. Checksum
|
||||
*/
|
||||
exports.TYPE = 'wind';
|
||||
exports.ID = 'MWV';
|
||||
|
||||
exports.decode = function(fields) {
|
||||
return {
|
||||
sentence: exports.ID,
|
||||
type: exports.TYPE,
|
||||
angle: +fields[1],
|
||||
reference: fields[2],
|
||||
speed: +fields[3],
|
||||
units: fields[4],
|
||||
status: fields[5]
|
||||
}
|
||||
}
|
||||
|
||||
exports.encode = function(talker, msg) {
|
||||
var result = ['$' + talker + exports.ID];
|
||||
result.push(helpers.encodeDegrees(msg.angle));
|
||||
result.push(msg.reference);
|
||||
result.push(helpers.encodeFixed(msg.speed, 2));
|
||||
result.push(msg.units);
|
||||
result.push(typeof msg.status === undefined ? 'A' : msg.status);
|
||||
var resultMsg = result.join(',');
|
||||
return resultMsg + helpers.computeChecksum(resultMsg);
|
||||
}
|
||||
Reference in New Issue
Block a user