📄 checkmemorrycmd.cpp
字号:
// CheckMemorryCmd.cpp: the implementation of the CCheckMemorryCmd class.
//
// 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 "SetAddressDlg.h"
#include "CheckMemorryCmd.h"
#include "SettingCmd.h"
#include "SaveIni.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/disappearance
//////////////////////////////////////////////////////////////////////
CCheckMemorryCmd::CCheckMemorryCmd()
{
}
CCheckMemorryCmd::~CCheckMemorryCmd()
{
}
////////////// This is the minute when I added later.丂////////////////////////////////////////
// The cipher of the hexadecimal number is combined to nDigit.
void CCheckMemorryCmd::ResetDigit(CString* strHex, int nDigit)
{
int nSubDigit = strHex->GetLength() - nDigit;
if(0 < nSubDigit)
{
CString strDummy;
for(int nIndex = 0; nIndex < nDigit; nIndex++)
{
strDummy += strHex->GetAt(nIndex);
}
*strHex = strDummy;
}
else if(0 > nSubDigit)
{
CString strDummy;
nSubDigit = -nSubDigit;
for(int nIndex = 0; nIndex < nSubDigit; nIndex++)
{
strDummy += "0";
}
*strHex += strDummy;
}
}
// The letter line that shows the hexadecimal number is transformed into the int style.
unsigned int CCheckMemorryCmd::StrToHex(CString strHex)
{
unsigned int nHex = 0; // the number after transformation
int nLength = 0;
nLength = strHex.GetLength();
for(int nIndex = 0; nIndex < nLength; nIndex++)
{
TCHAR tchHex = strHex.GetAt(nIndex);
nHex = (nHex * 0x10) + AToHex(&tchHex);
}
return nHex;
}
// The int style is transformed into the letter line that shows the hexadecimal number.
CString CCheckMemorryCmd::HexToStr(unsigned int nXdigit)
{
unsigned char s[2];
CString strRet;
s[1] = '\0';
// A numerical value is transformed into the letter line.
while(nXdigit)
{
CString strAdd;
unsigned int nHex = nXdigit % 0x10;
if(0 <= nHex && 9 >= nHex)
{
s[0] = nHex + '0';
strAdd = CString(s);
}
else if(0x0a <= nHex && 0x0f >= nHex)
{
s[0] = nHex - 0x0a + 'A';
strAdd = CString(s);
}
strRet += strAdd;
nXdigit /= 0x10;
}
// The cipher is combined.
int nDrop = 0;
if(0 < (nDrop = ADDRESS_SIZE - strRet.GetLength()))
{
for(int nIndex = 0; nDrop > nIndex; nIndex++)
{
strRet += "0";
}
}
strRet.MakeReverse();
return strRet;
}
// I acquire the address from the dialog.
BOOL CCheckMemorryCmd::GetAddressFromDialog(unsigned int* nStartAddress, unsigned int* nEndAddress, int nDigit)
{
BOOL bResult = TRUE;
CSetAddressDlg dlg;
int nResponse = 0;
// The initial display setting of the editing box.
if(*nStartAddress || *nEndAddress)
{
CString strStart = HexToStr(*nStartAddress);
CString strEnd = HexToStr(*nEndAddress);
dlg.SetEdit(strStart, strEnd);
}
nResponse = dlg.DoModal();
if(IDOK == nResponse)
{
CString strStart, strEnd;
// I return FALSE if it is not designated the address.
if(!dlg.GetAddress(&strStart, "start"))
{
bResult = FALSE;
}
if(!dlg.GetAddress(&strEnd, "end"))
{
bResult = FALSE;
}
if(!bResult)
{
return bResult;
}
// A letter line is transformed into a numerical value.
*nStartAddress = StrToHex(strStart);
*nEndAddress = StrToHex(strEnd);
// I arrange the address.
*nStartAddress = AddressToPage(*nStartAddress);
*nEndAddress = AddressToPage(*nEndAddress) + 0xff;
return bResult;
}
// When it ended with except for the OK button.
else
{
bResult = FALSE;
}
return bResult;
}
// I acquire the address of the range of the file where at present I am reading.
BOOL CCheckMemorryCmd::GetFileAddress(unsigned int* nStartAddress, unsigned int* nEndAddress, int nDigit)
{
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(!GetAddressFromDialog(nStartAddress, nEndAddress, nDigit))
{
return FALSE;
}
return TRUE;
}
// add EPRCommand function
void CCheckMemorryCmd::GetFileAddressOnly(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;
}
// I arrange the address.
*nStartAddress = AddressToPage(*nStartAddress);
*nEndAddress = AddressToPage(*nEndAddress) + 0xff;
}
// add end EPR Command
// An address is transformed into the data of the transmission form.
void CCheckMemorryCmd::ToSendStyle(int nAddress, BYTE* byteHi, BYTE* byteMid)
{
*byteHi = nAddress / 0x010000;
*byteMid = (nAddress / 0x0100) - (*byteHi * 0x0100);
}
// I implement the lead command.
BOOL CCheckMemorryCmd::DoRead(CSerialComm* pComObj, BYTE* receive, unsigned int nAddress)
{
DWORD dwTimeout = pComObj->GetTimeout();
CSaveIni objInit;
pComObj->SetTimeout(objInit.GetReadTimeout(dwTimeout));
BOOL bResult = TRUE;
BYTE send[3];
send[0] = 0xff;
ToSendStyle(nAddress, &send[2], &send[1]);
// A command is transmitted.
pComObj->CleanUp(NULL);
pComObj->Write(send, 3);
// Receive datas.
int n = 0;
if(!(n = pComObj->Read(receive, PAGE_SIZE)))
{
// /It is the processing at the time of the communication error.
CommError();
bResult = FALSE;
}
pComObj->SetTimeout(dwTimeout);
return bResult;
}
// I check the size of the start address and end address.
BOOL CCheckMemorryCmd::ChkStartToEnd(unsigned int nStart, unsigned int nEnd)
{
if(nStart >= nEnd)
{
return FALSE;
}
return TRUE;
}
// It does a page the clear.
void CCheckMemorryCmd::ClearPage(BYTE bytePage[PAGE_SIZE])
{
for(int nIndex = 0; nIndex < PAGE_SIZE; nIndex++)
{
bytePage[nIndex] = BLANK;
}
}
void CCheckMemorryCmd::BlankPage(BYTE bytePage [ PAGE_SIZE ])
{
for(int nIndex = 0; nIndex < PAGE_SIZE; nIndex++)
{
bytePage[nIndex] = 0x00;
}
}
BOOL CCheckMemorryCmd::GetDownloadAddress(unsigned int * nStartAddress, unsigned int * nEndAddress, int nDigit)
{
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 ( nAddress < 0x2c00 )
{
if(first_time)
{
first_time = false;
*nStartAddress = nAddress;
}
*nEndAddress = nAddress + 0x0100 - 1;
}
}
}
if(!GetAddressFromDialog(nStartAddress, nEndAddress, nDigit))
{
return FALSE;
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -