Qt_C++读写FM1208 CPU卡源码、支持windows、Linux系统

news2024/11/15 16:55:47

本示例使用的发卡器: Android Linux RFID读写器NFC发卡器WEB可编程NDEF文本/智能海报/-淘宝网 (taobao.com)

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

//电话、微信:13822155058
//QQ:954486673

//本示例可在windows、linux系统内编译、运行
//判断windows、linux系统,声明动态库函数----------------------------------------------------------------------------------------------------------------------------------------------
//让读写器发出声音
typedef  unsigned char (*pcdbeep)(unsigned long xms);
#ifdef Q_OS_WIN
    pcdbeep mypcdbeep = (pcdbeep)QLibrary("OUR_MIFARE.dll").resolve("pcdbeep");
#else
    pcdbeep mypcdbeep = (pcdbeep)QLibrary("./libOURMIFARE.so").resolve("pcdbeep");
#endif

//返回本读写器独一无二的设备编号
typedef  unsigned char (*pcdgetdevicenumber)(unsigned char *devicenumber);
#ifdef Q_OS_WIN
    pcdgetdevicenumber mypcdgetdevicenumber = (pcdgetdevicenumber)QLibrary("OUR_MIFARE.dll").resolve("pcdgetdevicenumber");
#else
    pcdgetdevicenumber mypcdgetdevicenumber = (pcdgetdevicenumber)QLibrary("./libOURMIFARE.so").resolve("pcdgetdevicenumber");
#endif

//CPU卡寻卡及将卡复位到14443A-4的指令状态
typedef  unsigned char (*cpurequest)(unsigned char *serial,unsigned char *param,unsigned char *cosver,unsigned char *code);
#ifdef Q_OS_WIN
    cpurequest mycpurequest = (cpurequest)QLibrary("OUR_MIFARE.dll").resolve("cpurequest");
#else
    cpurequest mycpurequest = (cpurequest)QLibrary("./libOURMIFARE.so").resolve("cpurequest");
#endif

//cpu卡初始化函数,(ctrlword是否需要先清空卡,不需要清空的话,可以需输入卡密码,卡密码长度)ctrlword_0是否先清空卡,分配空间(字节数)
typedef  unsigned char (*cpursinit)(unsigned char ctrlword,unsigned char *key,unsigned char *keylen,int customsize);
#ifdef Q_OS_WIN
    cpursinit mycpursinit = (cpursinit)QLibrary("OUR_MIFARE.dll").resolve("cpursinit");
#else
    cpursinit mycpursinit = (cpursinit)QLibrary("./libOURMIFARE.so").resolve("cpursinit");
#endif

//增加易写文件(文件序号0~5,文件只读密码:长度,文件读写密码,长度,分配空间)
typedef  unsigned char (*cpursfileadd_s)(unsigned char fileno,unsigned char *readonlykey,unsigned char *readonlykeylen,unsigned char *writekey,unsigned char *writekeylen,int customsize);
#ifdef Q_OS_WIN
    cpursfileadd_s mycpursfileadd_s = (cpursfileadd_s)QLibrary("OUR_MIFARE.dll").resolve("cpursfileadd_s");
#else
    cpursfileadd_s mycpursfileadd_s = (cpursfileadd_s)QLibrary("./libOURMIFARE.so").resolve("cpursfileadd_s");
#endif

//增加标准文件(文件序号0~5,文件只读密码:长度,文件读写密码,长度,分配空间)
typedef  unsigned char (*cpursfileadd)(unsigned char fileno,unsigned char *readonlykey,unsigned char *readonlykeylen,unsigned char *writekey,unsigned char *writekeylen,int customsize);
#ifdef Q_OS_WIN
    cpursfileadd mycpursfileadd = (cpursfileadd)QLibrary("OUR_MIFARE.dll").resolve("cpursfileadd");
#else
    cpursfileadd mycpursfileadd = (cpursfileadd)QLibrary("./libOURMIFARE.so").resolve("cpursfileadd");
#endif

//修改文件密码,修改后,请妥慎记住,否则该文件将无法再用
typedef  unsigned char (*cpursfilekeychg)(unsigned char fileno,unsigned char ctrword,unsigned char *oldkey,unsigned char *oldkeylen,unsigned char *newkey,unsigned char *newkeylen);
#ifdef Q_OS_WIN
    cpursfilekeychg mycpursfilekeychg = (cpursfilekeychg)QLibrary("OUR_MIFARE.dll").resolve("cpursfilekeychg");
#else
    cpursfilekeychg mycpursfilekeychg = (cpursfilekeychg)QLibrary("./libOURMIFARE.so").resolve("cpursfilekeychg");
#endif

//读文件数据(文件序号,读写密码,密码长度,读取起始位置,读取长度,读出内容)
typedef  unsigned char (*cpursfiledataread)(unsigned char fileno,unsigned char ctrword,unsigned char *oldkey,unsigned char *oldkeylen,int startaddr,unsigned char *databuf,int datalen);
#ifdef Q_OS_WIN
    cpursfiledataread mycpursfiledataread = (cpursfiledataread)QLibrary("OUR_MIFARE.dll").resolve("cpursfiledataread");
#else
    cpursfiledataread mycpursfiledataread = (cpursfiledataread)QLibrary("./libOURMIFARE.so").resolve("cpursfiledataread");
#endif

//写普通文件数据(文件序号,写密码,密码长度,写起始位置,写长度,写入内容)
typedef  unsigned char (*cpursfiledatawrite)(unsigned char fileno,unsigned char ctrword,unsigned char *oldkey,unsigned char *oldkeylen,int startaddr,unsigned char *databuf,int datalen);
#ifdef Q_OS_WIN
    cpursfiledatawrite mycpursfiledatawrite = (cpursfiledatawrite)QLibrary("OUR_MIFARE.dll").resolve("cpursfiledatawrite");
#else
    cpursfiledatawrite mycpursfiledatawrite = (cpursfiledatawrite)QLibrary("./libOURMIFARE.so").resolve("cpursfiledatawrite");
#endif

//写易写文件数据(文件序号,写密码,密码长度,写起始位置,写长度,写入内容)
typedef  unsigned char (*cpursfiledatawrite_s)(unsigned char fileno,unsigned char ctrword,unsigned char *oldkey,unsigned char *oldkeylen,int startaddr,unsigned char *databuf,int datalen);
#ifdef Q_OS_WIN
    cpursfiledatawrite_s mycpursfiledatawrite_s = (cpursfiledatawrite_s)QLibrary("OUR_MIFARE.dll").resolve("cpursfiledatawrite_s");
#else
    cpursfiledatawrite_s mycpursfiledatawrite_s = (cpursfiledatawrite_s)QLibrary("./libOURMIFARE.so").resolve("cpursfiledatawrite_s");
#endif

//强制清空卡,用cpursinit函数成功初始化过后,如果卡密码丢去了,可以尝试用以下的强制清空卡函数清空卡至出厂状态
typedef  unsigned char (*cpurscardclr)();
#ifdef Q_OS_WIN
    cpurscardclr mycpurscardclr = (cpurscardclr)QLibrary("OUR_MIFARE.dll").resolve("cpurscardclr");
#else
    cpurscardclr mycpurscardclr = (cpurscardclr)QLibrary("./libOURMIFARE.so").resolve("cpurscardclr");
#endif

//修改卡密码,卡密码和文件没有任何关系,卡密码只是用来清空卡,读和写文件是无效的。
typedef  unsigned char (*cpurscardkeychg)(unsigned char *oldkey,unsigned char *oldkeylen,unsigned char *newkey,unsigned char *newkeylen);
#ifdef Q_OS_WIN
    cpurscardkeychg mycpurscardkeychg = (cpurscardkeychg)QLibrary("OUR_MIFARE.dll").resolve("cpurscardkeychg");
#else
    cpurscardkeychg mycpurscardkeychg = (cpurscardkeychg)QLibrary("./libOURMIFARE.so").resolve("cpurscardkeychg");
#endif


const unsigned char NEWKEYR = 0x00;   //'更改只读密码
const unsigned char NEWKEYWR = 0x01;  //'更改读写密码
const unsigned char OLDKEYR = 0x00;   //'用只读密码认证
const unsigned char OLDKEYWR = 0x02;  //'用读写密码认证


//检测输入数据是否为16进制数------------------------------------------------------------------------------------------------------------------------------------------------------------
static bool checkinput(QString inputstr){
    QString inputyes="0123456789abcdefABCDEF";
    for(int i=0;i<inputstr.length();i++){
        if(inputyes.contains(inputstr.mid(i,1),Qt::CaseSensitive)){
        }else{return false;}
    }
    return true;
}

//检测输入数据是否为16进制数,将正确的16进制字符存入数组,并返回长度------------------------------------------------------------------------------------------------------------------------------------------------------------
static int checkhexdata(QString inputstr,unsigned char *databuf){
    QChar ch;
    QString writinf = inputstr.trimmed();
    QString writinf1 = "";
    int m = 0;
    int n = 0;
    char s;

    if(writinf.length()<1){
        return -1;
    }

    ch = writinf.at(0);
    s = writinf.at(0).toLatin1();
    for(int i=0; i<writinf.length() ; i++)
    {
        ch = writinf.at(i);
        s = writinf.at(i).toLatin1();
        if((('0' <= s) && (s <= '9')) || (('A' <= s) && (s <= 'F')) || (('a' <= s) && (s <= 'f')))
        {
            writinf1 += ch;
            n++;
            if(n==2){
                bool ok;
                databuf[m++] = writinf1.toInt(&ok,16);
                writinf1 = "";
                n = 0;
            }
        }
        else if(s == ' '){

        }
    }
    return m;
}

//检测动态库文件是否在运行目录内----------------------------------------------------------------------------------------------------------------------------------------------------------
static bool checkdllos(){
#ifdef Q_OS_WIN
    QLibrary mylib("OUR_MIFARE.dll");
    if (!mylib.load()){                //判断windows系统下,OUR_MIFARE.dll是否在运行目录内
        QMessageBox::information(NULL, "提示", "请将OUR_MIFARE.dll文件拷贝到生成exe文件相同目录下!");
        return false;
    }else{
        return true;
    }
#else
    QLibrary mylib("./libOURMIFARE.so");
    if (!mylib.load()){                //判断linux系统下,libOURMIFARE.so是否正运行目录内
        QMessageBox::information(NULL, "提示", "请将libOURMIFARE.so文件拷贝到生成的运行文件相同目录下!");
        return false;
    }else{return true;}
#endif
}

