Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heterogenous register types in yaml schema #40

Open
bruno-f-cruz opened this issue Mar 7, 2024 · 0 comments
Open

Heterogenous register types in yaml schema #40

bruno-f-cruz opened this issue Mar 7, 2024 · 0 comments

Comments

@bruno-f-cruz
Copy link
Member

@Poofjunior Thanks for the great input and raising this requirement, I agree having more flexibility in passing around packed custom structures with possibly heterogeneous types is important.

Following the meeting, I was playing around with the YAML schema and actually there is a small kink that doesn't allow it to represent heterogeneous types out-of-the-box (yet). It is definitely fixable though and this is a use case we should indeed support so I will flag an issue to fix it. Nevertheless, for aligned types, you could do:

%YAML 1.1
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/harp-tech/reflex-generator/main/schema/device.json
device: harpy
whoAmI: 0000
firmwareVersion: "0.1"
hardwareTargets: "0.0"
registers:
  Accelerometer:
    address: 32
    type: S16
    length: 3
    access: Event
    payloadSpec:
      X:
        offset: 0
        description: Represents the x-coordinate of the payload.
      Y:
        offset: 1
        description: Represents the y-coordinate of the payload.
      Z:
        offset: 2
        description: Represents the z-coordinate of the payload.

This will generate in the high-level interface the type AccelerometerPayload with the following signature (edited for conciseness):

public struct AccelerometerPayload
{
    public AccelerometerPayload(short x, short y, short z)
    {
        X = x;
        Y = y;
        Z = z;
    }

    public short X;
    public short Y;
    public short Z;
}

And the auto-generated converters:

static AccelerometerPayload ParsePayload(short[] payload)
{
    AccelerometerPayload result;
    result.X = payload[0];
    result.Y = payload[1];
    result.Z = payload[2];
    return result;
}

static short[] FormatPayload(AccelerometerPayload value)
{
    short[] result;
    result = new short[3];
    result[0] = value.X;
    result[1] = value.Y;
    result[2] = value.Z;
    return result;
}

It is actually possible using the message manipulation API to marshal arbitrary payload structs directly (with the equivalent of memcpy), and having an easy way to specify something like this in the spec is definitely interesting. I think I have a solution but need to go through a few edge cases more carefully to make sure it will be workable. Thanks for the push! I'll post here once I have something more complete.

Originally posted by @glopesdev in #27 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant