@ -10,6 +10,8 @@ import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.EventChannel
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.BPModelMeasuring
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.google.gson.Gson
import com.google.gson.Gson
@ -44,7 +46,6 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
private var eventSink : EventChannel . EventSink ? = null
private var eventSink : EventChannel . EventSink ? = null
private var ecgFileNames = arrayListOf < String > ( )
private var ecgFileNames = arrayListOf < String > ( )
private var bpFileNames = arrayListOf < String > ( )
var ecgList : ArrayList < EcgData > = arrayListOf ( )
var ecgList : ArrayList < EcgData > = arrayListOf ( )
@ -53,13 +54,13 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
companion object {
companion object {
private const val CHANNEL = " BLE-Platform-Bridge "
private const val CHANNEL = " BLE-Platform-Bridge "
private const val EVENTCHANNEL = " BLE-Platform-Bridge-Event "
private const val EVENTCHANNEL = " BLE-Platform-Bridge-Event "
private const val SCAN _DEVICE = " scan "
private const val SCAN _DEVICE = " scan Devices "
private const val CONNECT _DEVICE = " connectDevice "
private const val CONNECT _DEVICE = " connectDevice "
private const val SCAN _DEVICE _EKG = " scan_ekg "
private const val SCAN _DEVICE _EKG = " scan_ekg "
private const val EKG _FILES _LIST = " e kg_files_l ist"
private const val EKG _FILES _LIST = " e cgFilesL ist"
private const val BP2_FILES _LIST = " bp2_files_list "
private const val FACTORY_RESET _ECG = " factoryResetECG "
private const val EKG_FILE _DETAIL = " ekg_file_detail "
private const val BP2_FILES _LIST = " bp2FilesList "
private const val DISCONNECT _DEVICE = " disconnect _d evice"
private const val DISCONNECT _DEVICE = " disconnect D evice"
}
}
@ -176,12 +177,11 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
} else if ( methodCall . method == SCAN _DEVICE _EKG ) {
} else if ( methodCall . method == SCAN _DEVICE _EKG ) {
// scanDeviceEKG(methodCall, result)
// scanDeviceEKG(methodCall, result)
} else if ( methodCall . method == EKG _FILES _LIST ) {
} else if ( methodCall . method == EKG _FILES _LIST ) {
getEKGFilesList ( )
getECGFilesList ( methodCall . arguments as List < String > )
} else if ( methodCall . method == FACTORY _RESET _ECG ) {
factoryResetECG ( methodCall . arguments as List < String > )
} else if ( methodCall . method == BP2 _FILES _LIST ) {
} else if ( methodCall . method == BP2 _FILES _LIST ) {
getBP2FilesList ( )
getBP2FilesList ( )
} else if ( methodCall . method == EKG _FILE _DETAIL ) {
val fileName = methodCall . arguments ;
getEKGFileDetail ( fileName . toString ( ) )
} else {
} else {
result . notImplemented ( )
result . notImplemented ( )
}
}
@ -220,8 +220,8 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
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 " d evicesList" , " data " to gson . toJson ( BluetoothController . getDevices ( ) ) )
val returnData = mapOf ( " type " to " D evicesList" , " data " to gson . toJson ( BluetoothController . getDevices ( ) ) )
println ( " d evicesList: ${BluetoothController.getDevices()} " ) ;
println ( " D evicesList: ${BluetoothController.getDevices()} " ) ;
eventSink ?. success ( returnData )
eventSink ?. success ( returnData )
println ( " EventDeviceFound " )
println ( " EventDeviceFound " )
@ -248,13 +248,13 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
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 )
BleServiceHelper . BleServiceHelper . startRtTask ( model )
}
}
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 >
readFile ( )
readFile ForEr2 ( )
// val fileNames = it.data as ArrayList<String>
// val fileNames = it.data as ArrayList<String>
// println("DuoEK FileNames List: ${fileNames}")
// println("DuoEK FileNames List: ${fileNames}")
// val returnData =
// val returnData =
@ -288,13 +288,13 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
}
}
ecgFileNames . removeAt ( 0 )
ecgFileNames . removeAt ( 0 )
readFile ( )
readFile ForEr2 ( )
}
}
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 " realt imeDataECG" , " data " to gson . toJson ( data ) )
val returnData = mapOf ( " type " to " RealT imeDataECG" , " data " to gson . toJson ( data ) )
println ( returnData )
println ( returnData )
eventSink ?. success ( returnData )
eventSink ?. success ( returnData )
// DataController.receive(data.wave.ecgFloats)
// DataController.receive(data.wave.ecgFloats)
@ -388,7 +388,10 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
}
}
LiveEventBus . get < InterfaceEvent > ( InterfaceEvent . BP2 . EventBp2FileList ) . observe ( this . mainActivity ) {
LiveEventBus . get < InterfaceEvent > ( InterfaceEvent . BP2 . EventBp2FileList ) . observe ( this . mainActivity ) {
bpFileNames = it . data as ArrayList < String >
BleServiceHelper . BleServiceHelper . stopRtTask ( model )
ecgFileNames = it . data as ArrayList < String >
println ( " EventBp2FileList: ${it.data} " )
readFileForBp2 ( )
}
}
LiveEventBus . get < InterfaceEvent > ( InterfaceEvent . BP2 . EventBp2ReadFileComplete ) . observe ( this . mainActivity ) {
LiveEventBus . get < InterfaceEvent > ( InterfaceEvent . BP2 . EventBp2ReadFileComplete ) . observe ( this . mainActivity ) {
@ -403,35 +406,18 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
} else if ( data . type == 2 ) {
} else if ( data . type == 2 ) {
val file = EcgFile ( data . content )
val file = EcgFile ( data . content )
val ecgShorts = Er1Decompress . unCompressAlgECG ( file . waveData )
val ecgData = EcgData ( )
val ecgData = EcgData ( )
val startTime = DateUtil . getSecondTimestamp ( data . fileName )
val startTime = DateUtil . getSecondTimestamp ( data . fileName )
ecgData . fileName = data . fileName
ecgData . fileName = data . fileName
ecgData . duration = file . recordingTime
ecgData . duration = file . recordingTime
ecgData . shortData = Er1Decompress . unCompressAlgECG ( file . waveData )
ecgData . shortData = ecgShorts
// ecgData.shortData = FilterUtil.getEcgFileFilterData(it.model, data.content)
ecgData . startTime = startTime
ecgData . startTime = startTime
ecgList . add ( ecgData )
ecgList . add ( ecgData )
// sampling rate: 125HZ
print ( ecgList )
// 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 " )
}
}
bp FileNames. removeAt ( 0 )
ecgFileNames . removeAt ( 0 )
readFileForBp2 ( )
readFileForBp2 ( )
}
}
@ -450,20 +436,68 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
0 -> {
0 -> {
val bpIng = RtBpIng ( data . param . paramData )
val bpIng = RtBpIng ( data . param . paramData )
val returnData = mapOf ( " type " to " RealTimeDataBP2Measuring " , " data " to gson . toJson ( bpIng ) )
//class BpRtMeasuringModel {
// bool deflate;
// int pr;
// int pressure;
// bool pulse;
val bpMeasuring = BPModelMeasuring ( bpIng . pressure , bpIng . pr , bpIng . isDeflate , bpIng . isPulse ) ;
val returnData = mapOf ( " type " to " RealTimeDataBPMeasuring " , " data " to gson . toJson ( bpMeasuring ) )
eventSink ?. success ( returnData )
eventSink ?. success ( returnData )
}
}
1 -> {
1 -> {
val bpResult = RtBpResult ( data . param . paramData )
val bpResult = RtBpResult ( data . param . paramData )
val returnData = mapOf ( " type " to " RealTimeDataBP2Result " , " data " to gson . toJson ( bpResult ) )
val bpModel = BPModelResult ( bpResult . isDeflate , bpResult . dia , bpResult . mean , bpResult . pr , bpResult . pressure , bpResult . result , bpResult . sys ) ;
println ( " RealTimeDataBP2Result FOR BP : $returnData " )
val returnData = mapOf ( " type " to " RealTimeDataBPResult " , " data " to gson . toJson ( bpModel ) )
eventSink ?. success ( returnData )
eventSink ?. success ( returnData )
}
}
2 -> {
val ecgIng = RtEcgIng ( data . param . paramData )
val returnData = mapOf ( " type " to " RealTimeDataECGMeasuring " , " data " to gson . toJson ( ecgIng ) )
println ( " RealTimeDataECGMeasuring: $returnData " )
eventSink ?. success ( returnData )
// hr.text = "${ecgIng.hr}"
// data_log.text = "lead status: ${if (ecgIng.isLeadOff) "lead off" else "lead on"}\n" +
// "pool signal: ${if (ecgIng.isPoolSignal) "yes" else "no"}\n" +
// "duration: ${ecgIng.curDuration} s"
// DataController.receive(data.param.ecgFloatsFilter)
// sampling rate: 250HZ
// mV = n * 0.003098 (data.param.ecgFloats = data.param.ecgShorts * 0.003098)
}
3 -> {
val ecgResult = RtEcgResult ( data . param . paramData )
val returnData = mapOf ( " type " to " RealTimeDataECGResult " , " data " to gson . toJson ( ecgResult ) )
println ( " RealTimeDataECGResult: $returnData " )
eventSink ?. success ( returnData )
// hr.text = "${ecgResult.hr}"
// data_log.text = "result: ${ecgResult.diagnosis.resultMess}\n" +
// "hr: ${ecgResult.hr}\n" +
// "qrs: ${ecgResult.qrs}\n" +
// "pvcs: ${ecgResult.pvcs}\n" +
// "qtc: ${ecgResult.qtc}"
// ecgResult.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
}
}
}
@ -474,6 +508,7 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
}
}
@RequiresApi ( Build . VERSION_CODES . Q )
private fun connectDevice ( device : List < String > ) {
private fun connectDevice ( device : List < String > ) {
println ( " connectDevice: $device " ) ;
println ( " connectDevice: $device " ) ;
@ -497,9 +532,9 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
}
}
private fun readFile ( ) {
private fun readFile ForEr2 ( ) {
if ( ecgFileNames . size == 0 ) {
if ( ecgFileNames . size == 0 ) {
val returnData = mapOf ( " type " to " f ileDetail" , " data " to gson . toJson ( ecgList ) )
val returnData = mapOf ( " type " to " F ileDetail" , " data " to gson . toJson ( ecgList ) )
eventSink ?. success ( returnData )
eventSink ?. success ( returnData )
} else {
} else {
BleServiceHelper . BleServiceHelper . er2ReadFile ( model , ecgFileNames [ 0 ] )
BleServiceHelper . BleServiceHelper . er2ReadFile ( model , ecgFileNames [ 0 ] )
@ -508,26 +543,41 @@ class BleBridge(private var flutterEngine: FlutterEngine, private var mainActivi
private fun readFileForBp2 ( ) {
private fun readFileForBp2 ( ) {
if ( ecgFileNames . size == 0 ) {
if ( ecgFileNames . size == 0 ) {
val returnData = mapOf ( " type " to " f ileDetail" , " data " to gson . toJson ( ecgList ) )
val returnData = mapOf ( " type " to " F ileDetail" , " data " to gson . toJson ( ecgList ) )
eventSink ?. success ( returnData )
eventSink ?. success ( returnData )
} else {
} else {
BleServiceHelper . BleServiceHelper . bp2ReadFile ( model , bp FileNames[ 0 ] )
BleServiceHelper . BleServiceHelper . bp2ReadFile ( model , ecg FileNames[ 0 ] )
}
}
}
}
private fun getEKGFilesList ( ) {
private fun getECGFilesList ( device : List < String > ) {
//Get EKG File List
//Get ECG File List
BleServiceHelper . BleServiceHelper . er2GetFileList ( model )
val deviceName = device [ 0 ]
println ( " deviceName: $deviceName and model: $model " )
if ( deviceName . contains ( " DuoEK " ) ) {
BleServiceHelper . BleServiceHelper . er2GetFileList ( model ) ;
} else if ( deviceName . contains ( " BP2 " ) ) {
BleServiceHelper . BleServiceHelper . bp2GetFileList ( model ) ;
}
}
private fun factoryResetECG ( device : List < String > ) {
val deviceName = device [ 0 ]
println ( " deviceName: $deviceName and model: $model " )
if ( deviceName . contains ( " DuoEK " ) ) {
BleServiceHelper . BleServiceHelper . er2FactoryResetAll ( model ) ;
} else if ( deviceName . contains ( " BP2 " ) ) {
BleServiceHelper . BleServiceHelper . bp2FactoryResetAll ( model ) ;
}
}
}
private fun getBP2FilesList ( ) {
private fun getBP2FilesList ( ) {
//Get EKG File List
//Get BP2 File List
BleServiceHelper . BleServiceHelper . bp2GetFileList ( model )
BleServiceHelper . BleServiceHelper . bp2GetFileList ( model )
}
}
private fun getEKGFileDetail ( fileName : String ) {
// readFile()
// BleServiceHelper.BleServiceHelper.er2ReadFile(model, fileName)
}
}
}