//显示返回的错误代码信息-----------------------------------------------------------------------------------------------------------------------------------------------------------------
static void disperrinf(unsigned char result){
    switch (result) {
    case 8:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",未寻到卡,请重新拿开卡后再放到感应区!");
        break;
    case 50:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",RATS错误,厂家调试代码,用户不需理会!");
        break;
    case 51:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",PPS错误,厂家调试代码,用户不需理会!");
        break;
    case 52:
        QMessageBox::information(NULL, "提示", QString::asprintf("代码:%d", result)+",已进入了14443-4协议状态,可进行CPU卡功能所有操作了!");
        break;
    case 53:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",CPU卡功能通讯错误!");
        break;
    case 54:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",数据不足,需要接着发送未完成的数据至卡上!");
        break;
    case 55:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",发送ACK指令给卡,让卡接着发送数据回来!");
        break;
    case 56:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",清空根目录失败!");
        break;
    case 57:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",卡片不支持此功能!");
        break;
    case 58:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",卡片初始化失败!");
        break;
    case 59:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",分配的空间不足!");
        break;
    case 60:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",本次操作的实体已存在!");
        break;
    case 61:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",无足够空间!");
        break;
    case 62:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",文件不存在!");
        break;
    case 63:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",权限不足,有可能是用只读密码认证,导致无法更改读写密码或无法写文件!");
        break;
    case 64:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",密码不存在,或密钥文件未创建!");
        break;
    case 65:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",传送长度错误!");
        break;
    case 66:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",Le错误,即接收的数据长度指定过大!");
        break;
    case 67:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",功能不支持或卡中无MF 或卡片已锁定!");
        break;
    case 68:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",密码认证错识次数过多,该密码已被锁死!");
        break;
    case 70:
    case 71:
    case 72:
    case 73:
    case 74:
    case 75:
    case 76:
    case 77:
    case 78:
    case 79:
    case 80:
    case 81:
    case 82:
    case 83:
    case 84:
    case 85:
        QMessageBox::critical(NULL, "提示", QString::asprintf("密码错误,剩余次数为:%d", result-70)+",如果为0,该密码将锁死,无法再认证!");
        break;
    case 86:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",更改后的密码长度必须和创建时的长度一致!");
        break;
    case 87:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",应用目录不存在!");
        break;
    case 88:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",应用文件不存在!");
        break;
    case 89:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",文件号不能超过5!");
        break;
    case 90:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",读取文件时返回的长度不足,数据可能不正确!");
        break;
    case 91:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",一次读文件的长度不能超过255!");
        break;
    case 92:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",一次写文件的长度不能超过247!");
        break;
    default:
        QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",未知的错误信息!");
        break;
    }
}

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QPalette pa;
    pa.setColor(QPalette::WindowText,QColor(255, 0, 0));
    ui->label_7->setPalette(pa);
    ui->label_8->setPalette(pa);
    ui->label_9->setPalette(pa);
    ui->label_19->setPalette(pa);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pb_beep_clicked()
{
    if(!checkdllos()){return;}      //判断运行目录内动态库文件是否存在

    unsigned char status;
    if (mypcdbeep != NULL){         //是否成功连接上 pcdbeep()函数
        status = mypcdbeep(30);
        if(status==0){
        }
        else
        {
            disperrinf(status);
        }
    } else{
        QMessageBox::critical(NULL, "提示", "函数‘pcdbeep’未正确载入,请查询DLL文件版本是否正确!");
    }
}


void MainWindow::on_pb_getdevnum_clicked()
{
    if(!checkdllos()){return;}        //判断运行目录内动态库文件是否存在

    unsigned char devicenumber[4];    //设备编号缓冲
    unsigned char status;             //函数返回状态
    if (mypcdgetdevicenumber != NULL){         //是否成功连接上 pcdgetdevicenumber()函数
        status = mypcdgetdevicenumber(devicenumber);
        if(status==0){
            mypcdbeep(30);
            QMessageBox::information(NULL, "提示", QString::asprintf("设备编号:%03d-%03d-%03d-%03d", devicenumber[0],devicenumber[1],devicenumber[2],devicenumber[3]));
        }
        else
        {
            disperrinf(status);
        }
    }else{
        QMessageBox::critical(NULL, "提示", "函数‘pcdgetdevicenumber’未正确载入,请查询DLL文件版本是否正确!");
    }
}


void MainWindow::on_pb_request_clicked()
{
    if(!checkdllos()){return;}        //判断运行目录内动态库文件是否存在

    unsigned char mypiccserial[4];    //卡序列号
    unsigned char myparam[4];         //参数
    unsigned char myver[1];           //版本
    unsigned char mycode[1];          //厂商代码(复旦为90)
    unsigned char status;             //函数返回状态

    if (mycpurequest != NULL){        //是否成功连接上 cpurequest()函数
        status = mycpurequest(mypiccserial,myparam,myver,mycode);
        if(status==0  || status==52){
            mypcdbeep(30);
            QString uidstr=QString::asprintf("%02X%02X%02X%02X", mypiccserial[0],mypiccserial[1],mypiccserial[2],mypiccserial[3]);
            QString parstr=QString::asprintf("%02X%02X%02X%02X", myparam[0],myparam[1],myparam[2],myparam[3]);
            QString verstr=QString::asprintf("%02X", myver[0]);
            QString codestr=QString::asprintf("%02X", mycode[0]);

            ui->lineEdit_uid->setText(uidstr);
            QMessageBox::information(NULL, "提示", "卡号:"+uidstr+",参数:"+parstr+",版本号:"+verstr+",厂商代码:"+codestr+" 的CPU卡已激活进入14443-4协议模式,可以继续以下的功能操作!");
        }
        else
        {
            disperrinf(status);
        }
    }else{
        QMessageBox::critical(NULL, "提示", "函数‘cpurequest’未正确载入,请查询DLL文件版本是否正确!");
    }
}


