ltkc_frameextract.c
Go to the documentation of this file.
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 "ltkc_platform.h"
00023 #include "ltkc_base.h"
00024 #include "ltkc_frame.h"
00025 
00026 
00027 /*
00028  * <0  => Error
00029  *  0  => Done, length is *pMessageLength
00030  * >0  => Need more, return value is number of required bytes
00031  */
00032 
00033 LLRP_tSFrameExtract
00034 LLRP_FrameExtract (
00035   const unsigned char *         pBuffer,
00036   unsigned int                  nBuffer)
00037 {
00038     LLRP_tSFrameExtract         frameExtract;
00039 
00040     memset(&frameExtract, 0, sizeof frameExtract);
00041 
00042     if(10 > nBuffer)
00043     {
00044         frameExtract.MessageLength = 10u;
00045         frameExtract.nBytesNeeded = frameExtract.MessageLength - nBuffer;
00046         frameExtract.eStatus = LLRP_FRAME_NEED_MORE;
00047     }
00048     else
00049     {
00050         llrp_u16_t                  VersType;
00051 
00052         VersType = pBuffer[0];
00053         VersType <<= 8u;
00054         VersType |= pBuffer[1];
00055 
00056         frameExtract.MessageLength = pBuffer[2];
00057         frameExtract.MessageLength <<= 8u;
00058         frameExtract.MessageLength |= pBuffer[3];
00059         frameExtract.MessageLength <<= 8u;
00060         frameExtract.MessageLength |= pBuffer[4];
00061         frameExtract.MessageLength <<= 8u;
00062         frameExtract.MessageLength |= pBuffer[5];
00063 
00064         /*
00065          * Should we be picky about reserved bits?
00066          */
00067 
00068         frameExtract.MessageType = VersType & 0x3FFu;
00069         frameExtract.ProtocolVersion = (VersType >> 10u) & 0x7u;
00070 
00071         frameExtract.MessageID = pBuffer[6];
00072         frameExtract.MessageID <<= 8u;
00073         frameExtract.MessageID |= pBuffer[7];
00074         frameExtract.MessageID <<= 8u;
00075         frameExtract.MessageID |= pBuffer[8];
00076         frameExtract.MessageID <<= 8u;
00077         frameExtract.MessageID |= pBuffer[9];
00078 
00079         if(10u > frameExtract.MessageLength)
00080         {
00081             frameExtract.nBytesNeeded = frameExtract.MessageLength - nBuffer;
00082             frameExtract.eStatus = LLRP_FRAME_ERROR;
00083         }
00084         else if(nBuffer >= frameExtract.MessageLength)
00085         {
00086             frameExtract.nBytesNeeded = 0;
00087             frameExtract.eStatus = LLRP_FRAME_READY;
00088         }
00089         else
00090         {
00091             frameExtract.nBytesNeeded = frameExtract.MessageLength - nBuffer;
00092             frameExtract.eStatus = LLRP_FRAME_NEED_MORE;
00093         }
00094     }
00095 
00096     return frameExtract;
00097 }


thingmagic_rfid
Author(s): Brian Bingham
autogenerated on Thu May 16 2019 03:01:23