📄 ppgnewdlg.cpp
字号:
// PPGNEWDlg.cpp : implementation file
/*
1.检测加密是否成功
2.加上版本号检测
*/
/*
1. 支持多字节格式
*/
/*
1.读母片后,直接CONFIG加密
2.烧写校验CONFIG的BUG找到问题 (|or||)//12_19
3.修改LOGO图标
*/
#include "stdafx.h"
#include "PPGNEW.h"
#include "PPGNEWDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CPPGNEWDlg dialog
CPPGNEWDlg::CPPGNEWDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPPGNEWDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPPGNEWDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON1);
}
void CPPGNEWDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPPGNEWDlg)
DDX_Control(pDX, IDC_PIC, m_pic);
DDX_Control(pDX, IDC_EDIT_STATUS, m_cedit_status);
DDX_Control(pDX, IDC_STATIC_BUFCHECKSUM, m_cstatic_bufchksum);
DDX_Control(pDX, IDC_STATIC_BUFCONFIG, m_cstatic_bufconfig);
DDX_Control(pDX, IDC_EDIT_BUF, m_cedit_buf);
DDX_Control(pDX, IDC_PROGRESS1, m_progress);
DDX_Control(pDX, IDC_CHECK1, m_check_protect);
DDX_Control(pDX, IDC_STATIC_NCONFIG, m_cstatic_nconfig);
DDX_Control(pDX, IDC_STATIC_FCONFIG, m_cstatic_fconfig);
DDX_Control(pDX, IDC_STATIC_FCHKSUM, m_cstatic_fchksum);
DDX_Control(pDX, IDC_EDIT_FILE, m_cedit_file);
DDX_Control(pDX, IDC_COMBO_CLOCK, m_cclock);
DDX_Control(pDX, IDC_COMBO_LVR, m_clvr);
DDX_Control(pDX, IDC_COMBO_TYPE, m_ctype);
DDX_Control(pDX, IDC_COMBO_COM, m_ccom);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPPGNEWDlg, CDialog)
//{{AFX_MSG_MAP(CPPGNEWDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_OPEN, OnBtnOpen)
ON_CBN_SELCHANGE(IDC_COMBO_LVR, OnSelchangeComboLvr)
ON_CBN_SELCHANGE(IDC_COMBO_CLOCK, OnSelchangeComboClock)
ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
ON_BN_CLICKED(IDC_BUTTON3, OnButtonReadOtp)
ON_BN_CLICKED(IDC_BUTTON13, OnButtonBlank)
ON_BN_CLICKED(IDC_BUTTON7, OnButtonConnect)
ON_BN_CLICKED(IDC_BUTTON6, OnButtonDownload)
ON_BN_CLICKED(IDC_BUTTON8, OnButtonReadFlash)
ON_BN_CLICKED(IDC_BUTTON4, OnButtonVerify_OTP_FLASH)
ON_BN_CLICKED(IDC_BUTTON15, OnButtonVerify_OTP_FILE)
ON_BN_CLICKED(IDC_BUTTON2, OnButtonBPV)
ON_BN_CLICKED(IDC_BUTTON5, OnButtonWriteOtpFile)
ON_BN_CLICKED(IDC_BUTTON14, OnButtonSave)
ON_BN_CLICKED(IDC_BUTTON1, OnButtonWrtConfig)
ON_BN_CLICKED(IDC_BTN_READCONFIG, OnBtnReadconfig)
ON_BN_CLICKED(IDC_BUTTON_LOCK, OnButtonLock)
ON_BN_CLICKED(IDC_BUTTON_WV, OnButtonWv)
ON_CBN_SELCHANGE(IDC_COMBO_TYPE, OnSelchangeComboType)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON16, OnButtonHelp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPPGNEWDlg message handlers
BOOL CPPGNEWDlg::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
//=======================================
m_nPos=0;
m_iline=0;
CONFIG=0X2FFF; //???
CONFIG_BLANK=0X2FFF;
str_com_data=_T(""); //COM接收的数据
Csframe=_T(""); //接收的桢数据
str_rxhex.Empty();
m_flag_rtx=0;
m_flag_opened=0;
//-------------------------------------
m_ccom.AddString("COM0");
m_ccom.AddString("COM1");
m_ccom.AddString("USB");
m_ccom.SetCurSel(2);
m_ctype.AddString("PM10P40(P20/P16)");
m_ctype.AddString("PM10P40(W20/P8)");
m_ctype.AddString("PM11P40");
m_ctype.AddString("PM12P80");
m_ctype.AddString("PM10P20");
m_ctype.SetCurSel(0);
m_clvr.AddString("3.9V");
m_clvr.AddString("3.0V");
m_clvr.AddString("2.3V");
m_clvr.AddString("2.0V");
m_cclock.AddString("EXTERNAL CRYSTAL");
m_cclock.AddString("EXTERNAL RC");
m_cclock.AddString("INTERNAL RC(0.47M)");
m_cclock.AddString("INTERNAL RC(2.8M)");
m_ccom.EnableWindow(0);
//-----------------------------
m_progress.SetRange(0,100);
m_progress.SetPos(m_nPos);
m_progress.ShowWindow(SW_HIDE);
//=======================================
m_bnewflash =0;
m_breadflash = 0;
m_bblank = 0;
m_breadotp = 0;
m_bwriteotp =0;
m_bbpv=0;
m_bWriteVerify_f=0;
m_bverify_f=0;
m_bverifyotp_file=0;
RomSize=4; //4 表明为ROM SIZE: 4K WORD
OTP_TYPE=m_ctype.GetCurSel();
// SetTimer(000, 500, NULL);
AfxBeginThread(ThreadFun,this);
return TRUE; // return TRUE unless you set the focus to a control
}
void CPPGNEWDlg::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 CPPGNEWDlg::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 CPPGNEWDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CPPGNEWDlg::OnBtnOpen()
{
// TODO: Add your control notification handler code here
CFileDialog fileDlg(TRUE);
fileDlg.m_ofn.lpstrTitle="打开烧录文件";
fileDlg.m_ofn.lpstrFilter="烧录文件(*.hex)\0*.hex\0All Files(*.*)\0*.*\0\0";
fileDlg.m_ofn.lpstrDefExt="hex"; //del
if( fileDlg.DoModal()==IDOK)
{
CFile file(fileDlg.GetFileName(),CFile::modeRead);
char *pBuf;
CString file_buffer;
DWORD dwFileLen;
dwFileLen=file.GetLength();
pBuf=new char[dwFileLen+1];
pBuf[dwFileLen]=0;
file.Read(pBuf,dwFileLen);
file_buffer=(CString)pBuf;
file.Close();
//==================================
str_hexcode=_T(""); //str_hexcode为提取的无间隔的CODE-SOURCE
for(int i=0; i<1024*RomSize+1; i++)
{
str_hexcode=str_hexcode+"3FFF";
}
int int_temp1=0;
BYTE num_byte;
sscanf(file_buffer.Mid(1, 2), "%X", &num_byte);
while(num_byte > 0)
{
// MessageBox(file_buffer);
sscanf(file_buffer.Mid(3,4),"%X",&int_temp1); //提取文件中的地址数送给int_tmp1
if(int_temp1==0x2000)
{
str_hexcode.SetAt(1024*RomSize*4, file_buffer[11]); //最后加上CONFIG
str_hexcode.SetAt(1024*RomSize*4+1, file_buffer[12]);
str_hexcode.SetAt(1024*RomSize*4+2, file_buffer[9]);
str_hexcode.SetAt(1024*RomSize*4+3, file_buffer[10]);
break;
}
if(int_temp1>1024*RomSize)
{
MessageBox("文件和IC型号不匹配"); //如果地址数大于该型号的最大值,就提示错误
return;
}
//加上CODE的n个WORD
for(int i=1; i<(num_byte/2+1); i++)
{
if(file_buffer[(1+i)*4+3]!='F')
str_hexcode.SetAt((int_temp1+i-1)*4, file_buffer[(1+i)*4+3]);
else
str_hexcode.SetAt((int_temp1+i-1)*4, '3'); //CODE_WORD高八位为0XFF, 就当0X3F处理
str_hexcode.SetAt((int_temp1+i-1)*4+1, file_buffer[(1+i)*4+4]);
str_hexcode.SetAt((int_temp1+i-1)*4+2, file_buffer[(1+i)*4+1]);
str_hexcode.SetAt((int_temp1+i-1)*4+3, file_buffer[(1+i)*4+2]);
}
file_buffer.Delete(0, file_buffer.Find("\n", 0)+1);
sscanf(file_buffer.Mid(1, 2), "%X", &num_byte);
}
//========================================== //按照标准显示格式
CString str_temp="0000:| ";
CString str_adr="";
for(i=0; i<1024*RomSize*4; i=i+4)
{
str_temp=str_temp+str_hexcode.Mid(i, 4)+" | ";
if(((i+4)%32==0)&&(i!=0)&&(i!=1024*RomSize*4-4))
{
str_adr.Format("%.4X", (i+4)/4);
str_temp=str_temp+"\r\n"+str_adr+":| ";
}
}
//================================= 计算并显示文件CHECKSUM值
WORD byte_2=0x0000;
WORD check_sum=0x0000;
WORD word_temp;
CString str_temp1;
for(i=0; i<1024*RomSize; i++)
{
sscanf(str_hexcode.Mid(i*4, 4), "%X", &byte_2);
check_sum=check_sum+byte_2;
}
CHECKSUM_F=check_sum;
str_temp1.Format("%.4X", CHECKSUM_F);
m_cstatic_fchksum.SetWindowText("文件CHECKSUM: 0X"+str_temp1);
//=====================================计算文件CONFIG值
sscanf(str_hexcode.Mid(1024*RomSize*4, 4), "%X", &word_temp);
CONFIG=word_temp&CONFIG_BLANK; //更新CONFIG值
str_temp1.Format("%.4X", byte_2);
m_cstatic_fconfig.SetWindowText("文件CONFIG: 0X"+str_hexcode.Mid(1024*RomSize*4, 4));
//=========================== //更新PROTECT
m_check_protect.SetCheck(0);
byte_2=CONFIG&0X2000;
if(byte_2==0X2000)
m_check_protect.SetCheck(0);
else
m_check_protect.SetCheck(1);
//=========================== //更新下拉列表的clock值
byte_2=CONFIG&0X0060;
if(byte_2==0X0000)
m_cclock.SetCurSel(0);
else if(byte_2==0X0020)
m_cclock.SetCurSel(1);
else if(byte_2==0X0040)
m_cclock.SetCurSel(2);
else if(byte_2==0X0060)
m_cclock.SetCurSel(3);
else
{
m_cclock.SetCurSel(-1);
m_clvr.SetCurSel(-1);
}
//============================ //更新下拉列表的LVR值
byte_2=CONFIG&0X001F;
if(byte_2==0X000F)
m_clvr.SetCurSel(0);
else if(byte_2==0X0011)
m_clvr.SetCurSel(1);
else if(byte_2==0X001A)
m_clvr.SetCurSel(2);
else if(byte_2==0X0019)
m_clvr.SetCurSel(3);
else
{
m_cclock.SetCurSel(-1);
m_clvr.SetCurSel(-1);
}
//=================================
if( (OTP_TYPE==2)||(OTP_TYPE==3) )
{
m_cclock.SetCurSel(-1);
m_clvr.SetCurSel(-1);
}
str_temp1.Format("%.4X", CONFIG);
m_cstatic_nconfig.SetWindowText("NEW CONFIG: 0X"+str_temp1);
//==============================
m_flag_opened=1;
m_cedit_file.SetWindowText(str_temp); //显示在m_cedit_file
m_cedit_status.SetWindowText("打开文件"+fileDlg.GetPathName());
}
else
;
// MessageBox("没有打开文件");
}
void CPPGNEWDlg::OnSelchangeComboLvr()
{
// TODO: Add your control notification handler code here
//重新配置CONFIG的LVR电压
if(!m_flag_opened)
{
AfxMessageBox("文件还没有打开");
m_clvr.SetCurSel(-1);
m_cclock.SetCurSel(-1);
return;
}
int i=m_clvr.GetCurSel();
CString str_temp1;
CONFIG=CONFIG&0XFFE0;
if(i==0)
CONFIG=CONFIG+0X000F;
if(i==1)
CONFIG=CONFIG+0X0011;
if(i==2)
CONFIG=CONFIG+0X001A;
if(i==3)
CONFIG=CONFIG+0X0019;
str_temp1.Format("%.4X", CONFIG);
m_cstatic_nconfig.SetWindowText("NEW CONFIG: 0X"+str_temp1);
}
void CPPGNEWDlg::OnSelchangeComboClock()
{
// TODO: Add your control notification handler code here
//重新配置CONFIG的CLOCK参数
if(!m_flag_opened)
{
AfxMessageBox("文件还没有打开");
m_clvr.SetCurSel(-1);
m_cclock.SetCurSel(-1);
return;
}
int i=m_cclock.GetCurSel();
CString str_temp1;
CONFIG=CONFIG&0XFF9F;
if(i==0)
CONFIG=CONFIG+0X0000;
if(i==1)
CONFIG=CONFIG+0X0020;
if(i==2)
CONFIG=CONFIG+0X0040;
if(i==3)
CONFIG=CONFIG+0X0060;
str_temp1.Format("%.4X", CONFIG);
m_cstatic_nconfig.SetWindowText("NEW CONFIG: 0X"+str_temp1);
}
BEGIN_EVENTSINK_MAP(CPPGNEWDlg, CDialog)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -