Browse Source

完成基本功能。

sat23 4 years ago
parent
commit
eacaa8a847
3 changed files with 701 additions and 108 deletions
  1. 116 73
      Serail-Demo/Demo/Demo.cpp
  2. 478 7
      Serail-Demo/Demo/TCLCommand.cpp
  3. 107 28
      Serail-Demo/Demo/TCLCommand.h

+ 116 - 73
Serail-Demo/Demo/Demo.cpp

@@ -16,22 +16,35 @@ CWinApp theApp;
 
 using namespace std;
 
+void test();
+void test1();
+
 int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
 {
-	int nRetCode = 0;
-
-	// 初始化 MFC 并在失败时显示错误
-	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
-	{
-		// TODO: 更改错误代码以符合您的需要
-		_tprintf(_T("错误: MFC 初始化失败\n"));
-		nRetCode = 1;
-	}
-	else
-	{
-		// TODO: 在此处为应用程序的行为编写代码。
-#if 1
-		TCLCommand tcl(true);
+    int nRetCode = 0;
+
+    // 初始化 MFC 并在失败时显示错误
+    if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
+    {
+        // TODO: 更改错误代码以符合您的需要
+        _tprintf(_T("错误: MFC 初始化失败\n"));
+        nRetCode = 1;
+    }
+    else
+    {
+        // TODO: 在此处为应用程序的行为编写代码。
+        test1();
+        system("pause");
+    }
+
+    return nRetCode;
+}
+
+
+void test()
+{
+#if 0
+        TCLCommand tcl(true);
         std::string cmds;
         std::vector<CommandParam> vtCommandParams;
         utils::GetResourceData(BIN_CMD, "BIN", cmds);
@@ -39,70 +52,100 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
             tcl.parse_cmds_from_string(cmds, vtCommandParams);
         }
 
-		if (tcl.Open(21, _T("baud=115200 parity=N data=8 stop=1")) )
-		{
-			tcl.SetTimeouts();
-			//tcl.parse_cmds_from_file("F:\\source\\scbc_repos\\Serail-Demo\\Demo\\command.data", vtCommandParams);
-			for ( std::vector<CommandParam>::iterator it = vtCommandParams.begin(); it != vtCommandParams.end(); it++ )
-			{
-				if ( !_tcsicmp(it->name.c_str(), _T("LeaveFactory")) )
-					break;
-				byte szData[1024] = {0};
-				std::string cmd = tcl.PackingCommand(*it, _T(""), 0);
-				if (tcl.WriteSync((void*)cmd.c_str(), cmd.size()) )
-				{
-					Sleep(it->read_wait_time);
-					int c = tcl.ReadSync(szData, 1024);
-					std::string str = utils::BytesToHexString(szData, c, ' ');
-					utils::_dprintf("结果:%s", str.c_str());
-
-					str = "";
-					str.append((char*)szData, c);
-					tcl.ParseResultString(*it, str, str.size());
-					
-					Sleep(it->cmd_wait_time);
-				}
-			}
-		}
+        if (tcl.Open(21, _T("baud=115200 parity=N data=8 stop=1")) )
+        {
+            tcl.SetTimeouts();
+            //tcl.parse_cmds_from_file("F:\\source\\scbc_repos\\Serail-Demo\\Demo\\command.data", vtCommandParams);
+            for ( std::vector<CommandParam>::iterator it = vtCommandParams.begin(); it != vtCommandParams.end(); it++ )
+            {
+                if ( !_tcsicmp(it->name.c_str(), _T("LeaveFactory")) )
+                    break;
+                byte szData[1024] = {0};
+                tcl.PackingCommand(*it, _T(""), 0);
+                if (tcl.WriteSync((void*)it->_cmdContext.c_str(), it->_cmdContext.size()) )
+                {
+                    Sleep(it->read_wait_time);
+                    int c = tcl.ReadSync(szData, 1024);
+                    std::string str = utils::BytesToHexString(szData, c, ' ');
+                    utils::_dprintf("结果:%s", str.c_str());
+
+                    str = "";
+                    str.append((char*)szData, c);
+                    tcl.ParseResultString(*it, str, str.size());
+                    
+                    Sleep(it->cmd_wait_time);
+                }
+            }
+        }
 #else
-		TCLCommand tcl(false);
-		std::string cmds;
+        TCLCommand tcl(false);
+        std::string cmds;
         std::vector<CommandParam> vtCommandParams;
-		utils::GetResourceData(BIN_CMD, "BIN", cmds);
+        utils::GetResourceData(BIN_CMD, "BIN", cmds);
         if ( cmds.size() ) {
             tcl.parse_cmds_from_string(cmds, vtCommandParams);
         }
 
-		if ( tcl.Open(21, _T("baud=115200 parity=N data=8 stop=1") ) )
-		{
-			tcl.SetTimeouts();
-			//tcl.parse_cmds_from_file("F:\\source\\scbc_repos\\Serail-Demo\\Demo\\command.data", vtCommandParams);
-			for ( std::vector<CommandParam>::iterator it = vtCommandParams.begin(); it != vtCommandParams.end(); it++ )
-			{
-				if ( !_tcsicmp(it->name.c_str(), _T("LeaveFactory")) )
-					break;
-				byte szData[1024] = {0};
-				std::string cmd = tcl.PackingCommand(*it, _T(""), 0);
-				//sb.Read(szData, 1024, 100);
-				if ( tcl.Write((void*)cmd.c_str(), cmd.size()) )
-				{
-					Sleep(it->read_wait_time);
-					int c = tcl.Read(szData, 1024, 200);
-					std::string str = utils::BytesToHexString(szData, c, ' ');
-					utils::_dprintf("结果:%s", str.c_str());
-
-					str = "";
-					str.append((char*)szData, c);
-					tcl.ParseResultString(*it, str, str.size());
-					Sleep(it->cmd_wait_time);
-				}
-
-				tcl.ClearCommBuffer();
-			}
-		}
-#endif
-		system("pause");
-	}
+        if ( tcl.Open(21, _T("baud=115200 parity=N data=8 stop=1") ) )
+        {
+            tcl.SetTimeouts();
+            //tcl.parse_cmds_from_file("F:\\source\\scbc_repos\\Serail-Demo\\Demo\\command.data", vtCommandParams);
+            for ( std::vector<CommandParam>::iterator it = vtCommandParams.begin(); it != vtCommandParams.end(); it++ )
+            {
+                if ( !_tcsicmp(it->name.c_str(), _T("LeaveFactory")) )
+                    break;
+                byte szData[1024] = {0};
+                tcl.PackingCommand(*it, _T(""), 0);
+                //sb.Read(szData, 1024, 100);
+                if ( tcl.Write((void*)it->_cmdContext.c_str(), it->_cmdContext.size()) )
+                {
+                    Sleep(it->read_wait_time);
+                    int c = tcl.Read(szData, 1024, 200);
+                    std::string str = utils::BytesToHexString(szData, c, ' ');
+                    utils::_dprintf("结果:%s", str.c_str());
+
+                    str = "";
+                    str.append((char*)szData, c);
+                    tcl.ParseResultString(*it, str, str.size());
+                    Sleep(it->cmd_wait_time);
+                }
 
-	return nRetCode;
+                tcl.ClearCommBuffer();
+            }
+        }
+#endif
 }
+
+void test1()
+{
+    TCLCommand tcl(false);
+    tcl.SetInternalCMDParams(BIN_CMD);
+    tcl.SetExternalCMDParams(_T("F:\\cmds.bin"));
+
+    if (tcl.Open(21, _T("baud=115200 parity=N data=8 stop=1")) )
+    {
+        tcl.SetTimeouts();
+        tcl.EnterFactory();
+
+        int pid;
+        tcl.GetProjectId(pid);
+
+        std::string value;
+        tcl.GetSoftVersion(value);
+        tcl.GetDeviceId(value);
+        tcl.GetClientType(value);
+        tcl.GetMAC(value);
+        tcl.GetHDCPKey(value);
+
+        tcl.GetHDCPKey22(value);
+        tcl.GetWidi(value);
+        tcl.GetNetflixESN(value);
+        tcl.GetWidevine(value);
+        tcl.GetCiKey(value);
+        tcl.GetOSDLanguage(value);
+        tcl.GetShopLanguage(value);
+        tcl.GetChannel(value);
+
+        tcl.LeaveFactory();
+    }
+}

+ 478 - 7
Serail-Demo/Demo/TCLCommand.cpp

@@ -2,14 +2,21 @@
 #include "TCLCommand.h"
 
 #define NoneOptLen 5
