send-packet

gabbapeople/simple-byte-protocol/send-packet

Sends a packet via UART
send-packet
@/send-packet
Sends a packet via UART
UARTxod/uart/uart
PCKT@/packet
A packet to be sent
SENDpulse
Triggers a new packet sent
send-packet
UART
PCKT
SEND
DONE
ERR
ERRpulse
Fires on a failed packet sent
DONEpulse
Fires on a successful packet sent
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 {
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    if (!isInputDirty<input_SEND>(ctx))
        return;

    auto uart = getValue<input_UART>(ctx);
    auto _packet = getValue<input_PCKT>(ctx);

    size_t n = 0;
    while (_packet.bufferSize--) {
        if (uart->writeByte(*_packet.buffer++)){
            n++;
            emitValue<output_DONE>(ctx, 1);
        }
        else{
            emitValue<output_ERR>(ctx, 1);
            break;
        }
    }
}