This commit is contained in:
Seunghee Oh 2019-09-08 18:21:08 +09:00
parent e249b68e7f
commit b7bdee4d29
4 changed files with 68 additions and 19 deletions

2
.idea/misc.xml generated
View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

6
.idea/vcs.xml generated
View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -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");

View File

@ -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()
{