📄 rtsetupdlg.cpp
字号:
// RTSetupDlg.cpp : implementation file
//
#include "stdafx.h"
#include "sf1553.h"
#include "RTSetupDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRTSetupDlg dialog
static int oldrt=0, oldsa=0;
static DWORD tpdwRTSel=0;
static BOOL tpblRT_ClearTTagOnSync=FALSE;
static BOOL tpblRT_LoadTTagOnSync=FALSE;
static RT_STATUS_WORD_STRUCT tpstStatusWord[RT_ADDR_MAX];
static RT_TX_MODE_STRUCT tpstRTTxMode={0};
static BOOL tpblEnIllCmdTable=FALSE;
static WORD tpwdVctWord[RT_ADDR_MAX];
static WORD tpwdBitWord[RT_ADDR_MAX];
static RT_Illegal_CMD_TABLE_STRUCT tpstIllCmdTable={0};
static BOOL tpblEnIllRxData=TRUE;
CRTSetupDlg::CRTSetupDlg(CWnd* pParent /*=NULL*/)
: CDialog(CRTSetupDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CRTSetupDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CRTSetupDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRTSetupDlg)
DDX_Control(pDX, IDC_IDC_RTS_BT_DEALLRT, m_btDEAllRt);
DDX_Control(pDX, IDC_IDC_RTS_BT_ENALLRT, m_btEnAllRt);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRTSetupDlg, CDialog)
//{{AFX_MSG_MAP(CRTSetupDlg)
ON_BN_CLICKED(IDC_RTS_BT_LOADF, OnRtsBtLoadf)
ON_BN_CLICKED(IDC_RTS_BT_SAVEF, OnRtsBtSavef)
ON_CBN_SELCHANGE(IDC_RTS_CB_RTSEL, OnSelchangeRtsCbRtsel)
ON_BN_CLICKED(IDC_RTS_BT_ALLSETT, OnRtsBtAllsett)
ON_BN_CLICKED(IDC_RTS_BT_ALLSETR, OnRtsBtAllsetr)
ON_BN_CLICKED(IDC_RTS_BT_ALLCLR, OnRtsBtAllclr)
ON_BN_CLICKED(IDC_RTS_BT_ALLSETTR, OnRtsBtAllsettr)
ON_CBN_SELCHANGE(IDC_RTS_CB_SASEL, OnSelchangeRtsCbSasel)
ON_BN_CLICKED(IDC_RTS_CK_ALLRTSAME, OnRtsCkAllrtsame)
ON_BN_CLICKED(IDC_RTS_CK_ALLSASAME, OnRtsCkAllsasame)
ON_EN_KILLFOCUS(IDC_RTS_ED_SFTWORD, OnKillfocusRtsEdSftword)
ON_EN_KILLFOCUS(IDC_RTS_ED_VCTWORD, OnKillfocusRtsEdVctword)
ON_EN_CHANGE(IDC_RTS_ED_VCTWORD, OnChangeRtsEdVctword)
ON_EN_CHANGE(IDC_RTS_ED_SFTWORD, OnChangeRtsEdSftword)
ON_BN_CLICKED(IDC_IDC_RTS_BT_ENALLRT, OnIdcRtsBtEnallrt)
ON_BN_CLICKED(IDC_IDC_RTS_BT_DEALLRT, OnIdcRtsBtDeallrt)
ON_BN_CLICKED(IDC_RTS_CK_ENRT, OnRtsCkEnrt)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRTSetupDlg message handlers
BOOL CRTSetupDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
int i=0, j=0, k=0;
char c[80];
/////////////////////////////
// Init GUI
// RT Addr Sel
ComboBox_ResetContent(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_RTSEL));
for (i=0; i<RT_ADDR_MAX; i++)
{
itoa(i, c, 10);
ComboBox_AddString(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_RTSEL), TEXT(c));
}
// SA Addr Sel
ComboBox_ResetContent(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_SASEL));
for (i=0; i<RT_ADDR_MAX; i++)
{
itoa(i, c, 10);
ComboBox_AddString(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_SASEL), TEXT(c));
}
// RT Tx Mode
//
ComboBox_ResetContent(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_TXMODE));
ComboBox_AddString(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_TXMODE), TEXT("单缓冲"));
ComboBox_AddString(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_TXMODE), TEXT("循环缓冲"));
// Ill Cmd Table
for (i=0; i<32; i++)
{
ComboBox_ResetContent(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_ILL1+i));
ComboBox_AddString(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_ILL1+i), TEXT("合法"));
ComboBox_AddString(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_ILL1+i), TEXT("发(T)"));
ComboBox_AddString(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_ILL1+i), TEXT("接(R)"));
ComboBox_AddString(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_ILL1+i), TEXT("发/收"));
}
// Limit edit control Text length
//
Edit_LimitText(::GetDlgItem(this->m_hWnd, IDC_RTS_ED_VCTWORD), 4);
Edit_LimitText(::GetDlgItem(this->m_hWnd, IDC_RTS_ED_SFTWORD), 4);
oldrt = 0;
oldsa = 0;
/////////////////////////////
// resume Values
for (i=0; i<32; i++)
{
for (j=0; j<32; j++)
{
tpstRTTxMode.TxMode[i][j] = g_RTTxMode.TxMode[i][j];
}
}
tpdwRTSel = g_RTConf.dwRTSel;
tpblRT_ClearTTagOnSync = g_RTConf.blRT_ClearTTagOnSync;
tpblRT_LoadTTagOnSync = g_RTConf.blRT_LoadTTagOnSync;
for (i=0; i<RT_ADDR_MAX; i++)
{
tpstStatusWord[i].Busy = g_RTStatusWord[i].Busy;
tpstStatusWord[i].DBusCtl = g_RTStatusWord[i].DBusCtl;
tpstStatusWord[i].ServiceReq = g_RTStatusWord[i].ServiceReq;
tpstStatusWord[i].SubSystemFlag = g_RTStatusWord[i].SubSystemFlag;
tpstStatusWord[i].TerminalFlag = g_RTStatusWord[i].TerminalFlag;
}
tpblEnIllCmdTable = g_RTConf.blEnIllCmdTable;
for (i=0; i<RT_ADDR_MAX; i++)
{
tpwdVctWord[i] = g_RTConf.wdVctWord[i];
tpwdBitWord[i] = g_RTConf.wdBitWord[i];
}
for (i=0; i<32; i++)
{
for (j=0; j<2; j++)
{
for (k=0; k<32; k++)
{
tpstIllCmdTable.CmdTable[i][j][k] = g_RTConf.stIllCmdTable.CmdTable[i][j][k];
}
}
}
tpblEnIllRxData = g_RTConf.blEnIllRxData;
this->ShowConf();
tpdwRTSel = tpdwRTSel&0x7FFFFFFF;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CRTSetupDlg::ShowConf()
{
char c[80];
int i=0, j=0, k=0, n=0;
DWORD dwr=0, dwt=0;
DWORD rta=0x00000001;
// RT Sel
ComboBox_SetCurSel(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_RTSEL), oldrt);
// SA Sel
ComboBox_SetCurSel(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_SASEL), oldsa);
// RT Addr Enabled
rta = rta<<oldrt;
if ((tpdwRTSel&rta)==rta)
{
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_ENRT), BST_CHECKED);
}
else
{
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_ENRT), BST_UNCHECKED);
}
// Clear Time tag on Sync
if (tpblRT_ClearTTagOnSync)
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_SYNCCTAG), BST_CHECKED);
else
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_SYNCCTAG), BST_UNCHECKED);
// Load Time tag on Sync
if (tpblRT_LoadTTagOnSync)
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_SYNCLTAG), BST_CHECKED);
else
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_SYNCLTAG), BST_UNCHECKED);
// Enable Ill Cmd Table
if (tpblEnIllCmdTable)
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_ENILLCMD), BST_CHECKED);
else
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_ENILLCMD), BST_UNCHECKED);
// Enable Ill Rx Data
if (tpblEnIllRxData)
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_ENILLRD), BST_CHECKED);
else
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_ENILLRD), BST_UNCHECKED);
// RT Tx Mode
ComboBox_SetCurSel(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_TXMODE), tpstRTTxMode.TxMode[oldrt][oldsa]);
// Vector Word
sprintf(c, "%04x", tpwdVctWord[oldrt]);
::SetWindowText(::GetDlgItem(this->m_hWnd, IDC_RTS_ED_VCTWORD), c);
// Bit Word
sprintf(c, "%04x", tpwdBitWord[oldrt]);
::SetWindowText(::GetDlgItem(this->m_hWnd, IDC_RTS_ED_SFTWORD), c);
// RT Status Set
//
if (tpstStatusWord[oldrt].Busy) // busy
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_STBUSY), BST_CHECKED);
else
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_STBUSY), BST_UNCHECKED);
if (tpstStatusWord[oldrt].DBusCtl) // bus control
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_STDYNBUS), BST_CHECKED);
else
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_STDYNBUS), BST_UNCHECKED);
if (tpstStatusWord[oldrt].ServiceReq) // service
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_STSVR), BST_CHECKED);
else
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_STSVR), BST_UNCHECKED);
if (tpstStatusWord[oldrt].SubSystemFlag) // sub system flag
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_STSUBSYS), BST_CHECKED);
else
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_STSUBSYS), BST_UNCHECKED);
if (tpstStatusWord[oldrt].TerminalFlag) // terminal flag
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_STTMIFLAG), BST_CHECKED);
else
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_STTMIFLAG), BST_UNCHECKED);
// Ill Cmd Table
//
dwr = tpstIllCmdTable.CmdTable[oldrt][0][oldsa]; // Rx
dwt = tpstIllCmdTable.CmdTable[oldrt][1][oldsa]; // Tx
for (i=0; i<32; i++)
{
if (((dwr&0x00000001)==0x00000001)&&((dwt&0x00000001)==0x00000001)) // Rx & Tx Ill
{
ComboBox_SetCurSel(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_ILL1+i), 3);
}
else
{
if (((dwr&0x00000001)!=0x00000001)&&((dwt&0x00000001)!=0x00000001)) // Rx & Tx unIll
{
ComboBox_SetCurSel(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_ILL1+i), 0);
}
else
{
if ((dwr&0x00000001)==0x00000001) // Rx Ill
{
ComboBox_SetCurSel(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_ILL1+i), 2);
}
else // Tx Ill
{
ComboBox_SetCurSel(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_ILL1+i), 1);
}
} // end of // Rx & Tx unIll
} // end of // Rx & Tx Ill
dwr = dwr>>1;
dwt = dwt>>1;
} // end of for (i=0; i<32; i++)
if (oldrt==31)
{
::EnableWindow(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_ENRT), FALSE);
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_ENRT), BST_UNCHECKED);
}
else
{
::EnableWindow(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_ENRT), TRUE);
}
tpdwRTSel = tpdwRTSel&0x7FFFFFFF;
if (tpdwRTSel == 0x7FFFFFFF)
{
this->m_btEnAllRt.EnableWindow(FALSE);
this->m_btDEAllRt.EnableWindow(TRUE);
}
else if (tpdwRTSel == 0x00000000)
{
this->m_btEnAllRt.EnableWindow(TRUE);
this->m_btDEAllRt.EnableWindow(FALSE);
}
else
{
this->m_btEnAllRt.EnableWindow(TRUE);
this->m_btDEAllRt.EnableWindow(TRUE);
}
if (this->AlltoSameCheck()==0)
{
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_ALLRTSAME), BST_CHECKED);
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_ALLSASAME), BST_CHECKED);
}
}
int CRTSetupDlg::AlltoSameCheck()
{
unsigned long base=tpstIllCmdTable.CmdTable[0][0][0];
int i=0, j=0, k=0;
//int rt=0;
// check all same
//
for (i=0; i<32; i++)
{
for (j=0; j<2; j++)
{
for (k=0; k<32; k++)
{
if (base != tpstIllCmdTable.CmdTable[i][j][k])
{
//rt = -1;
//k =32;
//j=2;
//i=32;
return -1;
}
}
}
}
/*
// check rt same
//
base = tpstIllCmdTable.CmdTable[0][j][oldsa];
for (i=0; i<32; i++)
{
for (j=0; j<2; j++)
{
if (base != tpstIllCmdTable.CmdTable[i][j][oldsa])
{
}
}
}
// check sa same
//
base = tpstIllCmdTable.CmdTable[oldrt][j][0];
for (j=0; j<2; j++)
{
for (k=0; k<32; k++)
{
if (base != tpstIllCmdTable.CmdTable[oldrt][j][k])
{
}
}
}
*/
return 0; // all same
}
void CRTSetupDlg::OnRtsBtLoadf()
{
// TODO: Add your control notification handler code here
FILE *pf;
CString strpath;
char flag[8];
memset(flag, 0, sizeof(flag));
CFileDialog OpenDlg(TRUE, TEXT(".rts"), TEXT("RT Cfg.rts"),
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
TEXT("RT配置文件 (*.rts)|*.rts||"), NULL);
if ((OpenDlg.DoModal())!=IDOK)
{
return;
}
strpath = OpenDlg.GetPathName(); // create file
pf = fopen(strpath, "r+b");
if (pf==NULL)
{
MessageBox("打开文件失败!", "错误", MB_OK | MB_ICONERROR);
return;
}
if (fread(flag, sizeof(char), 4, pf)!=4) // read message Head flag
{
fclose(pf);
MessageBox("加载RT数据配置文件失败!", "错误", MB_OK | MB_ICONERROR);
return;
}
else
{
if (strcmp(flag, "RTST")!=0)
{
fclose(pf);
MessageBox("非RT数据配置文件类型!", "错误", MB_OK | MB_ICONERROR);
return;
}
}
fread(&tpstRTTxMode, sizeof(tpstRTTxMode), 1, pf);
fread(&tpblRT_ClearTTagOnSync, sizeof(tpblRT_ClearTTagOnSync), 1, pf);
fread(&tpblRT_LoadTTagOnSync, sizeof(tpblRT_LoadTTagOnSync), 1, pf);
fread(tpstStatusWord, sizeof(tpstStatusWord), 1, pf);
fread(&tpblEnIllCmdTable, sizeof(tpblEnIllCmdTable), 1, pf);
fread(tpwdVctWord, sizeof(tpwdVctWord), 1, pf);
fread(tpwdBitWord, sizeof(tpwdBitWord), 1, pf);
fread(&tpstIllCmdTable, sizeof(tpstIllCmdTable), 1, pf);
fclose(pf); // close file
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_ALLRTSAME), BST_UNCHECKED);
Button_SetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_ALLSASAME), BST_UNCHECKED);
this->ShowConf();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -