diff --git a/.idea/misc.xml b/.idea/misc.xml index 99ece92..f797995 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/flywithu/carnav/RealService.java b/app/src/main/java/com/flywithu/carnav/RealService.java index 6c073d2..3de53be 100644 --- a/app/src/main/java/com/flywithu/carnav/RealService.java +++ b/app/src/main/java/com/flywithu/carnav/RealService.java @@ -30,6 +30,8 @@ import com.hoho.android.usbserial.driver.UsbSerialPort; import com.hoho.android.usbserial.driver.UsbSerialProber; import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; @@ -47,6 +49,11 @@ public class RealService extends Service { } private void sendSerial(String str) { + + sendSerial(str,Charset.forName("UTF-8")); + } + + private void sendSerial(String str,Charset enc) { 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}; @@ -58,18 +65,21 @@ feff0041c9c0c5b4bc18005a */ if (sPort != null) { try { - // 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(getStringToByte(str,enc), 3000); sPort.write(new byte[]{0xd}, 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) { } @@ -78,6 +88,42 @@ feff0041c9c0c5b4bc18005a } + + protected byte[] getStringToByte(String str,Charset enc) + { + ByteBuffer buf = ByteBuffer.allocate(100);; + /* + sendSerial("U4PL13|soar|"); + sendSerial("U4PL23|헤어지자 (Prod. 정키)|"); + sendSerial("U4PL33|휘인 (Whee In)|"); + */ + String[] arrStr = null; + if(str.startsWith("U4PL13")||str.startsWith("U4PL23")||str.startsWith("U4PL33")) + { + arrStr = str.split("\\|"); + // System.out.println(arrStr[1]); + // System.out.println(arrStr[0]); + buf.put(arrStr[0].getBytes(Charset.forName("UTF-8"))); + buf.put(new byte[]{0x7c}); + buf.put(arrStr[1].getBytes(enc)); + buf.put(new byte[]{0x7c}); + // System.out.println(new String(buf.array())); + + } + else + { + + buf.put(str.getBytes(Charset.forName("UTF-8"))); + } + + + + + return buf.array(); + } + + + @Override public int onStartCommand(Intent intent, int flags, int startId) { serviceIntent = intent; @@ -104,7 +150,7 @@ feff0041c9c0c5b4bc18005a connection = manager.openDevice(driver.getDevice()); if (connection == null) { showToast(getApplication(), "No connection"); - return START_NOT_STICKY; + return START_NOT_STICKY; } sPort = driver.getPorts().get(0); @@ -139,8 +185,9 @@ feff0041c9c0c5b4bc18005a sendSerial("U4EN00"); sendSerial("*R|R1R2R3D1D2A1A3U4|"); sendSerial("U4PL03|5,3|0001010000000"); - sendSerial("U4PL13|soar| U4PL23|헤어지자 (Prod. 정키)|"); - sendSerial("U4PL33|휘인 (Whee In)|"); + sendSerial("U4PL13|8소아|",Charset.forName("UTF-8")); + sendSerial("U4PL23|16헤어지자 (Prod. 정키)|", Charset.forName("UTF-16")); + sendSerial("U4PL33|32휘인 (Whee In)|",Charset.forName("UTF-32")); // sendSerial("U4DI00"); diff --git a/app/src/test/java/com/flywithu/carnav/ExampleUnitTest.java b/app/src/test/java/com/flywithu/carnav/ExampleUnitTest.java index 6a29cb7..8f70f2a 100644 --- a/app/src/test/java/com/flywithu/carnav/ExampleUnitTest.java +++ b/app/src/test/java/com/flywithu/carnav/ExampleUnitTest.java @@ -2,6 +2,7 @@ package com.flywithu.carnav; import org.junit.Test; +import java.nio.charset.Charset; import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.util.Date; @@ -45,6 +46,13 @@ public class ExampleUnitTest { return sb.toString(); } + @Test + public void myTest() + { + RealService rs = new RealService(); + rs.getStringToByte("U4PL23|헤어지자 (Prod. 정키)|", Charset.forName("UTF-8")); + } + @Test public void checkout() {