-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstorage.cpp
More file actions
245 lines (198 loc) · 6.71 KB
/
storage.cpp
File metadata and controls
245 lines (198 loc) · 6.71 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
#include "storage.h"
#include <EApi.h>
storage::storage(QWidget *parent)
:QWidget(parent)
{
QFont fontlabel;
fontlabel.setBold(true);
fontlabel.setPointSize(11);
QFont fontvalue;
fontvalue.setBold(false);
fontvalue.setPointSize(11);
EApiStatus_t StatusCode = EAPI_STATUS_SUCCESS;
pStorgeSize = 0 ;
uint32_t pBlockLen = 0;
offset = 0 ;
length = 0;
char temp[300];
storageSize = new QLabel;
storageSize->setFont(fontvalue);
storageType = new QLabel;
storageType->setText( "<span style='font-size:11pt; font-weight:600; color:black;'>Selected Area: </span><span style='font-size:11pt; font-weight:normal; color:black;'>Standard Storage Area</span>" );
StatusCode=EApiStorageCap(EAPI_ID_STORAGE_STD,&pStorgeSize,&pBlockLen);
if(EAPI_TEST_SUCCESS(StatusCode))
{
definedStorage = true;
sprintf(temp,"<span style='font-size:11pt; font-weight:600; color:black;'>Area Size: </span><span style='font-size:11pt; font-weight:normal; color:black;'>%d bytes</span>",pStorgeSize);
storageSize->setText(temp);
}
else
{
definedStorage = false;
storageSize->setText( "<span style='font-size:11pt; font-weight:600; color:black;'>Area Size: </span><span style='font-size:11pt; font-weight:normal; color:black;'>No defined user storage area</span>" );
}
infoLayout = new QVBoxLayout;
infoLayout->addWidget(storageType);
infoLayout->addWidget(storageSize);
infoGroup = new QGroupBox("Information");
infoGroup->setFont(fontlabel);
infoGroup->setLayout(infoLayout);
/*************************************************/
bytegrid = new QGridLayout;
offsetLabel = new QLabel("Offset:");
offsetLabel->setFont(fontlabel);
offsetValue = new QLineEdit("0");
offsetValue->setFont(fontvalue);
offsetValue->setFixedWidth(50);
connect(offsetValue, SIGNAL(textChanged(QString)), this, SLOT(offsetChanged(QString)));
bytegrid->addWidget(offsetLabel,1,0);
bytegrid->addWidget(offsetValue,1,1);
lengthLabel = new QLabel;
if (pStorgeSize > 0)
sprintf(temp,"Length(1-%d):",pStorgeSize);
else
sprintf(temp,"Length(only 0):");
lengthLabel->setText(temp);
lengthValue = new QLineEdit("0");
lengthValue->setFont(fontvalue);
lengthValue->setFixedWidth(50);
connect(lengthValue, SIGNAL(textChanged(QString)), this, SLOT(lengthChanged(QString)));
bytegrid->addWidget(lengthLabel,2,0);
bytegrid->addWidget(lengthValue,2,1);
writeLabel = new QLabel("Write:");
writeValue = new QTextEdit;
writeValue->setFont(fontvalue);
connect(writeValue, SIGNAL(textChanged()), this, SLOT(getInput()));
writeButton = new QPushButton("Write");
connect( writeButton, SIGNAL( clicked() ), this, SLOT( writeClicked() ) );
bytegrid->addWidget(writeLabel,3,0);
bytegrid->addWidget(writeValue,3,1);
bytegrid->addWidget(writeButton,3,2);
readLabel = new QLabel("Read:");
readValue = new QTextEdit();
readValue->setFont(fontvalue);
readValue->setStyleSheet("QTextEdit { background-color: #BDD8CA; color : black; }");
readValue->setReadOnly(true);
readButton = new QPushButton("Read");
connect( readButton, SIGNAL( clicked() ), this, SLOT( readClicked() ) );
bytegrid->addWidget(readLabel,4,0);
bytegrid->addWidget(readValue,4,1);
bytegrid->addWidget(readButton,4,2);
byteGroup = new QGroupBox("Read/Write Data");
byteGroup->setFont(fontlabel);
byteGroup->setLayout(bytegrid);
if (definedStorage == false)
byteGroup->setEnabled(false);
grid = new QGridLayout;
grid->addWidget(infoGroup,0,0,1,2);
grid->addWidget(byteGroup,1,0,1,2);
setLayout(grid);
}
void storage::readClicked()
{
uint8_t *TmpStrBuf;
EApiStatus_t StatusCode = EAPI_STATUS_SUCCESS;
TmpStrBuf = (uint8_t*) malloc(sizeof(uint8_t)*(pStorgeSize+1));
StatusCode=EApiStorageAreaRead(EAPI_ID_STORAGE_STD,offset,TmpStrBuf,pStorgeSize, length);
if(EAPI_TEST_SUCCESS(StatusCode))
{
QString tokens;
for(unsigned int i = 0; i < length ;i ++) {
uint8_t value = TmpStrBuf[i] / 16;
if (value ==0 || value <=9)
tokens.append(48+value);
else
tokens.append(65+(value%10));
value = TmpStrBuf[i] % 16;
if (value ==0 || value <=9)
tokens.append(48+value);
else
tokens.append(65+(value%10));
tokens.append(" ");
}
readValue->setText(tokens);
}
else
readValue->setText("Error!");
free(TmpStrBuf);
}
void storage::writeClicked()
{
unsigned int size = 0;
uint8_t *writestr;
unsigned int originsize = 0;
unsigned int i = 0 , j =0;
char hex[2] = {(char)'0',(char)'0'};
uint8_t num = 0;
originsize = input.size();
if (originsize % 2 == 0)
size = originsize / 2 ;
else
size = (originsize /2) + 1;
writestr = (uint8_t*) malloc(sizeof(uint8_t)*(size));
j = 0;
for (i = 0; i < originsize ; i+=2)
{
if (((i+1) == originsize) && (originsize % 2 != 0))
{
hex[0] = (char)'0';
hex[1] = input.at(i).toLatin1();
}
else
{
hex[0] = input.at(i).toLatin1();
hex[1] = input.at(i+1).toLatin1();
}
num = (int)strtol(hex, NULL, 16);
if (j < size)
{
writestr[j] = num;
j++;
}
}
int tempLength = size;
if (length > size)
tempLength = size;
else
tempLength = length;
EApiStatus_t StatusCode;
StatusCode=EApiStorageAreaWrite(EAPI_ID_STORAGE_STD,offset,writestr,tempLength);
if(EAPI_TEST_SUCCESS(StatusCode))
writeValue->setText("Successful");
else
writeValue->setText("Error!");
free(writestr);
}
void storage::offsetChanged(QString text)
{
char temp[50];
offset = text.toInt();
if ((pStorgeSize - offset) > 0)
sprintf(temp,"Length(1-%d):",pStorgeSize - offset);
else
sprintf(temp,"Length(only 0):");
lengthLabel->setText(temp);
}
void storage::lengthChanged(QString text)
{
length = text.toInt();
}
void storage::getInput()
{
if ((writeValue->toPlainText() == "Successful") ||
(writeValue->toPlainText() == "Error!"))
{
input.clear();
return;
}
input = writeValue->toPlainText().toUpper();
input.replace(QRegExp("[^A-F0-9]"), "");
QStringList tokens;
for(int i = 0; i < input.length(); i += 2) {
tokens << input.mid(i, 2);
}
writeValue->blockSignals(true);
writeValue->setText(tokens.join(" "));
writeValue->moveCursor(QTextCursor::EndOfBlock);
writeValue->blockSignals(false);
}