rfvcDlg.cpp 13.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
// rfvcDlg.cpp : implementation file
//

#include "stdafx.h"
#include "rfvc.h"
#include "rfvcDlg.h"
#include "dcrf32.h"
#include "General.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//dc_HANDLE icdev;
HANDLE icdev;
unsigned long cardsnr;
/////////////////////////////////////////////////////////////////////////////
// CRfvcDlg dialog

CRfvcDlg::CRfvcDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CRfvcDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRfvcDlg)
	
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CRfvcDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRfvcDlg)
	DDX_Control(pDX, IDC_LIST1, m_list1);

	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CRfvcDlg, CDialog)
	//{{AFX_MSG_MAP(CRfvcDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
	ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
	ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
	ON_BN_CLICKED(IDC_BUTTON11, OnButton11)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRfvcDlg message handlers

BOOL CRfvcDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 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
    icdev=0;	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// 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 CRfvcDlg::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 CRfvcDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
void CRfvcDlg::show(CString datastr)
{

		m_list1.AddString(datastr);
		m_list1.SetCurSel(m_list1.GetCount()-1);
		MSG message;
		if (::PeekMessage(&message,NULL,0,0,PM_REMOVE))
		{
			::TranslateMessage(&message);
			::DispatchMessage(&message);
		}
}
void CRfvcDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here

	//初始化串口1,       
	icdev=dc_init(1,115200);
	if((int)icdev<=0)
	{
	   show("Init Com Error!");
	}
	else
	{
      show("Init Com OK!");
	}
	dc_beep(icdev,10);
	return;

}

void CRfvcDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here

	//下载密码,       
  int st;
  unsigned char keyA[6]={0xff,0xff,0xff,0xff,0xff,0xff};
  st=dc_load_key(icdev,0,32,keyA);
  if(st!=0)
	 show("Load Key Error!");
  else
	 show("Load Key Ok!");	
}

void CRfvcDlg::OnButton3() 
{
	// TODO: Add your control notification handler code here

	//寻卡函数,      
	int st;
	CString linstr;

	st=dc_card(icdev,0,&cardsnr);
    if(st!=0)
	{
   	   show("Find Card Error!");
       return;
	}
	else
	{
		show("Find Card Ok!");
	    linstr.Format("%d",cardsnr);
	    show(linstr);

	}

}

void CRfvcDlg::OnButton4() 
{
	// TODO: Add your control notification handler code here
	
	//核对密码       
	int st;
	st=dc_authentication(icdev,0,15);
    if(st!=0)
   	   show("Auth Card Error!");
    else
	   show("Auth Card Ok!");		


}

void CRfvcDlg::OnButton5() 
{
	// TODO: Add your control notification handler code here

	//写数据     
	int st;
	unsigned char databuff[]={0x44,0x33,0x33,0x66,0x33,0x44,0x33,0x66,0x36,0x34,0x33,0x44,0x33,0x66,0x36,0x34,0x00};//
	char databuff2[33];

	st=dc_write(icdev,61,databuff);
    if(st!=0)
	{
   	   show("Write Card Error!");
	   return;
	}
    else
	{
	   show("Write Card Ok!");	
       show(databuff);
	}
	st=dc_write_hex(icdev,254,databuff2);
    if(st!=0)
   	   show("Writehex Card Error!");
    else
	{
	   show("Writehex Card Ok!");	
       show(databuff2);
	}

}


void CRfvcDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	dc_exit(icdev);
	CDialog::OnClose();
}

void CRfvcDlg::OnButton7() 
{
	// TODO: Add your control notification handler code here
    int st;
	st=dc_halt(icdev);
    if(st!=0)
   	   show("Halt Card Error!");
    else
	   show("Halt Card Ok!");	
	
}

