From a28e4634e0decc9504f99c1ad3ac0b338e151e67 Mon Sep 17 00:00:00 2001 From: "smileomi18@gmail.com" Date: Wed, 19 Jul 2023 16:28:31 +0530 Subject: [PATCH] usb --- .../testRight/TestRightExpReference.kt | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) 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 f0406f0..7632240 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 @@ -52,6 +52,10 @@ class TestRightExpReference : Fragment() { Log.e("mariya", "onViewCreated 1") if (DataHolder.deviceType.equals(Constants.DEVICE_TYPE_HOMOCUBE) ) { Log.e("mariya", "onViewCreated if") + fetchHemoCubeResult() + Log.e("mariya", "onViewCreated 1") + if (DataHolder.deviceType.equals(Constants.DEVICE_TYPE_HOMOCUBE) ) { + Log.e("mariya", "onViewCreated if") // fetchHemoCubeResult() } // if (DataHolder.deviceConstant == null) { @@ -118,6 +122,50 @@ class TestRightExpReference : Fragment() { // } } + // private fun sendCmdToFetchDeviceConstant(recursive: Boolean) { + private fun fetchHemoCubeResult() { + Log.d("mariya", "fetchHemoCubeResult() called") + + viewModel.progressBar.postValue(true) + val fullReadOutput = StringBuilder() + + (activity as TestRightActivity).mService.eventDrivenWrite(TestRightCommands.read, + object : UsbServiceListener { + override fun onUsbRead(data: ByteArray?) { + Log.d("mariya", data.toString()) + data?.let { + val stringData = String(it) + fullReadOutput.append(stringData) + Log.d(TAG, "fullReadOutput = $fullReadOutput") + + if (stringData.contains("OK", true)) { + Log.d( + TAG, + "onUsbRead() called in sendCmdToFetchDeviceConstant() found OK" + ) + viewModel.mapDeviceConstants(fullReadOutput.toString()) + viewModel.progressBar.postValue(false) + } else if (stringData.contains("FINE", true)) { + Log.d(TAG, "results = FINE") + viewModel.progressBar.postValue(false) + + viewModel.errorTriggered.postValue(ErrorMessage("Please Try Again!!", Constants.ERROR_CRITICAL)) + + } + } + } + + override fun onUsbError(e: Exception?) { + Log.e(TAG, "onUsbIoError() called in sendCmdToFetchDeviceConstant() -> $e") + viewModel.errorTriggered.postValue(ErrorMessage("Please Try Again this step", Constants.ERROR_NORMAL)) + + viewModel.progressBar.postValue(false) + } + }) + } + + + // private fun sendCmdToFetchDeviceConstant(recursive: Boolean) { private fun sendCmdToFetchDeviceConstant() { Log.d(TAG, "sendCmdToFetchDeviceConstant() called")