From 99a08ffd0d33bc8c68d86c08d76bc44f3ae68ae4 Mon Sep 17 00:00:00 2001 From: Walter Huf Date: Sat, 16 Mar 2024 11:26:08 -0700 Subject: [PATCH] Reads some small data from RHMIApplicationEtch AAIdrive relies on the previous behavior where ImageIdModels can remember their imageId after being loaded from a resource file. This can be provided by RHMIApplicationIdempotent but the unit tests skip this wrapping layer --- .../idriveconnectkit/rhmi/RHMIApplication.kt | 19 +++++++++++++++++-- .../idriveconnectkit/xmlutils/XMLUtils.kt | 1 + .../idriveconnectkit/TestXMLParsing.kt | 3 +++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/bimmergestalt/idriveconnectkit/rhmi/RHMIApplication.kt b/src/main/java/io/bimmergestalt/idriveconnectkit/rhmi/RHMIApplication.kt index f1acc03..abf2a3d 100644 --- a/src/main/java/io/bimmergestalt/idriveconnectkit/rhmi/RHMIApplication.kt +++ b/src/main/java/io/bimmergestalt/idriveconnectkit/rhmi/RHMIApplication.kt @@ -131,27 +131,42 @@ class RHMIApplicationConcrete : RHMIApplication() { } -class RHMIApplicationEtch constructor(val remoteServer: BMWRemotingServer, val rhmiHandle: Int) : RHMIApplication() { - /** Represents an application layout that is backed by a Car connection */ +class RHMIApplicationEtch(val remoteServer: BMWRemotingServer, val rhmiHandle: Int) : RHMIApplication() { + /** Represents an application layout that is backed by a Car connection + * Most data is not retained, so if you want to read data back out, + * use RHMIApplicationConcrete or RHMIApplicationIdempotent + * */ override val models = HashMap() override val actions = HashMap() override val events = HashMap() override val states = HashMap() override val components = HashMap() + // remember a little bit of properties and small ints + val modelData = HashMap() + val propertyData = HashMap>() + @Throws(BMWRemoting.SecurityException::class, BMWRemoting.IllegalArgumentException::class, BMWRemoting.ServiceException::class) override fun setModel(modelId: Int, value: Any?) { + if (value is Int || value is BMWRemoting.RHMIResourceIdentifier) { + modelData[modelId] = value + } else { + modelData.remove(modelId) + } if (ignoreUpdates) return this.remoteServer.rhmi_setData(this.rhmiHandle, modelId, value) } + override fun getModel(modelId: Int): Any? = modelData[modelId] @Throws(BMWRemoting.SecurityException::class, BMWRemoting.IllegalArgumentException::class, BMWRemoting.ServiceException::class) override fun setProperty(componentId: Int, propertyId: Int, value: Any?) { + propertyData.getOrPut(componentId){HashMap()}[propertyId] = value if (ignoreUpdates) return val propertyValue = HashMap() propertyValue[0] = value this.remoteServer.rhmi_setProperty(rhmiHandle, componentId, propertyId, propertyValue) } + override fun getProperty(componentId: Int, propertyId: Int): Any? = propertyData[componentId]?.get(propertyId) @Throws(BMWRemoting.SecurityException::class, BMWRemoting.IllegalArgumentException::class, BMWRemoting.ServiceException::class) override fun triggerHMIEvent(eventId: Int, args: Map) { diff --git a/src/main/java/io/bimmergestalt/idriveconnectkit/xmlutils/XMLUtils.kt b/src/main/java/io/bimmergestalt/idriveconnectkit/xmlutils/XMLUtils.kt index 4fa1338..3954601 100644 --- a/src/main/java/io/bimmergestalt/idriveconnectkit/xmlutils/XMLUtils.kt +++ b/src/main/java/io/bimmergestalt/idriveconnectkit/xmlutils/XMLUtils.kt @@ -140,6 +140,7 @@ object XMLUtils { } else { getter.returnType } + println("Found setter $setterType $setterName for $key") try { when (setterType) { Integer::class.javaPrimitiveType -> classType.getMethod(setterName, Integer::class.javaPrimitiveType).invoke(obj, value.toInt()) diff --git a/src/test/java/io/bimmergestalt/idriveconnectkit/TestXMLParsing.kt b/src/test/java/io/bimmergestalt/idriveconnectkit/TestXMLParsing.kt index 2815afe..4b2fb4f 100644 --- a/src/test/java/io/bimmergestalt/idriveconnectkit/TestXMLParsing.kt +++ b/src/test/java/io/bimmergestalt/idriveconnectkit/TestXMLParsing.kt @@ -742,6 +742,9 @@ class TestXMLParsing { assertEquals(1, component?.properties?.size) assertEquals("false", component?.properties?.get(1)?.value) + val property = component?.properties?.get(1) as RHMIProperty + assertEquals("true", property.getForLayout(0)) + assertEquals(1, property.getForLayout(1)) val propertyBag = component?.properties?.get(1) as RHMIProperty.LayoutBag assertEquals("true", propertyBag.getForLayout(0)) assertEquals(1, propertyBag.getForLayout(1))