diff --git a/app/src/main/java/com/flywithu/carnav/RealService.java b/app/src/main/java/com/flywithu/carnav/RealService.java index 7ef1649..b7f22ab 100644 --- a/app/src/main/java/com/flywithu/carnav/RealService.java +++ b/app/src/main/java/com/flywithu/carnav/RealService.java @@ -44,6 +44,22 @@ public class RealService extends Service { public RealService() { } + private void sendSerial(String str) + { + if(sPort!=null) + { + try { + sPort.write(str.getBytes(), 3000); + } + catch(Exception e) + { + + } + + } + + } + @Override public int onStartCommand(Intent intent, int flags, int startId) { serviceIntent = intent; @@ -98,7 +114,16 @@ public class RealService extends Service { sPort = null; } //set the time - + //TMST001801140907 + //TMST00YYDDDD0907 + + SimpleDateFormat format1 = new SimpleDateFormat ( "00yyMMddHHmm"); + // String f = format1.format(System.currentTimeMillis()); + String currentInfo = format1.format(new Date()); + String currentTime = String.format("TMST%s",currentInfo); + sendSerial(currentTime); + + showToast(getApplication(),currentTime); // try { // sPort.write("zxcv".getBytes(), 50); diff --git a/app/src/test/java/com/flywithu/carnav/ExampleUnitTest.java b/app/src/test/java/com/flywithu/carnav/ExampleUnitTest.java index e90aded..ef04165 100644 --- a/app/src/test/java/com/flywithu/carnav/ExampleUnitTest.java +++ b/app/src/test/java/com/flywithu/carnav/ExampleUnitTest.java @@ -2,6 +2,10 @@ package com.flywithu.carnav; import org.junit.Test; +import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.util.Date; + import static org.junit.Assert.*; /** @@ -14,4 +18,22 @@ public class ExampleUnitTest { public void addition_isCorrect() { assertEquals(4, 2 + 2); } + + @Test + public void checkDate() + { + LocalDateTime currentDateTime = LocalDateTime.now(); + //TMST001801140907 + //TMST00YYDDDD0907 + + Date myDate = new Date ( "Sun,5 Dec 1999 00:07:21" ); + + + SimpleDateFormat format1 = new SimpleDateFormat ( "yy MM dd HH mm"); + // String f = format1.format(System.currentTimeMillis()); + String f = format1.format(myDate); + System.out.println(f); + + + } } \ No newline at end of file