Skip to content

Commit c2429ad

Browse files
committed
Mark optional commands by '-' symbol
1 parent 3f760e3 commit c2429ad

File tree

4 files changed

+99
-25
lines changed

4 files changed

+99
-25
lines changed

qt/chip_db.cpp

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
#define CHIP_DB_FILE_NAME "nando_chip_db.csv"
1414

15+
#define CHIP_PARAM_NOT_DEFINED_SYMBOL '-'
16+
#define CHIP_PARAM_NOT_DEFINED_VALUE 0xFFFFFFFF
17+
1518
QString ChipDb::findFile()
1619
{
1720
QString fileName = CHIP_DB_FILE_NAME;
@@ -30,6 +33,57 @@ QString ChipDb::findFile()
3033
return fileName;
3134
}
3235

36+
int ChipDb::getParamFromString(const QString &value, uint32_t &param)
37+
{
38+
bool ok;
39+
40+
param = value.toUInt(&ok);
41+
if (!ok)
42+
return -1;
43+
44+
return 0;
45+
}
46+
47+
int ChipDb::getStringFromParam(const uint32_t &param, QString &value)
48+
{
49+
value = QString("%1").arg(param);
50+
51+
return 0;
52+
}
53+
54+
int ChipDb::getOptParamFromString(const QString &value, uint32_t &param)
55+
{
56+
if (value.trimmed() == CHIP_PARAM_NOT_DEFINED_SYMBOL)
57+
{
58+
param = CHIP_PARAM_NOT_DEFINED_VALUE;
59+
return 0;
60+
}
61+
62+
return getParamFromString(value, param);
63+
}
64+
65+
int ChipDb::getStringFromOptParam(uint32_t &param, QString &value)
66+
{
67+
if (param == CHIP_PARAM_NOT_DEFINED_VALUE)
68+
{
69+
value = CHIP_PARAM_NOT_DEFINED_SYMBOL;
70+
return 0;
71+
}
72+
73+
return getStringFromParam(param, value);
74+
}
75+
76+
bool ChipDb::isParamValid(uint32_t param, uint32_t min, uint32_t max)
77+
{
78+
return param >= min && param <= max;
79+
}
80+
81+
bool ChipDb::isOptParamValid(uint32_t param, uint32_t min, uint32_t max)
82+
{
83+
return (param == CHIP_PARAM_NOT_DEFINED_VALUE) ||
84+
(param >= min && param <= max);
85+
}
86+
3387
int ChipDb::stringToChipInfo(const QString &s, ChipInfo &ci)
3488
{
3589
int paramNum;
@@ -48,10 +102,7 @@ int ChipDb::stringToChipInfo(const QString &s, ChipInfo &ci)
48102
ci.name = paramsList[CHIP_PARAM_NAME];
49103
for (int i = CHIP_PARAM_NAME + 1; i < CHIP_PARAM_NUM; i++)
50104
{
51-
bool ok;
52-
53-
ci.params[i] = paramsList[i].toUInt(&ok);
54-
if (!ok)
105+
if (getOptParamFromString(paramsList[i], ci.params[i]))
55106
{
56107
QMessageBox::critical(nullptr, tr("Error"), tr("Failed to parse"
57108
" parameter %1").arg(paramsList[i]));
@@ -64,11 +115,16 @@ int ChipDb::stringToChipInfo(const QString &s, ChipInfo &ci)
64115

65116
int ChipDb::chipInfoToString(const ChipInfo &ci, QString &s)
66117
{
118+
QString csvValue;
67119
QStringList paramsList;
68120

69121
paramsList.append(ci.name);
70122
for (int i = CHIP_PARAM_NAME + 1; i < CHIP_PARAM_NUM; i++)
71-
paramsList.append(QString("%1").arg(ci.params[i]));
123+
{
124+
if (getStringFromOptParam(ci.params[i], csvValue))
125+
return -1;
126+
paramsList.append(csvValue);
127+
}
72128

73129
s = paramsList.join(',');
74130

qt/chip_db.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ class ChipDb : public QObject
8888
int size();
8989
void commit();
9090
void reset();
91-
91+
int getParamFromString(const QString &value, uint32_t &param);
92+
int getStringFromParam(uint32_t &param, QString &value);
93+
int getOptParamFromString(const QString &value, uint32_t &param);
94+
int getStringFromOptParam(uint32_t &param, QString &value);
95+
bool isParamValid(uint32_t param, uint32_t min, uint32_t max);
96+
bool isOptParamValid(uint32_t param, uint32_t min, uint32_t max);
9297
ChipInfo *operator[](int index) { return &chipInfoVector[index]; }
9398
};
9499

qt/chip_db_table_model.cpp

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "chip_db_table_model.h"
22
#include <limits>
33

4+
#define CHIP_DB_TABLE_MODEL_MIN_CYCLES 1
45
#define CHIP_DB_TABLE_MODEL_MAX_CYCLES 4
56

67
ChipDbTableModel::ChipDbTableModel(ChipDb *chipDb, QObject *parent) :
@@ -22,6 +23,7 @@ int ChipDbTableModel::columnCount(const QModelIndex & /*parent*/) const
2223
QVariant ChipDbTableModel::data(const QModelIndex &index, int role) const
2324
{
2425
int column;
26+
QString paramStr;
2527

2628
if (role != Qt::DisplayRole && role != Qt::EditRole)
2729
return QVariant();
@@ -51,17 +53,23 @@ QVariant ChipDbTableModel::data(const QModelIndex &index, int role) const
5153
case CHIP_PARAM_T_REA:
5254
case CHIP_PARAM_ROW_CYCLES:
5355
case CHIP_PARAM_COL_CYCLES:
56+
case CHIP_PARAM_BB_MARK_OFF:
57+
return (*chipDb)[index.row()]->params[column];
5458
case CHIP_PARAM_READ1_CMD:
55-
case CHIP_PARAM_READ2_CMD:
5659
case CHIP_PARAM_READ_ID_CMD:
5760
case CHIP_PARAM_RESET_CMD:
5861
case CHIP_PARAM_WRITE1_CMD:
59-
case CHIP_PARAM_WRITE2_CMD:
6062
case CHIP_PARAM_ERASE1_CMD:
61-
case CHIP_PARAM_ERASE2_CMD:
6263
case CHIP_PARAM_STATUS_CMD:
63-
case CHIP_PARAM_BB_MARK_OFF:
64-
return (*chipDb)[index.row()]->params[column];
64+
chipDb->getStringFromParam((*chipDb)[index.row()]->params[column],
65+
paramStr);
66+
return paramStr;
67+
case CHIP_PARAM_READ2_CMD:
68+
case CHIP_PARAM_WRITE2_CMD:
69+
case CHIP_PARAM_ERASE2_CMD:
70+
chipDb->getStringFromOptParam((*chipDb)[index.row()]->params[column],
71+
paramStr);
72+
return paramStr;
6573
}
6674

6775
return QVariant();
@@ -190,7 +198,6 @@ Qt::ItemFlags ChipDbTableModel::flags (const QModelIndex &index) const
190198
bool ChipDbTableModel::setData(const QModelIndex &index, const QVariant &value,
191199
int role)
192200
{
193-
bool convOk;
194201
uint32_t paramVal;
195202

196203
if (role != Qt::EditRole)
@@ -219,34 +226,40 @@ bool ChipDbTableModel::setData(const QModelIndex &index, const QVariant &value,
219226
case CHIP_PARAM_T_WC:
220227
case CHIP_PARAM_T_RC:
221228
case CHIP_PARAM_T_REA:
222-
paramVal = value.toUInt(&convOk);
223-
if (!convOk)
229+
case CHIP_PARAM_BB_MARK_OFF:
230+
if (chipDb->getParamFromString(value.toString(), paramVal))
224231
return false;
225232
(*chipDb)[index.row()]->params[index.column()] = paramVal;
226233
return true;
227234
case CHIP_PARAM_ROW_CYCLES:
228235
case CHIP_PARAM_COL_CYCLES:
229-
paramVal = value.toUInt(&convOk);
230-
if (!convOk)
236+
if (chipDb->getParamFromString(value.toString(), paramVal))
231237
return false;
232-
if (paramVal > CHIP_DB_TABLE_MODEL_MAX_CYCLES)
238+
if (!chipDb->isParamValid(paramVal, CHIP_DB_TABLE_MODEL_MIN_CYCLES,
239+
CHIP_DB_TABLE_MODEL_MAX_CYCLES))
240+
{
233241
return false;
242+
}
234243
(*chipDb)[index.row()]->params[index.column()] = paramVal;
235244
return true;
236245
case CHIP_PARAM_READ1_CMD:
237-
case CHIP_PARAM_READ2_CMD:
238246
case CHIP_PARAM_READ_ID_CMD:
239247
case CHIP_PARAM_RESET_CMD:
240248
case CHIP_PARAM_WRITE1_CMD:
241-
case CHIP_PARAM_WRITE2_CMD:
242249
case CHIP_PARAM_ERASE1_CMD:
243-
case CHIP_PARAM_ERASE2_CMD:
244250
case CHIP_PARAM_STATUS_CMD:
245-
case CHIP_PARAM_BB_MARK_OFF:
246-
paramVal = value.toUInt(&convOk);
247-
if (!convOk)
251+
if (chipDb->getParamFromString(value.toString(), paramVal))
252+
return false;
253+
if (!chipDb->isParamValid(paramVal, 0x00, 0xFF))
254+
return false;
255+
(*chipDb)[index.row()]->params[index.column()] = paramVal;
256+
return true;
257+
case CHIP_PARAM_READ2_CMD:
258+
case CHIP_PARAM_WRITE2_CMD:
259+
case CHIP_PARAM_ERASE2_CMD:
260+
if (chipDb->getOptParamFromString(value.toString(), paramVal))
248261
return false;
249-
if (paramVal > std::numeric_limits<uint8_t>::max())
262+
if (!chipDb->isOptParamValid(paramVal, 0x00, 0xFF))
250263
return false;
251264
(*chipDb)[index.row()]->params[index.column()] = paramVal;
252265
return true;

qt/nando_chip_db.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# name, page size, block size, total size, spare size, tCS, tCLS, tALS, tCLR, tAR, tWP, tRP, tDS, tCH, tCLH, tALH, tWC, tRC, tREA, row cycles, col. cycles, read 1 com., read 2 com., read ID com., reset com., write 1 com., write 2 com., erase 1 com., erase 2 com., status com., bad block mark off.
22
K9F2G08U0C, 2048, 131072, 268435456, 64, 20, 12, 12, 10, 10, 12, 12, 12, 5, 5, 5, 25, 25, 20, 3, 2, 0, 48, 144, 255, 128, 16, 96, 208, 112, 0
33
K9F1G08U0E, 2048, 131072, 134217728, 64, 20, 12, 12, 10, 10, 12, 12, 12, 5, 5, 5, 25, 25, 20, 3, 2, 0, 48, 144, 255, 128, 16, 96, 208, 112, 0
4-
HY27US08561A, 512, 16384, 33554432, 16, 0, 0, 0, 10, 10, 25, 25, 20, 10, 10, 10, 50, 50, 30, 2, 1, 0, 255, 144, 255, 128, 16, 96, 208, 112, 5
4+
HY27US08561A, 512, 16384, 33554432, 16, 0, 0, 0, 10, 10, 25, 25, 20, 10, 10, 10, 50, 50, 30, 2, 1, 0, -, 144, 255, 128, 16, 96, 208, 112, 5

0 commit comments

Comments
 (0)