i2c_receiveData(sDevice *psDevice, byte_t *pbBuffer, uint16_t *puiLen)
{
.
.
//extract the packet data length
unFrameLen = (*(pbBuffer+1) << 8) | *(pbBuffer + 2);
if(unFrameLen > *puiLen)
unFrameLen=*puiLen;
.
.
}
Here how this statement is finding Frame Length?
unFrameLen = (*(pbBuffer+1) << 8) | *(pbBuffer + 2);
Here pbBuffer is a pointer to unsigned char array.
calling function was,
i2c_receiveData(psDevice, prgDataRecv, &unRegLen);
In this case, it appears the “frame length” is stored at offset 1 into the passed buffer.
It also appears that it is a 16-bit integer.
In order to get a usable 16-bit integer you must unpack from the buffer. It would be better to cast and use
htons/ntohsinstead, but I presume the architecture is well-known and portability isn’t a concern.For an input of, say,
pbBuffer = {0, 1, 2}, this ends up being:… which gives:
… shifting
1bleft 8 bits gives:… and OR-ing with
10b:Now you have a 16-bit integer from the two 8-bit integers in
pbBuffer[1..2]: