packet

gabbapeople/simple-byte-protocol/packet

Creates a packet type of a specific size
packet
@/packet
Creates a packet type of a specific size
SIZEnumber
Specifies the package size
packet
PCKT
SIZE
PCKT@/packet
To use the node in your project you should have the gabbapeople/simple-byte-protocol library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

struct State {
    uint8_t* buffer;
    uint8_t bufferSize;
    uint8_t idx;
};

struct Type {
    uint8_t* buffer;
    uint8_t bufferSize;
    uint8_t idx;
};

{{ GENERATED_CODE }}


void evaluate(Context ctx) {
    auto state = getState(ctx);

    if (isSettingUp()) {
        state->bufferSize = getValue<input_SIZE>(ctx);
        state->buffer = new uint8_t[state->bufferSize - 1];
        state->idx = 1;
    }

    Type packet;

    packet.bufferSize = state->bufferSize;
    packet.buffer = state->buffer;
    packet.idx = state->idx;
    emitValue<output_PCKT>(ctx, packet);

}