⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 idcheckdlg.cpp

📁 m16c flash startor 源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// IDCheckDlg.cpp: the 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 "IDCheckDlg.h"
#include "defining.h"

extern int id_send_flg;
BYTE g_send[SEND_ID];

#include <stdio.h>
#include <io.h>
#include <fcntl.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CIDCheckDlg dialog
///////// intialize /////////////////////////////////////////////////////////

int CIDCheckDlg::s_MpuIndex = 0;

/////////////////////////////////////////////////////////////////////////////
//A CIDCheckDlg dialog


CIDCheckDlg::CIDCheckDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CIDCheckDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CIDCheckDlg)
	m_strFilename = _T("");
	m_strID1 = _T("");
	m_strID2 = _T("");
	m_strID3 = _T("");
	m_strID4 = _T("");
	m_strID5 = _T("");
	m_strID6 = _T("");
	m_strID7 = _T("");
	m_MpuIndex = -1;
	//}}AFX_DATA_INIT
	m_MpuIndex = s_MpuIndex;
}


void CIDCheckDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CIDCheckDlg)
	DDX_Text(pDX, IDC_EDIT_FILENAME, m_strFilename);
	DDX_Text(pDX, IDC_EDIT_ID1, m_strID1);
	DDX_Text(pDX, IDC_EDIT_ID2, m_strID2);
	DDX_Text(pDX, IDC_EDIT_ID3, m_strID3);
	DDX_Text(pDX, IDC_EDIT_ID4, m_strID4);
	DDX_Text(pDX, IDC_EDIT_ID5, m_strID5);
	DDX_Text(pDX, IDC_EDIT_ID6, m_strID6);
	DDX_Text(pDX, IDC_EDIT_ID7, m_strID7);
	DDX_Radio(pDX, IDC_MPU1, m_MpuIndex);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CIDCheckDlg, CDialog)
	//{{AFX_MSG_MAP(CIDCheckDlg)
	ON_BN_CLICKED(IDC_BUTTON_REFFER, OnButtonReffer)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

	//The data of 1 column is transformed.  
BYTE CIDCheckDlg::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 CIDCheckDlg::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 CIDCheckDlg::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 CIDCheckDlg::OnButtonReffer() 
{


	UpdateData(TRUE);
	s_MpuIndex = m_MpuIndex;

	// 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();
		UpdateData(FALSE);

		//It is when the file name is designated.  
		if(!m_strFilename.IsEmpty())
		{
			s_MpuIndex = 0;
			m_MpuIndex = 0;
			MakeImage(m_strFilename);
			unsigned int nStartAddress = 0;
			unsigned int nEndAddress = 0;
			GetAddressOnly(&nStartAddress, &nEndAddress);
#if _DEBUG
			printf ( "start %X \n",nStartAddress );
			printf ( "end %X \n",nEndAddress );
#endif
			if( nEndAddress == IDS_PROTECT_80){
				s_MpuIndex = 1;
				m_MpuIndex = s_MpuIndex;
				UpdateData(FALSE);
			}else 	if( nEndAddress == IDS_PROTECT_380){
				s_MpuIndex = 2;
				m_MpuIndex = s_MpuIndex;
				UpdateData(FALSE);
			}
		}

		//Id is displayed.  
		CString idFile;
		// The pass name of the id file of a .mot file.
		if(".mot" == m_strFilename.Right(4))
		{
			idFile = m_strFilename.Left(m_strFilename.GetLength() - 4) + ".id";
		}
		// The pass name of the id file of a .s2 file.
		else if(".s2" == m_strFilename.Right(3))
		{
			idFile = m_strFilename.Left(m_strFilename.GetLength() - 3) + ".id";
		}
		// The pass name of the id file of a .s file.
		else if(".s" == m_strFilename.Right(2))
		{
			idFile = m_strFilename.Left(m_strFilename.GetLength() - 2) + ".id";
		}
		// The pass name of the id file of a .btp file.
		else if(".btp" == m_strFilename.Right(4))
		{
			idFile = m_strFilename.Left(m_strFilename.GetLength() - 4) + ".id";
		}
		//A except for mot file.
		else
		{
			CWnd::MessageBox(GetResString(IDS_NACCEPT), GetResString(IDS_FLASH_TITLE), MB_ICONERROR);
			m_strID1 = _T("");
			m_strID2 = _T("");
			m_strID3 = _T("");
			m_strID4 = _T("");
			m_strID5 = _T("");
			m_strID6 = _T("");
			m_strID7 = _T("");
			UpdateData(FALSE);
			return;
		}
		// It is when there is an .id file.  
		TRY
		{
			//Id is displayed.  
			CString strId;
//			s_MpuIndex = 0;
			m_MpuIndex = s_MpuIndex;
			CStdioFile fileId(idFile, CFile::modeRead);
			while(FALSE != fileId.ReadString(strId))
			{
				CString strIdAddress = strId.Left(ID_ADDRESS_80);
				CString strIdAddress2 = strId.Left(ID_ADDRESS_380);
				CString strIdAddress3 = strId.Left(ID_ADDRESS_R8C_S);
//				CString strIdNum = strId.Right(2);
#if _DEBUG

				printf ( "strIdAddress  (80) = %s \n",strIdAddress );
				printf ( "strIdAddress2  (380) = %s \n",strIdAddress2 );
				printf ( "strIdAddress3  (R8C) = %s \n",strIdAddress3 );
#endif
				if(GetResString(IDS_1_80) == strIdAddress)
				{
					s_MpuIndex = 1;
					m_MpuIndex = s_MpuIndex;
				}else if(GetResString(IDS_1_R8C_S) == strIdAddress3)
				{
					s_MpuIndex = 3;
					m_MpuIndex = s_MpuIndex;
				}else if(GetResString(IDS_1_380) == strIdAddress2)
				{
					s_MpuIndex = 2;
					m_MpuIndex = s_MpuIndex;
				}		
			}
		}
		//When there is not the id file.
		CATCH(CFileException, e)
		{
			CWnd::MessageBox(GetResString(IDS_NFIND_ID), GetResString(IDS_FLASH_TITLE), MB_ICONWARNING);
			m_strID1 = _T("");
			m_strID2 = _T("");
			m_strID3 = _T("");
			m_strID4 = _T("");
			m_strID5 = _T("");
			m_strID6 = _T("");
			m_strID7 = _T("");
			UpdateData(FALSE);
			return;
		}
		END_CATCH

		// It is when there is an .id file.  
		TRY
		{
			//Id is displayed.  
			CString strId;
			CStdioFile fileId(idFile, CFile::modeRead);
#if _DEBUG
			printf( "filename = %s \n ",idFile);
			printf( "s_MpuIndex = %d \n", s_MpuIndex );
#endif
			while(FALSE != fileId.ReadString(strId))
			{
				if(s_MpuIndex == 1){
					CString strIdAddress = strId.Left(ID_ADDRESS_80);
					CString strIdNum = strId.Right(2);
#if _DEBUG
					printf( "strIdAddress = %s \n", strIdAddress );
#endif
					if(GetResString(IDS_1_80) == strIdAddress)
					{
						m_strID1 = strIdNum;
					}	
					if(GetResString(IDS_2_80) == strIdAddress)
					{
						m_strID2 = strIdNum;
					}
					if(GetResString(IDS_3_80) == strIdAddress)
					{
						m_strID3 = strIdNum;
					}
					if(GetResString(IDS_4_80) == strIdAddress)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -