|
|
|
@ -1,5 +1,6 @@
|
|
|
|
package com.cloud.diplomaticquarterapp.ble
|
|
|
|
package com.cloud.diplomaticquarterapp.ble
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import TmpInfo
|
|
|
|
import android.annotation.SuppressLint
|
|
|
|
import android.annotation.SuppressLint
|
|
|
|
import android.bluetooth.BluetoothDevice
|
|
|
|
import android.bluetooth.BluetoothDevice
|
|
|
|
import android.os.Build
|
|
|
|
import android.os.Build
|
|
|
|
@ -13,7 +14,6 @@ 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.HexString
|
|
|
|
import com.cloud.diplomaticquarterapp.ble.utils.HexString
|
|
|
|
import com.cloud.diplomaticquarterapp.check_me_pro.UiChannel
|
|
|
|
|
|
|
|
import com.cloud.diplomaticquarterapp.check_me_pro.bean.BleBean
|
|
|
|
import com.cloud.diplomaticquarterapp.check_me_pro.bean.BleBean
|
|
|
|
import com.cloud.diplomaticquarterapp.check_me_pro.bean.UserBean
|
|
|
|
import com.cloud.diplomaticquarterapp.check_me_pro.bean.UserBean
|
|
|
|
import com.cloud.diplomaticquarterapp.check_me_pro.ble.format.UserInfo
|
|
|
|
import com.cloud.diplomaticquarterapp.check_me_pro.ble.format.UserInfo
|
|
|
|
@ -21,6 +21,12 @@ import com.cloud.diplomaticquarterapp.check_me_pro.ble.manager.BleScanManager
|
|
|
|
import com.cloud.diplomaticquarterapp.check_me_pro.ble.worker.BleDataWorker
|
|
|
|
import com.cloud.diplomaticquarterapp.check_me_pro.ble.worker.BleDataWorker
|
|
|
|
import com.cloud.diplomaticquarterapp.utils.Constant
|
|
|
|
import com.cloud.diplomaticquarterapp.utils.Constant
|
|
|
|
import com.cloud.diplomaticquarterapp.MainActivity
|
|
|
|
import com.cloud.diplomaticquarterapp.MainActivity
|
|
|
|
|
|
|
|
import com.cloud.diplomaticquarterapp.check_me_pro.bean.toJson
|
|
|
|
|
|
|
|
import com.cloud.diplomaticquarterapp.check_me_pro.ble.format.BpInfo
|
|
|
|
|
|
|
|
import com.cloud.diplomaticquarterapp.check_me_pro.ble.format.EcgInfo
|
|
|
|
|
|
|
|
import com.cloud.diplomaticquarterapp.check_me_pro.ble.format.GluInfo
|
|
|
|
|
|
|
|
import com.cloud.diplomaticquarterapp.check_me_pro.ble.format.OxyInfo
|
|
|
|
|
|
|
|
import com.cloud.diplomaticquarterapp.utils.UiChannel
|
|
|
|
import com.google.gson.Gson
|
|
|
|
import com.google.gson.Gson
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -56,6 +62,8 @@ import kotlinx.coroutines.withTimeoutOrNull
|
|
|
|
import org.apache.commons.io.FileUtils
|
|
|
|
import org.apache.commons.io.FileUtils
|
|
|
|
import org.json.JSONObject
|
|
|
|
import org.json.JSONObject
|
|
|
|
import java.io.File
|
|
|
|
import java.io.File
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat
|
|
|
|
|
|
|
|
import java.util.Locale
|
|
|
|
|
|
|
|
|
|
|
|
class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivity: MainActivity) {
|
|
|
|
class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivity: MainActivity) {
|
|
|
|
|
|
|
|
|
|
|
|
@ -102,7 +110,6 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
|
|
|
|
|
|
|
|
|
|
|
|
var mUserData: MutableList<UserBean> = java.util.ArrayList()
|
|
|
|
var mUserData: MutableList<UserBean> = java.util.ArrayList()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val userChannel = Channel<Int>(Channel.CONFLATED)
|
|
|
|
private val userChannel = Channel<Int>(Channel.CONFLATED)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -311,6 +318,7 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
|
|
|
|
|
|
|
|
|
|
|
|
@RequiresApi(Build.VERSION_CODES.M)
|
|
|
|
@RequiresApi(Build.VERSION_CODES.M)
|
|
|
|
private fun scanForCheckMePro(bleScanManager: BleScanManager, scanResultHandler: (String, BluetoothDevice) -> Unit) {
|
|
|
|
private fun scanForCheckMePro(bleScanManager: BleScanManager, scanResultHandler: (String, BluetoothDevice) -> Unit) {
|
|
|
|
|
|
|
|
initVar()
|
|
|
|
bleScanManager.initScan(this.mainActivity)
|
|
|
|
bleScanManager.initScan(this.mainActivity)
|
|
|
|
bleScanManager.setCallBack(object : BleScanManager.Scan {
|
|
|
|
bleScanManager.setCallBack(object : BleScanManager.Scan {
|
|
|
|
override fun scanReturn(name: String, bluetoothDevice: BluetoothDevice) {
|
|
|
|
override fun scanReturn(name: String, bluetoothDevice: BluetoothDevice) {
|
|
|
|
@ -319,6 +327,10 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun initVar() {
|
|
|
|
|
|
|
|
Constant.initVar(this.mainActivity)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("MissingPermission")
|
|
|
|
@SuppressLint("MissingPermission")
|
|
|
|
fun onScanResult(name: String, bluetoothDevice: BluetoothDevice) {
|
|
|
|
fun onScanResult(name: String, bluetoothDevice: BluetoothDevice) {
|
|
|
|
@ -356,7 +368,8 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
|
|
|
|
|
|
|
|
|
|
|
|
private suspend fun readUserFromCheckMePro() {
|
|
|
|
private suspend fun readUserFromCheckMePro() {
|
|
|
|
userChannel.receive()
|
|
|
|
userChannel.receive()
|
|
|
|
val userTemp = File(Constant.getPathX("usr.dat")).readBytes()
|
|
|
|
|
|
|
|
|
|
|
|
val userTemp = File(Constant.getPathX("usr.dat")).readBytes() // CRASHES HERE
|
|
|
|
userTemp.apply {
|
|
|
|
userTemp.apply {
|
|
|
|
userInfo = UserInfo(this)
|
|
|
|
userInfo = UserInfo(this)
|
|
|
|
|
|
|
|
|
|
|
|
@ -369,6 +382,7 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
|
|
|
|
tIndex++
|
|
|
|
tIndex++
|
|
|
|
UiChannel.progressChannel.send(tIndex * 100 / total)
|
|
|
|
UiChannel.progressChannel.send(tIndex * 100 / total)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mUserData.add(user)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (f in commonFileName) {
|
|
|
|
for (f in commonFileName) {
|
|
|
|
bleWorker.getFile(f)
|
|
|
|
bleWorker.getFile(f)
|
|
|
|
@ -378,7 +392,105 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
|
|
|
|
|
|
|
|
|
|
|
|
delay(300)
|
|
|
|
delay(300)
|
|
|
|
UiChannel.progressChannel.close()
|
|
|
|
UiChannel.progressChannel.close()
|
|
|
|
|
|
|
|
sendUsersDataToFlutter()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun sendUsersDataToFlutter() {
|
|
|
|
|
|
|
|
if (mUserData.isNotEmpty()) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val jsonDataList = mutableListOf<String>()
|
|
|
|
|
|
|
|
for (user in mUserData) {
|
|
|
|
|
|
|
|
val jsonData = user.toJson()
|
|
|
|
|
|
|
|
jsonDataList.add(jsonData)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Log.d("userBeanJSON", jsonDataList.toString())
|
|
|
|
|
|
|
|
val returnData = mapOf("type" to "CheckMeUsersList", "data" to jsonDataList)
|
|
|
|
|
|
|
|
eventSink?.success(returnData)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun getBPDataFromCheckMePro(s: String) {
|
|
|
|
|
|
|
|
val file = File(Constant.getPathX(s + "nibp.dat"))
|
|
|
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
|
|
|
val temp = file.readBytes()
|
|
|
|
|
|
|
|
if (temp.isNotEmpty()) {
|
|
|
|
|
|
|
|
temp.let {
|
|
|
|
|
|
|
|
val f = BpInfo(it)
|
|
|
|
|
|
|
|
val json = gson.toJson(f.Bp)
|
|
|
|
|
|
|
|
Log.d("BPMeter", json.toString())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// HANDLE FAILURE HERE WITH A GENERIC DATA MAP TO FLUTTER
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun getGlucoseDataFromCheckMePro(s: String) {
|
|
|
|
|
|
|
|
val file = File(Constant.getPathX(s + "glu.dat"))
|
|
|
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
|
|
|
val temp = file.readBytes()
|
|
|
|
|
|
|
|
if (temp.isNotEmpty()) {
|
|
|
|
|
|
|
|
temp.let {
|
|
|
|
|
|
|
|
val f = GluInfo(it)
|
|
|
|
|
|
|
|
val json = gson.toJson(f.Glu)
|
|
|
|
|
|
|
|
Log.d("BloodGlucoseMeter", json.toString())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// HANDLE FAILURE HERE WITH A GENERIC DATA MAP TO FLUTTER
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun getOxyDataFromCheckMePro() {
|
|
|
|
|
|
|
|
val file = File(Constant.getPathX("oxi.dat"))
|
|
|
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
|
|
|
val temp = file.readBytes()
|
|
|
|
|
|
|
|
if (temp.isNotEmpty()) {
|
|
|
|
|
|
|
|
temp.let {
|
|
|
|
|
|
|
|
val f = OxyInfo(it)
|
|
|
|
|
|
|
|
val json = gson.toJson(f.Oxy)
|
|
|
|
|
|
|
|
Log.d("Oximeter", json.toString())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// HANDLE FAILURE HERE WITH A GENERIC DATA MAP TO FLUTTER
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun getECGDataFromCheckMePro() {
|
|
|
|
|
|
|
|
val file = File(Constant.getPathX("ecg.dat"))
|
|
|
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
|
|
|
val temp = file.readBytes()
|
|
|
|
|
|
|
|
if (temp.isNotEmpty()) {
|
|
|
|
|
|
|
|
temp.let {
|
|
|
|
|
|
|
|
val f = EcgInfo(it)
|
|
|
|
|
|
|
|
val json = gson.toJson(f.ecg)
|
|
|
|
|
|
|
|
Log.d("ECGMeter", json.toString())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// HANDLE FAILURE HERE WITH A GENERIC DATA MAP TO FLUTTER
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun getTemperatureDataFromCheckMePro() {
|
|
|
|
|
|
|
|
val file = File(Constant.getPathX("tmp.dat"))
|
|
|
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
|
|
|
val temp = file.readBytes()
|
|
|
|
|
|
|
|
if (temp.isNotEmpty()) {
|
|
|
|
|
|
|
|
temp.let {
|
|
|
|
|
|
|
|
val f = TmpInfo(it)
|
|
|
|
|
|
|
|
val json = gson.toJson(f.Tmp)
|
|
|
|
|
|
|
|
Log.d("TempMeter", json.toString())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// HANDLE FAILURE HERE WITH A GENERIC DATA MAP TO FLUTTER
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -709,24 +821,41 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
|
|
|
|
Log.d("DeviceFound", "This is the Device i have : ${currentBluetoothDevice.name}")
|
|
|
|
Log.d("DeviceFound", "This is the Device i have : ${currentBluetoothDevice.name}")
|
|
|
|
// stopScanForCheckMePro()
|
|
|
|
// stopScanForCheckMePro()
|
|
|
|
bleWorker.initWorker(this.mainActivity, currentBluetoothDevice.bluetoothDevice)
|
|
|
|
bleWorker.initWorker(this.mainActivity, currentBluetoothDevice.bluetoothDevice)
|
|
|
|
|
|
|
|
dataScope.launch {
|
|
|
|
uiScope.launch {
|
|
|
|
|
|
|
|
val a = withTimeoutOrNull(10000) {
|
|
|
|
val a = withTimeoutOrNull(10000) {
|
|
|
|
bleWorker.waitConnect()
|
|
|
|
bleWorker.waitConnect()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
a?.let {
|
|
|
|
|
|
|
|
val b = withTimeoutOrNull(10000) {
|
|
|
|
|
|
|
|
Log.d("getFile", "getFile 718")
|
|
|
|
|
|
|
|
bleWorker.getFile("usr.dat")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
b?.let {
|
|
|
|
|
|
|
|
userChannel.send(1)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
uiScope.launch {
|
|
|
|
|
|
|
|
readUserFromCheckMePro()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// uiScope.launch {
|
|
|
|
|
|
|
|
// val a = withTimeoutOrNull(10000) {
|
|
|
|
|
|
|
|
// bleWorker.waitConnect()
|
|
|
|
|
|
|
|
// }
|
|
|
|
// a?.let {
|
|
|
|
// a?.let {
|
|
|
|
// val b = withTimeoutOrNull(10000) {
|
|
|
|
// val b = withTimeoutOrNull(10000) {
|
|
|
|
// bleWorker.getFile("usr.dat")
|
|
|
|
// bleWorker.getFile("usr.dat")
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// b?.let {
|
|
|
|
|
|
|
|
// userChannel.send(1)
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// uiScope.launch {
|
|
|
|
// uiScope.launch {
|
|
|
|
//// readUserFromCheckMePro()
|
|
|
|
////
|
|
|
|
// getCheckMeProDeviceInfo()
|
|
|
|
// getCheckMeProDeviceInfo()
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|