Skip to content

Commit c8d0644

Browse files
author
Ilia Platone
committed
Update json files
1 parent 4efaab4 commit c8d0644

22 files changed

Lines changed: 126 additions & 80 deletions

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ set(AHP_XC_GUI_VERSION "${AHP_XC_GUI_VERSION_MAJOR}.${AHP_XC_GUI_VERSION_MINOR}.
3030
#endif()
3131
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/")
3232

33-
find_package(Qt5 COMPONENTS Widgets Network SerialPort Charts Network REQUIRED)
33+
find_package(Qt5 COMPONENTS Widgets Network SerialPort Charts REQUIRED)
3434
find_package(Threads REQUIRED)
3535
find_package(AHPXC REQUIRED)
3636
find_package(AHPGT REQUIRED)

Erase.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

app.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
IDI_ICON1 ICON DISCARDABLE "icon.ico"
2+
IDI_DATA1 TEXT DISCARDABLE "Erase.json"
23
IDI_DATA1 TEXT DISCARDABLE "xc1.json"
34
IDI_DATA1 TEXT DISCARDABLE "xc2.json"
45
IDI_DATA1 TEXT DISCARDABLE "xc4.json"

mainwindow.cpp

Lines changed: 92 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
const double graph_ratio = 0.75;
3434

35+
36+
QMutex(MainWindow::vlbi_mutex);
3537
vlbi_context context[vlbi_total_contexts];
3638
double coverage_delegate(double x, double y)
3739
{
@@ -40,6 +42,16 @@ double coverage_delegate(double x, double y)
4042
return 1.0;
4143
}
4244

45+
static char *strrand(int len)
46+
{
47+
int i;
48+
char* ret = (char*)malloc(len+1);
49+
for(i = 0; i < len; i++)
50+
ret[i] = 'a' + (rand() % 21);
51+
ret[i] = 0;
52+
return ret;
53+
}
54+
4355
static int32_t reset_by_vid_pid(int vid, int pid)
4456
{
4557
int rc = 0;
@@ -66,26 +78,61 @@ static int32_t reset_by_vid_pid(int vid, int pid)
6678
return rc;
6779
}
6880

69-
static void flash_svf(QString svf, QString bsdl)
81+
bool MainWindow::svf_from_resources(QString json, QString svf, QString bsdl)
7082
{
71-
QString cmd = "echo 'cable FT2232\nbsdl path "+bsdl+"\ndetect\nfrequency "+QString::number(12000000)+"\nsvf "+svf+"'|jtag";
72-
system(cmd.toStdString().c_str());
73-
sleep(1);
74-
reset_by_vid_pid(0x0403, 0x6014);
83+
QByteArray bin;
84+
if(QFile::exists(":/data/"+json+".json")) {
85+
QFile s(":/data/"+json+".json");
86+
s.open(QIODevice::ReadOnly);
87+
if(s.isOpen()) {
88+
if(QFile::exists(svf)) unlink(svf.toStdString().c_str());
89+
if(QFile::exists(bsdl)) unlink(bsdl.toStdString().c_str());
90+
QJsonDocument doc = QJsonDocument::fromJson(s.readAll());
91+
QJsonObject obj = doc.object();
92+
QString base64;
93+
base64 = obj["data"].toString();
94+
bin = QByteArray::fromBase64(base64.toStdString().c_str());
95+
if(bin.length() == 0) {
96+
goto res_end;
97+
}
98+
QFile svf_file(svf);
99+
svf_file.open(QIODevice::WriteOnly);
100+
if(svf_file.isOpen()) {
101+
svf_file.write(bin, bin.length());
102+
svf_file.close();
103+
}
104+
base64 = obj["image"].toString();
105+
bin = QByteArray::fromBase64(base64.toStdString().c_str());
106+
if(bin.length() == 0) {
107+
goto res_end;
108+
}
109+
QFile bsdl_file(bsdl);
110+
bsdl_file.open(QIODevice::WriteOnly);
111+
if(bsdl_file.isOpen()) {
112+
bsdl_file.write(bin, bin.length());
113+
bsdl_file.close();
114+
}
115+
}
116+
res_end:
117+
s.close();
118+
if(!QFile::exists(svf)) return false;
119+
if(!QFile::exists(bsdl)) return false;
120+
return false;
121+
}
122+
return false;
75123
}
76124

77-
static char *strrand(int len)
125+
static void flash_svf(QStringList svf_list)
78126
{
79-
int i;
80-
char* ret = (char*)malloc(len+1);
81-
for(i = 0; i < len; i++)
82-
ret[i] = 'a' + (rand() % 21);
83-
ret[i] = 0;
84-
return ret;
127+
QString cmd = "echo 'cable FT2232\ndetect\nfrequency "+QString::number(12000000)+"\n";
128+
for(QString svf : svf_list)
129+
cmd+="svf "+svf+ "\n";
130+
cmd+="'|jtag";
131+
system(cmd.toStdString().c_str());
132+
sleep(1);
133+
reset_by_vid_pid(0x0403, 0x6014);
85134
}
86135

87-
QMutex(MainWindow::vlbi_mutex);
88-
89136
QStringList MainWindow::CheckFirmware(QString url, int timeout_ms)
90137
{
91138
QByteArray list;
@@ -119,7 +166,7 @@ QStringList MainWindow::CheckFirmware(QString url, int timeout_ms)
119166
return QStringList();
120167
}
121168

122-
bool MainWindow::DownloadFirmware(QString url, QString svf, QString bsdl, QSettings *settings, int timeout_ms)
169+
bool MainWindow::DownloadFirmware(QString url, QString svf, QString bsdl, int timeout_ms)
123170
{
124171
QByteArray bin;
125172
url+="&download=on";
@@ -128,34 +175,38 @@ bool MainWindow::DownloadFirmware(QString url, QString svf, QString bsdl, QSetti
128175
QTimer timer;
129176
timer.setSingleShot(true);
130177
QEventLoop loop;
131-
connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
132-
connect(response, SIGNAL(finished()), &loop, SLOT(quit()));
178+
QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
179+
QObject::connect(response, SIGNAL(finished()), &loop, SLOT(quit()));
133180
timer.start(timeout_ms);
134181
loop.exec();
135-
QString base64 = settings->value("firmware-"+svf, "").toString();
136182
if(response->error() == QNetworkReply::NetworkError::NoError) {
137-
if(QFile::exists(svf)) unlink(svf.toUtf8());
138-
if(QFile::exists(bsdl)) unlink(bsdl.toUtf8());
183+
if(QFile::exists(svf)) unlink(svf.toStdString().c_str());
184+
if(QFile::exists(bsdl)) unlink(bsdl.toStdString().c_str());
139185
QJsonDocument doc = QJsonDocument::fromJson(response->readAll());
140186
QJsonObject obj = doc.object();
187+
QString base64;
141188
base64 = obj["data"].toString();
142-
if(base64.isNull() || base64.isEmpty()) {
189+
bin = QByteArray::fromBase64(base64.toStdString().c_str());
190+
if(bin.length() == 0) {
143191
goto dl_end;
144192
}
145-
bin = QByteArray::fromBase64(base64.toUtf8());
146193
QFile svf_file(svf);
147194
svf_file.open(QIODevice::WriteOnly);
148-
svf_file.write(bin, bin.length());
149-
svf_file.close();
195+
if(svf_file.isOpen()) {
196+
svf_file.write(bin, bin.length());
197+
svf_file.close();
198+
}
150199
base64 = obj["image"].toString();
151-
if(base64.isNull() || base64.isEmpty()) {
200+
bin = QByteArray::fromBase64(base64.toStdString().c_str());
201+
if(bin.length() == 0) {
152202
goto dl_end;
153203
}
154-
bin = QByteArray::fromBase64(base64.toUtf8());
155204
QFile bsdl_file(bsdl);
156205
bsdl_file.open(QIODevice::WriteOnly);
157-
bsdl_file.write(bin, bin.length());
158-
bsdl_file.close();
206+
if(bsdl_file.isOpen()) {
207+
bsdl_file.write(bin, bin.length());
208+
bsdl_file.close();
209+
}
159210
}
160211
dl_end:
161212
response->deleteLater();
@@ -191,7 +242,9 @@ MainWindow::MainWindow(QWidget *parent)
191242
settings = new QSettings(ini, QSettings::Format::IniFormat);
192243
QString url = "https://www.iliaplatone.com/firmware.php?product=";
193244
bsdl_filename = homedir + dir_separator + strrand(32) + ".bsm";
194-
svf_filename = homedir + dir_separator + strrand(32);
245+
svf_filename = homedir + dir_separator + strrand(32) + ".svf";;
246+
erase_bsdl_filename = homedir + dir_separator + strrand(32) + ".bsm";
247+
erase_svf_filename = homedir + dir_separator + strrand(32) + ".svf";;
195248
stdout_filename = homedir + dir_separator + QDateTime::currentDateTimeUtc().toString(Qt::DateFormat::ISODate).replace(":", "") + ".log";
196249

197250
connected = false;
@@ -243,6 +296,8 @@ MainWindow::MainWindow(QWidget *parent)
243296
QStringList firmwares = CheckFirmware(url+"xc*");
244297
if(firmwares.count() > 0) {
245298
ui->firmware->clear();
299+
ui->firmware->addItem("Current");
300+
ui->firmware->addItem("Erase");
246301
for (QString fw : firmwares)
247302
ui->firmware->addItem(fw.replace("firmware/", "").replace("-firmware.bin", ""));
248303
}
@@ -372,46 +427,21 @@ MainWindow::MainWindow(QWidget *parent)
372427
ui->firmware->setEnabled(false);
373428
ui->Connect->setEnabled(false);
374429
ui->XCPort->setEnabled(false);
430+
if(ui->firmware->currentText() == "Current") goto skip_download;
375431
has_svf_firmware = false;
376-
if(DownloadFirmware(url+ui->firmware->currentText(), svf_filename, bsdl_filename, settings))
432+
if (DownloadFirmware(url+ui->firmware->currentText(), svf_filename, bsdl_filename, 3000)){
433+
has_svf_firmware = true;
434+
} else if(svf_from_resources(ui->firmware->currentText(), svf_filename, bsdl_filename)){
377435
has_svf_firmware = true;
378-
else {
379-
QFile svf_file(svf_filename);
380-
svf_file.open(QIODevice::ReadWrite);
381-
QFile bsdl_file(bsdl_filename);
382-
bsdl_file.open(QIODevice::ReadWrite);
383-
if(svf_file.isOpen() && bsdl_file.isOpen()) {
384-
QFile s(":/data/"+ui->firmware->currentText()+".json");
385-
s.open(QIODevice::ReadOnly);
386-
if(s.isOpen()) {
387-
QJsonDocument doc = QJsonDocument::fromJson(s.readAll());
388-
QJsonObject obj = doc.object();
389-
QString base64 = obj["data"].toString();
390-
if(base64.isNull() || base64.isEmpty()) {
391-
has_svf_firmware = false;
392-
} else {
393-
has_svf_firmware = true;
394-
svf_file.write(QByteArray::fromBase64(base64.toUtf8()));
395-
}
396-
base64 = obj["image"].toString();
397-
if(base64.isNull() || base64.isEmpty()) {
398-
has_bsdl = false;
399-
} else {
400-
has_bsdl = true;
401-
bsdl_file.write(QByteArray::fromBase64(base64.toUtf8()));
402-
}
403-
s.close();
404-
}
405-
svf_file.close();
406-
bsdl_file.close();
407-
}
408436
}
409437
if(has_svf_firmware) {
410-
flash_svf(svf_filename, bsdl_filename);
438+
//svf_from_resources("Erase", erase_svf_filename, erase_svf_filename);
439+
flash_svf(QStringList({svf_filename}));
411440
ui->firmware->setEnabled(true);
412441
ui->Connect->setEnabled(true);
413442
ui->XCPort->setEnabled(true);
414443
}
444+
skip_download:
415445
xcFD = -1;
416446
xc_local_port = false;
417447
if(xcport == "no connection")
@@ -732,7 +762,7 @@ MainWindow::MainWindow(QWidget *parent)
732762
}
733763
}
734764
ahp_xc_set_correlation_order(1);
735-
npackets = ahp_xc_scan_correlations(requests.toVector().data(), requests.count(), &spectrum, &threadsStopped, &percent);
765+
npackets = ahp_xc_scan_autocorrelations(requests.toVector().data(), requests.count(), &spectrum, &threadsStopped, &percent);
736766
if(npackets == 0)
737767
break;
738768
for(int x = 0; x < Lines.count(); x++)

mainwindow.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ class MainWindow : public QMainWindow
256256
}
257257

258258
QString homedir;
259+
QString erase_bsdl_filename;
260+
QString erase_svf_filename;
259261
QString bsdl_filename;
260262
QString svf_filename;
261263
QString dfu_filename;
@@ -273,8 +275,9 @@ class MainWindow : public QMainWindow
273275
bool enable_vlbi {false};
274276
bool has_svf_firmware {false};
275277
bool has_bsdl {false};
278+
bool svf_from_resources(QString json_filename, QString svf_filename, QString bsdl_filename);
276279
QStringList CheckFirmware(QString url, int timeout_ms = 30000);
277-
bool DownloadFirmware(QString url, QString svf, QString bsdl, QSettings *settings, int timeout_ms = 30000);
280+
bool DownloadFirmware(QString url, QString svf, QString bsdl, int timeout_ms = 30000);
278281
QString base64;
279282
int currentVoltage {0};
280283
FILE *f_stdout;

mainwindow.ui

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,16 @@
256256
<height>25</height>
257257
</rect>
258258
</property>
259+
<item>
260+
<property name="text">
261+
<string>Current</string>
262+
</property>
263+
</item>
264+
<item>
265+
<property name="text">
266+
<string>Erase</string>
267+
</property>
268+
</item>
259269
<item>
260270
<property name="text">
261271
<string>xc1</string>

polytope.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ void Polytope::stackCorrelations()
441441
line->resetStopPtr();
442442
line->setLocation();
443443
}
444-
npackets = ahp_xc_scan_correlations(requests.toVector().data(), requests.length(), &spectrum, stop, percent);
444+
npackets = ahp_xc_scan_crosscorrelations(requests.toVector().data(), requests.length(), &spectrum, stop, percent);
445445
if(spectrum != nullptr && npackets > 0)
446446
{
447447
setSpectrumSize(npackets);
@@ -451,7 +451,7 @@ void Polytope::stackCorrelations()
451451
ahp_xc_correlation correlation;
452452
memcpy(&correlation, &spectrum[z].correlations[0], sizeof(ahp_xc_correlation));
453453
for(int o = 0; o < getCorrelationOrder(); o++) {
454-
int lag = correlation.lags[o] * ahp_xc_get_sampletime();
454+
int lag = correlation.lag * ahp_xc_get_sampletime();
455455
if(lag < npackets && lag >= 0)
456456
{
457457
if(getSpectrum()->getElemental()->getMagnitude()[lag] == 0) getSpectrum()->getElemental()->getMagnitude()[lag] = 1.0;

resource.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
<file>xc4.json</file>
1818
<file>xc2.json</file>
1919
<file>xc1.json</file>
20+
<file>Erase.json</file>
2021
</qresource>
2122
</RCC>

xc1.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

xc10.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)