1
1
package com .csl .cs108ademoapp ;
2
2
3
3
import android .os .AsyncTask ;
4
+ import android .os .Handler ;
4
5
import android .widget .Button ;
5
6
import android .widget .TextView ;
6
7
import android .widget .Toast ;
@@ -13,10 +14,12 @@ public class AccessTask extends AsyncTask<Void, String, String> {
13
14
final boolean DEBUG = true ;
14
15
final boolean skipSelect = false ;
15
16
public enum TaskCancelRReason {
16
- NULL , INVALD_REQUEST , DESTORY , STOP , BUTTON_RELEASE , TIMEOUT
17
+ NULL , INVALD_REQUEST , DESTORY , STOP , BUTTON_RELEASE , ERROR , TIMEOUT
17
18
}
18
19
public TaskCancelRReason taskCancelReason ;
19
20
public String accessResult ;
21
+ Handler mHandler = new Handler ();
22
+ Runnable updateRunnable = null ;
20
23
21
24
Button button ; String buttonText ;
22
25
TextView registerRunTime , registerTagGot , registerVoltageLevel ;
@@ -46,7 +49,8 @@ public enum TaskCancelRReason {
46
49
47
50
public AccessTask (Button button , boolean invalidRequest ,
48
51
String selectMask , int selectBank , int selectOffset ,
49
- String strPassword , int powerLevel , Cs108Connector .HostCommands hostCommand , boolean bEnableErrorPopWindow ) {
52
+ String strPassword , int powerLevel , Cs108Connector .HostCommands hostCommand ,
53
+ boolean bEnableErrorPopWindow , Runnable updateRunnable ) {
50
54
this .button = button ;
51
55
this .registerTagGot = registerTagGot ;
52
56
this .registerVoltageLevel = registerVoltageLevel ;
@@ -59,6 +63,7 @@ public AccessTask(Button button, boolean invalidRequest,
59
63
this .powerLevel = powerLevel ;
60
64
this .hostCommand = hostCommand ;
61
65
this .bEnableErrorPopWindow = bEnableErrorPopWindow ;
66
+ this .updateRunnable = updateRunnable ;
62
67
if (true ) {
63
68
total = 0 ;
64
69
tagList .clear ();
@@ -95,6 +100,9 @@ public AccessTask(Button button, TextView textViewWriteCount, boolean invalidReq
95
100
}
96
101
preExecute ();
97
102
}
103
+ public void setRunnable (Runnable updateRunnable ) {
104
+ this .updateRunnable = updateRunnable ;
105
+ }
98
106
99
107
void preExecute () {
100
108
accessResult = null ;
@@ -106,13 +114,14 @@ void preExecute() {
106
114
String buttonText1 = null ; String strLastChar = buttonText .substring (buttonText .length ()-1 );
107
115
if (strLastChar .toUpperCase ().matches ("E" )) {
108
116
buttonText1 = buttonText .substring (0 , buttonText .length ()-1 );
109
- if (strLastChar . matches ("E " )) buttonText1 += "ING" ;
110
- else buttonText1 += "ing" ;
111
- }
117
+ } else if (buttonText . toUpperCase (). matches ("STOP " )) {
118
+ buttonText1 = buttonText ; buttonText1 += buttonText1 . substring ( buttonText . length ()- 1 ) ;
119
+ } else buttonText1 = buttonText ;
112
120
if (repeat || buttonText .length () == 0 ) button .setText ("Stop" );
113
- else if (buttonText1 != null ) button .setText (buttonText1 );
114
- else if (Character .isUpperCase (strLastChar .charAt (0 ))) button .setText (buttonText + "ING" );
115
- else button .setText (buttonText + "ing" );
121
+ else {
122
+ if (Character .isUpperCase (strLastChar .charAt (0 ))) button .setText (buttonText1 + "ING" );
123
+ else button .setText (buttonText1 + "ing" );
124
+ }
116
125
if (registerYield != null && tagList .size ()==0 ) registerYield .setText ("" );
117
126
if (registerTotal != null && total == 0 ) registerTotal .setText ("" );
118
127
@@ -163,6 +172,7 @@ else if (MainActivity.mCs108Library4a.setSelectedTag(selectMask, selectBank, sel
163
172
@ Override
164
173
protected String doInBackground (Void ... a ) {
165
174
boolean ending = false ;
175
+ int iTimeOut = 5000 ;
166
176
167
177
while (MainActivity .mCs108Library4a .isBleConnected () && isCancelled () == false && ending == false ) {
168
178
int batteryCount = MainActivity .mCs108Library4a .getBatteryCount ();
@@ -174,6 +184,7 @@ protected String doInBackground(Void... a) {
174
184
runTimeMillis = System .currentTimeMillis ();
175
185
publishProgress ("WW" );
176
186
}
187
+ byte [] notificationData = MainActivity .mCs108Library4a .onNotificationEvent ();
177
188
Cs108Connector .Rx000pkgData rx000pkgData = MainActivity .mCs108Library4a .onRFIDEvent ();
178
189
if (MainActivity .mCs108Library4a .mrfidToWriteSize () != 0 ) timeMillis = System .currentTimeMillis ();
179
190
else if (rx000pkgData != null ) {
@@ -182,11 +193,19 @@ else if (rx000pkgData != null) {
182
193
} else if (rx000pkgData .responseType == Cs108Connector .HostCmdResponseTypes .TYPE_18K6C_TAG_ACCESS ) {
183
194
if (true ) {
184
195
if (rx000pkgData .decodedError == null ) {
185
- if (done == false ) { accessResult = rx000pkgData .decodedResult ; MainActivity .mCs108Library4a .appendToLog ("HelloA, accResult=" + accessResult );}
196
+ if (done == false ) {
197
+ accessResult = rx000pkgData .decodedResult ;
198
+ MainActivity .mCs108Library4a .appendToLog ("StreamOut, accResult=" + accessResult );
199
+ if (updateRunnable != null ) {
200
+ MainActivity .mCs108Library4a .appendToLog ("StreamOut: start updateRunnable" );
201
+ mHandler .post (updateRunnable );
202
+ }
203
+ }
186
204
done = true ;
187
205
publishProgress (null , rx000pkgData .decodedResult );
188
206
}
189
207
else publishProgress (rx000pkgData .decodedError );
208
+ iTimeOut = 500 ;
190
209
}
191
210
} else if (rx000pkgData .responseType == Cs108Connector .HostCmdResponseTypes .TYPE_COMMAND_END ) {
192
211
if (rx000pkgData .decodedError != null ) { endingMessaage = rx000pkgData .decodedError ; ending = true ; }
@@ -204,11 +223,20 @@ else if (repeat && (nextNew == false || resultError.length() != 0)) {
204
223
}
205
224
timeMillis = System .currentTimeMillis ();
206
225
}
207
- if (System .currentTimeMillis () - timeMillis > 5000 ) {
208
- cancel (true );
226
+ else if (notificationData != null ) {
227
+ MainActivity .mCs108Library4a .appendToLog ("resultError=" + MainActivity .mCs108Library4a .byteArrayToString (notificationData ));
228
+ publishProgress ("Received notification uplink event 0xA101 with error code=" + MainActivity .mCs108Library4a .byteArrayToString (notificationData ));
229
+ timeMillis = System .currentTimeMillis ();
230
+ iTimeOut = 500 ;
231
+ }
232
+ if (System .currentTimeMillis () - timeMillis > iTimeOut ) {
233
+ MainActivity .mCs108Library4a .appendToLog ("endingMessage: iTimeout = " + iTimeOut );
209
234
taskCancelReason = TaskCancelRReason .TIMEOUT ;
210
235
}
211
- if (taskCancelReason != TaskCancelRReason .NULL ) cancel (true );
236
+ if (taskCancelReason != TaskCancelRReason .NULL ) {
237
+ MainActivity .mCs108Library4a .appendToLog ("taskCancelReason=" + TaskCancelRReason .values ());
238
+ cancel (true );
239
+ }
212
240
}
213
241
return "End of Asynctask():" + ending ;
214
242
}
@@ -244,6 +272,7 @@ else if (output[0] != null) {
244
272
resultError += output [0 ];
245
273
if (true )
246
274
MainActivity .mCs108Library4a .appendToLog ("output[0]: " + output [0 ] + ", resultError = " + resultError );
275
+ taskCancelReason = TaskCancelRReason .ERROR ;
247
276
}
248
277
} else {
249
278
if (registerYield != null ) {
@@ -260,8 +289,8 @@ else if (output[0] != null) {
260
289
@ Override
261
290
protected void onCancelled () {
262
291
super .onCancelled ();
263
- if (DEBUG ) MainActivity .mCs108Library4a .appendToLog ("AccessSecurityLockFragment.InventoryRfidTask.onCancelled()" );
264
-
292
+ if (DEBUG ) MainActivity .mCs108Library4a .appendToLog ("endingMesssage: taskCancelReason = " + taskCancelReason );
293
+ //if (taskCancelReason != TaskCancelRReason.NULL) MainActivity.mCs108Library4a.abortOperation1(); else
265
294
MainActivity .mCs108Library4a .abortOperation ();
266
295
if (taskCancelReason == TaskCancelRReason .NULL ) taskCancelReason = TaskCancelRReason .DESTORY ;
267
296
DeviceConnectTask4RegisterEnding ();
@@ -339,6 +368,9 @@ void DeviceConnectTask4RegisterEnding() {
339
368
case BUTTON_RELEASE :
340
369
strErrorMessage += "Finish as BUTTON is released. " ;
341
370
break ;
371
+ case ERROR :
372
+ strErrorMessage += "Finish due to error received." ;
373
+ break ;
342
374
case TIMEOUT :
343
375
strErrorMessage += "TIMEOUT without COMMAND_END. " ;
344
376
break ;
@@ -354,7 +386,7 @@ void DeviceConnectTask4RegisterEnding() {
354
386
if (strErrorMessage .length () != 0 ) endingMessaage = strErrorMessage ;
355
387
button .setText (buttonText );
356
388
if (endingMessaage != null ) {
357
- if (endingMessaage .length () != 0 || true ) {
389
+ if (endingMessaage .length () != 0 ) {
358
390
MainActivity .mCs108Library4a .appendToLog ("endingMessage=" + endingMessaage );
359
391
if (bEnableErrorPopWindow ) {
360
392
CustomPopupWindow customPopupWindow = new CustomPopupWindow (MainActivity .mContext );
0 commit comments