@jbroll/nmea-simple
Version:
NMEA 0183 sentence parser and encoder
56 lines (52 loc) • 2.43 kB
text/typescript
// Map talker IDs to system IDs according to uBlox NMEA 4.1 spec
export function getTalkerSystemId(talkerId: string): number {
switch (talkerId) {
case "GP": return 1; // GPS
case "GL": return 2; // GLONASS (primary)
case "GA": return 3; // Galileo
case "GB": return 4; // BeiDou
case "GQ": return 5; // QZSS
// case "GL": return 6; // GLONASS (secondary)
case "GI": return 7; // IRNSS/NavIC
default: return 0; // Unknown/Combined
}
}
// Apply system-specific PRN offset based on uBlox NMEA 4.1 spec
export function adjustPRN(prn: number, systemId: number): number {
switch (systemId) {
case 1: return prn; // GPS: no adjustment needed (1-32)
case 2: // GLONASS (primary): no adjustment needed (65-96)
case 6: return prn; // GLONASS (secondary): no adjustment needed (65-96)
case 3: return prn + 100; // Galileo: add 100 (101-136)
case 4: return prn + 200; // BeiDou: add 200 (201-235)
case 5: return prn; // QZSS: no adjustment needed (193-197)
case 7: return prn + 400; // IRNSS/NavIC: add 400 (401-414)
default: return prn; // Unknown: no adjustment
}
}
// Validate PRN is in correct range for system according to uBlox NMEA 4.1
export function validatePRN(prn: number, systemId: number): boolean {
switch (systemId) {
case 1: return prn >= 1 && prn <= 32; // GPS
case 2: // GLONASS (primary)
case 6: return prn >= 65 && prn <= 96; // GLONASS (secondary)
case 3: return prn >= 101 && prn <= 136; // Galileo
case 4: return prn >= 201 && prn <= 235; // BeiDou
case 5: return prn >= 193 && prn <= 197; // QZSS
case 7: return prn >= 401 && prn <= 414; // IRNSS/NavIC
default: return true; // Unknown: accept any
}
}
// Get the name of the GNSS system for a given system ID
export function getSystemName(systemId: number): string {
switch (systemId) {
case 1: return "GPS";
case 2:
case 6: return "GLONASS";
case 3: return "Galileo";
case 4: return "BeiDou";
case 5: return "QZSS";
case 7: return "IRNSS/NavIC";
default: return "Unknown";
}
}