|
|
|
@ -1,17 +1,8 @@
|
|
|
|
package com.ejada.hmg.utils
|
|
|
|
package com.ejada.hmg.utils
|
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
|
import android.annotation.SuppressLint
|
|
|
|
import android.content.Context
|
|
|
|
|
|
|
|
import android.content.Intent
|
|
|
|
|
|
|
|
import android.content.Intent.getIntent
|
|
|
|
|
|
|
|
import android.net.Uri
|
|
|
|
|
|
|
|
import android.os.Build
|
|
|
|
import android.os.Build
|
|
|
|
import android.os.Bundle
|
|
|
|
|
|
|
|
import android.os.Handler
|
|
|
|
import android.os.Handler
|
|
|
|
import android.provider.Settings
|
|
|
|
|
|
|
|
import android.util.Log
|
|
|
|
|
|
|
|
import android.widget.Toast
|
|
|
|
|
|
|
|
import androidx.core.app.ActivityCompat.startActivityForResult
|
|
|
|
|
|
|
|
import com.ejada.hmg.MainActivity
|
|
|
|
import com.ejada.hmg.MainActivity
|
|
|
|
import io.flutter.embedding.engine.FlutterEngine
|
|
|
|
import io.flutter.embedding.engine.FlutterEngine
|
|
|
|
import io.flutter.plugin.common.MethodCall
|
|
|
|
import io.flutter.plugin.common.MethodCall
|
|
|
|
@ -20,13 +11,11 @@ import io.flutter.plugin.common.EventChannel
|
|
|
|
import android.util.SparseArray
|
|
|
|
import android.util.SparseArray
|
|
|
|
import androidx.annotation.RequiresApi
|
|
|
|
import androidx.annotation.RequiresApi
|
|
|
|
import com.cloud.diplomaticquarterapp.ble.utils.EcgData
|
|
|
|
import com.cloud.diplomaticquarterapp.ble.utils.EcgData
|
|
|
|
import com.cloud.diplomaticquarterapp.ble.utils.RTBP2Data
|
|
|
|
|
|
|
|
import com.google.gson.Gson
|
|
|
|
import com.google.gson.Gson
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Ble
|
|
|
|
//Ble
|
|
|
|
import com.jeremyliao.liveeventbus.LiveEventBus
|
|
|
|
import com.jeremyliao.liveeventbus.LiveEventBus
|
|
|
|
import com.lepu.blepro.constants.Ble
|
|
|
|
|
|
|
|
import com.lepu.blepro.event.EventMsgConst
|
|
|
|
import com.lepu.blepro.event.EventMsgConst
|
|
|
|
import com.lepu.blepro.event.EventMsgConst.Ble.*
|
|
|
|
import com.lepu.blepro.event.EventMsgConst.Ble.*
|
|
|
|
import com.lepu.blepro.event.InterfaceEvent
|
|
|
|
import com.lepu.blepro.event.InterfaceEvent
|
|
|
|
@ -39,18 +28,15 @@ import com.lepu.blepro.ext.er2.DeviceInfo
|
|
|
|
import com.lepu.blepro.ext.er2.Er2EcgFile
|
|
|
|
import com.lepu.blepro.ext.er2.Er2EcgFile
|
|
|
|
import com.lepu.blepro.ext.er2.Er2File
|
|
|
|
import com.lepu.blepro.ext.er2.Er2File
|
|
|
|
import com.lepu.blepro.ext.er2.RtData
|
|
|
|
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.pc60fw.RtParam
|
|
|
|
import com.lepu.blepro.objs.Bluetooth
|
|
|
|
import com.lepu.blepro.objs.Bluetooth
|
|
|
|
import com.lepu.blepro.objs.BluetoothController
|
|
|
|
import com.lepu.blepro.objs.BluetoothController
|
|
|
|
import com.lepu.blepro.observer.BleChangeObserver
|
|
|
|
|
|
|
|
import com.lepu.blepro.utils.DateUtil
|
|
|
|
import com.lepu.blepro.utils.DateUtil
|
|
|
|
import com.lepu.blepro.utils.Er1Decompress
|
|
|
|
import com.lepu.blepro.utils.Er1Decompress
|
|
|
|
import io.flutter.plugin.common.EventChannel.EventSink
|
|
|
|
import kotlin.reflect.KFunction2
|
|
|
|
import no.nordicsemi.android.ble.observer.ConnectionObserver
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BleBridge(
|
|
|
|
class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivity: MainActivity) {
|
|
|
|
private var flutterEngine: FlutterEngine, private var mainActivity: MainActivity
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private lateinit var channel: MethodChannel
|
|
|
|
private lateinit var channel: MethodChannel
|
|
|
|
private lateinit var Echannel: EventChannel
|
|
|
|
private lateinit var Echannel: EventChannel
|
|
|
|
@ -196,14 +182,16 @@ class BleBridge(
|
|
|
|
result.notImplemented()
|
|
|
|
result.notImplemented()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Echannel.setStreamHandler(object : EventChannel.StreamHandler {
|
|
|
|
Echannel.setStreamHandler(
|
|
|
|
|
|
|
|
object : EventChannel.StreamHandler {
|
|
|
|
override fun onListen(arguments: Any?, eventSink: EventChannel.EventSink?) {
|
|
|
|
override fun onListen(arguments: Any?, eventSink: EventChannel.EventSink?) {
|
|
|
|
this@BleBridge.eventSink = eventSink
|
|
|
|
this@BleBridge.eventSink = eventSink
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onCancel(arguments: Any?) {
|
|
|
|
override fun onCancel(arguments: Any?) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -214,8 +202,17 @@ class BleBridge(
|
|
|
|
BleServiceHelper.BleServiceHelper.disconnect(false)
|
|
|
|
BleServiceHelper.BleServiceHelper.disconnect(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun scanDevice(methodCall: MethodCall, result: MethodChannel.Result) {
|
|
|
|
private fun scanDevice(methodCall: MethodCall, result: MethodChannel.Result) {
|
|
|
|
println("This is Test of Scanning")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LiveEventBus.get<Boolean>(EventMsgConst.Ble.EventServiceConnectedAndInterfaceInit).observe(this.mainActivity) {
|
|
|
|
|
|
|
|
// BleService init success
|
|
|
|
|
|
|
|
println("EventServiceConnectedAndInterfaceInit---------")
|
|
|
|
|
|
|
|
BleServiceHelper.BleServiceHelper.startScan(models)
|
|
|
|
|
|
|
|
println("EventServiceConnectedAndInterfaceInit")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LiveEventBus.get<Boolean>(EventMsgConst.Ble.EventServiceConnectedAndInterfaceInit).observe(this.mainActivity) {
|
|
|
|
LiveEventBus.get<Boolean>(EventMsgConst.Ble.EventServiceConnectedAndInterfaceInit).observe(this.mainActivity) {
|
|
|
|
// BleService init success
|
|
|
|
// BleService init success
|
|
|
|
println("EventServiceConnectedAndInterfaceInit---------")
|
|
|
|
println("EventServiceConnectedAndInterfaceInit---------")
|
|
|
|
@ -225,11 +222,13 @@ class BleBridge(
|
|
|
|
LiveEventBus.get<Bluetooth>(EventMsgConst.Discovery.EventDeviceFound).observe(this.mainActivity) {
|
|
|
|
LiveEventBus.get<Bluetooth>(EventMsgConst.Discovery.EventDeviceFound).observe(this.mainActivity) {
|
|
|
|
var deviceName: String = ""
|
|
|
|
var deviceName: String = ""
|
|
|
|
for (b in BluetoothController.getDevices()) {
|
|
|
|
for (b in BluetoothController.getDevices()) {
|
|
|
|
// println(b.name)
|
|
|
|
println(b.name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: UNCOMMENT THIS
|
|
|
|
// if (b.name.contains("POD-1_SN8187", true) || b.name.contains(
|
|
|
|
// if (b.name.contains("POD-1_SN8187", true) || b.name.contains(
|
|
|
|
// "O2M 1670", true
|
|
|
|
// "O2M 1670", true
|
|
|
|
// ) || b.name.contains("DuoEK", true) || b.name.contains("BP2", true)
|
|
|
|
// ) || b.name.contains("DuoEK", true) || b.name.contains("BP2", true)
|
|
|
|
//
|
|
|
|
// ) {
|
|
|
|
|
|
|
|
|
|
|
|
if (b.name.contains("BP2", true)) {
|
|
|
|
if (b.name.contains("BP2", true)) {
|
|
|
|
println("connecting bp2")
|
|
|
|
println("connecting bp2")
|
|
|
|
@ -241,6 +240,7 @@ class BleBridge(
|
|
|
|
BleServiceHelper.BleServiceHelper.connect(
|
|
|
|
BleServiceHelper.BleServiceHelper.connect(
|
|
|
|
this.mainActivity.applicationContext, b.model, b.device
|
|
|
|
this.mainActivity.applicationContext, b.model, b.device
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -260,6 +260,7 @@ class BleBridge(
|
|
|
|
val data = it.data as DeviceInfo
|
|
|
|
val data = it.data as DeviceInfo
|
|
|
|
println("DuoEK INFO DATA: $data")
|
|
|
|
println("DuoEK INFO DATA: $data")
|
|
|
|
val returnData = mapOf("type" to "infoData", "data" to data.toString())
|
|
|
|
val returnData = mapOf("type" to "infoData", "data" to data.toString())
|
|
|
|
|
|
|
|
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER2.EventEr2FileList).observe(this.mainActivity) {
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER2.EventEr2FileList).observe(this.mainActivity) {
|
|
|
|
@ -357,7 +358,7 @@ class BleBridge(
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.BP2.EventBp2Info).observe(this.mainActivity) {
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.BP2.EventBp2Info).observe(this.mainActivity) {
|
|
|
|
val data = it.data as com.lepu.blepro.ext.bp2.DeviceInfo
|
|
|
|
val data = it.data as com.lepu.blepro.ext.bp2.DeviceInfo
|
|
|
|
println("BP2 INFO DATA: $data")
|
|
|
|
println("BP2 INFO DATA: $data")
|
|
|
|
val returnData = mapOf("type" to "infoData", "data" to data.toString())
|
|
|
|
val returnData = mapOf("type" to "infoData", "data" to data.toString(), "deviceName" to deviceName)
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
BleServiceHelper.BleServiceHelper.startRtTask(model)
|
|
|
|
BleServiceHelper.BleServiceHelper.startRtTask(model)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -414,7 +415,7 @@ class BleBridge(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.BP2.EventBp2RtData).observe(this.mainActivity) {
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.BP2.EventBp2RtData).observe(this.mainActivity) {
|
|
|
|
val data = it.data as RTBP2Data
|
|
|
|
val data = it.data as com.lepu.blepro.ext.bp2.RtData
|
|
|
|
// data.status: RtStatus
|
|
|
|
// data.status: RtStatus
|
|
|
|
// data.status.deviceStatus: 0(STATUS_SLEEP), 1(STATUS_MEMERY), 2(STATUS_CHARGE), 3(STATUS_READY),
|
|
|
|
// data.status.deviceStatus: 0(STATUS_SLEEP), 1(STATUS_MEMERY), 2(STATUS_CHARGE), 3(STATUS_READY),
|
|
|
|
// 4(STATUS_BP_MEASURING), 5(STATUS_BP_MEASURE_END),
|
|
|
|
// 4(STATUS_BP_MEASURING), 5(STATUS_BP_MEASURE_END),
|
|
|
|
@ -424,10 +425,27 @@ class BleBridge(
|
|
|
|
// data.param: RtParam
|
|
|
|
// data.param: RtParam
|
|
|
|
// data.param.paramDataType: 0(Bp measuring), 1(Bp end), 2(Ecg measuring), 3(Ecg end)
|
|
|
|
// data.param.paramDataType: 0(Bp measuring), 1(Bp end), 2(Ecg measuring), 3(Ecg end)
|
|
|
|
|
|
|
|
|
|
|
|
println("EventBp2RtData FOR BP : $data")
|
|
|
|
when (data.param.paramDataType) {
|
|
|
|
val returnData = mapOf("type" to "RealTimeDataBP2", "data" to gson.toJson(data))
|
|
|
|
0 -> {
|
|
|
|
println(returnData)
|
|
|
|
val bpIng = RtBpIng(data.param.paramData)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val returnData = mapOf("type" to "RealTimeDataBP2Measuring", "data" to gson.toJson(bpIng))
|
|
|
|
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|