Commit 25e12974 by onuma

まだ2回目が計測できない

parent 932da70f
package jp.agentec.abook.abv.cl.util;
import java.util.TimerTask;
import jp.agentec.abook.abv.bl.common.log.Logger;
import static jp.agentec.abook.abv.cl.util.AlcoholCheckerUtil.F_BLE_COM_INIT;
import static jp.agentec.abook.abv.cl.util.AlcoholCheckerUtil.F_BLE_COM_RD_COMMAND;
import static jp.agentec.abook.abv.cl.util.AlcoholCheckerUtil.F_BLE_COM_RECONNECT1;
import static jp.agentec.abook.abv.cl.util.AlcoholCheckerUtil.F_BLE_COM_RECONNECT2;
import static jp.agentec.abook.abv.cl.util.AlcoholCheckerUtil.F_BLE_COM_RECONNECT3;
import static jp.agentec.abook.abv.cl.util.AlcoholCheckerUtil.F_BLE_COM_RP_COMMAND;
import static jp.agentec.abook.abv.cl.util.AlcoholCheckerUtil.F_BLE_COM_RP_START;
public class AlcoholCheckerTimerTask extends TimerTask {
public static final String TAG = "AlcoholCheckerTimerTask";
private AlcoholCheckerUtil alcoholCheckerUtil;
private AlcoholCheckerUtilListener listener;
public AlcoholCheckerTimerTask( AlcoholCheckerUtil alcoholCheckerUtil,
AlcoholCheckerUtilListener listener) {
this.alcoholCheckerUtil = alcoholCheckerUtil;
this.listener = listener;
}
@Override
public void run() {
//alcoholCheckerUtil.gi_rxlength = 0;
switch (alcoholCheckerUtil.gi_status) {
case F_BLE_COM_INIT:
// BLE Init
break;
case F_BLE_COM_RP_START:
// RP Command Send
//Logger.d(TAG,"F_BLE_COM_RP_START");
//alcoholCheckerUtil.sendMessage(F_BLE_COM_RP_COMMAND);
break;
case AlcoholCheckerUtil.F_BLE_COM_RD_START:
// RD Command Send
//Logger.d(TAG,"F_BLE_COM_RD_START");
//alcoholCheckerUtil.sendMessage(F_BLE_COM_RD_COMMAND);
break;
case AlcoholCheckerUtil.F_BLE_COM_FC_START:
// Fc Command Send
//Logger.d(TAG,"F_BLE_COM_FC_START");
//alcoholCheckerUtil.sendMessage(AlcoholCheckerUtil.F_BLE_COM_FC_COMMAND_F11);
break;
case AlcoholCheckerUtil.F_BLE_COM_FC_START22:
// Fc Command Send
//Logger.d(TAG,"F_BLE_COM_FC_START22");
//alcoholCheckerUtil.sendMessage(AlcoholCheckerUtil.F_BLE_COM_FC_COMMAND_F22);
break;
// case F_BLE_COM_RECONNECT1:
// // ReConecting(NOTIFICATION Disable) // @@@
// alcoholCheckerUtil.NotificationDisable(AlcoholCheckerUtil.RxChar, AlcoholCheckerUtil.CCCD);
// alcoholCheckerUtil.gi_status = F_BLE_COM_RECONNECT2;
// listener.onUpdateStatus("TIMER F_BLE_COM_RECONNECT2");
// break;
// case F_BLE_COM_RECONNECT2:
// // ReConecting(Wait) // @@@
// alcoholCheckerUtil.gi_status = F_BLE_COM_RECONNECT3;
// listener.onUpdateStatus("TIMER F_BLE_COM_RECONNECT3");
// break;
// case F_BLE_COM_RECONNECT3:
// // ReConecting(NOTIFICATION Enable) // @@@
// alcoholCheckerUtil.DescriptorDevice(AlcoholCheckerUtil.RxChar, AlcoholCheckerUtil.CCCD);
// alcoholCheckerUtil.gi_status = F_BLE_COM_RP_START;
// listener.onUpdateStatus("TIMER F_BLE_COM_RP_START");
// break;
default:
// Logger.i(TAG,"AlcohlCheckerTimerTask Timeout");
//
// if (alcoholCheckerUtil.gi_rxretry_cnt < 100) {
// alcoholCheckerUtil.gi_rxretry_cnt++;
// } else {
// alcoholCheckerUtil.gi_status = F_BLE_COM_RECONNECT1;
// //listener.onUpdateStatus("TIMER F_BLE_COM_RECONNECT1");
// }
break;
}
}
}
...@@ -4,16 +4,11 @@ import android.bluetooth.BluetoothGatt; ...@@ -4,16 +4,11 @@ import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor; import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService; import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothProfile;
import android.content.Context; import android.content.Context;
import android.util.Log;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Timer;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import jp.agentec.abook.abv.bl.common.log.Logger; import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.adf.util.StringUtil; import jp.agentec.adf.util.StringUtil;
...@@ -136,16 +131,21 @@ public class AlcoholCheckerUtil { ...@@ -136,16 +131,21 @@ public class AlcoholCheckerUtil {
public BleManagerUtil bleManagerUtil; public BleManagerUtil bleManagerUtil;
private AlcoholCheckerUtilListener listener; private AlcoholCheckerUtilListener listener;
// @Timer // @Timer
private AlcoholCheckerTimerTask alcoholCheckerTimerTask = null; //private AlcoholCheckerTimerTask alcoholCheckerTimerTask = null;
public boolean isConnected = false; public static boolean isConnected = false;
// アルコール濃度
private String strAlcoholValue = "";
// ステータス // ステータス
public static final int fugo_wait_connect = 0; public static final int fugo_init = 0;
public static final int fugo_conntected = 1; public static final int fugo_wait_connect = 1;
public static final int fugo_wait_go = 2; public static final int fugo_conntected = 2;
public static final int fugo_fu_error = 3; public static final int fugo_wait_go = 3;
public static final int fugo_restart = 4; public static final int fugo_fu_error = 4;
public int alcStatus = 0; public static final int fugo_restart = 5;
//public int alcStatus = 0;
public AlcoholCheckerUtil(Context context, AlcoholCheckerUtilListener listener) { public AlcoholCheckerUtil(Context context, AlcoholCheckerUtilListener listener) {
this.context = context; this.context = context;
...@@ -155,7 +155,6 @@ public class AlcoholCheckerUtil { ...@@ -155,7 +155,6 @@ public class AlcoholCheckerUtil {
public void finish() { public void finish() {
isConnected = false; isConnected = false;
stopAlcTimer();
disconnect(true); disconnect(true);
} }
...@@ -208,9 +207,9 @@ public class AlcoholCheckerUtil { ...@@ -208,9 +207,9 @@ public class AlcoholCheckerUtil {
@Override @Override
public void onServicesDiscovered(int status) { public void onServicesDiscovered(int status) {
Logger.i(TAG,"-------------------------------------------------------------- = %s", status); //Logger.i(TAG,"-------------------------------------------------------------- = %s", status);
Logger.i(TAG,"onServicesDiscovered = %s", status); Logger.i(TAG,"onServicesDiscovered = %s", status);
Logger.i(TAG,"-------------------------------------------------------------- = %s", status); //Logger.i(TAG,"-------------------------------------------------------------- = %s", status);
if (status == BluetoothGatt.GATT_SUCCESS) { if (status == BluetoothGatt.GATT_SUCCESS) {
Logger.i(TAG,"BluetoothGatt.GATT_SUCCESS"); Logger.i(TAG,"BluetoothGatt.GATT_SUCCESS");
...@@ -252,11 +251,11 @@ public class AlcoholCheckerUtil { ...@@ -252,11 +251,11 @@ public class AlcoholCheckerUtil {
//startAlcTimer(); //startAlcTimer();
SendMessage(gi_status); SendMessageFromApp(gi_status);
listener.onServicesDiscovered(status); listener.onServicesDiscovered(status);
Logger.i(TAG,"iiiiiiiiiiiiiiiiiiiiiii"); //Logger.i(TAG,"iiiiiiiiiiiiiiiiiiiiiii");
} }
} }
} else { } else {
...@@ -276,10 +275,6 @@ public class AlcoholCheckerUtil { ...@@ -276,10 +275,6 @@ public class AlcoholCheckerUtil {
} }
} }
sub_rx_chk(rx); sub_rx_chk(rx);
// if (gi_status == F_BLE_COM_FC_WAIT) {
// Logger.d(TAG,"FC_WAIT");
// }
} }
@Override @Override
...@@ -339,16 +334,16 @@ public class AlcoholCheckerUtil { ...@@ -339,16 +334,16 @@ public class AlcoholCheckerUtil {
return true; return true;
} }
public int lastSendCmd; // public int lastSendCmd;
public void SendMessage(final int statusa) { public void SendMessageFromApp(final int giStatus) {
// if (statusa == 1 || statusa == 3 || statusa ==8) { if (giStatus == F_BLE_COM_RP_START || giStatus == F_BLE_COM_RD_START || giStatus == F_BLE_COM_FC_START || giStatus == F_BLE_COM_FC_START22) {
// Logger.d(TAG, "SendMessage = " + statusa); Logger.d(TAG, "giStatus = " + giStatus);
// } } else {
// if (lastSendCmd == statusa) { Logger.w(TAG,"UNKOWN COMMAND");
// return; }
// }
lastSendCmd = statusa; //lastSendCmd = giStatus;
Thread thread = new Thread(new Runnable() { Thread thread = new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -357,14 +352,14 @@ public class AlcoholCheckerUtil { ...@@ -357,14 +352,14 @@ public class AlcoholCheckerUtil {
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
//gi_rxlength = 0;
if (statusa == F_BLE_COM_RP_START) { if (giStatus == F_BLE_COM_RP_START) {
sendMessage(F_BLE_COM_RP_COMMAND); sendMessage(F_BLE_COM_RP_COMMAND);
} else if (statusa == F_BLE_COM_RD_START) { } else if (giStatus == F_BLE_COM_RD_START) {
sendMessage(F_BLE_COM_RD_COMMAND); sendMessage(F_BLE_COM_RD_COMMAND);
} else if (statusa == F_BLE_COM_FC_START) { } else if (giStatus == F_BLE_COM_FC_START) {
sendMessage(F_BLE_COM_FC_COMMAND_F11); sendMessage(F_BLE_COM_FC_COMMAND_F11);
} else if (statusa == F_BLE_COM_FC_START22) { } else if (giStatus == F_BLE_COM_FC_START22) {
sendMessage(F_BLE_COM_FC_COMMAND_F22); sendMessage(F_BLE_COM_FC_COMMAND_F22);
} }
} }
...@@ -372,29 +367,6 @@ public class AlcoholCheckerUtil { ...@@ -372,29 +367,6 @@ public class AlcoholCheckerUtil {
thread.start(); thread.start();
} }
/**
* アルコールチェッカーを監視するタイマーを開始する
*/
public void startAlcTimer() {
if (alcoholCheckerTimerTask != null) {
alcoholCheckerTimerTask.cancel();
alcoholCheckerTimerTask = null;
}
alcoholCheckerTimerTask = new AlcoholCheckerTimerTask(this, listener);
Timer timer = new Timer(true);
timer.schedule(alcoholCheckerTimerTask, 0, 500);
}
/**
* タイマー停止
*/
public void stopAlcTimer() {
if (alcoholCheckerTimerTask != null) {
alcoholCheckerTimerTask.cancel();
alcoholCheckerTimerTask = null;
}
}
public void connect(int connectTargetDeviceType, String deviceAddress) { public void connect(int connectTargetDeviceType, String deviceAddress) {
bleManagerUtil.connect(connectTargetDeviceType, deviceAddress); bleManagerUtil.connect(connectTargetDeviceType, deviceAddress);
} }
...@@ -471,10 +443,6 @@ public class AlcoholCheckerUtil { ...@@ -471,10 +443,6 @@ public class AlcoholCheckerUtil {
} }
Logger.i(TAG,"Tx:" + message); Logger.i(TAG,"Tx:" + message);
if (message.equals("01464301F27D04")) {
Logger.d(TAG,"aaaaaaaaaaa");
}
// @Mode Change // @Mode Change
switch (gi_status) { switch (gi_status) {
case F_BLE_COM_RP_START: case F_BLE_COM_RP_START:
...@@ -498,8 +466,6 @@ public class AlcoholCheckerUtil { ...@@ -498,8 +466,6 @@ public class AlcoholCheckerUtil {
break; break;
} }
//SendMessage(gi_status);
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
Logger.w(TAG,e); Logger.w(TAG,e);
} catch (InterruptedException e) { } catch (InterruptedException e) {
...@@ -595,8 +561,7 @@ public class AlcoholCheckerUtil { ...@@ -595,8 +561,7 @@ public class AlcoholCheckerUtil {
sub_rx_data_gen(rxdata); sub_rx_data_gen(rxdata);
// Mode // Mode
int gi = gi_status; int oldgiStatus = gi_status;
//Logger.i(TAG,"sub_rx_chk gi_status = " + gi_status);
switch (gi_status) { switch (gi_status) {
case F_BLE_COM_INIT: case F_BLE_COM_INIT:
// BLE Init // BLE Init
...@@ -620,9 +585,13 @@ public class AlcoholCheckerUtil { ...@@ -620,9 +585,13 @@ public class AlcoholCheckerUtil {
gi_status = F_BLE_COM_RP_START; gi_status = F_BLE_COM_RP_START;
break; break;
} }
//if (gi!=gi_status)
{ if (oldgiStatus == F_BLE_COM_RP_WAIT && gi_status == F_BLE_COM_FC_WAIT && fcWaitMode == 1) {
SendMessage(gi_status); return;
}
if (oldgiStatus != gi_status) {
Logger.i(TAG,"chageStatus:" + gi_status);
SendMessageFromApp(gi_status);
} }
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
Logger.e(TAG,e); Logger.e(TAG,e);
...@@ -669,10 +638,17 @@ public class AlcoholCheckerUtil { ...@@ -669,10 +638,17 @@ public class AlcoholCheckerUtil {
// 01 72 70 02 // 01 72 70 02
// //
// 01 72 70 02
//
boolean go = false; boolean go = false;
if (rxdata[0] == 2 && rxdata[1] == 14 && rxdata[2] == -11 && rxdata[3] == 4) { if (rxdata[0] == 2 && rxdata[1] == 14 && rxdata[2] == -11 && rxdata[3] == 4) {
go = true; go = true;
} }
if (rxdata[0] == 1 && rxdata[1] == 102 && rxdata[2] == 99 && rxdata[3] == 3) {
// nor rp FC command
fcWaitMode = 1;
return si_ret = F_BLE_COM_FC_WAIT;
}
// Command Check // Command Check
Logger.d(TAG,"RP_RENGTH=" + gi_rxlength); Logger.d(TAG,"RP_RENGTH=" + gi_rxlength);
...@@ -715,10 +691,6 @@ public class AlcoholCheckerUtil { ...@@ -715,10 +691,6 @@ public class AlcoholCheckerUtil {
} else { } else {
si_ret = F_BLE_COM_RP_START; si_ret = F_BLE_COM_RP_START;
} }
// リザルトが出たら、FCでRDYに戻す
// si_ret = F_BLE_COM_FC_START;
break; break;
case (byte) 0x0D: case (byte) 0x0D:
// Wait // Wait
...@@ -806,111 +778,85 @@ public class AlcoholCheckerUtil { ...@@ -806,111 +778,85 @@ public class AlcoholCheckerUtil {
return si_ret; return si_ret;
} }
private int fn_rx_fc_chk(byte[] rxdata) {
Logger.d(TAG,"fn_rx_fc_chk");
int si_ret = F_BLE_COM_FC_WAIT;
for (byte b: rxdata) {
Logger.d(TAG,"%s, ", Byte.toString(b));
}
private int fn_rx_fc_chk2(byte[] rxdata) { // 01 72 70 02 rp 上位
Logger.d(TAG, "fn_rx_fc_chk2"); // 01 114 112 02
int si_ret = F_BLE_COM_FC_WAIT22;
// 2 14 -11 4 rp 下部
// 2 E F5 4
// 動作モード、進行状況、チェックサム
// 01 102 99 3 fc
//
if (fcWaitMode == 0) { if (fcWaitMode == 0) {
if (rxdata[0] == 1 && rxdata[1] == 102 && rxdata[2] == 99 && rxdata[3] == 3) { if (rxdata[0] == 1 && rxdata[1] == 102 && rxdata[2] == 99 && rxdata[3] == 3) {
fcWaitMode = 1; fcWaitMode = 1;
} }
if (rxdata[0] == 1 && rxdata[1] == 114 && rxdata[2] == 112 && rxdata[3] == 2) {
si_ret = F_BLE_COM_RP_WAIT;
return si_ret;
}
} else if (fcWaitMode == 1) { } else if (fcWaitMode == 1) {
if (rxdata.length == 5) { if (rxdata.length == 5) {
// 49 05 32 35 4 // 49 05 32 35 4
// 0x31 05 20 23 4 実行完了 本体動作モード リアルタイム測定進行状況 チェックサム 4 // 0x31 05 20 23 4 実行完了 本体動作モード リアルタイム測定進行状況 チェックサム 4
if (rxdata[0] == 49 && rxdata[1] == 2) { if (rxdata[0] ==49 && rxdata[1] == 2) {
Logger.i(TAG, "------FC2成功"); //Logger.i(TAG, "------FC失敗");
si_ret = F_BLE_COM_RP_START;
} }
//if (rxdata[1] == 0x05)
listener.onGetDeviceInfo(alcol);
// if (StringUtil.isNullOrEmpty(alcol)) { if(!StringUtil.isNullOrEmpty(strAlcoholValue)) {
// // 空文字の時は BLEに戻す // 測定値あれば成功
// si_ret = F_BLE_COM_FC_START; listener.onGetDeviceInfo(strAlcoholValue);
// } else { }
// if (status == F_BLE_COM_FC_WAIT22) {
// // RDY戻し待ちの場合は
// //si_ret = F_BLE_COM_FC_START22;
// si_ret = F_BLE_COM_RP_START;
// } else {
// //si_ret = F_BLE_COM_FC_START22;
// }
// si_ret = F_BLE_COM_RP_START;
// }
fcWaitMode = 0; fcWaitMode = 0;
si_ret = F_BLE_COM_RP_START;
//si_ret = F_BLE_COM_FC_START22;
//SendMessage(si_ret);
//listener.onGetDeviceInfo(alcol);
} }
} }
return si_ret; return si_ret;
} }
private int fn_rx_fc_chk(byte[] rxdata) {
Logger.d(TAG,"fn_rx_fc_chk");
int si_ret = F_BLE_COM_FC_WAIT;
private int fn_rx_fc_chk2(byte[] rxdata) {
Logger.d(TAG, "fn_rx_fc_chk2");
for (byte b: rxdata) { for (byte b: rxdata) {
Logger.d(TAG,"%s, ", Byte.toString(b)); Logger.d(TAG,"%s, ", Byte.toString(b));
} }
int si_ret = F_BLE_COM_FC_WAIT22;
// 01 72 70 02 rp 上位
// 01 114 112 02
// 2 14 -11 4 rp 下部
// 2 E F5 4
// 動作モード、進行状況、チェックサム
// 01 102 99 3 fc
//
if (fcWaitMode == 0) { if (fcWaitMode == 0) {
if (rxdata[0] == 1 && rxdata[1] == 102 && rxdata[2] == 99 && rxdata[3] == 3) { if (rxdata[0] == 1 && rxdata[1] == 102 && rxdata[2] == 99 && rxdata[3] == 3) {
fcWaitMode = 1; fcWaitMode = 1;
} }
} else if (fcWaitMode == 1) { } else if (fcWaitMode == 1) {
if (rxdata.length == 5) { if (rxdata.length == 5) {
if (rxdata.length == 5) {
// 49 05 32 35 4 // 49 05 32 35 4
// 0x31 05 20 23 4 実行完了 本体動作モード リアルタイム測定進行状況 チェックサム 4 // 0x31 05 20 23 4 実行完了 本体動作モード リアルタイム測定進行状況 チェックサム 4
if (rxdata[0] ==49 && rxdata[1] == 2) { if (rxdata[0] == 49 && rxdata[1] == 2) {
//Logger.i(TAG, "------FC失敗"); Logger.i(TAG, "RDYに戻る");
//si_ret = F_BLE_COM_RP_START; si_ret = F_BLE_COM_RP_START;
//return si_ret; }
}
//listener.onGetDeviceInfo(alcol);
// if (StringUtil.isNullOrEmpty(alcol)) {
// // 空文字の時は BLEに戻す
// si_ret = F_BLE_COM_FC_START;
// //} else {
//// if (status == F_BLE_COM_FC_WAIT22) {
//// // RDY戻し待ちの場合は
//// //si_ret = F_BLE_COM_FC_START22;
//// si_ret = F_BLE_COM_RP_START;
//// } else {
//// //si_ret = F_BLE_COM_FC_START22;
//// }
// //si_ret = F_BLE_COM_RP_START;
// }
fcWaitMode = 0;
//si_ret = F_BLE_COM_FC_START22; if (!StringUtil.isNullOrEmpty(strAlcoholValue)) {
//SendMessage(si_ret); // 測定値あれば成功
//listener.onGetDeviceInfo(alcol); listener.onGetDeviceInfo(strAlcoholValue);
}
fcWaitMode = 0;
si_ret = F_BLE_COM_RP_START;
}
} }
} }
return si_ret; return si_ret;
} }
private String alcol = "";
/* @RD Command Check */ /* @RD Command Check */
private int fn_rx_rd_chk(byte[] rxdata) { private int fn_rx_rd_chk(byte[] rxdata) {
Logger.d(TAG,"fn_rx_rd_chk"); Logger.d(TAG,"fn_rx_rd_chk");
...@@ -920,10 +866,23 @@ public class AlcoholCheckerUtil { ...@@ -920,10 +866,23 @@ public class AlcoholCheckerUtil {
String str_msg; String str_msg;
si_ret = F_BLE_COM_RD_WAIT; si_ret = F_BLE_COM_RD_WAIT;
for (byte b: rxdata) {
Logger.d(TAG,"%s, ", Byte.toString(b));
}
// 1 114 100 22
// 0x01 0x72 0x64, 0x16
// 1, 114, 100, 22, -1, -1, 0, -1, -1, 5, 3, 74, -1, -1, -1, -1, -1, -1, 45, 4
// 1, 114, 100, 22, -1, -1, 0, 5, 3, 75, -1, -1, -1, -1, -1, -1, 46 4
boolean go = false;
if (gi_rxlength >= 24 && rxdata[rxdata.length-1] == 4) {
go = true;
}
// Command Check // Command Check
Logger.d(TAG,"RD_LENGTH="+gi_rxlength); Logger.d(TAG,"RD_LENGTH="+gi_rxlength);
if (gi_rxlength == F_RX_RD_LENGTH) { if (gi_rxlength == F_RX_RD_LENGTH || go) {
// 0x72, 0x64 // 0x72, 0x64
if ((gb_rxdat[F_RX_COMMAND_POS] == F_RD_COMMAND_MSB) && (gb_rxdat[(F_RX_COMMAND_POS + 1)] == F_RD_COMMAND_LSB)) { if ((gb_rxdat[F_RX_COMMAND_POS] == F_RD_COMMAND_MSB) && (gb_rxdat[(F_RX_COMMAND_POS + 1)] == F_RD_COMMAND_LSB)) {
sb_data = gb_rxdat[F_RX_RD_DATA_POS]; sb_data = gb_rxdat[F_RX_RD_DATA_POS];
...@@ -948,7 +907,7 @@ public class AlcoholCheckerUtil { ...@@ -948,7 +907,7 @@ public class AlcoholCheckerUtil {
Logger.d(TAG,"測定結果表示"); Logger.d(TAG,"測定結果表示");
//str_msg += "[mg/L]"; //str_msg += "[mg/L]";
// 0x0C 測定結果表示状態"); // 0x0C 測定結果表示状態");
alcol = str_msg; strAlcoholValue = str_msg;
si_ret = F_BLE_COM_FC_START22; si_ret = F_BLE_COM_FC_START22;
return si_ret; return si_ret;
...@@ -958,8 +917,9 @@ public class AlcoholCheckerUtil { ...@@ -958,8 +917,9 @@ public class AlcoholCheckerUtil {
si_ret = F_BLE_COM_RP_START; si_ret = F_BLE_COM_RP_START;
} }
} else { } else {
Logger.e(TAG,"RD Error"); //Logger.e(TAG,"RD Error");
si_ret = F_BLE_COM_RP_START; //si_ret = F_BLE_COM_RP_START;
// 失敗の場合もエラーに戻す
} }
} else { } else {
if (gi_rxlength < F_RX_RD_LENGTH) { if (gi_rxlength < F_RX_RD_LENGTH) {
......
...@@ -161,16 +161,21 @@ public class BleManagerUtil { ...@@ -161,16 +161,21 @@ public class BleManagerUtil {
// キャラクタリスティック変更が通知されたときの処理 // キャラクタリスティック変更が通知されたときの処理
@Override @Override
public void onCharacteristicChanged( BluetoothGatt gatt, BluetoothGattCharacteristic characteristic ) { public void onCharacteristicChanged(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic ) {
Logger.d(TAG,"onCharacteristicChanged"); Logger.d(TAG,"onCharacteristicChanged");
try {
//if (mListener != null)
{
mListener.onCharacteristicChanged(gatt, characteristic); mListener.onCharacteristicChanged(gatt, characteristic);
} // runOnUiThread(new Runnable() {
} catch (Exception e) { // @Override
Logger.e(TAG,e); // public void run() {
} // try {
// if (mListener != null) {
// mListener.onCharacteristicChanged(gatt, characteristic);
// }
// } catch (Exception e) {
// Logger.e(TAG,e);
// }
// }
// });
} }
@Override @Override
......
...@@ -188,7 +188,9 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -188,7 +188,9 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
// 二重起動防止フラグ(アルコールチェッカー) // 二重起動防止フラグ(アルコールチェッカー)
private boolean isAlcBlock = false; private boolean isAlcBlock = false;
// 終了フラグ // 終了フラグ
private boolean isFinish = false; //private boolean isFinish = false;
private int checkerStatus = AlcoholCheckerUtil.fugo_init;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -277,58 +279,59 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -277,58 +279,59 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
@Override @Override
public void onServicesDiscovered(int status) { public void onServicesDiscovered(int status) {
Logger.d(TAG, "onServicesDiscovered = %s", status); Logger.d(TAG, "onServicesDiscovered = %s", status);
if (alcoholCheckerUtil.alcStatus == AlcoholCheckerUtil.fugo_wait_connect) {
alcoholCheckerUtil.alcStatus = AlcoholCheckerUtil.fugo_conntected; if (checkerStatus == AlcoholCheckerUtil.fugo_wait_connect) {
checkerStatus = AlcoholCheckerUtil.fugo_conntected;
} else { } else {
return; return;
} }
// runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
// @Override @Override
// public void run() { public void run() {
if (mWaitingDialog != null) { if (mWaitingDialog != null) {
mWaitingDialog.dismiss(); mWaitingDialog.dismiss();
mWaitingDialog = null; mWaitingDialog = null;
} }
alcoholCheckerUtil.isConnected = true; AlcoholCheckerUtil.isConnected = true;
// 測定開始ボタン押し待ち // 測定開始ボタン押し待ち
showWaitMeasureDialog(getString(R.string.alcohol_checker), getString(R.string.connection_completed)); showWaitMeasureDialog(getString(R.string.alcohol_checker), getString(R.string.connection_completed));
// } }
// }); });
} }
@Override @Override
public void onGetDeviceInfo(final String alcohol) { public void onGetDeviceInfo(final String alcohol) {
// runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
// @Override @Override
// public void run() { public void run() {
Logger.d(TAG, "測定完了 = " + alcohol); Logger.d(TAG, "測定完了 = " + alcohol);
if (!alcohol.equals("")) { if (!alcohol.equals("")) {
successAfterAbookCheckApi(alcohol, false); successAfterAbookCheckApi(alcohol, false);
} else { } else {
} }
// } }
// }); });
} }
@Override @Override
public void onStartMeasurement() { public void onStartMeasurement() {
Logger.d(TAG, "onStartMeasurement"); Logger.d(TAG, "onStartMeasurement");
if (alcoholCheckerUtil.alcStatus == AlcoholCheckerUtil.fugo_conntected) { if (checkerStatus == AlcoholCheckerUtil.fugo_conntected) {
alcoholCheckerUtil.alcStatus = AlcoholCheckerUtil.fugo_wait_go; checkerStatus = AlcoholCheckerUtil.fugo_wait_go;
} else { } else {
return; return;
} }
// runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
// @Override @Override
// public void run() { public void run() {
if (mWaitMeasureDialog != null) { if (mWaitMeasureDialog != null) {
mWaitMeasureDialog.dismiss(); mWaitMeasureDialog.dismiss();
mWaitMeasureDialog = null; mWaitMeasureDialog = null;
} }
showMeasureDialog(getString(R.string.alcohol_checker), getString(R.string.wait_breathe)); showMeasureDialog(getString(R.string.alcohol_checker), getString(R.string.wait_breathe));
// } }
// }); });
} }
@Override @Override
...@@ -340,15 +343,17 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -340,15 +343,17 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
} else if (status == 19) { } else if (status == 19) {
message = getString(R.string.msg_disconnected_device); message = getString(R.string.msg_disconnected_device);
} }
if (alcoholCheckerUtil != null) {
alcoholCheckerUtil.isConnected = false; alcoholCheckerUtil.isConnected = false;
errorAfterAbookCheckApi(message); }
errorAfterAbookCheckApi(message,true);
} }
@Override @Override
public void onMeasurementError(String text) { public void onMeasurementError(String text) {
Logger.d(TAG,"onMeasurementError = " + text); Logger.d(TAG,"onMeasurementError = " + text);
if (mMeasureDialog != null) { if (mMeasureDialog != null) {
alcoholCheckerUtil.alcStatus = AlcoholCheckerUtil.fugo_fu_error; checkerStatus = AlcoholCheckerUtil.fugo_fu_error;
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -360,22 +365,22 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -360,22 +365,22 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
@Override @Override
public void onBreakDownError(String text) { public void onBreakDownError(String text) {
errorAfterAbookCheckApi(getString(R.string.msg_break_down_device)); errorAfterAbookCheckApi(getString(R.string.msg_break_down_device),true);
} }
@Override @Override
public void onLowBatteryError(String text) { public void onLowBatteryError(String text) {
errorAfterAbookCheckApi(getString(R.string.msg_low_battery)); errorAfterAbookCheckApi(getString(R.string.msg_low_battery),true);
} }
@Override @Override
public void onOverUsedError(String text) { public void onOverUsedError(String text) {
errorAfterAbookCheckApi(getString(R.string.msg_over_used)); errorAfterAbookCheckApi(getString(R.string.msg_over_used),true);
} }
@Override @Override
public void onPowerOff(String text) { public void onPowerOff(String text) {
errorAfterAbookCheckApi(getString(R.string.msg_power_off)); errorAfterAbookCheckApi(getString(R.string.msg_power_off),true);
} }
}); });
} }
...@@ -407,7 +412,6 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -407,7 +412,6 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
* @param value 各種デバイスから取得した値 * @param value 各種デバイスから取得した値
*/ */
private void successAfterAbookCheckApi(final String value, boolean isFinish) { private void successAfterAbookCheckApi(final String value, boolean isFinish) {
this.isFinish = isFinish;
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -415,11 +419,9 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -415,11 +419,9 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
JSONObject responseJson = new JSONObject(); JSONObject responseJson = new JSONObject();
responseJson.put(ABookKeys.TASK_QUESTION_ID, mQid); responseJson.put(ABookKeys.TASK_QUESTION_ID, mQid);
responseJson.put("value", value); responseJson.put("value", value);
// alcoholCheckerUtil.sendMessage(AlcoholCheckerUtil.F_BLE_COM_FC_COMMAND_F11);
//alcoholCheckerUtil.sendMessage(AlcoholCheckerUtil.F_BLE_COM_FC_COMMAND_F22);
//alcoholCheckerUtil.gi_status = AlcoholCheckerUtil.F_BLE_COM_FC_START22;
afterABookCheckApi(mCmd, "", 0, "", responseJson.toString()); afterABookCheckApi(mCmd, "", 0, "", responseJson.toString());
Logger.i(TAG, "successAfterAbookCheckAip JSON [%s]", responseJson.toString()); Logger.i(TAG, "successAfterAbookCheckAip JSON [%s]", responseJson.toString());
isAlcBlock = false;
} }
}); });
} }
...@@ -428,17 +430,18 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -428,17 +430,18 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
* 各デバイスからエラー(接続不能など)発生した場合、HTML側にコールする * 各デバイスからエラー(接続不能など)発生した場合、HTML側にコールする
* @param errorMessage 各種デバイスから取得した値 * @param errorMessage 各種デバイスから取得した値
*/ */
private void errorAfterAbookCheckApi(final String errorMessage) { private void errorAfterAbookCheckApi(final String errorMessage, final boolean isSendResult) {
// エラーの時は終了 // エラーの時は終了
isFinish = true;
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
dismissAllDialog(); dismissAllDialog();
//alcoholCheckerUtil.gi_status = AlcoholCheckerUtil.F_BLE_COM_FC_START; alcoholCheckerUtil.SendMessageFromApp(AlcoholCheckerUtil.F_BLE_COM_FC_START);
//alcoholCheckerUtil.sendMessage(AlcoholCheckerUtil.F_BLE_COM_FC_COMMAND_F11); if (isSendResult) {
afterABookCheckApi(mCmd, "", 1, errorMessage, null); afterABookCheckApi(mCmd, "", 1, errorMessage, null);
}
Logger.e(TAG,errorMessage); Logger.e(TAG,errorMessage);
isAlcBlock = false;
} }
}); });
} }
...@@ -456,8 +459,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -456,8 +459,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Logger.i(TAG, "waiting Dialog stop click"); Logger.i(TAG, "waiting Dialog stop click");
successAfterAbookCheckApi("", true); errorAfterAbookCheckApi("", false);
//errorAfterAbookCheckApi("");
} }
}); });
mWaitingDialog.show(); mWaitingDialog.show();
...@@ -476,8 +478,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -476,8 +478,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Logger.i(TAG, "waiting mWaitMeasureDialog stop clickf"); Logger.i(TAG, "waiting mWaitMeasureDialog stop clickf");
successAfterAbookCheckApi("", false); errorAfterAbookCheckApi("", false);
//errorAfterAbookCheckApi("");
} }
}); });
mWaitMeasureDialog.show(); mWaitMeasureDialog.show();
...@@ -496,8 +497,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -496,8 +497,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Logger.i(TAG, "wait mMeasureDialog stop click"); Logger.i(TAG, "wait mMeasureDialog stop click");
successAfterAbookCheckApi("", false); errorAfterAbookCheckApi("", false);
//errorAfterAbookCheckApi("");
} }
}); });
mMeasureDialog.show(); mMeasureDialog.show();
...@@ -548,14 +548,14 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -548,14 +548,14 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
String deviceAddress = getABVUIDataCache().getPairingBluetoothDeviceAddress(Constant.DeviceType.alcoholChecker); String deviceAddress = getABVUIDataCache().getPairingBluetoothDeviceAddress(Constant.DeviceType.alcoholChecker);
if (StringUtil.isNullOrEmpty(deviceAddress)) { if (StringUtil.isNullOrEmpty(deviceAddress)) {
// 登録されているアルコールチェッカーが無い場合はエラー // 登録されているアルコールチェッカーが無い場合はエラー
errorAfterAbookCheckApi(getString(R.string.msg_pairing_device_no_info)); errorAfterAbookCheckApi(getString(R.string.msg_pairing_device_no_info), true);
return; return;
} }
BluetoothPairingDeviceInfoDto dto = getABVUIDataCache().getPairingBluetoothDeviceInfo(Constant.DeviceType.alcoholChecker); BluetoothPairingDeviceInfoDto dto = getABVUIDataCache().getPairingBluetoothDeviceInfo(Constant.DeviceType.alcoholChecker);
alcoholCheckerUtil.alcStatus = AlcoholCheckerUtil.fugo_wait_connect; checkerStatus = AlcoholCheckerUtil.fugo_wait_connect;
if (alcoholCheckerUtil.isConnected) { if (AlcoholCheckerUtil.isConnected) {
Logger.d(TAG, "isConnection = true"); Logger.d(TAG, "isConnection = true");
alcoholCheckerUtil.alcStatus = AlcoholCheckerUtil.fugo_conntected; checkerStatus = AlcoholCheckerUtil.fugo_conntected;
showWaitMeasureDialog(getString(R.string.alcohol_checker), getString(R.string.connection_completed)); showWaitMeasureDialog(getString(R.string.alcohol_checker), getString(R.string.connection_completed));
} else { } else {
Logger.d(TAG, "isConnection = false"); Logger.d(TAG, "isConnection = false");
...@@ -593,6 +593,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -593,6 +593,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
@Override @Override
protected void onResume() { protected void onResume() {
Logger.i(TAG,"onResume");
super.onResume(); super.onResume();
try { try {
if (readingLogFlg) { if (readingLogFlg) {
...@@ -625,41 +626,40 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -625,41 +626,40 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
}
@Override
protected void onStop() {
Logger.d(TAG,"-------------------------------------------------"); Logger.d(TAG,"-------------------------------------------------");
Logger.d(TAG,"onStop"); Logger.i(TAG,"onPause");
Logger.d(TAG,"-------------------------------------------------"); Logger.d(TAG,"-------------------------------------------------");
super.onStop();
if (!DeviceInfo.isForegrdound(getApplicationContext()) && readingLogFlg) {
ContentReadingLogLogic logic = AbstractLogic.getLogic(ContentReadingLogLogic.class);
logic.pauseContentReadLog(contentId);
}
// ダイアログ閉じる // ダイアログ閉じる
dismissAllDialog(); dismissAllDialog();
// タイマーにFCコマンド // タイマーにFCコマンド
if (alcoholCheckerUtil != null) { if (alcoholCheckerUtil != null) {
isAlcBlock = false; // false にしないと2回目押せない alcoholCheckerUtil.SendMessageFromApp(AlcoholCheckerUtil.F_BLE_COM_FC_START);
//alcoholCheckerUtil.gi_status = AlcoholCheckerUtil.F_BLE_COM_FC_START; isAlcBlock = false;
handler.postDelayed(new Runnable() { handler.postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
// チェッカーも終了 // チェッカーも終了
//alcoholCheckerUtil.finish(); alcoholCheckerUtil.finish();
} }
}, 1000); }, 1000);
} }
} }
@Override @Override
protected void onStop() {
super.onStop();
Logger.d(TAG,"onStop");
if (!DeviceInfo.isForegrdound(getApplicationContext()) && readingLogFlg) {
ContentReadingLogLogic logic = AbstractLogic.getLogic(ContentReadingLogLogic.class);
logic.pauseContentReadLog(contentId);
}
}
@Override
protected void onDestroy() { protected void onDestroy() {
Logger.d(TAG,"-------------------------------------------------");
Logger.d(TAG,"onDestroy"); Logger.d(TAG,"onDestroy");
Logger.d(TAG,"-------------------------------------------------");
if (readingLogFlg) { if (readingLogFlg) {
ContentReadingLogLogic logic = AbstractLogic.getLogic(ContentReadingLogLogic.class); ContentReadingLogLogic logic = AbstractLogic.getLogic(ContentReadingLogLogic.class);
logic.endContentReadLog(contentId); logic.endContentReadLog(contentId);
...@@ -1391,7 +1391,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -1391,7 +1391,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
ABookKeys.CMD_DELETE_TASK_REPORT , ABookKeys.CMD_CANCEL_TASK_REPORT, ABookKeys.CMD_LOCAL_SAVE_TASK_REPORT) ABookKeys.CMD_DELETE_TASK_REPORT , ABookKeys.CMD_CANCEL_TASK_REPORT, ABookKeys.CMD_LOCAL_SAVE_TASK_REPORT)
){ ){
// 作業一覧に戻る時,bluetoothを切断する。 // 作業一覧に戻る時,bluetoothを切断する。
//disconnectBluetoothDevice(); disconnectBluetoothDevice();
} }
} catch(Exception e) { } catch(Exception e) {
...@@ -1971,9 +1971,9 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -1971,9 +1971,9 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
private void disconnectBluetoothDevice() { private void disconnectBluetoothDevice() {
Logger.d(TAG, "disconnectBluetoothDevice"); Logger.d(TAG, "disconnectBluetoothDevice");
// if (alcoholCheckerUtil != null) { if (alcoholCheckerUtil != null) {
// alcoholCheckerUtil.finish(); alcoholCheckerUtil.finish();
// alcoholCheckerUtil = null; alcoholCheckerUtil = null;
// } }
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment