-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmainwindow.cpp
213 lines (173 loc) · 5.55 KB
/
mainwindow.cpp
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
results = NULL;
statusMessage = new QLabel();
serial = new QSerialPort(this);
ui->statusBar->addPermanentWidget(statusMessage, 1);
on_reloadButton_released();
}
MainWindow::~MainWindow()
{
delete statusMessage;
delete ui;
if(results != NULL)
delete results;
}
void MainWindow::on_reloadButton_released()
{
ui->comboBox->setDisabled(true);
ui->comboBox->clear();
SetStatus("Getting Serial Ports...");
// Example use QSerialPortInfo
foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
qDebug() << "Name: " << info.portName();
ui->comboBox->addItem(info.portName() + " - " + info.description(), QString(info.portName()));
qDebug() << "Description: " << info.description();
qDebug() << "Manufacturer: " << info.manufacturer();
}
ui->comboBox->setEnabled(true);
ReadyStatus();
}
void MainWindow::on_readButton_released()
{
if(results != NULL) {
delete results;
results = NULL;
}
SetStatus("Reading...");
ReadSerial(QVariant(ui->comboBox->currentData()).toString());
if(results != NULL && results->length() >= EEPROM_SIZE) {
if(results->length() > EEPROM_SIZE) {
results->remove(0, results->length() - EEPROM_SIZE);
}
qDebug() << results->toHex();
if(results->at(0) != 0)
{
//Load EEPROM data into fields
ui->serialLineEdit->setText(QString(results->mid(0x34, 12)));
XboxVersion(ui->serialLineEdit->text());
ui->onlineKeyLineEdit->setText(QString(results->mid(0x48, 16).toHex()).toUpper());
ui->dvdZoneLineEdit->setText(QString(results->mid(0xBC, 4).toHex()));
ui->macLineEdit->setText(QString(results->mid(0x40, 6).toHex().toUpper()));
ReadyStatus();
}
else {
SetStatus("Arduino's EEPROM is empty.");
}
}
else if(results != NULL && results->length() < EEPROM_SIZE) {
SetStatus(QString(results->data()));
}
else {
SetStatus("Invalid number of bytes read, try again.");
}
}
void MainWindow::on_actionExit_triggered()
{
QApplication::quit();
}
void MainWindow::on_actionSave_EEPROM_bin_triggered()
{
QString filter = "Binary File (*.bin)";
QFileDialog *fileDialog = new QFileDialog;
fileDialog->setDefaultSuffix("bin");
QString fileName = fileDialog->getSaveFileName(this, tr("Save File"), "EEPROM.bin",
filter, &filter);
if (fileName != "") {
QFile file(fileName);
if (file.open(QIODevice::ReadWrite)) {
QDataStream stream(&file);
//stream << ui->textBrowser->toPlainText();
stream.writeRawData(results->data(), EEPROM_SIZE);
file.flush();
file.close();
}
else {
QMessageBox::critical(this, tr("Error"), tr("Could not save file"));
return;
}
}
}
void MainWindow::on_actionAbout_triggered()
{
QMessageBox::about(this, "About", "<p align='center'>DuinoBoX " VERSION
"<br>An Xbox EEPROM Reader"
"<br>(<a href=" GITHUB_URL ">GitHub Page</a>)<br>"
"Copyright (C) 2017, Ben DeCamp</p>");
}
void MainWindow::ReadyStatus()
{
statusMessage->setText("Ready");
statusMessage->repaint();
}
void MainWindow::SetStatus(QString msg)
{
statusMessage->setText(msg);
statusMessage->repaint();
}
void MainWindow::ReadSerial(QString portName)
{
serial->setPortName(portName);
serial->setParity(QSerialPort::NoParity);
serial->setBaudRate(QSerialPort::Baud9600, QSerialPort::AllDirections);
serial->setDataBits(QSerialPort::Data8);
serial->setStopBits(QSerialPort::OneStop);
serial->setFlowControl(QSerialPort::NoFlowControl);
if(serial->open(QIODevice::ReadWrite)) {
QByteArray dataArray;
QString bootStr;
while (serial->waitForReadyRead(1000))
bootStr.append(serial->readAll());
if(bootStr != NULL)
qDebug() << bootStr;
writeData();
while (serial->waitForReadyRead(1000)) {
QByteArray temp = serial->readAll();
dataArray.append(temp);
}
//qDebug() << QString(dataArray.toHex());
results = new QByteArray(dataArray);
serial->close();
}
}
void MainWindow::writeData()
{
QString test = "1";
serial->write(test.toLocal8Bit());
}
void MainWindow::XboxVersion(QString serialNumber)
{
QString xboxVersion = "";
int yearWeekBuilt = serialNumber.mid(7, 2).toInt();
int factoryCode = serialNumber.mid(10, 2).toInt();
if(yearWeekBuilt < 23)
xboxVersion = "1.0";
else if(yearWeekBuilt == 23) {
if(factoryCode == 3)
xboxVersion = "1.0";
else
xboxVersion = "1.0-1.1";
}
else if(yearWeekBuilt <= 25)
xboxVersion = "1.1";
else if(yearWeekBuilt <= 30)
xboxVersion = "1.2";
else if(yearWeekBuilt <= 32)
xboxVersion = "1.3";
else if(yearWeekBuilt <= 33)
xboxVersion = "1.4-1.5";
else if(yearWeekBuilt <= 41)
xboxVersion = "1.6";
else
xboxVersion = "1.6b";
ui->xboxVersionLabel->setText(xboxVersion);
}
void MainWindow::VideoRegion()
{
uint32_t region = results->mid(0x58, 4).toUInt();
}