feat: 导入 NMEA-0183 GPS 协议解析库(node-nmea)
Some checks failed
Node.js CI / build (10.x) (push) Has been cancelled
Node.js CI / build (12.x) (push) Has been cancelled
Node.js CI / build (14.x) (push) Has been cancelled
Node.js CI / build (15.x) (push) Has been cancelled

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:
hyzl
2026-10-19 09:54:44 +08:00
commit b0a1993169
50 changed files with 1951 additions and 0 deletions

52
codecs/GLL.js Normal file
View File

@@ -0,0 +1,52 @@
var helpers = require("../helpers.js")
/*
=== GLL - Geographic Position - Latitude/Longitude ===
------------------------------------------------------------------------------
1 2 3 4 5 6 7 8
| | | | | | | |
$--GLL,llll.ll,a,yyyyy.yy,a,hhmmss.ss,a,m,*hh<CR><LF>
------------------------------------------------------------------------------
Field Number:
1. Latitude
2. N or S (North or South)
3. Longitude
4. E or W (East or West)
5. Universal Time Coordinated (UTC)
6. Status A - Data Valid, V - Data Invalid
7. FAA mode indicator (NMEA 2.3 and later)
8. Checksum
*/
exports.TYPE = 'geo-position';
exports.ID = 'GLL';
exports.decode = function(fields) {
return {
sentence: exports.ID,
type: 'geo-position',
timestamp: fields[5],
lat: fields[1],
latPole: fields[2],
lon: fields[3],
lonPole: fields[4],
timestamp: fields[5],
status: fields[6] == 'A' ? 'valid' : 'invalid'
};
}
exports.encode = function (talker, msg) {
var result = ['$' + talker + exports.ID];
result.push(helpers.encodeDegrees(msg.lat));
result.push(msg.latPole);
result.push(helpers.encodeDegrees(msg.lon));
result.push(msg.lonPole);
result.push(helpers.encodeTime(msg.timestamp));
result.push('A');
result.push('D');
var resultMsg = result.join(',');
return resultMsg + helpers.computeChecksum(resultMsg);
}