extended-nmea
Version:
A TypeScript library for parsing NMEA0183-like sentences with support for custom and proprietary sentences.
59 lines • 2.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.QuerySentence = void 0;
const NmeaSentence_1 = require("./NmeaSentence");
const SentenceType_1 = require("../SentenceType");
class QuerySentence extends NmeaSentence_1.NmeaSentence {
/**
* Create a NMEA0183 sentence from a string.
*
* @param data The line to interpret as an NMEA0183 sentence. Can also be an existing Sentence.
* @param prefix The prefix to use when validating the sentence.
* @param suffix The suffix to use when validating the sentence.
*/
constructor(data, prefix = NmeaSentence_1.NmeaSentence.Prefix, suffix = NmeaSentence_1.NmeaSentence.Suffix) {
super(data, SentenceType_1.SentenceType.Query, prefix, suffix);
}
/**
* The first field in the sentence (usually includes a talker id/sentence id).
*/
get idField() {
return this.fields[0];
}
/**
* The mnemonic being requested by the listener. Usually three characters.
*/
get mnemonic() {
return this.fields[1];
}
/**
* Returns the first two characters in the first field as per NMEA0183 standard.
*/
get talkerId() {
return this.idField.substr(0, 2);
}
/**
* Returns the first third and fourth characters in the first field as per NMEA0183 standard.
*/
get listenerId() {
return this.idField.substr(2, 2);
}
get valid() {
// MAYBE: validate length of mnemonic (3)
return super.valid && this.idField.length === 5 && this.idField[4].toUpperCase() === 'Q';
}
get invalidReason() {
if (!super.valid) {
return super.invalidReason;
}
if (this.idField.length !== 5) {
return `Invalid length of id field: expected 5, got ${this.idField.length}`;
}
if (this.idField[4].toUpperCase() !== 'Q') {
return `Invalid id field: expected Q at position 4, got ${this.idField[4]}`;
}
return null;
}
}
exports.QuerySentence = QuerySentence;
//# sourceMappingURL=QuerySentence.js.map