123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928 |
- #include "StdAfx.h"
- #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();
- }
- int TCLCommand::pares_time_value(std::string strTime)
- {
- int nTimes = 0;
- #if _MSC_VER >= 1200 && _MSC_VER < 1500
- if (strstr(strTime.c_str(), _T("ms")) || strstr(strTime.c_str(), _T("MS")))
- {
- nTimes = atol(strTime.c_str());
- }
- else if (strstr(strTime.c_str(), _T("s")) || strstr(strTime.c_str(), _T("S")))
- {
- nTimes = atol(strTime.c_str()) * 1000;
- }
- else if (strstr(strTime.c_str(), _T("m")) || strstr(strTime.c_str(), _T("M")))
- {
- nTimes = atol(strTime.c_str()) * 6000;
- }
- else
- {
- // 不带单位或其他的,默认ms;
- nTimes = atol(strTime.c_str());
- }
- #elif _MSC_VER >= 1500
- if (_tcsstr(strTime.c_str(), _T("ms")) || _tcsstr(strTime.c_str(), _T("MS")))
- {
- nTimes = _tstol(strTime.c_str());
- }
- else if (_tcsstr(strTime.c_str(), _T("s")) || _tcsstr(strTime.c_str(), _T("S")))
- {
- nTimes = _tstol(strTime.c_str()) * 1000;
- }
- else if (_tcsstr(strTime.c_str(), _T("m")) || _tcsstr(strTime.c_str(), _T("M")))
- {
- nTimes = _tstol(strTime.c_str()) * 6000;
- }
- else
- {
- // 不带单位或其他的,默认ms;
- nTimes = _tstol(strTime.c_str());
- }
- #endif
- return nTimes;
- }
- bool TCLCommand::parse_pair_key(std::string& RetValue, std::string strLine, TCHAR* lpszText)
- {
- TCHAR szText[MAX_PATH] = { 0 };
- TCHAR szValue[MAX_PATH] = { 0 };
- // 去除空格;
- #if _MSC_VER > 1900
- strLine.erase(std::remove_if(strLine.begin(), strLine.end(), [](unsigned char x) {return std::isspace(x); }), strLine.end()); //C++17
- #else
- for (std::string::iterator it = strLine.begin(); it != strLine.end();) {
- !isspace(*it) ? it++ : it = it = strLine.erase(it);
- }
- #endif
- #if _MSC_VER >= 1200 && _MSC_VER < 1500 // VC6.0~8.0
- if (2 == sscanf(strLine.c_str(), _T("%[^=]=%s"), szText, MAX_PATH, szValue, MAX_PATH))
- #else
- if (2 == _stscanf_s(strLine.c_str(), _T("%[^=]=%s"), szText, MAX_PATH, szValue, MAX_PATH))
- #endif
- {
- if (_tcsstr(szText, lpszText)) {
- RetValue = szValue;
- return true;
- }
- }
- return false;
- }
- int TCLCommand::parse_cmds_from_file(const TCHAR* file_name, std::vector<CommandParam>& vtCommandParams)
- {
- TCHAR buf[MAX_PATH] = { 0 };
- TCHAR name[MAX_PATH] = { 0 };
- TCHAR option[MAX_PATH] = { 0 };
- TCHAR head[MAX_PATH] = { 0 };
- TCHAR code[MAX_PATH] = { 0 };
- TCHAR param[MAX_PATH] = { 0 };
- TCHAR multicode[MAX_PATH] = { 0 };
- TCHAR cmd_wait_time[MAX_PATH] = { 0 };
- TCHAR read_wait_time[MAX_PATH] = { 0 };
- int ret = -1;
- FILE* fp = NULL;
- if (!file_name || file_name[0] == '\0')
- return ret;
- fp = fopen(file_name, "r");
- if (!fp)
- goto EXIT;
- while ((fgets((char*)buf, MAX_PATH, fp) != NULL)) {
- int tmp_len = 0;
- tmp_len = _tcslen(buf);
- if (tmp_len >= 1) {
- if (buf[tmp_len - 1] == '\r' || buf[tmp_len - 1] == '\n')
- buf[tmp_len - 1] = 0;
- if (tmp_len >= 2) {
- if (buf[tmp_len - 2] == '\r' || buf[tmp_len - 2] == '\n')
- buf[tmp_len - 2] = 0;
- }
- }
- #if _MSC_VER >= 1200 && _MSC_VER < 1500 // VC6.0~8.0
- if (sscanf(buf, "%[^;];%[^;];%[^;];%[^;];%[^;];%[^;];%[^;]", name, option, head, code, param, multicode, read_wait_time, cmd_wait_time) == 8)
- #elif _MSC_VER >= 1500
- //if ( _stscanf_s(buf, "%[^;];%[^;];%[^;];%[^;];%[^;];%[^;];%[^;];%[^;]", name, MAX_PATH, option, MAX_PATH, head, MAX_PATH, code, MAX_PATH, param, MAX_PATH, multicode, MAX_PATH, read_wait_time, MAX_PATH, cmd_wait_time, MAX_PATH) == 8) // 等价下面;
- if (_stscanf_s(buf, "%[^;];%[^;];%[^;];%[^;];%[^;];%[^;];%[^;];%s", name, MAX_PATH, option, MAX_PATH, head, MAX_PATH, code, MAX_PATH, param, MAX_PATH, multicode, MAX_PATH, read_wait_time, MAX_PATH, cmd_wait_time, MAX_PATH) == 8)
- #endif
- {
- CommandParam cp;
- parse_pair_key(cp.name, name, _T("Name"));
- parse_pair_key(cp.head, head, _T("HeadCode"));
- parse_pair_key(cp.code, code, _T("Command"));
- parse_pair_key(cp.param, param, _T("CMDParam"));
- std::string value;
- parse_pair_key(value, option, _T("Option"));
- if (!_tcsicmp(value.c_str(), _T("None")))
- cp.nOption = CMDOPT_None;
- else if (!_tcsicmp(value.c_str(), _T("Get")))
- cp.nOption = CMDOPT_Get;
- else if (!_tcsicmp(value.c_str(), _T("Set")))
- cp.nOption = CMDOPT_Set;
- parse_pair_key(value, multicode, _T("MultiParams"));
- cp.bMulticode = !_tcsicmp(value.c_str(), _T("true")) ? true : false;
- parse_pair_key(value, read_wait_time, _T("ReadWaitTime"));
- cp.read_wait_time = pares_time_value(value.c_str());
- parse_pair_key(value, cmd_wait_time, _T("CMDWaitTime"));
- cp.cmd_wait_time = pares_time_value(value.c_str());
- cp.UpdateRtnCode();
- vtCommandParams.push_back(cp);
- }
- }
- ret = 0;
- EXIT:
- if (fp)
- fclose(fp);
- return ret;
- }
- void TCLCommand::parse_cmds_from_string(std::string str, std::vector<CommandParam>& vtCommandParams)
- {
- int nPos(0);
- TCHAR buf[MAX_PATH] = { 0 };
- TCHAR name[MAX_PATH] = { 0 };
- TCHAR option[MAX_PATH] = { 0 };
- TCHAR head[MAX_PATH] = { 0 };
- TCHAR code[MAX_PATH] = { 0 };
- TCHAR param[MAX_PATH] = { 0 };
- TCHAR multicode[MAX_PATH] = { 0 };
- TCHAR cmd_wait_time[MAX_PATH] = { 0 };
- TCHAR read_wait_time[MAX_PATH] = { 0 };
- do
- {
- memset(buf, 0, MAX_PATH);
- int nPos1 = str.find_first_of('\r');
- int nPos2 = str.find_first_of('\n');
- if ( std::string::npos != nPos1 && std::string::npos != nPos2 ) {
- nPos = nPos1 > nPos2 ? nPos1 : nPos2;
- _stprintf_s(buf, _T("%s"), str.substr(0, nPos - 1).c_str());
- str = str.substr(nPos+1);
- }
- else if ( std::string::npos != nPos1 ) {
- _stprintf_s(buf, _T("%s"), str.substr(0, nPos1 - 1).c_str());
- str = str.substr(nPos + 1);
- }
- else if ( std::string::npos != nPos2 ) {
- _stprintf_s(buf, _T("%s"), str.substr(0, nPos2 - 1).c_str());
- str = str.substr(nPos + 1);
- }
- else {
- _stprintf_s(buf, _T("%s"), str.c_str());
- str.clear();
- }
- #if _MSC_VER >= 1200 && _MSC_VER < 1500 // VC6.0~8.0
- if (sscanf(buf, "%[^;];%[^;];%[^;];%[^;];%[^;];%[^;];%[^;]", name, option, head, code, param, multicode, read_wait_time, cmd_wait_time) == 8)
- #elif _MSC_VER >= 1500
- //if ( _stscanf_s(buf, "%[^;];%[^;];%[^;];%[^;];%[^;];%[^;];%[^;];%[^;]", name, MAX_PATH, option, MAX_PATH, head, MAX_PATH, code, MAX_PATH, param, MAX_PATH, multicode, MAX_PATH, read_wait_time, MAX_PATH, cmd_wait_time, MAX_PATH) == 8) // 等价下面;
- if (_stscanf_s(buf, "%[^;];%[^;];%[^;];%[^;];%[^;];%[^;];%[^;];%s", name, MAX_PATH, option, MAX_PATH, head, MAX_PATH, code, MAX_PATH, param, MAX_PATH, multicode, MAX_PATH, read_wait_time, MAX_PATH, cmd_wait_time, MAX_PATH) == 8)
- #endif
- {
- CommandParam cp;
- parse_pair_key(cp.name, name, _T("Name"));
- parse_pair_key(cp.head, head, _T("HeadCode"));
- parse_pair_key(cp.code, code, _T("Command"));
- parse_pair_key(cp.param, param, _T("CMDParam"));
- std::string value;
- parse_pair_key(value, option, _T("Option"));
- if (!_tcsicmp(value.c_str(), _T("None")))
- cp.nOption = CMDOPT_None;
- else if (!_tcsicmp(value.c_str(), _T("Get")))
- cp.nOption = CMDOPT_Get;
- else if (!_tcsicmp(value.c_str(), _T("Set")))
- cp.nOption = CMDOPT_Set;
- parse_pair_key(value, multicode, _T("MultiParams"));
- cp.bMulticode = !_tcsicmp(value.c_str(), _T("true")) ? true : false;
- parse_pair_key(value, read_wait_time, _T("ReadWaitTime"));
- cp.read_wait_time = pares_time_value(value.c_str());
- parse_pair_key(value, cmd_wait_time, _T("CMDWaitTime"));
- cp.cmd_wait_time = pares_time_value(value.c_str());
- cp.UpdateRtnCode();
- vtCommandParams.push_back(cp);
- }
- } while (str.size());
- }
- bool TCLCommand::GetCommandParams(std::string name, CommandParam& cmdPara)
- {
- bool bget = false;
- // 外部优先;
- for (std::vector<CommandParam>::iterator it = m_vtExternalCMDParams.begin(); it != m_vtExternalCMDParams.end(); it++ )
- {
- if ( !_tcsicmp(name.c_str(), it->name.c_str()) ) {
- bget = true;
- cmdPara = *it;
- break;
- }
- }
-
- if ( !bget )
- {
- for (std::vector<CommandParam>::iterator it = m_vtInternalCMDParams.begin(); it != m_vtInternalCMDParams.end(); it++ )
- {
- if ( !_tcsicmp(name.c_str(), it->name.c_str()) ) {
- bget = true;
- cmdPara = *it;
- break;
- }
- }
- }
- // 清除状态;
- cmdPara.Clean();
- return bget;
- }
- bool TCLCommand::TheFirstPart(CommandParam& cmdPara, std::string data)
- {
- if (data.size() == NoneOptLen) {
- if ((byte)data[0] == cmdPara._rtnCode) {
- // 长度;
- int nPacketLen = (byte)data[1];
- if (nPacketLen != NoneOptLen) {
- cmdPara._rtnError = utils::_dprintf("[%s] 返回数据长度错误:%ld", __FUNCTION__, (byte)data[1]);
- return false;
- }
- // 执行状态;
- cmdPara._rtnStatus = (byte)data[2];
- //utils::_dprintf(_T("[%s] rtnStatus=%02X"), __FUNCTION__, cmdPara._rtnStatus);
- // 校验crc;
- unsigned short usCRCValue = utils::CRC16Calculate((byte*)data.data(), nPacketLen - 2);
- if (((usCRCValue >> 8) & 0xFF) != (byte)data[nPacketLen - 2] || (usCRCValue & 0xFF) != (byte)data[nPacketLen - 1]) {
- cmdPara._rtnError = utils::_dprintf("[%s] CRC校验错误:计算[%02% %02X] != 接收[%02X %02X]", __FUNCTION__, (usCRCValue >> 8) & 0xFF, usCRCValue & 0xFF, (byte)data[nPacketLen - 2], (byte)data[nPacketLen - 1]);
- return false;
- }
- }
- else {
- cmdPara._rtnError = utils::_dprintf("[%s] 返回码错误:%02X", __FUNCTION__, (byte)data[0]);
- return false;
- }
- }
- else {
- cmdPara._rtnError = utils::_dprintf("[%s] 返回数据长度错误", __FUNCTION__);
- return false;
- }
- return true;
- }
- bool TCLCommand::TheSecondPart(CommandParam& cmdPara, std::string data)
- {
- // 数据起始位;
- int nDataPos = 0;
- // 数据包长度;
- int nPacketLen = 0;
- if ((byte)data[0] == cmdPara._rtnCode) {
- // 获取长度;
- if ((byte)data[1] == 0xFE) {
- nDataPos = 4;
- nPacketLen = (byte)data[2] << 8 | (byte)data[3];
- if (data.size() < 255 && data[2] != 0) {
- cmdPara._rtnError = utils::_dprintf(_T("[%s] 返回数据长度异常"), __FUNCTION__);
- return false;
- }
- }
- else
- {
- nDataPos = 2;
- nPacketLen = (byte)data[1];
- #if 0 // 如果数据包含有非协议包内的数据,会判断异常;
- if (data.size() > 255) {
- //nPackageLen = data[1] << 8 | data[2];
- cmdPara._rtnError = _dprintf(_T("长度异常"));
- return false;
- }
- #endif
- }
- #if 0
- // 计算出的长度,必等于包长;// 如果包含有其他非包数据,会判断异常;
- if (nPackageLen != data.size())
- return false;
- #endif
- if (_tcsicmp(cmdPara.code.c_str(), utils::ByteToChars((byte)data[nDataPos] - 1).c_str()) != 0) {
- cmdPara._rtnError = utils::_dprintf(_T("[%s] 返回的指令错误, %s, %02X"), __FUNCTION__, cmdPara.head.c_str(), (byte)data[nDataPos]);
- return false;
- }
- // 返回的数据;
- ++nDataPos;// 返回码占一字节;
- if (cmdPara.bMulticode) {
- if (_tcsicmp(cmdPara.param.c_str(), utils::ByteToChars((byte)data[nDataPos]).c_str()) != 0) {
- cmdPara._rtnError = utils::_dprintf(_T("[%s] 返回的指令参数错误, %s, %02X"), __FUNCTION__, cmdPara.param.c_str(), (byte)data[nDataPos]);
- return false;
- }
- ++nDataPos;// 指令参数码占一字节;
- }
- cmdPara._rtnData = data.substr(nDataPos, nPacketLen - nDataPos - 2); //2 = crc;
- utils::_dprintf(_T("rtnData=%s"), utils::BytesToHexString((byte*)cmdPara._rtnData.c_str(), cmdPara._rtnData.size(), ' ').c_str());
- // 校验crc;
- unsigned short usCRCValue = utils::CRC16Calculate((byte*)data.data(), nPacketLen - 2);
- if (((usCRCValue >> 8) & 0xFF) != (byte)data[nPacketLen - 2] || (usCRCValue & 0xFF) != (byte)data[nPacketLen - 1])
- {
- cmdPara._rtnError = utils::_dprintf("[%s] CRC校验错误:计算[%02X %02X] != 接收[%02X %02X]", __FUNCTION__, (usCRCValue >> 8) & 0xFF, usCRCValue & 0xFF, (byte)data[nPacketLen - 2], (byte)data[nPacketLen - 1]);
- return false;
- }
- if (data.size() > nPacketLen)
- utils::_dprintf("[%s] 带有脏数据:%s", __FUNCTION__, data.substr(nPacketLen));
- }
- else {
- cmdPara._rtnError = utils::_dprintf("[%s] 返回码错误:%02X", __FUNCTION__, (byte)data[0]);
- return false;
- }
- return true;
- }
- void TCLCommand::PackingCommand(CommandParam& cmdPara, std::string data, const int& dataLen)
- {
- // Tag:[命令头][全命令长度][命令码]<命令码参数><附加数据>[crc1][crc2]
- std::string command;
- // 命令头标识位;
- command.append(utils::HexStringToBytes(cmdPara.head, 2).c_str(), cmdPara.head.size() / 2);
- // 命令码;
- command.append(utils::HexStringToBytes(cmdPara.code, 2).c_str(), cmdPara.code.size() / 2);
- // 命令码参数;
- command.append(utils::HexStringToBytes(cmdPara.param, 2).c_str(), cmdPara.param.size() / 2);
- // 附加的数据;
- if (dataLen > 0)
- command.append(data.c_str(), dataLen);
- int len(0);
- // 长度:可能1字节表示,超过255用2字节表示;
- byte szlen[2] = { 0 };
- //if ((byte)command[1] == 0xFE)
- //if ( cmdPara.head.size() >= 4 && cmdPara.head.find("FE", 2, 2) != std::string::npos )
- if (_tcsicmp(_T("AAFE"), cmdPara.head.c_str()) == 0)
- {// 长度超过255,需要2字节表示;
- len = command.size() + 4; // 2位crc + 2位长度;
- szlen[0] = (len >> 8) & 0xFF;
- szlen[1] = len & 0xFF;
- command.insert(2, (char*)szlen, 2);
- }
- else {
- // 2位crc + 1位长度;
- len = command.size() + 3;
- //if ( _tcsicmp(cmdPara.code.c_str(), "99 00") == 0 )
- // len -= 2;
- if (len > 255) {// 长度超过255,多一个占位符;
- ++len;
- szlen[0] = (len >> 8) & 0xFF;
- szlen[1] = len & 0xFF;
- command.insert(1, (char*)szlen, 2);
- }
- else {
- szlen[0] = len & 0xFF;
- command.insert(1, (char*)szlen, 1);
- }
- }
- // crc校验;
- byte szcrc[2] = { 0 };
- WORD usCRCValue = utils::CRC16Calculate((byte*)command.c_str(), command.size()); // 如果有0断开有危险;
- //WORD usCRCValue = CRC16Calculate((byte *)command.c_str(), len - 2);
- szcrc[0] = (usCRCValue >> 8) & 0xFF;
- szcrc[1] = usCRCValue & 0xFF;
- command.append((char*)szcrc, 2);
- 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)
- {
- // Tag:[返回头][全数据长度][返回码]<返回码子项><附加数据>[crc16]
- if (!TheFirstPart(cmdPara, data.substr(0, 5)))
- return;
- if (cmdPara._rtnStatus != 0x0A) {
- utils::_dprintf("[%s] 执行结果错误:%02X", __FUNCTION__, cmdPara._rtnStatus);
- return;
- }
- switch (cmdPara.nOption)
- {
- case CMDOPT_None:
- break;
- case CMDOPT_Get:
- case CMDOPT_Set:
- TheSecondPart(cmdPara, data.substr(5));
- break;
- default:
- 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;
- }
|