📄 missionnewdlg.cpp
字号:
// MissionNewDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MissionNew.h"
#include "MissionNewDlg.h"
#include ".\missionnewdlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMissionNewDlg dialog
CDebug51Dlg::CDebug51Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CDebug51Dlg::IDD, pParent)
, m_strPort(_T(""))
, m_Receive(_T(""))
, m_strFilePath(_T(""))
, TCount(_T(0))
, m_strSavePath(_T(""))
{
//{{AFX_DATA_INIT(CMissionNewDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDebug51Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMissionNewDlg)
DDX_Control(pDX, IDC_MSCOMM1, m_com);
//}}AFX_DATA_MAP
DDX_CBString(pDX, IDC_COMBO1, m_strPort);
DDX_Text(pDX, IDC_EDIT2, m_Receive);
DDX_Control(pDX, IDC_EDIT2, m_EditCtrl);
DDX_Text(pDX, IDC_EDIT3, m_strFilePath);
DDX_Text(pDX, IDC_EDIT4, TCount);
DDX_Text(pDX, IDC_EDIT1, m_strSavePath);
DDX_Control(pDX, IDC_PROGRESS1, progress_ctrl);
}
BEGIN_MESSAGE_MAP(CDebug51Dlg, CDialog)
//{{AFX_MSG_MAP(CMissionNewDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON1, OnConnectPort)
ON_BN_CLICKED(IDC_BUTTON2, OnDisconnect)
ON_BN_CLICKED(IDC_BUTTON3, OnSelectFile)
ON_BN_CLICKED(IDC_BUTTON4, OnSendFile)
ON_WM_TIMER()
ON_WM_SIZE()
ON_BN_CLICKED(IDC_BUTTON5, OnSavePath)
ON_BN_CLICKED(IDC_BUTTON6, OnSaveIt)
ON_BN_CLICKED(IDC_BUTTON7, OnRunDSPProgram)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMissionNewDlg message handlers
BOOL CDebug51Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//**************创建ini**************************
CFile ini;
if(ini.Open("DebugDSP.ini",CFile::modeRead,NULL))//打开成功,ini存在,关闭
ini.Close();
else //不存在
{
ini.Open("DebugDSP.ini",CFile::modeCreate|CFile::modeWrite,NULL);
CString tem="[set conf]";
tem+=(char)13;tem+=(char)10;//回车换行
tem+="COM=1";
tem+=(char)13;tem+=(char)10;//回车换行
tem+="SendPath=";//初始发送路径为空
tem+=(char)13;tem+=(char)10;//回车换行
tem+="SavePath=temp1.tmp";//默认
ini.Write(tem,tem.GetLength());
ini.Close();
}
//**************获取运行路径**************************
char temp[200];
GetCurrentDirectory(200,temp);
path=temp;
//***************读ini初始化串口号和发送.保存.路径******************
CString bbb;
bbb.Format("%d",GetPrivateProfileInt("set conf","COM",1,path+"\\DebugDSP.ini"));//读取失败默认是1
m_strPort=bbb;
char temp2[256];
::GetPrivateProfileString("set conf","SendPath","",temp2,256,path+"\\DebugDSP.ini");
m_strFilePath=temp2;
char temp3[256];
::GetPrivateProfileString("set conf","SavePath","",temp3,256,path+"\\DebugDSP.ini");
m_strSavePath=temp3;
this->UpdateData(false);
gInputFileBuffer = new BYTE[0x100000]; //用于输入文件的缓冲区
gUpdataFileBuffer = new BYTE[0x100000]; //用于对比更新的缓冲区
g2RFBM_ReceiveCount = 0;
progress_ctrl.SetRange(0,100);
percent=0;
g4InputFileLength = 0;
do {
gUpdataFileBuffer[g4InputFileLength++] = 0x00;
} while (++g4InputFileLength < 0x100000);
g4InputFileLength = 0;
g2RFBM_RX_InFIFO = 0;
g2RFBM_RX_OutFIFO = 0;
gRFBM_Counter = 0;
gRFBM_Change_Timer = 0;
gRFBM_ChangeModeCommand = 0;
OnConnectPort();
FDSPHardwareFound = 0;
FRFBM_SlaveNotFound = 1;
FDSPHardwareBank = 0;
FRFBM_TransferFile = 0;
FRFBM_EnableTransferFile = 0;
//*************创建一个10ms计时器********************
this->SetTimer(1,10,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CDebug51Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CDebug51Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CDebug51Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDebug51Dlg::OnConnectPort()
{
// TODO: 在此添加控件通知处理程序代码
this->UpdateData(true);
::WritePrivateProfileString("set conf","COM",m_strPort,path+"\\DebugDSP.ini");
if(m_com.GetPortOpen())
m_com.SetPortOpen(FALSE);
m_com.SetCommPort(GetPrivateProfileInt("set conf","COM",1,path+"\\DebugDSP.ini"));
if( !m_com.GetPortOpen())
m_com.SetPortOpen(TRUE);
else
{AfxMessageBox("不能打开串口!");return;}
CString strString="115200,n,8,1";
m_com.SetSettings(strString);
m_com.SetInputMode(1);
m_com.SetRThreshold(1);
m_com.SetInputLen(0);
m_com.GetInput();
FRFBM_Connect = 1;
return;
}
BEGIN_EVENTSINK_MAP(CDebug51Dlg, CDialog)
ON_EVENT(CDebug51Dlg, IDC_MSCOMM1, 1, OnComm, VTS_NONE)
END_EVENTSINK_MAP()
void CDebug51Dlg::OnDisconnect(){
m_com.SetPortOpen(false);
FRFBM_Connect = 0;
return;
}
void CDebug51Dlg::OnSelectFile(){
CFileDialog dlg(TRUE,"","", OFN_FILEMUSTEXIST,"AVM主程序文件(*.avm)|*.avm|AVB BIOS文件(*.avb)|*.avb|总文件(*.avt)|*.avt|所有文件(*.*)|*.*||");
if(dlg.DoModal()==IDOK){
m_strFilePath=dlg.GetPathName();
}
else return;
this->UpdateData(false);
//写发送路径到ini文件
::WritePrivateProfileString("set conf","SendPath",m_strFilePath,path+"\\DebugDSP.ini");
return;
}
void CDebug51Dlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: 在此处添加消息处理程序代码
CRect rect;
GetClientRect(&rect);
m_EditCtrl.MoveWindow(10,164,rect.Width()-20,rect.Height()-175,true);
}
void CDebug51Dlg::OnSavePath()
{
// TODO: 在此添加控件通知处理程序代码
/*
CFileDialog dlg(TRUE,"","", OFN_FILEMUSTEXIST,"BIN文件(*.bin)|*.bin|所有文件(*.*)|*.*||");
if(dlg.DoModal()==IDOK)
{
m_strSavePath=dlg.GetPathName();
}else return;
this->UpdateData(false);
::WritePrivateProfileString("set conf","SavePath",m_strSavePath,path+"\\DebugDSP.ini");
//写发送路径到ini文件
*/
MDEBUG(0x65);
}
void CDebug51Dlg::OnSaveIt(){
this->UpdateData(true);
if(m_strSavePath==""){
AfxMessageBox("没有选择保存数据路径");
return;
}
CFile sss(m_strSavePath.GetBuffer(100),CFile::modeCreate|CFile::modeWrite);
//按照路径创建一个文件,如果已存在就截短为0
sss.Write(gRFBM_ReceiveBuffer,g2RFBM_ReceiveCount);
sss.Close();
m_Receive="";
g2RFBM_ReceiveCount = 0;
this->UpdateData(false);
return;
}
void CDebug51Dlg::OnRunDSPProgram(){
MRFBM_ChangeBank(1); // 进入运行模式
progress_ctrl.SetPos(0); // 复位进度条
FDSPHardwareBank = 0;
FRFBM_EnableTransferFile = 0;
FRFBM_TransferFile = 0;
return;
}
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
/// 以下程序结构已被大改
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
void CDebug51Dlg::OnTimer(UINT nIDEvent){
if (nIDEvent==1 && FRFBM_Connect){
MRFBM_RX_Buffer();
// 第一次启动检查
if (!FDSPHardwareFound){
if (FRFBM_SlaveNotFound){
MRFBM_RoutineCommand();
}
else {
FDSPHardwareFound = 1;
m_Receive = "DSP硬件已经连接!";
g2RFBM_ReceiveCount = cRFBM_ReceiveBuffer+1;
this->UpdateData(false);
}
}
else {
if (!FDSPHardwareBank && !FRFBM_TransferFile){
MRFBM_RoutineCommand();
}
if (gRFBM_ChangeModeCommand & 0x80){
if (gRFBM_ChangeModeCommand == 0x80){
FDSPHardwareBank = 0;
if (FRFBM_ChangeBank){
FRFBM_ChangeBank = 0;
if (FRFBM_EnableTransferFile){
FRFBM_EnableTransferFile = 0;
FRFBM_TransferFile = 1;
g2PageFileCounter = 0;
gRFBM_WriteDelayTime = 0;
}
gRFBM_WriteStartCommand = 1;
}
}
else {
FDSPHardwareBank = 1;
FRFBM_ChangeBank = 0;
}
gRFBM_Change_Timer = 0;
gRFBM_ChangeModeCommand = 0;
}
if (FRFBM_TransferFile){
MRFBM_WriteFile();
gRFBM_Change_Timer = 0;
}
if (gRFBM_Change_Timer > 0 && --gRFBM_Change_Timer == 0){ // DSP硬件出错
FDSPHardwareBank = 0;
FRFBM_EnableTransferFile = 0;
}
}
}
CDialog::OnTimer(nIDEvent);
return;
}
void CDebug51Dlg::OnSendFile(){
DWORD g4Local_1;
CFile sss;
this->UpdateData(true);
if (!FRFBM_Connect){
AfxMessageBox("请连接串口 !");
return;
}
if (m_strFilePath==""){
AfxMessageBox("没有选择待发送文件 !");
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -