From d69db23e3cf03be25469bb9d92b6758f9546f48a Mon Sep 17 00:00:00 2001 From: Benjamin Vedder Date: Sun, 10 Mar 2024 15:32:28 +0100 Subject: [PATCH] Fixed some bugs around custom configurations --- commands.cpp | 20 +++++++++++++++----- commands.h | 2 +- vescinterface.cpp | 10 +++++----- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/commands.cpp b/commands.cpp index d048f0f9f..05fe59918 100755 --- a/commands.cpp +++ b/commands.cpp @@ -50,7 +50,6 @@ Commands::Commands(QObject *parent) : QObject(parent) mTimeoutDecAdc = 0; mTimeoutDecChuk = 0; mTimeoutPingCan = 0; - mTimeoutCustomConf = 0; mTimeoutBmsVal = 0; mFilePercentage = 0.0; @@ -742,8 +741,12 @@ void Commands::processPacket(QByteArray data) case COMM_GET_CUSTOM_CONFIG: case COMM_GET_CUSTOM_CONFIG_DEFAULT: { - mTimeoutCustomConf = 0; int confInd = vb.vbPopFrontInt8(); + + if (mTimeoutCustomConf.size() > confInd) { + mTimeoutCustomConf[confInd] = 0; + } + emit customConfigRx(confInd, vb); } break; @@ -1994,11 +1997,15 @@ void Commands::customConfigGetChunk(int confInd, int len, int offset) void Commands::customConfigGet(int confInd, bool isDefault) { - if (mTimeoutCustomConf > 0) { + while (mTimeoutCustomConf.size() <= confInd) { + mTimeoutCustomConf.append(0); + } + + if (mTimeoutCustomConf[confInd] > 0) { return; } - mTimeoutCustomConf = mTimeoutCount; + mTimeoutCustomConf[confInd] = mTimeoutCount; VByteArray vb; vb.vbAppendUint8(isDefault ? COMM_GET_CUSTOM_CONFIG_DEFAULT : COMM_GET_CUSTOM_CONFIG); @@ -2272,7 +2279,10 @@ void Commands::timerSlot() qWarning() << "CAN ping timed out"; } } - if (mTimeoutCustomConf > 0) mTimeoutCustomConf--; + for (int i = 0;i < mTimeoutCustomConf.size();i++) { + if (mTimeoutCustomConf.at(i) > 0) mTimeoutCustomConf[i]--; + } + if (mTimeoutBmsVal > 0) mTimeoutBmsVal--; if (mTimeoutStats > 0) mTimeoutStats--; } diff --git a/commands.h b/commands.h index 9cd10444c..54f3b3c24 100644 --- a/commands.h +++ b/commands.h @@ -319,7 +319,7 @@ private slots: int mTimeoutDecAdc; int mTimeoutDecChuk; int mTimeoutPingCan; - int mTimeoutCustomConf; + QVector mTimeoutCustomConf; int mTimeoutBmsVal; int mTimeoutStats; diff --git a/vescinterface.cpp b/vescinterface.cpp index b99a66bec..8f283b013 100755 --- a/vescinterface.cpp +++ b/vescinterface.cpp @@ -3784,13 +3784,13 @@ void VescInterface::fwVersionReceived(FW_RX_PARAMS params) QDir().mkpath(confCacheDir); } + while (!mCustomConfigs.isEmpty()) { + mCustomConfigs.last()->deleteLater(); + mCustomConfigs.removeLast(); + } + // Read custom configs if (!mIgnoreCustomConfigs && params.customConfigNum > 0) { - while (!mCustomConfigs.isEmpty()) { - mCustomConfigs.last()->deleteLater(); - mCustomConfigs.removeLast(); - } - bool readConfigsOk = true; for (int i = 0;i < params.customConfigNum;i++) { QString confCacheFile;