From 3292a0e38239a69c1090845e1baa1e409843f20a Mon Sep 17 00:00:00 2001 From: Pritimay Sarkar Date: Wed, 2 Aug 2023 23:14:57 +0530 Subject: [PATCH 1/5] merge --- .../presentation/hemocube/HemoCubeFragment.kt | 68 ++++++++++++++++++- .../testRight/TestRightExpReference.kt | 2 +- .../presentation/testRight/UsbService.kt | 12 +++- 3 files changed, 78 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt index 08c3ab5..3fe5fee 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt @@ -14,6 +14,7 @@ import android.widget.Toast import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import com.example.hpostesting.data.DataHolder +import com.example.hpostesting.data.constant.HemoCubeCommands import com.example.hpostesting.data.model.patient.toHemoCubeTestData import com.example.hpostesting.presentation.UsbServiceListener import com.example.hpostesting.presentation.utils.MyDialogListener @@ -96,11 +97,11 @@ class HemoCubeFragment : Fragment() { override fun onClickNegativeButton() {} override fun onClickPositiveButton() { fetchHemoCubeResult() + sendCommandToHemoCube() } }) } }) - } binding.btnSubmit.setOnClickListener { @@ -194,7 +195,7 @@ class HemoCubeFragment : Fragment() { hemoCubeViewModel.progressBar.postValue(true) val fullReadOutput = StringBuilder() - (activity as HemocubeActivity).mService.eventDrivenWriteHemoCube(object : + (activity as HemocubeActivity).mService.listenToHemoCube(object : UsbServiceListener { override fun onUsbRead(data: ByteArray?) { data?.let { @@ -216,4 +217,67 @@ class HemoCubeFragment : Fragment() { } }) } + + private fun fetchHemoCubeResultNew() { + hemoCubeViewModel.progressBar.postValue(true) + val fullReadOutput = StringBuilder() + (activity as HemocubeActivity).mService.listenToHemoCube(object : + UsbServiceListener { + override fun onUsbRead(data: ByteArray?) { + data?.let { + val stringData = String(it) + fullReadOutput.append(stringData) + + // Split the data into lines + val lines = fullReadOutput.toString().split("\n") + + // Filter and get only the lines starting with "#" + val bufferLines = lines.filter { it.startsWith("#") } + + // Create a new text with the filtered lines and join them with line breaks + val newText = bufferLines.joinToString("\n") + + // Update the TextView with the new text + binding.tvSubtitle4.text = newText + + // Get the result data + val data = parseUsbData(fullReadOutput.toString()) + Log.d("Result", data.toString()) + + // Update the view model with progress bar state + hemoCubeViewModel.progressBar.postValue(false) + } + } + + override fun onUsbError(e: Exception?) { + hemoCubeViewModel.progressBar.postValue(false) + } + }) + } + + private fun sendCommandToHemoCube() { + hemoCubeViewModel.progressBar.postValue(true) + val fullReadOutput = StringBuilder() + + (activity as HemocubeActivity).mService.eventDrivenWriteHemoCube(HemoCubeCommands.run, + object : UsbServiceListener { + override fun onUsbRead(data: ByteArray?) { + data?.let { + val stringData = String(it) + fullReadOutput.append(stringData) + + if (stringData.contains("RESULT", true)) { +// hemoCubeViewModel.mapDeviceConstants(fullReadOutput.toString()) + hemoCubeViewModel.progressBar.postValue(false) + } else if (stringData.contains("FINE", true)) { + hemoCubeViewModel.progressBar.postValue(false) + } + } + } + + override fun onUsbError(e: Exception?) { + hemoCubeViewModel.progressBar.postValue(false) + } + }) + } } diff --git a/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightExpReference.kt b/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightExpReference.kt index 3c3941a..a9d0536 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightExpReference.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightExpReference.kt @@ -83,7 +83,6 @@ class TestRightExpReference : Fragment() { binding.btnSetReference.isEnabled = true } } - } /** @@ -96,6 +95,7 @@ class TestRightExpReference : Fragment() { private fun startTakingReference() { sendCmdToSetLed() } + private fun sendCmdToFetchDeviceConstant() { Log.d(TAG, "sendCmdToFetchDeviceConstant() called") diff --git a/app/src/main/java/com/example/hpostesting/presentation/testRight/UsbService.kt b/app/src/main/java/com/example/hpostesting/presentation/testRight/UsbService.kt index f9e86ae..9b4ee5c 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/testRight/UsbService.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/testRight/UsbService.kt @@ -7,6 +7,7 @@ import android.os.Binder import android.os.IBinder import android.util.Log import com.example.hpostesting.data.constant.Constants +import com.example.hpostesting.data.constant.HemoCubeCommands import com.example.hpostesting.data.constant.TestRightCommands import com.example.hpostesting.presentation.UsbServiceListener import com.hoho.android.usbserial.driver.UsbSerialDriver @@ -64,7 +65,7 @@ class UsbService : Service() { } } - fun eventDrivenWriteHemoCube(listener: UsbServiceListener) { + fun listenToHemoCube(listener: UsbServiceListener) { this.listener = listener try { @@ -72,4 +73,13 @@ class UsbService : Service() { listener.onUsbError(e) } } + + fun eventDrivenWriteHemoCube(command: HemoCubeCommands, listener: UsbServiceListener) { + try { + this.listener = listener + mPort.write(command.command.toByteArray(), Constants.WRITE_TIMEOUT_MILLIS) + } catch (e: IOException) { + listener.onUsbError(e) + } + } } \ No newline at end of file From c8199b90446dccada9e2daf158798ab420419b99 Mon Sep 17 00:00:00 2001 From: Pritimay Sarkar Date: Wed, 2 Aug 2023 23:23:47 +0530 Subject: [PATCH 2/5] merge --- .../example/hpostesting/data/constant/HemoCubeCommands.kt | 5 +++++ .../hpostesting/data/model/patient/HemoCubeTestData.kt | 4 ++-- .../hpostesting/presentation/testRight/TestRightViewModel.kt | 2 -- 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/com/example/hpostesting/data/constant/HemoCubeCommands.kt diff --git a/app/src/main/java/com/example/hpostesting/data/constant/HemoCubeCommands.kt b/app/src/main/java/com/example/hpostesting/data/constant/HemoCubeCommands.kt new file mode 100644 index 0000000..09bf400 --- /dev/null +++ b/app/src/main/java/com/example/hpostesting/data/constant/HemoCubeCommands.kt @@ -0,0 +1,5 @@ +package com.example.hpostesting.data.constant + +enum class HemoCubeCommands(val command: String) { + run("R\r"), +} \ No newline at end of file diff --git a/app/src/main/java/com/example/hpostesting/data/model/patient/HemoCubeTestData.kt b/app/src/main/java/com/example/hpostesting/data/model/patient/HemoCubeTestData.kt index 8e19da6..2d4f146 100644 --- a/app/src/main/java/com/example/hpostesting/data/model/patient/HemoCubeTestData.kt +++ b/app/src/main/java/com/example/hpostesting/data/model/patient/HemoCubeTestData.kt @@ -22,8 +22,8 @@ data class HemoCubeTestData( var led2Buffer: Double? = null, var led1Sample: Double? = null, var led2Sample: Double? = null, - var led1Avarage: Double? = null, - var led2Avarage: Double? = null, + var led1Average: Double? = null, + var led2Average: Double? = null, var deviceRatio: Double? = null, var calculatedRatio: Double? = null ) diff --git a/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightViewModel.kt b/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightViewModel.kt index ef254d1..636f8b3 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightViewModel.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightViewModel.kt @@ -532,6 +532,4 @@ class TestRightViewModel @Inject constructor( fun deleteById(userId: String) = viewModelScope.launch { userDao.deleteById(id = userId) } - - } \ No newline at end of file From 4c847fb1327a77ae31c299dd872463c9907c7564 Mon Sep 17 00:00:00 2001 From: mohamedkaif356 Date: Thu, 3 Aug 2023 12:46:45 +0530 Subject: [PATCH 3/5] Added KitNumber and KitCount --- .../hpostesting/data/constant/Constants.kt | 4 +++ .../presentation/KitScanActivity.kt | 29 +++++++++++++++---- .../hpostesting/presentation/MainActivity.kt | 8 ++--- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt b/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt index 3ad5305..b6e7449 100644 --- a/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt +++ b/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt @@ -44,4 +44,8 @@ object Constants { ) const val password = "SMI@12345" + + const val KIT_NUMBER = "KitNumber" + + const val KIT_COUNT = "KitCount" } \ No newline at end of file diff --git a/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt b/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt index 9ad6a39..2422dfd 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt @@ -1,6 +1,8 @@ package com.example.hpostesting.presentation +import android.content.Context import android.content.Intent +import android.content.SharedPreferences import android.os.Bundle import android.util.Log import android.widget.Toast @@ -21,6 +23,8 @@ class KitScanActivity : AppCompatActivity() { private val TAG = "KitScanActivity" private lateinit var binding: ActivityKitScanBinding + private lateinit var sharedPreference: SharedPreferences + private val barcodeLauncher = registerForActivityResult( ScanContract() ) { result: ScanIntentResult -> @@ -40,13 +44,19 @@ class KitScanActivity : AppCompatActivity() { super.onCreate(savedInstanceState) binding = ActivityKitScanBinding.inflate(layoutInflater) + sharedPreference = this.getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE) setContentView(binding.root) - if (DataHolder.sampleReadCounter <= Constants.MAXIMUM_TEST_ALLOWED_BEFORE_REFERENCE && DataHolder.isReferenceTaken){ + if (DataHolder.sampleReadCounter <= Constants.MAXIMUM_TEST_ALLOWED_BEFORE_REFERENCE && DataHolder.isReferenceTaken) { DataHolder.selectedTest!!.kitSerial = DataHolder.kitSerial moveToNext() } + if (checkHemoCubeKitData()) { + DataHolder.selectedTest!!.kitSerial = + sharedPreference.getString(Constants.KIT_NUMBER, "").toString() + } + binding.nameEditText.setText("SMI/SC/") setSupportActionBar(binding.toolbar) @@ -61,6 +71,11 @@ class KitScanActivity : AppCompatActivity() { if (serialNumber.isNotEmpty() && checkDataNotNull() && isSerialValid(serialNumber)) { DataHolder.kitSerial = binding.nameEditText.text.toString() DataHolder.selectedTest?.kitSerial = binding.nameEditText.text.toString() + with(sharedPreference.edit()) { + putString(Constants.KIT_NUMBER, binding.nameEditText.text.toString()) + putInt(Constants.KIT_COUNT, 1) + apply() + } moveToNext() } else { Toast.makeText(this, "Invalid KIT Number", Toast.LENGTH_LONG).show() @@ -68,8 +83,13 @@ class KitScanActivity : AppCompatActivity() { } } + private fun checkHemoCubeKitData(): Boolean { + return sharedPreference.getString(Constants.KIT_NUMBER, "") + ?.isNotBlank() == true || sharedPreference.getInt(Constants.KIT_COUNT, 0) > 0 + } + private fun isSerialValid(s: String): Boolean { - if (s.length != 17){ + if (s.length != 17) { binding.nameEditText.error = getString(R.string.invalid_kit) return false } @@ -84,6 +104,7 @@ class KitScanActivity : AppCompatActivity() { val i = Intent(applicationContext, HemocubeActivity::class.java) startActivity(i) } + Constants.DEVICE_TYPE_TEST_RIGHT -> { val i = Intent(applicationContext, TestRightActivity::class.java) startActivity(i) @@ -111,9 +132,7 @@ class KitScanActivity : AppCompatActivity() { private fun checkDataNotNull(): Boolean { return if (DataHolder.selectedTest?._id == null) { Toast.makeText( - applicationContext, - "Please Select patient before starting test", - Toast.LENGTH_SHORT + applicationContext, "Please Select patient before starting test", Toast.LENGTH_SHORT ).show() val i = Intent(applicationContext, DashboardActivity::class.java) diff --git a/app/src/main/java/com/example/hpostesting/presentation/MainActivity.kt b/app/src/main/java/com/example/hpostesting/presentation/MainActivity.kt index 83f1346..b573edb 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/MainActivity.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/MainActivity.kt @@ -70,10 +70,10 @@ class MainActivity : AppCompatActivity() { DataHolder.deviceType.observe(this) { deviceType -> with(binding) { if (deviceType == Constants.DEVICE_TYPE_HOMOCUBE) { - binding.cvItem1.visibility = View.VISIBLE - binding.cvItem3.visibility = View.VISIBLE - binding.cvItem2.visibility = View.GONE - binding.cvItem4.visibility = View.GONE + cvItem1.visibility = View.VISIBLE + cvItem3.visibility = View.VISIBLE + cvItem2.visibility = View.GONE + cvItem4.visibility = View.GONE } DataHolder.usbConnected.value = true } From 8237e753c0f241139cc8a51ed6fbb540aa75909f Mon Sep 17 00:00:00 2001 From: mohamedkaif356 Date: Thu, 3 Aug 2023 13:01:03 +0530 Subject: [PATCH 4/5] Added Buffer Value Logic --- .../hpostesting/data/constant/Constants.kt | 2 +- .../presentation/hemocube/HemoCubeFragment.kt | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt b/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt index b6e7449..2b538c8 100644 --- a/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt +++ b/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt @@ -46,6 +46,6 @@ object Constants { const val password = "SMI@12345" const val KIT_NUMBER = "KitNumber" - const val KIT_COUNT = "KitCount" + const val BUFFER_VALUE = "BufferValue" } \ No newline at end of file diff --git a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt index beea992..e910609 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt @@ -14,6 +14,7 @@ import android.widget.Toast import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import com.example.hpostesting.data.DataHolder +import com.example.hpostesting.data.constant.Constants import com.example.hpostesting.data.constant.HemoCubeCommands import com.example.hpostesting.data.model.patient.DeviceData import com.example.hpostesting.data.model.patient.toHemoCubeTestData @@ -83,6 +84,21 @@ class HemoCubeFragment : Fragment() { isOnline = isNetworkAvailable } } + + if (checkBufferValue()) { + TODO("Call S command") + //We have to store the buffer value like this + with(sharedPreference.edit()) { + putInt(Constants.BUFFER_VALUE, 2000) + apply() + } + } else { + TODO("Call B command") + } + } + + private fun checkBufferValue(): Boolean { + return sharedPreference.getInt(Constants.BUFFER_VALUE, 0) > 0 } private fun setupButtonClickListeners() { From 0dd77027e9ebf694a0e4411f86aff5e92ba006f6 Mon Sep 17 00:00:00 2001 From: mohamedkaif356 Date: Thu, 3 Aug 2023 13:12:28 +0530 Subject: [PATCH 5/5] Flushed Kit number, Kit count and Buffer value for new kit --- .../example/hpostesting/presentation/KitScanActivity.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt b/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt index 2422dfd..dceaffa 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt @@ -55,6 +55,14 @@ class KitScanActivity : AppCompatActivity() { if (checkHemoCubeKitData()) { DataHolder.selectedTest!!.kitSerial = sharedPreference.getString(Constants.KIT_NUMBER, "").toString() + moveToNext() + } else { + with(sharedPreference.edit()) { + putString(Constants.KIT_NUMBER, "") + putInt(Constants.KIT_COUNT, 0) + putInt(Constants.BUFFER_VALUE, 0) + apply() + } } binding.nameEditText.setText("SMI/SC/") @@ -86,6 +94,7 @@ class KitScanActivity : AppCompatActivity() { private fun checkHemoCubeKitData(): Boolean { return sharedPreference.getString(Constants.KIT_NUMBER, "") ?.isNotBlank() == true || sharedPreference.getInt(Constants.KIT_COUNT, 0) > 0 + || sharedPreference.getInt(Constants.KIT_COUNT, 0) < 35 } private fun isSerialValid(s: String): Boolean {