mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2025-12-21 16:34:23 +01:00
Mock devices improvements (#137)
This commit is contained in:
committed by
GitHub
parent
c922e69efa
commit
de978fd9fc
@@ -35,7 +35,7 @@ import android.app.Application
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
import no.nordicsemi.android.analytics.AppAnalytics
|
||||
import no.nordicsemi.android.analytics.AppOpenEvent
|
||||
import no.nordicsemi.android.gls.GlsServer
|
||||
import no.nordicsemi.android.gls.GLSServer
|
||||
import no.nordicsemi.android.uart.UartServer
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -49,7 +49,7 @@ class NrfToolboxApplication : Application() {
|
||||
lateinit var uartServer: UartServer
|
||||
|
||||
@Inject
|
||||
lateinit var glsServer: GlsServer
|
||||
lateinit var glsServer: GLSServer
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
@@ -23,6 +23,7 @@ import no.nordicsemi.android.kotlin.ble.advertiser.BleAdvertiser
|
||||
import no.nordicsemi.android.kotlin.ble.core.MockServerDevice
|
||||
import no.nordicsemi.android.kotlin.ble.core.advertiser.BleAdvertisingConfig
|
||||
import no.nordicsemi.android.kotlin.ble.core.advertiser.BleAdvertisingData
|
||||
import no.nordicsemi.android.kotlin.ble.core.advertiser.BleAdvertisingSettings
|
||||
import no.nordicsemi.android.kotlin.ble.core.data.BleGattPermission
|
||||
import no.nordicsemi.android.kotlin.ble.core.data.BleGattProperty
|
||||
import no.nordicsemi.android.kotlin.ble.profile.gls.RecordAccessControlPointInputParser
|
||||
@@ -39,7 +40,7 @@ private const val STANDARD_DELAY = 1000L
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
@Singleton
|
||||
class GlsServer @Inject constructor(
|
||||
class GLSServer @Inject constructor(
|
||||
private val scope: CoroutineScope,
|
||||
@ApplicationContext
|
||||
private val context: Context,
|
||||
@@ -151,8 +152,8 @@ class GlsServer @Inject constructor(
|
||||
fun start(
|
||||
context: Context,
|
||||
device: MockServerDevice = MockServerDevice(
|
||||
name = "GLS Server",
|
||||
address = "11:22:33:44:55:66"
|
||||
name = "Mock Glucose Server",
|
||||
address = "AA:BB:CC:DD:EE:FF"
|
||||
),
|
||||
) = scope.launch {
|
||||
val gmCharacteristic = ServerBleGattCharacteristicConfig(
|
||||
@@ -199,11 +200,20 @@ class GlsServer @Inject constructor(
|
||||
logger = { _, log -> println(log) }
|
||||
)
|
||||
|
||||
val advertiser = BleAdvertiser.create(context)
|
||||
advertiser.advertise(
|
||||
config = BleAdvertisingConfig(advertiseData = BleAdvertisingData(serviceUuid = ParcelUuid(GLS_SERVICE_UUID))),
|
||||
mock = device
|
||||
).launchIn(scope)
|
||||
BleAdvertiser.create(context)
|
||||
.advertise(
|
||||
config = BleAdvertisingConfig(
|
||||
settings = BleAdvertisingSettings(
|
||||
deviceName = "Glucose",
|
||||
legacyMode = true,
|
||||
),
|
||||
advertiseData = BleAdvertisingData(
|
||||
includeDeviceName = true,
|
||||
serviceUuid = ParcelUuid(GLS_SERVICE_UUID),
|
||||
)
|
||||
),
|
||||
mock = device)
|
||||
.launchIn(scope)
|
||||
|
||||
launch {
|
||||
server.connections
|
||||
@@ -74,7 +74,7 @@ internal class GLSViewModelTest {
|
||||
|
||||
lateinit var viewModel: GLSViewModel
|
||||
|
||||
lateinit var glsServer: GlsServer
|
||||
lateinit var glsServer: GLSServer
|
||||
|
||||
private val device = MockServerDevice(
|
||||
name = "GLS Server",
|
||||
@@ -112,7 +112,7 @@ internal class GLSViewModelTest {
|
||||
}))
|
||||
justRun { viewModel.logAnalytics(any()) }
|
||||
|
||||
glsServer = GlsServer(CoroutineScope(UnconfinedTestDispatcher()), context, logger)
|
||||
glsServer = GLSServer(CoroutineScope(UnconfinedTestDispatcher()), context, logger)
|
||||
glsServer.start(spyk(), device)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ class UartServer @Inject constructor(
|
||||
fun start(
|
||||
context: Context,
|
||||
device: MockServerDevice = MockServerDevice(
|
||||
name = "UART Server",
|
||||
name = "Mock UART Server",
|
||||
address = "66:55:44:33:22:11"
|
||||
),
|
||||
) = scope.launch {
|
||||
|
||||
Reference in New Issue
Block a user