|
|
|
|
@ -10,13 +10,13 @@ import io.flutter.plugin.common.MethodChannel
|
|
|
|
|
import io.flutter.plugin.common.EventChannel
|
|
|
|
|
import android.util.SparseArray
|
|
|
|
|
import androidx.annotation.RequiresApi
|
|
|
|
|
import com.cloud.diplomaticquarterapp.ble.OxymeterModel
|
|
|
|
|
import com.cloud.diplomaticquarterapp.ble.utils.EcgData
|
|
|
|
|
import com.google.gson.Gson
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Ble
|
|
|
|
|
import com.jeremyliao.liveeventbus.LiveEventBus
|
|
|
|
|
import com.lepu.blepro.constants.Constant
|
|
|
|
|
import com.lepu.blepro.event.EventMsgConst
|
|
|
|
|
import com.lepu.blepro.event.EventMsgConst.Ble.*
|
|
|
|
|
import com.lepu.blepro.event.InterfaceEvent
|
|
|
|
|
@ -31,15 +31,11 @@ import com.lepu.blepro.ext.er2.Er2File
|
|
|
|
|
import com.lepu.blepro.ext.er2.RtData
|
|
|
|
|
import com.lepu.blepro.ext.bp2.*
|
|
|
|
|
import com.lepu.blepro.ext.pc60fw.RtParam
|
|
|
|
|
import com.lepu.blepro.ext.sp20.GetConfigResult
|
|
|
|
|
import com.lepu.blepro.ext.sp20.RtWave
|
|
|
|
|
import com.lepu.blepro.ext.sp20.SetConfigResult
|
|
|
|
|
import com.lepu.blepro.ext.sp20.TempResult
|
|
|
|
|
import com.lepu.blepro.objs.Bluetooth
|
|
|
|
|
import com.lepu.blepro.objs.BluetoothController
|
|
|
|
|
import com.lepu.blepro.utils.DateUtil
|
|
|
|
|
import com.lepu.blepro.utils.Er1Decompress
|
|
|
|
|
import kotlin.reflect.KFunction2
|
|
|
|
|
|
|
|
|
|
class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivity: MainActivity) {
|
|
|
|
|
|
|
|
|
|
@ -58,6 +54,7 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
|
|
|
|
|
private const val CHANNEL = "BLE-Platform-Bridge"
|
|
|
|
|
private const val EVENTCHANNEL = "BLE-Platform-Bridge-Event"
|
|
|
|
|
private const val SCAN_DEVICE = "scan"
|
|
|
|
|
private const val CONNECT_DEVICE = "connectDevice"
|
|
|
|
|
private const val SCAN_DEVICE_EKG = "scan_ekg"
|
|
|
|
|
private const val EKG_FILES_LIST = "ekg_files_list"
|
|
|
|
|
private const val BP2_FILES_LIST = "bp2_files_list"
|
|
|
|
|
@ -171,7 +168,9 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
|
|
|
|
|
channel.setMethodCallHandler { methodCall: MethodCall, result: MethodChannel.Result ->
|
|
|
|
|
|
|
|
|
|
if (methodCall.method == SCAN_DEVICE) {
|
|
|
|
|
scanDevice(methodCall, result)
|
|
|
|
|
scanDevice()
|
|
|
|
|
} else if (methodCall.method == CONNECT_DEVICE) {
|
|
|
|
|
connectDevice(methodCall.arguments as List<String>)
|
|
|
|
|
} else if (methodCall.method == DISCONNECT_DEVICE) {
|
|
|
|
|
disconnectDevice(methodCall, result)
|
|
|
|
|
} else if (methodCall.method == SCAN_DEVICE_EKG) {
|
|
|
|
|
@ -201,6 +200,7 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequiresApi(Build.VERSION_CODES.Q)
|
|
|
|
|
fun disconnectDevice(methodCall: MethodCall, result: MethodChannel.Result) {
|
|
|
|
|
if (rtHandler.hasCallbacks(rtTask)) rtHandler.removeCallbacks(rtTask)
|
|
|
|
|
@ -208,7 +208,7 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun scanDevice(methodCall: MethodCall, result: MethodChannel.Result) {
|
|
|
|
|
private fun scanDevice() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LiveEventBus.get<Boolean>(EventMsgConst.Ble.EventServiceConnectedAndInterfaceInit).observe(this.mainActivity) {
|
|
|
|
|
@ -218,274 +218,285 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
|
|
|
|
|
println("EventServiceConnectedAndInterfaceInit")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LiveEventBus.get<Boolean>(EventMsgConst.Ble.EventServiceConnectedAndInterfaceInit).observe(this.mainActivity) {
|
|
|
|
|
// BleService init success
|
|
|
|
|
println("EventServiceConnectedAndInterfaceInit---------")
|
|
|
|
|
BleServiceHelper.BleServiceHelper.startScan(models)
|
|
|
|
|
println("EventServiceConnectedAndInterfaceInit")
|
|
|
|
|
}
|
|
|
|
|
LiveEventBus.get<Bluetooth>(EventMsgConst.Discovery.EventDeviceFound).observe(this.mainActivity) {
|
|
|
|
|
var deviceName: String = ""
|
|
|
|
|
for (b in BluetoothController.getDevices()) {
|
|
|
|
|
println(b.name)
|
|
|
|
|
|
|
|
|
|
//TODO: UNCOMMENT THIS
|
|
|
|
|
// if (b.name.contains("POD-1_SN8187", true) || b.name.contains(
|
|
|
|
|
// "O2M 1670", true
|
|
|
|
|
// ) || b.name.contains("DuoEK", true) || b.name.contains("BP2", true) || b.name.contains("SP-20", true)
|
|
|
|
|
// ) {
|
|
|
|
|
|
|
|
|
|
if (b.name.contains("SP-20", true)) {
|
|
|
|
|
|
|
|
|
|
model = b.model
|
|
|
|
|
deviceName = b.name
|
|
|
|
|
BleServiceHelper.BleServiceHelper.setInterfaces(b.model)
|
|
|
|
|
BleServiceHelper.BleServiceHelper.stopScan()
|
|
|
|
|
BleServiceHelper.BleServiceHelper.connect(
|
|
|
|
|
this.mainActivity.applicationContext, b.model, b.device
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
val deviceName: String = ""
|
|
|
|
|
val returnData = mapOf("type" to "devicesList", "data" to gson.toJson(BluetoothController.getDevices()))
|
|
|
|
|
println("devicesList: ${BluetoothController.getDevices()}");
|
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
|
|
|
|
|
|
println("EventDeviceFound")
|
|
|
|
|
println(deviceName)
|
|
|
|
|
|
|
|
|
|
if (deviceName == "POD-1_SN8187") {
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.PC60Fw.EventPC60FwRtParam).observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as RtParam
|
|
|
|
|
println("OXY DATA POD-1W: $data")
|
|
|
|
|
eventSink?.success(data.toString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
val rawFolders = SparseArray<String>()
|
|
|
|
|
try {
|
|
|
|
|
BleServiceHelper.BleServiceHelper.initRawFolder(rawFolders).initService(this.mainActivity.application)
|
|
|
|
|
|
|
|
|
|
} catch (e: Exception) {
|
|
|
|
|
println(e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (deviceName.contains("DuoEK", ignoreCase = true)) {
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER2.EventEr2Info).observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as DeviceInfo
|
|
|
|
|
println("DuoEK INFO DATA: $data")
|
|
|
|
|
val returnData = mapOf("type" to "infoData", "data" to data.toString())
|
|
|
|
|
|
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
|
}
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER2.EventEr2FileList).observe(this.mainActivity) {
|
|
|
|
|
BleServiceHelper.BleServiceHelper.stopRtTask(model)
|
|
|
|
|
ecgFileNames = it.data as ArrayList<String>
|
|
|
|
|
readFile()
|
|
|
|
|
@RequiresApi(Build.VERSION_CODES.Q)
|
|
|
|
|
private fun subscribeToStreams(deviceName: String) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ECG TRACKER
|
|
|
|
|
if (deviceName.contains("DuoEK", ignoreCase = true)) {
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER2.EventEr2Info).observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as DeviceInfo
|
|
|
|
|
println("DuoEK INFO DATA: $data")
|
|
|
|
|
val returnData = mapOf("type" to "infoData", "data" to data.toString())
|
|
|
|
|
|
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
|
}
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER2.EventEr2FileList).observe(this.mainActivity) {
|
|
|
|
|
BleServiceHelper.BleServiceHelper.stopRtTask(model)
|
|
|
|
|
ecgFileNames = it.data as ArrayList<String>
|
|
|
|
|
readFile()
|
|
|
|
|
// val fileNames = it.data as ArrayList<String>
|
|
|
|
|
// println("DuoEK FileNames List: ${fileNames}")
|
|
|
|
|
// val returnData =
|
|
|
|
|
// mapOf("type" to "fileList", "data" to fileNames)
|
|
|
|
|
// eventSink?.success(returnData)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER2.EventEr2SetTime).observe(this.mainActivity) {
|
|
|
|
|
println("EventEr2SetTime")
|
|
|
|
|
// Get Device Info
|
|
|
|
|
BleServiceHelper.BleServiceHelper.er2GetInfo(model)
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER2.EventEr2SetTime).observe(this.mainActivity) {
|
|
|
|
|
println("EventEr2SetTime")
|
|
|
|
|
// Get Device Info
|
|
|
|
|
BleServiceHelper.BleServiceHelper.er2GetInfo(model)
|
|
|
|
|
// ecgRTTask.run()
|
|
|
|
|
}
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER2.EventEr2ReadFileComplete).observe(this.mainActivity) {
|
|
|
|
|
println("EventEr2ReadFileComplete")
|
|
|
|
|
val data = it.data as Er2File
|
|
|
|
|
if (data.fileName.contains("R")) {
|
|
|
|
|
val file = Er2EcgFile(data.content)
|
|
|
|
|
val ecgShorts = Er1Decompress.unCompressAlgECG(file.waveData)
|
|
|
|
|
val ecgData = EcgData()
|
|
|
|
|
val startTime = DateUtil.getSecondTimestamp(data.fileName.replace("R", ""))
|
|
|
|
|
ecgData.fileName = data.fileName
|
|
|
|
|
ecgData.duration = file.recordingTime
|
|
|
|
|
ecgData.shortData = ecgShorts
|
|
|
|
|
ecgData.startTime = startTime
|
|
|
|
|
ecgList.add(ecgData)
|
|
|
|
|
print(ecgList)
|
|
|
|
|
}
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER2.EventEr2ReadFileComplete).observe(this.mainActivity) {
|
|
|
|
|
println("EventEr2ReadFileComplete")
|
|
|
|
|
val data = it.data as Er2File
|
|
|
|
|
if (data.fileName.contains("R")) {
|
|
|
|
|
val file = Er2EcgFile(data.content)
|
|
|
|
|
val ecgShorts = Er1Decompress.unCompressAlgECG(file.waveData)
|
|
|
|
|
val ecgData = EcgData()
|
|
|
|
|
val startTime = DateUtil.getSecondTimestamp(data.fileName.replace("R", ""))
|
|
|
|
|
ecgData.fileName = data.fileName
|
|
|
|
|
ecgData.duration = file.recordingTime
|
|
|
|
|
ecgData.shortData = ecgShorts
|
|
|
|
|
ecgData.startTime = startTime
|
|
|
|
|
ecgList.add(ecgData)
|
|
|
|
|
print(ecgList)
|
|
|
|
|
// val returnData =
|
|
|
|
|
// mapOf("type" to "fileDetail", "data" to gson.toJson(ecgList))
|
|
|
|
|
// eventSink?.success(returnData)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
ecgFileNames.removeAt(0)
|
|
|
|
|
readFile()
|
|
|
|
|
}
|
|
|
|
|
ecgFileNames.removeAt(0)
|
|
|
|
|
readFile()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER2.EventEr2RtData).observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as RtData
|
|
|
|
|
println("EventEr2RtData")
|
|
|
|
|
val returnData = mapOf("type" to "realtimeDataECG", "data" to gson.toJson(data))
|
|
|
|
|
println(returnData)
|
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER2.EventEr2RtData).observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as RtData
|
|
|
|
|
println("EventEr2RtData")
|
|
|
|
|
val returnData = mapOf("type" to "realtimeDataECG", "data" to gson.toJson(data))
|
|
|
|
|
println(returnData)
|
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
|
// DataController.receive(data.wave.ecgFloats)
|
|
|
|
|
// hr.text = "${data.param.hr}"
|
|
|
|
|
// data_log.text = "${data.param}"
|
|
|
|
|
|
|
|
|
|
// sampling rate:125HZ
|
|
|
|
|
// mV = n * 0.002467(data.wave.ecgFloats = data.wave.ecgShorts * 0.002467)
|
|
|
|
|
// data.param.batteryState:0(no charge),1(charging),2(charging complete),3(low battery)
|
|
|
|
|
// data.param.battery:0-100
|
|
|
|
|
// data.param.recordTime:unit(s)
|
|
|
|
|
// data.param.curStatus:0(idle),1(preparing),2(measuring),3(saving file),4(saving succeed),
|
|
|
|
|
// 5(less than 30s, file not saved),6(6 retests),7(lead off)
|
|
|
|
|
}
|
|
|
|
|
// sampling rate:125HZ
|
|
|
|
|
// mV = n * 0.002467(data.wave.ecgFloats = data.wave.ecgShorts * 0.002467)
|
|
|
|
|
// data.param.batteryState:0(no charge),1(charging),2(charging complete),3(low battery)
|
|
|
|
|
// data.param.battery:0-100
|
|
|
|
|
// data.param.recordTime:unit(s)
|
|
|
|
|
// data.param.curStatus:0(idle),1(preparing),2(measuring),3(saving file),4(saving succeed),
|
|
|
|
|
// 5(less than 30s, file not saved),6(6 retests),7(lead off)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// OXYMETER
|
|
|
|
|
|
|
|
|
|
if (deviceName == "POD-1_SN8187" || deviceName == "PC-60FW") { //DONE
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.PC60Fw.EventPC60FwRtParam).observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as RtParam
|
|
|
|
|
println("POD-1_SN8187: $data")
|
|
|
|
|
println("PC-60FW: $data")
|
|
|
|
|
val oxyModel = OxymeterModel(data.spo2, data.pr, data.pi, data.isProbeOff, data.isPulseSearching, true, 100);
|
|
|
|
|
val returnData = mapOf("type" to "OxyRtParam", "data" to gson.toJson(oxyModel))
|
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (deviceName == "O2M 1670") {
|
|
|
|
|
rtHandler.removeCallbacks(rtTask)
|
|
|
|
|
rtHandler.post(rtTask)
|
|
|
|
|
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.Oxy.EventOxyRtParamData).observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as com.lepu.blepro.ext.oxy.RtParam
|
|
|
|
|
println("OXY DATA O2M: $data")
|
|
|
|
|
eventSink?.success(data.toString())
|
|
|
|
|
// tv_oxy.text = data.spo2.toString()
|
|
|
|
|
// tv_pr.text = data.pr.toString()
|
|
|
|
|
// tv_pi.text = data.pi.toString()
|
|
|
|
|
// data_log.text = "$data"
|
|
|
|
|
// data.battery:0-100
|
|
|
|
|
// data.batteryState:0(no charge),1(charging),2(charging complete)
|
|
|
|
|
// data.state:0(lead off),1(lead on),other(error)
|
|
|
|
|
}
|
|
|
|
|
if (deviceName == "O2M 1670" || deviceName == "O2Ring 4135") { // DONE
|
|
|
|
|
rtHandler.removeCallbacks(rtTask)
|
|
|
|
|
rtHandler.post(rtTask)
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.Oxy.EventOxyRtParamData).observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as com.lepu.blepro.ext.oxy.RtParam
|
|
|
|
|
println("O2M 1670: $data")
|
|
|
|
|
println("O2Ring 4135: $data")
|
|
|
|
|
val oxyModel = OxymeterModel(data.spo2, data.pr, data.pi, false, true, true, data.battery);
|
|
|
|
|
val returnData = mapOf("type" to "OxyRtParam", "data" to gson.toJson(oxyModel))
|
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (deviceName.contains("BP2", ignoreCase = true)) {
|
|
|
|
|
if (deviceName.contains("SP-20", ignoreCase = true)) { //DONE
|
|
|
|
|
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.BP2.EventBp2SyncTime).observe(this.mainActivity) {
|
|
|
|
|
println("EventBp2SyncTime")
|
|
|
|
|
// Get Device Info
|
|
|
|
|
BleServiceHelper.BleServiceHelper.bp2GetInfo(model)
|
|
|
|
|
}
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.SP20.EventSp20SetTime).observe(this.mainActivity) {
|
|
|
|
|
println("EventSp20SetTime")
|
|
|
|
|
BleServiceHelper.BleServiceHelper.bp2GetInfo(model)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.BP2.EventBp2Info).observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as com.lepu.blepro.ext.bp2.DeviceInfo
|
|
|
|
|
println("BP2 INFO DATA: $data")
|
|
|
|
|
val returnData = mapOf("type" to "infoData", "data" to data.toString(), "deviceName" to deviceName)
|
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
|
BleServiceHelper.BleServiceHelper.startRtTask(model)
|
|
|
|
|
}
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.SP20.EventSp20DeviceInfo).observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as com.lepu.blepro.ext.sp20.DeviceInfo
|
|
|
|
|
println("EventSp20DeviceInfo: $data")
|
|
|
|
|
val returnData = mapOf("type" to "infoData", "data" to data.toString(), "deviceName" to deviceName)
|
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
|
BleServiceHelper.BleServiceHelper.startRtTask(model)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.BP2.EventBp2FileList).observe(this.mainActivity) {
|
|
|
|
|
bpFileNames = it.data as ArrayList<String>
|
|
|
|
|
}
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.SP20.EventSp20RtParam).observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as com.lepu.blepro.ext.sp20.RtParam
|
|
|
|
|
println("OxyRtParam: $data")
|
|
|
|
|
val oxyModel = OxymeterModel(data.spo2, data.pr, data.pi, data.isProbeOff, data.isPulseSearching, data.isCheckProbe, data.battery);
|
|
|
|
|
val returnData = mapOf("type" to "OxyRtParam", "data" to gson.toJson(oxyModel))
|
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
|
}
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.SP20.EventSp20RtWave).observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as RtWave
|
|
|
|
|
println("OxyRtParam: $data")
|
|
|
|
|
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.BP2.EventBp2ReadFileComplete).observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as Bp2File
|
|
|
|
|
// data.type: 1(BP), 2(ECG)
|
|
|
|
|
println("LiveEventBus with BP2 : $data")
|
|
|
|
|
|
|
|
|
|
if (data.type == 1) {
|
|
|
|
|
val file = BpFile(data.content)
|
|
|
|
|
// file.measureTime:unit(s)
|
|
|
|
|
println("BpFile : $file")
|
|
|
|
|
} else if (data.type == 2) {
|
|
|
|
|
|
|
|
|
|
val file = EcgFile(data.content)
|
|
|
|
|
val ecgData = EcgData()
|
|
|
|
|
val startTime = DateUtil.getSecondTimestamp(data.fileName)
|
|
|
|
|
ecgData.fileName = data.fileName
|
|
|
|
|
ecgData.duration = file.recordingTime
|
|
|
|
|
ecgData.shortData = Er1Decompress.unCompressAlgECG(file.waveData)
|
|
|
|
|
// ecgData.shortData = FilterUtil.getEcgFileFilterData(it.model, data.content)
|
|
|
|
|
ecgData.startTime = startTime
|
|
|
|
|
ecgList.add(ecgData)
|
|
|
|
|
// sampling rate:125HZ
|
|
|
|
|
// mV = file.waveShortData * 0.003098
|
|
|
|
|
// file.measureTime:unit(s)
|
|
|
|
|
// file.recordingTime:unit(s)
|
|
|
|
|
// file.connectCable: Whether the cable is connected
|
|
|
|
|
// file.diagnosis:EcgDiagnosis
|
|
|
|
|
// diagnosis.isRegular:Whether Regular ECG Rhythm
|
|
|
|
|
// diagnosis.isPoorSignal:Whether Unable to analyze
|
|
|
|
|
// diagnosis.isLeadOff:Whether Always lead off
|
|
|
|
|
// diagnosis.isFastHr:Whether Fast Heart Rate
|
|
|
|
|
// diagnosis.isSlowHr:Whether Slow Heart Rate
|
|
|
|
|
// diagnosis.isIrregular:Whether Irregular ECG Rhythm
|
|
|
|
|
// diagnosis.isPvcs:Whether Possible ventricular premature beats
|
|
|
|
|
// diagnosis.isHeartPause:Whether Possible heart pause
|
|
|
|
|
// diagnosis.isFibrillation:Whether Possible Atrial fibrillation
|
|
|
|
|
// diagnosis.isWideQrs:Whether Wide QRS duration
|
|
|
|
|
// diagnosis.isProlongedQtc:Whether QTc is prolonged
|
|
|
|
|
// diagnosis.isShortQtc:Whether QTc is short
|
|
|
|
|
println("EcgFile : $file")
|
|
|
|
|
}
|
|
|
|
|
bpFileNames.removeAt(0)
|
|
|
|
|
readFileForBp2()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.BP2.EventBp2RtData).observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as com.lepu.blepro.ext.bp2.RtData
|
|
|
|
|
// data.status: RtStatus
|
|
|
|
|
// data.status.deviceStatus: 0(STATUS_SLEEP), 1(STATUS_MEMERY), 2(STATUS_CHARGE), 3(STATUS_READY),
|
|
|
|
|
// 4(STATUS_BP_MEASURING), 5(STATUS_BP_MEASURE_END),
|
|
|
|
|
// 6(STATUS_ECG_MEASURING), 7(STATUS_ECG_MEASURE_END), 20(STATUS_VEN)
|
|
|
|
|
// data.status.batteryStatus: 0(no charge), 1(charging), 2(charging complete), 3(low battery)
|
|
|
|
|
// data.status.percent: 0-100
|
|
|
|
|
// data.param: RtParam
|
|
|
|
|
// data.param.paramDataType: 0(Bp measuring), 1(Bp end), 2(Ecg measuring), 3(Ecg end)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
when (data.param.paramDataType) {
|
|
|
|
|
0 -> {
|
|
|
|
|
val bpIng = RtBpIng(data.param.paramData)
|
|
|
|
|
|
|
|
|
|
val returnData = mapOf("type" to "RealTimeDataBP2Measuring", "data" to gson.toJson(bpIng))
|
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
|
//BLOOD PRESSURE
|
|
|
|
|
if (deviceName.contains("BP2", ignoreCase = true)) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.BP2.EventBp2SyncTime).observe(this.mainActivity) {
|
|
|
|
|
println("EventBp2SyncTime")
|
|
|
|
|
// Get Device Info
|
|
|
|
|
BleServiceHelper.BleServiceHelper.bp2GetInfo(model)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
1 -> {
|
|
|
|
|
val bpResult = RtBpResult(data.param.paramData)
|
|
|
|
|
val returnData = mapOf("type" to "RealTimeDataBP2Result", "data" to gson.toJson(bpResult))
|
|
|
|
|
println("RealTimeDataBP2Result FOR BP : $returnData")
|
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.BP2.EventBp2Info).observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as com.lepu.blepro.ext.bp2.DeviceInfo
|
|
|
|
|
println("BP2 INFO DATA: $data")
|
|
|
|
|
val returnData = mapOf("type" to "infoData", "data" to data.toString(), "deviceName" to deviceName)
|
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
|
BleServiceHelper.BleServiceHelper.startRtTask(model)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.BP2.EventBp2FileList).observe(this.mainActivity) {
|
|
|
|
|
bpFileNames = it.data as ArrayList<String>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.BP2.EventBp2ReadFileComplete).observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as Bp2File
|
|
|
|
|
// data.type: 1(BP), 2(ECG)
|
|
|
|
|
println("LiveEventBus with BP2 : $data")
|
|
|
|
|
|
|
|
|
|
if (data.type == 1) {
|
|
|
|
|
val file = BpFile(data.content)
|
|
|
|
|
// file.measureTime:unit(s)
|
|
|
|
|
println("BpFile : $file")
|
|
|
|
|
} else if (data.type == 2) {
|
|
|
|
|
|
|
|
|
|
val file = EcgFile(data.content)
|
|
|
|
|
val ecgData = EcgData()
|
|
|
|
|
val startTime = DateUtil.getSecondTimestamp(data.fileName)
|
|
|
|
|
ecgData.fileName = data.fileName
|
|
|
|
|
ecgData.duration = file.recordingTime
|
|
|
|
|
ecgData.shortData = Er1Decompress.unCompressAlgECG(file.waveData)
|
|
|
|
|
// ecgData.shortData = FilterUtil.getEcgFileFilterData(it.model, data.content)
|
|
|
|
|
ecgData.startTime = startTime
|
|
|
|
|
ecgList.add(ecgData)
|
|
|
|
|
// sampling rate:125HZ
|
|
|
|
|
// mV = file.waveShortData * 0.003098
|
|
|
|
|
// file.measureTime:unit(s)
|
|
|
|
|
// file.recordingTime:unit(s)
|
|
|
|
|
// file.connectCable: Whether the cable is connected
|
|
|
|
|
// file.diagnosis:EcgDiagnosis
|
|
|
|
|
// diagnosis.isRegular:Whether Regular ECG Rhythm
|
|
|
|
|
// diagnosis.isPoorSignal:Whether Unable to analyze
|
|
|
|
|
// diagnosis.isLeadOff:Whether Always lead off
|
|
|
|
|
// diagnosis.isFastHr:Whether Fast Heart Rate
|
|
|
|
|
// diagnosis.isSlowHr:Whether Slow Heart Rate
|
|
|
|
|
// diagnosis.isIrregular:Whether Irregular ECG Rhythm
|
|
|
|
|
// diagnosis.isPvcs:Whether Possible ventricular premature beats
|
|
|
|
|
// diagnosis.isHeartPause:Whether Possible heart pause
|
|
|
|
|
// diagnosis.isFibrillation:Whether Possible Atrial fibrillation
|
|
|
|
|
// diagnosis.isWideQrs:Whether Wide QRS duration
|
|
|
|
|
// diagnosis.isProlongedQtc:Whether QTc is prolonged
|
|
|
|
|
// diagnosis.isShortQtc:Whether QTc is short
|
|
|
|
|
println("EcgFile : $file")
|
|
|
|
|
}
|
|
|
|
|
bpFileNames.removeAt(0)
|
|
|
|
|
readFileForBp2()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.BP2.EventBp2RtData).observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as com.lepu.blepro.ext.bp2.RtData
|
|
|
|
|
// data.status: RtStatus
|
|
|
|
|
// data.status.deviceStatus: 0(STATUS_SLEEP), 1(STATUS_MEMERY), 2(STATUS_CHARGE), 3(STATUS_READY),
|
|
|
|
|
// 4(STATUS_BP_MEASURING), 5(STATUS_BP_MEASURE_END),
|
|
|
|
|
// 6(STATUS_ECG_MEASURING), 7(STATUS_ECG_MEASURE_END), 20(STATUS_VEN)
|
|
|
|
|
// data.status.batteryStatus: 0(no charge), 1(charging), 2(charging complete), 3(low battery)
|
|
|
|
|
// data.status.percent: 0-100
|
|
|
|
|
// data.param: RtParam
|
|
|
|
|
// data.param.paramDataType: 0(Bp measuring), 1(Bp end), 2(Ecg measuring), 3(Ecg end)
|
|
|
|
|
|
|
|
|
|
when (data.param.paramDataType) {
|
|
|
|
|
0 -> {
|
|
|
|
|
val bpIng = RtBpIng(data.param.paramData)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
val returnData = mapOf("type" to "RealTimeDataBP2Measuring", "data" to gson.toJson(bpIng))
|
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (deviceName.contains("SP-20", ignoreCase = true)) {
|
|
|
|
|
1 -> {
|
|
|
|
|
val bpResult = RtBpResult(data.param.paramData)
|
|
|
|
|
val returnData = mapOf("type" to "RealTimeDataBP2Result", "data" to gson.toJson(bpResult))
|
|
|
|
|
println("RealTimeDataBP2Result FOR BP : $returnData")
|
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
|
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.SP20.EventSp20SetTime).observe(this.mainActivity) {
|
|
|
|
|
println("EventSp20SetTime")
|
|
|
|
|
BleServiceHelper.BleServiceHelper.bp2GetInfo(model)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.SP20.EventSp20DeviceInfo).observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as com.lepu.blepro.ext.sp20.DeviceInfo
|
|
|
|
|
println("EventSp20DeviceInfo: $data")
|
|
|
|
|
val returnData = mapOf("type" to "infoData", "data" to data.toString(), "deviceName" to deviceName)
|
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
|
BleServiceHelper.BleServiceHelper.startRtTask(model)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.SP20.EventSp20RtParam).observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as com.lepu.blepro.ext.sp20.RtParam
|
|
|
|
|
println("EventSp20RtParam: $data")
|
|
|
|
|
val returnData = mapOf("type" to "EventSp20RtParam", "data" to gson.toJson(data))
|
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
|
}
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.SP20.EventSp20RtWave).observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as RtWave
|
|
|
|
|
println("EventSp20RtWave: $data")
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
val rawFolders = SparseArray<String>()
|
|
|
|
|
try {
|
|
|
|
|
BleServiceHelper.BleServiceHelper.initRawFolder(rawFolders).initService(this.mainActivity.application)
|
|
|
|
|
|
|
|
|
|
} catch (e: Exception) {
|
|
|
|
|
println(e)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun connectDevice(device: List<String>) {
|
|
|
|
|
|
|
|
|
|
println("connectDevice: $device");
|
|
|
|
|
model = device[1].toInt()
|
|
|
|
|
val deviceName = device[0]
|
|
|
|
|
for (b in BluetoothController.getDevices()) {
|
|
|
|
|
println("getDevices device: ${b.name}")
|
|
|
|
|
if (b.name == deviceName) {
|
|
|
|
|
BleServiceHelper.BleServiceHelper.setInterfaces(b.model)
|
|
|
|
|
// BleServiceHelper.BleServiceHelper.stopScan()
|
|
|
|
|
BleServiceHelper.BleServiceHelper.connect(
|
|
|
|
|
this.mainActivity.applicationContext, model, b.device
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
subscribeToStreams(deviceName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun readFile() {
|
|
|
|
|
if (ecgFileNames.size == 0) {
|
|
|
|
|
val returnData = mapOf("type" to "fileDetail", "data" to gson.toJson(ecgList))
|
|
|
|
|
|