void MainWindow::on_pb_init_clicked()
{
    if(!checkdllos()){return;}        //判断运行目录内动态库文件是否存在

    unsigned char status;             //函数返回状态
    unsigned char ctrlword;           //是否先清空卡
    unsigned char mylen[1];           //密钥长度
    unsigned char keybuf[20];         //密钥
    int keylen;
    int spacesize;                    //空间大小

    if(ui->checkBox_clear->isChecked()){
        ctrlword=1;
    }else{ctrlword=0;}

    QString writinf = ui->lineEdit_cardkey->text().trimmed();
    keylen=checkhexdata(writinf,keybuf);
    if(keylen<0){
        QMessageBox::critical(NULL, "提示", "请输入正确的16进制卡密码!");
        ui->lineEdit_cardkey->setFocus();
        return;
    }

    mylen[0]=keylen;
    spacesize=ui->spinBox_maxsize->value();

    if (mycpursinit != NULL){        //是否成功连接上 cpursinit()函数
        status = mycpursinit(ctrlword,keybuf,mylen,spacesize);
        if(status==0 ){
            mypcdbeep(30);
            QMessageBox::information(NULL, "提示", "CPU卡初始化成功!");
        }
        else
        {
            disperrinf(status);
        }
    }else{
        QMessageBox::critical(NULL, "提示", "函数‘cpursinit’未正确载入,请查询DLL文件版本是否正确!");
    }
}

void MainWindow::on_pb_addeasyfile_clicked()
{
    if(!checkdllos()){return;}        //判断运行目录内动态库文件是否存在

    unsigned char status;             //函数返回状态
    unsigned char fileno;             //文件号
    unsigned char readkeylen[1];      //只读密钥长度
    unsigned char readkeybuf[20];     //只读密钥
    unsigned char rwkeylen[1];        //读写密钥长度
    unsigned char rwkeybuf[20];       //读写密钥
    int keylen;
    int spacesize;                    //空间大小
    QString keystr;

    fileno=ui->comboBox_addfile->currentIndex(); //新增加的文件号

    keystr = ui->lineEdit_readkey->text().trimmed();
    keylen=checkhexdata(keystr,readkeybuf);
    if(keylen<0){
        QMessageBox::critical(NULL, "提示", "请输入正确的16进制文件只读密码!");
        ui->lineEdit_readkey->setFocus();
        return;
    }
    readkeylen[0]=keylen;

    keystr = ui->lineEdit_rwkey->text().trimmed();
    keylen=checkhexdata(keystr,rwkeybuf);
    if(keylen<0){
        QMessageBox::critical(NULL, "提示", "请输入正确的16进制文件读写密码!");
        ui->lineEdit_rwkey->setFocus();
        return;
    }
    rwkeylen[0]=keylen;

    spacesize=ui->spinBox_2->value();

    if (mycpursfileadd_s != NULL){        //是否成功连接上 cpursfileadd_s()函数
        status = mycpursfileadd_s(fileno,readkeybuf,readkeylen,rwkeybuf,rwkeylen,spacesize);
        if(status==0 ){
            mypcdbeep(30);
            QMessageBox::information(NULL, "提示", "CPU卡创建易写文件成功,需要使用易写函数写入文件数据!");
        }
        else
        {
            disperrinf(status);
        }
    }else{
        QMessageBox::critical(NULL, "提示", "函数‘cpursfileadd_s’未正确载入,请查询DLL文件版本是否正确!");
    }
}



void MainWindow::on_pb_addfile_clicked()
{
    if(!checkdllos()){return;}        //判断运行目录内动态库文件是否存在

    unsigned char status;             //函数返回状态
    unsigned char fileno;             //文件号
    unsigned char readkeylen[1];      //只读密钥长度
    unsigned char readkeybuf[20];     //只读密钥
    unsigned char rwkeylen[1];        //读写密钥长度
    unsigned char rwkeybuf[20];       //读写密钥
    int keylen;
    int spacesize;                    //空间大小
    QString keystr;

    fileno=ui->comboBox_addfile->currentIndex();  //新增加的文件号

    keystr = ui->lineEdit_readkey->text().trimmed();
    keylen=checkhexdata(keystr,readkeybuf);
    if(keylen<0){
        QMessageBox::critical(NULL, "提示", "请输入正确的16进制文件只读密码!");
        ui->lineEdit_readkey->setFocus();
        return;
    }
    readkeylen[0]=keylen;

    keystr = ui->lineEdit_rwkey->text().trimmed();
    keylen=checkhexdata(keystr,rwkeybuf);
    if(keylen<0){
        QMessageBox::critical(NULL, "提示", "请输入正确的16进制文件读写密码!");
        ui->lineEdit_rwkey->setFocus();
        return;
    }
    rwkeylen[0]=keylen;

    spacesize=ui->spinBox_2->value();

    if (mycpursfileadd != NULL){        //是否成功连接上 cpursfileadd()函数
        status = mycpursfileadd(fileno,readkeybuf,readkeylen,rwkeybuf,rwkeylen,spacesize);
        if(status==0 ){
            mypcdbeep(30);
            QMessageBox::information(NULL, "提示", "CPU卡创建标准文件成功,需使用写标准文件函数写入数据!");
        }
        else
        {
            disperrinf(status);
        }
    }else{
        QMessageBox::critical(NULL, "提示", "函数‘cpursfileadd’未正确载入,请查询DLL文件版本是否正确!");
    }
}


