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 index 28acdab..9cf44a6 100644 --- a/app/src/main/java/com/example/hpostesting/data/constant/HemoCubeCommands.kt +++ b/app/src/main/java/com/example/hpostesting/data/constant/HemoCubeCommands.kt @@ -5,4 +5,5 @@ enum class HemoCubeCommands(val command: String) { getBuffer("D\r"), startSample("S\r"), getSample("P\r"), + getDeviceId("I\r"), } \ No newline at end of file diff --git a/app/src/main/java/com/example/hpostesting/presentation/diagnostics/DiagnosticsFragment.kt b/app/src/main/java/com/example/hpostesting/presentation/diagnostics/DiagnosticsFragment.kt index 1b949a6..3d51759 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/diagnostics/DiagnosticsFragment.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/diagnostics/DiagnosticsFragment.kt @@ -59,6 +59,7 @@ class DiagnosticsFragment : Fragment() { private fun initViews() { listenToHemoCube() + getDeviceId() binding.btnSubmit.setOnClickListener { binding.btnSubmit.visibility = View.GONE getBufferdiagnostics() @@ -95,6 +96,32 @@ class DiagnosticsFragment : Fragment() { } } + private fun getDeviceId() { + diagnosticsViewModel.progressBar.postValue(true) + (activity as DiagnosticsActivity).mService.sendAndListenToHemoCube( + HemoCubeCommands.getDeviceId, + object : UsbServiceListener { + override fun onUsbRead(data: ByteArray?) { + data?.let { + val stringData = String(it) + diagnosticsViewModel.messages.postValue(stringData) + val pattern = Regex("([A-Z]+)\\s(\\d+)") + val matchResult = pattern.find(stringData) + if (matchResult != null) { + val (sn, hardwareId) = matchResult.destructured + with(sharedPreferences.edit()) { + putString(com.example.hpostesting.data.constant.Constants.DEVICE_ID, hardwareId) + apply() + } + } + binding.tvSubtitle4.text = stringData + } + } + override fun onUsbError(e: Exception?) { + diagnosticsViewModel.progressBar.postValue(false) + } + }) + } private fun getBufferdiagnostics() { diagnosticsViewModel.progressBar.postValue(true)