/*
 * btcmd.h
 *
 *  Created on: 23 Apr 2015
 *      Author: john
 */



#ifndef BTCMD_H_
#define BTCMD_H_

#include <klog/klog.h>
#include <stdint.h>

class cBTCmd : public cKlog
{
	enum eMdm_response
	{
		MDM_OK,
		MDM_ERR,
		MDM_UNKOWN
	};


	pthread_mutex_t mWaitMutex;
	pthread_cond_t mWaitCond;
	pthread_mutex_t mBuffMutex;

	char* mCMD;
	char mTempStr[64];

protected:

	uint8_t mRxBuff[1024];
	uint8_t mRxLen;
	bool replied;
	int mTimeout;

	cBTCmd(const char * fmt,...);

	uint8_t* getCMD();

	virtual bool handleResponse(const char* response);

	void removeLF(char* string);

	void setCMD(char*);
	bool waitReply();

public:
	virtual ~cBTCmd();

	bool execute();
	void handleData(uint8_t* data, int len);
	int waitData(char* buff);

};

class cBTCmdGetConfig : public cBTCmd
{
	char mBuildVer[16];
	char mBDAddress[13];
	char mName[20];
	char mPIN[5];

	bool handleResponse(const char* response);
public:
	cBTCmdGetConfig();


	char* getBuild(){ return mBuildVer; };
	char* getAddress(){ return mBDAddress; };
	char* getName(){ return mName; };
	char* getPIN(){ return mPIN; };


};

class cBTCmdUpdateInquiryScan : public cBTCmd
{
public:
	cBTCmdUpdateInquiryScan(int mode,int duration,int interval);
protected:
	bool handleResponse(const char* response);
};

class cBTCmdSetName : public cBTCmd
{
	bool handleResponse(const char* response);
public:
	cBTCmdSetName(const char* name);
};

class cBTCmdSPPDisconnect : public cBTCmd
{
	bool handleResponse(const char* response);
public:
	cBTCmdSPPDisconnect();
};

class cBTCmdEnableBond : public cBTCmd
{
	bool handleResponse(const char* response);
public:
	cBTCmdEnableBond();
};

class cBTCmdDisableBond : public cBTCmd
{
	bool handleResponse(const char* response);
public:
	cBTCmdDisableBond();
};

class cBTCmdEraseBondTable : public cBTCmd
{
	bool handleResponse(const char* response);
public:
	cBTCmdEraseBondTable();
};


#endif /* BTCMD_H_ */
