Compare commits
1 Commits
dev-server
...
review_rel
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
67d98b1b27 |
@@ -125,4 +125,4 @@ publishTestResults:
|
|||||||
artifacts:
|
artifacts:
|
||||||
when: always
|
when: always
|
||||||
reports:
|
reports:
|
||||||
junit: app/build/test-results/testDebugUnitTest/*.xml
|
junit: app/build/test-results/testDebugUnitTest/*.xml
|
||||||
@@ -21,7 +21,7 @@ android {
|
|||||||
minSdk 21
|
minSdk 21
|
||||||
targetSdk 34
|
targetSdk 34
|
||||||
versionCode 130
|
versionCode 130
|
||||||
versionName "2.1.130 -usb"
|
versionName "2.1.130"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,7 +30,6 @@ android {
|
|||||||
release {
|
release {
|
||||||
minifyEnabled false
|
minifyEnabled false
|
||||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
signingConfig signingConfigs.debug
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
compileOptions {
|
compileOptions {
|
||||||
@@ -64,7 +63,6 @@ android {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation "com.google.dagger:hilt-android:2.46"
|
implementation "com.google.dagger:hilt-android:2.46"
|
||||||
implementation 'androidx.activity:activity:1.8.0'
|
implementation 'androidx.activity:activity:1.8.0'
|
||||||
implementation 'androidx.compose.ui:ui-android:1.7.6'
|
|
||||||
kapt "com.google.dagger:hilt-android-compiler:2.46"
|
kapt "com.google.dagger:hilt-android-compiler:2.46"
|
||||||
|
|
||||||
implementation 'androidx.core:core-ktx:1.12.0'
|
implementation 'androidx.core:core-ktx:1.12.0'
|
||||||
|
|||||||
@@ -68,7 +68,6 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name="com.example.hpostesting.presentation.usb_teminal.UsbTerminalActivity"
|
android:name="com.example.hpostesting.presentation.usb_teminal.UsbTerminalActivity"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:launchMode="singleInstance"
|
|
||||||
android:screenOrientation="portrait" />
|
android:screenOrientation="portrait" />
|
||||||
<activity
|
<activity
|
||||||
android:name="com.example.hpostesting.presentation.deviceinfo.DeviceActivity"
|
android:name="com.example.hpostesting.presentation.deviceinfo.DeviceActivity"
|
||||||
@@ -199,7 +198,6 @@
|
|||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:permission=""
|
android:permission=""
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
android:launchMode="singleInstance"
|
|
||||||
android:theme="@style/AppTheme.NoActionBar">
|
android:theme="@style/AppTheme.NoActionBar">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
|
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
|
||||||
|
|||||||
@@ -73,15 +73,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
sharedPreference = getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
sharedPreference = getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
||||||
val action = intent?.action
|
|
||||||
if (action == UsbManager.ACTION_USB_DEVICE_ATTACHED || action == UsbManager.ACTION_USB_DEVICE_DETACHED) {
|
|
||||||
// If the activity is triggered by USB events, simply finish it
|
|
||||||
checkAndUpdateUsbConnection()
|
|
||||||
finish()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
binding.myToolbar.title = "Test Type"
|
binding.myToolbar.title = "Test Type"
|
||||||
@@ -157,7 +150,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
(device.productId == 24577 && device.vendorId == 1027) || (device.productId == 8963 && device.vendorId == 1659) || (device.productId == 4614 && device.vendorId == 7111) -> {
|
(device.productId == 24577 && device.vendorId == 1027) || (device.productId == 8963 && device.vendorId == 1659) || (device.productId == 4614 && device.vendorId == 7111) -> {
|
||||||
// changeUI()
|
changeUI()
|
||||||
DataHolder.deviceType.postValue(Constants.DEVICE_TYPE_TRUEHEME)
|
DataHolder.deviceType.postValue(Constants.DEVICE_TYPE_TRUEHEME)
|
||||||
Constants.DEVICE_TYPE_TRUEHEME
|
Constants.DEVICE_TYPE_TRUEHEME
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,7 +116,6 @@ class GalleryFragment : Fragment() {
|
|||||||
binding.btnUsbTerminal.setOnClickListener {
|
binding.btnUsbTerminal.setOnClickListener {
|
||||||
startActivity(Intent(requireContext(), UsbTerminalActivity::class.java))
|
startActivity(Intent(requireContext(), UsbTerminalActivity::class.java))
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.btnSubmit.setOnClickListener {
|
binding.btnSubmit.setOnClickListener {
|
||||||
startActivity(Intent(requireContext(), HemocubeBufferCheckActivity::class.java))
|
startActivity(Intent(requireContext(), HemocubeBufferCheckActivity::class.java))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,11 @@ import androidx.core.content.ContextCompat
|
|||||||
import androidx.core.view.get
|
import androidx.core.view.get
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.constant.DataHolder
|
import com.example.hpostesting.data.constant.DataHolder
|
||||||
|
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||||
import com.example.hpostesting.data.constant.LanguageManager
|
import com.example.hpostesting.data.constant.LanguageManager
|
||||||
|
import com.example.hpostesting.presentation.deviceinfo.DeviceFragment
|
||||||
|
import com.example.hpostesting.presentation.utils.DeviceCommunicationHandler
|
||||||
|
import com.example.hpostesting.presentation.utils.UsbServiceListener
|
||||||
import com.example.hpostesting.util.UsbService
|
import com.example.hpostesting.util.UsbService
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialDriver
|
import com.hoho.android.usbserial.driver.UsbSerialDriver
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialProber
|
import com.hoho.android.usbserial.driver.UsbSerialProber
|
||||||
@@ -55,37 +59,25 @@ class UsbTerminalActivity : AppCompatActivity() {
|
|||||||
private var mConnection: UsbDeviceConnection? = null
|
private var mConnection: UsbDeviceConnection? = null
|
||||||
lateinit var mService: UsbService
|
lateinit var mService: UsbService
|
||||||
private var deviceId = ""
|
private var deviceId = ""
|
||||||
private var executedCommands: MutableList<String> = mutableListOf()
|
|
||||||
private var isResuming = false
|
|
||||||
private val TAG = "Calibration"
|
private val TAG = "Calibration"
|
||||||
|
|
||||||
private val broadcastReceiver = object : BroadcastReceiver() {
|
private val broadcastReceiver = object : BroadcastReceiver() {
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
val device: UsbDevice? = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE)
|
val device: UsbDevice? = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE)
|
||||||
|
|
||||||
if (UsbManager.ACTION_USB_DEVICE_DETACHED == intent.action) {
|
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
|
||||||
// Handle USB disconnection
|
device?.apply {
|
||||||
Log.d(TAG, "USB device detached")
|
|
||||||
cleanupUsb()
|
|
||||||
DataHolder.usbConnected.postValue(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (UsbManager.ACTION_USB_DEVICE_ATTACHED == intent.action) {
|
|
||||||
// Handle USB reconnection
|
|
||||||
Log.d(TAG, "USB device attached")
|
|
||||||
connectUsb(false) // Attempt reconnection
|
|
||||||
} else if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
|
|
||||||
// Handle USB permission granted
|
|
||||||
device?.let {
|
|
||||||
connectUsb(true)
|
connectUsb(true)
|
||||||
DataHolder.usbConnected.postValue(true)
|
DataHolder.usbConnected.postValue(true)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "USB permission denied")
|
onErrorReported("permission denied for device")
|
||||||
DataHolder.usbConnected.postValue(false)
|
DataHolder.usbConnected.postValue(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,15 +96,6 @@ class UsbTerminalActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getExecutedCommands(): List<String> {
|
|
||||||
return executedCommands
|
|
||||||
}
|
|
||||||
|
|
||||||
fun addExecutedCommand(command: String) {
|
|
||||||
if (!executedCommands.contains(command)) {
|
|
||||||
executedCommands.add(command)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
override fun attachBaseContext(newBase: Context?) {
|
override fun attachBaseContext(newBase: Context?) {
|
||||||
val languageCode = LanguageManager.getSavedLanguage(newBase!!)
|
val languageCode = LanguageManager.getSavedLanguage(newBase!!)
|
||||||
LanguageManager.setLocale(newBase, languageCode)
|
LanguageManager.setLocale(newBase, languageCode)
|
||||||
@@ -123,28 +106,18 @@ class UsbTerminalActivity : AppCompatActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
binding = ActivityUsbTerminalBinding.inflate(layoutInflater)
|
binding = ActivityUsbTerminalBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
// setSupportActionBar(binding.myToolbar)
|
||||||
val filter = IntentFilter()
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED)
|
|
||||||
filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED)
|
|
||||||
registerReceiver(broadcastReceiver, filter)
|
|
||||||
|
|
||||||
doBoth()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun doBoth(){
|
|
||||||
setupListener()
|
setupListener()
|
||||||
connectUsb(false)
|
connectUsb(false)
|
||||||
}
|
}
|
||||||
private fun setupListener() {
|
|
||||||
|
|
||||||
|
private fun setupListener() {
|
||||||
DataHolder.usbConnected.observe(this) {
|
DataHolder.usbConnected.observe(this) {
|
||||||
Log.d("USB OBSERVE", "HemoCube called -> $it")
|
Log.d("USB OBSERVE", "HemoCube called -> $it")
|
||||||
if (it) {
|
if (it) {
|
||||||
myMenu?.get(0)?.icon =
|
myMenu?.get(0)?.icon =
|
||||||
ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_24)
|
ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_24)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
myMenu?.get(0)?.icon =
|
myMenu?.get(0)?.icon =
|
||||||
ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_off_24)
|
ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_off_24)
|
||||||
@@ -155,14 +128,11 @@ class UsbTerminalActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
open fun connectUsb(permissionGranted: Boolean) {
|
open fun connectUsb(permissionGranted: Boolean) {
|
||||||
Log.d(TAG, "connectUsb() called, permission variable = $permissionGranted")
|
Log.d(TAG, "connectUsb() called, permission variable = $permissionGranted")
|
||||||
cleanupUsb() // Clean up before reinitializing
|
|
||||||
|
|
||||||
val manager = getSystemService(Context.USB_SERVICE) as UsbManager
|
val manager = getSystemService(Context.USB_SERVICE) as UsbManager
|
||||||
val availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager)
|
val availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager)
|
||||||
|
|
||||||
if (availableDrivers.isEmpty()) {
|
if (availableDrivers.isEmpty()) {
|
||||||
onErrorReported("No Device Connected")
|
onErrorReported("No Device is Connected")
|
||||||
DataHolder.usbConnected.postValue(false)
|
|
||||||
} else {
|
} else {
|
||||||
mDriver = availableDrivers[0]
|
mDriver = availableDrivers[0]
|
||||||
mConnection = manager.openDevice(mDriver.device)
|
mConnection = manager.openDevice(mDriver.device)
|
||||||
@@ -170,13 +140,13 @@ class UsbTerminalActivity : AppCompatActivity() {
|
|||||||
requestUserPermission(manager, mDriver.device)
|
requestUserPermission(manager, mDriver.device)
|
||||||
} else {
|
} else {
|
||||||
setupService()
|
setupService()
|
||||||
DataHolder.usbConnected.postValue(true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onErrorReported(msg: String) {
|
fun onErrorReported(msg: String) {
|
||||||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
|
||||||
|
if (!isFinishing) onBackPressed()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun moveToNext() {
|
private fun moveToNext() {
|
||||||
@@ -186,9 +156,6 @@ class UsbTerminalActivity : AppCompatActivity() {
|
|||||||
.commit()
|
.commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressLint("MutableImplicitPendingIntent")
|
@SuppressLint("MutableImplicitPendingIntent")
|
||||||
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
|
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
|
||||||
val mPendingIntent: PendingIntent
|
val mPendingIntent: PendingIntent
|
||||||
@@ -220,29 +187,12 @@ class UsbTerminalActivity : AppCompatActivity() {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
unregisterReceiver(broadcastReceiver)
|
|
||||||
if (usbTerminalViewModel.isServiceConnected) {
|
if (usbTerminalViewModel.isServiceConnected) {
|
||||||
mService.disconnect()
|
mService.disconnect()
|
||||||
unbindService(connection)
|
unbindService(connection)
|
||||||
usbTerminalViewModel.isServiceConnected = false
|
usbTerminalViewModel.isServiceConnected = false
|
||||||
}
|
}
|
||||||
cleanupUsb()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun cleanupUsb() {
|
|
||||||
try {
|
|
||||||
mService.disconnect()
|
|
||||||
unbindService(connection)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e(TAG, "Error during USB cleanup: ${e.message}")
|
|
||||||
}
|
|
||||||
mConnection?.close()
|
|
||||||
mConnection = null
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -13,8 +13,6 @@
|
|||||||
|
|
||||||
package com.example.hpostesting.presentation.usb_teminal
|
package com.example.hpostesting.presentation.usb_teminal
|
||||||
|
|
||||||
// Fragment Class
|
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@@ -25,150 +23,63 @@ import android.view.ViewGroup
|
|||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||||
import com.example.hpostesting.presentation.utils.UsbServiceListener
|
import com.example.hpostesting.presentation.utils.UsbServiceListener
|
||||||
|
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||||
|
import com.google.firebase.ktx.Firebase
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentUsbTerminalBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentUsbTerminalBinding
|
||||||
|
|
||||||
|
|
||||||
class UsbTerminalFragment : Fragment() {
|
class UsbTerminalFragment : Fragment() {
|
||||||
private lateinit var binding: FragmentUsbTerminalBinding
|
private lateinit var binding: FragmentUsbTerminalBinding
|
||||||
private val usbTerminalViewModel: UsbTerminalViewModel by activityViewModels()
|
private val usbTerminalViewModel: UsbTerminalViewModel by activityViewModels()
|
||||||
private lateinit var sharedPreferences: SharedPreferences
|
private lateinit var sharedPreferences: SharedPreferences
|
||||||
private var startListening = MutableLiveData(false)
|
private var startListening = MutableLiveData(false)
|
||||||
private var resultData = StringBuilder()
|
private var resultData: String = ""
|
||||||
private var commandQueue: MutableList<String> = mutableListOf()
|
|
||||||
private var currentCommand: String? = null
|
|
||||||
var executedCommands: MutableList<String> = mutableListOf()
|
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
|
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
|
||||||
): View {
|
): View {
|
||||||
binding = FragmentUsbTerminalBinding.inflate(inflater, container, false)
|
binding = FragmentUsbTerminalBinding.inflate(inflater, container, false)
|
||||||
binding.clearQueueButton.setOnClickListener {
|
sharedPreferences =
|
||||||
clearQueue()
|
requireContext().getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
||||||
}
|
|
||||||
sharedPreferences = requireContext().getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
val pastCommands = (activity as? UsbTerminalActivity)?.getExecutedCommands() ?: emptyList()
|
|
||||||
if (pastCommands.isNotEmpty()) {
|
|
||||||
resumeCommands(pastCommands)
|
|
||||||
}
|
|
||||||
|
|
||||||
initViews()
|
initViews()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun initViews() {
|
private fun initViews() {
|
||||||
binding.messageCommand.movementMethod = ScrollingMovementMethod()
|
binding.messageCommand.movementMethod = ScrollingMovementMethod()
|
||||||
|
usbTerminalViewModel.messages.observe(viewLifecycleOwner) {
|
||||||
// Observe messages with proper formatting
|
binding.messageCommand.text = it
|
||||||
usbTerminalViewModel.messages.observe(viewLifecycleOwner) { message ->
|
|
||||||
binding.messageCommand.text = message
|
|
||||||
scrollToBottom()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.sendCommand.setOnClickListener {
|
binding.sendCommand.setOnClickListener {
|
||||||
val commands = binding.etCommands.text.toString().trim()
|
callCommand(binding.etCommands.text.trim().toString())
|
||||||
if (commands.isNotEmpty()) {
|
|
||||||
// Process entire command string
|
|
||||||
addToQueue(listOf(commands))
|
|
||||||
binding.etCommands.text.clear()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
listenToHemoCube()
|
listenToHemoCube()
|
||||||
callCommand("I")
|
callCommand("I")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun scrollToBottom() {
|
|
||||||
binding.messageCommand.post {
|
|
||||||
val scrollAmount = binding.messageCommand.layout.getLineTop(binding.messageCommand.lineCount) -
|
|
||||||
binding.messageCommand.height
|
|
||||||
if (scrollAmount > 0) {
|
|
||||||
binding.messageCommand.scrollTo(0, scrollAmount)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun addToQueue(commands: List<String>) {
|
|
||||||
// Append new commands to the queue instead of replacing it
|
|
||||||
commandQueue.addAll(commands)
|
|
||||||
|
|
||||||
// Track commands in the activity
|
|
||||||
(activity as? UsbTerminalActivity)?.let { activity ->
|
|
||||||
commands.forEach { command ->
|
|
||||||
activity.addExecutedCommand(command)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
appendFormattedMessage("\nAdded commands to queue: ${commands.joinToString(" ")}")
|
|
||||||
processNextCommand() // Start processing if not already in progress
|
|
||||||
}
|
|
||||||
|
|
||||||
fun clearQueue() {
|
|
||||||
commandQueue.clear()
|
|
||||||
currentCommand = null
|
|
||||||
appendFormattedMessage("\nCommand queue cleared")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun appendFormattedMessage(message: String) {
|
|
||||||
resultData.append("\n").append(message)
|
|
||||||
usbTerminalViewModel.messages.postValue(resultData.toString())
|
|
||||||
scrollToBottom()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun processNextCommand() {
|
|
||||||
if (currentCommand == null && commandQueue.isNotEmpty()) {
|
|
||||||
currentCommand = commandQueue.removeAt(0)
|
|
||||||
callCommand(currentCommand!!)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun callCommand(command: String) {
|
private fun callCommand(command: String) {
|
||||||
// Don't process if command was cleared
|
|
||||||
if (currentCommand == null) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
usbTerminalViewModel.progressBar.postValue(true)
|
usbTerminalViewModel.progressBar.postValue(true)
|
||||||
appendFormattedMessage("Sending command: $command \n")
|
(activity as UsbTerminalActivity).mService.sendAndListenToHemoCubeTxt(
|
||||||
|
command,
|
||||||
try {
|
object : UsbServiceListener {
|
||||||
(activity as UsbTerminalActivity).mService.sendAndListenToHemoCubeTxt(
|
override fun onUsbRead(data: ByteArray?) {
|
||||||
command,
|
//nothing
|
||||||
object : UsbServiceListener {
|
|
||||||
override fun onUsbRead(data: ByteArray?) {
|
|
||||||
// Keep empty as per original code
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onUsbError(e: Exception?) {
|
|
||||||
activity?.runOnUiThread {
|
|
||||||
|
|
||||||
appendFormattedMessage("Error sending command $command: ${e?.message ?: "Unknown error"}")
|
|
||||||
usbTerminalViewModel.progressBar.postValue(false)
|
|
||||||
currentCommand = null
|
|
||||||
|
|
||||||
|
|
||||||
processNextCommand()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
|
||||||
} catch (e: Exception) {
|
override fun onUsbError(e: Exception?) {
|
||||||
appendFormattedMessage("Error: ${e.localizedMessage}")
|
usbTerminalViewModel.progressBar.postValue(false)
|
||||||
usbTerminalViewModel.progressBar.postValue(false)
|
}
|
||||||
currentCommand = null
|
})
|
||||||
processNextCommand()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun listenToHemoCube() {
|
private fun listenToHemoCube() {
|
||||||
|
|
||||||
|
val fullReadOutput = StringBuilder()
|
||||||
startListening.postValue(true)
|
startListening.postValue(true)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -176,58 +87,20 @@ class UsbTerminalFragment : Fragment() {
|
|||||||
override fun onUsbRead(data: ByteArray?) {
|
override fun onUsbRead(data: ByteArray?) {
|
||||||
data?.let {
|
data?.let {
|
||||||
val stringData = String(it)
|
val stringData = String(it)
|
||||||
resultData.append(stringData)
|
fullReadOutput.append(stringData)
|
||||||
|
resultData += stringData
|
||||||
activity?.runOnUiThread {
|
usbTerminalViewModel.messages.postValue(resultData)
|
||||||
usbTerminalViewModel.messages.postValue(resultData.toString())
|
|
||||||
scrollToBottom()
|
|
||||||
|
|
||||||
// Check for command completion
|
|
||||||
if (currentCommand != null && stringData.contains("${currentCommand}C")) {
|
|
||||||
currentCommand = null
|
|
||||||
usbTerminalViewModel.progressBar.postValue(false)
|
|
||||||
|
|
||||||
// If there are no more commands in queue, clear completion flags
|
|
||||||
if (commandQueue.isEmpty()) {
|
|
||||||
appendFormattedMessage("\nAll commands completed")
|
|
||||||
} else {
|
|
||||||
processNextCommand()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onUsbError(e: Exception?) {
|
override fun onUsbError(e: Exception?) {
|
||||||
activity?.runOnUiThread {
|
usbTerminalViewModel.messages.postValue(e!!.localizedMessage)
|
||||||
appendFormattedMessage("Error: ${e?.localizedMessage ?: "Unknown error"}")
|
usbTerminalViewModel.progressBar.postValue(false)
|
||||||
usbTerminalViewModel.progressBar.postValue(false)
|
|
||||||
currentCommand = null
|
|
||||||
processNextCommand()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
appendFormattedMessage("Error: ${e.localizedMessage}")
|
usbTerminalViewModel.messages.postValue(e.localizedMessage)
|
||||||
|
Firebase.crashlytics.recordException(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
fun resumeCommands(pastCommands: List<String>) {
|
|
||||||
appendFormattedMessage("Resuming execution...")
|
|
||||||
pastCommands.forEach { command ->
|
|
||||||
if (!commandQueue.contains(command)) {
|
|
||||||
commandQueue.add(command)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
processNextCommand()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
override fun onDestroyView() {
|
|
||||||
super.onDestroyView()
|
|
||||||
startListening.value = false
|
|
||||||
resultData.clear()
|
|
||||||
commandQueue.clear()
|
|
||||||
currentCommand = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class UsbTerminalViewModel @Inject constructor(
|
class UsbTerminalViewModel @Inject constructor(
|
||||||
|
private val hemoCubeDao: HemoCubeDao,
|
||||||
|
private val repository: Repository,
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
var isServiceConnected = false
|
var isServiceConnected = false
|
||||||
val progressBar = MutableLiveData(false)
|
val progressBar = MutableLiveData(false)
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
|
|
||||||
|
|
||||||
<path android:fillColor="@android:color/white" android:pathData="M2.01,21L23,12 2.01,3 2,10l15,2 -15,2z"/>
|
|
||||||
|
|
||||||
</vector>
|
|
||||||
@@ -11,51 +11,59 @@
|
|||||||
~ // from ShanMukha Innovations Pvt. Ltd.
|
~ // from ShanMukha Innovations Pvt. Ltd.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:layout_marginStart="8dp"
|
||||||
android:padding="16dp">
|
android:layout_marginEnd="8dp"
|
||||||
|
>
|
||||||
<Button
|
|
||||||
android:id="@+id/clearQueueButton"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Clar All Commands" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/messageCommand"
|
android:id="@+id/message_command"
|
||||||
|
style="@style/title1_1"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1"
|
android:layout_marginTop="10dp"
|
||||||
android:background="@android:color/darker_gray"
|
android:gravity="start|bottom"
|
||||||
android:padding="8dp"
|
android:text="Start"
|
||||||
android:scrollbars="vertical"
|
android:scrollbars = "vertical"
|
||||||
android:textColor="@android:color/white" />
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
<LinearLayout
|
android:layout_above="@+id/ll_commands"
|
||||||
|
android:visibility="visible"
|
||||||
|
android:textColor="@color/black"
|
||||||
|
android:textSize="18sp"
|
||||||
|
/>
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/ll_commands"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/etCommands"
|
android:id="@+id/et_commands"
|
||||||
android:layout_width="0dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_marginTop="10dp"
|
||||||
android:hint="Enter command"
|
android:hint="@string/commands"
|
||||||
android:inputType="text"
|
android:layout_alignParentStart="true"
|
||||||
android:maxLines="1"
|
android:imeOptions="actionDone"
|
||||||
android:minHeight="48dp" />
|
android:textSize="18sp"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
/>
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/send_command"
|
||||||
|
android:layout_width="32dp"
|
||||||
|
android:layout_height="26dp"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_centerInParent="true"
|
||||||
|
android:src="@drawable/ic_baseline_send_24"/>
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/sendCommand"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="8dp"
|
|
||||||
android:text="Send" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">HPOS ALPHA Testing</string>
|
<string name="app_name">HPOS Testing</string>
|
||||||
|
|
||||||
<string-array name="instrument">
|
<string-array name="instrument">
|
||||||
<item>TestRight</item>
|
<item>TestRight</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user