void MainWindow::on_pb_changkey_clicked()
{
    if(!checkdllos()){return;}        //判断运行目录内动态库文件是否存在

    unsigned char status;             //函数返回状态
    unsigned char fileno;             //文件号
    unsigned char ctrlword;           //控制字
    unsigned char oldkeylen[1];       //旧密钥长度
    unsigned char oldkeybuf[20];      //旧密钥
    unsigned char newkeylen[1];       //新密钥长度
    unsigned char newkeybuf[20];      //新密钥
    int keylen;
    QString keystr;

    fileno=ui->comboBox_changekeyfile->currentIndex();  //要更改密钥的文件号

    if(ui->comboBox_changekey->currentIndex()==0){
        ctrlword=NEWKEYR;       //更改只读密码
    }else{ctrlword=NEWKEYWR;}   //更改读写密码

    if(ui->comboBox_authkey->currentIndex()==0){
        ctrlword=ctrlword+OLDKEYR;      //用只读密码来认证
    }else{ctrlword=ctrlword+OLDKEYWR;}  //用读写密码来认证

    keystr = ui->lineEdit_authkey->text().trimmed();
    keylen=checkhexdata(keystr,oldkeybuf);
    if(keylen<0){
        QMessageBox::critical(NULL, "提示", "请输入正确的16进制文件认证密码!");
        ui->lineEdit_authkey->setFocus();
        return;
    }
    oldkeylen[0]=keylen;

    keystr = ui->lineEdit_newkey->text().trimmed();
    keylen=checkhexdata(keystr,newkeybuf);
    if(keylen<0){
        QMessageBox::critical(NULL, "提示", "请输入正确的16进制文件新密码!");
        ui->lineEdit_newkey->setFocus();
        return;
    }
    newkeylen[0]=keylen;

    if (mycpursfilekeychg != NULL){        //是否成功连接上 cpursfilekeychg()函数
        status = mycpursfilekeychg(fileno,ctrlword,oldkeybuf,oldkeylen,newkeybuf,newkeylen);
        if(status==0 ){
            mypcdbeep(30);
            QMessageBox::information(NULL, "提示", "修改文件密码成功");
        }
        else
        {
            disperrinf(status);
        }
    }else{
        QMessageBox::critical(NULL, "提示", "函数‘cpursfilekeychg’未正确载入,请查询DLL文件版本是否正确!");
    }
}


void MainWindow::on_pb_read_clicked()
{
    if(!checkdllos()){return;}        //判断运行目录内动态库文件是否存在

    unsigned char status;             //函数返回状态
    unsigned char fileno;             //文件号
    unsigned char ctrlword;           //控制字
    unsigned char oldkeylen[1];       //旧密钥长度
    unsigned char oldkeybuf[20];      //旧密钥
    int staradd;                      //读写起始地址
    int datalen;                      //读写长度
    unsigned char rwbuf[8000];        //读写数据缓冲
    int keylen;
    QString keystr;

    fileno=ui->comboBox_rwfile->currentIndex();  //要读写的文件号
    staradd=ui->spinBox_rwbegin->value();        //读写起始地址
    datalen=ui->spinBox_rwlen->value();          //读写数据长度
    if(datalen<1 || datalen>255){
        QMessageBox::critical(NULL, "提示", "每次读卡最多255字节,请输入正确的读卡长度!");
        ui->spinBox_rwlen->setFocus();
        return;
    }

    if(ui->comboBox_authrwkey->currentIndex()==0){
        ctrlword=OLDKEYR;      //用只读密码来认证
    }else{ctrlword=OLDKEYWR;}  //用读写密码来认证

    keystr = ui->lineEdit_authkey2->text().trimmed();
    keylen=checkhexdata(keystr,oldkeybuf);
    if(keylen<0){
        QMessageBox::critical(NULL, "提示", "请输入正确的16进制文件认证密码!");
        ui->lineEdit_authkey2->setFocus();
        return;
    }
    oldkeylen[0]=keylen;

    if (mycpursfiledataread != NULL){        //是否成功连接上 cpursfiledataread()函数
        status = mycpursfiledataread(fileno,ctrlword,oldkeybuf,oldkeylen,staradd,rwbuf,datalen);
        if(status==0 ){
            mypcdbeep(30);
            QString datastr="";
            for(int i=0;i<datalen;i++){
                datastr=datastr+QString::asprintf("%02X ", rwbuf[i]);
            }
            ui->plainTextEdit->setPlainText(datastr);

            QMessageBox::information(NULL, "提示", "读取数据成功!");
        }
        else
        {
            disperrinf(status);
        }
    }else{
        QMessageBox::critical(NULL, "提示", "函数‘cpursfiledataread’未正确载入,请查询DLL文件版本是否正确!");
    }
}



