Пример #1
0
//*****************************************************************************
//
//! GetPacket() receives a data packet.
//!
//! \param pucData is the location to store the data received from the device.
//! \param pucSize is the number of bytes returned in the pucData buffer that
//! was provided.
//!
//! This function receives a packet of data from UART port.
//!
//! \returns The function returns zero to indicated success while any non-zero
//! value indicates a failure.
//
//*****************************************************************************
int
GetPacket(unsigned char *pucData, unsigned char *pucSize)
{
    unsigned char ucCheckSum;
    unsigned char ucSize;

    //
    // Get the size waht and the checksum.
    //
    do
    {
        if(UARTReceiveData(&ucSize, 1))
        {
            return(-1);
        }
    }
    while(ucSize == 0);

    if(UARTReceiveData(&ucCheckSum, 1))
    {
        return(-1);
    }
    *pucSize = ucSize - 2;

    if(UARTReceiveData(pucData, *pucSize))
    {
        *pucSize = 0;
        return(-1);
    }

    //
    // Calculate the checksum from the data.
    //
    if(CheckSum(pucData, *pucSize) != ucCheckSum)
    {
        *pucSize = 0;
        return(NakPacket());
    }

    return(AckPacket());
}
Пример #2
0
//*****************************************************************************
//
//! GetPacket() receives a data packet.
//!
//! \param pui8Data is the location to store the data received from the device.
//! \param pui8Size is the number of bytes returned in the pui8Data buffer that
//! was provided.
//!
//! This function receives a packet of data from UART port.
//!
//! \returns The function returns zero to indicated success while any non-zero
//! value indicates a failure.
//
//*****************************************************************************
int32_t
GetPacket(uint8_t *pui8Data, uint8_t *pui8Size)
{
    uint8_t ui8CheckSum;
    uint8_t ui8Size;

    //
    // Get the size and the checksum.
    //
    do
    {
        if(UARTReceiveData(&ui8Size, 1))
        {
            return(-1);
        }
    }
    while(ui8Size == 0);

    if(UARTReceiveData(&ui8CheckSum, 1))
    {
        return(-1);
    }
    *pui8Size = ui8Size - 2;

    if(UARTReceiveData(pui8Data, *pui8Size))
    {
        *pui8Size = 0;
        return(-1);
    }

    //
    // Calculate the checksum from the data.
    //
    if(CheckSum(pui8Data, *pui8Size) != ui8CheckSum)
    {
        *pui8Size = 0;
        return(NakPacket());
    }

    return(AckPacket());
}