⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtsetupdlg.cpp

📁 1553B板卡的源代码,只有购买板卡才能得到的好资料
💻 CPP
📖 第 1 页 / 共 3 页
字号:


	
}

void CRTSetupDlg::OnRtsBtSavef() 
{
	// TODO: Add your control notification handler code here
	FILE *pf;
	CString strpath;

	CFileDialog OpenDlg(FALSE, TEXT(".rts"), TEXT("RT Cfg.rts"), 
						OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, 
						TEXT("RT配置文件 (*.rts)|*.rts||"), NULL);

	if ((OpenDlg.DoModal())!=IDOK)
	{
		return;
	}

	this->OnSelchangeRtsCbRtsel();

	strpath = OpenDlg.GetPathName(); // create file
	pf = fopen(strpath, "w+b");
	if (pf==NULL)
	{
		MessageBox("创建文件失败!", "错误", MB_OK | MB_ICONERROR);
		return;
	}

	fwrite("RTST", sizeof(char), 4, pf); // write message Head flag

	fwrite(&tpstRTTxMode, sizeof(tpstRTTxMode), 1, pf);
	fwrite(&tpblRT_ClearTTagOnSync, sizeof(tpblRT_ClearTTagOnSync), 1, pf);
	fwrite(&tpblRT_LoadTTagOnSync, sizeof(tpblRT_LoadTTagOnSync), 1, pf);
	fwrite(tpstStatusWord, sizeof(tpstStatusWord), 1, pf);
	fwrite(&tpblEnIllCmdTable, sizeof(tpblEnIllCmdTable), 1, pf);
	fwrite(tpwdVctWord, sizeof(tpwdVctWord), 1, pf);
	fwrite(tpwdBitWord, sizeof(tpwdBitWord), 1, pf);
	fwrite(&tpstIllCmdTable, sizeof(tpstIllCmdTable), 1, pf);

	fclose(pf); // close file

	
}

void CRTSetupDlg::OnSelchangeRtsCbRtsel() 
{
	// TODO: Add your control notification handler code here
		char c[80];
	int i=0, j=0, k=0, n=0;
	DWORD dwr=0, dwt=0;
	int irt=0, isa=0;
	DWORD rta=0x00000001;

	// RT Sel
	irt = ComboBox_GetCurSel(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_RTSEL));

	// SA Sel
	isa = ComboBox_GetCurSel(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_SASEL));


	// -----------------------------------------
	//	Save New configuration
	//

	// Clear Time tag on Sync
	if (Button_GetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_SYNCCTAG)) != BST_UNCHECKED)
		tpblRT_ClearTTagOnSync = TRUE;
	else
		tpblRT_ClearTTagOnSync = FALSE;

	// Load Time tag on Sync
	if (Button_GetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_SYNCLTAG)) != BST_UNCHECKED)
		tpblRT_LoadTTagOnSync = TRUE;
	else
		tpblRT_LoadTTagOnSync = FALSE;

	// Enable Ill Cmd Table
	if (Button_GetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_ENILLCMD)) != BST_UNCHECKED)
		tpblEnIllCmdTable = TRUE;
	else
		tpblEnIllCmdTable = FALSE;

	// RT Tx Mode
	tpstRTTxMode.TxMode[oldrt][oldsa] = ComboBox_GetCurSel(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_TXMODE));

	// Vector Word
	::GetWindowText(::GetDlgItem(this->m_hWnd, IDC_RTS_ED_VCTWORD), c, sizeof(c));
	tpwdVctWord[oldrt] = (WORD) HEXS(c);

	// RT Addr Enabled
	rta = 0x00000001;
	rta = rta<<oldrt;
	if (Button_GetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_ENRT)) != BST_UNCHECKED)
	{
		tpdwRTSel = tpdwRTSel | rta;
	}
	else
	{
		tpdwRTSel = tpdwRTSel & (~rta);
	}

	// Bit Word
	::GetWindowText(::GetDlgItem(this->m_hWnd, IDC_RTS_ED_SFTWORD), c, sizeof(c));
	tpwdBitWord[oldrt] = (WORD) HEXS(c);

	// RT Status Set
	//
	if (Button_GetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_STBUSY)) != BST_UNCHECKED) // busy
		tpstStatusWord[oldrt].Busy = TRUE;
	else
		tpstStatusWord[oldrt].Busy = FALSE;

	if (Button_GetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_STDYNBUS)) != BST_UNCHECKED) // bus control
		tpstStatusWord[oldrt].DBusCtl = TRUE;
	else
		tpstStatusWord[oldrt].DBusCtl = FALSE;

	if (Button_GetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_STSVR)) != BST_UNCHECKED) // service
		tpstStatusWord[oldrt].ServiceReq = TRUE;
	else
		tpstStatusWord[oldrt].ServiceReq = FALSE;

	if (Button_GetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_STSUBSYS)) != BST_UNCHECKED) // sub system flag
		tpstStatusWord[oldrt].SubSystemFlag = TRUE;
	else
		tpstStatusWord[oldrt].SubSystemFlag = FALSE;

	if (Button_GetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_STTMIFLAG)) != BST_UNCHECKED) // terminal flag
		tpstStatusWord[oldrt].TerminalFlag = TRUE;
	else
		tpstStatusWord[oldrt].TerminalFlag = FALSE;
	
	// Ill Cmd Table
	//
	dwr = 0;
	dwt = 0;
	for (i=0; i<32; i++)
	{
		dwr = dwr>>1;
		dwt = dwt>>1;
		switch (ComboBox_GetCurSel(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_ILL1+i))) // Rx & Tx Ill
		{
			case 0: // Rx & Tx unIll
				dwr = dwr & 0x7FFFFFFF;
				dwt = dwt & 0x7FFFFFFF;
				break;

			case 1: // Tx Ill
				dwr = dwr & 0x7FFFFFFF;
				dwt = dwt | 0x80000000;
				break;

			case 2: // Rx Ill
				dwr = dwr | 0x80000000;
				dwt = dwt & 0x7FFFFFFF;
				break;

			case 3: // Rx & Tx Ill
				dwr = dwr | 0x80000000;
				dwt = dwt | 0x80000000;
				break;
		}
	} // end of for (i=0; i<32; i++)
	tpstIllCmdTable.CmdTable[oldrt][0][oldsa] = dwr; // Rx
	tpstIllCmdTable.CmdTable[oldrt][1][oldsa] = dwt; // Tx

	//	same operating
	//
	if ((Button_GetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_ALLRTSAME)) != BST_UNCHECKED)&&
		(Button_GetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_ALLSASAME)) == BST_UNCHECKED)) // same RT
	{
		for (i=0; i<32; i++)
		{
			for (j=0; j<2; j++)
			{
				tpstIllCmdTable.CmdTable[i][j][oldsa] = tpstIllCmdTable.CmdTable[oldrt][j][oldsa];
			}
		}
	}
	else if ((Button_GetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_ALLRTSAME)) == BST_UNCHECKED)&&
			 (Button_GetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_ALLSASAME)) != BST_UNCHECKED)) // same SA
	{
		for (j=0; j<2; j++)
		{
			for (k=0; k<32; k++)
			{
				tpstIllCmdTable.CmdTable[oldrt][j][k] = tpstIllCmdTable.CmdTable[oldrt][j][oldsa];
			}
		}
	}
	else if ((Button_GetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_ALLRTSAME)) != BST_UNCHECKED)&&
			 (Button_GetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_ALLSASAME)) != BST_UNCHECKED)) // All same
	{
		for (i=0; i<32; i++)
		{
			for (j=0; j<2; j++)
			{
				for (k=0; k<32; k++)
				{
					tpstIllCmdTable.CmdTable[i][j][k] = tpstIllCmdTable.CmdTable[oldrt][j][oldsa];
				}
			}
		}
	}

	// -----------------------------------------
	//	Resume Old configuration
	//
	oldrt = irt;
	oldsa = isa;

	// RT Addr Enabled
	rta = 0x00000001;
	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);

	// 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);
	}


	
}

