Qt_C++读写t5557卡复制HID卡源码

news2024/10/5 19:11:26

      T5557卡是美国Atmel公司生产的多功能非接触式射频卡芯片,属于125KHz的低频卡,在国内有广大的应用市场。该芯片共有330bit(比特)的EPROM(分布为10个区块, 每个区块33bit)。0页的块0是被保留用于设置T5557操作模式的参数配置块。第0页第7块可以作用户数据块使用,也可以作为保护全部数据的密码(假如在配置块中启用密码功能的话),防止非法改写数据。 第1页的1、2块保存了出厂商信息及唯一出厂ID,只能读取不可更改,我们的读写器取出其中的6个字节做为物理卡号,以实现与13.56等高频卡相同的应用场景。

        T5567、T5577是T5557的升级版。

发卡器介绍:T5557 T5567 T5577低频RFID读写器 EM4100 HID卡复制器 酒店门卡-淘宝网 (taobao.com)

一、函数声明 

#include <QDebug>
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "QLibrary"
#include "QMessageBox"

//函数声明
//驱动发卡器响声
typedef  unsigned char (*idr_beep)(unsigned long xms);
idr_beep myidr_beep = (idr_beep)QLibrary("OUR_IDR.dll").resolve("idr_beep");

//读取发卡器编号
typedef  unsigned char  (*pcdgetdevicenumber)(unsigned char *devicenumber);
pcdgetdevicenumber mypcdgetdevicenumber = (pcdgetdevicenumber)QLibrary("OUR_IDR.dll").resolve("pcdgetdevicenumber");

//读t5557卡
typedef  unsigned char (*t5557_read)(unsigned char ctrlword,unsigned char *piccserial,unsigned char *authkey,unsigned char *blockflag,unsigned char *readdata);
t5557_read myt5557_read = (t5557_read)QLibrary("OUR_IDR.dll").resolve("t5557_read");

//写t5557卡
typedef  unsigned char (*t5557_write)(unsigned char ctrlword,unsigned char *piccserial,unsigned char *authkey,unsigned char *blockflag,unsigned char *writedata);
t5557_write myt5557_write = (t5557_write)QLibrary("OUR_IDR.dll").resolve("t5557_write");

//修改t5557卡密码
typedef  unsigned char (*t5557_changekey)(unsigned char ctrlword,unsigned char *piccserial,unsigned char *authkey,unsigned char *newkey);
t5557_changekey myt5557_changekey = (t5557_changekey)QLibrary("OUR_IDR.dll").resolve("t5557_changekey");

//修改t5557卡配置值
typedef  unsigned char (*t5557_init)(unsigned char ctrlword,unsigned char *piccserial,unsigned char *authkey,unsigned char *mypiccdata,unsigned char *newkey);
t5557_init myt5557_init = (t5557_init)QLibrary("OUR_IDR.dll").resolve("t5557_init");

//读id卡
typedef  unsigned char (*idr_read)(unsigned char *piccserial);
idr_read myidr_read = (idr_read)QLibrary("OUR_IDR.dll").resolve("idr_read");

//读hid卡
typedef  unsigned char (*hid_read)(unsigned char *piccserial);
hid_read myhid_read = (hid_read)QLibrary("OUR_IDR.dll").resolve("hid_read");

//将t5557卡制作成ID卡
typedef  unsigned char (*t5557_to4100)(unsigned char ctrlword,unsigned char *piccserial,unsigned char *authkey,unsigned char *newkey,unsigned char *newuid);
t5557_to4100 myt5557_to4100 = (t5557_to4100)QLibrary("OUR_IDR.dll").resolve("t5557_to4100");

//将t5557卡制作成HID卡
typedef  unsigned char (*t5557_tohid)(unsigned char ctrlword,unsigned char *piccserial,unsigned char *authkey,unsigned char *newkey,unsigned char *newuid);
t5557_tohid myt5557_tohid = (t5557_tohid)QLibrary("OUR_IDR.dll").resolve("t5557_tohid");


const unsigned char NEEDSERIAL=0x01;   //需要只对指定系列号的卡操作
const unsigned char NEEDKEY=0x02;      //需要用密码认证
const unsigned char LOCKBIT=0x04;      //锁定配置块或数据块
const unsigned char KEYENABLE=0x08;    //启用本卡的密码功能
const unsigned char RESETCARD=0x10;    //操作成功后重启卡片

二、读取t5557卡块数据

void MainWindow::on_push_readcard_clicked()
{
    unsigned char status;
    unsigned char myctrlword=0;
    unsigned char mypiccserial[6];
    unsigned char oldpicckey[4];
    unsigned char mypiccdata[50];
    unsigned char mypiccblockflag[2];

    if(ui->check_authkey->isChecked()){
        QString authkey=ui->text_authkey->text().trimmed();
        if(authkey.length()==8 and checkinput(authkey)){
            for(int i=0;i<4;i++){
                bool ok;
                oldpicckey[i]=QString(authkey.mid(i*2,2)).toInt(&ok,16);
            }
            myctrlword=myctrlword+NEEDKEY;
        }else{
            QMessageBox::critical(NULL, "提示","请输入8位16进制认证密码!");
            return;
        }
    }

    if(ui->check_serial->isChecked()){
        QString picserial=ui->text_piccserial->text().trimmed();
        if(picserial.length()==12 and checkinput(picserial)){
            for(int i=0;i<6;i++){
                bool ok;
                mypiccserial[i]=QString(picserial.mid(i*2,2)).toInt(&ok,16);
            }
            myctrlword=myctrlword+NEEDSERIAL;
        }else{
            QMessageBox::critical(NULL, "提示","请输入12位16进制卡号!");
            return;
        }
    }

    mypiccblockflag[0]=0;
    if(ui->check_block0->isChecked()){mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,0);}
    if(ui->check_block1->isChecked()){mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,1);}
    if(ui->check_block2->isChecked()){mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,2);}
    if(ui->check_block3->isChecked()){mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,3);}
    if(ui->check_block4->isChecked()){mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,4);}
    if(ui->check_block5->isChecked()){mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,5);}
    if(ui->check_block6->isChecked()){mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,6);}
    if(ui->check_block7->isChecked()){mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,7);}

    mypiccblockflag[1]=0;
    if(ui->check_block8->isChecked()){mypiccblockflag[1]=mypiccblockflag[1]+qPow(2,1);}
    if(ui->check_block9->isChecked()){mypiccblockflag[1]=mypiccblockflag[1]+qPow(2,2);}
    if(ui->check_block10->isChecked()){mypiccblockflag[1]=mypiccblockflag[1]+qPow(2,3);}
    if(ui->check_block11->isChecked()){mypiccblockflag[1]=mypiccblockflag[1]+qPow(2,4);}

    if (myt5557_read == NULL){
        QMessageBox::critical(NULL, "提示", "t5557_read函数装载失败!");
    }else{
        status = myt5557_read(myctrlword,mypiccserial,oldpicckey,mypiccblockflag,mypiccdata);
        if(status==0){
            myidr_beep(30);            
            QString blockdata="";
            for(int i=0;i<mypiccdata[1];i++){
                blockdata=blockdata+QString::asprintf("%02X", mypiccdata[2+i]);
            }
            if(ui->check_block0->isChecked()){ui->text_block0->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}
            if(ui->check_block1->isChecked()){ui->text_block1->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}
            if(ui->check_block2->isChecked()){ui->text_block2->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}
            if(ui->check_block3->isChecked()){ui->text_block3->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}
            if(ui->check_block4->isChecked()){ui->text_block4->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}
            if(ui->check_block5->isChecked()){ui->text_block5->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}
            if(ui->check_block6->isChecked()){ui->text_block6->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}
            if(ui->check_block7->isChecked()){ui->text_block7->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}
            if(ui->check_block8->isChecked()){ui->text_block8->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}
            if(ui->check_block9->isChecked()){ui->text_block9->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}
            if(ui->check_block10->isChecked()){ui->text_block10->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}
            if(ui->check_block11->isChecked()){ui->text_block11->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}

            QMessageBox::information(NULL, "提示", QString::asprintf("读卡成功,卡号:%02X%02X%02X%02X%02X%02X", mypiccserial[0],mypiccserial[1],mypiccserial[2],mypiccserial[3],mypiccserial[4],mypiccserial[5])+QString::asprintf(",卡无线转输分频比:%03d",mypiccdata[0] ));
        }
        else
        {
            disperrinf(status);
        }
    }
}

三、写数据到t5557指定块

void MainWindow::on_push_writcard_clicked()
{
    unsigned char status;
    unsigned char myctrlword=0;
    unsigned char mypiccserial[6];
    unsigned char oldpicckey[4];
    unsigned char mypiccdata[48];
    unsigned char mypiccblockflag[2];

    if(ui->check_authkey->isChecked()){
        QString authkey=ui->text_authkey->text().trimmed();
        if(authkey.length()==8 and checkinput(authkey)){
            for(int i=0;i<4;i++){
                bool ok;
                oldpicckey[i]=QString(authkey.mid(i*2,2)).toInt(&ok,16);
            }
            myctrlword=myctrlword+NEEDKEY;
        }else{
            QMessageBox::critical(NULL, "提示","请输入8位16进制认证密码!");
            return;
        }
    }

    if(ui->check_serial->isChecked()){
        QString picserial=ui->text_piccserial->text().trimmed();
        if(picserial.length()==12 and checkinput(picserial)){
            for(int i=0;i<6;i++){
                bool ok;
                mypiccserial[i]=QString(picserial.mid(i*2,2)).toInt(&ok,16);
            }
            myctrlword=myctrlword+NEEDSERIAL;
        }else{
            QMessageBox::critical(NULL, "提示","请输入12位16进制卡号!");
            return;
        }
    }

    QString writinf="";
    mypiccblockflag[0]=0;
    if(ui->check_block0->isChecked()){
        if(ui->text_block0->text().length()==8 and checkinput(ui->text_block0->text())){
            mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,0);
            writinf=writinf+ui->text_block0->text();
        }else{
            QMessageBox::critical(NULL, "提示","第0块请输入8位16进制数据!");
            return;
        }
    }

    if(ui->check_block1->isChecked()){
        if(ui->text_block1->text().length()==8 and checkinput(ui->text_block1->text())){
            mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,1);
            writinf=writinf+ui->text_block1->text();
        }else{
            QMessageBox::critical(NULL, "提示","第1块请输入8位16进制数据!");
            return;
        }
    }

    if(ui->check_block2->isChecked()){
        if(ui->text_block2->text().length()==8 and checkinput(ui->text_block2->text())){
            mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,2);
            writinf=writinf+ui->text_block2->text();
        }else{
            QMessageBox::critical(NULL, "提示","第2块请输入8位16进制数据!");
            return;
        }
    }

    if(ui->check_block3->isChecked()){
        if(ui->text_block3->text().length()==8 and checkinput(ui->text_block3->text())){
            mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,3);
            writinf=writinf+ui->text_block3->text();
        }else{
            QMessageBox::critical(NULL, "提示","第3块请输入8位16进制数据!");
            return;
        }
    }

    if(ui->check_block4->isChecked()){
        if(ui->text_block4->text().length()==8 and checkinput(ui->text_block4->text())){
            mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,4);
            writinf=writinf+ui->text_block4->text();
        }else{
            QMessageBox::critical(NULL, "提示","第4块请输入8位16进制数据!");
            return;
        }
    }

    if(ui->check_block5->isChecked()){
        if(ui->text_block5->text().length()==8 and checkinput(ui->text_block5->text())){
            mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,5);
            writinf=writinf+ui->text_block5->text();
        }else{
            QMessageBox::critical(NULL, "提示","第5块请输入8位16进制数据!");
            return;
        }
    }

    if(ui->check_block6->isChecked()){
        if(ui->text_block6->text().length()==8 and checkinput(ui->text_block6->text())){
            mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,6);
            writinf=writinf+ui->text_block6->text();
        }else{
            QMessageBox::critical(NULL, "提示","第6块请输入8位16进制数据!");
            return;
        }
    }

    if(ui->check_block7->isChecked()){
        if(ui->text_block7->text().length()==8 and checkinput(ui->text_block7->text())){
            mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,7);
            writinf=writinf+ui->text_block7->text();
        }else{
            QMessageBox::critical(NULL, "提示","第7块请输入8位16进制数据!");
            return;
        }
    }

    mypiccblockflag[1]=0;
    if(ui->check_block8->isChecked()){
        if(ui->text_block8->text().length()==8 and checkinput(ui->text_block8->text())){
            mypiccblockflag[1]=mypiccblockflag[1]+qPow(2,1);
            writinf=writinf+ui->text_block8->text();
        }else{
            QMessageBox::critical(NULL, "提示","第8块请输入8位16进制数据!");
            return;
        }
    }

    if(ui->check_block9->isChecked()){
        if(ui->text_block9->text().length()==8 and checkinput(ui->text_block9->text())){
            mypiccblockflag[1]=mypiccblockflag[1]+qPow(2,2);
            writinf=writinf+ui->text_block9->text();
        }else{
            QMessageBox::critical(NULL, "提示","第9块请输入8位16进制数据!");
            return;
        }
    }

    if(ui->check_block10->isChecked()){
        if(ui->text_block10->text().length()==8 and checkinput(ui->text_block10->text())){
            mypiccblockflag[1]=mypiccblockflag[1]+qPow(2,3);
            writinf=writinf+ui->text_block10->text();
        }else{
            QMessageBox::critical(NULL, "提示","第10块请输入8位16进制数据!");
            return;
        }
    }

    if(ui->check_block11->isChecked()){
        if(ui->text_block11->text().length()==8 and checkinput(ui->text_block11->text())){
            mypiccblockflag[1]=mypiccblockflag[1]+qPow(2,4);
            writinf=writinf+ui->text_block11->text();
        }else{
            QMessageBox::critical(NULL, "提示","第11块请输入8位16进制数据!");
            return;
        }
    }

    if(writinf.length()==0){
        QMessageBox::critical(NULL, "提示", "请选择要写入数据的块!");
        return;
    }else{
        for(int i=0;i<writinf.length()/2;i++){
            bool ok;
            mypiccdata[i]=QString(writinf.mid(i*2,2)).toInt(&ok,16);
        }
    }

    if (myt5557_write == NULL){
        QMessageBox::critical(NULL, "提示", "t5557_write函数装载失败!");
    }else{
        status = myt5557_write(myctrlword,mypiccserial,oldpicckey,mypiccblockflag,mypiccdata);
        if(status==0){
            myidr_beep(30);
            QMessageBox::information(NULL, "提示", QString::asprintf("写卡成功,卡号:%02X%02X%02X%02X%02X%02X", mypiccserial[0],mypiccserial[1],mypiccserial[2],mypiccserial[3],mypiccserial[4],mypiccserial[5]));
        }
        else
        {
            disperrinf(status);
        }
    }
}

四、将t5557卡制做成ID、HID卡

void MainWindow::on_pushButton_3_clicked()
{
    unsigned char status;
    unsigned char myctrlword=0;
    unsigned char mypiccserial[6];
    unsigned char oldpicckey[4];
    unsigned char newpicckey[4];

    if(ui->check_authkey->isChecked()){
        QString authkey=ui->text_authkey->text().trimmed();
        if(authkey.length()==8 and checkinput(authkey)){
                for(int i=0;i<4;i++){
                        bool ok;
                        oldpicckey[i]=QString(authkey.mid(i*2,2)).toInt(&ok,16);
                }
                myctrlword=myctrlword+NEEDKEY;
        }else{
                QMessageBox::critical(NULL, "提示","请输入8位16进制认证密码!");
                return;
        }
    }

    if(ui->check_serial->isChecked()){
        QString picserial=ui->text_piccserial->text().trimmed();
        if(picserial.length()==12 and checkinput(picserial)){
                for(int i=0;i<6;i++){
                        bool ok;
                        mypiccserial[i]=QString(picserial.mid(i*2,2)).toInt(&ok,16);
                }
                myctrlword=myctrlword+NEEDSERIAL;
        }else{
                QMessageBox::critical(NULL, "提示","请输入12位16进制卡号!");
                return;
        }
    }

    if(ui->check_authkey_2->isChecked()){
        QString authkey2=ui->text_authkey_2->text().trimmed();
        if(authkey2.length()==8 and checkinput(authkey2)){
                for(int i=0;i<4;i++){
                        bool ok;
                        newpicckey[i]=QString(authkey2.mid(i*2,2)).toInt(&ok,16);
                }
                myctrlword=myctrlword+KEYENABLE;
        }else{
                QMessageBox::critical(NULL, "提示","请输入8位16进制新密码!");
                return;
        }
    }

    myctrlword=myctrlword+RESETCARD;  //操作后重启卡片,否则在制卡后,需要拿开卡片重放才能成功读卡

    QString uidstr=ui->text_idserial->text().trimmed();
    if(ui->radio_em4100->isChecked()){
        if(uidstr.length()!=10 or checkinput(uidstr)==false){
                QMessageBox::critical(NULL, "提示", "请输入10位16进制原始ID卡号!");
                return;
        }else{
            unsigned char mynewuid[5];
            for(int i=0;i<5;i++){
                bool ok;
                mynewuid[i]=QString(uidstr.mid(i*2,2)).toInt(&ok,16);
            }
            if (myt5557_to4100 == NULL){
                QMessageBox::critical(NULL, "提示", "t5557_to4100函数装载失败!");
            }else{
                status = myt5557_to4100(myctrlword,mypiccserial,oldpicckey,newpicckey,mynewuid);
                if(status==0){
                    myidr_beep(30);
                    QMessageBox::information(NULL, "提示", "ID卡号写入成功,卡片变成ID卡!不能再用t5557的指令读写此卡,可重新设置配置块恢复t5557卡功能。");
                }
                else
                {
                    disperrinf(status);
                }
            }
        }
    }else{
            if(uidstr.length()!=14 or checkinput(uidstr)==false){
                QMessageBox::critical(NULL, "提示", "请输入14位16进制原始HID卡号!");
                return;
            }else{
                unsigned char mynewuid[7];
                for(int i=0;i<7;i++){
                    bool ok;
                    mynewuid[i]=QString(uidstr.mid(i*2,2)).toInt(&ok,16);
                }
                if (myt5557_tohid == NULL){
                    QMessageBox::critical(NULL, "提示", "t5557_tohid函数装载失败!");
                }else{
                    status = myt5557_tohid(myctrlword,mypiccserial,oldpicckey,newpicckey,mynewuid);
                    if(status==0){
                        myidr_beep(30);
                        QMessageBox::information(NULL, "提示", "HID卡号写入成功,卡片变成HID卡!不能再用t5557的指令读写此卡,可重新设置配置块恢复t5557卡功能。");
                    }
                    else
                    {
                        disperrinf(status);
                    }
                }
            }
    }
}

五、卡号转换

void MainWindow::on_push_changeid0_clicked()
{
    bool ok;
    unsigned long  cardno;
    QString cardstr;
    QString binstr;

    if(ui->radio_em4100->isChecked()){
        QString uidstr=ui->text_idserial->text().trimmed();
        if(uidstr.length()!=10 or checkinput(uidstr)==false){
            QMessageBox::critical(NULL, "提示", "请输入10位16进制原始ID卡号!");
            return;
        }else{
            switch (ui->comboBox->currentIndex()){
                case 0:
                    ui->text_newid0->setText(uidstr.mid(0,2));
                    ui->text_newid1->setText(uidstr.mid(2,2));
                    ui->text_newid2->setText(uidstr.mid(4,6));
                    break;
                case 1:
                    ui->text_newid0->setText(uidstr.mid(0,2));
                    ui->text_newid1->setText("");
                    cardno=uidstr.mid(2,2).toInt(&ok,16)*16777216 + uidstr.mid(4,2).toInt(&ok,16)*65536 + uidstr.mid(6,2).toInt(&ok,16)*256 + uidstr.mid(8,2).toInt(&ok,16) ;
                    cardstr=QString::number(cardno);
                    ui->text_newid2->setText(("0000000000"+QString::number(cardno)).right(10));
                    break;
                case 2:
                    ui->text_newid0->setText(uidstr.mid(0,2));
                    ui->text_newid1->setText("");
                    cardno=uidstr.mid(2,2).toInt(&ok,16)*256 + uidstr.mid(4,2).toInt(&ok,16) ;
                    cardstr=QString::asprintf("%05d",cardno);
                    cardno=uidstr.mid(6,2).toInt(&ok,16)*256 + uidstr.mid(8,2).toInt(&ok,16) ;
                    cardstr=cardstr+QString::asprintf("%05d",cardno);
                    ui->text_newid2->setText(cardstr);
                    break;
                default:
                    ui->text_newid0->setText(uidstr.mid(0,2));
                    ui->text_newid1->setText(uidstr.mid(2,2));
                    cardno= uidstr.mid(4,2).toInt(&ok,16) ;
                    cardstr=QString::asprintf("%03d",cardno);
                    cardno=uidstr.mid(6,2).toInt(&ok,16)*256 + uidstr.mid(8,2).toInt(&ok,16) ;
                    cardstr=cardstr+QString::asprintf("%05d",cardno);
                    ui->text_newid2->setText(cardstr);
                    break;
                }
            }
    }else{
            QString uidstr=ui->text_idserial->text().trimmed();
            if(uidstr.length()!=14 or checkinput(uidstr)==false){
                QMessageBox::critical(NULL, "提示", "请输入14位16进制原始ID卡号!");
                return;
            }else{
                ui->text_newid3->setText(QString::asprintf("%d",uidstr.mid(0,2).toInt(&ok,16)));
                switch (ui->comboBox->currentIndex()){
                    case 0:
                        ui->text_newid0->setText(uidstr.mid(2,4));
                        ui->text_newid1->setText(uidstr.mid(6,2));
                        ui->text_newid2->setText(uidstr.mid(8,6));
                        break;
                    case 1:
                        ui->text_newid0->setText(uidstr.mid(2,4));
                        ui->text_newid1->setText("");
                        cardno=uidstr.mid(6,2).toInt(&ok,16)*16777216 + uidstr.mid(8,2).toInt(&ok,16)*65536 + uidstr.mid(10,2).toInt(&ok,16)*256 + uidstr.mid(12,2).toInt(&ok,16) ;
                        ui->text_newid2->setText(QString::asprintf("%010d",cardno));
                        break;
                    case 2:
                        ui->text_newid0->setText(uidstr.mid(2,4));
                        ui->text_newid1->setText("");
                        cardno=uidstr.mid(6,2).toInt(&ok,16)*256 + uidstr.mid(8,2).toInt(&ok,16) ;
                        cardstr=QString::asprintf("%05d",cardno);
                        cardno=uidstr.mid(10,2).toInt(&ok,16)*256 + uidstr.mid(12,2).toInt(&ok,16) ;
                        cardstr=cardstr+QString::asprintf("%05d",cardno);
                        ui->text_newid2->setText(cardstr);
                        break;
                    case 3:
                        ui->text_newid0->setText(uidstr.mid(2,4));
                        ui->text_newid1->setText(uidstr.mid(6,2));
                        cardno= uidstr.mid(8,2).toInt(&ok,16) ;
                        cardstr=QString::asprintf("%03d",cardno);
                        cardno=uidstr.mid(10,2).toInt(&ok,16)*256 + uidstr.mid(12,2).toInt(&ok,16) ;
                        cardstr=cardstr+QString::asprintf("%05d",cardno);
                        ui->text_newid2->setText(cardstr);
                        break;

                    case 4:
                        ui->text_newid0->setText(uidstr.mid(2,4));
                        binstr=("00000000"+QString::number(uidstr.mid(6,2).toInt(&ok,16),2)).right(8)+("00000000"+QString::number(uidstr.mid(8,2).toInt(&ok,16),2)).right(8)+("00000000"+QString::number(uidstr.mid(10,2).toInt(&ok,16),2)).right(8)+("00000000"+QString::number(uidstr.mid(12,2).toInt(&ok,16),2)).right(8);
                        cardno=binstr.mid(0,13).toInt(&ok,2);
                        ui->text_newid1->setText(("0000"+QString::number(cardno,16)).right(4));

                        cardno=binstr.mid(13,19).toInt(&ok,2);
                        ui->text_newid2->setText(("000000"+QString::number(cardno,10)).right(6));

                        break;
                    default:
                        ui->text_newid0->setText(uidstr.mid(2,4));
                        ui->text_newid1->setText(uidstr.mid(6,4));
                        cardno=uidstr.mid(10,2).toInt(&ok,16)*256 + uidstr.mid(12,2).toInt(&ok,16) ;
                        cardstr=QString::asprintf("%05d",cardno);
                        ui->text_newid2->setText(cardstr);
                        break;
                }
            }
    }
}

