📄 m16cflsh.cpp
字号:
// M16Cflsh.cpp: I do the definition of the class for the application.
//
// 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 "M16CflshDlg.h"
#include "IDCheckDlg.h"
#include "SelectDlg.h"
#include "S_PrgDlg.h"
#include "FirstSetDlg.h"
#include "SettingCmd.h"
#include "SaveIni.h"
#include "defining.h"
int id_send_flg = FALSE;
bool VDC_ON_OFF_STATUS = 0;
int g_FlashType=0;
// #include <iostream.h>
#include <iostream> // for VS.NET
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <fcntl.h>
#include <conio.h>
#include <process.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CM16CflshApp
//////////////////////////////////////////////////////////////////////
//It is letter lines fixed number.
BEGIN_MESSAGE_MAP(CM16CflshApp, CWinApp)
//{{AFX_MSG_MAP(CM16CflshApp)
//}}AFX_MSG_MAP
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//The construction of the CM16CflshApp class
CM16CflshApp::CM16CflshApp()
{
// TODO: Please add the cord for construction to this position.
//Please describe all the important initialization processing in InitInstance here.
}
/////////////////////////////////////////////////////////////////////////////
//The sole CM16CflshApp object
CM16CflshApp theApp;
/////////////////////////////////////////////////////////////////////////////
//The initialization of the CM16CflshApp class
static const TCHAR* APPNAME = _T("M16CFLASH.exe");
BOOL CM16CflshApp::InitInstance()
{
id_send_flg = TRUE;
#if _DEBUG
int hCrt;
FILE *fpConsole = NULL;
HANDLE hStdOut;
AllocConsole();
if( (hStdOut = GetStdHandle(STD_OUTPUT_HANDLE)) != INVALID_HANDLE_VALUE){
hCrt = _open_osfhandle((long)hStdOut, _O_TEXT);
fpConsole = _fdopen(hCrt, "w");
setvbuf(fpConsole,NULL,_IONBF,0);
*stdout= *fpConsole;
}
#endif
//Standard initialization processing
//Please eliminate an unnecessary thing out of the following particular initialization
//routine if you want to make the size of small of the implementation file, without
//using these functions.
m_hMutex = ::CreateMutex(NULL, FALSE, APPNAME);
if(m_hMutex == NULL)
{
AfxGetMainWnd()->MessageBox(GetResString(IDS_PROGRAM_RUN), GetResString(IDS_FLASH_TITLE), MB_ICONERROR);
return FALSE;
}
if(::GetLastError() == 183L)
{
AfxGetMainWnd()->MessageBox(GetResString(IDS_PROGRAM_RUN), GetResString(IDS_FLASH_TITLE), MB_ICONERROR);
return FALSE;
}
// for VS 6.0 need . for VS.NET need comment
// #ifdef _AFXDLL
// Enable3dControls(); //Please call here in the case that I use MFC in sharing DLL.
//
// #else
// Enable3dControlsStatic(); //please call here in the case that it links statically with MFC.
//
// #endif
m_acceptedID = FALSE;
//An initialization dialog is displayed. (it does not do anything now.)
// Check Flash TYPE.
//int nFlashType;
CString nCOMPort;
CS_PrgDlg progDlg;
//progDlg.InitDisp();
progDlg.m_FlashType = 0; // Set Flash Type
// check start type
//Initialize the start .
// CString D_Type = "+a";
CString D_Type = "-a";
{
CSaveIni objInit;
if(NULL != objInit.LoadDType())
{
objInit.GetDType(&D_Type);
}
objInit.SetDType(D_Type);
}
#if _DEBUG
printf(" first func type = %s\n", D_Type);
#endif
CString Z_Type = "-Z";
{
CSaveIni objInit;
if(NULL != objInit.LoadZType())
{
objInit.GetZType(&Z_Type);
}
objInit.SetZType(Z_Type);
}
#if _DEBUG
printf(" first func type send_data f = %s\n", Z_Type);
#endif
LPSTR f_pstr;
f_pstr = GetCommandLine();
char *n;
#if _DEBUG
printf(" command line = %d\n", f_pstr);
#endif
n = strstr(f_pstr,"+a");
#if _DEBUG
printf(" N? +a : %s \n", n);
#endif
if( n != NULL)
D_Type = "+a"; // a_type mode setting
n = strstr(f_pstr,"-a");
#if _DEBUG
printf(" N? -a : %s \n", n);
#endif
if( n != NULL )
D_Type = "-a"; // nomal mode setting
#if _DEBUG
printf(" secound func type = %s\n", D_Type);
#endif
CSaveIni objInit;
objInit.SetDType(D_Type);
objInit.SaveDType();
#if _DEBUG
printf(" command line = %d\n", f_pstr);
#endif
n = strstr(f_pstr,"+Z");
#if _DEBUG
printf(" N? +Z : %s \n", n);
#endif
if( n != NULL)
Z_Type = "+Z"; // Z_type mode setting
n = strstr(f_pstr,"-Z");
#if _DEBUG
printf(" N? -Z : %s \n", n);
#endif
if( n != NULL )
Z_Type = "-Z"; // nomal mode setting
#if _DEBUG
printf(" secound Z func type = %s\n", Z_Type);
#endif
objInit.SetZType(Z_Type);
objInit.SaveZType();
if (progDlg.DoModal() == IDOK)
{
m_FlashType = progDlg.m_FlashType; // Get Flash Type
nCOMPort = progDlg.m_strCOM; // Get USED COM_PORT
}
else // If Cancel buttun Pushed, Program end.
{
return FALSE;
}
if (m_FlashType == 2)
{ // M16C/10
char m16c10_prg[80] = "FlaSta10";
_execl( m16c10_prg, m16c10_prg, nCOMPort, NULL, NULL );
// FlaSta10.exe execute error!
AfxGetMainWnd()->MessageBox(GetResString(IDS_NEXECUTE), GetResString(IDS_FLASH_TITLE), MB_ICONERROR);
return FALSE;
}
//Initialize the serial communication object.
DWORD dwBaudrate = DEFAULT_BAUDRATE;
BYTE btByteSize = DEFAULT_BYTESIZE;
BYTE btParity = DEFAULT_PARITY;
BYTE btStopBits = DEFAULT_STOPBITS;
//GetSerialComm().Open(GetResString(IDS_DEFAULT_COMMPORT)); //open the default port.
//##### modify
// GetSerialComm().Open(nCOMPort); //open the select port.
if(!GetSerialComm().Open(nCOMPort)){ //open the select port.
AfxGetMainWnd()->MessageBox("select port open error", "serial setting",MB_ICONERROR);
return FALSE;
}
//########
SetFirstSerialState(GetSerialComm(), dwBaudrate, btByteSize, btParity, btStopBits);
#if _DEBUG
printf(" First send = %s\n", Z_Type);
#endif
GetSerialComm().SetTimeout(TIMEOUT5);
// set First send data
// BYTE btCommChkW = 0xB0;
BYTE btCommChkW;
if( Z_Type == "+Z" )
{
btCommChkW = 0xB0;
} else {
btCommChkW = 0x00;
}
BYTE btCommChkR = 0;
Sleep(SLEEP_IN);
GetSerialComm().CleanUp(NULL);
GetSerialComm().Write(&btCommChkW, 1);
btCommChkW = 0xB0;
// add 99.4.23 send 0x00 x16
Sleep(SLEEP_IN);
for(int i = 0; i < SEND_00_TIMES ; i++)
{
BYTE BtSnd0 = 0x00;
GetSerialComm().Write(&BtSnd0, 1);
Sleep(20);
}
Sleep(SLEEP_IN);
btCommChkW = 0xB0;
GetSerialComm().Write(&btCommChkW, 1);
Sleep(SLEEP_IN);
// add end
BOOL bCommChk = GetSerialComm().Read(&btCommChkR, 1);
if(!bCommChk || btCommChkR != btCommChkW)
{
// AfxGetMainWnd()->MessageBox(GetResString(IDS_NFIT_MICON), GetResString(IDS_FLASH_TITLE), MB_ICONERROR);
// return FALSE;
//CommError();
DWORD bbb;
bbb = CommError();
if ( bbb == 0 ){
return FALSE;
}
}
Sleep(SLEEP_ONE);
GetSerialComm().CleanUp(NULL);
// CSaveIni objInit;
if(NULL != objInit.LoadComm())
{
objInit.GetComm(&dwBaudrate, &btByteSize, &btParity, &btStopBits);
dwBaudrate = SetSerialState(GetSerialComm(), dwBaudrate, btByteSize, btParity, btStopBits, IDS_SET_BAUDRATE_1);
}
//Communication confirmation
BYTE byteSend = 0x70;
if(!m_FlashType){
BYTE byteSRD[2];
BYTE byteSend = 0x70;
GetSerialComm().CleanUp(NULL);
GetSerialComm().Write(&byteSend, 1);
if(!GetSerialComm().Read(byteSRD, 2))
{
SetAcceptedComm(FALSE);
GetSerialComm().CleanUp(NULL);
int nResponse = 0;
CFirstSetDlg dlg;
nResponse = dlg.DoModal();
if(IDOK == nResponse)
{
CSettingCmd cmd;
cmd.exec();
}
else if(IDCANCEL == nResponse)
{
AfxGetMainWnd()->MessageBox(GetResString(IDS_NCOMM), GetResString(IDS_FLASH_TITLE), MB_ICONERROR);
}
}
else
{
SetAcceptedComm(TRUE);
objInit.SetComm(dwBaudrate, btByteSize, btParity, btStopBits);
objInit.SaveComm();
}
//It confirms whether ID is passing.
// Check ID status.
int nStateID = 3 & (byteSRD[1] >> 2);
if(0 == nStateID)
{
SetAcceptedID(FALSE);
}
else if(1 == nStateID)
{
SetAcceptedID(FALSE);
}
else if(3 == nStateID)
{
SetAcceptedID(TRUE);
}
// Clear dtatus registor.
byteSend = 0x50;
GetSerialComm().Write(&byteSend, 1);
Sleep(SLEEP_IN);
}
else{
SetAcceptedID(TRUE);
SetAcceptedComm(TRUE);
objInit.SetComm(dwBaudrate, btByteSize, btParity, btStopBits);
objInit.SaveComm();
}
CMotFile m_objMotFile;
int nResponse;
if (!m_FlashType) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -