|
@@ -7,6 +7,33 @@
|
|
|
// TODO: 在 STDAFX.H 中
|
|
|
// 引用任何所需的附加头文件,而不是在此文件中引用
|
|
|
|
|
|
+VOID _dprintf(CHAR* pszStr, ...)
|
|
|
+{
|
|
|
+ const int LOGLEN = 3072;
|
|
|
+ char szData[LOGLEN] = { 0 };
|
|
|
+#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
+ sprintf(szData, _T("[%s %s]\n\t"), _T("Db"), CTime::GetCurrentTime().Format(_T("%H:%M:%S")));
|
|
|
+#elif _MSC_VER >= 1500
|
|
|
+ _stprintf_s(szData, _T("[%s %s]\n\t"), _T("Db"), CTime::GetCurrentTime().Format(_T("%H:%M:%S")).GetString());
|
|
|
+#endif
|
|
|
+ int len = strlen(szData);
|
|
|
+ va_list args;
|
|
|
+ va_start(args, pszStr);
|
|
|
+#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
+ _vsnprintf(szData + len, LOGLEN - len, pszStr, args);
|
|
|
+#elif _MSC_VER >= 1500
|
|
|
+ _vsntprintf_s(szData + len, LOGLEN - len, _TRUNCATE, pszStr, args);
|
|
|
+#endif
|
|
|
+ va_end(args);
|
|
|
+ if (szData[strlen(szData) - 1] != '\n')
|
|
|
+#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
+ strcat(szData, "\n");
|
|
|
+#elif _MSC_VER >= 1500
|
|
|
+ strcat_s(szData, "\n");
|
|
|
+#endif
|
|
|
+ OutputDebugStringA(szData);
|
|
|
+}
|
|
|
+
|
|
|
bool parse_key(std::string &RetValue, std::string strLine, TCHAR *lpszText)
|
|
|
{
|
|
|
TCHAR szText[MAX_PATH] = {0};
|
|
@@ -150,6 +177,7 @@ int parse_cmd_param_from_file(TCHAR *file_name, std::vector<CommandParam> &vtCom
|
|
|
|
|
|
parse_key(value, cmd_wait_time, _T("CMDWaitTime"));
|
|
|
cp.cmd_wait_time = pares_time_value(value.c_str());
|
|
|
+ cp.UpdateRtnCode();
|
|
|
|
|
|
vtCommandParams.push_back(cp);
|
|
|
}
|
|
@@ -254,6 +282,19 @@ std::string BytesToHexString(const unsigned char *pbuffer, int nLen)
|
|
|
return hex;
|
|
|
}
|
|
|
|
|
|
+std::string ByteToChars(byte b)
|
|
|
+{
|
|
|
+ char szhex[3] = { 0 };
|
|
|
+
|
|
|
+#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
+ sprintf(szhex, "%02X", b);
|
|
|
+#elif _MSC_VER >= 1500
|
|
|
+ _stprintf_s(szhex, "%02X", b);
|
|
|
+#endif
|
|
|
+
|
|
|
+ return std::string(szhex);
|
|
|
+}
|
|
|
+
|
|
|
BOOL IsValidString(LPCTSTR lpszString)
|
|
|
{
|
|
|
if (lpszString == NULL)
|
|
@@ -292,6 +333,7 @@ std::string &trim(std::string &str)
|
|
|
|
|
|
std::string PackingCommand(CommandParam &cmdPara, std::string data, const int &dataLen)
|
|
|
{
|
|
|
+ // Tag:[命令头][全命令长度][命令码]<命令码参数><附加数据>[crc1][crc2]
|
|
|
std::string command;
|
|
|
// 命令头标识位;
|
|
|
command.append(HexStringToBytes(cmdPara.head, 2).c_str(), cmdPara.head.size() / 2);
|
|
@@ -342,8 +384,48 @@ std::string PackingCommand(CommandParam &cmdPara, std::string data, const int &d
|
|
|
return command;
|
|
|
}
|
|
|
|
|
|
+#define NoneOptLen 5
|
|
|
+
|
|
|
+void TheFirstPart(CommandParam& cmdPara, std::string data, const int& dataLen)
|
|
|
+{
|
|
|
+ if (data.size() == NoneOptLen) {
|
|
|
+ if (data[0] == cmdPara._rtnCode) {
|
|
|
+ // 长度;
|
|
|
+ int nPackageLen = data[1];
|
|
|
+ if (nPackageLen != NoneOptLen) {
|
|
|
+ _dprintf("None长度错误:%ld", data[1]);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 执行状态;
|
|
|
+ cmdPara._rtnStatus = data[2];
|
|
|
+ _dprintf(_T("rtnStatus=%02X"), cmdPara._rtnStatus);
|
|
|
+
|
|
|
+ // 校验crc;
|
|
|
+ unsigned short usCRCValue = CRC16Calculate((unsigned char*)data.data(), nPackageLen - 2);
|
|
|
+ if (((usCRCValue >> 8) & 0xFF) != (unsigned char)data[nPackageLen - 2] || (usCRCValue & 0xFF) != (unsigned char)data[nPackageLen - 1])
|
|
|
+ {
|
|
|
+ _dprintf("CRC校验错误:计算[%02% %02X] != 接收[%02X %02X]", (usCRCValue >> 8) & 0xFF, usCRCValue & 0xFF, data[nPackageLen - 2], data[nPackageLen - 1]);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ _dprintf("返回码错误:%02X", data[0]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ _dprintf("长度对不上:Option.None");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void TheSecondPart(CommandParam& cmdPara, std::string data, const int& dataLen)
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
void ParseResultString(CommandParam& cmdPara, std::string data, const int& dataLen)
|
|
|
{
|
|
|
+ // Tag:[返回头][全数据长度][返回码]<返回码子项><附加数据>[crc1][crc2]
|
|
|
if ( data.size() < 5) {
|
|
|
return;
|
|
|
}
|
|
@@ -353,13 +435,58 @@ void ParseResultString(CommandParam& cmdPara, std::string data, const int& dataL
|
|
|
if ( !_tcsicmp(_T("AA"), head.c_str()) ) { // 调试用命令代码引导码;
|
|
|
rtnCode = 0xAB;
|
|
|
}
|
|
|
- else if (!_tcsicmp(_T("AC"), head.c_str())) {// 软件配屏参数调整命令代码引导码;
|
|
|
+ else if (!_tcsicmp(_T("AC"), head.c_str())) { // 软件配屏参数调整命令代码引导码;
|
|
|
rtnCode = 0xAD;
|
|
|
}
|
|
|
- else if (!_tcsicmp(_T("AE"), head.c_str())) {// 保留命令发送类型引导码;
|
|
|
+ else if (!_tcsicmp(_T("AE"), head.c_str())) { // 保留命令发送类型引导码;
|
|
|
rtnCode = 0xAF;
|
|
|
}
|
|
|
|
|
|
int nTakenLen = 0; // 已取出的长度;
|
|
|
unsigned short usCRCValue; // CRC验证值;
|
|
|
+ // 一个完整的包段;
|
|
|
+ int nPackageLen = 0;
|
|
|
+ std::string packaged;
|
|
|
+
|
|
|
+ // None可以看作是第一段数据包;
|
|
|
+ if ( cmdPara.nOption == CMDOPT::CMDOPT_None ) {
|
|
|
+ if ( data.size() == NoneOptLen) {
|
|
|
+ if (data[0] == rtnCode) {
|
|
|
+ if (data[1] == 0xFE) { // None中不应该出现,配置出错;
|
|
|
+ _dprintf("类型配置错误:%02X %02X", data[0], data[1]);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 长度;
|
|
|
+ nPackageLen = data[1];
|
|
|
+ if (nPackageLen != NoneOptLen) {
|
|
|
+ _dprintf("None长度错误:%ld", data[1]);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 执行状态;
|
|
|
+
|
|
|
+ // 校验crc;
|
|
|
+ usCRCValue = CRC16Calculate((unsigned char*)data.data(), nPackageLen - 2);
|
|
|
+ if (((usCRCValue >> 8) & 0xFF) != (unsigned char)data[nPackageLen - 2] || (usCRCValue & 0xFF) != (unsigned char)data[nPackageLen - 1])
|
|
|
+ {
|
|
|
+ _dprintf("CRC校验错误:计算[%02% %02X] != 接收[%02X %02X]", (usCRCValue >> 8) & 0xFF, usCRCValue & 0xFF, data[nPackageLen - 2], data[nPackageLen - 1]);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ _dprintf("返回码错误:%02X", data[0]);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ _dprintf("长度对不上:Option.None");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if ( cmdPara.nOption == CMDOPT::CMDOPT_Get )
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ else if ( cmdPara.nOption == CMDOPT::CMDOPT_Set )
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
}
|