Skip to content

Any plans to support Generic Delta Set? #573

Description

@vkurkchi

After digging into the documentation and the source code, I noticed that the current implementation does not support sending the Generic Delta (Generic Level) messages. The GenericLevelSet message sends the level with only 2 bytes(Mesh Model Spec, 3.2.2.2) without a simple way to morph the level message into delta, while delta messages require 4 bytes(Mesh Model Spec, 3.2.2.4) for the payload.

The solution seems to be pretty straightforward, we can have a class that duplicates the GenericLevelSet interface (let's say GenericLevelDeltaSet) with a different opCode (0x8209), and instead of sending the level with 2 bytes, we can have a delta field of 4 bytes.

Currently, as an alternative, I use a hack like this one:

class GenericLevelDeltaSet(
    appKey: ApplicationKey,
    delta: Int,
    tId: Int,
    transitionSteps: Int? = null,
    transitionResolution: Int? = null,
    delay: Int? = null,
) : GenericUserPropertySet(appKey,
    (delta and 0xFFFF).toShort(),
    if (transitionSteps == null || transitionResolution == null || delay == null) {
        ByteArray(3).apply {
            set(0, (((delta shr 16) and 0xFF).toByte()))
            set(1, (((delta shr 24) and 0xFF).toByte()))
            set(2, ((tId and 0xFF).toByte()))
        }
    } else {
        ByteArray(5).apply{
            set(0, (((delta shr 16) and 0xFF).toByte()))
            set(1, (((delta shr 24) and 0xFF).toByte()))
            set(2, ((tId and 0xFF).toByte()))

            set(3, ((((transitionResolution shl 6) or transitionSteps) and 0xFF).toByte()))
            set(4, ((delay and 0xFF).toByte()))
        }
    }) {
    override fun getOpCode(): Int {
        return 0x8209 // Generic Delta Set
    }
}

In the hack above, I split the delta into "propertyId" and "values" fields.

In general, having a generic application message class for extension would be great (let's say making ApplicationMessage public), that way you can introduce a predictable way for extending the supported messages list.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions