handle multiple device id format and refactor
This commit is contained in:
@@ -16,7 +16,7 @@ android {
|
||||
|
||||
// prod - production, preprod - preproduction, quality - qc, dev - development
|
||||
defaultConfig {
|
||||
applicationId "in.sminnovations.hpostesting.quality"
|
||||
applicationId "in.sminnovations.hpostesting.dev"
|
||||
minSdk 21
|
||||
targetSdk 34
|
||||
versionCode 82
|
||||
|
||||
@@ -205,6 +205,37 @@ object Constants {
|
||||
const val TEST_STATUS_CODE_FORTH_GAIN_PRINT_COMPLETED = 27.0
|
||||
const val TEST_STATUS_CODE_TEST_COMPLETED = 30.0
|
||||
|
||||
enum class TestStatus(val CODE: Double) {
|
||||
TEST_STARTED(1.0),
|
||||
CONFIG_STARTED(2.0),
|
||||
CONFIG_COMPLETED(3.0),
|
||||
BUFFER_STARTED(4.0),
|
||||
BUFFER_COMPLETED(5.0),
|
||||
BUFFER_PRINT_STARTED(6.0),
|
||||
BUFFER_PRINT_COMPLETED(7.0),
|
||||
SAMPLE_STARTED(8.0),
|
||||
SAMPLE_COMPLETED(9.0),
|
||||
SAMPLE_PRINT_STARTED(10.0),
|
||||
SAMPLE_PRINT_COMPLETED(11.0),
|
||||
FIRST_GAIN_STARTED(12.0),
|
||||
FIRST_GAIN_COMPLETED(13.0),
|
||||
FIRST_GAIN_PRINT_STARTED(14.0),
|
||||
FIRST_GAIN_PRINT_COMPLETED(15.0),
|
||||
SECOND_GAIN_STARTED(16.0),
|
||||
SECOND_GAIN_COMPLETED(17.0),
|
||||
SECOND_GAIN_PRINT_STARTED(18.0),
|
||||
SECOND_GAIN_PRINT_COMPLETED(19.0),
|
||||
THIRD_GAIN_STARTED(20.0),
|
||||
THIRD_GAIN_COMPLETED(21.0),
|
||||
THIRD_GAIN_PRINT_STARTED(22.0),
|
||||
THIRD_GAIN_PRINT_COMPLETED(23.0),
|
||||
FORTH_GAIN_STARTED(24.0),
|
||||
FORTH_GAIN_COMPLETED(25.0),
|
||||
FORTH_GAIN_PRINT_STARTED(26.0),
|
||||
FORTH_GAIN_PRINT_COMPLETED(27.0),
|
||||
TEST_COMPLETED(30.0)
|
||||
}
|
||||
|
||||
val DEVICE_CONFIGURATION: Map<String, List<List<Double>>> = mapOf<String, List<List<Double>>>(
|
||||
"HCV-000-3001" to listOf(
|
||||
listOf(1.313, -0.89), // LED1, 435nm
|
||||
|
||||
@@ -396,32 +396,12 @@ class HemoCubeFragment : Fragment() {
|
||||
|
||||
when {
|
||||
resultData.contains("SNE") && this.testStatusCode < Constants.TEST_STATUS_CODE_CONFIG_COMPLETED -> {
|
||||
val pattern = Regex("HPP1-\\d{4}-\\d{4}")
|
||||
val matchResult = pattern.find(resultData)
|
||||
val hardwareId = matchResult?.value
|
||||
if (resultData.contains("HCV")) {
|
||||
processHardwareId(resultData, "HCV", 12)
|
||||
}
|
||||
|
||||
if (hardwareId.toString().length == 14) {
|
||||
deviceHardwareId += hardwareId
|
||||
with(sharedPreferences.edit()) {
|
||||
putString(Constants.DEVICE_ID, deviceHardwareId)
|
||||
apply()
|
||||
}
|
||||
this.testStatusCode = Constants.TEST_STATUS_CODE_CONFIG_COMPLETED
|
||||
activity?.runOnUiThread {
|
||||
binding.btnPlacebuffer.visibility = View.VISIBLE
|
||||
}
|
||||
hemoCubeViewModel.messages.postValue(getString(R.string.start))
|
||||
|
||||
if (!Constants.DEVICE_CONFIGURATION.containsKey(deviceHardwareId)) {
|
||||
allErrorMessages += "Calibration configuration for this device id is not found"
|
||||
Toast.makeText(requireContext(), "Calibration configuration for this device id is not found", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
if (!Constants.BUFFER_INTENSITY_THRESHOLDS.containsKey(deviceHardwareId)) {
|
||||
allErrorMessages += "ADC thresholds for this device id are not found"
|
||||
Toast.makeText(requireContext(), "ADC thresholds for this device id are not found", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
} else {
|
||||
hemoCubeViewModel.messages.postValue("Config error")
|
||||
if (resultData.contains("HPP")) {
|
||||
processHardwareId(resultData, "HPP1", 14)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -488,7 +468,7 @@ class HemoCubeFragment : Fragment() {
|
||||
hemoCubeViewModel.messages.postValue("7.6X Gain Started")
|
||||
}
|
||||
|
||||
currentResultData.contains("#SC5") && this.testStatusCode < Constants.TEST_STATUS_CODE_FORTH_GAIN_COMPLETED -> {
|
||||
currentResultData.contains("#SC5") && this.testStatusCode < Constants.TestStatus.CONFIG_COMPLETED.CODE -> {
|
||||
this.testStatusCode = Constants.TEST_STATUS_CODE_FORTH_GAIN_COMPLETED
|
||||
hemoCubeViewModel.messages.postValue("7.6X Gain Completed")
|
||||
fetchResult()
|
||||
@@ -526,13 +506,9 @@ class HemoCubeFragment : Fragment() {
|
||||
bufferIntensity.toDoubleOrNull()!!
|
||||
}
|
||||
|
||||
var sampleIntensity = resultLines[5].split(' ')[1].trim()
|
||||
led1SampleForDevice = resultLines[5].split(' ')[1].trim().toDoubleOrNull()!!
|
||||
sampleIntensity = resultLines[6].split(' ')[1].trim()
|
||||
led2SampleForDevice = resultLines[6].split(' ')[1].trim().toDoubleOrNull()!!
|
||||
sampleIntensity = resultLines[7].split(' ')[1].trim()
|
||||
led3SampleForDevice = resultLines[7].split(' ')[1].trim().toDoubleOrNull()!!
|
||||
sampleIntensity = resultLines[8].split(' ')[1].split('\r')[0].trim()
|
||||
led4SampleForDevice =
|
||||
resultLines[8].split(' ')[1].split('\r')[0].trim().toDoubleOrNull()!!
|
||||
processResult()
|
||||
@@ -603,6 +579,36 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
fun processHardwareId(resultData: String, prefix: String, expectedLength: Int) {
|
||||
val pattern = Regex("$prefix-\\d{3,4}-\\d{4}")
|
||||
val matchResult = pattern.find(resultData)
|
||||
val hardwareId = matchResult?.value
|
||||
|
||||
if (hardwareId?.length == expectedLength) {
|
||||
deviceHardwareId += hardwareId
|
||||
with(sharedPreferences.edit()) {
|
||||
putString(Constants.DEVICE_ID, deviceHardwareId)
|
||||
apply()
|
||||
}
|
||||
this.testStatusCode = Constants.TEST_STATUS_CODE_CONFIG_COMPLETED
|
||||
activity?.runOnUiThread {
|
||||
binding.btnPlacebuffer.visibility = View.VISIBLE
|
||||
}
|
||||
hemoCubeViewModel.messages.postValue(getString(R.string.start))
|
||||
|
||||
if (!Constants.DEVICE_CONFIGURATION.containsKey(deviceHardwareId)) {
|
||||
allErrorMessages += "Calibration configuration for this device id is not found\n"
|
||||
Toast.makeText(requireContext(), "Calibration configuration for this device id is not found", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
if (!Constants.BUFFER_INTENSITY_THRESHOLDS.containsKey(deviceHardwareId)) {
|
||||
allErrorMessages += "ADC thresholds for this device id are not found\n"
|
||||
Toast.makeText(requireContext(), "ADC thresholds for this device id are not found", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
} else {
|
||||
hemoCubeViewModel.messages.postValue("Config error")
|
||||
}
|
||||
}
|
||||
|
||||
private fun showError() {
|
||||
activity?.runOnUiThread {
|
||||
UIUtils.createAlertDialog(requireContext(),
|
||||
|
||||
Reference in New Issue
Block a user