优化心率血氧佩戴回应,发送接口应遵循manager方式发送,而不是helper层去处理回应
This commit is contained in:
parent
53e8df1683
commit
68ebe94bcb
@ -278,7 +278,12 @@ public class ASR5515DeviceManager {
|
|||||||
@Override
|
@Override
|
||||||
public void onWearDetectionResponse(ASR5515Protocol.WearDetectionResponse response) {
|
public void onWearDetectionResponse(ASR5515Protocol.WearDetectionResponse response) {
|
||||||
if (wearDetectionListener != null) {
|
if (wearDetectionListener != null) {
|
||||||
mainHandler.post(() -> wearDetectionListener.onWearDetectionResponse(response));
|
mainHandler.post(() -> {
|
||||||
|
// 发送佩戴检测接收确认
|
||||||
|
onWearDetectionResponseReceived(response.sn);
|
||||||
|
// 调用佩戴检测监听器
|
||||||
|
wearDetectionListener.onWearDetectionResponse(response);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -303,7 +308,17 @@ public class ASR5515DeviceManager {
|
|||||||
@Override
|
@Override
|
||||||
public void onAlgoResultReceived(final ASR5515Protocol.AlgoResultResponse response) {
|
public void onAlgoResultReceived(final ASR5515Protocol.AlgoResultResponse response) {
|
||||||
if (algoResultListener != null) {
|
if (algoResultListener != null) {
|
||||||
mainHandler.post(() -> algoResultListener.onAlgoResultReceived(response));
|
mainHandler.post(() -> {
|
||||||
|
// 根据算法结果类型发送接收确认
|
||||||
|
if (response.type == ASR5515Protocol.AlgoResultResponse.TYPE_HEART_RATE) {
|
||||||
|
// 发送心率接收确认
|
||||||
|
onHeartRateDataReceived(response.sn);
|
||||||
|
} else if (response.type == ASR5515Protocol.AlgoResultResponse.TYPE_SPO2) {
|
||||||
|
// 发送血氧接收确认
|
||||||
|
onSpO2DataReceived(response.sn);
|
||||||
|
}
|
||||||
|
algoResultListener.onAlgoResultReceived(response);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -535,7 +550,7 @@ public class ASR5515DeviceManager {
|
|||||||
* 设置采集频率
|
* 设置采集频率
|
||||||
* @param freq 频率值
|
* @param freq 频率值
|
||||||
*/
|
*/
|
||||||
public void setCollectFreq(byte freq) {
|
public void setCollectFreq(byte len, byte freq) {
|
||||||
wakeupDevice();
|
wakeupDevice();
|
||||||
serialPortHelper.setCollectFreq(freq);
|
serialPortHelper.setCollectFreq(freq);
|
||||||
}
|
}
|
||||||
@ -572,6 +587,19 @@ public class ASR5515DeviceManager {
|
|||||||
serialPortHelper.sendWearDetectionRequest();
|
serialPortHelper.sendWearDetectionRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onWearDetectionResponseReceived(short sn) {
|
||||||
|
if (!isDeviceReady()) {
|
||||||
|
LogManager.e(TAG, "设备未就绪,无法发送佩戴检测接收确认");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
wakeupDevice();
|
||||||
|
serialPortHelper.onWearDetectionResponseReceived(sn);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogManager.e(TAG, "发送佩戴检测接收确认失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 发送GH3220开启测量请求
|
* 发送GH3220开启测量请求
|
||||||
* @param type 测量类型,参考ASR5515Protocol.GH3220MeasureType
|
* @param type 测量类型,参考ASR5515Protocol.GH3220MeasureType
|
||||||
@ -592,43 +620,41 @@ public class ASR5515DeviceManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送心率接收确认
|
* 发送心率接收确认
|
||||||
|
*
|
||||||
* @param sn 序列号
|
* @param sn 序列号
|
||||||
* @return true 如果发送成功
|
|
||||||
*/
|
*/
|
||||||
public boolean onHeartRateDataReceived(short sn) {
|
public void onHeartRateDataReceived(short sn) {
|
||||||
if (!isDeviceReady()) {
|
if (!isDeviceReady()) {
|
||||||
LogManager.e(TAG, "设备未就绪,无法发送心率接收确认");
|
LogManager.e(TAG, "设备未就绪,无法发送心率接收确认");
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
wakeupDevice();
|
wakeupDevice();
|
||||||
byte[] request = ASR5515Protocol.createHeartRateReceivedRequest(sn);
|
byte[] request = ASR5515Protocol.createHeartRateReceivedRequest(sn);
|
||||||
return safeSendData(request);
|
safeSendData(request);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogManager.e(TAG, "发送心率接收确认失败: " + e.getMessage());
|
LogManager.e(TAG, "发送心率接收确认失败: " + e.getMessage());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送血氧接收确认
|
* 发送血氧接收确认
|
||||||
|
*
|
||||||
* @param sn 序列号
|
* @param sn 序列号
|
||||||
* @return true 如果发送成功
|
|
||||||
*/
|
*/
|
||||||
public boolean onSpO2DataReceived(short sn) {
|
public void onSpO2DataReceived(short sn) {
|
||||||
if (!isDeviceReady()) {
|
if (!isDeviceReady()) {
|
||||||
LogManager.e(TAG, "设备未就绪,无法发送血氧接收确认");
|
LogManager.e(TAG, "设备未就绪,无法发送血氧接收确认");
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
wakeupDevice();
|
wakeupDevice();
|
||||||
byte[] request = ASR5515Protocol.createSpO2ReceivedRequest(sn);
|
byte[] request = ASR5515Protocol.createSpO2ReceivedRequest(sn);
|
||||||
return safeSendData(request);
|
safeSendData(request);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogManager.e(TAG, "发送血氧接收确认失败: " + e.getMessage());
|
LogManager.e(TAG, "发送血氧接收确认失败: " + e.getMessage());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +208,9 @@ public class ASR5515Protocol {
|
|||||||
public static final short CMD_DYNAMIC_MEASURE = 0x00CF; // 动态测量 [207 0 0]
|
public static final short CMD_DYNAMIC_MEASURE = 0x00CF; // 动态测量 [207 0 0]
|
||||||
public static final short CMD_DYNAMIC_MEASURE_RESP = 0x00D0; // 动态测量响应 [208 sn 0]
|
public static final short CMD_DYNAMIC_MEASURE_RESP = 0x00D0; // 动态测量响应 [208 sn 0]
|
||||||
public static final short CMD_WEAR_DETECTION = 0x0105; // 佩戴检测查询 [261 0 0]
|
public static final short CMD_WEAR_DETECTION = 0x0105; // 佩戴检测查询 [261 0 0]
|
||||||
|
public static final short CMD_WEAR_DETECTION_RESP_CHECK = 0x0106; // 佩戴检测响应 [262 sn len 0/1]
|
||||||
public static final short CMD_WEAR_DETECTION_RESP = 0x0108; // 佩戴检测响应 [264 sn len 0/1]
|
public static final short CMD_WEAR_DETECTION_RESP = 0x0108; // 佩戴检测响应 [264 sn len 0/1]
|
||||||
|
public static final short CMD_WEAR_ACK = 0x0109; // 佩戴检测确认 [265 0 0]
|
||||||
public static final short CMD_GH3220_MEASURE_START = 0x01F5; // GH3220开启测量 [501 0 len type]
|
public static final short CMD_GH3220_MEASURE_START = 0x01F5; // GH3220开启测量 [501 0 len type]
|
||||||
public static final short CMD_GH3220_MEASURE_START_RESP = 0x01F6; // GH3220开启测量响应 [502 sn len status]
|
public static final short CMD_GH3220_MEASURE_START_RESP = 0x01F6; // GH3220开启测量响应 [502 sn len status]
|
||||||
public static final short CMD_GH3220_MEASURE_STOP = 0x01F7; // GH3220停止测量 [503 0 len type]
|
public static final short CMD_GH3220_MEASURE_STOP = 0x01F7; // GH3220停止测量 [503 0 len type]
|
||||||
@ -601,17 +603,29 @@ public class ASR5515Protocol {
|
|||||||
return createFrame(Commands.CMD_WEAR_DETECTION, (short) 0, new byte[]{});
|
return createFrame(Commands.CMD_WEAR_DETECTION, (short) 0, new byte[]{});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 创建佩戴检测确认请求帧 [265 0 0]
|
||||||
|
public static byte[] createWearAckRequest(short sn) {
|
||||||
|
return createFrame(Commands.CMD_WEAR_ACK, sn, new byte[]{});
|
||||||
|
}
|
||||||
|
|
||||||
// 佩戴检测响应类
|
// 佩戴检测响应类
|
||||||
public static class WearDetectionResponse {
|
public static class WearDetectionResponse {
|
||||||
public boolean isWearing; // true表示已佩戴,false表示未佩戴
|
public boolean isWearing; // true表示已佩戴,false表示未佩戴
|
||||||
|
public short sn;
|
||||||
|
|
||||||
public WearDetectionResponse( boolean isWearing) {
|
public WearDetectionResponse(boolean isWearing, short sn) {
|
||||||
this.isWearing = isWearing;
|
this.isWearing = isWearing;
|
||||||
|
this.sn = sn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public short getSn() {
|
||||||
|
return sn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "WearDetectionResponse{" +
|
return "WearDetectionResponse{" +
|
||||||
|
"sn=" + sn +
|
||||||
", isWearing=" + isWearing +
|
", isWearing=" + isWearing +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
@ -619,11 +633,15 @@ public class ASR5515Protocol {
|
|||||||
|
|
||||||
// 解析佩戴检测响应帧 [262 sn len 0/1]
|
// 解析佩戴检测响应帧 [262 sn len 0/1]
|
||||||
public static WearDetectionResponse parseWearDetectionResponse(Frame frame) {
|
public static WearDetectionResponse parseWearDetectionResponse(Frame frame) {
|
||||||
if (frame == null || frame.command != Commands.CMD_WEAR_DETECTION_RESP ) {
|
if (frame == null || (frame.command != Commands.CMD_WEAR_DETECTION_RESP_CHECK &&
|
||||||
|
frame.command != Commands.CMD_WEAR_DETECTION_RESP)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (frame.data == null || frame.data.length < 1) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
boolean isWearing = frame.data[0] == 1;
|
boolean isWearing = frame.data[0] == 1;
|
||||||
return new WearDetectionResponse(isWearing);
|
return new WearDetectionResponse(isWearing, frame.sn);
|
||||||
}
|
}
|
||||||
|
|
||||||
// GH3220测量类型常量
|
// GH3220测量类型常量
|
||||||
@ -698,12 +716,14 @@ public class ASR5515Protocol {
|
|||||||
public static final int TYPE_SPO2 = 1; // 血氧类型
|
public static final int TYPE_SPO2 = 1; // 血氧类型
|
||||||
|
|
||||||
public int type; // 算法类型:0-心率,1-血氧
|
public int type; // 算法类型:0-心率,1-血氧
|
||||||
|
public short sn; // 序列号
|
||||||
public int value; // 主要值(心率值或血氧值)
|
public int value; // 主要值(心率值或血氧值)
|
||||||
public int confidence; // 置信度
|
public int confidence; // 置信度
|
||||||
public int signalQuality; // 信号质量(心率为信噪比,血氧为R值)
|
public int signalQuality; // 信号质量(心率为信噪比,血氧为R值)
|
||||||
public int confidenceLevel; // 置信等级(仅用于血氧,范围-2到5)
|
public int confidenceLevel; // 置信等级(仅用于血氧,范围-2到5)
|
||||||
|
|
||||||
public AlgoResultResponse(int type, int value, int confidence, int signalQuality, int confidenceLevel) {
|
public AlgoResultResponse(int type, short sn, int value, int confidence, int signalQuality, int confidenceLevel) {
|
||||||
|
this.sn = sn;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.confidence = confidence;
|
this.confidence = confidence;
|
||||||
@ -736,11 +756,17 @@ public class ASR5515Protocol {
|
|||||||
return confidence;
|
return confidence;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取序列号
|
||||||
|
public short getSn() {
|
||||||
|
return sn;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (type == TYPE_HEART_RATE) {
|
if (type == TYPE_HEART_RATE) {
|
||||||
return "AlgoResultResponse{" +
|
return "AlgoResultResponse{" +
|
||||||
"type=HeartRate" +
|
"type=HeartRate" +
|
||||||
|
", sn=" + sn +
|
||||||
", heartRate=" + value +
|
", heartRate=" + value +
|
||||||
", confidence=" + confidence +
|
", confidence=" + confidence +
|
||||||
", signalNoiseRatio=" + signalQuality +
|
", signalNoiseRatio=" + signalQuality +
|
||||||
@ -748,6 +774,7 @@ public class ASR5515Protocol {
|
|||||||
} else {
|
} else {
|
||||||
return "AlgoResultResponse{" +
|
return "AlgoResultResponse{" +
|
||||||
"type=SpO2" +
|
"type=SpO2" +
|
||||||
|
", sn=" + sn +
|
||||||
", spo2=" + value +
|
", spo2=" + value +
|
||||||
", confidence=" + confidence +
|
", confidence=" + confidence +
|
||||||
", rValue=" + signalQuality +
|
", rValue=" + signalQuality +
|
||||||
@ -825,7 +852,7 @@ public class ASR5515Protocol {
|
|||||||
LogManager.d(TAG, "Parse algo result - type: " + (type == AlgoResultResponse.TYPE_HEART_RATE ? "HeartRate" : "SpO2") +
|
LogManager.d(TAG, "Parse algo result - type: " + (type == AlgoResultResponse.TYPE_HEART_RATE ? "HeartRate" : "SpO2") +
|
||||||
", value: " + value + ", confidence: " + confidence);
|
", value: " + value + ", confidence: " + confidence);
|
||||||
|
|
||||||
return new AlgoResultResponse(type, value, confidence, signalQuality, confidenceLevel);
|
return new AlgoResultResponse(type, frame.sn, value, confidence, signalQuality, confidenceLevel);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogManager.e(TAG, "Parse algo result error: " + e.getMessage());
|
LogManager.e(TAG, "Parse algo result error: " + e.getMessage());
|
||||||
return null;
|
return null;
|
||||||
|
@ -323,6 +323,16 @@ public class SerialPortHelper {
|
|||||||
sendData(data, null);
|
sendData(data, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送佩戴检测确认
|
||||||
|
* @param sn 序列号
|
||||||
|
* @return true 如果发送成功
|
||||||
|
*/
|
||||||
|
public void onWearDetectionResponseReceived(short sn) {
|
||||||
|
byte[] data = ASR5515Protocol.createWearAckRequest(sn);
|
||||||
|
sendData(data, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean open() {
|
public boolean open() {
|
||||||
try {
|
try {
|
||||||
@ -649,12 +659,14 @@ public class SerialPortHelper {
|
|||||||
|
|
||||||
case ASR5515Protocol.Commands.CMD_WEAR_DETECTION_RESP:
|
case ASR5515Protocol.Commands.CMD_WEAR_DETECTION_RESP:
|
||||||
ASR5515Protocol.WearDetectionResponse wearDetectionResponse = ASR5515Protocol.parseWearDetectionResponse(frame);
|
ASR5515Protocol.WearDetectionResponse wearDetectionResponse = ASR5515Protocol.parseWearDetectionResponse(frame);
|
||||||
if (wearDetectionResponse != null && wearDetectionCallback != null) {
|
if (wearDetectionResponse != null) {
|
||||||
|
if (wearDetectionCallback != null) {
|
||||||
if (lastWearStatus == null || lastWearStatus != wearDetectionResponse.isWearing) {
|
if (lastWearStatus == null || lastWearStatus != wearDetectionResponse.isWearing) {
|
||||||
wearDetectionCallback.onWearDetectionResponse(wearDetectionResponse);
|
wearDetectionCallback.onWearDetectionResponse(wearDetectionResponse);
|
||||||
lastWearStatus = wearDetectionResponse.isWearing;
|
lastWearStatus = wearDetectionResponse.isWearing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ASR5515Protocol.Commands.CMD_GH3220_MEASURE_START_RESP:
|
case ASR5515Protocol.Commands.CMD_GH3220_MEASURE_START_RESP:
|
||||||
@ -674,13 +686,6 @@ public class SerialPortHelper {
|
|||||||
case ASR5515Protocol.Commands.CMD_SPO2_RESULT:
|
case ASR5515Protocol.Commands.CMD_SPO2_RESULT:
|
||||||
ASR5515Protocol.AlgoResultResponse algoResultResponse = ASR5515Protocol.parseAlgoResultResponse(frame);
|
ASR5515Protocol.AlgoResultResponse algoResultResponse = ASR5515Protocol.parseAlgoResultResponse(frame);
|
||||||
if (algoResultResponse != null && algoResultCallback != null) {
|
if (algoResultResponse != null && algoResultCallback != null) {
|
||||||
// 发送接收确认
|
|
||||||
byte[] confirmData;
|
|
||||||
if(frame.command == ASR5515Protocol.Commands.CMD_HEART_RATE_RESULT)
|
|
||||||
onHeartRateDataReceived(frame.sn);
|
|
||||||
else if(frame.command == ASR5515Protocol.Commands.CMD_SPO2_RESULT)
|
|
||||||
onSpO2DataReceived(frame.sn);
|
|
||||||
|
|
||||||
algoResultCallback.onAlgoResultReceived(algoResultResponse);
|
algoResultCallback.onAlgoResultReceived(algoResultResponse);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user