Complete Trailer Decoder(without test)

This commit is contained in:
wh201906 2020-08-05 00:45:54 +08:00
parent a935ff9703
commit 6f860111df
2 changed files with 62 additions and 35 deletions

View file

@ -1,6 +1,40 @@
#include "mf_trailerdecoderdialog.h" #include "mf_trailerdecoderdialog.h"
#include "ui_mf_trailerdecoderdialog.h" #include "ui_mf_trailerdecoderdialog.h"
MF_trailerDecoderDialog::AccessType MF_trailerDecoderDialog::dataCondition[8][4] =
{
{ACC_KEY_AB, ACC_KEY_AB, ACC_KEY_AB, ACC_KEY_AB},
{ACC_KEY_AB, ACC_NEVER, ACC_NEVER, ACC_NEVER},
{ACC_KEY_AB, ACC_KEY_B, ACC_NEVER, ACC_NEVER},
{ACC_KEY_AB, ACC_KEY_B, ACC_KEY_B, ACC_KEY_AB},
{ACC_KEY_AB, ACC_NEVER, ACC_NEVER, ACC_KEY_AB},
{ACC_KEY_B, ACC_KEY_B, ACC_NEVER, ACC_NEVER},
{ACC_KEY_B, ACC_NEVER, ACC_NEVER, ACC_NEVER},
{ACC_NEVER, ACC_NEVER, ACC_NEVER, ACC_NEVER},
};
MF_trailerDecoderDialog::AccessType MF_trailerDecoderDialog::trailerReadCondition[8][3] =
{
{ACC_NEVER, ACC_KEY_A, ACC_KEY_A},
{ACC_NEVER, ACC_KEY_A, ACC_KEY_A},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
{ACC_NEVER, ACC_KEY_A, ACC_KEY_A},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
};
MF_trailerDecoderDialog::AccessType MF_trailerDecoderDialog::trailerWriteCondition[8][3] =
{
{ACC_KEY_A, ACC_NEVER, ACC_KEY_A},
{ACC_NEVER, ACC_NEVER, ACC_NEVER},
{ACC_KEY_B, ACC_NEVER, ACC_KEY_B},
{ACC_NEVER, ACC_NEVER, ACC_NEVER},
{ACC_KEY_A, ACC_KEY_A, ACC_KEY_A},
{ACC_KEY_B, ACC_KEY_B, ACC_KEY_B},
{ACC_NEVER, ACC_KEY_B, ACC_NEVER},
{ACC_NEVER, ACC_NEVER, ACC_NEVER},
};
MF_trailerDecoderDialog::MF_trailerDecoderDialog(QWidget *parent) : MF_trailerDecoderDialog::MF_trailerDecoderDialog(QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::MF_trailerDecoderDialog) ui(new Ui::MF_trailerDecoderDialog)
@ -55,10 +89,30 @@ void MF_trailerDecoderDialog::on_accessBitsEdit_textEdited(const QString &arg1)
quint8 ACBits[4]; quint8 ACBits[4];
for(int i = 0; i < 4; i++) for(int i = 0; i < 4; i++)
{ {
ACBits[i] = (((halfBytes[4] >> i) & 1) << 2) & (((halfBytes[5] >> i) & 1) << 1) & (((halfBytes[2] >> i) & 1) << 0); ACBits[i] = (((halfBytes[4] >> i) & 1) << 2) | (((halfBytes[5] >> i) & 1) << 1) | (((halfBytes[2] >> i) & 1) << 0);
} }
bool isKeyBReadable = ACBits[3] == 0 || ACBits[3] == 1 || ACBits[3] == 4; bool isKeyBReadable = ACBits[3] == 0 || ACBits[3] == 1 || ACBits[3] == 4;
setTableItem(ui->trailerBlockWidget, 0, 0, "X"); for(int j = 0; j < 3; j++)
{
setTableItem(ui->trailerBlockWidget, 0, j, trailerReadCondition[ACBits[3]][j]);
setTableItem(ui->trailerBlockWidget, 1, j, trailerWriteCondition[ACBits[3]][j]);
}
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 4; j++)
{
AccessType type = dataCondition[ACBits[i]][j];
if(type == ACC_KEY_B && isKeyBReadable)
{
type = ACC_NEVER;
}
else if(type == ACC_KEY_AB && isKeyBReadable)
{
type = ACC_KEY_A;
}
setTableItem(ui->dataBlockWidget, i, j, type);
}
}
} }
} }

View file

@ -37,39 +37,12 @@ private:
QRegularExpressionValidator* validator; QRegularExpressionValidator* validator;
QButtonGroup* sizeGroup; QButtonGroup* sizeGroup;
void setTableItem(QTableWidget *widget, int row, int column, AccessType accessType); void setTableItem(QTableWidget *widget, int row, int column, AccessType accessType);
AccessType dataCondition[8][4] =
{ // If I don't make them static, the app will crash(these arrays might take too much space)
{ACC_KEY_AB, ACC_KEY_AB, ACC_KEY_AB, ACC_KEY_AB}, static AccessType dataCondition[8][4];
{ACC_KEY_AB, ACC_NEVER, ACC_NEVER, ACC_NEVER}, static AccessType trailerReadCondition[8][3];
{ACC_KEY_AB, ACC_KEY_B, ACC_NEVER, ACC_NEVER}, static AccessType trailerWriteCondition[8][3];
{ACC_KEY_AB, ACC_KEY_B, ACC_KEY_B, ACC_KEY_AB},
{ACC_KEY_AB, ACC_NEVER, ACC_NEVER, ACC_KEY_AB},
{ACC_KEY_B, ACC_KEY_B, ACC_NEVER, ACC_NEVER},
{ACC_KEY_B, ACC_NEVER, ACC_NEVER, ACC_NEVER},
{ACC_NEVER, ACC_NEVER, ACC_NEVER, ACC_NEVER},
};
AccessType trailerReadCondition[8][3] =
{
{ACC_NEVER, ACC_KEY_A, ACC_KEY_A},
{ACC_NEVER, ACC_KEY_A, ACC_KEY_A},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
{ACC_NEVER, ACC_KEY_A, ACC_KEY_A},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
};
AccessType trailerWriteCondition[8][3] =
{
{ACC_KEY_A, ACC_NEVER, ACC_KEY_A},
{ACC_NEVER, ACC_NEVER, ACC_NEVER},
{ACC_KEY_B, ACC_NEVER, ACC_KEY_B},
{ACC_NEVER, ACC_NEVER, ACC_NEVER},
{ACC_KEY_A, ACC_KEY_A, ACC_KEY_A},
{ACC_KEY_B, ACC_KEY_B, ACC_KEY_B},
{ACC_NEVER, ACC_KEY_B, ACC_NEVER},
{ACC_NEVER, ACC_NEVER, ACC_NEVER},
};
}; };
#endif // MF_TRAILERDECODERDIALOG_H #endif // MF_TRAILERDECODERDIALOG_H