Exemplo n.º 1
0
static void receiveMorePackets(void)
{
    uint8 XDATA * packet;

    if (rxBytesLeft != 0)
    {
        // There are bytes available.  The higher-level code should
        // call radioComRxReceiveByte to get them.
        return;
    }

    if (WAITING_TO_REPORT_RX_SIGNALS)
    {
        // The higher-level code needs to call radioComRxSignals before
        // we feed it any more data.
        return;
    }

    // Each iteration of this loop processes one packet received on the radio.
    // This loop stops when we are out of packets or when we received a packet
    // that contains some information that the higher-level code needs to process.
    while(packet = radioLinkRxCurrentPacket())
    {
        switch(radioLinkRxCurrentPayloadType())
        {
        case PAYLOAD_TYPE_DATA:
            // We received some data.  Populate rxPointer and rxBytesLeft.
            // The data can be retreived with radioComRxAvailable and racioComRxReceiveByte().

            // Assumption: radioLink doesn't ever return zero-length packets,
            // so rxBytesLeft is non-zero now and we don't have to worry about
            // discard zero-length packets in radio_com.c.
            rxBytesLeft = packet[0];  // Read the packet length.
            rxPointer = packet+1;              // Make rxPointer point to the data.
            return;

        case PAYLOAD_TYPE_CONTROL_SIGNALS:
            // We received a command to set the control signals.
            radioComRxSignals = packet[1];

            radioLinkRxDoneWithPacket();

            if (WAITING_TO_REPORT_RX_SIGNALS)
            {
                // The higher-level code has not seen these values for the control
                // signals yet, so stop processing packets.
                // The higher-level code can access these values by calling radioComRxControlSignals().
                return;
            }

            // It was a redundant command so don't do anything special.
            // Keep processing packets.
            break;
        }
    }
}
Exemplo n.º 2
0
/** Checks for new bytes available from the wireless radio
 * and processes all that are available. */
void processBytesFromRadio()
{
    uint8 i, n;
    uint8 XDATA *rcv;
    
    rcv = radioLinkRxCurrentPacket();
    if(rcv != NULL) {
        n = rcv[0]; // payload length
        for(i = 1; i <= n && radioLinkTxAvailable(); i++) {
            processByte(rcv[i]);
        }
        radioLinkRxDoneWithPacket();
    }
}