Added ER1 Without fileList

dev_3.3_BLE
Faiz Hashmi 2 years ago
parent 1cc77e7d32
commit 43f149d940

@ -51,7 +51,7 @@ android {
disable 'MissingTranslation' disable 'MissingTranslation'
checkReleaseBuilds false checkReleaseBuilds false
} }
defaultConfig { defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
@ -122,7 +122,7 @@ dependencies {
// }) // })
implementation 'pub.devrel:easypermissions:0.4.0' implementation 'pub.devrel:easypermissions:0.4.0'
// implementation 'com.google.firebase:firebase-inappmessaging-display:17.2.0' // implementation 'com.google.firebase:firebase-inappmessaging-display:17.2.0'
// implementation 'com.google.firebase:firebase-inappmessaging-display:17.2.0' // implementation 'com.google.firebase:firebase-inappmessaging-display:17.2.0'
implementation 'com.google.guava:guava:27.0.1-android' implementation 'com.google.guava:guava:27.0.1-android'
// Dependency on local binaries // Dependency on local binaries
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
@ -146,12 +146,13 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
implementation 'androidx.work:work-runtime:2.7.0-alpha05' implementation 'androidx.work:work-runtime:2.7.0-alpha05'
androidTestImplementation "androidx.test:core:1.4.0" androidTestImplementation "androidx.test:core:1.4.0"
// Lepu Libraries // Lepu Libraries
implementation 'no.nordicsemi.android:ble:2.2.4' implementation 'no.nordicsemi.android:ble:2.2.4'
implementation(name: 'lepu-blepro-1.0.1', ext: 'aar') implementation(name: 'lepu-blepro-1.0.1', ext: 'aar')
implementation 'io.github.jeremyliao:live-event-bus-x:1.8.0' implementation 'io.github.jeremyliao:live-event-bus-x:1.8.0'
implementation 'com.guolindev.permissionx:permissionx:1.7.1' implementation 'com.guolindev.permissionx:permissionx:1.7.1'
implementation 'org.apache.commons:commons-io:1.3.2' // for FileUtills in ER1 device configuration
} }

