Is GenericChannel Non Blocking?

Forgive me if I'm asking something really dumb, but I'm coming from a C background and just trying to get a handle on the timing of things.
Suppose I've used Ant.GenericChannel and am listening to incoming Ant messages at roughly 4 times a second, and want to send some messages back to the master device.

If my listener is something like-

function onMessage(msg)
{
//..
// update remote device
GenericChannel.sendAcknowledge(msg1);
GenericChannel.sendAcknowledge(msg2);
GenericChannel.sendAcknowledge(msg3);
GenericChannel.sendAcknowledge(msg4);
//..
}


Do the SendAcknowledge commands get queued internally and the function return immediately, or is there a quarter second delay for each one to wait for the next available time-slot?
And If there is a delay, are incoming ant messages queued, or just discarded until onMessage returns?
  • I think the answer should be in the "ANT Message Protocol and Usage" document but I wasn't able to find it in the time I have right now.

    My guess is that if you do the 4 send Acknowledges in a row like that and all in between incoming messages, that only msg4 would get sent and the other 3 would be overwritten and never sent. I would need to test this to be sure though.
  • Yup, As I sequence I wouldn't expect it to work if fed straight into the ant radio module, I'm just trying to get a feel for what level of abstraction monkeyC has from transceiver.
  • It's non blocking, it will get buffered and sent to the radio in a different context.

    When sending acknowledge messages, wait to receive TX_COMPLETE or TX_FAIL before attempting to send the one. In the case of TX_FAIL I usual will retry the previous message. If you don't wait for TX_COMPLETE/TX_FAIL from a previous ack message, you will receive a TRANSFER_IN_PROGRESS when attempting to send a subsequent message.

    When sending broadcast messages, wait for the TX_EVENT before you send the next broadcast message. Else you can overwrite the previous one.
  • I'm not sure I understand the blocking vs non-blocking terminology. However, it looks like my guess above was wrong. If I send multiple acknowledge messages in between transmissions it looks like it buffers the messages and sends them out in response to subsequent received messages.

    I put in the following code. The display device is setup to send it's current time back to the sensor when the sensor requests it. I just added in a bunch more acknowledge messages so I could look in SimulANT+ to see what the messages looked like.

    if (utcTimeRequired) {
    // create and populate the data payload
    var payload = new [8];
    payload[0] = 0x10; // Command data page
    payload[1] = 0x00; // Set time command
    payload[2] = 0xFF; // Reserved
    payload[3] = 0; // Signed 2's complement value indicating local time offset in 15m intervals

    // set the current time
    var epoch = Time.now().value() - 631065600;
    payload[4] = (epoch ) & 0xFF;
    payload[5] = (epoch >> 8) & 0xFF;
    payload[6] = (epoch >> 16) & 0xFF;
    payload[7] = (epoch >> 24) & 0xFF;

    // form and send the message
    var message = new Ant.Message();
    message.setPayload(payload);
    GenericChannel.sendAcknowledge(message);

    payload[0] = 0x00;
    payload[1] = 0x00;
    payload[2] = 0x00;
    payload[3] = 0x00;
    payload[4] = 0x00;
    payload[5] = 0x00;
    payload[6] = 0x00;
    payload[7] = 0x00;
    message.setPayload(payload);
    GenericChannel.sendAcknowledge(message);

    payload[0] = 0x01;
    payload[1] = 0x01;
    payload[2] = 0x01;
    payload[3] = 0x01;
    payload[4] = 0x01;
    payload[5] = 0x01;
    payload[6] = 0x01;
    payload[7] = 0x01;
    message.setPayload(payload);
    GenericChannel.sendAcknowledge(message);

    payload[0] = 0x02;
    payload[1] = 0x02;
    payload[2] = 0x02;
    payload[3] = 0x02;
    payload[4] = 0x02;
    payload[5] = 0x02;
    payload[6] = 0x02;
    payload[7] = 0x02;
    message.setPayload(payload);
    GenericChannel.sendAcknowledge(message);

    payload[0] = 0x03;
    payload[1] = 0x03;
    payload[2] = 0x03;
    payload[3] = 0x03;
    payload[4] = 0x03;
    payload[5] = 0x03;
    payload[6] = 0x03;
    payload[7] = 0x03;
    message.setPayload(payload);
    GenericChannel.sendAcknowledge(message);

    }


    I got the following response in SimulANT+. It queued up the acknowledge messages in order and sent them one at a time.


    https://cdn2.hubspot.net/hubfs/188620/images/image.png