LTKCPP-- LLRP Toolkit C Plus Plus Library
ltkcpp_frameextract.cpp
1 
2 /*
3  *****************************************************************************
4  * *
5  * IMPINJ CONFIDENTIAL AND PROPRIETARY *
6  * *
7  * This source code is the sole property of Impinj, Inc. Reproduction or *
8  * utilization of this source code in whole or in part is forbidden without *
9  * the prior written consent of Impinj, Inc. *
10  * *
11  * (c) Copyright Impinj, Inc. 2007,2008. All rights reserved. *
12  * *
13  *****************************************************************************/
14 
15 
16 
17 #include <assert.h>
18 #include <stdio.h>
19 
20 #include "ltkcpp_platform.h"
21 #include "ltkcpp_base.h"
22 #include "ltkcpp_frame.h"
23 
24 
25 namespace LLRP
26 {
27 
28 CFrameExtract::CFrameExtract (void)
29 {
30  memset(this, 0, sizeof *this);
31 }
32 
33 CFrameExtract::CFrameExtract (
34  const unsigned char * pBuffer,
35  unsigned int nBuffer)
36 {
37  memset(this, 0, sizeof *this);
38 
39  if(10u > nBuffer)
40  {
41  m_MessageLength = 10u;
42  m_nBytesNeeded = m_MessageLength - nBuffer;
43  m_eStatus = NEED_MORE;
44  }
45  else
46  {
47  llrp_u16_t VersType;
48 
49  VersType = pBuffer[0];
50  VersType <<= 8u;
51  VersType |= pBuffer[1];
52 
53  m_MessageLength = pBuffer[2];
54  m_MessageLength <<= 8u;
55  m_MessageLength |= pBuffer[3];
56  m_MessageLength <<= 8u;
57  m_MessageLength |= pBuffer[4];
58  m_MessageLength <<= 8u;
59  m_MessageLength |= pBuffer[5];
60 
61  /*
62  * Should we be picky about reserved bits?
63  */
64 
65  m_MessageType = VersType & 0x3FFu;
66  m_ProtocolVersion = (VersType >> 10u) & 0x7u;
67 
68  m_MessageID = pBuffer[6];
69  m_MessageID <<= 8u;
70  m_MessageID |= pBuffer[7];
71  m_MessageID <<= 8u;
72  m_MessageID |= pBuffer[8];
73  m_MessageID <<= 8u;
74  m_MessageID |= pBuffer[9];
75 
76  if(10u > m_MessageLength)
77  {
78  m_nBytesNeeded = 0;
79  m_eStatus = FRAME_ERROR;
80  }
81  else if(nBuffer >= m_MessageLength)
82  {
83  m_nBytesNeeded = 0;
84  m_eStatus = READY;
85  }
86  else
87  {
88  m_nBytesNeeded = m_MessageLength - nBuffer;
89  m_eStatus = NEED_MORE;
90  }
91  }
92 }
93 
94 
95 }; /* namespace LLRP */
96 
Based type descriptions for the LTKCPP library.
Classes to encode and decod LLRP binary frames.
Based types for the LKTCPP library.