#pragma once

#include "bombax.h"

#include "..\pilelibs\includes\plccomm\plccomm.h"

#define TD_SUCCESS   0
#define TD_FAILED    1
#define TD_NOCHECK   -1


//电批类型
#define TD_UNK    -1
#define TD_SSW     0
#define TD_YAKO    1

#define TD_ERR_DESC_LEN  128
//
//typedef struct __td_driver_work_opts_
//{
//	int   mode ;      // 拧紧模式 ，暂时未用
//	int   clockwise;  // 拧紧方向 ， 暂时未使用
//
//	float tightRounds1;  //拧紧圈数1
//	float tightSpeed1;   //拧紧速度1
//	float tightRounds2;  //拧紧圈数2
//	float tightSpeed2;   //拧紧速度2
//	float tightRounds3;  //拧紧圈数3
//	float tightSpeed3;   //拧紧速度3
//
//	float freeRounds;   //免检圈数
//	float fakeThres;    //浮高界定，圈数
//	float slipThres;    //滑牙界定，圈数
//	int   holdDura;     //扭力保持时间， 毫秒
//	float targetForce;  //目标扭力，公斤
//	float forceToler;   //扭力补偿， 公斤
//	BOOL  bCheckFake;   //启动浮高滑牙检测
//}TD_DRIVER_WORK_OPTS;


//typedef struct __td_driver_work_results_
//{
//	 int   taskNum;   //任务号
//	 float distance;  //行程
//	 float _maxTorque; //最大扭力
//	 int duration;  //动作所花时间
//	 int result;    //结果
//	 int alarm;     //报警
//	 char strAlarmDesc[TD_ERR_DESC_LEN +1] ;// 报警描述
//}TD_DRIVER_WORK_RESULTS;

#define WM_TD_WORK_REPORT  (WM_USER + 1024)

class BOMBAX_API CToolDriver
{
public:
	CToolDriver(void);
	virtual ~CToolDriver(void);

 
	enum TD_MOVE_TYPE{
		TDM_UNK=-1,
		TDM_SCREW=0,
		TDM_UNSCREW,
		TDM_FREE,
	};

	enum TD_STOP_MODE{
	     TD_SM_DEFAULT=0, //默认
	     TD_SM_TORQUE=1, //力矩
		 TD_SM_ROUND ,    //圈数
		 TD_SM_ANY,      //力矩或圈数
		 TD_SM_BOTH,     //力矩和圈数
	};

	//串口
	virtual BOOL Connect(int portIndex, int stopMode, BOOL bAutoRecept = TRUE, JP_COMM_OPTIONS* pCommOpts =NULL ){return FALSE;};
	virtual void Disconnect(){;};
	BOOL   IsConnected(){ return m_bDriverConnected; };

	//拧紧
	virtual BOOL Start (BOOL bClockWise)=0;
	virtual BOOL Stop ()=0;

	//自由转动
	virtual BOOL StartFreeRun( BOOL bClockWise)=0;
	virtual BOOL StopFreeRun()=0;

	virtual const char* GetRunState(int state) =0;
	virtual const char* GetAlarmState(int state) = 0;

	//检查是否完成
	virtual BOOL CheckFinished(int state)=0;

	BOOL   IsRunning(){ return m_bRunning; };

	int   GetRunType(){ return m_nRunType; };

	int GetDriverType(){ return m_nDriverType; };

	//刷新参数
	virtual BOOL  Flush(void* pParams, int size){ return FALSE; };
	virtual BOOL  Read(void* pParams, int size){ return FALSE; };



	virtual BOOL  GetResult(void* pResultBuffer, int bufferSize){ return FALSE; };

public:
	//TD_DRIVER_WORK_OPTS* m_pDriveWorkOpts;
	HWND   m_hNotifyWnd;

protected :
	BOOL m_bDriverConnected;
	BOOL m_bRunning;
	int  m_nRunType; 

	int  m_nDriverType;
};

