|
@@ -124,6 +124,7 @@ BEGIN_MESSAGE_MAP(CTCLToolsDlg, CDialog)
|
|
|
ON_BN_CLICKED(BTN_EXEC_CMD2, &CTCLToolsDlg::OnBnClickedExecCmd2)
|
|
|
ON_BN_CLICKED(BTN_EXEC_CMD3, &CTCLToolsDlg::OnBnClickedExecCmd3)
|
|
|
ON_BN_CLICKED(BTN_EXEC_CMD4, &CTCLToolsDlg::OnBnClickedExecCmd4)
|
|
|
+ ON_BN_CLICKED(IDC_CHECK_USEFILE, &CTCLToolsDlg::OnBnClickedCheckUsefile)
|
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
|
|
@@ -498,41 +499,63 @@ void CTCLToolsDlg::ExecuteCommand(CString strCMDName)
|
|
|
CString strText;
|
|
|
bool bStatus = false;
|
|
|
CommandParam cmdpara;
|
|
|
+ BOOL bCheckUseFile = ((CButton*)GetDlgItem(IDC_CHECK_USEFILE))->GetCheck();
|
|
|
g_tclCommand.GetCommandParams(strCMDName.GetString(), cmdpara);
|
|
|
if ( cmdpara.nOption == CMDOPT_Write)
|
|
|
{
|
|
|
- // 需要选择文件;
|
|
|
GetDlgItemText(IDC_EDIT_KEY, strText);
|
|
|
- if ( !PathFileExists(strText) )
|
|
|
- {
|
|
|
- if ( MessageBox("Set指令没有选择Key文件,是否继续?", "警告!", MB_ICONWARNING|MB_YESNO) == IDNO )
|
|
|
- return;
|
|
|
- bStatus = g_tclCommand.SendCommand(strCMDName.GetString(), cmdpara);
|
|
|
+ if ( bCheckUseFile )
|
|
|
+ {// 使用key文件;
|
|
|
+ if ( !PathFileExists(strText) )
|
|
|
+ {
|
|
|
+ if ( MessageBox("Set指令没有选择Key文件,是否继续?", "警告!", MB_ICONWARNING|MB_YESNO) == IDNO )
|
|
|
+ return;
|
|
|
+ // 发送空key指令;
|
|
|
+ bStatus = g_tclCommand.SendCommand(strCMDName.GetString(), cmdpara);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::string data;
|
|
|
+ if ( ReadKeyFromFile(strText.GetString(), data) )
|
|
|
+ {
|
|
|
+ // 默认读取内容;
|
|
|
+ BOOL bCheckHB = ((CButton*)GetDlgItem(IDC_CHECK_HB))->GetCheck();
|
|
|
+ BOOL bCheckBH = ((CButton*)GetDlgItem(IDC_CHECK_BH))->GetCheck();
|
|
|
+ if ( !bCheckBH && !bCheckHB )
|
|
|
+ {// 原始文件内容;
|
|
|
+ g_tclCommand.SendCommand(strCMDName.GetString(), cmdpara, (LPVOID)data.c_str(), data.size());
|
|
|
+ }
|
|
|
+ else if ( !bCheckBH && bCheckHB )
|
|
|
+ {// 将文件内容按十六进制转字节;
|
|
|
+ // 去除所有空格;
|
|
|
+ utils::trim(data);
|
|
|
+ std::string strBytes = utils::HexStringToBytes(data,2);
|
|
|
+ g_tclCommand.SendCommand(strCMDName.GetString(), cmdpara, (LPVOID)strBytes.c_str(), strBytes.size());
|
|
|
+ }
|
|
|
+ else if ( bCheckBH && !bCheckHB )
|
|
|
+ {// 将文件内容按字节转十六进制;
|
|
|
+ std::string strBytes = utils::BytesToHexString((const unsigned char *)data.c_str(), data.size());
|
|
|
+ g_tclCommand.SendCommand(strCMDName.GetString(), cmdpara, (LPVOID)strBytes.c_str(), strBytes.size());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
- {
|
|
|
- std::string data;
|
|
|
- if ( ReadKeyFromFile(strText.GetString(), data) )
|
|
|
+ {// 使用十六进制字符串;
|
|
|
+ if ( strText.IsEmpty() )
|
|
|
{
|
|
|
- // 默认读取内容;
|
|
|
- BOOL bCheckHB = ((CButton*)GetDlgItem(IDC_CHECK_HB))->GetCheck();
|
|
|
- BOOL bCheckBH = ((CButton*)GetDlgItem(IDC_CHECK_BH))->GetCheck();
|
|
|
- if ( !bCheckBH && !bCheckHB )
|
|
|
- {// 原始文件内容;
|
|
|
- g_tclCommand.SendCommand(strCMDName.GetString(), cmdpara, (LPVOID)data.c_str(), data.size());
|
|
|
- }
|
|
|
- else if ( !bCheckBH && bCheckHB )
|
|
|
- {// 将文件内容按十六进制转字节;
|
|
|
- // 去除所有空格;
|
|
|
- utils::trim(data);
|
|
|
- std::string strBytes = utils::HexStringToBytes(data,2);
|
|
|
- g_tclCommand.SendCommand(strCMDName.GetString(), cmdpara, (LPVOID)strBytes.c_str(), strBytes.size());
|
|
|
- }
|
|
|
- else if ( bCheckBH && !bCheckHB )
|
|
|
- {// 将文件内容按字节转十六进制;
|
|
|
- std::string strBytes = utils::BytesToHexString((const unsigned char *)data.c_str(), data.size());
|
|
|
- g_tclCommand.SendCommand(strCMDName.GetString(), cmdpara, (LPVOID)strBytes.c_str(), strBytes.size());
|
|
|
- }
|
|
|
+ if ( MessageBox("Set指令没有输入十六进制字符,是否继续?", "警告!", MB_ICONWARNING|MB_YESNO) == IDNO )
|
|
|
+ return;
|
|
|
+ // 发送空key指令;
|
|
|
+ bStatus = g_tclCommand.SendCommand(strCMDName.GetString(), cmdpara);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::string data = strText;
|
|
|
+ // 去除所有空格;
|
|
|
+ utils::trim(data);
|
|
|
+ std::string strBytes = utils::HexStringToBytes(data,2);
|
|
|
+ g_tclCommand.SendCommand(strCMDName.GetString(), cmdpara, (LPVOID)strBytes.c_str(), strBytes.size());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -593,4 +616,14 @@ void CTCLToolsDlg::ExecuteCommand(CString strCMDName)
|
|
|
{
|
|
|
MessageBox("串口未打开", "错误!", MB_ICONEXCLAMATION);
|
|
|
}
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+void CTCLToolsDlg::OnBnClickedCheckUsefile()
|
|
|
+{
|
|
|
+ // TODO: 在此添加控件通知处理程序代码
|
|
|
+ BOOL bCheck = ((CButton*)GetDlgItem(IDC_CHECK_USEFILE))->GetCheck();
|
|
|
+ GetDlgItem(IDC_EDIT_KEY)->EnableWindow(!bCheck);
|
|
|
+ GetDlgItem(BTN_OPEN_FILE)->ShowWindow(bCheck ? SW_SHOW : SW_HIDE);
|
|
|
+ GetDlgItem(IDC_CHECK_HB)->ShowWindow(bCheck ? SW_SHOW : SW_HIDE);
|
|
|
+ GetDlgItem(IDC_CHECK_BH)->ShowWindow(bCheck ? SW_SHOW : SW_HIDE);
|
|
|
+}
|