void CRfvcDlg::OnButton8() 
{
	// TODO: Add your control notification handler code here
    // 设备函数          
	unsigned char key[]={'1','2','3','4','5','6','7','8','9','0','a','b','c','d','e','f',0};
    unsigned char sour[]={'a','b','c','d','e','f','1','2','3','4','5','6','8','7','9','0',0};

	unsigned char dest[16];
	int st;
    unsigned char addr;
	unsigned char len;
	unsigned char datastr[10];
    CString linstr;
	unsigned char linchar[17];
	unsigned char timestr[17];



    memset(linchar,0,16);
	st= dc_getver(icdev,linchar);//得设备号
	if (st!=0)
	{
		show("dc_getver error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_getver ok");
//	hex_a(linchar,linchar,8);
	show(linchar);
	
    linchar[0]=0x45;
    linchar[1]=0x75;
    linchar[3]=0x55;
    linchar[4]=0x65;
    linchar[2]=0x35;
	linchar[5]=0;
	st= dc_swr_eeprom(icdev,500,5,linchar);//写存储器EEPROM的函数(范围:0-1597)
	if (st!=0)
	{
		show("dc_swr_eeprom error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_swr_eeprom ok");

	linchar[0]=0;
	st= dc_srd_eeprom(icdev,500,5,linchar);//read
	if (st!=0)
	{
		show("dc_srd_eeprom error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_srd_eeprom ok");
	linchar[5]=0;
	show(linchar);

	linchar[0]='4';
    linchar[1]='5';
    linchar[2]='7';
    linchar[3]='5';
    linchar[4]='3';
    linchar[5]='5';
    linchar[6]='5';
    linchar[7]='5';
    linchar[8]='6';
    linchar[9]='5';
	linchar[10]=0;
	st= dc_swr_eepromhex(icdev,600,5,linchar);//
	if (st!=0)
	{
		show("dc_swr_eepromhex error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_swr_eepromhex ok");

	linchar[0]=0;
	st= dc_srd_eepromhex(icdev,600,5,linchar);
	if (st!=0)
	{
		show("dc_srd_eepromhex error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_srd_eepromhex ok");
	linchar[10]=0;
	show(linchar);
    
	linchar[0]='a';
    linchar[1]='.';
    linchar[2]='b';
    linchar[3]='.';
    linchar[4]='c';
    linchar[5]='d';
    linchar[6]='.';
    linchar[7]='0';
	st= dc_disp_str(icdev,(char *)linchar);//数码显示
	if (st!=0)
	{
		show("dc_disp_str error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_disp_str ok");

	st= dc_reset(icdev,100);//设备复位
	if (st!=0)
	{
		show("dc_reset error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_reset ok");

	st= dc_setbright(icdev,10);//设计亮度函数,0-15
	if (st!=0)
	{
		show("dc_setbright error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_setbright ok");

	st= dc_ctl_mode(icdev,1);//控制显示函数,0:计算机控制显示,1:读写器控制显示
	if (st!=0)
	{
		show("dc_ctl_mode error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_ctl_mode ok");

	st= dc_disp_mode(icdev,1);//显示格式函数,0,年-月-日,1:时-分-秒
	if (st!=0)
	{
		show("dc_disp_mode error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_disp_mode ok");

	st= dc_gettime( icdev,timestr); //从设备获取时间,格式:年,星期,月,日,时,分,秒 
	if (st!=0)
	{
		show("dc_gettime error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_gettime ok");
	timestr[7]=0;

	st= dc_settime( icdev,timestr );  //设计设备时间,格式:年,星期,月,日,时,分,秒
	if (st!=0)
	{
		show("dc_settime error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_settime ok");

	hex_a(timestr,linchar,7);
	show(linchar);

	
	st= dc_gettimehex( icdev,(char *)timestr); 
	if (st!=0)
	{
		show("dc_gettimehex error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_gettimehex ok");
	timestr[14]=0;
	show(timestr);

	st= dc_settimehex( icdev,(char *)timestr);
	if (st!=0)
	{
		show("dc_settimehex error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_settimehex ok");
	timestr[14]=0;
	show(timestr);
//	

    datastr[0]=0x80;
    datastr[1]=0x45;
    datastr[2]=0x8c;
    datastr[3]=0x00;
    datastr[4]=0x8a;
	datastr[5]=0x61;
    datastr[6]=0x01;
    addr=1;
	len=7;
	st= dc_high_disp(icdev, addr,len,datastr);//显示字符串操作
	if (st!=0)
	{
		show("dc_high_disp error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_high_disp ok");

    //des算法加解密函数 ,            
	st=dcdeshex(key,sour,dest,0);
    if (st!=0)
	{
		show("dcdeshex error");
		return;
	}
	show("dcdeshex ok");
	dest[16]=0;
	show(dest);

	show(sour);
    sour[0]=0;

	st=dcdeshex(key,dest,sour,1);
    if (st!=0)
	{
		show("dcdeshex error");
		return;
	}
	show("dcdeshex ok");
	sour[16]=0;
	show(sour);


}	

void CRfvcDlg::OnButton9() 
{ 
	//高级函数(不用执行dc_card)
	int st;
	CString linstr;
	unsigned char pieceaddr=128;
	unsigned long cardsnr=0;
	unsigned char wrdata[33]={'3','4','6','5','3','3','8','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3',0};
	unsigned char redata[33];
	//unsigned char cardsnrchar[16];


	st= dc_HL_authentication(icdev,0,0,0,32);
	if (st!=0)
	{
		show("dc_HL_authentication error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_HL_authentication ok");

	wrdata[16]=0;	
	st= dc_HL_write(icdev,0,pieceaddr,&cardsnr,wrdata);
	if (st!=0)
	{
		show("dc_HL_write error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_HL_write ok");
	linstr.Format("%d",cardsnr);
	show(linstr);
	cardsnr=0;
    
	st= dc_HL_read(icdev,0,pieceaddr,0,redata,&cardsnr);
	if (st!=0)
	{
		show("dc_HL_read error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_HL_read ok");
	linstr.Format("%d",cardsnr);
	show(linstr);
	redata[16]=0;
	show(redata);

    wrdata[16]='3';
	st= dc_HL_writehex(icdev,0,pieceaddr,&cardsnr,wrdata);
	if (st!=0)
	{
		show("dc_HL_writehex error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_HL_writehex ok");
	linstr.Format("%d",cardsnr);
	show(linstr);
      
	memset(redata,0,32);
	st= dc_HL_readhex(icdev,0,pieceaddr,0, redata,&cardsnr);
	if (st!=0)
	{
		show("dc_HL_readhex error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_HL_readhex ok");
	linstr.Format("%d",cardsnr);
	show(linstr);
	redata[32]=0;
	show(redata);
    
	
}


void CRfvcDlg::OnButton11() 
{
	//卡函数,
    unsigned char pieceaddr;
	unsigned long value;
    CString linstr;
    int st;
	unsigned char keya[7]={0xff,0xff,0xff,0xff,0xff,0xff};
	unsigned char keyb[7]={0xff,0xff,0xff,0xff,0xff,0xff};
	
	unsigned char datachar[40]={'3','4','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3'};
	
	
	int i;
	unsigned char databuff[17]={0};
	char databuff2[33]={0};




    //写数据      wfl   2003.10.28
	srand(time(NULL));
	for (i=0;i<16;i++)
	{
		databuff[i]=rand();
	}
	st=dc_write(icdev,61,databuff);
    if(st!=0)
	{
		show("Write Card Error!");
		return;
	}
    else
	{
		show("Write Card Ok!");	
		show(databuff);
	}
	st=dc_read_hex(icdev,61,databuff2);
    if(st!=0)
	{
		show("Readhex Card Error!");
		return;
    }
	else
	{
		show("Readhex Card Ok!");
		show(databuff2);		
	}	
	st=dc_write_hex(icdev,62,databuff2);
    if(st!=0)
		show("Writehex Card Error!");
    else
	{
		show("Writehex Card Ok!");	
		show(databuff2);
	}	
	st=dc_read(icdev,62,databuff);	
    if(st!=0)
		show("Read Card Error!");
    else
	{
		show("Read Card Ok!");
		memset(databuff2,0,32);
		hex_a(databuff,(unsigned char *)databuff2,16);
		show(databuff2);
	}
	
    st= dc_check_write(icdev,cardsnr,0,62,(unsigned char *)databuff);
	if (st!=0)
	{
		show("dc_check_write error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_check_write ok");
   st= dc_check_writehex(icdev,cardsnr,0,61,(unsigned char *)databuff2);
	if (st!=0)
	{
		show("dc_check_writehex error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_check_writehex ok");
	
    st= dc_changeb3(icdev,15,keya,0,0,0,1,0,keyb);//修改密码下列控制位参数值保证与原密码和控制位一致,一般建议不要改参数3,4,5,6,7
	if (st!=0)
	{
		show("dc_changeb3 error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_changeb3 ok");
	
	value=10000;
	pieceaddr=61;
    st= dc_initval(icdev, pieceaddr, value);
	if (st!=0)
	{
		show("dc_initval error");
	    linstr.Format("%d",st);
	    show(linstr);
		return;
	}
	show("dc_initval ok");

	value=20;
	st= dc_increment( icdev,pieceaddr,value);
	if (st!=0)
	{
		show("dc_increment error");
		return;
	}
	show("dc_increment ok");
	value=200;

    st= dc_decrement( icdev,pieceaddr,value);
	if (st!=0)
	{
		show("dc_decrement error");
		return;
	}
	show("dc_decrement ok");

    st= dc_readval(icdev,pieceaddr,&value);
	if (st!=0)
	{
		show("dc_readval error");
		return;
	}
	show("dc_readval ok");
	linstr.Format("%d",value);
	show(linstr);

return;
}