second commit
This commit is contained in:
parent
91b1ff2a93
commit
3d2fe9eb5a
@ -35,7 +35,7 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class RealService extends Service {
|
public class RealService extends Service {
|
||||||
// private Thread mainThread;
|
// private Thread mainThread;
|
||||||
public static Intent serviceIntent = null;
|
public static Intent serviceIntent = null;
|
||||||
|
|
||||||
private static UsbSerialPort sPort = null;
|
private static UsbSerialPort sPort = null;
|
||||||
@ -44,15 +44,31 @@ public class RealService extends Service {
|
|||||||
public RealService() {
|
public RealService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendSerial(String str)
|
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};
|
||||||
if(sPort!=null)
|
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 {
|
try {
|
||||||
sPort.write(str.getBytes(), 3000);
|
// sPort.write(str.getBytes(), 3000);
|
||||||
}
|
sPort.write(t1, 3000);
|
||||||
catch(Exception e)
|
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() {
|
// public void run() {
|
||||||
|
|
||||||
|
|
||||||
|
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
|
||||||
|
List<UsbSerialDriver> availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager);
|
||||||
|
if (availableDrivers.isEmpty()) {
|
||||||
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
|
showToast(getApplication(), "NO SERIAL");
|
||||||
List<UsbSerialDriver> availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager);
|
return START_NOT_STICKY;
|
||||||
if (availableDrivers.isEmpty()) {
|
}
|
||||||
showToast(getApplication(), "NO SERIAL");
|
|
||||||
return START_NOT_STICKY;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open a connection to the first available driver.
|
// Open a connection to the first available driver.
|
||||||
UsbSerialDriver driver = null;
|
UsbSerialDriver driver = null;
|
||||||
UsbDeviceConnection connection = null;
|
UsbDeviceConnection connection = null;
|
||||||
try {
|
try {
|
||||||
driver = availableDrivers.get(0);
|
driver = availableDrivers.get(0);
|
||||||
connection = manager.openDevice(driver.getDevice());
|
connection = manager.openDevice(driver.getDevice());
|
||||||
if (connection == null) {
|
if (connection == null) {
|
||||||
showToast(getApplication(), "No connection");
|
showToast(getApplication(), "No connection");
|
||||||
// You probably need to call UsbManager.requestPermission(driver.getDevice(), ..)
|
// You probably need to call UsbManager.requestPermission(driver.getDevice(), ..)
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e)
|
showToast(getApplication(), e.toString());
|
||||||
{
|
}
|
||||||
showToast(getApplication(),e.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sPort.open(connection);
|
sPort.open(connection);
|
||||||
sPort.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE);
|
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");
|
// sendSerial("U4DI00");
|
||||||
// String f = format1.format(System.currentTimeMillis());
|
// sendSerial("*R|R1R2R3D1D2A1A3|");
|
||||||
String currentInfo = format1.format(new Date());
|
// U4EN00
|
||||||
String currentTime = String.format("TMST%s",currentInfo);
|
// *R|R1R2R3D1D2A1A3U4|
|
||||||
sendSerial(currentTime);
|
// A1PL00
|
||||||
|
|
||||||
showToast(getApplication(),currentTime);
|
|
||||||
|
//U4PL03|1,1|0001010000000 U4PL13|soar| U4PL23|헤어지자 (Prod. 정키)| U4PL33|휘인 (Whee In)|
|
||||||
|
|
||||||
|
showToast(getApplication(), currentTime);
|
||||||
|
|
||||||
// try {
|
// try {
|
||||||
// sPort.write("zxcv".getBytes(), 50);
|
// sPort.write("zxcv".getBytes(), 50);
|
||||||
@ -174,9 +199,7 @@ public class RealService extends Service {
|
|||||||
try {
|
try {
|
||||||
sPort.close();
|
sPort.close();
|
||||||
sPort = null;
|
sPort = null;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
serviceIntent = null;
|
serviceIntent = null;
|
||||||
@ -219,27 +242,22 @@ public class RealService extends Service {
|
|||||||
c.setTimeInMillis(System.currentTimeMillis());
|
c.setTimeInMillis(System.currentTimeMillis());
|
||||||
c.add(Calendar.SECOND, 1);
|
c.add(Calendar.SECOND, 1);
|
||||||
Intent intent = new Intent(this, AlarmRecever.class);
|
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);
|
AlarmManager mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
||||||
mAlarmManager.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), sender);
|
mAlarmManager.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
try {
|
try {
|
||||||
if (sPort != null)
|
if (sPort != null) {
|
||||||
{
|
|
||||||
sPort.write("abc".getBytes(), 3000);
|
sPort.write("abc".getBytes(), 3000);
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
e.toString();
|
e.toString();
|
||||||
}
|
}
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
@ -251,8 +269,7 @@ public class RealService extends Service {
|
|||||||
Log.v("tag", artist + ":" + album + ":" + track);
|
Log.v("tag", artist + ":" + album + ":" + track);
|
||||||
|
|
||||||
|
|
||||||
|
// Toast.makeText(MainActivity.this, track, Toast.LENGTH_SHORT).show();
|
||||||
// Toast.makeText(MainActivity.this, track, Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -35,5 +35,32 @@ public class ExampleUnitTest {
|
|||||||
System.out.println(f);
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user