int hoursNow = cal.get(Calendar.HOUR_OF_DAY);
int minsNow = cal.get(Calendar.MINUTE);
int secsNow = cal.get(Calendar.SECOND);
StringUtil su = new StringUtil();
/* AIS seconds - assumes 'current' minute... due network &
* processing delays, it may in fact be the previous minute
* as we're not GPS hardware time synchronised...
*/
int aisSecs = Integer.parseInt(input, 2);
switch (aisSecs) {
case 60:
timestampStr = "Not Available";
break;
case 61:
timestampStr = "EPFS manual";
break;
case 62:
timestampStr = "EPFS DR";
break;
case 63:
timestampStr = "EPFS U/S";
break;
default:
/* Do a simple check to see if it was 'probably' the previous
* minute... if so, correct the display time. NOTE: the PC
* system clock needs to be pretty close to UTC (within 1-2s)
* for this to work - clock synchronisation is needed regularly!
*/
if ((minsNow * 60) + secsNow + CLOCK_JITTER < (minsNow * 60) + aisSecs) {
switch (minsNow) {
case 0:
minsNow = 59;
switch (hoursNow) {
case 0:
hoursNow = 23;
break;
default:
hoursNow -= 1;
}
break;
default:
minsNow -= 1;
}
}
// Set the calendar time to the AIS message received time - in UTC
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),
cal.get(Calendar.DAY_OF_MONTH), hoursNow, minsNow, aisSecs);
//Store this as the last update time
timestamp = cal.getTimeInMillis();
Calendar newCal = Calendar.getInstance();
// Current system time in UTC
newCal.add(
Calendar.MILLISECOND,
-newCal.get(Calendar.DST_OFFSET)
- newCal.get(Calendar.ZONE_OFFSET));
// build a string representation of the message time...
timestampStr = String.valueOf(su.padNumZero(hoursNow, 2))
+ ":" + String.valueOf(su.padNumZero(minsNow, 2))
+ ":" + String.valueOf(su.padNumZero(aisSecs, 2));
}
}