@@ -570,18 +570,19 @@ public String createBufferNoCRC(boolean allCharsToLowerCase, boolean forStorage)
570570 if (this .sendMyTime ) {
571571 //Time data to be sent must be generated just before sending the message to minimise Tx timing errors as messages
572572 // can stay in the Tx queue for a while (multiple messages, busy with a message reception, etc...)
573- Long myTime = System .currentTimeMillis () / 1000 ; //UTC time by definition
574- myTime = myTime - ((Long ) (myTime / 1000000L ) * 1000000L ); //Keep the last 6 digits representing seconds
573+ Long myTime = System .currentTimeMillis () / 1000 ; //UTC time in seconds by definition
574+ //Changed from last 6 digits of epoch to full epoch value to allow clocks to be widely off (anywhere between 1970 to 2038 at minimum)
575+ //myTime = myTime - ((Long) (myTime / 1000000L) * 1000000L); //Keep the last 6 digits representing seconds
575576 //int TxDelay = 0;
576577 //String TxDelayStr = Main.configuration.getPreference("TXDELAY", "0");
577578 //int dcdSecs = Integer.parseInt(Main.configuration.getPreference("DCD", "0"));
578579 //if (TxDelayStr.length() > 0) {
579580 // TxDelay = Integer.parseInt(TxDelayStr);
580581 //}
581582 myTime += (3 ); //DCD and TxDelay not used for RadioMsg
582- String myTimeStr = ("0000000" + myTime .toString ());
583- myTimeStr = myTimeStr .substring (myTimeStr .length () - 6 );
584- txBuffer += "tim:" + myTimeStr + "\n " ;
583+ // String myTimeStr = ("0000000" + myTime.toString());
584+ // myTimeStr = myTimeStr.substring(myTimeStr.length() - 6);
585+ txBuffer += "tim:" + myTime + "\n " ;
585586 }
586587 if (allCharsToLowerCase ) {
587588 txBuffer = txBuffer .toLowerCase (Locale .US );
@@ -759,10 +760,12 @@ public static RMsgObject extractMsgObjectFromString(String dataString, boolean w
759760 mMessage .picture = Bitmap .decodeFile (filePath + pictureFn );
760761 }
761762 } else if (group1 .equals ("tim" )) {
762- //We have a time synchronisation data, store it
763- if (group2 .length () == 6 ) { //6 digits?
763+ //We have a time synchronisation data, store it.
764+ //Now allows for full epoch value to be sent
765+ if (group2 .length () >= 1 ) { //at least one digit
766+ //All digits and nothing else?
764767 boolean formatOk = true ;
765- for (int i = 0 ; i < 6 ; i ++) {
768+ for (int i = 0 ; i < group2 . length () ; i ++) {
766769 if (group2 .charAt (i ) < '0' || group2 .charAt (i ) > '9' ) {
767770 formatOk = false ;
768771 break ; //end of exercise
@@ -773,16 +776,21 @@ public static RMsgObject extractMsgObjectFromString(String dataString, boolean w
773776 if (Main .lastRsidTime > 0L ) {
774777 //We have a recent RSID received time, store the delta time and
775778 // the provisional time server call sign for later processing
776- Long timeRef = Long .parseLong (group2 );
777- Long timeHere = Main .lastRsidTime / 1000 - ((Long ) (Main .lastRsidTime / 1000000000L ) * 1000000L ); //Keep the last 6 digits representing seconds
778- Long deltaTime = timeRef - timeHere ;
779- //Wrap around if we passed a 100000 seconds threshold
780- if (Math .abs (deltaTime ) > 99998L ) {
781- deltaTime = deltaTime < 0L ? deltaTime + 1000000L : deltaTime - 1000000L ;
779+ try {
780+ Long timeRef = Long .parseLong (group2 );
781+ //Long timeHere = Main.lastRsidTime / 1000 - ((Long) (Main.lastRsidTime / 1000000000L) * 1000000L); //Keep the last 6 digits representing seconds
782+ //Long deltaTime = timeRef - timeHere;
783+ Long deltaTime = timeRef - Main .lastRsidTime / 1000 ;
784+ //Wrap around if we passed a 100000 seconds threshold
785+ //if (Math.abs(deltaTime) > 99998L) {
786+ // deltaTime = deltaTime < 0L ? deltaTime + 1000000L : deltaTime - 1000000L;
787+ //}
788+ Main .deviceToRefTimeCorrection = deltaTime ;
789+ Main .refTimeSource = mMessage .from ;
790+ mMessage .sms = "*Time Reference Received*" ;
791+ } catch (NumberFormatException e ) {
792+ //Discard. Should not happen, but to make sure
782793 }
783- Main .deviceToRefTimeCorrection = deltaTime ;
784- Main .refTimeSource = mMessage .from ;
785- mMessage .sms = "*Time Reference Received*" ;
786794 }
787795 }
788796 }
0 commit comments