@@ -51,7 +51,6 @@ public enum TaskCancelRReason {
5151 long firstTime ;
5252 long lastTime ;
5353 boolean continousRequest = false ;
54- boolean finishingRequest = false ; boolean debugEndRequest = false ;
5554 int batteryCountInventory_old ;
5655
5756 boolean requestSound = false ; boolean requestNewSound = false ; boolean requestNewVibrate = false ; long timeMillisNewVibrate ;
@@ -63,8 +62,7 @@ public enum TaskCancelRReason {
6362 boolean serverConnectValid = false ;
6463 Handler handler = new Handler (); boolean bValidVibrateNewAll = false ; boolean bUseVibrateMode0 = false ;
6564
66- @ Override
67- protected void onPreExecute () {
65+ void inventoryHandler_setup () {
6866 MainActivity .sharedObjects .runningInventoryRfidTask = true ;
6967 total = 0 ; allTotal = 0 ; yield = 0 ;
7068 if (tagsList != null ) {
@@ -112,6 +110,11 @@ protected void onPreExecute() {
112110 if (bValidVibrateNewAll ) MainActivity .mCs108Library4a .setVibrateOn (2 );
113111 }
114112
113+ @ Override
114+ protected void onPreExecute () {
115+ inventoryHandler_setup ();
116+ }
117+
115118 @ Override
116119 protected String doInBackground (Void ... a ) {
117120 boolean ending = false ;
@@ -174,83 +177,69 @@ protected String doInBackground(Void... a) {
174177 timeMillis = System .currentTimeMillis ();
175178 }
176179 }
177- /* if (System.currentTimeMillis() - timeMillis > 10000) {
178- if (debugEndRequest) MainActivity.mCs108Library4a.getMacLastCommandDuration(true);
179- taskCancelReason = TaskCancelRReason.TIMEOUT; taskCancelling = true;
180- }*/
181- /* if (System.currentTimeMillis() - timeMillisSound > 1000) {
180+ if (System .currentTimeMillis () - timeMillis > 10000 && false ) { //no tag timeout handling during inventory
181+ if (true ) taskCancelReason = TaskCancelRReason .TIMEOUT ;
182+ else {
182183 timeMillisSound = System .currentTimeMillis ();
183184 requestSound = true ;
184- }*/
185+ }
186+ }
185187 if (taskCancelReason != TaskCancelRReason .NULL ) {
186188 MainActivity .mCs108Library4a .abortOperation ();
187189 publishProgress ("XX" );
188- if (popRequest ) { popStatus = true ; publishProgress ("P" ); }
189- timeMillis = 0 ; boolean endStatus = true ; if (finishingRequest ) publishProgress ("EEE" );
190- while (MainActivity .mCs108Library4a .isBleConnected () && ((popRequest && popStatus ) || endStatus ) && finishingRequest ) {
191- if (System .currentTimeMillis () - timeMillis > 2000 ) {
192- timeMillis = System .currentTimeMillis ();
193- //publishProgress("EEE");
194- }
195- rx000pkgData = MainActivity .mCs108Library4a .onRFIDEvent ();
196- if (rx000pkgData != null ) {
197- if (MainActivity .mCs108Library4a .mrfidToWriteSize () == 0 ) {
198- MainActivity .mCs108Library4a .abortOperation ();
199- }
200- } else if (MainActivity .mCs108Library4a .mrfidToWriteSize () == 0 ) {
201- endStatus = false ;
202- }
203- }
204- if (taskCancelReason == TaskCancelRReason .TIMEOUT && debugEndRequest ) {
205- if (MainActivity .mCs108Library4a .getMacLastCommandDuration (false ) == 0 )
206- taskCancelReason = TaskCancelRReason .RFID_RESET ;
207- }
190+ if (popRequest ) publishProgress ("P" );
191+ timeMillis = 0 ; boolean endStatus = true ;
208192 cancel (true );
209193 }
210194 }
211195 return "End of Asynctask()" ;
212196 }
213197
214- boolean debugged = false ;
215- long firstTimeOld = 0 ; int totalResetCount = 0 ; int totalOld = 0 ;
198+ long firstTimeOld = 0 , timeMillisSound = 0 ; int totalOld = 0 ;
216199 @ Override
217200 protected void onProgressUpdate (String ... output ) {
218201 if (output [0 ] != null ) {
219- if (output [0 ].length () == 1 ) {
220- String message ;
221- switch (taskCancelReason ) {
222- case STOP :
223- message = "Stop button pressed" ;
224- break ;
225- case BUTTON_RELEASE :
226- message = "Trigger Released" ;
227- break ;
228- case TIMEOUT :
229- message = "Time Out" ;
230- break ;
231- default :
232- message = taskCancelReason .name ();
233- break ;
234- }
235- CustomPopupWindow customPopupWindow = new CustomPopupWindow (MainActivity .mContext );
236- customPopupWindow .popupStart (message , false );
237- } else if (output [0 ].length () == 2 ) {
202+ if (output [0 ].length () == 1 ) inventoryHandler_endReason ();
203+ else if (output [0 ].length () == 2 ) {
238204 if (output [0 ].contains ("XX" )) MainActivity .mCs108Library4a .appendToLogView ("CANCELLING. sent abortOperation" );
239- else if (output [0 ].contains ("WW" )) {
240- long timePeriod = (System .currentTimeMillis () - startTimeMillis ) / 1000 ;
241- if (timePeriod > 0 ) {
242- if (rfidRunTime != null ) rfidRunTime .setText (String .format ("Run time: %d sec" , timePeriod ));
243- yieldRate = yield4RateCount ; yield4RateCount = 0 ;
244- }
245- } else if (taskCancelReason == TaskCancelRReason .NULL ) {
246- if (rfidVoltageLevel != null ) rfidVoltageLevel .setText (MainActivity .mCs108Library4a .getBatteryDisplay (true ));
247- }
248- } else if (output [0 ].length () == 3 ) {
249- mytoast = Toast .makeText (MainActivity .mContext , R .string .toast_finishing_tag_data_upload , Toast .LENGTH_LONG );
250- mytoast .show ();
205+ else if (output [0 ].contains ("WW" )) inventoryHandler_runtime ();
206+ else if (output [0 ].contains ("VV" )) inventoryHandler_voltage ();
251207 } else
252208 if (DEBUG ) MainActivity .mCs108Library4a .appendToLog ("InventoryRfidTask.InventoryRfidTask.onProgressUpdate(): " + output [0 ]);
253- } else {
209+ } else inventoryHandler_tag ();
210+ }
211+
212+ void inventoryHandler_endReason () {
213+ String message ;
214+ switch (taskCancelReason ) {
215+ case STOP :
216+ message = "Stop button pressed" ;
217+ break ;
218+ case BUTTON_RELEASE :
219+ message = "Trigger Released" ;
220+ break ;
221+ case TIMEOUT :
222+ message = "Time Out" ;
223+ break ;
224+ default :
225+ message = taskCancelReason .name ();
226+ break ;
227+ }
228+ CustomPopupWindow customPopupWindow = new CustomPopupWindow (MainActivity .mContext );
229+ customPopupWindow .popupStart (message , false );
230+ }
231+ void inventoryHandler_runtime () {
232+ long timePeriod = (System .currentTimeMillis () - startTimeMillis ) / 1000 ;
233+ if (timePeriod > 0 ) {
234+ if (rfidRunTime != null ) rfidRunTime .setText (String .format ("Run time: %d sec" , timePeriod ));
235+ yieldRate = yield4RateCount ; yield4RateCount = 0 ;
236+ }
237+ }
238+ void inventoryHandler_voltage () {
239+ if (rfidVoltageLevel != null ) rfidVoltageLevel .setText (MainActivity .mCs108Library4a .getBatteryDisplay (true ));
240+ }
241+ void inventoryHandler_tag () {
242+ {
254243 long currentTime = 0 ;
255244 {
256245 while (rx000pkgDataArrary .size () != 0 ) {
@@ -288,7 +277,7 @@ else if (output[0].contains("WW")) {
288277 }
289278 String strExtra1 = null ; if (rx000pkgData .decodedData1 != null ) {
290279 strExtra1 = MainActivity .mCs108Library4a .byteArrayToString (rx000pkgData .decodedData1 );
291- if (strMdid != null && strExtra1 != null && strExtra2 != null ) {
280+ if (strMdid != null && strExtra1 != null && strExtra2 != null ) {
292281 decodeMicronData (strExtra1 , strExtra2 );
293282 }
294283 }
@@ -319,13 +308,13 @@ else if (output[0].contains("WW")) {
319308
320309 int iPc = Integer .parseInt (strPc , 16 );
321310 String strXpc = null ; int iSensorData = ReaderDevice .INVALID_SENSORDATA ; if ((iPc & 0x0200 ) != 0 ) {
322- int iXpcw1 = Integer .parseInt (strEpc .substring (0 ,4 ), 16 );
311+ int iXpcw1 = Integer .parseInt (strEpc .substring (0 , 4 ), 16 );
323312 if ((iXpcw1 & 0x8000 ) != 0 ) {
324- strXpc = strEpc .substring (0 ,8 );
313+ strXpc = strEpc .substring (0 , 8 );
325314 strEpc = strEpc .substring (8 ); strAddresss = strEpc ;
326315 if (strMdid != null ) {
327316 if (strMdid .indexOf ("E280B12" ) == 0 ) {
328- int iXpcw2 = Integer .parseInt (strXpc .substring (4 ,8 ), 16 );
317+ int iXpcw2 = Integer .parseInt (strXpc .substring (4 , 8 ), 16 );
329318 if ((iXpcw1 & 0x8100 ) != 0 && (iXpcw2 & 0xF000 ) == 0 ) {
330319 if ((iXpcw2 & 0x0C00 ) == 0x0C00 ) {
331320 //iXpcw2 |= 0x200;
@@ -339,7 +328,7 @@ else if (output[0].contains("WW")) {
339328 }
340329 }
341330 } else {
342- strXpc = strEpc .substring (0 ,4 );
331+ strXpc = strEpc .substring (0 , 4 );
343332 strEpc = strEpc .substring (4 ); strAddresss = strEpc ;
344333 }
345334 }
@@ -466,15 +455,15 @@ else if (output[0].contains("WW")) {
466455 }
467456 if (bAdd2End ) tagsList .add (readerDevice );
468457 else tagsList .add (0 , readerDevice );
469- SharedObjects .TagsIndex tagsIndex = new SharedObjects .TagsIndex (strAddresss , tagsList .size ()- 1 ); MainActivity .sharedObjects .tagsIndexList .add (tagsIndex ); Collections .sort (MainActivity .sharedObjects .tagsIndexList );
458+ SharedObjects .TagsIndex tagsIndex = new SharedObjects .TagsIndex (strAddresss , tagsList .size () - 1 ); MainActivity .sharedObjects .tagsIndexList .add (tagsIndex ); Collections .sort (MainActivity .sharedObjects .tagsIndexList );
470459 if (serverConnectValid && ALLOW_RTSAVE && true ) {
471460 try {
472461// saveExternalTask = new SaveList2ExternalTask();
473462// saveExternalTask.openServer();
474463 String msgOutput = saveExternalTask .createJSON (null , readerDevice ).toString (); MainActivity .mCs108Library4a .appendToLog ("Json = " + msgOutput );
475464 saveExternalTask .write2Server (msgOutput );
476465
477- // saveExternalTask.closeServer();
466+ // saveExternalTask.closeServer();
478467 MainActivity .mCs108Library4a .appendToLog ("write2Server is done" );
479468 } catch (Exception ex ) {
480469 MainActivity .mCs108Library4a .appendToLog ("write2Server has Exception" );
@@ -504,8 +493,8 @@ else if (output[0].contains("WW")) {
504493 } else {
505494 String stringTemp = "Unique:" + String .valueOf (yield );
506495 if (true ) {
507- float fErrorRate = (float ) MainActivity .mCs108Library4a .invalidata / ( (float ) MainActivity .mCs108Library4a .validata + (float ) MainActivity .mCs108Library4a .invalidata ) * 100 ;
508- stringTemp += "\n E" + String .valueOf (MainActivity .mCs108Library4a .invalidata ) + "/" + String .valueOf (MainActivity .mCs108Library4a .validata ) + "/" + String .valueOf ((int )fErrorRate );
496+ float fErrorRate = (float ) MainActivity .mCs108Library4a .invalidata / ((float ) MainActivity .mCs108Library4a .validata + (float ) MainActivity .mCs108Library4a .invalidata ) * 100 ;
497+ stringTemp += "\n E" + String .valueOf (MainActivity .mCs108Library4a .invalidata ) + "/" + String .valueOf (MainActivity .mCs108Library4a .validata ) + "/" + String .valueOf ((int ) fErrorRate );
509498 } else if (true ) {
510499 stringTemp += "\n E" + String .valueOf (MainActivity .mCs108Library4a .invalidata ) + "," + String .valueOf (MainActivity .mCs108Library4a .invalidUpdata ) + "/" + String .valueOf (MainActivity .mCs108Library4a .validata );
511500 }
@@ -525,7 +514,7 @@ else if (output[0].contains("WW")) {
525514 //}
526515 }
527516 }
528- if (false ) MainActivity .mCs108Library4a .appendToLogView ("playerN = " + (playerN == null ? "Null" : "Valid" ) + ", playerO = " + (playerO == null ? "Null" : "Valid" ) );
517+ if (false ) MainActivity .mCs108Library4a .appendToLogView ("playerN = " + (playerN == null ? "Null" : "Valid" ) + ", playerO = " + (playerO == null ? "Null" : "Valid" ));
529518 if (playerN != null && playerO != null ) {
530519 if (false ) MainActivity .mCs108Library4a .appendToLogView ("requestSound = " + requestSound + ", bStartBeepWaiting = " + bStartBeepWaiting + ", Op=" + playerO .isPlaying () + ", Np=" + playerN .isPlaying ());
531520 if (requestSound && playerO .isPlaying () == false && playerN .isPlaying () == false ) {
@@ -651,7 +640,7 @@ public InventoryRfidTask(Context context, int extra1Bank, int extra2Bank, int da
651640 }
652641 }
653642
654- boolean popStatus = false ; boolean popRequest = false ; Toast mytoast ;
643+ boolean popRequest = false ; Toast mytoast ;
655644 void DeviceConnectTask4InventoryEnding (TaskCancelRReason taskCancelRReason ) {
656645 MainActivity .mCs108Library4a .appendToLog ("serverConnectValid = " + serverConnectValid );
657646 if (serverConnectValid && ALLOW_RTSAVE ) {
0 commit comments