void CRTSetupDlg::OnRtsBtAllsett() 
{
	// TODO: Add your control notification handler code here
	int i=0;

	for (i=0; i<32; i++)
	{
		ComboBox_SetCurSel(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_ILL1+i), 1); // Tx
	}	
}

void CRTSetupDlg::OnRtsBtAllsetr() 
{
	// TODO: Add your control notification handler code here
		int i=0;

	for (i=0; i<32; i++)
	{
		ComboBox_SetCurSel(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_ILL1+i), 2); // Rx
	}

	
}

void CRTSetupDlg::OnRtsBtAllclr() 
{
	// TODO: Add your control notification handler code here
	int i=0;

	for (i=0; i<32; i++)
	{
		ComboBox_SetCurSel(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_ILL1+i), 0); // 合法
	}
	
}

void CRTSetupDlg::OnRtsBtAllsettr() 
{
	// TODO: Add your control notification handler code here
	int i=0;

	for (i=0; i<32; i++)
	{
		ComboBox_SetCurSel(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_ILL1+i), 3); // Ill
	}

	
}

void CRTSetupDlg::OnSelchangeRtsCbSasel() 
{
	// TODO: Add your control notification handler code here
	this->OnSelchangeRtsCbRtsel();
	
}

void CRTSetupDlg::OnRtsCkAllrtsame() 
{
	// TODO: Add your control notification handler code here
		this->OnSelchangeRtsCbRtsel();

}

void CRTSetupDlg::OnRtsCkAllsasame() 
{
	// TODO: Add your control notification handler code here
	this->OnSelchangeRtsCbRtsel();	
}

void CRTSetupDlg::SaveConf()
{
	char c[80];
	int i=0, j=0, k=0, n=0;
	DWORD dwr=0, dwt=0;
	DWORD rta=0x00000001;

	// RT Sel
	oldrt = ComboBox_GetCurSel(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_RTSEL));

	// SA Sel
	oldsa = ComboBox_GetCurSel(::GetDlgItem(this->m_hWnd, IDC_RTS_CB_SASEL));

	// RT Addr Enabled
	rta = rta<<oldrt;
	if (Button_GetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_ENRT)) != BST_UNCHECKED)
	{
		tpdwRTSel = tpdwRTSel | rta;
	}
	else
	{
		tpdwRTSel = tpdwRTSel & (~rta);
	}

	// Clear Time tag on Sync
	if (Button_GetCheck(::GetDlgItem(this->m_hWnd, IDC_RTS_CK_SYNCCTAG)) != BST_UNCHECKED)
		tpblRT_ClearTTagOnSync = TRUE;
	else
		tpblRT_ClearTTagOnSync = FALSE;

	// Load Time tag on Sync

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -