|
|
// DlgIMP.cpp : 实现文件
|
|
|
//
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
#include "CH91PayloadSoftware.h"
|
|
|
#include "DlgIMP.h"
|
|
|
#include "afxdialogex.h"
|
|
|
|
|
|
// CDlgIMP 对话框
|
|
|
|
|
|
IMPLEMENT_DYNAMIC(CDlgIMP, CDialogEx)
|
|
|
|
|
|
CDlgIMP::CDlgIMP()
|
|
|
: CDialogEx(CDlgIMP::IDD)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
CDlgIMP::~CDlgIMP()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
void CDlgIMP::DoDataExchange(CDataExchange* pDX)
|
|
|
{
|
|
|
CDialogEx::DoDataExchange(pDX);
|
|
|
}
|
|
|
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CDlgIMP, CDialogEx)
|
|
|
ON_BN_CLICKED(IDC_BUTTON1, &CDlgIMP::OnBnClickedButton1)
|
|
|
|
|
|
ON_MESSAGE(WM_UPDATE_IMP_SERIAL_CONNECT, ImpSerialConnectMessage) //IMP通信开始消息
|
|
|
ON_MESSAGE(WM_UPDATE_IMPDOWN_CHECKED, OnUpdateIMPDownDataChecked) //更新IMP下行遥测数据
|
|
|
END_MESSAGE_MAP()
|
|
|
BOOL CDlgIMP::OnInitDialog()
|
|
|
{
|
|
|
CDialogEx::OnInitDialog();
|
|
|
g_IMPDLGhwnd = GetSafeHwnd();
|
|
|
return TRUE;
|
|
|
}
|
|
|
|
|
|
// DlgIMP 消息处理程序
|
|
|
void CDlgIMP::SetIMPData(CFrameIMPDown_ data)
|
|
|
{
|
|
|
CString tstr;
|
|
|
tstr.Format(_T("%d"),data.Data.Bytes);
|
|
|
GetDlgItem(IDC_EDIT2)->SetWindowTextA(tstr);
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
void CDlgIMP::OnBnClickedButton1()
|
|
|
{
|
|
|
// TODO: 在此添加控件通知处理程序代码
|
|
|
}
|
|
|
|
|
|
//IMP串口有数据后,进行校验
|
|
|
void OnReadFromCommIMP( char *buffer,const DWORD size)
|
|
|
{
|
|
|
//buffer = (unsigned char*)buffer;
|
|
|
const BYTE* buffer2 = (BYTE*)buffer;
|
|
|
if(size>0)
|
|
|
{
|
|
|
BYTE DCBufferCmd[6];
|
|
|
memset(DCBufferCmd,0,sizeof(DCBufferCmd));
|
|
|
DCBufferCmd[0] = buffer2[0] ;
|
|
|
DCBufferCmd[1] = buffer2[1] ;
|
|
|
DCBufferCmd[2] = buffer2[2] ;
|
|
|
int a = sizeof(buffer2);
|
|
|
/********进入校验,校验通过就给g_FrameIMPDown赋值********/
|
|
|
g_FrameIMPDown.Phrase(buffer2, size);
|
|
|
|
|
|
::SendMessageA(g_IMPDLGhwnd,WM_UPDATE_IMPDOWN_CHECKED,0,0);
|
|
|
}
|
|
|
}
|
|
|
LRESULT CDlgIMP::ImpSerialConnectMessage(WPARAM param, LPARAM lparam)
|
|
|
{
|
|
|
// 卸载串口
|
|
|
if (TRUE == m_SerialIMP.IsInitialized())
|
|
|
{
|
|
|
m_SerialIMP.DeInit();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//串口通信设置
|
|
|
char pSerialPort[20];//串口号
|
|
|
DWORD pSerialPortBaud;//端口号
|
|
|
memset(pSerialPort, 0, 20);
|
|
|
|
|
|
/*自定义消息发送CString类型数据时,消息发送时采用如下方式:
|
|
|
//::SendMessageA(g_IMPDLGhwnd,WM_UPDATE_IMP_SERIAL_CONNECT,(WPARAM)mComPortIMP.AllocSysString(), (LPARAM)mComBaudIMP.AllocSysString());
|
|
|
//解析时采用如下方式,即:WPARAM转CSTring
|
|
|
*/
|
|
|
CString sPort = (CString)((BSTR)param);
|
|
|
CString sBaud = (CString)((BSTR)lparam);
|
|
|
SysFreeString((BSTR)param);
|
|
|
SysFreeString((BSTR)lparam);
|
|
|
|
|
|
|
|
|
GetSerialPortNumber(pSerialPort,sPort);
|
|
|
pSerialPortBaud = atoi(sBaud);//波特率
|
|
|
|
|
|
if (!OnCheckComPort(pSerialPort)) //串口被占用,返回false
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
if(m_SerialIMP.Initialize(pSerialPort, pSerialPortBaud, 8, 0, 0)) //开启串口通信
|
|
|
{
|
|
|
m_SerialIMP.SetComReadCallback( OnReadFromCommIMP );
|
|
|
//m_SerialIMP.SetNotCheckCallback(nullptr,NULL);
|
|
|
BYTE buffersend[10];
|
|
|
memset(buffersend,1,10);
|
|
|
m_SerialIMP.WriteABuffer(buffersend,sizeof(buffersend));
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
//处理通过校验的IMP下行数据
|
|
|
LRESULT CDlgIMP::OnUpdateIMPDownDataChecked(WPARAM param, LPARAM lparam)
|
|
|
{
|
|
|
//数据解析与显示
|
|
|
//if(p_DlgIMP->IsWindowVisible())
|
|
|
//{
|
|
|
// p_DlgIMP->SetIMPData(g_FrameIMPDown);
|
|
|
//}
|
|
|
if(IMPDlgWindowVisible)
|
|
|
{
|
|
|
SetIMPData(g_FrameIMPDown);
|
|
|
}
|
|
|
return 0;
|
|
|
} |