void MainWindow::on_pb_write_clicked()
{
    if(!checkdllos()){return;}        //判断运行目录内动态库文件是否存在

    unsigned char status;             //函数返回状态
    unsigned char fileno;             //文件号
    unsigned char ctrlword;           //控制字
    unsigned char oldkeylen[1];       //旧密钥长度
    unsigned char oldkeybuf[20];      //旧密钥
    int staradd;                      //读写起始地址
    int datalen;                      //读写长度
    unsigned char rwbuf[8000];        //读写数据缓冲
    int keylen;
    QString keystr;
    QString datastr;

    keystr = ui->lineEdit_authkey2->text().trimmed();
    keylen=checkhexdata(keystr,oldkeybuf);
    if(keylen<0){
        QMessageBox::critical(NULL, "提示", "请输入正确的16进制文件认证密码!");
        ui->lineEdit_authkey2->setFocus();
        return;
    }
    oldkeylen[0]=keylen;

    datastr = ui->plainTextEdit->toPlainText().trimmed();
    datalen=checkhexdata(datastr,rwbuf);
    if(datalen<0){
        QMessageBox::critical(NULL, "提示", "请输入正确的16进制写入数据!");
        ui->plainTextEdit->setFocus();
        return;
    }

    fileno=ui->comboBox_rwfile->currentIndex();  //要读写的文件号
    staradd=ui->spinBox_rwbegin->value();        //读写起始地址
    datalen=ui->spinBox_rwlen->value();          //读写数据长度
    if(datalen<1 || datalen>247){
        QMessageBox::critical(NULL, "提示", "每次写卡最多247字节,请输入正确的写卡长度!");
        ui->spinBox_rwlen->setFocus();
        return;
    }

    if(ui->comboBox_authrwkey->currentIndex()==0){
        ctrlword=OLDKEYR;      //用只读密码来认证
    }else{ctrlword=OLDKEYWR;}  //用读写密码来认证

    if (mycpursfiledatawrite != NULL){        //是否成功连接上 cpursfiledatawrite()函数
        status = mycpursfiledatawrite(fileno,ctrlword,oldkeybuf,oldkeylen,staradd,rwbuf,datalen);
        if(status==0 ){
            mypcdbeep(30);
            QMessageBox::information(NULL, "提示", "写入数据成功!");
        }
        else
        {
            disperrinf(status);
        }
    }else{
        QMessageBox::critical(NULL, "提示", "函数‘cpursfiledatawrite’未正确载入,请查询DLL文件版本是否正确!");
    }
}


void MainWindow::on_pb_easy_write_clicked()
{
    if(!checkdllos()){return;}        //判断运行目录内动态库文件是否存在

    unsigned char status;             //函数返回状态
    unsigned char fileno;             //文件号
    unsigned char ctrlword;           //控制字
    unsigned char oldkeylen[1];       //旧密钥长度
    unsigned char oldkeybuf[20];      //旧密钥
    int staradd;                      //读写起始地址
    int datalen;                      //读写长度
    unsigned char rwbuf[8000];        //读写数据缓冲
    int keylen;
    QString keystr;
    QString datastr;

    keystr = ui->lineEdit_authkey2->text().trimmed();
    keylen=checkhexdata(keystr,oldkeybuf);
    if(keylen<0){
        QMessageBox::critical(NULL, "提示", "请输入正确的16进制文件认证密码!");
        ui->lineEdit_authkey2->setFocus();
        return;
    }
    oldkeylen[0]=keylen;

    datastr = ui->plainTextEdit->toPlainText().trimmed();
    datalen=checkhexdata(datastr,rwbuf);
    if(datalen<0){
        QMessageBox::critical(NULL, "提示", "请输入正确的16进制写入数据!");
        ui->plainTextEdit->setFocus();
        return;
    }

    fileno=ui->comboBox_rwfile->currentIndex();  //要读写的文件号
    staradd=ui->spinBox_rwbegin->value();        //读写起始地址
    datalen=ui->spinBox_rwlen->value();          //读写数据长度

    if(ui->comboBox_authrwkey->currentIndex()==0){
        ctrlword=OLDKEYR;      //用只读密码来认证
    }else{ctrlword=OLDKEYWR;}  //用读写密码来认证

    if (mycpursfiledatawrite_s != NULL){        //是否成功连接上 cpursfiledatawrite_s()函数
        status = mycpursfiledatawrite_s(fileno,ctrlword,oldkeybuf,oldkeylen,staradd,rwbuf,datalen);
        if(status==0 ){
            mypcdbeep(30);
            QMessageBox::information(NULL, "提示", "写入数据成功!");
        }
        else
        {
            disperrinf(status);
        }
    }else{
        QMessageBox::critical(NULL, "提示", "函数‘cpursfiledatawrite_s’未正确载入,请查询DLL文件版本是否正确!");
    }
}


