diff -r a2efdd544abf -r b47902b73a93 datasourcemodules/bluetoothgpspositioningmodule/btgpspsy/src/Utils/BTGPSNmeaBuffer.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/datasourcemodules/bluetoothgpspositioningmodule/btgpspsy/src/Utils/BTGPSNmeaBuffer.cpp Fri Jun 04 10:34:15 2010 +0100 @@ -0,0 +1,196 @@ +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + + + +// INCLUDE FILES +#include "BTGPSNmeaBuffer.h" +#include "BTGPSMessageDef.h" +#include "BTGPSPanic.h" + +// EXTERNAL DATA STRUCTURES + +// EXTERNAL FUNCTION PROTOTYPES + +// CONSTANTS + +// Granularity + +// MACROS + +// LOCAL CONSTANTS AND MACROS + +// MODULE DATA STRUCTURES + +// LOCAL FUNCTION PROTOTYPES + +// FORWARD DECLARATIONS + +// ============================= LOCAL FUNCTIONS =============================== + +// ============================ MEMBER FUNCTIONS =============================== + + +// ----------------------------------------------------------------------------- +// CBTGPSNmeaBuffer::NewL +// ----------------------------------------------------------------------------- +CBTGPSNmeaBuffer* CBTGPSNmeaBuffer::NewL(TInt aSize) + { + CBTGPSNmeaBuffer* self = new (ELeave) CBTGPSNmeaBuffer(); + CleanupStack::PushL(self); + self->ConstructL(aSize); + CleanupStack::Pop(); + return self; + } + +// ----------------------------------------------------------------------------- +// CBTGPSNmeaBuffer::~CBTGPSNmeaBuffer +// ----------------------------------------------------------------------------- +CBTGPSNmeaBuffer::~CBTGPSNmeaBuffer() + { + delete iBuffer; + } + +// ----------------------------------------------------------------------------- +// CBTGPSNmeaBuffer::ConstructL +// ----------------------------------------------------------------------------- +void CBTGPSNmeaBuffer::ConstructL(TInt aSize) + { + iBuffer = (TUint8*)User::AllocZL(aSize); + iSize = aSize; + } + +// ----------------------------------------------------------------------------- +// CBTGPSNmeaBuffer::CBTGPSNmeaBuffer +// C++ default constructor can NOT contain any code, that +// might leave. +// ----------------------------------------------------------------------------- +CBTGPSNmeaBuffer::CBTGPSNmeaBuffer() + { + } + +// ----------------------------------------------------------------------------- +// CBTGPSNmeaBuffer::ResetBuffer +// ----------------------------------------------------------------------------- +void CBTGPSNmeaBuffer::ResetBuffer() + { + Mem::FillZ(iBuffer,iSize); + iBottom = 0; + } + +// ----------------------------------------------------------------------------- +// CBTGPSNmeaBuffer::CurrentIndex +// ----------------------------------------------------------------------------- +TInt CBTGPSNmeaBuffer::CurrentIndex() const + { + return iBottom; + } + +// ----------------------------------------------------------------------------- +// CBTGPSNmeaBuffer::AddSentences +// ----------------------------------------------------------------------------- +void CBTGPSNmeaBuffer::AddSentences(const TDesC8& aNmea) + { + TPtrC8 srcDes(aNmea); + TInt srcLen = srcDes.Length(); + + while(srcLen>0) + { + TInt maxSize = iSize-iBottom; + TPtr8 ptr(iBuffer+iBottom, maxSize); + TInt cpLen = Min(maxSize,srcLen); + ptr.Copy(srcDes.Left(cpLen)); + iBottom = (iBottom+cpLen)%iSize; + srcDes.Set(srcDes.Right(srcLen-cpLen)); + srcLen = srcDes.Length(); + } + } + +// ----------------------------------------------------------------------------- +// CBTGPSNmeaBuffer::ReadSentences +// ----------------------------------------------------------------------------- +TInt CBTGPSNmeaBuffer::ReadSentences( + TDes8& aDest, + TInt& aBeginning) const + { + __ASSERT_DEBUG(aBeginning