OpenCyphal / libcanard

A compact implementation of the Cyphal/CAN protocol in C for high-integrity real-time embedded systems
http://opencyphal.org
MIT License
326 stars 192 forks source link

Readme usage example typos/bugs #144

Closed PetervdPerk-NXP closed 4 years ago

PetervdPerk-NXP commented 4 years ago

In readme.md an example described on how to use libcanard, however in this segment

for (const CanardFrame* txf = NULL; (txf = canardTxPeek(&ins)) != NULL;)  // Look at the top of the TX queue.
{
    if (txf->timestamp_usec < getCurrentMicroseconds())  // Check if the frame has timed out.
    {
        if (!pleaseTransmit(&txf))             // Send the frame. Redundant interfaces may be used here.
        {
            break;                             // If the driver is busy, break and retry later.
        }
    }
    canardTxPop(&ins);                         // Remove the frame from the queue after it's transmitted.
    ins.memory_free(&ins, (CanardFrame*)txf);  // Deallocate the dynamic memory afterwards.
}

There are two bugs, I suppose we want to drop frames when the frame has timed out e.g:

if (txf->timestamp_usec > getCurrentMicroseconds())  // Check if the frame has timed out.

And I suppose we want to have a pointer here instead of a reference.

if (!pleaseTransmit(txf))             // Send the frame. Redundant interfaces may be used here.

Furthermore the example doesn't describe on how to subscribe to the uavcan.node.Heartbeat messages, If that could be added that would be nice.