|
@@ -59,8 +59,7 @@ int pares_time_value(std::string strTime)
|
|
|
// 不带单位或其他的,默认ms;
|
|
|
nTimes = atol(strTime.c_str());
|
|
|
}
|
|
|
-#endif
|
|
|
-#if _MSC_VER >= 1500
|
|
|
+#elif _MSC_VER >= 1500
|
|
|
if ( _tcsstr(strTime.c_str(), _T("ms")) || _tcsstr(strTime.c_str(), _T("MS")))
|
|
|
{
|
|
|
nTimes = _tstol(strTime.c_str());
|
|
@@ -87,6 +86,7 @@ int parse_cmd_param_from_file(TCHAR *file_name, std::vector<CommandParam> &vtCom
|
|
|
{
|
|
|
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};
|
|
@@ -120,32 +120,39 @@ int parse_cmd_param_from_file(TCHAR *file_name, std::vector<CommandParam> &vtCom
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-#if _MSC_VER >= 1500
|
|
|
- //if ( _stscanf_s(buf, "%[^;];%[^;];%[^;];%[^;];%[^;];%[^;];%[^;]", name, MAX_PATH, head, MAX_PATH, code, MAX_PATH, param, MAX_PATH, multicode, MAX_PATH, read_wait_time, MAX_PATH, cmd_wait_time, MAX_PATH) == 7) // 等价下面;
|
|
|
- if ( _stscanf_s(buf, "%[^;];%[^;];%[^;];%[^;];%[^;];%[^;];%s", name, MAX_PATH, head, MAX_PATH, code, MAX_PATH, param, MAX_PATH, multicode, MAX_PATH, read_wait_time, MAX_PATH, cmd_wait_time, MAX_PATH) == 7)
|
|
|
-#endif
|
|
|
#if _MSC_VER >= 1200 && _MSC_VER < 1500 // VC6.0~8.0
|
|
|
- if ( sscanf(buf, "%[^;];%[^;];%[^;];%[^;];%[^;];%[^;];%[^;]", name, head, code, param, multicode, read_wait_time, cmd_wait_time) == 7)
|
|
|
+ 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_key(cp.name, name, _T("Name"));
|
|
|
- parse_key(cp.head, head, _T("HeadCode"));
|
|
|
- parse_key(cp.code, code, _T("Command"));
|
|
|
- parse_key(cp.param, param, _T("CMDParam"));
|
|
|
-
|
|
|
- std::string value;
|
|
|
- parse_key(value, multicode, _T("MultiParams"));
|
|
|
- cp.bMulticode = !_tcsicmp(value.c_str(), _T("true")) ? true : false;
|
|
|
-
|
|
|
- parse_key(value, read_wait_time, _T("ReadWaitTime"));
|
|
|
- cp.read_wait_time = pares_time_value(value.c_str());
|
|
|
-
|
|
|
- parse_key(value, cmd_wait_time, _T("CMDWaitTime"));
|
|
|
- cp.cmd_wait_time = pares_time_value(value.c_str());
|
|
|
-
|
|
|
- vtCommandParams.push_back(cp);
|
|
|
- }
|
|
|
+ {
|
|
|
+ CommandParam cp;
|
|
|
+ parse_key(cp.name, name, _T("Name"));
|
|
|
+ parse_key(cp.head, head, _T("HeadCode"));
|
|
|
+ parse_key(cp.code, code, _T("Command"));
|
|
|
+ parse_key(cp.param, param, _T("CMDParam"));
|
|
|
+
|
|
|
+ std::string value;
|
|
|
+ parse_key(value, option, _T("Option"));
|
|
|
+ if ( !_tcsicmp(value.c_str(), _T("None")) )
|
|
|
+ cp.nOption = 0;
|
|
|
+ else if (!_tcsicmp(value.c_str(), _T("Get")))
|
|
|
+ cp.nOption = 1;
|
|
|
+ else if (!_tcsicmp(value.c_str(), _T("Set")))
|
|
|
+ cp.nOption = 2;
|
|
|
+
|
|
|
+ parse_key(value, multicode, _T("MultiParams"));
|
|
|
+ cp.bMulticode = !_tcsicmp(value.c_str(), _T("true")) ? true : false;
|
|
|
+
|
|
|
+ parse_key(value, read_wait_time, _T("ReadWaitTime"));
|
|
|
+ cp.read_wait_time = pares_time_value(value.c_str());
|
|
|
+
|
|
|
+ parse_key(value, cmd_wait_time, _T("CMDWaitTime"));
|
|
|
+ cp.cmd_wait_time = pares_time_value(value.c_str());
|
|
|
+
|
|
|
+ vtCommandParams.push_back(cp);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
ret = 0;
|
|
@@ -200,11 +207,10 @@ std::string HexStringToBytes(std::string strHex, const int &len /* = 3 */)
|
|
|
int nSize = strHex.size();
|
|
|
for (int i = 0; i < nSize; i += len)
|
|
|
{
|
|
|
-#if _MSC_VER >=1500
|
|
|
- strBytes.push_back((char)TwoHexCharToInteger(strHex[i], strHex[i + 1]));
|
|
|
-#endif
|
|
|
#if _MSC_VER >=1200 && _MSC_VER < 1500
|
|
|
strBytes.append((char)TwoHexCharToInteger(strHex[i], strHex[i + 1]),1);
|
|
|
+#elif _MSC_VER >=1500
|
|
|
+ strBytes.push_back((char)TwoHexCharToInteger(strHex[i], strHex[i + 1]));
|
|
|
#endif
|
|
|
}
|
|
|
|
|
@@ -220,8 +226,7 @@ std::string BytesToHexString(const unsigned char *pbuffer, int nLen, char chSpac
|
|
|
memset(szhex, 0, 5);
|
|
|
#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
sprintf(szhex, "%02X%c", pbuffer[i], chSpace);
|
|
|
-#endif
|
|
|
-#if _MSC_VER >= 1500
|
|
|
+#elif _MSC_VER >= 1500
|
|
|
_stprintf_s(szhex, "%02X%c", pbuffer[i], chSpace);
|
|
|
#endif
|
|
|
hex.append(szhex);
|
|
@@ -240,8 +245,7 @@ std::string BytesToHexString(const unsigned char *pbuffer, int nLen)
|
|
|
|
|
|
#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
sprintf(szhex, "%02X", pbuffer[i]);
|
|
|
-#endif
|
|
|
-#if _MSC_VER >= 1500
|
|
|
+#elif _MSC_VER >= 1500
|
|
|
_stprintf_s(szhex, "%02X", pbuffer[i]);
|
|
|
#endif
|
|
|
hex.append(szhex);
|
|
@@ -255,11 +259,9 @@ BOOL IsValidString(LPCTSTR lpszString)
|
|
|
if (lpszString == NULL)
|
|
|
return FALSE;
|
|
|
|
|
|
- do
|
|
|
- {
|
|
|
+ do {
|
|
|
// ASCII可显示的字符;
|
|
|
- if (*lpszString < 32 || *lpszString > 126)
|
|
|
- {
|
|
|
+ if (*lpszString < 32 || *lpszString > 126) {
|
|
|
return FALSE;
|
|
|
}
|
|
|
} while (*++lpszString);
|
|
@@ -278,13 +280,12 @@ std::string &trim(std::string &str)
|
|
|
return str;
|
|
|
#endif
|
|
|
|
|
|
-#if _MSC_VER > 1900
|
|
|
- str.erase(std::remove_if(str.begin(), str.end(), [](unsigned char x) {return std::isspace(x); }), str.end()); //C++17
|
|
|
-#endif
|
|
|
#if _MSC_VER >= 1200 && _MSC_VER < 1600
|
|
|
for (std::string::iterator it = str.begin(); it != str.end();) {
|
|
|
!isspace(*it) ? it++ : it = it = str.erase(it);
|
|
|
}
|
|
|
+#elif _MSC_VER >= 1600
|
|
|
+ str.erase(std::remove_if(str.begin(), str.end(), [](unsigned char x) {return std::isspace(x); }), str.end()); //C++17
|
|
|
#endif
|
|
|
return str;
|
|
|
}
|
|
@@ -332,8 +333,8 @@ std::string PackingCommand(CommandParam &cmdPara, std::string data, const int &d
|
|
|
|
|
|
// crc校验;
|
|
|
byte szcrc[2] = {0};
|
|
|
- //WORD usCRCValue = CRC16Calculate((byte *)command.c_str(), command.size()); // 如果有0断开有危险;
|
|
|
- WORD usCRCValue = CRC16Calculate((byte *)command.c_str(), len - 2);
|
|
|
+ WORD usCRCValue = 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);
|