From 41d0e73380a7e138e0ab3a8e600329703a6a6c61 Mon Sep 17 00:00:00 2001 From: tccyp Date: Thu, 24 Aug 2017 17:21:01 -0700 Subject: [PATCH] V2.0.0.1 Fixed a few issues - Fixed locale issue, solved the crash for non-english country - Changed the java datetime to joda time, so that we can support lower jdk versions --- GNSSLogger/app/app.iml | 15 +-- GNSSLogger/app/src/main/AndroidManifest.xml | 2 + .../location/gps/gnsslogger/PlotFragment.java | 5 +- .../app/src/main/res/values/strings.xml | 2 +- GNSSLogger/pseudorange/build.gradle | 1 + .../lbs/gnss/gps/pseudorange/GpsTime.java | 117 ++++++++---------- 6 files changed, 70 insertions(+), 72 deletions(-) diff --git a/GNSSLogger/app/app.iml b/GNSSLogger/app/app.iml index 10996d5..cd95c6f 100644 --- a/GNSSLogger/app/app.iml +++ b/GNSSLogger/app/app.iml @@ -62,13 +62,6 @@ - - - - - - - @@ -76,6 +69,13 @@ + + + + + + + @@ -127,5 +127,6 @@ + \ No newline at end of file diff --git a/GNSSLogger/app/src/main/AndroidManifest.xml b/GNSSLogger/app/src/main/AndroidManifest.xml index 7e9d59b..689310b 100755 --- a/GNSSLogger/app/src/main/AndroidManifest.xml +++ b/GNSSLogger/app/src/main/AndroidManifest.xml @@ -9,6 +9,8 @@ + + GnssLogger - v2.0.0.0 + v2.0.0.1 Settings Log diff --git a/GNSSLogger/pseudorange/build.gradle b/GNSSLogger/pseudorange/build.gradle index 4b8808f..bb4305e 100644 --- a/GNSSLogger/pseudorange/build.gradle +++ b/GNSSLogger/pseudorange/build.gradle @@ -40,6 +40,7 @@ dependencies { androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) + compile 'joda-time:joda-time:2.9.4' compile 'com.android.support:appcompat-v7:26.+' testCompile 'junit:junit:4.12' compile files('libs/guava-22.0-android.jar') diff --git a/GNSSLogger/pseudorange/src/main/java/com/google/location/lbs/gnss/gps/pseudorange/GpsTime.java b/GNSSLogger/pseudorange/src/main/java/com/google/location/lbs/gnss/gps/pseudorange/GpsTime.java index b265d61..0d88c0e 100644 --- a/GNSSLogger/pseudorange/src/main/java/com/google/location/lbs/gnss/gps/pseudorange/GpsTime.java +++ b/GNSSLogger/pseudorange/src/main/java/com/google/location/lbs/gnss/gps/pseudorange/GpsTime.java @@ -21,10 +21,8 @@ import com.google.common.base.Preconditions; import com.google.common.primitives.Longs; import java.util.Calendar; import java.util.concurrent.TimeUnit; -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.time.Instant; -import java.util.GregorianCalendar; +import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; /** * A simple class to represent time unit used by GPS. @@ -46,27 +44,18 @@ public class GpsTime implements Comparable { TimeUnit.DAYS.toSeconds(GPS_DAYS_SINCE_JAVA_EPOCH); public static final long GPS_UTC_EPOCH_OFFSET_NANOS = TimeUnit.SECONDS.toNanos(GPS_UTC_EPOCH_OFFSET_SECONDS); - private static final ZonedDateTime LEAP_SECOND_DATE_1981 = getZonedDateTimeUTC(1981, 7, 1); - private static final ZonedDateTime LEAP_SECOND_DATE_2012 = getZonedDateTimeUTC(2012, 7, 1); - private static final ZonedDateTime LEAP_SECOND_DATE_2015 = getZonedDateTimeUTC(2015, 7, 1); - private static final ZonedDateTime LEAP_SECOND_DATE_2017 = getZonedDateTimeUTC(2017, 7, 1); - private static final long nanoSecPerSec = TimeUnit.SECONDS.toNanos(7); + private static final DateTimeZone UTC_ZONE = DateTimeZone.UTC; + private static final DateTime LEAP_SECOND_DATE_1981 = + new DateTime(1981, 7, 1, 0, 0, UTC_ZONE); + private static final DateTime LEAP_SECOND_DATE_2012 = + new DateTime(2012, 7, 1, 0, 0, UTC_ZONE); + private static final DateTime LEAP_SECOND_DATE_2015 = + new DateTime(2015, 7, 1, 0, 0, UTC_ZONE); + private static final DateTime LEAP_SECOND_DATE_2017 = + new DateTime(2017, 1, 1, 0, 0, UTC_ZONE); // nanoseconds since GPS epoch (1980/1/6). private long gpsNanos; - private static ZonedDateTime getZonedDateTimeUTC(int year, int month, int day) { - return getZonedDateTimeUTC(year, month, day, 0, 0, 0, 0); - } - - private static ZonedDateTime getZonedDateTimeUTC(int year, int month, int day, - int hour, int minute, int sec, int nanoSec){ - ZoneId zone = ZoneId.of("UTC"); - ZonedDateTime zdt = ZonedDateTime.of(year, month, day, hour, minute, sec, nanoSec, zone); - return zdt; - } - private static long getMillisFromZonedDateTime(ZonedDateTime zdt) { - return zdt.toInstant().toEpochMilli(); - } /** * Constructor for GpsTime. Input values are all in GPS time. * @param year Year @@ -77,27 +66,23 @@ public class GpsTime implements Comparable { * @param second Second from 0 to 59 */ public GpsTime(int year, int month, int day, int hour, int minute, double second) { - ZonedDateTime utcDateTime = getZonedDateTimeUTC(year, month, day, hour, minute, - (int) second, (int) ((second * nanoSecPerSec) % nanoSecPerSec)); - + DateTime utcDateTime = new DateTime(year, month, day, hour, minute, + (int) second, (int) (second * 1000) % 1000, UTC_ZONE); // Since input time is already specify in GPS time, no need to count leap second here. - initGpsNanos(utcDateTime); - + gpsNanos = TimeUnit.MILLISECONDS.toNanos(utcDateTime.getMillis()) + - GPS_UTC_EPOCH_OFFSET_NANOS; } /** * Constructor - * @param zDateTime is created using GPS time values. + * @param dateTime is created using GPS time values. */ - public GpsTime(ZonedDateTime zDateTime) { - initGpsNanos(zDateTime); - } - - public void initGpsNanos(ZonedDateTime zDateTime){ - this.gpsNanos = TimeUnit.MILLISECONDS.toNanos(getMillisFromZonedDateTime(zDateTime)) + public GpsTime(DateTime dateTime) { + gpsNanos = TimeUnit.MILLISECONDS.toNanos(dateTime.getMillis()) - GPS_UTC_EPOCH_OFFSET_NANOS; } + /** * Constructor * @param gpsNanos nanoseconds since GPS epoch. @@ -108,21 +93,20 @@ public class GpsTime implements Comparable { /** * Creates a GPS time using a UTC based date and time. - * @param zDateTime represents the current time in UTC time, must be after 2009 + * @param dateTime represents the current time in UTC time, must be after 2009 */ - public static GpsTime fromUtc(ZonedDateTime zDateTime) { - return new GpsTime(TimeUnit.MILLISECONDS.toNanos(getMillisFromZonedDateTime(zDateTime)) + public static GpsTime fromUtc(DateTime dateTime) { + return new GpsTime( + TimeUnit.MILLISECONDS.toNanos(dateTime.getMillis()) + TimeUnit.SECONDS.toNanos( - GpsTime.getLeapSecond(zDateTime) - GPS_UTC_EPOCH_OFFSET_SECONDS)); + GpsTime.getLeapSecond(dateTime) - GPS_UTC_EPOCH_OFFSET_SECONDS)); } /** * Creates a GPS time based upon the current time. */ public static GpsTime now() { - ZoneId zone = ZoneId.of("UTC"); - ZonedDateTime current = ZonedDateTime.now(zone); - return fromUtc(current); + return fromUtc(DateTime.now(DateTimeZone.UTC)); } /** @@ -147,9 +131,8 @@ public class GpsTime implements Comparable { Preconditions.checkArgument(yumaWeek < 1024); // Estimate the multiplier of current week. - ZoneId zone = ZoneId.of("UTC"); - ZonedDateTime current = ZonedDateTime.now(zone); - GpsTime refTime = new GpsTime(current); + DateTime currentTime = DateTime.now(UTC_ZONE); + GpsTime refTime = new GpsTime(currentTime); Pair refWeekSec = refTime.getGpsWeekSecond(); int weekMultiplier = refWeekSec.first / 1024; @@ -166,7 +149,7 @@ public class GpsTime implements Comparable { * @param time * @return number of leap seconds since GPS epoch. */ - public static int getLeapSecond(ZonedDateTime time) { + public static int getLeapSecond(DateTime time) { if (LEAP_SECOND_DATE_2017.compareTo(time) <= 0) { return 18; } else if (LEAP_SECOND_DATE_2015.compareTo(time) <= 0) { @@ -217,16 +200,26 @@ public class GpsTime implements Comparable { return Pair.create(week, tow23b); } + public long[] getBreakdownEpoch(TimeUnit... units) { + long nanos = this.gpsNanos; + long[] values = new long[units.length]; + for (int idx = 0; idx < units.length; ++idx) { + TimeUnit unit = units[idx]; + long value = unit.convert(nanos, TimeUnit.NANOSECONDS); + values[idx] = value; + nanos -= unit.toNanos(value); + } + return values; + } + /** * @return Day of year in GPS time (GMT time) */ public static int getCurrentDayOfYear() { - ZoneId zone = ZoneId.of("UTC"); - ZonedDateTime current = ZonedDateTime.now(zone); + DateTime current = DateTime.now(DateTimeZone.UTC); // Since current is derived from UTC time, we need to add leap second here. - long gpsTimeMillis = getMillisFromZonedDateTime(current) - + TimeUnit.SECONDS.toMillis(getLeapSecond(current)); - ZonedDateTime gpsCurrent = ZonedDateTime.ofInstant(Instant.ofEpochMilli(gpsTimeMillis), ZoneId.of("UTC")); + long gpsTimeMillis = current.getMillis() + getLeapSecond(current); + DateTime gpsCurrent = new DateTime(gpsTimeMillis, UTC_ZONE); return gpsCurrent.getDayOfYear(); } @@ -262,26 +255,24 @@ public class GpsTime implements Comparable { * @return the GPS time in Calendar. */ public Calendar getTimeInCalendar() { - return GregorianCalendar.from(getGpsDateTime()); + return getGpsDateTime().toGregorianCalendar(); } /** - * @return a ZonedDateTime with leap seconds considered. + * @return a DateTime with leap seconds considered. */ - public ZonedDateTime getUtcDateTime() { - ZonedDateTime gpsDateTime = getGpsDateTime(); - long gpsMillis = getMillisFromZonedDateTime(gpsDateTime) - - TimeUnit.SECONDS.toMillis(getLeapSecond(gpsDateTime)); - return ZonedDateTime.ofInstant(Instant.ofEpochMilli(gpsMillis), ZoneId.of("UTC")); - + public DateTime getUtcDateTime() { + DateTime gpsDateTime = getGpsDateTime(); + return new DateTime( + gpsDateTime.getMillis() - TimeUnit.SECONDS.toMillis(getLeapSecond(gpsDateTime)), UTC_ZONE); } /** - * @return a ZonedDateTime based on the pure GPS time (without considering leap second). + * @return a DateTime based on the pure GPS time (without considering leap second). */ - public ZonedDateTime getGpsDateTime() { - long gpsMillis = TimeUnit.NANOSECONDS.toMillis(gpsNanos + GPS_UTC_EPOCH_OFFSET_NANOS); - return ZonedDateTime.ofInstant(Instant.ofEpochMilli(gpsMillis), ZoneId.of("UTC")); + public DateTime getGpsDateTime() { + return new DateTime(TimeUnit.NANOSECONDS.toMillis(gpsNanos + + GPS_UTC_EPOCH_OFFSET_NANOS), UTC_ZONE); } /** @@ -312,4 +303,4 @@ public class GpsTime implements Comparable { public int hashCode() { return Longs.hashCode(getNanosSinceGpsEpoch()); } -} +} \ No newline at end of file