diff --git a/app/src/main/java/com/flywithu/carnav/RealService.java b/app/src/main/java/com/flywithu/carnav/RealService.java index b7f22ab..5e9e7ff 100644 --- a/app/src/main/java/com/flywithu/carnav/RealService.java +++ b/app/src/main/java/com/flywithu/carnav/RealService.java @@ -35,7 +35,7 @@ import java.util.Date; import java.util.List; public class RealService extends Service { - // private Thread mainThread; + // private Thread mainThread; public static Intent serviceIntent = null; private static UsbSerialPort sPort = null; @@ -44,15 +44,31 @@ public class RealService extends Service { public RealService() { } - private void sendSerial(String str) - { - if(sPort!=null) - { + private void sendSerial(String str) { + byte t1[] = new byte[]{0x55, 0x34, 0x50, 0x4C, 0x30, 0x33, 0x7C, 0x31, 0x2C, 0x31, 0x7C, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30}; + byte t2[] = new byte[]{0x55, 0x34, 0x50, 0x4C, 0x31, 0x33, 0x7C, 0x41, (byte) 0xec, (byte) 0xa7, (byte) 0x80, (byte) 0xec, (byte) 0x96, (byte) 0xb4, (byte) 0xeb, (byte) 0xb0, (byte) 0x98, 0x5a, 0x7c}; + byte t3[] = new byte[]{0x55, 0x34, 0x50, 0x4C, 0x32, 0x33, 0x7C, (byte) 0xfe, (byte) 0xff, 0x00, 0x41, (byte) 0xc9, (byte) 0xc0, (byte) 0xc5, (byte) 0xb4, (byte) 0xbc, 0x18, 0x00, 0x5a, 0x7c}; + byte t4[] = new byte[]{0x55, 0x34, 0x50, 0x4C, 0x33, 0x33, 0x7C, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, (byte) 0xc9, (byte) 0xc0, 0x00, 0x00, (byte) 0xc5, (byte) 0xb4, 0x00, 0x00, (byte) 0xbc, 0x18, 0x00, 0x00, 0x00, 0x5a, 0x7c}; + /* + 41eca780ec96b4ebb0985a +feff0041c9c0c5b4bc18005a +000000410000c9c00000c5b40000bc180000005a + */ + if (sPort != null) { try { - sPort.write(str.getBytes(), 3000); - } - catch(Exception e) - { + // sPort.write(str.getBytes(), 3000); + sPort.write(t1, 3000); + sPort.write(new byte[]{0xd}, 3000); + + sPort.write(t2, 3000); + sPort.write(new byte[]{0xd}, 3000); + + sPort.write(t3, 3000); + sPort.write(new byte[]{0xd}, 3000); + + sPort.write(t4, 3000); + sPort.write(new byte[]{0xd}, 3000); + } catch (Exception e) { } @@ -71,59 +87,68 @@ public class RealService extends Service { // public void run() { - - - - UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); - List availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager); - if (availableDrivers.isEmpty()) { - showToast(getApplication(), "NO SERIAL"); - return START_NOT_STICKY; - } + UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); + List availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager); + if (availableDrivers.isEmpty()) { + showToast(getApplication(), "NO SERIAL"); + return START_NOT_STICKY; + } // Open a connection to the first available driver. - UsbSerialDriver driver = null; - UsbDeviceConnection connection = null; - try { - driver = availableDrivers.get(0); - connection = manager.openDevice(driver.getDevice()); - if (connection == null) { - showToast(getApplication(), "No connection"); - // You probably need to call UsbManager.requestPermission(driver.getDevice(), ..) - return START_NOT_STICKY; - } - } - catch(Exception e) - { - showToast(getApplication(),e.toString()); - } + UsbSerialDriver driver = null; + UsbDeviceConnection connection = null; + try { + driver = availableDrivers.get(0); + connection = manager.openDevice(driver.getDevice()); + if (connection == null) { + showToast(getApplication(), "No connection"); + // You probably need to call UsbManager.requestPermission(driver.getDevice(), ..) + return START_NOT_STICKY; + } + } catch (Exception e) { + showToast(getApplication(), e.toString()); + } - try { - sPort.open(connection); - sPort.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE); + try { + sPort.open(connection); + sPort.setParameters(19200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE); + } catch (IOException e) { + showToast(getApplication(), "Error opening device: " + e.getMessage()); + try { + sPort.close(); + } catch (IOException e2) { + // Ignore. + } + sPort = null; + } + //set the time + //TMST001801140907 + //TMST00YYDDDD0907 + //TMST001205010916 + 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); + sendSerial("U4EN00"); + sendSerial("*R|R1R2R3D1D2A1A3U4|"); + sendSerial("U4PL03|5,3|0001010000000"); + sendSerial("U4PL13|soar| U4PL23|헤어지자 (Prod. 정키)|"); + sendSerial("U4PL33|휘인 (Whee In)|"); - } catch (IOException e) { - showToast(getApplication(),"Error opening device: " + e.getMessage()); - try { - sPort.close(); - } catch (IOException e2) { - // Ignore. - } - 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); +// sendSerial("U4DI00"); +// sendSerial("*R|R1R2R3D1D2A1A3|"); +// U4EN00 +// *R|R1R2R3D1D2A1A3U4| +// A1PL00 - showToast(getApplication(),currentTime); + + //U4PL03|1,1|0001010000000 U4PL13|soar| U4PL23|헤어지자 (Prod. 정키)| U4PL33|휘인 (Whee In)| + + showToast(getApplication(), currentTime); // try { // sPort.write("zxcv".getBytes(), 50); @@ -174,9 +199,7 @@ public class RealService extends Service { try { sPort.close(); sPort = null; - } - catch(Exception e) - { + } catch (Exception e) { } serviceIntent = null; @@ -219,27 +242,22 @@ public class RealService extends Service { c.setTimeInMillis(System.currentTimeMillis()); c.add(Calendar.SECOND, 1); Intent intent = new Intent(this, AlarmRecever.class); - PendingIntent sender = PendingIntent.getBroadcast(this, 0,intent,0); + PendingIntent sender = PendingIntent.getBroadcast(this, 0, intent, 0); AlarmManager mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mAlarmManager.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), sender); } - private BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { try { - if (sPort != null) - { + if (sPort != null) { sPort.write("abc".getBytes(), 3000); } - } - - catch(Exception e) - { + } catch (Exception e) { e.toString(); } String action = intent.getAction(); @@ -251,8 +269,7 @@ public class RealService extends Service { Log.v("tag", artist + ":" + album + ":" + track); - - // Toast.makeText(MainActivity.this, track, Toast.LENGTH_SHORT).show(); + // Toast.makeText(MainActivity.this, track, Toast.LENGTH_SHORT).show(); } }; diff --git a/app/src/test/java/com/flywithu/carnav/ExampleUnitTest.java b/app/src/test/java/com/flywithu/carnav/ExampleUnitTest.java index ef04165..6a29cb7 100644 --- a/app/src/test/java/com/flywithu/carnav/ExampleUnitTest.java +++ b/app/src/test/java/com/flywithu/carnav/ExampleUnitTest.java @@ -35,5 +35,32 @@ public class ExampleUnitTest { System.out.println(f); + } + private static String bytesToHex(byte[] hashInBytes) { + + StringBuilder sb = new StringBuilder(); + for (byte b : hashInBytes) { + sb.append(String.format("%02x", b)); + } + return sb.toString(); + + } + @Test + public void checkout() + { + //55 34 50 4C 33 33 7C ED 9C 98 EC 9D B8 20 28 57 68 65 65 20 49 6E 29 7C 0D + String test = "A지어반Z"; + //EC A7 80 EC 96 B4 EB B0 98 + System.out.println(test); + try { + System.out.println(bytesToHex(test.getBytes("utf-8"))); + System.out.println(bytesToHex(test.getBytes("utf-16"))); + System.out.println(bytesToHex(test.getBytes("utf-32"))); + } + catch(Exception e) + { + e.printStackTrace(); + } + } } \ No newline at end of file