void MainWindow::on_pb_clear_clicked()
{
    if(!checkdllos()){return;}      //判断运行目录内动态库文件是否存在

    unsigned char status;
    if (mycpurscardclr != NULL){         //是否成功连接上 cpurscardclr()函数
        status = mycpurscardclr();
        if(status==0){
            mypcdbeep(30);
            QMessageBox::information(NULL, "提示", "cpu卡强制清空卡成功");
        }else{
            if(status==64){
                QMessageBox::information(NULL, "提示", "此卡为未经过我们cpursinit函数成功初始化的卡");
            }else{
                disperrinf(status);
            }
        }
    } else{
        QMessageBox::critical(NULL, "提示", "函数‘cpurscardclr’未正确载入,请查询DLL文件版本是否正确!");
    }
}


void MainWindow::on_pb_changecardkey_clicked()
{
    if(!checkdllos()){return;}        //判断运行目录内动态库文件是否存在

    unsigned char status;             //函数返回状态
    unsigned char oldkeylen[1];       //旧密钥长度
    unsigned char oldkeybuf[20];      //旧密钥
    unsigned char newkeylen[1];       //新密钥长度
    unsigned char newkeybuf[20];      //新密钥
    int keylen;
    QString keystr;

    keystr = ui->lineEdit_cardoldkey->text().trimmed();
    keylen=checkhexdata(keystr,oldkeybuf);
    if(keylen<0){
        QMessageBox::critical(NULL, "提示", "请输入正确的16进制卡旧密码!");
        ui->lineEdit_cardoldkey->setFocus();
        return;
    }
    oldkeylen[0]=keylen;

    keystr = ui->lineEdit_cardnewkey->text().trimmed();
    keylen=checkhexdata(keystr,newkeybuf);
    if(keylen<0){
        QMessageBox::critical(NULL, "提示", "请输入正确的16进制卡新密码!");
        ui->lineEdit_cardnewkey->setFocus();
        return;
    }
    newkeylen[0]=keylen;

    if (mycpurscardkeychg != NULL){        //是否成功连接上 cpurscardkeychg()函数
        status = mycpurscardkeychg(oldkeybuf,oldkeylen,newkeybuf,newkeylen);
        if(status==0 ){
            mypcdbeep(30);
            QMessageBox::information(NULL, "提示", "修改卡片密码成功");
        }
        else
        {
            disperrinf(status);
        }
    }else{
        QMessageBox::critical(NULL, "提示", "函数‘cpurscardkeychg’未正确载入,请查询DLL文件版本是否正确!");
    }
}

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

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

相关文章

政府部门搭建的数字化工具平台有哪些?

政府部门搭建的数字化工具平台多样且广泛&#xff0c;旨在提高行政效能、优化公共服务和促进政务创新。以下是一些常见的数字化工具平台及其功能的详细介绍。 一、电子政务平台 1. 政务门户网站&#xff1a;作为政府对外的窗口&#xff0c;提供政府机构、政策信息、在线办事、…

Redis 的过期键 | Navicat 技术干货

Redis 是一种高性能的内存数据存储&#xff0c;以其速度和多功能性而闻名。其中一个有用的特性是为键设置过期时间的功能。在 Redis 中&#xff0c;为键设置过期时间对于管理数据和确保过时或临时数据自动从数据库中删除是至关重要的。在本文中&#xff0c;我们将探讨在 redis-…

SpringBoot整合DataWay配置前端查询

Dataway介绍 Dataway 是基于 DataQL 服务聚合能力&#xff0c;为应用提供的一个接口配置工具。使得使用者无需开发任何代码就配置一个满足需求的接口。整个接口配置、测试、冒烟、发布。一站式都通过 Dataway 提供的 UI 界面完成。UI 会以 Jar 包方式提供并集成到应用中并和应…

Springboot学习笔记——3

Springboot学习笔记——3 一、热部署1.1、手动启动热部署1.2、自动启动热部署1.3、热部署范围配置1.4、关闭热部署 二、配置高级2.1、第三方bean属性绑定2.2、松散绑定2.3、常用计量单位应用2.4、bean属性校验2.5、进制数据转换规则 三、测试3.1、加载测试专用属性3.2、加载测试…

mysql面试题32:MySQL数据库服务器性能分析的方法命令有哪些?

该文章专注于面试,面试只要回答关键点即可,不需要对框架有非常深入的回答,如果你想应付面试,是足够了,抓住关键点 面试官:MySQL数据库服务器性能分析的方法命令有哪些? MySQL数据库服务器性能分析的方法和命令有以下几种: EXPLAIN命令:用于分析查询语句的执行计划,…

基于springboot实现在线动漫信息交流分享平台项目【项目源码+论文说明】计算机毕业设计

基于springboot实现在线动漫信息交流分享平台演示 摘要 随着社会互联网技术的快速发展&#xff0c;每个行业都在努力与现代先进技术接轨&#xff0c;通过科技手段提高自身的优势&#xff1b;对于在线动漫信息平台当然也不能排除在外&#xff0c;随着网络技术的不断成熟&#x…

结婚请帖邀请函制作全攻略,一分钟学会

结婚是人生的重要时刻之一&#xff0c;而一份精美的结婚请帖邀请函则是新人向亲友们发出完美邀请的必备品。为了让你轻松制作出令人惊艳的结婚请帖邀请函&#xff0c;我们为你推荐一个简单易用的在线制作平台——乔拓云微传单平台。只需一分钟&#xff0c;你就能轻松学会&#…

