mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-04-06 02:01:58 +02:00
Make ota and serial check for the device status
This commit is contained in:
@@ -17,6 +17,7 @@ import kotlinx.coroutines.withContext
|
||||
import kotlinx.coroutines.withTimeout
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import solarxr_protocol.datatypes.DeviceId
|
||||
import solarxr_protocol.datatypes.TrackerStatus
|
||||
import solarxr_protocol.rpc.FirmwarePart
|
||||
import solarxr_protocol.rpc.FirmwareUpdateStatus
|
||||
import java.io.DataInputStream
|
||||
@@ -156,7 +157,12 @@ suspend fun doOtaFlash(
|
||||
// wait for the tracker with the correct id to come online
|
||||
val connected = withTimeoutOrNull(60_000) {
|
||||
server.context.state
|
||||
.map { state -> state.devices.values.any { it.context.state.value.id.toUByte() == deviceId.id } }
|
||||
.map { state ->
|
||||
state.devices.values.any {
|
||||
it.context.state.value.id.toUByte() == deviceId.id &&
|
||||
it.context.state.value.status != TrackerStatus.DISCONNECTED
|
||||
}
|
||||
}
|
||||
.filter { it }
|
||||
.first()
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import kotlinx.coroutines.flow.mapNotNull
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import solarxr_protocol.datatypes.TrackerStatus
|
||||
import solarxr_protocol.rpc.FirmwarePart
|
||||
import solarxr_protocol.rpc.FirmwareUpdateStatus
|
||||
|
||||
@@ -182,7 +183,8 @@ internal suspend fun doSerialFlashPostFlash(
|
||||
// wait for the tracker with that MAC to connect to the server via UDP
|
||||
val connected = withTimeoutOrNull(60_000) {
|
||||
server.context.state
|
||||
.map { state -> state.devices.values.any { it.context.state.value.macAddress?.uppercase() == macAddress } }
|
||||
.map { state -> state.devices.values.any { it.context.state.value.macAddress?.uppercase() == macAddress
|
||||
&& it.context.state.value.status != TrackerStatus.DISCONNECTED } }
|
||||
.filter { it }
|
||||
.first()
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ private fun createTracker(device: DeviceState, tracker: TrackerState, trackerMas
|
||||
trackerNum = tracker.id.toUByte(),
|
||||
deviceId = DeviceId(device.id.toUByte()),
|
||||
),
|
||||
status = if (trackerMask.status == true) tracker.status else null,
|
||||
status = if (trackerMask.status == true) device.status else null,
|
||||
rotation = if (trackerMask.rotation == true) tracker.rawRotation.let { Quat(it.x, it.y, it.z, it.w) } else null,
|
||||
info = if (trackerMask.info == true) {
|
||||
TrackerInfo(
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.ktor.http.HttpProtocolVersion
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import solarxr_protocol.datatypes.TrackerStatus
|
||||
import solarxr_protocol.datatypes.hardware_info.BoardType
|
||||
import solarxr_protocol.datatypes.hardware_info.ImuType
|
||||
import solarxr_protocol.datatypes.hardware_info.McuType
|
||||
@@ -33,6 +34,7 @@ data class DeviceState(
|
||||
val boardType: BoardType,
|
||||
val mcuType: McuType,
|
||||
val protocolVersion: Int,
|
||||
val status: TrackerStatus,
|
||||
val origin: DeviceOrigin,
|
||||
)
|
||||
|
||||
@@ -82,6 +84,7 @@ fun createDevice(
|
||||
protocolVersion = protocolVersion,
|
||||
ping = null,
|
||||
signalStrength = null,
|
||||
status = TrackerStatus.DISCONNECTED,
|
||||
)
|
||||
|
||||
val behaviours = listOf(DeviceStatsBehaviour)
|
||||
|
||||
@@ -20,7 +20,6 @@ data class TrackerState(
|
||||
val hardwareId: String,
|
||||
val sensorType: ImuType,
|
||||
val bodyPart: BodyPart?,
|
||||
val status: TrackerStatus,
|
||||
val customName: String?,
|
||||
val rawRotation: Quaternion,
|
||||
val deviceId: Int,
|
||||
@@ -61,7 +60,6 @@ fun createTracker(
|
||||
hardwareId = hardwareId,
|
||||
name = "Tracker #$id",
|
||||
rawRotation = Quaternion.IDENTITY,
|
||||
status = TrackerStatus.DISCONNECTED,
|
||||
bodyPart = null,
|
||||
origin = origin,
|
||||
deviceId = deviceId,
|
||||
|
||||
@@ -237,6 +237,15 @@ val SensorInfoBehaviour = UDPConnectionBehaviour(
|
||||
},
|
||||
observer = { observerContext ->
|
||||
observerContext.packetEvents.onPacket<SensorInfo> { event ->
|
||||
val device = observerContext.getDevice()
|
||||
?: error("invalid state - a device should exist at this point")
|
||||
|
||||
device.context.dispatch(
|
||||
DeviceActions.Update {
|
||||
copy(status = event.data.status)
|
||||
},
|
||||
)
|
||||
|
||||
val tracker = observerContext.getTracker(event.data.sensorId)
|
||||
|
||||
val action = TrackerActions.Update {
|
||||
@@ -249,9 +258,6 @@ val SensorInfoBehaviour = UDPConnectionBehaviour(
|
||||
if (tracker != null) {
|
||||
tracker.context.dispatch(action)
|
||||
} else {
|
||||
|
||||
val device = observerContext.getDevice()
|
||||
?: error("invalid state - a device should exist at this point")
|
||||
val deviceState = device.context.state.value
|
||||
val trackerId = observerContext.serverContext.nextHandle()
|
||||
val newTracker = createTracker(
|
||||
|
||||
@@ -307,7 +307,7 @@ class DoSerialFlashTest {
|
||||
protocolVersion = 0,
|
||||
serverContext = vrServer,
|
||||
boardType = BoardType.SLIMEVR,
|
||||
mcuType = McuType.ESP8266
|
||||
mcuType = McuType.ESP8266,
|
||||
)
|
||||
vrServer.context.dispatch(VRServerActions.NewDevice(device.context.state.value.id, device))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user