#ifndef CLASERDRIVER_SP_H
#define CLASERDRIVER_SP_H
#include "claserdriver_base.h"

class LASER_DRIVER_IMPL_EXPORT CLaserDriver_SP : public CLaserDriver_Base
{
public:
    enum msg_id
    {
        SETEPULSEFREQ=MAX_LASERDRIVER_MSG_ID,
		GETEPULSEFREQ,
		GETSTATE,
		GETINNERPOWER,
		SETINNERGATE,
		INITINISHED,
        MAX_LASERDRIVER_SP_MSG_ID,
    };
    CLaserDriver_SP(const QString& name,int32_t id);


	virtual int SetLDD(int32_t laserid, bool_t bOn);

	virtual int SetCurrent_Ref(int32_t laserid, double dCurrent);
	virtual int GetCurrent_Cur(int32_t laserid);

	virtual void do_msg(int iID,QVariantList& vlInput,V_MsgOutput* pvlOutput);


	virtual int GetDiodTemp(int32_t laserid);

	virtual int GetInnerPower();


	virtual int GetLaserTime(int32_t laserid) override;

	// CDriverCard interface
public:
    virtual int32_t init_driver() override;
    virtual int32_t exit_driver() override;
    void SendCommand(const char *pCommand, char *pResponse);
private:
	void PacketCommand(const char* pCommand, int& srcSize, char* pPacketCommand);
    // CLaserDriver interface
	bool m_bConnected;
public:
    virtual int SetFreq(int32_t laserid, float64_t dFreq) override;
    virtual int GetFreq(int32_t laserid) override;
    virtual int OpenLaserGate(int32_t laserid, bool bOpen) override;
    virtual int SetPowerRate(int32_t laserid, float64_t dpower) override;
    virtual int GetPowerRate(int32_t laserid) override;
    virtual int SetGateSource(int32_t laserid, bool_t bExt) override;

	virtual int SetInnerGate(int laserId, bool bOpen) override;
public:
	int SetEpulseFreq(int32_t laserid, int frequency) override;
	int GetEpulseFreq(int32_t laserid, int& frequency) override;
	int GetState();


	bool ReadWarmupTime(int& timeSeconds);
	bool ReadThgTime(double& dCurThgUserHours);
	bool ReadAllThgTime(double& dAllThgUseHousrs);
	
	inline bool IsBitOn(uint state, uint location) {return (state & 1UL << location);}


private:
	bool CheckResponse(char *pResponse);
};

#endif // CLASERDRIVER_SP_H
