-
Notifications
You must be signed in to change notification settings - Fork 3
/
ft_reader.java
105 lines (97 loc) · 2.95 KB
/
ft_reader.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package com.example.ftbtdemo;
import java.io.InputStream;
import java.io.OutputStream;
import android.os.Handler;
import com.feitian.reader.devicecontrol.Card;
import com.feitian.readerdk.Tool.DK;
public class ft_reader{
private boolean isPowerOn = false;
private Card inner_card;
Handler mHandler;
public ft_reader(InputStream Intmp, OutputStream Outmp) {
inner_card = new Card(Intmp, Outmp);
}
public boolean isPowerOn(){
return isPowerOn;
}
public int PowerOn() throws FtBlueReadException{
int ret = inner_card.PowerOn();
if(ret != DK.RETURN_SUCCESS){
throw new FtBlueReadException("Power On Failed");
}
isPowerOn = true;
return ret;
}
public int PowerOff() throws FtBlueReadException{
int ret = inner_card.PowerOff();
if(ret != DK.RETURN_SUCCESS){
throw new FtBlueReadException("Power Off Failed");
}
isPowerOn = false;
return ret;
}
public int getProtocol() throws FtBlueReadException{
if(isPowerOn == false){
throw new FtBlueReadException("Power Off already");
}
return inner_card.getProtocol();
}
public byte[] getAtr() throws FtBlueReadException{
if(isPowerOn == false){
throw new FtBlueReadException("Power Off already");
}
return inner_card.getAtr();
}
public int getVersion(byte []recvBuf,int []recvBufLen){
return inner_card.getVersion(recvBuf, recvBufLen);
}
public String getDkVersion(){
return inner_card.GetDkVersion();
}
/**/
public int getCardStatus() throws FtBlueReadException{
return inner_card.getcardStatus();
}
public int setAutoOff(boolean isAutoOff){
return inner_card.FTSetAutoTurnOff(isAutoOff);
}
/**/
public int getSerialNum(byte[] serial,int serialLen[]){
return inner_card.FtGetSerialNum(serial, serialLen);
}
public int readFlash(byte[] buf,int offset,int len){
return inner_card.FtReadFlash(buf, offset, len);
}
public int writeFlash(byte[] buf,int offset,int len){
return inner_card.FtWriteFlash(buf, offset, len);
}
/*new api for monitor the card status*/
public void registerCardStatusMonitoring(Handler Handler) throws FtBlueReadException{
mHandler = Handler;
if(inner_card.registerCardStatusMonitoring(Handler) !=DK.RETURN_SUCCESS){
throw new FtBlueReadException("not support cardStatusMonitoring");
}
}
public int transApdu(int tx_length,final byte tx_buffer[],
int rx_length[],final byte rx_buffer[]) throws FtBlueReadException{
if(isPowerOn == false){
throw new FtBlueReadException("Power Off already");
}
int ret = inner_card.transApdu(tx_length, tx_buffer, rx_length, rx_buffer);
if(ret == DK.RETURN_SUCCESS){
return ret;
}
if(ret == DK.BUFFER_NOT_ENOUGH){
throw new FtBlueReadException("receive buffer not enough");
}else if(ret == DK.CARD_ABSENT){
mHandler.obtainMessage(DK.CARD_STATUS,
DK.CARD_ABSENT, -1).sendToTarget();
throw new FtBlueReadException("card is absent");
}else{
throw new FtBlueReadException("trans apdu error");
}
}
public void readerClose(){
inner_card.cardClose();
}
}