城市项目招商创业园区供需特产公益小程序开源版开发

城市项目招商创业园区供需特产公益小程序开源版开发 城市项目招商创业园区供需特产公益小程序的功能主要包括以下几个方面&#xff1a; 项目招商&#xff1a;提供城市项目招商信息&#xff0c;包括项目介绍、投资额、回报率等详细信息&#xff0c;方便投资者了解项目情况&#…

云数据库(林子雨慕课课程)

文章目录 6.云数据库6.1 云数据库概述6.2 云数据库产品6.3 UMP系统6.3.1 UMP系统概述6.3.2 UMP系统架构6.3.3 UMP系统功能 6.4 Amazon云数据库6.4.1 Amazon和云计算的渊源6.4.2 Amazon AWS6.4.3 AWS平台上的云数据库6.5 微软云数据库SQL Azure 6.云数据库 6.1 云数据库概述 云…

小说推文和短剧推广真的赚钱吗以及授权渠道

先说授权渠道&#xff0c;可以通过”巨量推文“进行申请授权 小说推文和短剧推广大致分为cpa拉新 cps分成和cpm广告点击的收益 cpa拉新是通过你的引导进入后的新用户 cps分成是根据你的引导进入后并付费一定的比例分成给你 cpm广告点击是进入小程序后看了广告和点击了广告的…

浅述安防视频可视化场景中TSINGSEE青犀AI智能化应用的分析

随着社会的不断发展和安防需求的不断提升&#xff0c;安防视频可视化场景已经成为人们关注的焦点。而随着人工智能、大数据等技术的不断发展&#xff0c;智能化应用在安防视频可视化场景中的应用也越来越多。本文将分析安防视频可视化场景中的智能化应用&#xff0c;主要包括以…

【QT】Windows 编译并使用 QT 5.12.7源码

1、下载 QT 源码 QT5.12.7源码下载地址: download | QT 5.12.7 选择任意一种下载即可&#xff0c;适用于 Windows 和 Linux 环境 ​ 这里选择下载 .zip 文件。 2、安装依赖 (1) 安装 perl perl 安装包下载地址: download | perl for windows 根据当前系统选择对应版本。…

[硬件基础]-555定时器-单稳态多谐振荡器配置

555定时器-单稳态多谐振荡器配置 文章目录 555定时器-单稳态多谐振荡器配置1、概述2、单稳态多谐振荡器的内部运行原理2.1 初始条件2.2 运行条件 在上一篇文章中&#xff0c;我们了解了555定时器的内部工作原理。 在本文中&#xff0c;我们将研究 555 定时器的单稳态操作模式。…

STC89C51基础及项目第14天:循迹小车、跟随小车

1. 循迹小车基本原理和方案&#xff08;269.114&#xff09; 循迹模块使用 TCRT5000传感器的红外发射二极管不断发射红外线&#xff1a;当发射出的红外线 没有 被反射回来或被反射回来但强度不够大时&#xff0c;红外接收管一直处于关断状态&#xff0c;此时模块的输出端为 高…

积分球测量作用

积分球在测量光通量上的使用可以追溯到1890年&#xff0c;并且现在已经成为一个多方面广泛使用的仪器。积分球是专门用于LED光色参数测量和光谱分析的仪器。LED光源以其体积小、能耗低、响应快、寿命长等诸多优点&#xff0c;在各个领域都得到广泛使用&#xff0e;积分球作为一…

腾讯云学生用户专享活动汇总

腾讯云一直致力于为广大用户提供更加优惠的云计算服务&#xff0c;其中也包括学生用户。为了让学生用户更好地享受腾讯云的优惠政策&#xff0c;腾讯云推出了多种学生用户专享的优惠活动。本文将为大家介绍腾讯云学生用户专享的优惠活动&#xff0c;帮助学生用户更好地了解腾讯…

修炼k8s+flink+hdfs+dlink(四:k8s(二)组件)

一&#xff1a;控制平面组件。 控制平面组件会为集群做出全局决策&#xff0c;比如资源的调度。 以及检测和响应集群事件&#xff0c;例如当不满足部署的 replicas 字段时&#xff0c; 要启动新的 pod&#xff09;。 1. kube-apiserver。 该组件负责公开了 Kubernetes API&a…

QECon大会亮相产品,全栈测试平台推荐:RunnerGo

最近在gitee上看见一款获得GVP&#xff08;最有价值开源项目&#xff09;的测试平台RunnerGo&#xff0c;看他们官网介绍包含了接口测试、性能测试、自动化测试。知道他们有saas版可以试用&#xff0c;果断使用了一下&#xff0c;对其中场景管理和性能测试印象深刻&#xff0c;…

智慧公厕技术解析 | 提高公厕管理效率的关键

智慧公厕&#xff0c;作为现代城市管理的重要一环&#xff0c;已经越来越受到各地、各行业、各单位的重视。通过引入先进的技术手段&#xff0c;智慧公厕不仅能够提升管理效率&#xff0c;还能够改善用户体验&#xff0c;成为城市发展、旅游景区、商业大厦等场所的亮丽名片。本…

【项目】在线oj

1. 创建项目 创建maven项目。 引入依赖&#xff08;mysql connector和servlet&#xff09;&#xff1a; <dependencies><!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --><dependency><groupId>mysql</groupId><ar…