Recycle example.cydsn/Generated_Source/PSoC5/XBEE.c
uint8_t XBEE_ReadPacket(XBEE_packet_t * packet) {
    uint8_t i, readData, checksum;
    uint16_t length;
    
    /* Check if there are any packets in the RX buffer */
    if(XBEE_rxBufferHead == XBEE_rxBufferTail) {
        /* Unset PACKET status bit */
        XBEE_RX_STATUS_REG &= ~XBEE_RX_STATUS_PACKET;
        return XBEE_READPACKET_EMPTY;
    }

    /* Read from the head of the queue */
    XBEE_rxBufferRead = XBEE_rxBufferHead;
        
    /* Check for packet start */
    if(XBEE_RxBufferRead() != XBEE_PACKET_START) {
        /* Raise START ERROR status bit */
        XBEE_RX_STATUS_REG |= XBEE_RX_STATUS_START_ERROR;
        return XBEE_READPACKET_ERROR;
    }
        
    /* Read packet length */
    length = (XBEE_RxBufferRead() << 8) + XBEE_RxBufferRead();
        
    /* Check length against buffer size */
    if(length > XBEE_RxBufferSize() + 4) {
        /* Raise LENGTH ERROR status bit */
        XBEE_RX_STATUS_REG |= XBEE_RX_STATUS_LENGTH_ERROR;
        return XBEE_READPACKET_ERROR;
    }
    
    /* Update length field */
    packet->length = length;
            
    /* Read packet payload */
    checksum = 0xFF;
    for(i=0; i < length; i++) {
        readData = XBEE_RxBufferRead();
        packet->payload[i] = readData;
        checksum -= readData;
    }
        
    /* Read checksum */
    packet->checksum = XBEE_RxBufferRead();
        
    /* Check if there's been an UNDERRUN condition during reading */
    if((XBEE_RX_STATUS_REG & XBEE_RX_STATUS_UNDERRUN) != 0u) {
        return XBEE_READPACKET_ERROR;
    }
    
    /* Verify checksum and return result */
    if(packet->checksum != checksum) {
        /* Set CHECKSUM ERROR status bit */
        XBEE_RX_STATUS_REG |= XBEE_RX_STATUS_CHECKSUM_ERROR;
        return XBEE_READPACKET_ERROR;
    }
    
    /* Check for more packets in the buffer */
    if(XBEE_rxBufferHead == XBEE_rxBufferTail) {
        /* Unset PACKET status bit */
        XBEE_RX_STATUS_REG &= ~XBEE_RX_STATUS_PACKET;
    }
    
    /* Update buffer head */
    XBEE_rxBufferHead = XBEE_rxBufferRead;
    
    return XBEE_READPACKET_OK;
}
/**
* Read packet from the XBEE_rxBuffer.
* This functions modifies the XBEE_RX_STATUS_REG variable. Check it for
* deeper insight of the status of the register.
*
* @see XBEE_ReadRxStatus()
* @see XBEE_RX_STATUS_REG
*
* @param packet Packet to store the content from the buffer.
* @return XBEE_READPACKET_OK: Packet read successfully.
* @return XBEE_READPACKET_EMPTY: There are no packets in the buffer.
* @return XBEE_READPACKET_ERROR: There is been an error reading the packet.
*/
Read packet from the XBEE_rxBuffer.
This functions modifies the XBEE_RX_STATUS_REG variable. Check it for
deeper insight of the status of the register.
Read packet from the XBEE_rxBuffer . This functions modifies the XBEE_RX_STATUS_REG variable . Check it for deeper insight of the status of the register .
uint8_t XBEE_ReadPacket(XBEE_packet_t * packet) {
    uint8_t i, readData, checksum;
    uint16_t length;
    if(XBEE_rxBufferHead == XBEE_rxBufferTail) {
        XBEE_RX_STATUS_REG &= ~XBEE_RX_STATUS_PACKET;
        return XBEE_READPACKET_EMPTY;
    }
    XBEE_rxBufferRead = XBEE_rxBufferHead;
    if(XBEE_RxBufferRead() != XBEE_PACKET_START) {
        XBEE_RX_STATUS_REG |= XBEE_RX_STATUS_START_ERROR;
        return XBEE_READPACKET_ERROR;
    }
    length = (XBEE_RxBufferRead() << 8) + XBEE_RxBufferRead();
    if(length > XBEE_RxBufferSize() + 4) {
        XBEE_RX_STATUS_REG |= XBEE_RX_STATUS_LENGTH_ERROR;
        return XBEE_READPACKET_ERROR;
    }
    packet->length = length;
    checksum = 0xFF;
    for(i=0; i < length; i++) {
        readData = XBEE_RxBufferRead();
        packet->payload[i] = readData;
        checksum -= readData;
    }
    packet->checksum = XBEE_RxBufferRead();
    if((XBEE_RX_STATUS_REG & XBEE_RX_STATUS_UNDERRUN) != 0u) {
        return XBEE_READPACKET_ERROR;
    }
    if(packet->checksum != checksum) {
        XBEE_RX_STATUS_REG |= XBEE_RX_STATUS_CHECKSUM_ERROR;
        return XBEE_READPACKET_ERROR;
    }
    if(XBEE_rxBufferHead == XBEE_rxBufferTail) {
        XBEE_RX_STATUS_REG &= ~XBEE_RX_STATUS_PACKET;
    }
    XBEE_rxBufferHead = XBEE_rxBufferRead;
    return XBEE_READPACKET_OK;
}
uint8_t XBEE_ReadPacket ( XBEE_packet_t * packet ) { uint8_t i , readData , checksum ; uint16_t length ; if ( XBEE_rxBufferHead == XBEE_rxBufferTail ) { XBEE_RX_STATUS_REG &= ~ XBEE_RX_STATUS_PACKET ; return XBEE_READPACKET_EMPTY ; } XBEE_rxBufferRead = XBEE_rxBufferHead ; if ( XBEE_RxBufferRead ( ) != XBEE_PACKET_START ) { XBEE_RX_STATUS_REG |= XBEE_RX_STATUS_START_ERROR ; return XBEE_READPACKET_ERROR ; } length = ( XBEE_RxBufferRead ( ) << 8 ) + XBEE_RxBufferRead ( ) ; if ( length > XBEE_RxBufferSize ( ) + 4 ) { XBEE_RX_STATUS_REG |= XBEE_RX_STATUS_LENGTH_ERROR ; return XBEE_READPACKET_ERROR ; } packet -> length = length ; checksum = 0xFF ; for ( i = 0 ; i < length ; i ++ ) { readData = XBEE_RxBufferRead ( ) ; packet -> payload [ i ] = readData ; checksum -= readData ; } packet -> checksum = XBEE_RxBufferRead ( ) ; if ( ( XBEE_RX_STATUS_REG & XBEE_RX_STATUS_UNDERRUN ) != 0u ) { return XBEE_READPACKET_ERROR ; } if ( packet -> checksum != checksum ) { XBEE_RX_STATUS_REG |= XBEE_RX_STATUS_CHECKSUM_ERROR ; return XBEE_READPACKET_ERROR ; } if ( XBEE_rxBufferHead == XBEE_rxBufferTail ) { XBEE_RX_STATUS_REG &= ~ XBEE_RX_STATUS_PACKET ; } XBEE_rxBufferHead = XBEE_rxBufferRead ; return XBEE_READPACKET_OK ; }
Read packet from the XBEE_rxBuffer.
Read packet from the XBEE_rxBuffer .
/* Check if there are any packets in the RX buffer */ /* Unset PACKET status bit */ /* Read from the head of the queue */ /* Check for packet start */ /* Raise START ERROR status bit */ /* Read packet length */ /* Check length against buffer size */ /* Raise LENGTH ERROR status bit */ /* Update length field */ /* Read packet payload */ /* Read checksum */ /* Check if there's been an UNDERRUN condition during reading */ /* Verify checksum and return result */ /* Set CHECKSUM ERROR status bit */ /* Check for more packets in the buffer */ /* Unset PACKET status bit */ /* Update buffer head */