bluetoothengine/headsetsimulator/profiles/hfpprofile/inc/dataprocessing/hfpcommand.h
author michal.sulewski
Wed, 15 Sep 2010 15:59:44 +0200
branchheadsetsimulator
changeset 60 90dbfc0435e3
permissions -rw-r--r--
source code commit

/* 
 *
 * Copyright (c) <2010> Comarch S.A. and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of the License "Eclipse Public License v1.0"
 * which accompanies this distribution, and is available
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
 *
 * Original Contributors:
 * Comarch S.A. - original contribution.
 *
 * Contributors:
 *
 * Description:
 *
 */

#ifndef HFPCOMMAND_H_
#define HFPCOMMAND_H_

#include <e32base.h>

/** Profile helpful constants */
_LIT8(KHsHFPCommandPrefix,"AT");
_LIT8(KHsHFPCommandSuffix,"\r\n");
_LIT8(KHsHFPBRSFCommand,"+BRSF");
_LIT8(KHsHFPCIEVCommand,"+CIEV");
_LIT8(KHsHFPCHUPCommand,"+CHUP");
_LIT8(KHsHFPCINDCommand,"+CIND");
_LIT8(KHsHFPCMERCommand,"+CMER");
_LIT8(KHsHFPCOPSCommand,"+COPS");
_LIT8(KHsHFPVGSCommand,"+VGS");
_LIT8(KHsHFPVGMCommand,"+VGM");
_LIT8(KHsHFPBLDNCommand,"+BLDN");
_LIT8(KHsHFPCLIPCommand,"+CLIP");
_LIT8(KHsHFPOKCommand,"\r\nOK\r\n");
_LIT8(KHsHFPERRORCommand,"\r\nERROR\r\n");
_LIT8(KHsHFPRINGCommand,"\r\nRING\r\n");
_LIT8(KHsHFPATACommand,"ATA");
_LIT8(KHsHFPATACommandWithoutPrefix,"A");
_LIT8(KHsHFPATDCommand,"ATD");
_LIT8(KHsHFPATDCommandWithoutPrefix,"D");
_LIT8(KHsHFPParamsSeparator,",");
_LIT8(KHsHFPCommandSeparator,"\r\n\r\n");
_LIT8(KHsHFPIndicatorParamsSeparator,"),");
_LIT8(KHsHFPATTestModeDes,"=?");
_LIT8(KHsHFPATWriteModeDes,"=");
_LIT8(KHsHFPATReadModeDes,"?");
_LIT8(KHsHFPATTestModeDesAG,"=?");
_LIT8(KHsHFPATWriteModeDesAG,": ");
_LIT8(KHsHFPATReadModeDesAG,"?");

/** Max size of HFP AT param */
const TInt KHsHFPMaxATParamSize = 256;

/** Max size of VGS or VGM param*/
const TInt KHsHFPMaxVolumeLevelParamSize = 2;

/**
 *  @brief Represents singular AT command parameter.
 */
class TATParam
    {
public:

    /**
     * Constructor
     * 
     * @param aValue param descriptor
     */
    TATParam(const TDesC8& aValue);

    /**
     * Returns the parameter as text.
     * 
     * @return the non-modifiable pointer descriptor
     */
    const TDesC8& Des() const;

    /**
     * Returns the paramater as integer value (if conversion is possible)
     * 
     * @return integer value
     */
    TInt IntL() const;

private:
    /** Buffer for AT param */
    TBuf8<KHsHFPMaxATParamSize> iValue;
    };

/** Array of AT params */
typedef RArray<TATParam> RATParamArray;

/** HFP AT commands types enum */
enum THsHFPCommandType
    {
    EHFPCmdBRSF,
    EHFPCmdCIEV,
    EHFPCmdCHUP,
    EHFPCmdOK,
    EHFPCmdERROR,
    EHFPCmdCIND,
    EHFPCmdCMER,
    EHFPCmdCOPS,
    EHFPCmdRING,
    EHFPCmdATA,
    EHFPCmdVGS,
    EHFPCmdVGM,
    EHFPCmdBLDN,
    EHFPCmdATD,
    EHFPCmdCLIP,
    EHFPCmdUnknown
    };

