00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <assert.h>
00023 #include <stdio.h>
00024
00025 #include "ltkcpp_platform.h"
00026 #include "ltkcpp_base.h"
00027 #include "ltkcpp_frame.h"
00028
00029
00030 namespace LLRP
00031 {
00032
00033 CFrameExtract::CFrameExtract (void)
00034 {
00035 memset(this, 0, sizeof *this);
00036 }
00037
00038 CFrameExtract::CFrameExtract (
00039 const unsigned char * pBuffer,
00040 unsigned int nBuffer)
00041 {
00042 memset(this, 0, sizeof *this);
00043
00044 if(10u > nBuffer)
00045 {
00046 m_MessageLength = 10u;
00047 m_nBytesNeeded = m_MessageLength - nBuffer;
00048 m_eStatus = NEED_MORE;
00049 }
00050 else
00051 {
00052 llrp_u16_t VersType;
00053
00054 VersType = pBuffer[0];
00055 VersType <<= 8u;
00056 VersType |= pBuffer[1];
00057
00058 m_MessageLength = pBuffer[2];
00059 m_MessageLength <<= 8u;
00060 m_MessageLength |= pBuffer[3];
00061 m_MessageLength <<= 8u;
00062 m_MessageLength |= pBuffer[4];
00063 m_MessageLength <<= 8u;
00064 m_MessageLength |= pBuffer[5];
00065
00066
00067
00068
00069
00070 m_MessageType = VersType & 0x3FFu;
00071 m_ProtocolVersion = (VersType >> 10u) & 0x7u;
00072
00073 m_MessageID = pBuffer[6];
00074 m_MessageID <<= 8u;
00075 m_MessageID |= pBuffer[7];
00076 m_MessageID <<= 8u;
00077 m_MessageID |= pBuffer[8];
00078 m_MessageID <<= 8u;
00079 m_MessageID |= pBuffer[9];
00080
00081 if(10u > m_MessageLength)
00082 {
00083 m_nBytesNeeded = 0;
00084 m_eStatus = FRAME_ERROR;
00085 }
00086 else if(nBuffer >= m_MessageLength)
00087 {
00088 m_nBytesNeeded = 0;
00089 m_eStatus = READY;
00090 }
00091 else
00092 {
00093 m_nBytesNeeded = m_MessageLength - nBuffer;
00094 m_eStatus = NEED_MORE;
00095 }
00096 }
00097 }
00098
00099
00100 };
00101