@ -14,6 +14,7 @@ import com.cloud.diplomaticquarterapp.ble.BPModelMeasuring
import com.cloud.diplomaticquarterapp.ble.BPModelResult import com.cloud.diplomaticquarterapp.ble.BPModelResult
import com.cloud.diplomaticquarterapp.ble.OxymeterModel import com.cloud.diplomaticquarterapp.ble.OxymeterModel
import com.cloud.diplomaticquarterapp.ble.utils.EcgData import com.cloud.diplomaticquarterapp.ble.utils.EcgData
import com.cloud.diplomaticquarterapp.ble.utils.HexString
import com.google.gson.Gson import com.google.gson.Gson
@ -32,12 +33,18 @@ 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.bp2.*
import com.lepu.blepro.ext.er1.Er1Config
import com.lepu.blepro.ext.er1.Er1EcgFile
import com.lepu.blepro.ext.er1.Er1File
import com.lepu.blepro.ext.er1.Er1HrFile
import com.lepu.blepro.ext.pc60fw.RtParam import com.lepu.blepro.ext.pc60fw.RtParam
import com.lepu.blepro.ext.sp20.RtWave import com.lepu.blepro.ext.sp20.RtWave
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.utils.DateUtil import com.lepu.blepro.utils.DateUtil
import com.lepu.blepro.utils.Er1Decompress import com.lepu.blepro.utils.Er1Decompress
import org.apache.commons.io.FileUtils
import java.io.File
class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivity: MainActivity) { class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivity: MainActivity) {
@ -210,14 +217,12 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
private fun scanDevice() { private fun scanDevice() {
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---------")
BleServiceHelper.BleServiceHelper.startScan(models) BleServiceHelper.BleServiceHelper.startScan(models)
println("EventServiceConnectedAndInterfaceInit") println("EventServiceConnectedAndInterfaceInit")
} }
LiveEventBus.get<Bluetooth>(EventMsgConst.Discovery.EventDeviceFound).observe(this.mainActivity) { LiveEventBus.get<Bluetooth>(EventMsgConst.Discovery.EventDeviceFound).observe(this.mainActivity) {
val deviceName: String = "" val deviceName: String = ""
val returnData = mapOf("type" to "DevicesList", "data" to gson.toJson(BluetoothController.getDevices())) val returnData = mapOf("type" to "DevicesList", "data" to gson.toJson(BluetoothController.getDevices()))
@ -231,7 +236,6 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
val rawFolders = SparseArray<String>() val rawFolders = SparseArray<String>()
try { try {
BleServiceHelper.BleServiceHelper.initRawFolder(rawFolders).initService(this.mainActivity.application) BleServiceHelper.BleServiceHelper.initRawFolder(rawFolders).initService(this.mainActivity.application)
} catch (e: Exception) { } catch (e: Exception) {
println(e) println(e)
} }
@ -251,20 +255,16 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
eventSink?.success(returnData) eventSink?.success(returnData)
BleServiceHelper.BleServiceHelper.startRtTask(model) BleServiceHelper.BleServiceHelper.startRtTask(model)
} }
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER2.EventEr2FactoryReset).observe(this.mainActivity) {
val data = it.data as Boolean // We will get a ping from here to confirm if reset success
}
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER2.EventEr2FileList).observe(this.mainActivity) { LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER2.EventEr2FileList).observe(this.mainActivity) {
BleServiceHelper.BleServiceHelper.stopRtTask(model) BleServiceHelper.BleServiceHelper.stopRtTask(model)
ecgFileNames = it.data as ArrayList<String> ecgFileNames = it.data as ArrayList<String>
readFileForEr2() readFileForEr2()
// 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) { LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER2.EventEr2SetTime).observe(this.mainActivity) {
println("EventEr2SetTime") println("EventEr2SetTime")
// Get Device Info
BleServiceHelper.BleServiceHelper.er2GetInfo(model) BleServiceHelper.BleServiceHelper.er2GetInfo(model)
// ecgRTTask.run() // ecgRTTask.run()
} }
@ -282,25 +282,69 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
ecgData.startTime = startTime ecgData.startTime = startTime
ecgList.add(ecgData) ecgList.add(ecgData)
print(ecgList) print(ecgList)
// val returnData =
// mapOf("type" to "fileDetail", "data" to gson.toJson(ecgList))
// eventSink?.success(returnData)
} }
ecgFileNames.removeAt(0) ecgFileNames.removeAt(0)
readFileForEr2() readFileForEr2()
} }
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER2.EventEr2RtData).observe(this.mainActivity) { LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER2.EventEr2RtData).observe(this.mainActivity) {
val data = it.data as RtData val data = it.data as RtData
println("EventEr2RtData") println("EventEr2RtData")
val returnData = mapOf("type" to "RealTimeDataECG", "data" to gson.toJson(data)) val returnData = mapOf("type" to "RealTimeDataECG", "data" to gson.toJson(data))
println(returnData) println(returnData)
eventSink?.success(returnData) eventSink?.success(returnData)
// DataController.receive(data.wave.ecgFloats) }
// hr.text = "${data.param.hr}" }
// data_log.text = "${data.param}"
if (deviceName.contains("ER1")) {
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER1.EventEr1Info).observe(this.mainActivity) {
val data = it.data as com.lepu.blepro.ext.er1.DeviceInfo
println("ER1 INFO DATA: $data")
val returnData = mapOf("type" to "infoData", "data" to data.toString())
eventSink?.success(returnData)
BleServiceHelper.BleServiceHelper.startRtTask(model)
}
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER1.EventEr1ResetFactory).observe(this.mainActivity) {
val data = it.data as Boolean
}
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER1.EventEr1FileList).observe(this.mainActivity) {
BleServiceHelper.BleServiceHelper.stopRtTask(model)
ecgFileNames = it.data as ArrayList<String>
readFileForEr1()
}
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER1.EventEr1SetTime).observe(this.mainActivity) {
println("EventEr1SetTime")
BleServiceHelper.BleServiceHelper.er1GetInfo(model)
}
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER1.EventEr1ReadFileComplete).observe(this.mainActivity) {
println("EventEr1ReadFileComplete")
val rawFile = getOffset(it.model, ecgFileNames[0], "")
val data = it.data as Er1File
val file = if (rawFile.isEmpty()) {
Er1EcgFile(data.content)
} else {
Er1EcgFile(rawFile)
}
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)
ecgFileNames.removeAt(0)
readFileForEr1()
}
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.ER1.EventEr1RtData).observe(this.mainActivity) {
val data = it.data as com.lepu.blepro.ext.er1.RtData
println("EventEr2RtData")
val returnData = mapOf("type" to "RealTimeDataECG", "data" to gson.toJson(data))
println(returnData)
eventSink?.success(returnData)
// sampling rate125HZ // sampling rate125HZ
// mV = n * 0.002467data.wave.ecgFloats = data.wave.ecgShorts * 0.002467 // mV = n * 0.002467data.wave.ecgFloats = data.wave.ecgShorts * 0.002467
// data.param.batteryState0no charge1charging2charging complete3low battery // data.param.batteryState0no charge1charging2charging complete3low battery
@ -312,9 +356,7 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
} }
// OXYMETER // OXYMETER
if (deviceName == "POD-1_SN8187" || deviceName == "PC-60FW") { //DONE if (deviceName == "POD-1_SN8187" || deviceName == "PC-60FW") { //DONE
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.PC60Fw.EventPC60FwRtParam).observe(this.mainActivity) { LiveEventBus.get<InterfaceEvent>(InterfaceEvent.PC60Fw.EventPC60FwRtParam).observe(this.mainActivity) {
val data = it.data as RtParam val data = it.data as RtParam
@ -326,6 +368,7 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
} }
} }
if (deviceName == "O2M 1670" || deviceName == "O2Ring 4135") { // DONE if (deviceName == "O2M 1670" || deviceName == "O2Ring 4135") { // DONE
rtHandler.removeCallbacks(rtTask) rtHandler.removeCallbacks(rtTask)
rtHandler.post(rtTask) rtHandler.post(rtTask)
@ -339,13 +382,12 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
} }
} }
if (deviceName.contains("SP-20", ignoreCase = true)) { //DONE
if (deviceName.contains("SP-20", ignoreCase = true)) { //DONE
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.SP20.EventSp20SetTime).observe(this.mainActivity) { LiveEventBus.get<InterfaceEvent>(InterfaceEvent.SP20.EventSp20SetTime).observe(this.mainActivity) {
println("EventSp20SetTime") println("EventSp20SetTime")
BleServiceHelper.BleServiceHelper.bp2GetInfo(model) BleServiceHelper.BleServiceHelper.bp2GetInfo(model)
} }
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.SP20.EventSp20DeviceInfo).observe(this.mainActivity) { LiveEventBus.get<InterfaceEvent>(InterfaceEvent.SP20.EventSp20DeviceInfo).observe(this.mainActivity) {
val data = it.data as com.lepu.blepro.ext.sp20.DeviceInfo val data = it.data as com.lepu.blepro.ext.sp20.DeviceInfo
println("EventSp20DeviceInfo: $data") println("EventSp20DeviceInfo: $data")
@ -353,7 +395,6 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
eventSink?.success(returnData) eventSink?.success(returnData)
BleServiceHelper.BleServiceHelper.startRtTask(model) BleServiceHelper.BleServiceHelper.startRtTask(model)
} }
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.SP20.EventSp20RtParam).observe(this.mainActivity) { LiveEventBus.get<InterfaceEvent>(InterfaceEvent.SP20.EventSp20RtParam).observe(this.mainActivity) {
val data = it.data as com.lepu.blepro.ext.sp20.RtParam val data = it.data as com.lepu.blepro.ext.sp20.RtParam
println("OxyRtParam: $data") println("OxyRtParam: $data")
@ -366,19 +407,16 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
println("OxyRtParam: $data") println("OxyRtParam: $data")
} }
} }
//BLOOD PRESSURE //BLOOD PRESSURE
if (deviceName.contains("BP2", ignoreCase = true)) { if (deviceName.contains("BP2", ignoreCase = true)) {
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.BP2.EventBp2SyncTime).observe(this.mainActivity) { LiveEventBus.get<InterfaceEvent>(InterfaceEvent.BP2.EventBp2SyncTime).observe(this.mainActivity) {
println("EventBp2SyncTime") println("EventBp2SyncTime")
// Get Device Info // Get Device Info
BleServiceHelper.BleServiceHelper.bp2GetInfo(model) BleServiceHelper.BleServiceHelper.bp2GetInfo(model)
} }
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")
@ -386,14 +424,12 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
eventSink?.success(returnData) eventSink?.success(returnData)
BleServiceHelper.BleServiceHelper.startRtTask(model) BleServiceHelper.BleServiceHelper.startRtTask(model)
} }
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.BP2.EventBp2FileList).observe(this.mainActivity) { LiveEventBus.get<InterfaceEvent>(InterfaceEvent.BP2.EventBp2FileList).observe(this.mainActivity) {
BleServiceHelper.BleServiceHelper.stopRtTask(model) BleServiceHelper.BleServiceHelper.stopRtTask(model)
ecgFileNames = it.data as ArrayList<String> ecgFileNames = it.data as ArrayList<String>
println("EventBp2FileList: ${it.data}") println("EventBp2FileList: ${it.data}")
readFileForBp2() readFileForBp2()
} }
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.BP2.EventBp2ReadFileComplete).observe(this.mainActivity) { LiveEventBus.get<InterfaceEvent>(InterfaceEvent.BP2.EventBp2ReadFileComplete).observe(this.mainActivity) {
val data = it.data as Bp2File val data = it.data as Bp2File
// data.type: 1(BP), 2(ECG) // data.type: 1(BP), 2(ECG)
@ -420,7 +456,6 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
ecgFileNames.removeAt(0) ecgFileNames.removeAt(0)
readFileForBp2() readFileForBp2()
} }
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.BP2.EventBp2RtData).observe(this.mainActivity) { LiveEventBus.get<InterfaceEvent>(InterfaceEvent.BP2.EventBp2RtData).observe(this.mainActivity) {
val data = it.data as com.lepu.blepro.ext.bp2.RtData val data = it.data as com.lepu.blepro.ext.bp2.RtData
// data.status: RtStatus // data.status: RtStatus
@ -541,6 +576,15 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
} }
} }
private fun readFileForEr1() {
if (ecgFileNames.size == 0) {
val returnData = mapOf("type" to "FileDetail", "data" to gson.toJson(ecgList))
eventSink?.success(returnData)
} else {
BleServiceHelper.BleServiceHelper.er1ReadFile(model, ecgFileNames[0])
}
}
private fun readFileForBp2() { private fun readFileForBp2() {
if (ecgFileNames.size == 0) { if (ecgFileNames.size == 0) {
val returnData = mapOf("type" to "FileDetail", "data" to gson.toJson(ecgList)) val returnData = mapOf("type" to "FileDetail", "data" to gson.toJson(ecgList))
@ -550,6 +594,22 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
} }
} }
// sdk save the original file name : userId + fileName + .dat
private fun getOffset(model: Int, fileName: String, userId: String): ByteArray {
val trimStr = HexString.trimStr(fileName)
BleServiceHelper.BleServiceHelper.rawFolder?.get(model)?.let { s ->
val mFile = File(s, "$userId$trimStr.dat")
if (mFile.exists()) {
FileUtils.readFileToByteArray(mFile)?.let {
return it
}
} else {
return ByteArray(0)
}
}
return ByteArray(0)
}
private fun getECGFilesList(device: List<String>) { private fun getECGFilesList(device: List<String>) {
//Get ECG File List //Get ECG File List
val deviceName = device[0] val deviceName = device[0]

@ -1,26 +0,0 @@
//package com.cloud.diplomaticquarterapp.ble.utils;
//
////
//// Source code recreated from a .class file by IntelliJ IDEA
//// (powered by FernFlower decompiler)
////
//
//
//import doac.docd;
//import doag.doad;
//import doag.doae;
//
//public class DecompressUtil {
// private static doad er1Decompress;
// private static doae er3Decompress;
// private static docd waveFile;
// private static int leadType;
//
// public DecompressUtil() {
// }
//
// public static short[] er1Decompress(byte[] var0) {
// return doad. do (var0);
// }
//
//}

@ -55,7 +55,7 @@ class MyTrackersViewModel extends ChangeNotifier {
], ],
"ECGTracker": [ "ECGTracker": [
{"model": "DuoEK"}, {"model": "DuoEK"},
{"model": ""}, {"model": "ER1"},
{"model": ""}, {"model": ""},
{"model": ""}, {"model": ""},
], ],
@ -67,7 +67,7 @@ class MyTrackersViewModel extends ChangeNotifier {
], ],
}; };
List<String> ecgEnabledDevices = ["BP2 0567", "DuoEK"]; List<String> ecgEnabledDevices = ["BP2 0567", "DuoEK", "ER1"];
//************************************* OXYMETER ************************************* //************************************* OXYMETER *************************************

Loading…
Cancel
Save