X-Git-Url: https://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=tim%2Fprune%2Fload%2FNmeaFileLoader.java;h=76ed15785dc1fff93ec18661790e8c9955539711;hp=090bb6d3a9a0c738b3ad1e71c64e512a9e0a4922;hb=c0387c124840c9407e040600fda88f3c3e8f6aa6;hpb=1ee49ae3c8ef3aa2e63eadd458531e5f8bd4f92c diff --git a/tim/prune/load/NmeaFileLoader.java b/tim/prune/load/NmeaFileLoader.java index 090bb6d..76ed157 100644 --- a/tim/prune/load/NmeaFileLoader.java +++ b/tim/prune/load/NmeaFileLoader.java @@ -36,6 +36,7 @@ public class NmeaFileLoader { BufferedReader reader = null; ArrayList messages = new ArrayList(); + String lastDate = null; try { reader = new BufferedReader(new FileReader(inFile)); @@ -46,17 +47,32 @@ public class NmeaFileLoader // Try to make an NmeaMessage object for each line of file if (currLine.trim().length() > 0) { - NmeaMessage message = processLine(currLine); + NmeaMessage message = processGGA(currLine); if (message != null) { - if (message.hasFix()) { + if (message.hasFix()) + { message.setSegment(newSegment); + message.setDate(lastDate); // add message to list messages.add(message); } // Start a new segment if fix lost newSegment = !message.hasFix(); } + else { + String date = getDateFromRMC(currLine); + if (date != null) + { + if (lastDate == null && !messages.isEmpty()) { + // Backfill first few messages received before the first date + for (int m=0; m= 10) @@ -107,6 +121,27 @@ public class NmeaFileLoader return null; } + /** + * Process the given MRC sentence and return the date + * @param inLine line to process + * @return date, if any + */ + private static String getDateFromRMC(String inLine) + { + // Only consider lines which are long enough and begin with the RMC sentence + if (inLine == null || inLine.length() < 20 || !inLine.startsWith("$GPRMC")) { + return null; + } + // Assume comma delimiter, split into array + String[] splitLine = inLine.split(","); + if (splitLine != null && splitLine.length >= 10) + { + return splitLine[9]; // date in position 9 + } + // Couldn't parse it, return null + return null; + } + /** * Make an object array from the data list * @param inList list of messages