remove prefix based pattern search in deviceid
This commit is contained in:
@@ -334,7 +334,7 @@ class HomeFragment : Fragment() {
|
||||
|
||||
private fun createDeviceUpdateRequestData(): DeviceUpdateRequest {
|
||||
return DeviceUpdateRequest(
|
||||
serial_no = "HPOS-000-3001"
|
||||
serial_no = sharedPreference.getString(Constants.DEVICE_ID, "")
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -378,13 +378,7 @@ class HemoCubeFragment : Fragment() {
|
||||
|
||||
when {
|
||||
resultData.contains("SNE") && this.testStatusCode < TestStatus.CONFIG_COMPLETED.code -> {
|
||||
if (resultData.contains("HCV")) {
|
||||
processHardwareId(resultData, "HCV", 12)
|
||||
}
|
||||
|
||||
if (resultData.contains("HPP")) {
|
||||
processHardwareId(resultData, "HPP1", 14)
|
||||
}
|
||||
processHardwareId(resultData)
|
||||
}
|
||||
|
||||
resultData.contains("#BS") && this.testStatusCode < TestStatus.BUFFER_STARTED.code -> {
|
||||
@@ -580,12 +574,10 @@ class HemoCubeFragment : Fragment() {
|
||||
currentResultData = ""
|
||||
}
|
||||
|
||||
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
|
||||
fun processHardwareId(resultData: String) {
|
||||
val hardwareId = extractMiddleString(resultData)
|
||||
|
||||
if (hardwareId?.length == expectedLength) {
|
||||
if (!hardwareId.isNullOrBlank()) {
|
||||
updateDeviceId(hardwareId)
|
||||
activity?.runOnUiThread {
|
||||
binding.btnPlacebuffer.visibility = View.VISIBLE
|
||||
@@ -595,17 +587,22 @@ class HemoCubeFragment : Fragment() {
|
||||
if (!Constants.DEVICE_CONFIGURATION.containsKey(deviceHardwareId)) {
|
||||
deviceHardwareId = "HCV-000-3001"
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
fun extractMiddleString(input: String): String? {
|
||||
val pattern = Regex("SNS\\s(.*?)\\sSNE")
|
||||
val matchResult: MatchResult? = pattern.find(input)
|
||||
|
||||
return matchResult?.groups?.get(1)?.value
|
||||
}
|
||||
|
||||
private fun updateDeviceId(hardwareId: String?) {
|
||||
hardwareId?.let {
|
||||
deviceHardwareId += it
|
||||
|
||||
Reference in New Issue
Block a user