+#define MINSIZE 128
+#define MIDSIZE 4096
+#define MAXSIZE 10240
 
+byte* TCLCommand::m_pData = NULL;
 TCLCommand::TCLCommand(bool bSync):CBaseSerial(bSync ? 0 : FILE_FLAG_OVERLAPPED)
 {
-
+    m_pData = new byte[MAXSIZE];
 }
 
 TCLCommand::~TCLCommand(void)
 {
+    if (m_pData)
+        delete []m_pData;
+    m_pData = NULL;
     m_vtExternalCMDParams.clear();
     m_vtInternalCMDParams.clear();
 }
@@ -86,7 +93,7 @@ bool TCLCommand::parse_pair_key(std::string& RetValue, std::string strLine, TCHA
     return false;
 }
 
-int TCLCommand::parse_cmds_from_file(TCHAR* file_name, std::vector<CommandParam>& vtCommandParams)
+int TCLCommand::parse_cmds_from_file(const TCHAR* file_name, std::vector<CommandParam>& vtCommandParams)
 {
     TCHAR buf[MAX_PATH] = { 0 };
     TCHAR name[MAX_PATH] = { 0 };
@@ -256,6 +263,7 @@ bool TCLCommand::GetCommandParams(std::string name, CommandParam& cmdPara)
             if ( !_tcsicmp(name.c_str(), it->name.c_str()) ) {
                 bget = true;
                 cmdPara = *it;
+                break;
             }
         }
     }
@@ -374,7 +382,7 @@ bool TCLCommand::TheSecondPart(CommandParam& cmdPara, std::string data)
     return true;
 }
 
-std::string TCLCommand::PackingCommand(CommandParam& cmdPara, std::string data, const int& dataLen)
+void TCLCommand::PackingCommand(CommandParam& cmdPara, std::string data, const int& dataLen)
 {
     // Tag:[命令头][全命令长度][命令码]<命令码参数><附加数据>[crc1][crc2]
     std::string command;
@@ -426,10 +434,8 @@ std::string TCLCommand::PackingCommand(CommandParam& cmdPara, std::string data,
     szcrc[1] = usCRCValue & 0xFF;
     command.append((char*)szcrc, 2);
 
-    cmdPara._cmdContext = utils::BytesToHexString((byte*)command.c_str(), command.size(), ' ');
-    utils::_dprintf(_T("指令:%s = %s"), cmdPara.name.c_str(), cmdPara._cmdContext.c_str());
-
-    return command;
+    cmdPara._cmdContext = command;
+    utils::_dprintf(_T("指令:%s = %s"), cmdPara.name.c_str(), utils::BytesToHexString((byte*)command.c_str(), command.size(), ' ').c_str());
 }
 
 void TCLCommand::ParseResultString(CommandParam& cmdPara, std::string data, const int& dataLen)
@@ -455,3 +461,468 @@ void TCLCommand::ParseResultString(CommandParam& cmdPara, std::string data, cons
         break;
     }
 }
