Skip to content

Commit

Permalink
Merge branch 'vedderb:master' into ci
Browse files Browse the repository at this point in the history
  • Loading branch information
darwinbeing authored Nov 1, 2023
2 parents 3b1b76b + a420f27 commit d2c3751
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 14 deletions.
6 changes: 6 additions & 0 deletions QCodeEditor/resources/languages/lisp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -453,5 +453,11 @@
<name>fw-erase</name>
<name>fw-write</name>
<name>fw-reboot</name>
<name>lbm-erase</name>
<name>lbm-write</name>
<name>lbm-run</name>
<name>qml-erase</name>
<name>qml-write</name>
<name>shutdown-hold</name>
</section>
</root>
82 changes: 68 additions & 14 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ static void showHelp()
qDebug() << "--eraseLisp : Erase lisp-script.";
qDebug() << "--uploadFirmware [path] : Upload firmware-file from path.";
qDebug() << "--uploadBootloaderBuiltin : Upload bootloader from generic included bootloaders.";
qDebug() << "--createFirmwareForBootloader [fileIn:fileOut] : Generate firmware-file compatible with the bootloader. ";
qDebug() << "--writeFileToSdCard [fileLocal:pathSdcard] : Write file to SD-card.";
qDebug() << "--packFirmware [fileIn:fileOut] : Pack firmware-file for compatibility with the bootloader. ";
qDebug() << "--packLisp [fileIn:fileOut] : Pack lisp-file and the included imports.";
}

#ifdef Q_OS_LINUX
Expand Down Expand Up @@ -298,10 +299,12 @@ int main(int argc, char *argv[])
bool eraseLisp = false;
QString firmwarePath = "";
bool uploadBootloaderBuiltin = false;
QString fwForBootloaderIn = "";
QString fwForBootloaderOut = "";
QString fwPackIn = "";
QString fwPackOut = "";
QString fileForSdIn = "";
QString fileForSdOut = "";
QString lispPackIn = "";
QString lispPackOut = "";

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

if (str == "--createFirmwareForBootloader") {
if (str == "--writeFileToSdCard") {
if ((i + 1) < args.size()) {
i++;
auto p = args.at(i).split(":");
if (p.size() == 2) {
fwForBootloaderIn = p.at(0);
fwForBootloaderOut = p.at(1);
fileForSdIn = p.at(0);
fileForSdOut = p.at(1);
} else {
qCritical() << "Invalid paths specified";
return 1;
Expand All @@ -617,13 +620,33 @@ int main(int argc, char *argv[])
}
}

if (str == "--writeFileToSdCard") {
if (str == "--packFirmware") {
if ((i + 1) < args.size()) {
i++;
auto p = args.at(i).split(":");
if (p.size() == 2) {
fileForSdIn = p.at(0);
fileForSdOut = p.at(1);
fwPackIn = p.at(0);
fwPackOut = p.at(1);
} else {
qCritical() << "Invalid paths specified";
return 1;
}

found = true;
} else {
i++;
qCritical() << "No paths specified";
return 1;
}
}

if (str == "--packLisp") {
if ((i + 1) < args.size()) {
i++;
auto p = args.at(i).split(":");
if (p.size() == 2) {
lispPackIn = p.at(0);
lispPackOut = p.at(1);
} else {
qCritical() << "Invalid paths specified";
return 1;
Expand Down Expand Up @@ -675,16 +698,16 @@ int main(int argc, char *argv[])
return 0;
}

if (!fwForBootloaderIn.isEmpty()) {
QFile fIn(fwForBootloaderIn);
if (!fwPackIn.isEmpty()) {
QFile fIn(fwPackIn);
if (!fIn.open(QIODevice::ReadOnly)) {
qWarning() << QString("Could not open %1 for reading.").arg(fwForBootloaderIn);
qWarning() << QString("Could not open %1 for reading.").arg(fwPackIn);
return 1;
}

QFile fOut(fwForBootloaderOut);
QFile fOut(fwPackOut);
if (!fOut.open(QIODevice::WriteOnly)) {
qWarning() << QString("Could not open %1 for writing.").arg(fwForBootloaderOut);
qWarning() << QString("Could not open %1 for writing.").arg(fwPackOut);
return 1;
}

Expand Down Expand Up @@ -737,6 +760,37 @@ int main(int argc, char *argv[])
return 0;
}

if (!lispPackIn.isEmpty()) {
QFile fIn(lispPackIn);
if (!fIn.open(QIODevice::ReadOnly)) {
qWarning() << QString("Could not open %1 for reading.").arg(lispPackIn);
return 1;
}

QFile fOut(lispPackOut);
if (!fOut.open(QIODevice::WriteOnly)) {
qWarning() << QString("Could not open %1 for writing.").arg(lispPackOut);
return 1;
}

CodeLoader loader;
QFileInfo fi(fIn);
VByteArray vb = loader.lispPackImports(fIn.readAll(), fi.canonicalPath());
fIn.close();

quint16 crc = Packet::crc16((const unsigned char*)vb.constData(), uint32_t(vb.size()));
VByteArray data;
data.vbAppendUint32(vb.size() - 2);
data.vbAppendUint16(crc);
data.append(vb);

fOut.write(data);
fOut.close();

qDebug() << "Done!";
return 0;
}

if (!pkgArgs.isEmpty()) {
if (pkgArgs.size() < 4) {
qWarning() << "Invalid arguments";
Expand Down
27 changes: 27 additions & 0 deletions res/Lisp/Examples/lbm_update.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
; These files can be generated using the VESC Tool CLI

;(def f (f-open "lbm/test_native.lpkg" "r"))
;(def can-id 26)

(def f (f-open "lbm/test.lpkg" "r"))
(def can-id -1)

(def fsize (f-size f))

(print "erase")
(print (list "Erase res" (lbm-erase can-id)))

(def offset 0)
(loopwhile t {
(var data (f-read f 256))
(if (eq data nil) {
(print "Upload done")
(break)
})

(lbm-write offset data can-id)
(setq offset (+ offset (buflen data)))
(print (list "Progress" (floor (* 100 (/ (to-float offset) fsize)))))
})

(print (list "Run res" (lbm-run 1 can-id)))
1 change: 1 addition & 0 deletions res_lisp.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@
<file>res/Lisp/Examples/speed_test_tak_q2.lisp</file>
<file>res/Lisp/Examples/log_vesc_tool.lisp</file>
<file>res/Lisp/Examples/fw_update.lisp</file>
<file>res/Lisp/Examples/lbm_update.lisp</file>
</qresource>
</RCC>

0 comments on commit d2c3751

Please sign in to comment.