|
@@ -190,20 +190,36 @@ void TCLCommand::parse_cmds_from_string(std::string str, std::vector<CommandPara
|
|
|
int nPos2 = str.find_first_of('\n');
|
|
|
if ( std::string::npos != nPos1 && std::string::npos != nPos2 ) {
|
|
|
nPos = nPos1 > nPos2 ? nPos1 : nPos2;
|
|
|
+#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
+ sprintf(buf, _T("%s"), str.substr(0, nPos - 1).c_str());
|
|
|
+#elif _MSC_VER >= 1500
|
|
|
_stprintf_s(buf, _T("%s"), str.substr(0, nPos - 1).c_str());
|
|
|
+#endif
|
|
|
str = str.substr(nPos+1);
|
|
|
}
|
|
|
else if ( std::string::npos != nPos1 ) {
|
|
|
+#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
+ sprintf(buf, _T("%s"), str.substr(0, nPos1 - 1).c_str());
|
|
|
+#elif _MSC_VER >= 1500
|
|
|
_stprintf_s(buf, _T("%s"), str.substr(0, nPos1 - 1).c_str());
|
|
|
+#endif
|
|
|
str = str.substr(nPos + 1);
|
|
|
}
|
|
|
else if ( std::string::npos != nPos2 ) {
|
|
|
+#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
+ sprintf(buf, _T("%s"), str.substr(0, nPos2 - 1).c_str());
|
|
|
+#elif _MSC_VER >= 1500
|
|
|
_stprintf_s(buf, _T("%s"), str.substr(0, nPos2 - 1).c_str());
|
|
|
+#endif
|
|
|
str = str.substr(nPos + 1);
|
|
|
}
|
|
|
else {
|
|
|
+#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
+ sprintf(buf, _T("%s"), str.c_str());
|
|
|
+#elif _MSC_VER >= 1500
|
|
|
_stprintf_s(buf, _T("%s"), str.c_str());
|
|
|
- str.clear();
|
|
|
+#endif
|
|
|
+ str = "";
|
|
|
}
|
|
|
|
|
|
#if _MSC_VER >= 1200 && _MSC_VER < 1500 // VC6.0~8.0
|
|
@@ -281,7 +297,11 @@ bool TCLCommand::TheFirstPart(CommandParam& cmdPara, std::string data)
|
|
|
// 长度;
|
|
|
int nPacketLen = (byte)data[1];
|
|
|
if (nPacketLen != NoneOptLen) {
|
|
|
+#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
+ cmdPara._rtnError = utils::_dprintf("[%s] 返回数据长度错误:%ld", (byte)data[1]);
|
|
|
+#elif _MSC_VER >= 1500
|
|
|
cmdPara._rtnError = utils::_dprintf("[%s] 返回数据长度错误:%ld", __FUNCTION__, (byte)data[1]);
|
|
|
+#endif
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -292,17 +312,29 @@ bool TCLCommand::TheFirstPart(CommandParam& cmdPara, std::string data)
|
|
|
// 校验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]) {
|
|
|
+#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
+ cmdPara._rtnError = utils::_dprintf("CRC校验错误:计算[%02% %02X] != 接收[%02X %02X]", (usCRCValue >> 8) & 0xFF, usCRCValue & 0xFF, (byte)data[nPacketLen - 2], (byte)data[nPacketLen - 1]);
|
|
|
+#elif _MSC_VER >= 1500
|
|
|
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;
|
|
|
+#endif
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
+#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
+ cmdPara._rtnError = utils::_dprintf("返回码错误:%02X", (byte)data[0]);
|
|
|
+#elif _MSC_VER >= 1500
|
|
|
cmdPara._rtnError = utils::_dprintf("[%s] 返回码错误:%02X", __FUNCTION__, (byte)data[0]);
|
|
|
+#endif
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
+#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
+ cmdPara._rtnError = utils::_dprintf("返回数据长度错误", (byte)data[0]);
|
|
|
+#elif _MSC_VER >= 1500
|
|
|
cmdPara._rtnError = utils::_dprintf("[%s] 返回数据长度错误", __FUNCTION__);
|
|
|
+#endif
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -321,7 +353,11 @@ bool TCLCommand::TheSecondPart(CommandParam& cmdPara, std::string data)
|
|
|
nDataPos = 4;
|
|
|
nPacketLen = (byte)data[2] << 8 | (byte)data[3];
|
|
|
if (data.size() < 255 && data[2] != 0) {
|
|
|
+#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
+ cmdPara._rtnError = utils::_dprintf(_T("返回数据长度异常"));
|
|
|
+#elif _MSC_VER >= 1500
|
|
|
cmdPara._rtnError = utils::_dprintf(_T("[%s] 返回数据长度异常"), __FUNCTION__);
|
|
|
+#endif
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
@@ -345,7 +381,11 @@ bool TCLCommand::TheSecondPart(CommandParam& cmdPara, std::string data)
|
|
|
#endif
|
|
|
|
|
|
if (_tcsicmp(cmdPara.code.c_str(), utils::ByteToChars((byte)data[nDataPos] - 1).c_str()) != 0) {
|
|
|
+#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
+ cmdPara._rtnError = utils::_dprintf(_T("返回的指令错误, %s, %02X"), cmdPara.head.c_str(), (byte)data[nDataPos]);
|
|
|
+#elif _MSC_VER >= 1500
|
|
|
cmdPara._rtnError = utils::_dprintf(_T("[%s] 返回的指令错误, %s, %02X"), __FUNCTION__, cmdPara.head.c_str(), (byte)data[nDataPos]);
|
|
|
+#endif
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -353,8 +393,12 @@ bool TCLCommand::TheSecondPart(CommandParam& cmdPara, std::string data)
|
|
|
++nDataPos;// 返回码占一字节;
|
|
|
if (cmdPara.bMulticode) {
|
|
|
if (_tcsicmp(cmdPara.param.c_str(), utils::ByteToChars((byte)data[nDataPos]).c_str()) != 0) {
|
|
|
+#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
+ cmdPara._rtnError = utils::_dprintf(_T("返回的指令参数错误, %s, %02X"), cmdPara.param.c_str(), (byte)data[nDataPos]);
|
|
|
+#elif _MSC_VER >= 1500
|
|
|
cmdPara._rtnError = utils::_dprintf(_T("[%s] 返回的指令参数错误, %s, %02X"), __FUNCTION__, cmdPara.param.c_str(), (byte)data[nDataPos]);
|
|
|
- return false;
|
|
|
+#endif
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
++nDataPos;// 指令参数码占一字节;
|
|
@@ -367,15 +411,27 @@ bool TCLCommand::TheSecondPart(CommandParam& cmdPara, std::string data)
|
|
|
unsigned short usCRCValue = utils::CRC16Calculate((byte*)data.data(), nPacketLen - 2);
|
|
|
if (((usCRCValue >> 8) & 0xFF) != (byte)data[nPacketLen - 2] || (usCRCValue & 0xFF) != (byte)data[nPacketLen - 1])
|
|
|
{
|
|
|
+#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
+ cmdPara._rtnError = utils::_dprintf("CRC校验错误:计算[%02X %02X] != 接收[%02X %02X]", (usCRCValue >> 8) & 0xFF, usCRCValue & 0xFF, (byte)data[nPacketLen - 2], (byte)data[nPacketLen - 1]);
|
|
|
+#elif _MSC_VER >= 1500
|
|
|
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;
|
|
|
+#endif
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
if (data.size() > nPacketLen)
|
|
|
+#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
+ utils::_dprintf(_T("带有脏数据:%s"), data.substr(nPacketLen));
|
|
|
+#elif _MSC_VER >= 1500
|
|
|
utils::_dprintf("[%s] 带有脏数据:%s", __FUNCTION__, data.substr(nPacketLen));
|
|
|
+#endif
|
|
|
}
|
|
|
else {
|
|
|
- cmdPara._rtnError = utils::_dprintf("[%s] 返回码错误:%02X", __FUNCTION__, (byte)data[0]);
|
|
|
+#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
+ cmdPara._rtnError = utils::_dprintf("返回码错误:%02X", (byte)data[0]);
|
|
|
+#elif _MSC_VER >= 1500
|
|
|
+ cmdPara._rtnError = utils::_dprintf("[%s] 返回码错误:%02X", __FUNCTION__, (byte)data[0]);
|
|
|
+#endif
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -445,7 +501,11 @@ void TCLCommand::ParseResultString(CommandParam& cmdPara, std::string data, cons
|
|
|
return;
|
|
|
|
|
|
if (cmdPara._rtnStatus != 0x0A) {
|
|
|
+#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
+ utils::_dprintf("执行结果错误:%02X", cmdPara._rtnStatus);
|
|
|
+#elif _MSC_VER >= 1500
|
|
|
utils::_dprintf("[%s] 执行结果错误:%02X", __FUNCTION__, cmdPara._rtnStatus);
|
|
|
+#endif
|
|
|
return;
|
|
|
}
|
|
|
|