-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from angas/master
- Added ZDA sentence
- Loading branch information
Showing
5 changed files
with
67 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* === ZDA - Time & Date - UTC, day, month, year and local time zone === | ||
* | ||
* ------------------------------------------------------------------------------ | ||
* 1 2 3 4 5 6 7 | ||
* | | | | | | | | ||
* $--ZDA,hhmmss.ss,dd,mm,yyyy,zz,zz*hh<CR><LF> | ||
* ------------------------------------------------------------------------------ | ||
* | ||
* Field Number: | ||
* 1. UTC time (hours, minutes, seconds, may have fractional subsecond) | ||
* 2. Day, 01 to 31 | ||
* 3. Month, 01 to 12 | ||
* 4. Year (4 digits) | ||
* 5. Local zone description, 00 to +- 13 hours | ||
* 6. Local zone minutes description, 00 to 59, apply same sign as local hours | ||
* 7. Checksum | ||
*/ | ||
|
||
import { parseIntSafe, parseTime } from "../helpers"; | ||
|
||
export const sentenceId: "ZDA" = "ZDA"; | ||
export const sentenceName = "UTC, day, month, year, and local time zone"; | ||
|
||
export interface ZDAPacket { | ||
sentenceId: "ZDA"; | ||
sentenceName: string; | ||
talkerId?: string; | ||
datetime: Date; | ||
localZoneHours: number; | ||
localZoneMinutes: number; | ||
} | ||
|
||
export function decodeSentence(fields: string[]): ZDAPacket { | ||
return { | ||
sentenceId: sentenceId, | ||
sentenceName: sentenceName, | ||
datetime: parseTime(fields[1], fields.slice(2, 5).join("")), | ||
localZoneHours: parseIntSafe(fields[5]), | ||
localZoneMinutes: parseIntSafe(fields[6]) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import "should"; | ||
|
||
import { parseNmeaSentence } from "../index"; | ||
|
||
describe("ZDA", (): void => { | ||
it("parser", (): void => { | ||
const packet = parseNmeaSentence("$GPZDA,160012.71,11,03,2004,-1,00*7D"); | ||
packet.should.have.property("sentenceId", "ZDA"); | ||
packet.should.have.property("sentenceName", "UTC, day, month, year, and local time zone"); | ||
packet.should.have.property("datetime", new Date("2004-03-11T16:00:12.710Z")); | ||
packet.should.have.property("localZoneHours", -1); | ||
packet.should.have.property("localZoneMinutes", 0); | ||
}); | ||
}); |