|
@@ -25,71 +25,71 @@ TCLCommand::~TCLCommand(void)
|
|
m_vtInternalCMDParams.clear();
|
|
m_vtInternalCMDParams.clear();
|
|
}
|
|
}
|
|
|
|
|
|
-int TCLCommand::pares_time_value(std::string strTime)
|
|
|
|
|
|
+int TCLCommand::ParseTimeValue(std::string strTimeInfo)
|
|
{
|
|
{
|
|
int nTimes = 0;
|
|
int nTimes = 0;
|
|
#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
- if (strstr(strTime.c_str(), _T("ms")) || strstr(strTime.c_str(), _T("MS")))
|
|
|
|
|
|
+ if (strstr(strTimeInfo.c_str(), _T("ms")) || strstr(strTimeInfo.c_str(), _T("MS")))
|
|
{
|
|
{
|
|
- nTimes = atol(strTime.c_str());
|
|
|
|
|
|
+ nTimes = atol(strTimeInfo.c_str());
|
|
}
|
|
}
|
|
- else if (strstr(strTime.c_str(), _T("s")) || strstr(strTime.c_str(), _T("S")))
|
|
|
|
|
|
+ else if (strstr(strTimeInfo.c_str(), _T("s")) || strstr(strTimeInfo.c_str(), _T("S")))
|
|
{
|
|
{
|
|
- nTimes = atol(strTime.c_str()) * 1000;
|
|
|
|
|
|
+ nTimes = atol(strTimeInfo.c_str()) * 1000;
|
|
}
|
|
}
|
|
- else if (strstr(strTime.c_str(), _T("m")) || strstr(strTime.c_str(), _T("M")))
|
|
|
|
|
|
+ else if (strstr(strTimeInfo.c_str(), _T("m")) || strstr(strTimeInfo.c_str(), _T("M")))
|
|
{
|
|
{
|
|
- nTimes = atol(strTime.c_str()) * 6000;
|
|
|
|
|
|
+ nTimes = atol(strTimeInfo.c_str()) * 6000;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
// 不带单位或其他的,默认ms;
|
|
// 不带单位或其他的,默认ms;
|
|
- nTimes = atol(strTime.c_str());
|
|
|
|
|
|
+ nTimes = atol(strTimeInfo.c_str());
|
|
}
|
|
}
|
|
#elif _MSC_VER >= 1500
|
|
#elif _MSC_VER >= 1500
|
|
- if (_tcsstr(strTime.c_str(), _T("ms")) || _tcsstr(strTime.c_str(), _T("MS")))
|
|
|
|
|
|
+ if (_tcsstr(strTimeInfo.c_str(), _T("ms")) || _tcsstr(strTimeInfo.c_str(), _T("MS")))
|
|
{
|
|
{
|
|
- nTimes = _tstol(strTime.c_str());
|
|
|
|
|
|
+ nTimes = _tstol(strTimeInfo.c_str());
|
|
}
|
|
}
|
|
- else if (_tcsstr(strTime.c_str(), _T("s")) || _tcsstr(strTime.c_str(), _T("S")))
|
|
|
|
|
|
+ else if (_tcsstr(strTimeInfo.c_str(), _T("s")) || _tcsstr(strTimeInfo.c_str(), _T("S")))
|
|
{
|
|
{
|
|
- nTimes = _tstol(strTime.c_str()) * 1000;
|
|
|
|
|
|
+ nTimes = _tstol(strTimeInfo.c_str()) * 1000;
|
|
}
|
|
}
|
|
- else if (_tcsstr(strTime.c_str(), _T("m")) || _tcsstr(strTime.c_str(), _T("M")))
|
|
|
|
|
|
+ else if (_tcsstr(strTimeInfo.c_str(), _T("m")) || _tcsstr(strTimeInfo.c_str(), _T("M")))
|
|
{
|
|
{
|
|
- nTimes = _tstol(strTime.c_str()) * 6000;
|
|
|
|
|
|
+ nTimes = _tstol(strTimeInfo.c_str()) * 6000;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
// 不带单位或其他的,默认ms;
|
|
// 不带单位或其他的,默认ms;
|
|
- nTimes = _tstol(strTime.c_str());
|
|
|
|
|
|
+ nTimes = _tstol(strTimeInfo.c_str());
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
|
|
return nTimes;
|
|
return nTimes;
|
|
}
|
|
}
|
|
|
|
|
|
-bool TCLCommand::parse_pair_key(std::string& RetValue, std::string strLine, TCHAR* lpszText)
|
|
|
|
|
|
+bool TCLCommand::ParseKeyValuePairs(std::string& strValue, std::string strPairText, const TCHAR* lpszKeyName)
|
|
{
|
|
{
|
|
TCHAR szText[MAX_PATH] = { 0 };
|
|
TCHAR szText[MAX_PATH] = { 0 };
|
|
TCHAR szValue[MAX_PATH] = { 0 };
|
|
TCHAR szValue[MAX_PATH] = { 0 };
|
|
// 去除空格;
|
|
// 去除空格;
|
|
#if _MSC_VER > 1900
|
|
#if _MSC_VER > 1900
|
|
- strLine.erase(std::remove_if(strLine.begin(), strLine.end(), [](unsigned char x) {return std::isspace(x); }), strLine.end()); //C++17
|
|
|
|
|
|
+ strPairText.erase(std::remove_if(strPairText.begin(), strPairText.end(), [](unsigned char x) {return std::isspace(x); }), strPairText.end()); //C++17
|
|
#else
|
|
#else
|
|
- for (std::string::iterator it = strLine.begin(); it != strLine.end();) {
|
|
|
|
- !isspace(*it) ? it++ : it = it = strLine.erase(it);
|
|
|
|
|
|
+ for (std::string::iterator it = strPairText.begin(); it != strPairText.end();) {
|
|
|
|
+ !isspace(*it) ? it++ : it = it = strPairText.erase(it);
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
|
|
#if _MSC_VER >= 1200 && _MSC_VER < 1500 // VC6.0~8.0
|
|
#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))
|
|
|
|
|
|
+ if (2 == sscanf(strPairText.c_str(), _T("%[^=]=%s"), szText, MAX_PATH, szValue, MAX_PATH))
|
|
#else
|
|
#else
|
|
- if (2 == _stscanf_s(strLine.c_str(), _T("%[^=]=%s"), szText, MAX_PATH, szValue, MAX_PATH))
|
|
|
|
|
|
+ if (2 == _stscanf_s(strPairText.c_str(), _T("%[^=]=%s"), szText, MAX_PATH, szValue, MAX_PATH))
|
|
#endif
|
|
#endif
|
|
{
|
|
{
|
|
- if (_tcsstr(szText, lpszText)) {
|
|
|
|
- RetValue = szValue;
|
|
|
|
|
|
+ if (_tcsstr(szText, lpszKeyName)) {
|
|
|
|
+ strValue = szValue;
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -97,7 +97,7 @@ bool TCLCommand::parse_pair_key(std::string& RetValue, std::string strLine, TCHA
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
-int TCLCommand::parse_cmds_from_file(const TCHAR* file_name, std::vector<CommandParam>& vtCommandParams)
|
|
|
|
|
|
+int TCLCommand::ParseCommandsFromFile(const TCHAR* file_name, std::vector<CommandParam>& vtCommandParams)
|
|
{
|
|
{
|
|
int ret = -1;
|
|
int ret = -1;
|
|
FILE* fp = NULL;
|
|
FILE* fp = NULL;
|
|
@@ -133,7 +133,7 @@ EXIT:
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
-void TCLCommand::parse_cmds_from_string(std::string str, std::vector<CommandParam>& vtCommandParams)
|
|
|
|
|
|
+void TCLCommand::ParseCommandsFromString(std::string str, std::vector<CommandParam>& vtCommandParams)
|
|
{
|
|
{
|
|
int nPos(0);
|
|
int nPos(0);
|
|
TCHAR buf[MAX_PATH] = { 0 };
|
|
TCHAR buf[MAX_PATH] = { 0 };
|
|
@@ -201,13 +201,13 @@ bool TCLCommand::ParseCommandFromString(std::string str, CommandParam &cmdParam)
|
|
if (_stscanf_s(str.c_str(), "%[^;];%[^;];%[^;];%[^;];%[^;];%[^;];%[^;];%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)
|
|
if (_stscanf_s(str.c_str(), "%[^;];%[^;];%[^;];%[^;];%[^;];%[^;];%[^;];%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
|
|
#endif
|
|
{
|
|
{
|
|
- parse_pair_key(cmdParam.name, name, _T("name"));
|
|
|
|
- parse_pair_key(cmdParam.head, head, _T("head"));
|
|
|
|
- parse_pair_key(cmdParam.code, code, _T("cmd"));
|
|
|
|
- parse_pair_key(cmdParam.param, param, _T("param"));
|
|
|
|
|
|
+ ParseKeyValuePairs(cmdParam.name, name, _T("name"));
|
|
|
|
+ ParseKeyValuePairs(cmdParam.head, head, _T("head"));
|
|
|
|
+ ParseKeyValuePairs(cmdParam.code, code, _T("cmd"));
|
|
|
|
+ ParseKeyValuePairs(cmdParam.param, param, _T("param"));
|
|
|
|
|
|
std::string value;
|
|
std::string value;
|
|
- parse_pair_key(value, option, _T("option"));
|
|
|
|
|
|
+ ParseKeyValuePairs(value, option, _T("option"));
|
|
if (!_tcsicmp(value.c_str(), _T("None")))
|
|
if (!_tcsicmp(value.c_str(), _T("None")))
|
|
cmdParam.nOption = CMDOPT_None;
|
|
cmdParam.nOption = CMDOPT_None;
|
|
else if (!_tcsicmp(value.c_str(), _T("Get")))
|
|
else if (!_tcsicmp(value.c_str(), _T("Get")))
|
|
@@ -215,14 +215,14 @@ bool TCLCommand::ParseCommandFromString(std::string str, CommandParam &cmdParam)
|
|
else if (!_tcsicmp(value.c_str(), _T("Set")))
|
|
else if (!_tcsicmp(value.c_str(), _T("Set")))
|
|
cmdParam.nOption = CMDOPT_Set;
|
|
cmdParam.nOption = CMDOPT_Set;
|
|
|
|
|
|
- parse_pair_key(value, multicode, _T("returnParam"));
|
|
|
|
|
|
+ ParseKeyValuePairs(value, multicode, _T("returnParam"));
|
|
cmdParam.returnParam = !_tcsicmp(value.c_str(), _T("true")) ? true : false;
|
|
cmdParam.returnParam = !_tcsicmp(value.c_str(), _T("true")) ? true : false;
|
|
|
|
|
|
- parse_pair_key(value, read_wait_time, _T("readWaitTime"));
|
|
|
|
- cmdParam.read_wait_time = pares_time_value(value.c_str());
|
|
|
|
|
|
+ ParseKeyValuePairs(value, read_wait_time, _T("readWaitTime"));
|
|
|
|
+ cmdParam.read_wait_time = ParseTimeValue(value.c_str());
|
|
|
|
|
|
- parse_pair_key(value, cmd_wait_time, _T("cmdWaitTime"));
|
|
|
|
- cmdParam.cmd_wait_time = pares_time_value(value.c_str());
|
|
|
|
|
|
+ ParseKeyValuePairs(value, cmd_wait_time, _T("cmdWaitTime"));
|
|
|
|
+ cmdParam.cmd_wait_time = ParseTimeValue(value.c_str());
|
|
cmdParam.UpdateRtnCode();
|
|
cmdParam.UpdateRtnCode();
|
|
|
|
|
|
return true;
|
|
return true;
|
|
@@ -534,7 +534,7 @@ bool TCLCommand::TheSecondPartForFC(CommandParam& cmdPara, std::string data)
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
-void TCLCommand::PackingCommand(CommandParam& cmdPara, LPVOID data, const int& dataLen)
|
|
|
|
|
|
+void TCLCommand::PackingCommand(CommandParam& cmdPara, LPCVOID data, const int& dataLen)
|
|
{
|
|
{
|
|
// Tag:[命令头][全命令长度][命令码]<命令码参数><附加数据>[crc1][crc2]
|
|
// Tag:[命令头][全命令长度][命令码]<命令码参数><附加数据>[crc1][crc2]
|
|
std::string command;
|
|
std::string command;
|
|
@@ -658,7 +658,7 @@ bool TCLCommand::SendCommand(CommandParam& cmdPara)
|
|
return cmdPara._rtnStatus == 0x0A ? true : false;
|
|
return cmdPara._rtnStatus == 0x0A ? true : false;
|
|
}
|
|
}
|
|
|
|
|
|
-bool TCLCommand::SendCommand(std::string name, CommandParam& cmdPara, LPVOID data /* = NULL */, int dataLen /* = 0 */)
|
|
|
|
|
|
+bool TCLCommand::SendCommand(std::string name, CommandParam& cmdPara, LPCVOID data /* = NULL */, int dataLen /* = 0 */)
|
|
{
|
|
{
|
|
if ( !GetCommandParams(name, cmdPara) )
|
|
if ( !GetCommandParams(name, cmdPara) )
|
|
return false;
|
|
return false;
|
|
@@ -671,12 +671,12 @@ void TCLCommand::SetInternalCMDParams(DWORD dwResouceID)
|
|
std::string data;
|
|
std::string data;
|
|
if ( utils::GetResourceData(dwResouceID, _T("BIN"), data) )
|
|
if ( utils::GetResourceData(dwResouceID, _T("BIN"), data) )
|
|
{
|
|
{
|
|
- parse_cmds_from_string(data, m_vtInternalCMDParams);
|
|
|
|
|
|
+ ParseCommandsFromString(data, m_vtInternalCMDParams);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void TCLCommand::SetExternalCMDParams(LPCTSTR lpFileName)
|
|
void TCLCommand::SetExternalCMDParams(LPCTSTR lpFileName)
|
|
{
|
|
{
|
|
m_vtExternalCMDParams.clear();
|
|
m_vtExternalCMDParams.clear();
|
|
- parse_cmds_from_file(lpFileName, m_vtExternalCMDParams);
|
|
|
|
|
|
+ ParseCommandsFromFile(lpFileName, m_vtExternalCMDParams);
|
|
}
|
|
}
|