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

📄 cpudlg.cpp

📁 智能卡 CPU卡操作DEMO 测试工具
💻 CPP
字号:
// cpuDlg.cpp : implementation file
//

#include "stdafx.h"
#include "cpudemo.h"
#include "cpuDlg.h"
#include "mc900.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()

/////////////////////////////////////////////////////////////////////////////
// CCpuDlg dialog

CCpuDlg::CCpuDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCpuDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCpuDlg)
	m_port = 0;
	m_class = 0;
	m_input = _T("00 a4 04 0c 06 'JSIC01'");
	m_output = _T("");
	m_line = _T("");
	m_status = _T("");
	m_sw1 = _T("");
	m_sw2 = _T("");
	m_power = FALSE;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CCpuDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCpuDlg)
	DDX_Radio(pDX, IDC_RADIO1, m_port);
	DDX_Radio(pDX, IDC_RADIO5, m_class);
	DDX_Text(pDX, IDC_EDIT1, m_input);
	DDX_Text(pDX, IDC_EDIT2, m_output);
	DDX_Text(pDX, IDC_EDIT3, m_line);
	DDX_Text(pDX, IDC_EDIT4, m_status);
	DDX_Text(pDX, IDC_EDIT5, m_sw1);
	DDX_Text(pDX, IDC_EDIT6, m_sw2);
	DDX_Check(pDX, IDC_CHECK1, m_power);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCpuDlg, CDialog)
	//{{AFX_MSG_MAP(CCpuDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_SEND, OnButtonSend)
	ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCpuDlg message handlers

BOOL CCpuDlg::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);
	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
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CCpuDlg::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 CCpuDlg::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 CCpuDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

int GetString(unsigned char * data,CString Src)
{
int i,j,k,len;
char ch;
	len=Src.GetLength();
    for(i=0,j=0,k=0;i<len;i++){
		ch=Src[i];
		switch(k){
		case 0://no data
			ch=(char)toupper(ch);
			if(ch=='\'')
				k=2;
			if(!isxdigit(ch))
				continue;
			data[j]=isdigit(ch)? ch-'0': ch-'A'+10;
			k=1;
			break;
		case 1:// 1 data
			ch=(char)toupper(ch);
			if(!isxdigit(ch)){
				k=0;
				//k=(ch=='\''? 2:0);
				//j++;
				continue;
			}
			data[j]=data[j]*16+(isdigit(ch)? ch-'0': ch-'A'+10);
			j++;
			k=0;
			break;
		case 2:
			if(ch=='\'')
				{k=0; continue;}
			data[j++]=ch;
		}
	}
	if(k==1)
		j--;

	return j;
}


void CCpuDlg::OnButtonSend() 
{
	unsigned char data[256],buf[10],me1,me2;
	int i,status,line,len;

	lock();
	UpdateData(TRUE);

	data[0]=m_class==0? 0xDA:0xDB;

	len=2;
    len=GetString(data+1,m_input)+1;
	CommonCommand( m_port+1,data,len, &me1, &me2, &status, &line,&len);
	
	for(i=0,m_output.Empty();i<len;i++){
		sprintf((char *)buf,"%02X ",data[i]);
		m_output+=buf;
	}

 	sprintf((char *)buf,"%02X ",me1);
	m_sw1=buf;
 	sprintf((char *)buf,"%02X ",me2);
	m_sw2=buf;
 	sprintf((char *)buf,"%04X ",line);
	m_line=buf;
 	sprintf((char *)buf,"%04X ",status);
	m_status=buf;
	
	UpdateData(FALSE);
	unlock();
}


void CCpuDlg::OnCheck1() 
{
	unsigned char data[256],buf[10],me1,me2;
	int status,line,len,i;

	lock();
	UpdateData(TRUE);

	if(m_power){
		if(OpenCom(m_port+1,9600)==0){
			//open com OK
			PowerOn (m_port+1, data, &me1, &me2, &status, &line);
			len=min(30,(int)data[2]);
			for(i=0,m_output.Empty();i<len;i++){
				sprintf((char *)buf,"%02X ",data[i+3]);
				m_output+=buf;
			}
			sprintf((char *)buf,"%02X ",me1);
			m_sw1=buf;
 			sprintf((char *)buf,"%02X ",me2);
			m_sw2=buf;
 			sprintf((char *)buf,"%04X ",line);
			m_line=buf;
 			sprintf((char *)buf,"%04X ",status);
			m_status=buf;

			UpdateData(FALSE);

			if(line==0 && status==0){
				//power on OK
				GetDlgItem(IDC_CHECK1)->SetWindowText("Power Off");
			}
			else{
				//power on fail
				CloseCom(m_port+1);
				m_power=FALSE;
				UpdateData(FALSE);
				MessageBox("Power On Failure");
			}

		}
		else{
			//open com fail
			m_power=FALSE;
			UpdateData(FALSE);
			MessageBox("Open Com Failure");
		}
	}
	else{
		PowerOff(m_port+1,&status,&line);
		CloseCom(m_port+1);
		GetDlgItem(IDC_CHECK1)->SetWindowText("Power On");
	}

	unlock();
}

void CCpuDlg::lock() 
{
	GetDlgItem(IDCANCEL)->EnableWindow(FALSE);
	GetDlgItem(IDC_RADIO1)->EnableWindow(FALSE);
	GetDlgItem(IDC_RADIO2)->EnableWindow(FALSE);
	GetDlgItem(IDC_RADIO3)->EnableWindow(FALSE);
	GetDlgItem(IDC_RADIO4)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_SEND)->EnableWindow(FALSE);
}

void CCpuDlg::unlock() 
{
	if(m_power)	
		GetDlgItem(IDC_BUTTON_SEND)->EnableWindow(TRUE);
	else{
		GetDlgItem(IDCANCEL)->EnableWindow(TRUE);
		GetDlgItem(IDC_RADIO1)->EnableWindow(TRUE);
		GetDlgItem(IDC_RADIO2)->EnableWindow(TRUE);
		GetDlgItem(IDC_RADIO3)->EnableWindow(TRUE);
		GetDlgItem(IDC_RADIO4)->EnableWindow(TRUE);
	}
}

⌨️ 快捷键说明

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