#pragma once

#include "TCPClient.h"

class CRedRatProcess: public CTCPClient
{
public:
	CRedRatProcess(void);
	~CRedRatProcess(void);

protected:
	bool checkEOM(std::string& data);

private:
	// 只能运行一个红老鼠进程;
	static DWORD m_dwCurAppId;
	std::string m_strCurDevice;
	std::string m_strCurDataset;
	std::vector<std::string> m_vtDevices;
	std::vector<std::string> m_vtDataset;
	std::vector<std::string> m_vtSignals;

	// 外部程序接口;
public:
	static bool StartApp(LPCTSTR lpAppDir, LPCTSTR lpSignalXml, DWORD dwPort = 40000);
	static DWORD IsAppRunning(LPCTSTR lpszAppDir);
	static bool CloseApp(DWORD dwAppId = 0);
	static DWORD GetProcessId(std::string strApp = "RedRatHubCmd.exe");

	// 红老鼠接口;
public:
	// 获取设备列表;
	bool getDeviceNameList();
	bool getDeviceNameList(std::vector<std::string>& vtDevice);
	// 设置信号数据集;
	void SelectDataset(std::string dataset) { m_strCurDataset = dataset; }
	// 获取数据集列表;
	bool getDatasetNameList();
	bool getDatasetNameList(std::vector<std::string>& vtDataset);
	// 加载信号数据集xml文件,将会删除以前所有加载过的xml文件;
	bool loadSignalDataSet(std::string file);
	// 添加信号数据集xml文件, 相同数据集名称的将会被覆盖
	bool addSignalDataSet(std::string file);
	// 获取指定数据集信号名称;
	//bool getSignalsName(std::string dataset = "");
	bool getSignalsName(std::vector<std::string>& vtSignals, std::string dataset = "");
	std::string getSignalsName(std::string dataset = "");
	// 发送单个信号;
	bool sendSignal(std::string signal, int send_times = 1, int sleep_time = 1000);
	// 发送多个信号;
	bool sendSignals(const char(*signals)[10], int nCount, int sleep_time = 1000);
	bool sendSignals(std::string signals[], int nCount, int sleep_time = 1000);
	bool sendSignals(std::vector<std::string>& vtSignals, int sleep_time = 1000);
	// 重复发送;
	bool sendRepeatsSignal(std::string signal, int repeat_time = 2);
	bool sendDurationSignal(std::string signal, int duration_time = 1000);
	bool sendBothSignal(std::string signal, int repeat_time = 2, int duration_time = 1000);
};