+
+bool TCLCommand::SendCommand(CommandParam& cmdPara)
+{
+    memset(m_pData, 0, MAXSIZE);
+    if (_dwIOMode == FILE_FLAG_OVERLAPPED)
+    {
+        if (!Write((void*)cmdPara._cmdContext.c_str(), cmdPara._cmdContext.size()))
+            return false;
+
+        Sleep(cmdPara.read_wait_time);     
+		int nReadCount = Read(m_pData, MAXSIZE);
+		cmdPara._rtnContext.append((char*)m_pData, nReadCount);
+    }
+    else 
+    {
+        if (!WriteSync((void*)cmdPara._cmdContext.c_str(), cmdPara._cmdContext.size()))
+            return false;
+
+        Sleep(cmdPara.read_wait_time);
+        int nReadCount = ReadSync(m_pData, MAXSIZE);
+		cmdPara._rtnContext.append((char*)m_pData, nReadCount);
+    }
+
+	utils::_dprintf("结果:%s = %s", cmdPara.name.c_str(), utils::BytesToHexString((byte*)cmdPara._rtnContext.c_str(), cmdPara._rtnContext.size(), ' ').c_str());
+	ParseResultString(cmdPara, cmdPara._rtnContext, cmdPara._rtnContext.size());
+    Sleep(cmdPara.cmd_wait_time);
+
+    return cmdPara._rtnStatus == 0x0A ? true : false;
+}
+
+void TCLCommand::SetInternalCMDParams(DWORD dwResouceID)
+{
+    std::string data;
+    if ( utils::GetResourceData(dwResouceID, _T("BIN"), data) )
+    {
+        parse_cmds_from_string(data, m_vtInternalCMDParams);
+    }
+}
+
+void TCLCommand::SetExternalCMDParams(LPCTSTR lpFileName)
+{
+    parse_cmds_from_file(lpFileName, m_vtExternalCMDParams);
+}
+
+bool TCLCommand::EnterFactory()
+{
+	CommandParam cmdpara;
+	GetCommandParams("EnterFactory", cmdpara);
+	PackingCommand(cmdpara);
+    return SendCommand(cmdpara);
+}
+
+bool TCLCommand::LeaveFactory()
+{
+	CommandParam cmdpara;
+	GetCommandParams("LeaveFactory", cmdpara);
+	PackingCommand(cmdpara);
+    return SendCommand(cmdpara);
+}
+
+bool TCLCommand::GetProjectId(int& pid)
+{
+	CommandParam cmdpara;
+	GetCommandParams("GetProjectId", cmdpara);
+	PackingCommand(cmdpara);
+    if (SendCommand(cmdpara))
+    {
+        if (cmdpara._rtnData.size() == 2)
+            pid = (byte)cmdpara._rtnData[0] << 8 | (byte)cmdpara._rtnData[1];
+        else
+            pid = (byte)cmdpara._rtnData[0];
+
+        return true;
+    }
+
+    return false;
+}
+
+bool TCLCommand::GetSoftVersion(std::string& strValue)
+{
+	CommandParam cmdpara;
+	GetCommandParams("GetSoftVersion", cmdpara);
+	PackingCommand(cmdpara);
+	if (SendCommand(cmdpara))
+	{
+        strValue = cmdpara._rtnData;
+		return true;
+	}
+
+	return false;
+}
+
+bool TCLCommand::GetDeviceId(std::string& strValue)
+{
+	CommandParam cmdpara;
+	GetCommandParams("GetDeviceId", cmdpara);
+	PackingCommand(cmdpara);
+	if (SendCommand(cmdpara))
+	{
+		strValue = cmdpara._rtnData;
+		return true;
+	}
+
+	return false;
+}
+
+bool TCLCommand::GetClientType(std::string& strValue)
+{
+	CommandParam cmdpara;
+	GetCommandParams("GetClientType", cmdpara);
+	PackingCommand(cmdpara);
+	if (SendCommand(cmdpara))
+	{
+		strValue = cmdpara._rtnData;
+		return true;
+	}
+
+	return false;
+}
+
+bool TCLCommand::GetMAC(std::string& strValue)
+{
+	CommandParam cmdpara;
+	GetCommandParams("GetMAC", cmdpara);
+	PackingCommand(cmdpara);
+	if (SendCommand(cmdpara))
+	{
+		strValue = cmdpara._rtnData;
+		return true;
+	}
+
+	return false;
+}
+
+bool TCLCommand::GetHDCPKey(std::string& strValue)
+{
+	CommandParam cmdpara;
+	GetCommandParams("GetHDCPKey", cmdpara);
+	PackingCommand(cmdpara);
+	if (SendCommand(cmdpara))
+	{
+		strValue = cmdpara._rtnData;
+		return true;
+	}
+
+	return false;
+}
+
+bool TCLCommand::GetHDCPKey22(std::string& strValue)
+{
+	CommandParam cmdpara;
+	GetCommandParams("GetHDCPKey22", cmdpara);
+	PackingCommand(cmdpara);
+	if (SendCommand(cmdpara))
+	{
+		strValue = cmdpara._rtnData;
+		return true;
+	}
+
+	return false;
+}
+
+bool TCLCommand::GetWidi(std::string& strValue)
+{
+	CommandParam cmdpara;
+	GetCommandParams("GetWidi", cmdpara);
+	PackingCommand(cmdpara);
+	if (SendCommand(cmdpara))
+	{
+		strValue = cmdpara._rtnData;
+		return true;
+	}
+
+	return false;
+}
+
+bool TCLCommand::GetNetflixESN(std::string& strValue)
+{
+	CommandParam cmdpara;
+	GetCommandParams("GetNetflixESN", cmdpara);
+	PackingCommand(cmdpara);
+	if (SendCommand(cmdpara))
+	{
+		strValue = cmdpara._rtnData;
+		return true;
+	}
+
+	return false;
+}
+
+bool TCLCommand::GetWidevine(std::string& strValue)
+{
+	CommandParam cmdpara;
+	GetCommandParams("GetWidevine", cmdpara);
+	PackingCommand(cmdpara);
+	if (SendCommand(cmdpara))
+	{
+		strValue = cmdpara._rtnData;
+		return true;
+	}
+
+	return false;
+}
+
+bool TCLCommand::GetCiKey(std::string& strValue)
+{
+	CommandParam cmdpara;
+	GetCommandParams("GetCiKey", cmdpara);
+	PackingCommand(cmdpara);
+	if (SendCommand(cmdpara))
+	{
+		strValue = cmdpara._rtnData;
+		return true;
+	}
+
+	return false;
+}
+
+bool TCLCommand::GetOSDLanguage(std::string& strValue)
+{
+	CommandParam cmdpara;
+	GetCommandParams("GetOSDLanguage", cmdpara);
+	PackingCommand(cmdpara);
+	if (SendCommand(cmdpara))
+	{
+		strValue = cmdpara._rtnData;
+		return true;
+	}
+
+	return false;
+}
+
+bool TCLCommand::GetShopLanguage(std::string& strValue)
+{
+	CommandParam cmdpara;
+	GetCommandParams("GetShopLanguage", cmdpara);
+	PackingCommand(cmdpara);
+	if (SendCommand(cmdpara))
+	{
+		strValue = cmdpara._rtnData;
+		return true;
+	}
+
+	return false;
+}
+
+bool TCLCommand::GetChannel(std::string& strValue)
+{
+	CommandParam cmdpara;
+	GetCommandParams("GetChannel", cmdpara);
+	PackingCommand(cmdpara);
+	if (SendCommand(cmdpara))
+	{
+		strValue = cmdpara._rtnData;
+		return true;
+	}
+
+	return false;
+}
+
+
+bool TCLCommand::SetProjectId(const byte* pBuffer, const int& nLen)
+{
+	return false;
+}
+
+bool TCLCommand::SetDeviceId(LPCTSTR lpDeviceId)
+{
+    return false;
+}
+
+bool TCLCommand::SetDeviceId(const byte* pBuffer, const int& nLen)
+{
+    return false;
+}
+
+bool TCLCommand::SetMAC(LPCTSTR lpMac)
+{
+    return false;
+}
+
+bool TCLCommand::SetMAC(const byte* pBuffer, const int& nLen)
+{
+    return false;
+}
+
+bool TCLCommand::SetHDCPKey(LPCTSTR lpHDCP, bool bHasSpace)
+{
+    return false;
+}
+
+bool TCLCommand::SetHDCPKey(const byte* pBuffer, const int& nLen)
+{
+    return false;
+}
+
+bool TCLCommand::SetHDCPKey22(LPCTSTR lpHDCP22, bool bHasSpace)
+{
+    return false;
+}
+
+bool TCLCommand::SetHDCPKey22(const byte* pBuffer, const int& nLen)
+{
+    return false;
+}
+
+bool TCLCommand::SetNetflixESN(LPCTSTR lpESN, bool bHasSpace)
+{
+    return false;
+}
+
+bool TCLCommand::SetNetflixESN(const byte* pBuffer, const int& nLen)
+{
+    return false;
+}
+
+bool TCLCommand::SetWidi(LPCTSTR lpWidi, bool bHasSpace)
+{
+    return false;
+}
+
+bool TCLCommand::SetWidi(const byte* pBuffer, const int& nLen)
+{
+    return false;
+}
+
+bool TCLCommand::SetWidevine(LPCTSTR lpWidevine, bool bHasSpace)
+{
+    return false;
+}
+
+bool TCLCommand::SetWidevine(const byte* pBuffer, const int& nLen)
+{
+    return false;
+}
+
+bool TCLCommand::SetCiKey(LPCTSTR lpCiKey, bool bHasSpace)
+{
+    return false;
+}
+
+bool TCLCommand::SetCiKey(const byte* pBuffer, const int& nLen)
+{
+    return false;
+}
+
+bool TCLCommand::SetOSDLanguage(LPCTSTR lan, bool bHasSpace)
+{
+    return false;
+}
+
+bool TCLCommand::SetOSDLanguage(const byte* pBuffer, const int& nLen)
+{
+    return false;
+}
+
+bool TCLCommand::SetShopLanguage(LPCTSTR lan, bool bHasSpace)
+{
+    return false;
+}
+
+bool TCLCommand::SetShopLanguage(const byte* pBuffer, const int& nLen)
+{
+    return false;
+}
+
+bool TCLCommand::SetChannel(LPCTSTR channel, bool bHasSpace)
+{
+    return false;
+}
+
+bool TCLCommand::SetChannel(const byte* pBuffer, const int& nLen)
+{
+    return false;
+}
+
+bool TCLCommand::SetWBNormal(LPCTSTR data)
+{
+    return false;
+}
+
+bool TCLCommand::SetWBNormal(const byte* pBuffer, const int& nLen)
+{
+    return false;
+}
+
+bool TCLCommand::SetWBCool(LPCTSTR data)
+{
+    return false;
+}
+
+bool TCLCommand::SetWBCool(const byte* pBuffer, const int& nLen)
+{
+    return false;
+}
+
+bool TCLCommand::SetWBWarm(LPCTSTR data)
+{
+    return false;
+}
+
+bool TCLCommand::SetWBWarm(const byte* pBuffer, const int& nLen)
+{
+    return false;
+}
+
+bool TCLCommand::CheckDeviceId()
+{
+    return false;
+}
+
+bool TCLCommand::CheckMAC()
+{
+    return false;
+}
+
+bool TCLCommand::CheckHDCP()
+{
+    return false;
+}
+
+bool TCLCommand::CheckHDCP22()
+{
+    return false;
+}
+
+bool TCLCommand::CheckNetflixESN()
+{
+    return false;
+}
+
+bool TCLCommand::CheckWidi()
+{
+    return false;
+}
+
+bool TCLCommand::CheckWidevine()
+{
+    return false;
+}
+
+bool TCLCommand::CheckCikey()
+{
+    return false;
+}
+
+bool TCLCommand::StarWarmUpMode()
+{
+    return false;
+}
+
+bool TCLCommand::StopWarmUpMode()
+{
+    return false;
+}
+
+bool TCLCommand::SetProjectId(int pid)
+{
+    return false;
+}
+
+bool TCLCommand::SetProjectId(LPCTSTR lpPid)
+{
+    return false;
+}

