Commitc322b1d2 by developer4

"block-read example" v2.7 now have BLOCK WRITE functionality

Added "Block write" key to the UI. Click on the "Block write" key to write data (16 byte hexadecimal representation) from the "Block data" edit box to the card. "Block Addr.", "Authentication mode" and "Key" have to be correctly defined before write data to the card.
家长 f3ebecf7
... ... @@ -2,13 +2,13 @@ apply plugin: 'com.android.application'
android{
compileSdkVersion23
buildToolsVersion'23.0.3'
buildToolsVersion'25.0.0'
defaultConfig{
applicationId"net.dlogic.android.ufr.block_read_example"
minSdkVersion15
targetSdkVersion15
versionCode26
versionName'2.6'
versionCode27
versionName'2.7'
}
buildTypes{
release{
... ...
xmlns:android="http://schemas.android.com/apk/res/android"
package="net.dlogic.ufr.block_read"
android:versionCode="26"
android:versionName="2.6">
android:versionCode="27"
android:versionName="2.7">
android:minSdkVersion="15"/>
android:name="android.hardware.usb.host"/>
android:name="android.hardware.usb.accessory"/>
... ...
... ... @@ -33,6 +33,7 @@ public class Main extends Activity {
static按钮btnReaderType;
static按钮btnTagId;
static按钮btnBlockRead;
static按钮btnBlockWrite;
static按钮btnUiSignal;
static按钮btnEnterSleep;
static按钮btnLeaveSleep;
... ... @@ -54,6 +55,7 @@ public class Main extends Activity {
privatebyteblock_addr;
staticfinalbyte[]default_key=newbyte[]{(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF};
staticbyte[]key=newbyte[]{(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF};
staticbyte[]mDataForWrite=newbyte[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
staticConcurrentLinkedQueue<Task>mCommandQueue=newConcurrentLinkedQueue<Task>();
ReaderThreadmReaderThread;
... ... @@ -97 7 + 99 6 @@公共class Main extends Activity {
ebTagUid=(EditText)findViewById(R.id.ebTagUid);
ebTagUid.setInputType(0);
ebBlockData=(EditText)findViewById(R.id.ebBlockData);
ebBlockData.setInputType(0);
ebKey=(EditText)findViewById(R.id.ebKey);
/ / btnOpen = (Button) findViewById(R.id.btnOpen);
... ... @@ -105,6 +106,7 @@ public class Main extends Activity {
btnReaderType=(按钮)findViewById(R.id.btnDeviceType);
btnTagId=(按钮)findViewById(R.id.btnTagId);
btnBlockRead=(按钮)findViewById(R.id.btnBlockRead);
btnBlockWrite=(按钮)findViewById(R.id.btnBlockWrite);
btnUiSignal=(按钮)findViewById(R.id.btnUiSignal);
btnEnterSleep=(按钮)findViewById(R.id.btnEnterSleep);
btnLeaveSleep=(按钮)findViewById(R.id.btnLeaveSleep);
... ... @@ -225,6 +227,33 @@ public class Main extends Activity {
}
}
});
btnBlockWrite.setOnClickListener(newView.OnClickListener(){
publicvoidonClick(Viewv){
if(device.readerStillConnected()){
if(Tools.isNumeric(ebBlockAddr.getText().toString())){
inti=Integer.parseInt(ebBlockAddr.getText().toString());
if((i>=0)&&(i<Consts.MAX_BLOCK_ADDR)){
block_addr=(byte)i;
if(setKey(ebKey.getText().toString())&&setDataForWrite(ebBlockData.getText().toString())){
try{
mCommandQueue.add(newTask(Consts.TASK_BLOCK_WRITE,block_addr,(byte)authenticationMode,getKey(),getDataForWrite()));
}catch(Exceptione){
Toast.makeText(context,e.toString(),Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(context,"Wrong key format. Key must be HEX string 6 bytes long.",Toast.LENGTH_LONG).show();
}
}else{
Toast.makeText(context,"Wrong block address.",Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(context,"Block address must be a number.",Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(context,"Device not connected.",Toast.LENGTH_SHORT).show();
}
}
});
btnUiSignal.setOnClickListener(newView.OnClickListener(){
publicvoidonClick(Viewv){
... ... @@ -271,6 +300,10 @@ public class Main extends Activity {
returnkey;
}
privatestaticbyte[]getDataForWrite(){
returnmDataForWrite;
}
privatestaticbooleansetKey(字符串keyHexStr){
if(keyHexStr.length()!=12){
... ... @@ -286,6 +319,21 @@ public class Main extends Activity {
returntrue;
}
privatestaticbooleansetDataForWrite(字符串dataHexStr){
if(dataHexStr.length()!=32){
returnfalse;
}
if(!dataHexStr.matches("[0-9A-Fa-f]+")){
returnfalse;
}
for(inti=0;i<32;i+=2){
mDataForWrite[i/2]=(byte)((Character.digit(dataHexStr.charAt(i),16)<<4)
+Character.digit(dataHexStr.charAt(i+1),16));
}
returntrue;
}
privatestaticvoidmakeKeyDefault(){
java.lang.System.arraycopy(default_key,0,key,0,6);
}
... ... @@ -314,6 +362,10 @@ public class Main extends Activity {
Toast.makeText(context,"Block successfully read.",Toast.LENGTH_SHORT).show();
break;
caseConsts.RESPONSE_SUCESS:
Toast.makeText(context,"Operation completed successfully.",Toast.LENGTH_SHORT).show();
break;
caseConsts.RESPONSE_DISCONNECTED:
ebBlockAddr.setText("0");
ebDeviceType.setText("");
... ... @@ -349,12 +401,14 @@ public class Main extends Activity {
publicstaticfinalintTASK_EMIT_UI_SIGNAL=6;
publicstaticfinalintTASK_ENTER_SLEEP=7;
publicstaticfinalintTASK_LEAVE_SLEEP=8;
publicstaticfinalintTASK_BLOCK_WRITE=9;
publicstaticfinalintRESPONSE_CONNECTED=100;
publicstaticfinalintRESPONSE_READER_TYPE=101;
publicstaticfinalintRESPONSE_CARD_ID=102;
publicstaticfinalintRESPONSE_BLOCK_READ=103;
publicstaticfinalintRESPONSE_DISCONNECTED=104;
publicstaticfinalintRESPONSE_SUCESS=105;
publicstaticfinalintRESPONSE_ERROR=400;
publicstaticfinalintRESPONSE_ERROR_QUIETLY=401;
... ... @@ -447,6 +501,18 @@ public class Main extends Activity {
}
break;
caseConsts.TASK_BLOCK_WRITE:
if(connected){
try{
device.blockWrite(local_task.byte_arr_param2/*getData()*/,local_task.byte_param1/*block_addr*/,
local_task.byte_param2/*authenticationMode*/,local_task.byte_arr_param1/*getKey()*/);
handler.sendMessage(handler.obtainMessage(Consts.RESPONSE_SUCESS));
}catch(Exceptione){
handler.sendMessage(handler.obtainMessage(Consts.RESPONSE_ERROR,e.getMessage()));
}
}
break;
caseConsts.TASK_EMIT_UI_SIGNAL:
if(connected){
try{
... ... @@ -489,6 +555,7 @@ public class Main extends Activity {
inttaskCode;
bytebyte_param1,byte_param2;
byte[]byte_arr_param1;
byte[]byte_arr_param2;
publicTask(intcode){
taskCode=code;
... ... @@ -504,6 +571,13 @@ public class Main extends Activity {
byte_param2=p2;
byte_arr_param1=pa1;
}
publicTask(intcode,bytep1,bytep2,byte[]pa1,byte[]pa2){
taskCode=code;
byte_param1=p1;
byte_param2=p2;
byte_arr_param1=pa1;
byte_arr_param2=pa2;
}
}
staticclassTools{
... ...
lib@2c014e63
Subproject commite52a8c034efc4b4d1a316d7e461e1e213c21bae6
Subproject commit2c014e6382a597cb244258f2e48d8e8ff9f90125
name="app_name">DLogic uFR block read demo
name="title_activity_main">DLogic uFR block read demo 2.6
name="title_activity_main">DLogic uFR block read demo 2.7
name="light_signal_modes">
None
... ...
... ... @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies{
classpath'com.android.tools.build:gradle:2.1.0'
classpath'com.android.tools.build:gradle:2.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
... ...
#Mon Apr 25 10:30:33 CEST 2016
#Tue Apr 18 13:30:08 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
    Markdownis supported
    0%or
    You are about to add0peopleto the discussion. Proceed with caution.
    Finish editing this message first!
    Pleaseregisterorto comment
    Baidu
    map