📄 protocolpara.cpp
字号:
// ProtocolPara.cpp : implementation file
//
#include "stdafx.h"
#include "fert2000.h"
#include "ProtocolPara.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern RTU Rtus[MAX_RTU_NUM];
/////////////////////////////////////////////////////////////////////////////
// CProtocolPara property page
IMPLEMENT_DYNCREATE(CProtocolPara, CDialog)
CProtocolPara::CProtocolPara()
:CDialog(CProtocolPara::IDD)
{
//{{AFX_DATA_INIT(CProtocolPara)
m_Radio_BMYes = -1;
m_Radio_JFYes = 0;
m_Radio_ZDYes = 0;
m_Radio_BMNo = 0;
m_Radio_JFNo = -1;
m_Radio_ZDNo = -1;
m_StartYx = _T("");
m_StartYc = _T("");
m_StartKwh = _T("");
m_CustomSynWord = _T("");
m_CheckCustom = FALSE;
m_ONoPerchPre = FALSE;
//}}AFX_DATA_INIT
CurProtocol = 0;
}
CProtocolPara::~CProtocolPara()
{
}
void CProtocolPara::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CProtocolPara)
DDX_Control(pDX, IDC_SEL_SYNWORD, m_SelSynWord);
DDX_Control(pDX, IDC_COMBO_JINZHI, m_JinZhi);
DDX_Control(pDX, IDC_COMBO_FUHAO, m_FuHao);
DDX_Radio(pDX, IDC_RADIO_BMYES, m_Radio_BMYes);
DDX_Radio(pDX, IDC_RADIO_JFYES, m_Radio_JFYes);
DDX_Radio(pDX, IDC_RADIO_ZDYES,m_Radio_ZDYes);
DDX_Radio(pDX, IDC_RADIO_BMNO, m_Radio_BMNo);
DDX_Radio(pDX, IDC_RADIO_JFNO, m_Radio_JFNo);
DDX_Radio(pDX, IDC_RADIO_ZDNO, m_Radio_ZDNo);
DDX_Text(pDX, IDC_START_YX, m_StartYx);
DDV_MaxChars(pDX, m_StartYx, 2);
DDX_Text(pDX, IDC_START_YC, m_StartYc);
DDV_MaxChars(pDX, m_StartYc, 2);
DDX_Text(pDX, IDC_START_KWH, m_StartKwh);
DDV_MaxChars(pDX, m_StartKwh, 2);
DDX_Text(pDX, IDC_CUSTOM_SYNWORD, m_CustomSynWord);
DDV_MaxChars(pDX, m_CustomSynWord, 12);
DDX_Check(pDX, IDC_CHECK_CUSTOM, m_CheckCustom);
DDX_Check(pDX, IDC_CHECK1, m_ONoPerchPre);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CProtocolPara, CDialog)
//{{AFX_MSG_MAP(CProtocolPara)
ON_BN_CLICKED(IDC_RADIO_BMYES, OnRadioBmyes)
ON_BN_CLICKED(IDC_RADIO_JFYES, OnRadioJfyes)
ON_BN_CLICKED(IDC_RADIO_ZDYES, OnRadioZdyes)
ON_BN_CLICKED(IDC_RADIO_BMNO, OnRadioBmno)
ON_BN_CLICKED(IDC_RADIO_JFNO, OnRadioJfno)
ON_BN_CLICKED(IDC_RADIO_ZDNO, OnRadioZdno)
ON_WM_CHAR()
ON_EN_CHANGE(IDC_START_KWH, OnChangeStartKwh)
ON_EN_CHANGE(IDC_START_YC, OnChangeStartYc)
ON_EN_CHANGE(IDC_START_YX, OnChangeStartYx)
ON_BN_CLICKED(IDC_CHECK_CUSTOM, OnCheckCustom)
ON_EN_CHANGE(IDC_CUSTOM_SYNWORD, OnChangeCustomSynword)
ON_EN_UPDATE(IDC_START_KWH, OnUpdateStartKwh)
ON_CBN_SELCHANGE(IDC_SEL_SYNWORD, OnSelchangeSelSynword)
ON_CBN_SELCHANGE(IDC_COMBO_JINZHI, OnSelchangeComboJinzhi)
ON_CBN_SELCHANGE(IDC_COMBO_FUHAO, OnSelchangeComboFuhao)
ON_BN_CLICKED(IDC_DEFAULT_VALUE, OnDefaultValue)
ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CProtocolPara message handlers
BOOL CProtocolPara::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_Radio_ZDYes = Rtus[CurRtuNo].ProtocolStamp[7]?0:-1;
m_Radio_ZDNo = Rtus[CurRtuNo].ProtocolStamp[7]?-1:0;
m_Radio_JFYes = Rtus[CurRtuNo].ProtocolStamp[5]?0:-1;
m_Radio_JFNo = Rtus[CurRtuNo].ProtocolStamp[5]?-1:0;
m_Radio_BMYes = Rtus[CurRtuNo].ProtocolStamp[6]?0:-1;
m_Radio_BMNo = Rtus[CurRtuNo].ProtocolStamp[6]?-1:0;
m_ONoPerchPre = Rtus[CurRtuNo].ProtocolStamp[8]?TRUE:FALSE;
m_FuHao.SetCurSel(Rtus[CurRtuNo].ProtocolStamp[3]);
m_JinZhi.SetCurSel(Rtus[CurRtuNo].ProtocolStamp[4]);
m_StartYc.Format("%X",Rtus[CurRtuNo].ProtocolStamp[0]);
m_StartYx.Format("%X",Rtus[CurRtuNo].ProtocolStamp[1]);
m_StartKwh.Format("%X",Rtus[CurRtuNo].ProtocolStamp[2]);
char str[13];
for (int j=0;j<6;j++) sprintf(str+j*2,"%02X",Rtus[CurRtuNo].SynWord[j+1]);
str[13] = 0;
if (Rtus[CurRtuNo].SynWord[0] == 1)
{
GetDlgItem(IDC_SEL_SYNWORD)->EnableWindow(FALSE);
GetDlgItem(IDC_CUSTOM_SYNWORD) ->EnableWindow(TRUE);
m_CheckCustom = TRUE;
m_CustomSynWord = str;
}else
{
GetDlgItem(IDC_SEL_SYNWORD)->EnableWindow(TRUE);
GetDlgItem(IDC_CUSTOM_SYNWORD) ->EnableWindow(FALSE);
m_CheckCustom = FALSE;
m_SelSynWord.SetWindowText(str);
}
if ((CurProtocol == 0) || (CurProtocol == 4))//CDT OR CDT-ZF
GetDlgItem(IDC_CHECK1)->EnableWindow(FALSE);
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CProtocolPara::OnRadioBmyes()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if (m_Radio_BMYes)
{
m_Radio_BMYes = 0;
m_Radio_BMNo = -1;
Rtus[CurRtuNo].ModifyFlag = -1;
UpdateData(FALSE);
}
}
void CProtocolPara::OnRadioJfyes()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if (m_Radio_JFYes)
{
m_Radio_JFYes = 0;
m_Radio_JFNo = -1;
Rtus[CurRtuNo].ModifyFlag = -1;
UpdateData(FALSE);
}
}
void CProtocolPara::OnRadioZdyes()
{
// TODO: Add your control notification handler code here
if (m_Radio_ZDYes)
{
m_Radio_ZDYes = 0;
m_Radio_ZDNo = -1;
Rtus[CurRtuNo].ModifyFlag = -1;
UpdateData(FALSE);
}
}
void CProtocolPara::OnRadioBmno()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(m_Radio_BMNo)
{
m_Radio_BMNo = 0;
m_Radio_BMYes =-1;
Rtus[CurRtuNo].ModifyFlag = -1;
UpdateData(FALSE);
}
}
void CProtocolPara::OnRadioJfno()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(m_Radio_JFNo)
{
m_Radio_JFNo = 0;
m_Radio_JFYes = -1;
Rtus[CurRtuNo].ModifyFlag = -1;
UpdateData(FALSE);
}
}
void CProtocolPara::OnRadioZdno()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(m_Radio_ZDNo)
{
m_Radio_ZDNo = 0;
m_Radio_ZDYes = -1;
Rtus[CurRtuNo].ModifyFlag = -1;
UpdateData(FALSE);
}
}
void CProtocolPara::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnChar(nChar, nRepCnt, nFlags);
}
void CProtocolPara::OnChangeStartKwh()
{
UpdateData(TRUE);
char *str = m_StartKwh.GetBufferSetLength(4);
if (('0'<=str[0])&&(str[0]<='9') || ('a'<=str[0])&&(str[0]<='f') || ('A'<=str[0])&&(str[0]<='F') || !str[0])
{
if (('0'<=str[1])&&(str[1]<='9') || ('a'<=str[1])&&(str[1]<='f') || ('A'<=str[1])&&(str[1]<='F') || !str[1]);
else str[1] = 0;
}else str[0] = 0;
Rtus[CurRtuNo].ModifyFlag = -1;
UpdateData(FALSE);
}
void CProtocolPara::OnChangeStartYc()
{
UpdateData(TRUE);
char *str = m_StartYc.GetBufferSetLength(4);
if (('0'<=str[0])&&(str[0]<='9') || ('a'<=str[0])&&(str[0]<='f') || ('A'<=str[0])&&(str[0]<='F') || !str[0])
{
if (('0'<=str[1])&&(str[1]<='9') || ('a'<=str[1])&&(str[1]<='f') || ('A'<=str[1])&&(str[1]<='F') || !str[1]);
else str[1] = 0;
}else str[0] = 0;
Rtus[CurRtuNo].ModifyFlag = -1;
UpdateData(FALSE);
}
void CProtocolPara::OnChangeStartYx()
{
UpdateData(TRUE);
char *str = m_StartYx.GetBufferSetLength(4);
if (('0'<=str[0])&&(str[0]<='9') || ('a'<=str[0])&&(str[0]<='f') || ('A'<=str[0])&&(str[0]<='F') || !str[0])
{
if (('0'<=str[1])&&(str[1]<='9') || ('a'<=str[1])&&(str[1]<='f') || ('A'<=str[1])&&(str[1]<='F') || !str[1]);
else str[1] = 0;
}else str[0] = 0;
Rtus[CurRtuNo].ModifyFlag = -1;
UpdateData(FALSE);
}
bool CProtocolPara::SaveAProtocolPara()
{
UpdateData(TRUE);
if (!m_Radio_ZDYes) Rtus[CurRtuNo].ProtocolStamp[7] = 1;
else Rtus[CurRtuNo].ProtocolStamp[7] = 0;
if (!m_Radio_JFYes) Rtus[CurRtuNo].ProtocolStamp[5] = 1;
else Rtus[CurRtuNo].ProtocolStamp[5] = 0;
if (!m_Radio_BMYes) Rtus[CurRtuNo].ProtocolStamp[6] = 1;
else Rtus[CurRtuNo].ProtocolStamp[6] = 0;
Rtus[CurRtuNo].ProtocolStamp[8] = (m_ONoPerchPre)? 1:0;
Rtus[CurRtuNo].ProtocolStamp[3] = m_FuHao.GetCurSel();
Rtus[CurRtuNo].ProtocolStamp[4] = m_JinZhi.GetCurSel();
DWORD Temp;
sscanf((const char *)m_StartYc.GetBuffer(3),"%X",&Temp);
Rtus[CurRtuNo].ProtocolStamp[0] = (BYTE)Temp;
sscanf((const char *)m_StartYx.GetBuffer(3),"%X",&Temp);
Rtus[CurRtuNo].ProtocolStamp[1] = (BYTE)Temp;
sscanf((const char *)m_StartKwh.GetBuffer(3),"%02X",&Temp);
Rtus[CurRtuNo].ProtocolStamp[2] = (BYTE)Temp;
if (m_CheckCustom)
{
char *str = m_CustomSynWord.GetBufferSetLength(13);
Rtus[CurRtuNo].SynWord[0] = 1;
for (int j=0;j<12;j++)
if ((('0'>=str[0]) || (str[0]>='9')) && (('a'>=str[0]) || (str[0]>='f')) && (('A'>=str[0]) || (str[0]>='F'))) break;
if (j<12)
{
MessageBox("自定义同步码错误!\n请重新输入!\n(十六进制字符)","重新输入",MB_OK|MB_ICONSTOP);
return false;
}
str[12] = 0;
for (j=0;j<6;j++) sscanf(str+j*2,"%02X",&Rtus[CurRtuNo].SynWord[j+1]);
}else
{
char str[15];
Rtus[CurRtuNo].SynWord[0] = 0;
m_SelSynWord.GetWindowText(str,13);
str[12] = 0;
for (int j=0;j<6;j++) sscanf(str+j*2,"%02X",&Rtus[CurRtuNo].SynWord[j+1]);
}
Rtus[CurRtuNo].ModifyFlag = 0;
return true;
// UpdateData(FALSE);
}
void CProtocolPara::OnCheckCustom()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if (m_CheckCustom)
{
m_SelSynWord.EnableWindow(FALSE);
GetDlgItem(IDC_CUSTOM_SYNWORD)->EnableWindow(TRUE);
}else
{
m_SelSynWord.EnableWindow(TRUE);
GetDlgItem(IDC_CUSTOM_SYNWORD)->EnableWindow(FALSE);
}
Rtus[CurRtuNo].ModifyFlag = TRUE;
}
void CProtocolPara::OnChangeCustomSynword()
{
Rtus[CurRtuNo].ModifyFlag = -1;
}
void CProtocolPara::OnUpdateStartKwh()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function to send the EM_SETEVENTMASK message to the control
// with the ENM_UPDATE flag ORed into the lParam mask.
// TODO: Add your control notification handler code here
// UpdateData(TRUE);
/* char *str = m_Custom_SynWord.GetBufferSetLength(4);
if (('0'<=str[0])&&(str[0]<='9') || ('a'<=str[0])&&(str[0]<='f') || ('A'<=str[0])&&(str[0]<='F') || !str[0])
{
if (('0'<=str[1])&&(str[1]<='9') || ('a'<=str[1])&&(str[1]<='f') || ('A'<=str[1])&&(str[1]<='F') || !str[1]);
else str[1] = 0;
}else str[0] = 0;
Rtus[CurRtuNo].ModifyFlag = -1;
UpdateData(FALSE); */
}
void CProtocolPara::OnSelchangeSelSynword()
{
// TODO: Add your control notification handler code here
Rtus[CurRtuNo].ModifyFlag = -1;
}
void CProtocolPara::OnSelchangeComboJinzhi()
{
// TODO: Add your control notification handler code here
Rtus[CurRtuNo].ModifyFlag=1;
}
void CProtocolPara::OnSelchangeComboFuhao()
{
// TODO: Add your control notification handler code here
Rtus[CurRtuNo].ModifyFlag=1;
}
void CProtocolPara::OnOK()
{
if (!SaveAProtocolPara()) return;
CDialog::OnOK();
}
void CProtocolPara::OnDefaultValue()
{
if ((CurProtocol == 0) || (CurProtocol == 4) )//CDT91 OR CDT91-ZF
{
m_StartYc = "0";
m_StartYx = "F0";
m_StartKwh = "A0";
m_Radio_BMYes = 0;
m_Radio_BMNo = 1;
}else //CDT85 OR CDT85-1
{
m_StartYc = "01";
m_StartYx = "F8";
m_StartKwh = "A3";
m_Radio_BMYes = 1;
m_Radio_BMNo = 0;
m_ONoPerchPre = 0;//高位在前
}
m_Radio_JFYes = 1;
m_Radio_ZDYes = 1;
m_Radio_JFNo = 0;
m_Radio_ZDNo = 0;
m_JinZhi.SetCurSel(0);
m_FuHao.SetCurSel(0);
Rtus[CurRtuNo].ModifyFlag=1;
UpdateData(FALSE);
}
void CProtocolPara::OnCheck1()
{
// TODO: Add your control notification handler code here
Rtus[CurRtuNo].ModifyFlag=1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -