datasourcemodules/bluetoothgpspositioningmodule/btgpspsy/inc/BTGPSFix.h
changeset 36 b47902b73a93
parent 0 9cfd9a3ee49c
equal deleted inserted replaced
35:a2efdd544abf 36:b47902b73a93
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef BTGPSFIX_H
       
    22 #define BTGPSFIX_H
       
    23 
       
    24 //  INCLUDES
       
    25 
       
    26 #include <lbsposition.h>
       
    27 #include <lbs.h>
       
    28 #include <e32std.h>
       
    29 #include "BTGPSMessageDef.h"
       
    30 
       
    31 // CONSTANTS
       
    32 
       
    33 //The maximum number of satellites the GPS can track at once
       
    34 static const TInt KMaxNumberOfSatellites = 12;
       
    35 
       
    36 //The maximum number of GSV sentence that specified in NMEA spec
       
    37 const TInt KMaxGSVMessageNumber = 9;
       
    38 
       
    39 //The maximum length of GSV sentence
       
    40 const TInt KMaxGSVLength = 82;
       
    41 
       
    42 // MACROS
       
    43 
       
    44 // DATA TYPES
       
    45 
       
    46 // FUNCTION PROTOTYPES
       
    47 
       
    48 // FORWARD DECLARATIONS
       
    49 class TBTGPSNmeaParser;
       
    50 class CBTGPSNmeaBuffer;
       
    51 
       
    52 // CLASS DECLARATION
       
    53 
       
    54 /**
       
    55 *  Class for parsing NMEA sentences and storing the information about the fix.
       
    56 *  Parsing:
       
    57 *       - If lexition parsing failed, the whole NMEA sentence is ignored
       
    58 *       - NULL field is acceptable for any field, even explicitly specified in
       
    59 *         NMEA spec that can't be NULL
       
    60 *       - Only all RMC, GGA, GSA sentence are received, then the fix information
       
    61 *         is valid. 
       
    62 *       - GSV recieved time is stored for checking GSV validity
       
    63 *
       
    64 */
       
    65 class CBTGPSFix : public CBase
       
    66     {
       
    67 
       
    68     public:
       
    69 
       
    70         /**
       
    71         *Enumerate the status of fix parsing. The value is used when a NMEA sentence
       
    72 		*is parsed by this class.
       
    73         */
       
    74         enum TParsingStatus
       
    75             {
       
    76             EInvalid,       ///The NMEA sentence is invalid
       
    77             EInfoUpdated,   ///The NMEA sentence is valid and information updated
       
    78             EUnkown         ///The NMEA sentence is not supported by parser
       
    79             };
       
    80         
       
    81         /**
       
    82         *Enumerate the different qualities of fix. This information is specified
       
    83         *in GSA sentence
       
    84         */
       
    85         enum TState
       
    86             {
       
    87             EFixValidityUnkown, ///No GSA sentence received.
       
    88             EFixNotValid,       ///Not a valid fix.
       
    89             EFixValid2D,        ///2D fix made
       
    90             EFixValid3D         ///3D fix made
       
    91             };
       
    92 
       
    93     public:  // Constructors and destructor
       
    94         /**
       
    95         * Constructor.
       
    96         */
       
    97         CBTGPSFix();
       
    98         
       
    99         /**
       
   100         * Set NMEA Buffer
       
   101         */
       
   102         void SetNmeaBuffer(CBTGPSNmeaBuffer* aNmeaBuffer);
       
   103 
       
   104     public:  // New functions
       
   105 
       
   106         /**
       
   107         * Resets the all fix parameters.
       
   108         */
       
   109         void Reset();
       
   110         
       
   111         /**
       
   112         * Reset fix parameter except setellites in view information(GSV information)
       
   113         */
       
   114         void ResetFix();
       
   115         
       
   116         /**
       
   117         * Reset GSV time
       
   118         */
       
   119         void ResetGSVTime();
       
   120 
       
   121         /**
       
   122         * Parse message.
       
   123 		* @param aMsg Received message.
       
   124 		* @return Parsing status as specified in CBTGPSFix::TParsingStatus.
       
   125         */
       
   126         TParsingStatus ParseMessage(const TBTGPSNmeaParser& aParser);
       
   127         
       
   128         /**
       
   129         * Get fix state(not valid, 2d fix or 3d fix)
       
   130 		* @return Fix state as specified in CBTGPSFix::TState
       
   131         */
       
   132         TState FixState() const;
       
   133         
       
   134         /**
       
   135         * Check if fix is valid
       
   136 		* @return Return ETrue if fix is valid
       
   137         */
       
   138         TBool IsFixValid() const;
       
   139                 
       
   140         /**
       
   141         * Check if full NMEA message pattern received. 
       
   142 		* @return Return ETrue if GSA, RMC and GGA are received.
       
   143         */
       
   144         TBool IfFullNmeaPatternReceived() const;
       
   145         
       
   146         /**
       
   147         * Get fix time. Fix time is updated when new latitude and
       
   148 		* longitude are received.
       
   149 		* @return Fix received time.
       
   150         */
       
   151         TTime FixTime() const;
       
   152         
       
   153         /**
       
   154         * Get GSV time
       
   155 		* @return Return GSV sentence received time.
       
   156         */
       
   157         TTime GsvTime() const;
       
   158         
       
   159         /**
       
   160         * Fill fix into to TPositionInfo. Non-leave function.
       
   161         */
       
   162         TInt FillPositionInfo(
       
   163             TPositionInfoBase& aPosInfo,
       
   164             TInt* aNmeaIndex = NULL) const;
       
   165                     
       
   166         /**
       
   167         * Fill fix info to TPositionInfo.
       
   168         * If fix is not available, then aPosInfo will be emptied.
       
   169 		* @param aPosInfo The TPositionInfo object to fill the fix info
       
   170 		* @param aNmeaIndex The pointer to the index where last time
       
   171 		* NMEA message is retruned to client. On return this value
       
   172 		* is updated to the current bottom of the NMEA buffer;
       
   173         */
       
   174         void FillPositionInfoL(
       
   175             TPositionInfoBase& aPosInfo,
       
   176             TInt* aNmeaIndex = NULL) const;
       
   177             
       
   178             
       
   179         /**
       
   180         * Validate the NMEA buffer index. Client shall keep the 
       
   181         * index in the FIFO circulate NMEA buffer, which indicate
       
   182         * the position when last time. This function will validate
       
   183         * the index. If the buffer round back, then the index is 
       
   184         * invalidated. Next time client will receive the whole 
       
   185         * buffer. Note: This function shall be called before
       
   186         * FillPositionInfoL(). 
       
   187         * @param aNmeaIndex The NMEA buffer index.
       
   188         * @param aBottom Last time the client saw the bottom.
       
   189         */
       
   190         void ValidateNmeaBufferIndex(
       
   191             TInt& aNmeaIndex,
       
   192             TInt& aBottom) const;
       
   193         
       
   194         /**
       
   195         * Copy content of this
       
   196 		* @param aFix the fix info that will be copied.
       
   197         */
       
   198         void operator =(const CBTGPSFix& aFix);
       
   199 
       
   200     private:  // Enumeration
       
   201 
       
   202 		/**
       
   203         * Internal data class for satellite info
       
   204         */
       
   205         struct TSatelliteInfo
       
   206             {
       
   207             TInt iSatelliteId;
       
   208             TReal32 iElevation;
       
   209             TReal32 iAzimuth;
       
   210             TInt iSNR;
       
   211             };
       
   212     
       
   213         /**
       
   214         * GPS working mode
       
   215         */
       
   216         enum TGPSMode
       
   217             {
       
   218             EGpsModeSatellite=0, //GSP is using satellite to get fix
       
   219             EGpsModeEstimated,   //dead reckoning
       
   220             EGpsModeManualInput,
       
   221             EGpsModeSimulator,
       
   222             EGpsModeInvalid      //The fix is not valid
       
   223             };
       
   224             
       
   225         /**
       
   226         * GPS Quality Indicator
       
   227         */
       
   228         enum TGPSQuality
       
   229             {
       
   230             EGpsQualityNotValid = 0,
       
   231             EGpsQualitySPS      = 1,
       
   232             EGpsQualityDGPS     = 2,
       
   233             EGpsQualityPPS      = 3,
       
   234             EGpsQualityRTK      = 4,
       
   235             EGpsQualityFloatRTK = 5,
       
   236             EGpsQualityEstimated    = 6,
       
   237             EGpsQualityManualInput  = 7,
       
   238             EGpsQualitySimulation   = 8
       
   239             };
       
   240             
       
   241     private:  // New functions
       
   242         /**
       
   243         * Reset position parameters
       
   244         */
       
   245         void ResetPosition();
       
   246         
       
   247         /**
       
   248         * Parse message
       
   249         */
       
   250         void ParseMessageL(const TBTGPSNmeaParser& aParser);
       
   251 
       
   252 
       
   253         /**
       
   254         * Parse NMEA GGA Sentence
       
   255         */
       
   256         void ParseGGASentenceL(
       
   257             const TBTGPSNmeaParser& aParser);
       
   258         
       
   259         /**
       
   260         * Parse NMEA GSV Sentence
       
   261         */
       
   262         void ParseGSVSentenceL(
       
   263             const TBTGPSNmeaParser& aParser);
       
   264         
       
   265         /**
       
   266         * Parse NMEA GSA Sentence
       
   267         */
       
   268         void ParseGSASentenceL(
       
   269             const TBTGPSNmeaParser& aParser);
       
   270         
       
   271         /**
       
   272         * Parse NMEA RMC Sentence
       
   273         */
       
   274         void ParseRMCSentenceL(
       
   275             const TBTGPSNmeaParser& aParser);
       
   276 
       
   277         /**
       
   278         * Get latitude and longitude
       
   279         */
       
   280         void GetLatitudeLongitude(
       
   281             const TBTGPSNmeaParser& aParser,
       
   282             TInt aStartId);
       
   283             
       
   284         /**
       
   285         * Parses the degree information from the NMEA command 
       
   286         * (degrees and minutes) to
       
   287         * true degrees.
       
   288         * @return Error code
       
   289         */
       
   290         TInt GetDegrees(
       
   291             const TDesC8& aSide,
       
   292             const TDesC8& aDegreesMinutes,
       
   293             TReal64& aDegrees);
       
   294 
       
   295         /**
       
   296         * Appends the satellite data to the fix and quarantees 
       
   297         * that only KMaxNumberOfSatellites
       
   298         * are added.
       
   299         */
       
   300         void AppendSatelliteData(TSatelliteInfo& aSatInfo);
       
   301         
       
   302         /**
       
   303         * Extract satellite info from message parser
       
   304         */
       
   305         void ExtractSatInfoL(const TBTGPSNmeaParser& aParser);
       
   306         
       
   307         /**
       
   308         * Extracts the satellite data from a NMEA message and 
       
   309         * updates internal data variables.
       
   310         */
       
   311         void ExtractSatelliteDataL(
       
   312             const TBTGPSNmeaParser& aMessage,
       
   313             TInt aField1,
       
   314             TInt aField2,
       
   315             TInt aField3,
       
   316             TInt aField4);
       
   317 
       
   318         /**
       
   319         * Is used to copy the NMEA message and prevent panic if the 
       
   320         * NMEA message is too long.
       
   321         */
       
   322         TBool SecureCopy(TDes8& aTo,const TDesC8& aFrom);
       
   323 
       
   324     private: 
       
   325         /**
       
   326         * Defines the mask of received message
       
   327         */
       
   328         enum TReceivedMessage
       
   329             {
       
   330             EReceivedGSA = 0x01,
       
   331             EReceivedGGA = 0x02,
       
   332             EReceivedRMC = 0x04
       
   333             };
       
   334         
       
   335     private:    // Data
       
   336         //Current Fix data
       
   337         
       
   338         //Latitude, defaults to WGS-84 format.
       
   339         TReal64 iLatitude;
       
   340 
       
   341         //Longitude, defaults to WGS-84 format.
       
   342         TReal64 iLongitude;
       
   343 
       
   344         //Altitude, defaults to WGS-84 format.
       
   345         TReal32 iAltitude;
       
   346 
       
   347         //The timestamp of the fix
       
   348         TTime iTime;
       
   349 
       
   350         //Speed, defaults to WGS-84 format
       
   351         TReal32 iSpeed;
       
   352 
       
   353         //Heading, defaults to WGS-84 format
       
   354         TReal32 iHeading;
       
   355 
       
   356         //Number of satellites seen
       
   357         TInt iNumberOfSatellites;
       
   358 
       
   359         //Array of satellites
       
   360         TFixedArray<TSatelliteInfo,KMaxNumberOfSatellites> iSatelliteArray;
       
   361 
       
   362         //Satellites used in location calculation
       
   363         TInt iSatellitesUsed;
       
   364 
       
   365         //Array of used satellites
       
   366         TFixedArray<TInt,KMaxNumberOfSatellites> iUsedSatellitesArray;
       
   367 
       
   368         //Time received from satellites
       
   369        	TTime iSatelliteTime;
       
   370 
       
   371         //Horizontal dilution of precision
       
   372         TReal32 iHorizontalDoP;
       
   373 
       
   374         //Vertical dilution of precision
       
   375         TReal32 iVerticalDoP;
       
   376         
       
   377         //2D dilution of precision
       
   378         TReal32 iPositionDoP;
       
   379         
       
   380         //Geoidal Seperation
       
   381         TReal32 iGeoidalSeperation;
       
   382         
       
   383         // The fix validity
       
   384         TState iValid;
       
   385 
       
   386         //GPS Quality Indicator specified in GGA
       
   387         TGPSMode iGpsMode;
       
   388 
       
   389         //Received message mask
       
   390         TUint32 iReceivedMsgMask;
       
   391         
       
   392         //GSV sentence cache
       
   393         TBuf8<KMaxGSVLength> iNMEAGSVCache[KMaxGSVMessageNumber];
       
   394         
       
   395         //GSV total number of message
       
   396         TInt iGsvTotalNumberOfMessage;
       
   397         
       
   398         //GSV satellites in view
       
   399         TInt iGsvSatelliteInView;
       
   400         
       
   401         //The time that GSV sentences are fully retrieved.
       
   402         TTime iGsvTime;
       
   403         
       
   404         //NMEA Buffer. Not owned by this class
       
   405         CBTGPSNmeaBuffer* iNmeaBuffer;
       
   406         
       
   407     };
       
   408     
       
   409 #endif 
       
   410 // End of File