📄 selectdlg.cpp
字号:
// SelectDlg.cpp : Implementation file
//
// This software can be offered for free and used as necessary to aid
// in your program developments.
//
// RENESAS TECHNOLOGY CORPORATION, RENESAS SOLUTIONS CORPORATION,
// and related original software developers assume no responsibility
// for any damage or infringement of any third-party's rights, originating
// in the use of the following software.
// Please use this software under the agreement and acceptance of these conditions.
//
// Copyright(C)1998(2003) RENESAS TECHNOLOGY CORPORATION AND RENESAS SOLUTIONS CORPORATION
// ALL RIGHTS RESERVED
//
#include "stdafx.h"
#include "m16cflsh.h"
#include "SelectDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSelectDlg dialog
CSelectDlg::CSelectDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSelectDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSelectDlg)
m_strFilename = _T("");
//}}AFX_DATA_INIT
}
void CSelectDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSelectDlg)
DDX_Text(pDX, IDC_EDIT_FILENAME, m_strFilename);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSelectDlg, CDialog)
//{{AFX_MSG_MAP(CSelectDlg)
ON_BN_CLICKED(IDC_BUTTON_REFFER, OnButtonReffer)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSelectDlg Message handle
//The data of 1 column is transformed.
BYTE CSelectDlg::charToByte(TCHAR chHex)
{
//Returning NOT_MOT if it is not a hexadecimal number.
if(!isxdigit(chHex))
{
return NOT_MOT;
}
//It transforms it into the BYTE style.
BYTE byteHex = 0;
if('0' <= chHex && '9' >= chHex)
{
byteHex = chHex - '0';
}
else if('a' <= chHex && 'f' >= chHex)
{
byteHex = chHex - 'a' + 0x0a;
}
else if('A' <= chHex && 'F' >= chHex)
{
byteHex = chHex - 'A' + 0x0A;
}
return byteHex;
}
//The data of 1 byte is transformed.
BOOL CSelectDlg::strToByte(BYTE* byteHex, CString strHex)
{
//Returning FALSE if byteHex is not a blank it ends.
if(BLANK != *byteHex)
{
return FALSE;
}
//Returning FALSE if it is not a hexadecimal number.
if(!isxdigit(strHex.GetAt(0)) || !isxdigit(strHex.GetAt(1)))
{
return FALSE;
}
//It transforms it into the BYTE style.
int nLength = strHex.GetLength();
for(int nDigit = 0; nDigit < nLength; nDigit++)
{
*byteHex = (*byteHex * 0x10) + charToByte(strHex.GetAt(nDigit));
}
return TRUE;
}
//I check whether ID passed.
int CSelectDlg::checkID(void)
{
int bResult = 0;
//I acquire the communication object.
CSerialComm& comObj = GetSerialComm();
//I acquire status.
BYTE send = 0x70;
BYTE btSRD[2];
comObj.Write(&send, 1);
if(!comObj.Read(btSRD, 2))
{
return -1;
}
//I check ID status.
int nStateID = 3 & (btSRD[1] >> 2);
if(0 == nStateID)
{
bResult = 0;
}
else if(1 == nStateID)
{
bResult = 0;
}
else if(3 == nStateID)
{
bResult = 1;
}
return bResult;
}
/////////////////////////////////////////////////////////////////////////////
//CIDCheckDlg message handle
void CSelectDlg::OnButtonReffer()
{
UpdateData(TRUE);
// MPU type set
// s_MpuIndex = m_MpuIndex;
// TODO: Add the cord for control notice handle to this position
char* filter = FS_MOT FS_BOOT FS_ALLFILES;
//It is a file frank dialog.
CFileDialog dlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | 0, filter);
//Any file was selected.
if(IDOK == dlg.DoModal())
{
m_strFilename = dlg.GetPathName();
m_strFilename.MakeUpper();
UpdateData(FALSE);
//It is when the file name is designated.
if(!m_strFilename.IsEmpty())
{
MakeImage(m_strFilename);
unsigned int nStartAddress = 0;
unsigned int nEndAddress = 0;
GetAddressOnly(&nStartAddress, &nEndAddress);
}
//I Checked File name.
// The pass name of the id file of a .mot file.
if(".MOT" == m_strFilename.Right(4))
{
}
// The pass name of the id file of a .s file.
else if(".S" == m_strFilename.Right(2))
{
}
// The pass name of the id file of a .s2 file.
else if(".S2" == m_strFilename.Right(3))
{
}
//A except for mot file.
else
{
CWnd::MessageBox(GetResString(IDS_NACCEPT), GetResString(IDS_FLASH_TITLE), MB_ICONERROR);
m_strFilename = _T("");
UpdateData(FALSE);
return;
}
}
}
void CSelectDlg::OnOK()
{
// TODO: Add the cords for other inspections to this position.
BeginWaitCursor();
UpdateData(TRUE);
//It is when the file name is designated.
if(!m_strFilename.IsEmpty())
{
MakeImage(m_strFilename);
//ID is passing.
SetAcceptedID(TRUE);
//I make the transmission image.
MakeImage(m_strFilename);
EndWaitCursor();
CDialog::OnOK();
}
//It is when the file name is not designated.
else
{
MessageBox(GetResString(IDS_NFILE), GetResString(IDS_FLASH_TITLE), MB_ICONWARNING);
}
EndWaitCursor();
}
void CSelectDlg::GetAddressOnly(unsigned int* nStartAddress, unsigned int* nEndAddress)
{
BYTE byteDummy[PAGE_SIZE];
CLineImage* ptrIs;
bool first_time = true;
unsigned int nAddress = 0;
for(int nIndex = 0; NUM_PAGE2 > nIndex; nIndex++) // I decide it.
{
ptrIs = GetPage(byteDummy, nIndex);
if(NULL != ptrIs)
{
nAddress = (unsigned int)(nIndex * 0x0100);
if(first_time)
{
first_time = false;
*nStartAddress = nAddress;
}
*nEndAddress = nAddress + 0x0100 - 1;
}
}
if(first_time)
{
*nStartAddress = DEF_START_ADDRESS;
*nEndAddress = DEF_END_ADDRESS;
}
}
void CSelectDlg::OnCancel()
{
CDialog::OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -