Skip to content

Commit a420f27

Browse files
committed
Added CLI-arguments and more keywords
1 parent 14bd1a7 commit a420f27

File tree

4 files changed

+102
-14
lines changed

4 files changed

+102
-14
lines changed

QCodeEditor/resources/languages/lisp.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,5 +453,11 @@
453453
<name>fw-erase</name>
454454
<name>fw-write</name>
455455
<name>fw-reboot</name>
456+
<name>lbm-erase</name>
457+
<name>lbm-write</name>
458+
<name>lbm-run</name>
459+
<name>qml-erase</name>
460+
<name>qml-write</name>
461+
<name>shutdown-hold</name>
456462
</section>
457463
</root>

main.cpp

Lines changed: 68 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ static void showHelp()
102102
qDebug() << "--eraseLisp : Erase lisp-script.";
103103
qDebug() << "--uploadFirmware [path] : Upload firmware-file from path.";
104104
qDebug() << "--uploadBootloaderBuiltin : Upload bootloader from generic included bootloaders.";
105-
qDebug() << "--createFirmwareForBootloader [fileIn:fileOut] : Generate firmware-file compatible with the bootloader. ";
106105
qDebug() << "--writeFileToSdCard [fileLocal:pathSdcard] : Write file to SD-card.";
106+
qDebug() << "--packFirmware [fileIn:fileOut] : Pack firmware-file for compatibility with the bootloader. ";
107+
qDebug() << "--packLisp [fileIn:fileOut] : Pack lisp-file and the included imports.";
107108
}
108109

109110
#ifdef Q_OS_LINUX
@@ -298,10 +299,12 @@ int main(int argc, char *argv[])
298299
bool eraseLisp = false;
299300
QString firmwarePath = "";
300301
bool uploadBootloaderBuiltin = false;
301-
QString fwForBootloaderIn = "";
302-
QString fwForBootloaderOut = "";
302+
QString fwPackIn = "";
303+
QString fwPackOut = "";
303304
QString fileForSdIn = "";
304305
QString fileForSdOut = "";
306+
QString lispPackIn = "";
307+
QString lispPackOut = "";
305308

306309
// Arguments can be hard-coded in a build like this:
307310
// qmlWindowSize = QSize(400, 800);
@@ -597,13 +600,13 @@ int main(int argc, char *argv[])
597600
}
598601
}
599602

600-
if (str == "--createFirmwareForBootloader") {
603+
if (str == "--writeFileToSdCard") {
601604
if ((i + 1) < args.size()) {
602605
i++;
603606
auto p = args.at(i).split(":");
604607
if (p.size() == 2) {
605-
fwForBootloaderIn = p.at(0);
606-
fwForBootloaderOut = p.at(1);
608+
fileForSdIn = p.at(0);
609+
fileForSdOut = p.at(1);
607610
} else {
608611
qCritical() << "Invalid paths specified";
609612
return 1;
@@ -617,13 +620,33 @@ int main(int argc, char *argv[])
617620
}
618621
}
619622

620-
if (str == "--writeFileToSdCard") {
623+
if (str == "--packFirmware") {
621624
if ((i + 1) < args.size()) {
622625
i++;
623626
auto p = args.at(i).split(":");
624627
if (p.size() == 2) {
625-
fileForSdIn = p.at(0);
626-
fileForSdOut = p.at(1);
628+
fwPackIn = p.at(0);
629+
fwPackOut = p.at(1);
630+
} else {
631+
qCritical() << "Invalid paths specified";
632+
return 1;
633+
}
634+
635+
found = true;
636+
} else {
637+
i++;
638+
qCritical() << "No paths specified";
639+
return 1;
640+
}
641+
}
642+
643+
if (str == "--packLisp") {
644+
if ((i + 1) < args.size()) {
645+
i++;
646+
auto p = args.at(i).split(":");
647+
if (p.size() == 2) {
648+
lispPackIn = p.at(0);
649+
lispPackOut = p.at(1);
627650
} else {
628651
qCritical() << "Invalid paths specified";
629652
return 1;
@@ -675,16 +698,16 @@ int main(int argc, char *argv[])
675698
return 0;
676699
}
677700

678-
if (!fwForBootloaderIn.isEmpty()) {
679-
QFile fIn(fwForBootloaderIn);
701+
if (!fwPackIn.isEmpty()) {
702+
QFile fIn(fwPackIn);
680703
if (!fIn.open(QIODevice::ReadOnly)) {
681-
qWarning() << QString("Could not open %1 for reading.").arg(fwForBootloaderIn);
704+
qWarning() << QString("Could not open %1 for reading.").arg(fwPackIn);
682705
return 1;
683706
}
684707

685-
QFile fOut(fwForBootloaderOut);
708+
QFile fOut(fwPackOut);
686709
if (!fOut.open(QIODevice::WriteOnly)) {
687-
qWarning() << QString("Could not open %1 for writing.").arg(fwForBootloaderOut);
710+
qWarning() << QString("Could not open %1 for writing.").arg(fwPackOut);
688711
return 1;
689712
}
690713

@@ -737,6 +760,37 @@ int main(int argc, char *argv[])
737760
return 0;
738761
}
739762

763+
if (!lispPackIn.isEmpty()) {
764+
QFile fIn(lispPackIn);
765+
if (!fIn.open(QIODevice::ReadOnly)) {
766+
qWarning() << QString("Could not open %1 for reading.").arg(lispPackIn);
767+
return 1;
768+
}
769+
770+
QFile fOut(lispPackOut);
771+
if (!fOut.open(QIODevice::WriteOnly)) {
772+
qWarning() << QString("Could not open %1 for writing.").arg(lispPackOut);
773+
return 1;
774+
}
775+
776+
CodeLoader loader;
777+
QFileInfo fi(fIn);
778+
VByteArray vb = loader.lispPackImports(fIn.readAll(), fi.canonicalPath());
779+
fIn.close();
780+
781+
quint16 crc = Packet::crc16((const unsigned char*)vb.constData(), uint32_t(vb.size()));
782+
VByteArray data;
783+
data.vbAppendUint32(vb.size() - 2);
784+
data.vbAppendUint16(crc);
785+
data.append(vb);
786+
787+
fOut.write(data);
788+
fOut.close();
789+
790+
qDebug() << "Done!";
791+
return 0;
792+
}
793+
740794
if (!pkgArgs.isEmpty()) {
741795
if (pkgArgs.size() < 4) {
742796
qWarning() << "Invalid arguments";

res/Lisp/Examples/lbm_update.lisp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; These files can be generated using the VESC Tool CLI
2+
3+
;(def f (f-open "lbm/test_native.lpkg" "r"))
4+
;(def can-id 26)
5+
6+
(def f (f-open "lbm/test.lpkg" "r"))
7+
(def can-id -1)
8+
9+
(def fsize (f-size f))
10+
11+
(print "erase")
12+
(print (list "Erase res" (lbm-erase can-id)))
13+
14+
(def offset 0)
15+
(loopwhile t {
16+
(var data (f-read f 256))
17+
(if (eq data nil) {
18+
(print "Upload done")
19+
(break)
20+
})
21+
22+
(lbm-write offset data can-id)
23+
(setq offset (+ offset (buflen data)))
24+
(print (list "Progress" (floor (* 100 (/ (to-float offset) fsize)))))
25+
})
26+
27+
(print (list "Run res" (lbm-run 1 can-id)))

res_lisp.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@
4545
<file>res/Lisp/Examples/speed_test_tak_q2.lisp</file>
4646
<file>res/Lisp/Examples/log_vesc_tool.lisp</file>
4747
<file>res/Lisp/Examples/fw_update.lisp</file>
48+
<file>res/Lisp/Examples/lbm_update.lisp</file>
4849
</qresource>
4950
</RCC>

0 commit comments

Comments
 (0)