Skip to content

Commit

Permalink
Mock devices improvements (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
philips77 authored Jan 3, 2024
1 parent c922e69 commit de978fd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit de978fd

Please sign in to comment.