📄 commwizarddlg.cpp
字号:
pub_send_data_len=(t_yx_word+2)*6;
dire_send_long=pub_send_data_len;
CDT_send_add_cou=0;
}
void CCommWizardDlg::FunMakeCDTYcFrameCycle()
{
switch(GlYcFrameCou)
{
case 1:
case 3:
case 4:
case 6:
case 7:
case 9:
case 10:
case 12:
case 13:
case 15:
case 16:
case 18:
{
FunCDT_A_frame();//组重要遥测帧
GlYcFrameCou++;
if(GlYcFrameCou>18) GlYcFrameCou=1;
break;
}
case 2:
case 8:
case 11:
case 17:
{
FunCDT_B_frame();//组次要遥测帧
GlYcFrameCou++;
break;
}
case 5:
case 14:
{
FunCDT_C_frame();//组一般遥测帧
GlYcFrameCou++;
break;
}
default :GlYcFrameCou=1;
}//end switch(GlYcFrameCou)
}
unsigned char CCommWizardDlg::CRC_check(unsigned char *CRC_cur, unsigned char List_kind)
{
unsigned char Syn_data,i;
Syn_data=*CRC_cur;
for(i=0;i<4;i++)
{CRC_cur++;
Syn_data=(*CRC_cur)^CRC_data[List_kind][Syn_data];
}
Syn_data=CRC_data[List_kind][Syn_data];
Syn_data=Syn_data^0xff;
return Syn_data;
}
void CCommWizardDlg::FunCdtReServer()
{
}
void CCommWizardDlg::FunCdtTrServer()
{
unsigned int Loclen;
// unsigned char CDT_send_reg;/**j for testing***/
CString strSend;
CByteArray hexdata;
// if(CDT_syn_cou>=6)
// {
if(pub_send_data_len<=0)
{
m_strReceive+="\r\n";
FunChangeRowDisp(1);//调整行显示,增加了一行
Loclen=fun_hex_to_array(hexdata,CDT_syn_array[DireCycle],6);//发送数据
FunCdtTrDisplayString(CDT_syn_array[DireCycle],6);//显示发送的数据
CDT_syn_cou=Loclen;
}
else
{
// CDT_send_reg=*(t_buffer[for_direc_code]+CDT_send_add_cou[for_direc_code]);
Loclen=fun_hex_to_array(hexdata,pub_send_data_buf,pub_send_data_len);//发送数据
m_strReceive+="\r\nsend:\r\n";
FunChangeRowDisp(2);//调整行显示,增加了两行
FunCdtTrDisplayString(pub_send_data_buf,pub_send_data_len);//显示发送的数据
pub_send_data_len-=Loclen;
CDT_send_add_cou+=Loclen;
if(pub_send_data_len<=0)
{CDT_syn_cou=0;
}
}
m_Com.SetOutput(COleVariant(hexdata));
GlSendFrameFlag=0;//清掉帧数据未发送完毕标志
}
//DEL void CCommWizardDlg::OnStatrUptest()
//DEL {
//DEL // TODO: Add your control notification handler code here
//DEL // TODO: Add your control notification handler code here
//DEL m_Com.GetInput();//先预读缓冲区以清除残留数据
//DEL bStartTest = !bStartTest;
//DEL if(bStartTest)
//DEL {
//DEL m_ctrlStartTest.SetWindowText(_T("停止测试"));
//DEL FunCdtTrServer();//先预发送以启动发送服务
//DEL }
//DEL else
//DEL {
//DEL m_ctrlStartTest.SetWindowText(_T("开始测试"));
//DEL
//DEL }
//DEL }
/*void CCommWizardDlg::OnStatrtest()
{
// TODO: Add your control notification handler code here
m_Com.GetInput();//先预读缓冲区以清除残留数据
bStartTest = !bStartTest;
if(bStartTest)
{
m_ctrlStartTest.SetWindowText(_T("停止测试"));
FunCdtTrServer();//先预发送以启动发送服务
}
else
{
m_ctrlStartTest.SetWindowText(_T("开始测试"));
}
}*/
void CCommWizardDlg::OnButstartwork()
{
// TODO: Add your control notification handler code here
m_Com.GetInput();//先预读缓冲区以清除残留数据
bStartTest = !bStartTest;
if(bStartTest)
{
m_ctrlStartWork.SetWindowText(_T("停止通信"));
FunCdtTrServer();//先预发送以启动发送服务
}
else
{
m_ctrlStartWork.SetWindowText(_T("开始通信"));
}
}
void CCommWizardDlg::FunCdtTrDisplayString(unsigned char *Loc_send_data_buf,int Loc_send_data_len)
{
CString strtemp;
// int LocInCharCou;
// m_strReceive += "\r\nsend:\r\n";
GlRowCharCou=0;//清行字符显示计数
GlCDTCharDispCou=0;//清CDT模式字符显示计数,每6个字节(一个信息字)多一个空格
// GlRowCharCou=0;//用于分行字符数计数
for(int k=0;k<Loc_send_data_len;k++) //将数组转换为Cstring型变量
{
BYTE bt=*(char*)(Loc_send_data_buf+k); //字符型
strtemp.Format("%02X ",bt); //将字符以十六进制方式送入临时变量strtemp存放,注意这里加入一个空隔
m_strReceive = m_strReceive + strtemp; //加入接收编辑框对应字符串
FunChangeRowCharDisp(1);//调整本行的字符显示,本行增加了一个字符
FunChangeCDTCharDisp(1);//调整本行的CDT模式字符显示,即每6个字符一组(一个远动字),组间加空格
}//end for(int k=0;k<Loc_send_data_len;k++)
}
//重要遥测组帧,发送遥测范围:前1-64点
void CCommWizardDlg::FunCDT_A_frame()
{
unsigned int t_yx_word,i;
unsigned char t_frame_temp[6];
unsigned short LocYcVal;
// unsigned int for_send_direc;
// for_send_direc=ex_str_cdt_relax[for_direc_code].this_direc_code;
// t_yx_word=(exstr_agree_layer_para+for_direc_code)->agree_union.cdt_agree.cdt_yx_num;
t_yx_word=AYCDOTAMOUNT/2;//t_yx_word:信息字个数。一个遥信信息字(4个信息字节、一个功能码字节、一个校验字节)可传送32点遥测
if(AYCDOTAMOUNT%2!=0)
{
t_yx_word++;
}
for(i=0;i<6;i++)//同步头
{
pub_send_data_buf[i]=CDT_syn_array[DireCycle][i];
}
t_frame_temp[0]=0x71;
t_frame_temp[1]=0x61;
t_frame_temp[2]=t_yx_word;
t_frame_temp[3]=GlSourAddr;
GlSourAddr++;//源站址加1用于测试
t_frame_temp[4]=GlAimAddr;
t_frame_temp[5]=CRC_check(t_frame_temp,VeriDireCycle);//求本信息字的CRC校验,0:指取CRC正码表;1:指取反码。默认为0
for(i=0;i<6;i++)//控制字
{
pub_send_data_buf[i+6]=t_frame_temp[i];
}
unsigned int j=0;
while(j<t_yx_word)//信息字
{
pub_send_data_buf[(j+2)*6+0]=0x00+j;
LocYcVal=GlYcDataCur[j*2+0];
pub_send_data_buf[(j+2)*6+1]=(unsigned char)LocYcVal;
LocYcVal=LocYcVal>>8;
pub_send_data_buf[(j+2)*6+2]=(unsigned char)LocYcVal;
LocYcVal=GlYcDataCur[j*2+1];
pub_send_data_buf[(j+2)*6+3]=(unsigned char)LocYcVal;
LocYcVal=LocYcVal>>8;
pub_send_data_buf[(j+2)*6+4]=(unsigned char)LocYcVal;
pub_send_data_buf[(j+2)*6+5]=CRC_check(&pub_send_data_buf[(j+2)*6+0],VeriDireCycle);
j++;
}
pub_send_data_len=(t_yx_word+2)*6;
dire_send_long=pub_send_data_len;
CDT_send_add_cou=0;
}
//次要遥测组帧,发送遥测范围:第65-128点
void CCommWizardDlg::FunCDT_B_frame()
{
unsigned int t_yx_word,i;
unsigned char t_frame_temp[6];
unsigned short LocYcVal;
// unsigned int for_send_direc;
// for_send_direc=ex_str_cdt_relax[for_direc_code].this_direc_code;
// t_yx_word=(exstr_agree_layer_para+for_direc_code)->agree_union.cdt_agree.cdt_yx_num;
t_yx_word=BYCDOTAMOUNT/2;//t_yx_word:信息字个数。一个遥信信息字(4个信息字节、一个功能码字节、一个校验字节)可传送32点遥测
if(BYCDOTAMOUNT%2!=0)
{
t_yx_word++;
}
for(i=0;i<6;i++)//同步头
{
pub_send_data_buf[i]=CDT_syn_array[DireCycle][i];
}
t_frame_temp[0]=0x71;
t_frame_temp[1]=0xc2;
t_frame_temp[2]=t_yx_word;
t_frame_temp[3]=GlSourAddr;
GlSourAddr++;//源站址加1用于测试
t_frame_temp[4]=GlAimAddr;
t_frame_temp[5]=CRC_check(t_frame_temp,VeriDireCycle);//求本信息字的CRC校验,0:指取CRC正码表;1:指取反码。默认为0
for(i=0;i<6;i++)//控制字
{
pub_send_data_buf[i+6]=t_frame_temp[i];
}
unsigned int j=0;
while(j<t_yx_word)//信息字
{
pub_send_data_buf[(j+2)*6+0]=0x00+AYCDOTAMOUNT/2+j;
LocYcVal=GlYcDataCur[j*2+AYCDOTAMOUNT+0];
pub_send_data_buf[(j+2)*6+1]=(unsigned char)LocYcVal;
LocYcVal=LocYcVal>>8;
pub_send_data_buf[(j+2)*6+2]=(unsigned char)LocYcVal;
LocYcVal=GlYcDataCur[j*2+AYCDOTAMOUNT+1];
pub_send_data_buf[(j+2)*6+3]=(unsigned char)LocYcVal;
LocYcVal=LocYcVal>>8;
pub_send_data_buf[(j+2)*6+4]=(unsigned char)LocYcVal;
pub_send_data_buf[(j+2)*6+5]=CRC_check(&pub_send_data_buf[(j+2)*6+0],VeriDireCycle);
j++;
}
pub_send_data_len=(t_yx_word+2)*6;
dire_send_long=pub_send_data_len;
CDT_send_add_cou=0;
}
//一般遥测组帧,发送遥测范围:第129-256点
void CCommWizardDlg::FunCDT_C_frame()
{
unsigned int t_yx_word,i;
unsigned char t_frame_temp[6];
unsigned short LocYcVal;
// unsigned int for_send_direc;
// for_send_direc=ex_str_cdt_relax[for_direc_code].this_direc_code;
// t_yx_word=(exstr_agree_layer_para+for_direc_code)->agree_union.cdt_agree.cdt_yx_num;
t_yx_word=CYCDOTAMOUNT/2;//t_yx_word:信息字个数。一个遥信信息字(4个信息字节、一个功能码字节、一个校验字节)可传送32点遥测
if(CYCDOTAMOUNT%2!=0)
{
t_yx_word++;
}
for(i=0;i<6;i++)//同步头
{
pub_send_data_buf[i]=CDT_syn_array[DireCycle][i];
}
t_frame_temp[0]=0x71;
t_frame_temp[1]=0xb3;
t_frame_temp[2]=t_yx_word;
t_frame_temp[3]=GlSourAddr;
GlSourAddr++;//源站址加1用于测试
t_frame_temp[4]=GlAimAddr;
t_frame_temp[5]=CRC_check(t_frame_temp,VeriDireCycle);//求本信息字的CRC校验,0:指取CRC正码表;1:指取反码。默认为0
for(i=0;i<6;i++)//控制字
{
pub_send_data_buf[i+6]=t_frame_temp[i];
}
unsigned int j=0;
while(j<t_yx_word)//信息字
{
pub_send_data_buf[(j+2)*6+0]=0x00+(AYCDOTAMOUNT+BYCDOTAMOUNT)/2+j;
LocYcVal=GlYcDataCur[j*2+AYCDOTAMOUNT+BYCDOTAMOUNT+0];
pub_send_data_buf[(j+2)*6+1]=(unsigned char)LocYcVal;
LocYcVal=LocYcVal>>8;
pub_send_data_buf[(j+2)*6+2]=(unsigned char)LocYcVal;
LocYcVal=GlYcDataCur[j*2+AYCDOTAMOUNT+BYCDOTAMOUNT+1];
pub_send_data_buf[(j+2)*6+3]=(unsigned char)LocYcVal;
LocYcVal=LocYcVal>>8;
pub_send_data_buf[(j+2)*6+4]=(unsigned char)LocYcVal;
pub_send_data_buf[(j+2)*6+5]=CRC_check(&pub_send_data_buf[(j+2)*6+0],VeriDireCycle);
j++;
}
pub_send_data_len=(t_yx_word+2)*6;
dire_send_long=pub_send_data_len;
CDT_send_add_cou=0;
}
void CCommWizardDlg::FunChangeRowDisp(int LocAddRowAmount)
{
for(int i=0;i<LocAddRowAmount;i++)
{
ExPrintLineCou++;
if(ExPrintLineCou>DisplayrowROW)//滚动
{
}
if(ExPrintLineCou>DisplayrowAmount)//大于DisplayrowAmount行重新显示
{
// UpdateData(FALSE);//更新编辑框显示的内容
m_EditRecv.SetSel(0,-1); //全选
// m_EditRecv.Clear();
m_EditRecv.ReplaceSel(m_strReceive); //填入内容
m_EditRecv.ScrollWindow(0,0); //滚动到插入点
GlThisPageDispFlag=1;//本页已显示标记
// Sleep(100);
// AfxMessageBox("open file error");
m_strReceive = _T("");
/* m_EditRecv.SetSel(0,-1); //全选
m_EditRecv.ReplaceSel(m_strReceive); //填入内容
m_EditRecv.ScrollWindow(0,0); //滚动到插入点 */
ExPrintLineCou=0;
}
}
}
void CCommWizardDlg::FunChangeRowCharDisp(int LocAddCharAmount)
{
for(int i=0;i<LocAddCharAmount;i++)
{
GlRowCharCou++;
if(GlRowCharCou>=DisplayrowLen)//本行字符显示到头,换行
{
GlRowCharCou=0;
m_strReceive += "\r\n";
FunChangeRowDisp(1);//调整行显示,增加了一行
}//end if(LocCharCou>DisplayrowLen)
}
}
void CCommWizardDlg::FunChangeCDTCharDisp(int LocAddCDTCharAmount)
{
for(int i=0;i<LocAddCDTCharAmount;i++)
{
GlCDTCharDispCou++;
if(GlCDTCharDispCou>=6)
{
m_strReceive = m_strReceive+" ";
GlCDTCharDispCou=0;
FunChangeRowCharDisp(1);//调整本行的字符显示,本行增加了一个字符(空格)
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -