bluetoothengine/headsetsimulator/profiles/hspprofile/inc/dataprocessing/hspcommand.h
branchheadsetsimulator
changeset 60 90dbfc0435e3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bluetoothengine/headsetsimulator/profiles/hspprofile/inc/dataprocessing/hspcommand.h	Wed Sep 15 15:59:44 2010 +0200
@@ -0,0 +1,247 @@
+/* 
+ *
+ * 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 HSPCOMMAND_H_
+#define HSPCOMMAND_H_
+
+#include <e32base.h>
+
+/** Helpful constants */
+_LIT8(KHsHSPCommandPrefix,"AT");
+_LIT8(KHsHSPCommandSuffix,"\r\n");
+_LIT8(KHsHSPVGSCommand,"+VGS");
+_LIT8(KHsHSPVGMCommand,"+VGM");
+_LIT8(KHsHSPCKPDCommand,"+CKPD");
+_LIT8(KHsHSPOKCommand,"\r\nOK\r\n");
+_LIT8(KHsHSPERRORCommand,"\r\nERROR\r\n");
+_LIT8(KHsHSPRINGCommand,"\r\nRING\r\n");
+_LIT8(KHsHSPParamsSeparator,",");
+_LIT8(KHsHSPIndicatorParamsSeparator,"),");
+_LIT8(KHsHSPCommandSeparator,"\r\n\r\n");
+_LIT8(KHsHSPATTestModeDes,"=?");
+_LIT8(KHsHSPATWriteModeDes,"=");
+_LIT8(KHsHSPATReadModeDes,"?");
+_LIT8(KHsHSPATTestModeDesAG,"=?");
+_LIT8(KHsHSPATWriteModeDesAG,": ");
+_LIT8(KHsHSPATReadModeDesAG,"?");
+
+/** Max size of AT command's param */
+const TInt KHsHSPMaxATParamSize = 256;
+
+/**
+ * @brief TATParam represents singular AT command parameter.
+ */
+class TATParam
+{
+public:
+
+    /**
+     * Constructor
+     * 
+     * @param aValue 8-bit 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. If conversion is impossible then leave occures
+     */
+    TInt IntL() const;
+
+private:
+
+    /** Buffer for AT param */
+    TBuf8 <KHsHSPMaxATParamSize> iValue;
+};
+
+/** Array of AT params */
+typedef RArray <TATParam> RATParamArray;
+
+/** HSP's supported commands */
+enum THsHSPCommandType
+{
+    /** <cr><lf> OK <cr><lf> */
+    EHSPCmdOK,
+    /** <cr><lf> ERROR <cr><lf> */
+    EHSPCmdERROR,
+    /** <cr><lf> RING <cr><lf> */
+    EHSPCmdRING,
+    /** +VGS */
+    EHSPCmdVGS,
+    /** +VGM */
+    EHSPCmdVGM,
+    /** +CKPD */
+    EHSPCmdCKPD,
+    /** Other (unsupported) command */
+    EHSPCmdUnknown
+};
+
+/** AT command's mode */
+enum THsHSPCommandMode
+{
+    /** = */
+    ECmdModeWrite,
+    /** ? */
+    ECmdModeRead,
+    /** =? */
+    ECmdModeTest,
+    /** empty without params */
+    ECmdModeNormal,
+    /** empty with params */
+    ECmdModeOther,
+
+    ECmdUnknownMode
+};
+
+/**
+ *  @brief AT command representation 
+ */
+class CHsHSPCommand : public CBase
+{
+
+public:
+
+    /**
+     * Two-phased constructor.
+     * 
+     * @return class instance
+     */
+    static CHsHSPCommand* NewL();
+
+    /**
+     * Two-phased constructor.
+     * 
+     * @return class instance
+     */
+    static CHsHSPCommand* NewLC();
+
+    /** 
+     * Destructor
+     */
+    ~CHsHSPCommand();
+
+public:
+
+    /** Sets command's type 
+     * 
+     * @param aType type
+     * @return error code
+     */
+    TInt SetType( const THsHSPCommandType aType );
+
+    /** Sets command's mode
+     * 
+     * @param aMode  mode
+     * @return error code
+     */
+    TInt SetMode( const THsHSPCommandMode aMode );
+
+    /** Sets command's params 
+     * 
+     * @param aParams array of params
+     * @return error code
+     */
+    TInt SetParams( const RATParamArray& aParams );
+
+    /** Sets command's source
+     * 
+     * @param aFromAG denotes if command sent by AG
+     */
+    void SetSource( const TBool aFromAG );
+
+    /**
+     * Returns command as a 8-bit descriptor
+     * 
+     * @param aBuf buffer
+     */
+    void ToDes8( TDes8& aBuf ) const;
+
+    /** Getter for command's type */
+    THsHSPCommandType Type() const;
+
+    /** Getter for command's mode */
+    THsHSPCommandMode Mode() const;
+
+    /** Getter for command's source - denotes if sent by AG */
+    TBool FromAG() const;
+
+    /** Getter for command's array of params */
+    const RATParamArray Params() const;
+
+    /**
+     * Clones CHsHSPCommand object
+     * 
+     * @param aCmdFrom source
+     * @param aCmdTo destination 
+     */
+    static void CopyL( const CHsHSPCommand* aCmdFrom, CHsHSPCommand& aCmdTo );
+
+private:
+    /**
+     * Constructor for performing 1st stage construction
+     */
+    CHsHSPCommand();
+
+    /**
+     * Constructor for performing 2nd stage construction
+     */
+    void ConstructL();
+
+private:
+
+    /** Param array's granularity */
+    const TInt KParamArrayGranularity = 3;
+
+    /** Max length of command's type represented as descriptor */
+    const TInt KTypeDesMaxLength = 9;
+
+    /** Max length of command's mode represented as descriptor */
+    const TInt KModeDesMaxLength = 3;
+
+    /** Max length of command's params represented as descriptor */
+    const TInt KParamsDesMaxLength = 200;
+
+    /** Command's type */
+    THsHSPCommandType iType;
+
+    /** Command's mode */
+    THsHSPCommandMode iMode;
+
+    /** Command's source. Denotes if command was sent from AG */
+    TBool iFromAG;
+
+    /** Command's params */
+    RATParamArray iParams;
+
+    /** Command's type as a descriptor */
+    RBuf8 iTypeDes;
+
+    /** Command's mode as a descriptor */
+    RBuf8 iModeDes;
+
+    /** Command's params as a descriptor */
+    RBuf8 iParamsDes;
+};
+
+#endif /* HSPCOMMAND_H_ */