/** HFP AT commands modes enum */
enum THsHFPCommandMode
    {
    /** = */
    ECmdModeWrite,
    /** ? */
    ECmdModeRead,
    /** =? */
    ECmdModeTest,
    /** empty without params */
    ECmdModeNormal,
    /** empty with params */
    ECmdModeOther,
    /** unknown mode - default */
    ECmdUnknownMode
    };

/**
 *  @brief AT command representation 
 */
class CHsHFPCommand : public CBase
    {

public:

    /**
     * Two-phased constructor.
     * 
     * @return class instance
     */
    static CHsHFPCommand* NewL();

    /**
     * Two-phased constructor.
     * 
     * @return class instance
     */
    static CHsHFPCommand* NewLC();

    /** 
     * Destructor
     */
    ~CHsHFPCommand();

public:
    /**
     * Sets type of AT command
     * 
     * @param aType type
     * @return KErrNone if successful, otherwise one of the system-wide error codes
     */
    TInt SetType(const THsHFPCommandType aType);

    /**
     * Sets mode of AT command
     * 
     * @param aMode mode
     * @return KErrNone if successful, otherwise one of the system-wide error codes
     */
    TInt SetMode(const THsHFPCommandMode aMode);

    /**
     * Sets params of AT command
     * 
     * @param aParams array of params
     * @return KErrNone if successful, otherwise one of the system-wide error codes
     */
    TInt SetParams(const RATParamArray& aParams);

    /**
     * Sets flag which denotes if AT command was sent from AG or HF
     * 
     * @param aFromAG AT command source
     */
    void SetSource(const TBool aFromAG);

    /**
     * Returns the AT command as text
     * 
     * @param aBuf on exit contains command as descriptor
     */
    void ToDes8(TDes8& aBuf) const;

    /**
     * Returns the AT command type
     * 
     * @return type of command
     */
    THsHFPCommandType Type() const;

    /**
     * Returns the AT command mode
     * 
     * @return mode of command
     */
    THsHFPCommandMode Mode() const;

    /**
     * Returns the AT command source
     * 
     * @return flag that denotes if AT command was sent from AG or HF
     */
    TBool FromAG() const;

    /**
     * Returns the AT command params
     * 
     * @return array of params
     */
    const RATParamArray& Params() const;

    /**
     * Clones CHsHFPCommand object
     * 
     * @param aCmdFrom source
     * @param aCmdTo destination 
     */
    static void CopyL(const CHsHFPCommand& aCmdFrom, CHsHFPCommand& aCmdTo);

private:
    /**
     * Constructor for performing 1st stage construction
     */
    CHsHFPCommand();

    /**
     * Constructor for performing 2nd stage construction
     */
    void ConstructL();

private:

    /** Granulity of AT params array */
    const TInt KParamArrayGranularity = 3;

    /** Max length of AT type descriptor */
    const TInt KTypeDesMaxLength = 9;

    /** Max length of AT mode descriptor */
    const TInt KModeDesMaxLength = 3;

    /** Max length of AT param descriptor */
    const TInt KParamsDesMaxLength = 200;

    /** Command type */
    THsHFPCommandType iType;

    /** Command mode */
    THsHFPCommandMode iMode;

    /** Denotes if AT command was sent from AG or HF */
    TBool iFromAG;

    /** Array of params */
    RATParamArray iParams;

    /** Command type as descriptor */
    RBuf8 iTypeDes;

    /** Command mode as descriptor */
    RBuf8 iModeDes;

    /** Command params as descriptor */
    RBuf8 iParamsDes;
    };

#endif /* HFPCOMMAND_H_ */