-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
take into account only GGA packets and export all locations as a single track
- Loading branch information
Showing
6 changed files
with
2,622 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,32 @@ | ||
const makeStream = require('./stream'); | ||
|
||
module.exports = importNmea; | ||
|
||
function importNmea() { | ||
/* global WritableStream */ | ||
|
||
/** | ||
* Parses ASCII stream containing NMEA messages into Furkot's trip | ||
* @param {ReadableStream} from | ||
*/ | ||
async function importNmea(from) { | ||
const stream = makeStream({ GGA: true }); | ||
const track = []; | ||
|
||
await from.pipeThrough(stream).pipeTo(new WritableStream({ | ||
write: packet => track.push(toStop(packet)) | ||
})); | ||
|
||
return { | ||
track: [track] | ||
}; | ||
} | ||
|
||
function toStop({ longitude, latitude, time }) { | ||
return { | ||
coordinates: { | ||
lon: longitude, | ||
lat: latitude | ||
}, | ||
timestamp: time.toISOString() | ||
}; | ||
} |
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,49 @@ | ||
const nmea = require("nmea-simple"); | ||
|
||
module.exports = makeStream; | ||
|
||
/* global TransformStream */ | ||
|
||
function makeStream(types) { | ||
return new TransformStream(makeSource(types)); | ||
} | ||
|
||
function makeSource(types) { | ||
let prefix = ''; | ||
return { | ||
transform, | ||
flush | ||
}; | ||
|
||
/** | ||
* @param {String} chunk | ||
* @param {TransformStreamDefaultController} controller | ||
*/ | ||
function transform(chunk, controller) { | ||
const lines = chunk.split(/[\n\r]+/); | ||
if (prefix) { | ||
lines[0] = prefix + lines[0]; | ||
} | ||
prefix = lines.length > 0 ? lines.pop() : ''; | ||
for (const line of lines) { | ||
processSentence(line, controller); | ||
} | ||
} | ||
|
||
/** | ||
* @param {TransformStreamDefaultController} controller | ||
*/ | ||
function flush(controller) { | ||
processSentence(prefix, controller); | ||
} | ||
|
||
function processSentence(line, controller) { | ||
if (line[0] === '$') { | ||
const packet = nmea.parseNmeaSentence(line); | ||
const { sentenceId } = packet; | ||
if (types[sentenceId]) { | ||
controller.enqueue(packet); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.