六、修改t5557卡配置块

void MainWindow::on_push_editconfig_clicked()
{
    unsigned char status;
    unsigned char myctrlword=0;
    unsigned char mypiccserial[6];
    unsigned char oldpicckey[4];
    unsigned char newpicckey[4];
    unsigned char mypiccdata[4];

    if(ui->check_authkey->isChecked()){
        QString authkey=ui->text_authkey->text().trimmed();
        if(authkey.length()==8 and checkinput(authkey)){
            for(int i=0;i<4;i++){
                bool ok;
                oldpicckey[i]=QString(authkey.mid(i*2,2)).toInt(&ok,16);
            }
            myctrlword=myctrlword+NEEDKEY;
        }else{
            QMessageBox::critical(NULL, "提示","请输入8位16进制认证密码!");
            return;
        }
    }else{
        newpicckey[0]=0;
        newpicckey[1]=0;
        newpicckey[2]=0;
        newpicckey[3]=0;
    }

    if(ui->check_Enkey->isChecked()){
        QString newkey=ui->text_Enauthkey->text().trimmed();
        if(newkey.length()!=8 or checkinput(newkey)==false){
            QMessageBox::critical(NULL, "提示", "请输入8位16进制保护密码!");
            return;
        }else{
            for(int i=0;i<newkey.length()/2;i++){
                bool ok;
                newpicckey[i]=QString(newkey.mid(i*2,2)).toInt(&ok,16);
            }
            myctrlword = myctrlword + KEYENABLE;
        }
    }else{
        newpicckey[0]=0;
        newpicckey[1]=0;
        newpicckey[2]=0;
        newpicckey[3]=0;
    }

    QString configstr=ui->text_config->text().trimmed();
    if(configstr.length()!=8 or checkinput(configstr)==false){
        QMessageBox::critical(NULL, "提示", "请输入8位16进制配置值!");
        return;
    }else{
        for(int i=0;i<configstr.length()/2;i++){
            bool ok;
            mypiccdata[i]=QString(configstr.mid(i*2,2)).toInt(&ok,16);
        }
    }

    if (myt5557_init == NULL){
        QMessageBox::critical(NULL, "提示", "t5557_init函数装载失败!");
    }else{
        status = myt5557_init(myctrlword,mypiccserial,oldpicckey,mypiccdata,newpicckey);
        if(status==0){
            myidr_beep(30);
            QMessageBox::information(NULL, "提示", QString::asprintf("修改卡配置值成功,卡号:%02X%02X%02X%02X%02X%02X", mypiccserial[0],mypiccserial[1],mypiccserial[2],mypiccserial[3],mypiccserial[4],mypiccserial[5]));
        }
        else
        {
            disperrinf(status);
        }
    }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/494888.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Qt5.9学习笔记-事件(三) 多线程和事件处理

⭐️我叫忆_恒心&#xff0c;一名喜欢书写博客的在读研究生&#x1f468;‍&#x1f393;。 如果觉得本文能帮到您&#xff0c;麻烦点个赞&#x1f44d;呗&#xff01; 近期会不断在专栏里进行更新讲解博客~~~ 有什么问题的小伙伴 欢迎留言提问欧&#xff0c;喜欢的小伙伴给个三…

OpenCV中的图像处理3.4-3.6(四)平滑化、形态学、图像梯度

目录 3.4 平滑化图像目标二维卷积 ( 图像滤波 )图像模糊(图像平滑)其他资源 3.5 形态学转换目标理论结构化元素 3.6 图像梯度目标理论代码一个重要的问题! 翻译及二次校对&#xff1a;cvtutorials.com 编辑者&#xff1a;廿瓶鲸&#xff08;和鲸社区Siby团队成员&#xff09; …

用 Bitmap 实现亿级海量数据统计

在移动应用的业务场景中&#xff0c;我们需要保存这样的信息&#xff1a;一个 key 关联了一个数据集合。 常见的场景如下&#xff1a; 给一个 userId &#xff0c;判断用户登陆状态&#xff1b; 显示用户某个月的签到次数和首次签到时间&#xff1b; 两亿用户最近 7 天的签到…

【C++:模块3-------数组】

C&#xff1a;模块3-------数组 数组概念&#xff1a;数组特点&#xff1a;数组访问方法&#xff1a; 一维数组&#xff1a;1.1三种定义形式&#xff1a;&#xff08;和C语言中一样&#xff09;1.2一维数组数组名的作用&#xff1a;&#xff08;1&#xff09; 统计数组在内存中…

日常的性能测试工作

日常的性能测试工作 (1)在日常的测试工作时如何进行性能测试 日常的性能测试主要是从业务功能点中抽取具有并发特点的&#xff0c;高风险的、大数据量处理的业务&#xff0c;整理成测试用例&#xff0c;制定相应的指标&#xff0c;然后用工具或者手工进行性能测试并分析&#x…

MySQL HeatWave 被添加了机器学习,甲骨文认真了

开头还是介绍一下群&#xff0c;如果感兴趣polardb ,mongodb ,mysql ,postgresql ,redis 等有问题&#xff0c;有需求都可以加群群内有各大数据库行业大咖&#xff0c;CTO&#xff0c;可以解决你的问题。加群请联系 liuaustin3 &#xff0c;在新加的朋友会分到2群&#xff08;共…

基于javaweb的学生就业管理系统

一、简介 学生基业管理系统有三个角色&#xff1a;管理员、企业、学生 对学生信息管理、企业信息管理、求职信息管理 后端架构&#xff1a;spring springmvc mybatis 前端架构&#xff1a;jsp layui 系统环境&#xff1a;jdk1.8 | maven | mysql 二、主要功能 1. 登录…

jvm之垃圾回收相关概念解读

目录 System.gc()的理解 内存溢出与内存泄露 内存溢出&#xff08;OOM&#xff09; 内存泄漏&#xff08;Memory Leak&#xff09; Stop The World 垃圾回收的并行与并发 程序中的并发&#xff08;Concurrent&#xff09; 程序中的并发&#xff08;Parallel&#xff09…

揭秘镭速传输点对点传输技术,NAT+Raysync强强组合

点对点传输是一种文件即时传输方式用于实现数据的快速联动&#xff0c;为所有客户端提供资源&#xff0c;包括带宽、存储空间、计算能力。点对点传输技术有很多应用&#xff0c;包括共享各种格式音频、视频、数据等。 在5G重新定义带宽&#xff0c;信息技术不断发展的今天&…

Python:概念解析:基础语法

Python基础语法 1. 列表&#xff0c;元组&#xff0c;字典1.1 列表1.2. tuple元组1.3 字典dict 2. 数据类型推断2.1 在Python中有一个函数 isinstance(data,type) , 可以用来判断某个数据是什么类型。 3. Python 基本数据类型3.1 整型 int 本章节介绍Python的一些基础语法 1. 列…

《可穿戴式血压测量设备与高血压管理的新方法:数字时代》阅读笔记

目录 一、论文摘要 二、论文十问 Q1&#xff1a;论文试图解决什么问题&#xff1f; Q2&#xff1a;这是否是一个新的问题&#xff1f; Q3&#xff1a;这篇文章要验证一个什么科学假设&#xff1f; Q4&#xff1a;有哪些相关研究&#xff1f;如何归类&#xff1f;谁是这一课…

PySide6/PyQT多线程之 线程安全:互斥锁条件变量的最佳实践

前言 在PySide6/PyQT中使用多线程时&#xff0c;线程锁和线程安全是非常重要的概念。本文将介绍线程锁和线程安全的基本概念&#xff0c;以及如何在PySide6/PyQT中使用它们。 使用PySide6/PyQT开发GUI应用程序&#xff0c;在多个线程同时访问同一个共享对象时候&#xff0c;如果…

单词词义、词性、例句查询python代码

单词发音、词义、词性、例句查询、输出结果更简洁&#xff0c;一次可查多个单词 运行该代码&#xff0c;命令窗口输入单词&#xff0c;单词用“/”分开&#xff0c;例如&#xff1a;noisy/problem/community/neighbor 可以更多。先安装两个python包requests、 beautifulsoup4&…

Eureka详解

Eureka概述和架构 Eureka Spring Cloud Eureka 是Netflix 开发的注册发现组件&#xff0c;本身是一个基于 REST 的服务。提供注册与发现&#xff0c;同时还提供了负载均衡、故障转移等能力 Eureka3个角色 服务中心&#xff0c;服务提供者&#xff0c;服务消费者 Eureka Se…

Win11的两个实用技巧系列之蓝屏死循环解决办法、调高进程的优先级方法

Win11蓝屏死循环怎么办?Win11蓝屏死循环解决办法 有用户安装Win11系统的时候&#xff0c;重新启动电脑的时候&#xff0c;会一直进入蓝屏的错误循环中&#xff0c;本文就为大家带来详细的解决方法&#xff0c;需要的朋友一起看看吧 Win11蓝屏死循环解决办法分享。有用户安装W…

Ubuntu18.04系统及相关软件安装恢复过程

Ubuntu18.04系统及相关软件安装恢复过程 一、常用软件安装1. [系统安装](https://blog.csdn.net/qq_43309940/article/details/116656810)2. [显卡驱动安装](https://blog.csdn.net/qq_43309940/article/details/126898929)3. [ROS Melodic安装](https://ismango.blog.csdn.net…

[Python]爬虫基础——urllib库

urllib目录 一、简介二、发送请求1、urlopen()函数2、Request()函数 三、异常处理四、解析URL五、分析Robots协议 一、简介 urllib库是Python内置的标准库。包含以下四个模块&#xff1a; 1、request&#xff1a;模拟发送HTTP请求&#xff1b; 2、error&#xff1a;处理HTTP请…

实验六 UML建模工具应用

一、实验目的 1.掌握面向对象开发思想及实现机制 2.理解并掌握UML常用图&#xff08;重点&#xff1a;类、对象图、用例图&#xff09; 3.掌握并常见UML建模工具&#xff0c;并绘制UML各种图 二、实验准备与要求 1.StarUML(简称SU)&#xff0c;是一种创建UML类图&#xff0c…

洛谷P8597 [蓝桥杯 2013 省 B] 翻硬币C语言/C++

[蓝桥杯 2013 省 B] 翻硬币 题目背景 小明正在玩一个“翻硬币”的游戏。 题目描述 桌上放着排成一排的若干硬币。我们用 * 表示正面&#xff0c;用 o 表示反面&#xff08;是小写字母&#xff0c;不是零&#xff09;&#xff0c;比如可能情形是 **oo***oooo&#xff0c;如果…

ideaSSM医院挂号管理系统VS开发mysql数据库web结构java编程计算机网页源码maven项目

一、源码特点 SSM医院挂号管理系统是一套完善的完整医院类型系统&#xff0c;结合SSM框架和bootstrap完成本系统SpringMVC spring mybatis &#xff0c;对理解JSP java编程开发语言有帮助系统采用SSM框架&#xff08;MVC模式 开发&#xff09;&#xff0c;系统具有完整的源代…