Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

ltkcpp_frameextract.cpp

00001 
00002 /*
00003  ***************************************************************************
00004  *  Copyright 2007,2008 Impinj, Inc.
00005  *
00006  *  Licensed under the Apache License, Version 2.0 (the "License");
00007  *  you may not use this file except in compliance with the License.
00008  *  You may obtain a copy of the License at
00009  *
00010  *      http://www.apache.org/licenses/LICENSE-2.0
00011  *
00012  *  Unless required by applicable law or agreed to in writing, software
00013  *  distributed under the License is distributed on an "AS IS" BASIS,
00014  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  *  See the License for the specific language governing permissions and
00016  *  limitations under the License.
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          * Should we be picky about reserved bits?
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 }; /* namespace LLRP */
00101 

Generated on Wed Nov 26 12:27:45 2008 for LTKCPP-- LLRP Toolkit C Plus Plus Library by  doxygen 1.3.9.1