+ 107 - 28
Serail-Demo/Demo/TCLCommand.h

@@ -2,8 +2,7 @@
 #include "serial.h"
 
 
-enum CMDOPT
-{
+enum CMDOPT {
     CMDOPT_None = 0,
     CMDOPT_Get = 1,
     CMDOPT_Set = 2
@@ -28,8 +27,8 @@ typedef struct __CMDPARAM__ {
     std::string _rtnError;
     std::string _rtnContext;
     std::string _cmdContext;
-    void UpdateRtnCode()
-    {
+
+    void UpdateRtnCode() {
         if (!_tcsicmp(_T("AA"), head.c_str())) { // 调试用命令代码引导码;
             _rtnCode = 0xAB;
         }
@@ -41,33 +40,30 @@ typedef struct __CMDPARAM__ {
         }
     }
 
-    __CMDPARAM__& operator=(const __CMDPARAM__& cls)
-    {
-        if (this != &cls)
-        {
-           name = cls.name;
-           head = cls.head;
-           code = cls.code;
-           param = cls.param;
-           nOption = cls.nOption;
-           bMulticode = cls.bMulticode;
-           cmd_wait_time = cls.cmd_wait_time;
-           read_wait_time = cls.read_wait_time;
-           _rtnCode = cls._rtnCode;
-           _rtnStatus = cls._rtnStatus;
-           _rtnData = cls._rtnData;
-           _rtnError = cls._rtnError;
-           _rtnContext = cls._rtnContext;
-           _cmdContext = cls._cmdContext;
+    __CMDPARAM__& operator=(const __CMDPARAM__& cls) {
+        if (this != &cls) {
+            name = cls.name;
+            head = cls.head;
+            code = cls.code;
+            param = cls.param;
+            nOption = cls.nOption;
+            bMulticode = cls.bMulticode;
+            cmd_wait_time = cls.cmd_wait_time;
+            read_wait_time = cls.read_wait_time;
+            _rtnCode = cls._rtnCode;
+            _rtnStatus = cls._rtnStatus;
+            _rtnData = cls._rtnData;
+            _rtnError = cls._rtnError;
+            _rtnContext = cls._rtnContext;
+            _cmdContext = cls._cmdContext;
         }
-        
+
         return *this;
     }
 
-    void Clean()
-    {
+    void Clean() {
         //_rtnCode = 0;
-        _rtnStatus = 0;
+        _rtnStatus = 0x0E;
 #if _MSC_VER >= 1200 && _MSC_VER < 1500
         _rtnData = "";
         _rtnError = "";
@@ -94,6 +90,7 @@ typedef struct __CMDPARAM__ {
 
 class TCLCommand :public CBaseSerial
 {
+    static byte* m_pData;
     // 内部-低优先查找;
     std::vector<CommandParam> m_vtInternalCMDParams;
     // 外部-高优先查找;
@@ -105,15 +102,97 @@ public:
 public:
     int pares_time_value(std::string strTime);
     bool parse_pair_key(std::string& RetValue, std::string strLine, TCHAR* lpszText);
-    int parse_cmds_from_file(TCHAR* file_name, std::vector<CommandParam>& vtCommandParams);
+    int parse_cmds_from_file(const TCHAR* file_name, std::vector<CommandParam>& vtCommandParams);
     void parse_cmds_from_string(std::string str, std::vector<CommandParam>& vtCommandParams);
     bool GetCommandParams(std::string name, CommandParam& cmdPara);
 
     bool TheFirstPart(CommandParam& cmdPara, std::string data);
     bool TheSecondPart(CommandParam& cmdPara, std::string data);
-    std::string PackingCommand(CommandParam& cmdPara, std::string data, const int& dataLen);
+    void PackingCommand(CommandParam& cmdPara, std::string data = "", const int& dataLen = 0);
     void ParseResultString(CommandParam& cmdPara, std::string data, const int& dataLen);
 
+    bool SendCommand(CommandParam& cmdPara);
 public:
+    void SetInternalCMDParams(DWORD dwResouceID);
+    void SetExternalCMDParams(LPCTSTR lpFileName);
+
+    bool EnterFactory();
+    bool LeaveFactory();
+    bool GetProjectId(int &pid);
+    bool GetSoftVersion(std::string &strValue);
+    bool GetDeviceId(std::string &strValue);
+    bool GetClientType(std::string &strValue);
+    bool GetMAC(std::string &strValue);
+    bool GetHDCPKey(std::string &strValue);
+    bool GetHDCPKey22(std::string &strValue);
+    bool GetWidi(std::string &strValue);
+    bool GetNetflixESN(std::string &strValue);
+    bool GetWidevine(std::string &strValue);
+    bool GetCiKey(std::string &strValue);
+    bool GetOSDLanguage(std::string &strValue);
+    bool GetShopLanguage(std::string &strValue);
+    bool GetChannel(std::string &strValue);
+
+    bool SetProjectId(int pid);
+    bool SetProjectId(LPCTSTR lpPid);
+    bool SetProjectId(const byte* pBuffer, const int& nLen);
+    bool SetDeviceId(LPCTSTR lpDeviceId);
+    bool SetDeviceId(const byte* pBuffer, const int &nLen);
+    bool SetMAC(LPCTSTR lpMac);
+    bool SetMAC(const byte* pBuffer, const int& nLen);
+    bool SetHDCPKey(LPCTSTR lpHDCP, bool bHasSpace = FALSE);
+    bool SetHDCPKey(const byte* pBuffer, const int& nLen);
+    bool SetHDCPKey22(LPCTSTR lpHDCP22, bool bHasSpace = FALSE);
+    bool SetHDCPKey22(const byte* pBuffer, const int& nLen);
+    bool SetNetflixESN(LPCTSTR lpESN, bool bHasSpace = FALSE);
+    bool SetNetflixESN(const byte* pBuffer, const int& nLen);
+    bool SetWidi(LPCTSTR lpWidi, bool bHasSpace = FALSE);
+    bool SetWidi(const byte* pBuffer, const int& nLen);
+    bool SetWidevine(LPCTSTR lpWidevine, bool bHasSpace = FALSE);
+    bool SetWidevine(const byte* pBuffer, const int& nLen);
+    bool SetCiKey(LPCTSTR lpCiKey, bool bHasSpace = FALSE);
+    bool SetCiKey(const byte* pBuffer, const int& nLen);
+    bool SetOSDLanguage(LPCTSTR lan, bool bHasSpace = TRUE);
+    bool SetOSDLanguage(const byte* pBuffer, const int& nLen);
+    bool SetShopLanguage(LPCTSTR lan, bool bHasSpace = TRUE);
+    bool SetShopLanguage(const byte* pBuffer, const int& nLen);
+    bool SetChannel(LPCTSTR channel, bool bHasSpace = TRUE);
+    bool SetChannel(const byte* pBuffer, const int& nLen);
+    bool SetWBNormal(LPCTSTR data);
+    bool SetWBNormal(const byte* pBuffer, const int& nLen);
+    bool SetWBCool(LPCTSTR data);
+    bool SetWBCool(const byte* pBuffer, const int& nLen);
+    bool SetWBWarm(LPCTSTR data);
+    bool SetWBWarm(const byte* pBuffer, const int& nLen);
+
+    bool CheckDeviceId();
+    bool CheckMAC();
+    bool CheckHDCP();
+    bool CheckHDCP22();
+    bool CheckNetflixESN();
+    bool CheckWidi();
+    bool CheckWidevine();
+    bool CheckCikey();
+
+    bool StarWarmUpMode();
+    bool StopWarmUpMode();
 
+    // 工厂菜单显示与隐藏;
+    bool ShowFactoryMenu();
+    bool HideFactoryMenu();
+    // 工厂信息内容显示与隐藏;
+    bool ShowFactoryInformation();
+    bool HideFactoryInformation();
+    // 老化模式的开与关、老化时间读取;
+    bool EnterAgingModel();
+    bool LeaveAgingModel();
+    bool ReadAgingTime(int &min);
+    // 红绿蓝增益;
+    bool SetRedGainRegister(int value);
+    bool SetGreenGainRegister(int value);
+    bool SetBlueGainRegister(int value);
+    // 红绿蓝偏移;
+    bool SetRedOffsetRegister(int value);
+    bool SetGreenOffsetRegister(int value);
+    bool SetBlueOffsetRegister(int value);
 };