#pragma once
//#pragma warning(disable:4251)
#include <vector>
#include <mutex>
#include "string.h"
#include"CRS232.h"

#ifdef LAMP_EXPORTS
#define LAMP_DLL_API __declspec(dllexport)
#else
#define LAMP_DLL_API //__declspec(dllimport)
#endif

typedef struct _LIGHT_STRUCT
{
	int ChannelIndex;
	int LightValue;
}LIGHT_STRUCT;

//�豸����
enum Lamp_Ctltype { LAMP_CST = 1 , LIGTH_HONGREN};

#define LIGTH_BASE_ERROR (SERIAL_PORT_BASE_ERROR+10000)
typedef enum
{
	DEVICE_BASE_FAIL = LIGTH_BASE_ERROR,
	LIGTH_TYPE_FAIL,
	//RTU_ERR_ORDER,
	//RTU_ERR_ADDR,
	//RTU_ERR_DATA,
	//RTU_ERR_CONN,
	//RTU_ERR_WRITE,
	//RTU_ERR_READ_NULL,
	//RTU_ERR_RECV,
	//RTU_ERR_PARITY,
	COM_PORT_FAIL,
} LIGTHERR;

class LAMP_DLL_API ILamp
{
public:
	typedef struct _LIGHT_STRUCT
	{
		string addrs;
		ILamp* pLigth;
	}ILAMP_LST;

protected:
	bool m_bIsInitSuccess;
	Lamp_Ctltype m_iLightType; //�豸����
	string m_strLightName;

	bool    m_bEnable;               //�ƹ��������ֹ/����

	ILamp(Lamp_Ctltype iLightType,string strLightName);
	~ILamp();
public:
	// ��ȡ��ʵ������
	static long GetInstance(const char* ipAddress, Lamp_Ctltype iLigthType, ILamp **ligth);

	virtual string GetErrText(long errid);

	virtual long Init(unsigned long iPort); //��ʼ��
	virtual long Init(const char* ipAddress); //��ʼ��

	virtual void UnInit() = 0;//�ر�

	bool IsInitSuccess() { return m_bIsInitSuccess; };

public:
	virtual long SetLight(std::vector<LIGHT_STRUCT> vecLight, unsigned char iMaxSendNum = 3) = 0;
	virtual long SetLight(int ChannelIndex, int LightValue, unsigned char iMaxSendNum = 3) = 0; 
	virtual long GetLight(int ChannelIndex,int &LightValue, unsigned char iMaxSendNum = 3) = 0; 


private:
	static std::mutex m_Mutex;
	static std::vector<ILamp::ILAMP_LST> m_vecLamp;

	static ILamp* GetLamp(string addrs);
};