From a420f27ddf6e92e3083a79b9faca556c1d8e8217 Mon Sep 17 00:00:00 2001 From: Benjamin Vedder Date: Wed, 1 Nov 2023 14:26:13 +0100 Subject: [PATCH] Added CLI-arguments and more keywords --- QCodeEditor/resources/languages/lisp.xml | 6 ++ main.cpp | 82 ++++++++++++++++++++---- res/Lisp/Examples/lbm_update.lisp | 27 ++++++++ res_lisp.qrc | 1 + 4 files changed, 102 insertions(+), 14 deletions(-) create mode 100644 res/Lisp/Examples/lbm_update.lisp diff --git a/QCodeEditor/resources/languages/lisp.xml b/QCodeEditor/resources/languages/lisp.xml index 4e6262378..3600f80de 100644 --- a/QCodeEditor/resources/languages/lisp.xml +++ b/QCodeEditor/resources/languages/lisp.xml @@ -453,5 +453,11 @@ fw-erase fw-write fw-reboot +lbm-erase +lbm-write +lbm-run +qml-erase +qml-write +shutdown-hold diff --git a/main.cpp b/main.cpp index d8eabab3f..8bc416bc4 100755 --- a/main.cpp +++ b/main.cpp @@ -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 @@ -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); @@ -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; @@ -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; @@ -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; } @@ -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"; diff --git a/res/Lisp/Examples/lbm_update.lisp b/res/Lisp/Examples/lbm_update.lisp new file mode 100644 index 000000000..b78f4ede9 --- /dev/null +++ b/res/Lisp/Examples/lbm_update.lisp @@ -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))) diff --git a/res_lisp.qrc b/res_lisp.qrc index 728e770fe..c6054a09b 100644 --- a/res_lisp.qrc +++ b/res_lisp.qrc @@ -45,5 +45,6 @@ res/Lisp/Examples/speed_test_tak_q2.lisp res/Lisp/Examples/log_vesc_tool.lisp res/Lisp/Examples/fw_update.lisp + res/Lisp/Examples/lbm_update.lisp