chore(firmware): remove unused/deprecated model labels code (#7717)

This commit is contained in:
philmoz
2026-08-28 12:14:18 +10:00
committed by GitHub
parent 4f6e0223c9
commit 8cbc5f1232
4 changed files with 2 additions and 238 deletions
-43
View File
@@ -937,44 +937,6 @@ int cliTestMemorySpeed()
}
#endif
#if defined(DEBUG_MODELSLIST)
#include "modelslist.h"
using std::list;
int cliTestModelsList()
{
ModelsList modList;
modList.load();
int count = 0;
cliSerialPrint("Starting fetching RF data 100x...");
const uint32_t start = time_get_ms();
const list<ModelsCategory *> &cats = modList.getCategories();
while (1) {
for (list<ModelsCategory *>::const_iterator cat_it = cats.begin();
cat_it != cats.end(); ++cat_it) {
for (ModelsCategory::iterator mod_it = (*cat_it)->begin();
mod_it != (*cat_it)->end(); mod_it++) {
if (!(*mod_it)->fetchRfData()) {
cliSerialPrint("Error while fetching RF data...");
return 0;
}
if (++count >= 100) goto done;
}
}
}
done:
cliSerialPrint("Done fetching %ix RF data: %lu ms", count,
(time_get_ms() - start));
return 0;
}
#endif
#endif // #if defined(COLORLCD)
#if defined(DEBUG)
@@ -994,11 +956,6 @@ int cliTest(const char ** argv)
return cliTestMemorySpeed();
}
#endif
#if defined(DEBUG_MODELSLIST)
else if (!strcmp(argv[1], "modelslist")) {
return cliTestModelsList();
}
#endif
#endif
else {
cliSerialPrint("%s: Invalid argument \"%s\"", argv[0], argv[1]);
-3
View File
@@ -64,9 +64,6 @@ extern FIL g_oLogFile;
#define RADIO_FILENAME "radio.bin"
const char RADIO_SETTINGS_PATH[] = RADIO_PATH PATH_SEPARATOR RADIO_FILENAME;
#define LABELS_FILENAME "labels.yml"
#define MODELS_FILENAME "models.yml"
const char MODELSLIST_YAML_PATH[] = MODELS_PATH PATH_SEPARATOR MODELS_FILENAME;
const char FALLBACK_MODELSLIST_YAML_PATH[] = RADIO_PATH PATH_SEPARATOR MODELS_FILENAME;
const char LABELSLIST_YAML_PATH[] = MODELS_PATH PATH_SEPARATOR LABELS_FILENAME;
const char RADIO_SETTINGS_YAML_PATH[] = RADIO_PATH PATH_SEPARATOR "radio.yml";
const char RADIO_SETTINGS_TMPFILE_YAML_PATH[] = RADIO_PATH PATH_SEPARATOR "radio_new.yml";
+2 -171
View File
@@ -61,14 +61,6 @@ ModelCell::ModelCell(const char *fileName) : valid_rfData(false)
modelFilename[sizeof(modelFilename) - 1] = '\0';
}
ModelCell::ModelCell(const char *fileName, uint8_t len) : valid_rfData(false)
{
if (len > sizeof(modelFilename) - 1) len = sizeof(modelFilename) - 1;
memcpy(modelFilename, fileName, len);
modelFilename[len] = '\0';
}
void ModelCell::setModelName(char *name)
{
strncpy(modelName, name, LEN_MODEL_NAME);
@@ -82,26 +74,6 @@ void ModelCell::setModelName(char *name)
}
}
void ModelCell::setModelName(char *name, uint8_t len)
{
if (len > LEN_MODEL_NAME - 1) len = LEN_MODEL_NAME - 1;
memcpy(modelName, name, len);
modelName[len] = '\0';
if (modelName[0] == '\0') {
char *tmp;
strncpy(modelName, modelFilename, LEN_MODEL_NAME);
tmp = (char *)memchr(modelName, '.', LEN_MODEL_NAME);
if (tmp != nullptr) *tmp = 0;
}
}
void ModelCell::setModelId(uint8_t moduleIdx, uint8_t id)
{
modelId[moduleIdx] = id;
}
void ModelCell::setRfData(ModelHeader *header, ModuleData* modData)
{
for (uint8_t i = 0; i < NUM_MODULES; i++) {
@@ -174,41 +146,6 @@ ModelsVector ModelMap::getModelsByLabel(const std::string &lbl)
return rv;
}
/**
* @brief Returns all models that are in multiple labels (OR function)
*
* @param lbls Labels to search
* @return ModelsVector aka vector<ModelCell*> of all models belonging to a
* label
*/
ModelsVector ModelMap::getModelsByLabels(const LabelsVector &lbls)
{
bool addunlabeled = false;
// Build a list of the requested indexes
std::vector<int> idxvect;
for (const auto &lbl : lbls) {
if (lbl == STR_UNLABELEDMODEL) addunlabeled = true;
int index = getIndexByLabel(lbl);
if (index >= 0) idxvect.push_back(index);
}
ModelsVector rv;
for (auto it = begin(); it != end(); ++it) {
for (auto idx : idxvect) {
if (it->first == idx) rv.push_back(it->second);
}
}
if (addunlabeled) {
ModelsVector unlabeled = getUnlabeledModels();
rv.insert(rv.end(), unlabeled.begin(), unlabeled.end());
}
sortModelsBy(rv, _sortOrder);
return rv;
}
/**
* @brief Returns all models that match the selected labels
*
@@ -1106,99 +1043,18 @@ bool ModelsList::loadYaml()
f_closedir(&moddir);
}
// Check if models.yml exists
// Any files found above that are not listed in the file will be moved into
// /MDOELS/UNUSED and removed from the discovered file hash list
char line[LEN_MODELS_IDX_LINE + 1];
FILINFO fno;
FRESULT result;
bool foundInModels = f_stat(MODELSLIST_YAML_PATH, &fno) == FR_OK;
bool foundInRadio = f_stat(FALLBACK_MODELSLIST_YAML_PATH, &fno) == FR_OK;
if(foundInModels) { // Default to /Models copy
result = f_open(&file, MODELSLIST_YAML_PATH, FA_OPEN_EXISTING | FA_READ);
} else if (foundInRadio) {
result = f_open(&file, FALLBACK_MODELSLIST_YAML_PATH, FA_OPEN_EXISTING | FA_READ);
}
if((foundInModels || foundInRadio) && result == FR_OK) {
// Create /Models/Unused if it doesn't exist
bool moveRequired = false;
DIR unusedFolder;
FRESULT result = f_opendir(&unusedFolder, UNUSED_MODELS_PATH);
if (result != FR_OK) {
if (result == FR_NO_PATH) result = f_mkdir(UNUSED_MODELS_PATH);
if (result != FR_OK) {
TRACE("Unable to create unused models folder");
f_close(&file);
return false;
}
} else f_closedir(&unusedFolder);
YamlParser ymp;
std::vector<std::string> modfiles;
void *ctx = get_modelslist_iter(&modfiles);
ymp.init(get_modelslist_parser_calls(), ctx);
UINT bytes_read = 0;
while (f_read(&file, line, sizeof(line), &bytes_read) == FR_OK) {
if (bytes_read == 0) break;
if (f_eof(&file)) ymp.set_eof();
if (ymp.parse(line, bytes_read) != YamlParser::CONTINUE_PARSING) break;
}
f_close(&file);
// Loop through file hases, move any files found that don't exists to /unused
std::vector<filedat> newFileHash;
for(const auto &fhas: fileHashInfo) {
bool found = false;
for(const auto &file : modfiles) {
if (file == fhas.name) {
TRACE_LABELS("Found file %s in models.yml.. OK!", file);
found = true;
break;
}
}
if(!found) {
moveRequired = true;
TRACE_LABELS("Model %s not in models.yml, moving to /UNUSED", fhas.name.c_str());
// Move model into unused folder.
const char *warning = sdMoveFile(fhas.name.c_str(), MODELS_PATH, fhas.name.c_str(), UNUSED_MODELS_PATH);
if(warning)
POPUP_WARNING(warning);
} else {
newFileHash.push_back(fhas); // File exists, keep it
}
}
if(foundInRadio) {
const char *warning = sdMoveFile(MODELS_FILENAME, RADIO_PATH, MODELS_FILENAME ".old", UNUSED_MODELS_PATH);
if(warning)
POPUP_WARNING(warning);
}
if(foundInModels) { // Will overwrite the copy from /radio if both existed, do last
const char *warning = sdMoveFile(MODELS_FILENAME, MODELS_PATH, MODELS_FILENAME ".old", UNUSED_MODELS_PATH);
if(warning)
POPUP_WARNING(warning);
}
if(moveRequired) {
fileHashInfo = newFileHash; // Update the new file list
std::string s(STR_MODELS_MOVED);
s += "\n";
s += UNUSED_MODELS_PATH;
s += "\n";
s += STR_PRESS_ANY_KEY_TO_SKIP;
POPUP_WARNING(s.c_str());
}
}
#if defined(DEBUG_TIMERS)
DEBUG_TIMER_SAMPLE(debugTimerYamlScan);
TRACE("Lables: Time to scan models folder %luus",
TRACE("Labels: Time to scan models folder %luus",
debugTimers[debugTimerYamlScan].getLast());
#endif
// Scan labels.yml
result = f_open(&file, LABELSLIST_YAML_PATH, FA_OPEN_EXISTING | FA_READ);
if (result == FR_OK) {
char line[32];
YamlParser yp;
void *ctx = get_labelslist_iter();
yp.init(get_labelslist_parser_calls(), ctx);
@@ -1479,31 +1335,6 @@ bool ModelsList::removeModel(ModelCell *model)
return false;
}
/**
* @brief Moves a model in the list for customization of order
*
* @param curindex Index of the model to move
* @param toindex Destination index of the model
* @return true Failure
* @return false Success
*/
bool ModelsList::moveModelTo(unsigned curindex, unsigned toindex)
{
if (curindex == toindex || curindex >= size() || toindex >= size())
return true;
if (curindex < toindex) { // Move forward
std::rotate(rend() - curindex - 1, rend() - curindex, rend() - toindex);
} else { // Move back
std::rotate(begin() + curindex, begin() + curindex + 1,
begin() + toindex + 1);
}
modelslabels.setDirty();
return false;
}
/**
* @brief Checks if a models RF module has a unique id
*
-21
View File
@@ -37,10 +37,6 @@
#include "dataconstants.h"
#include "rtc.h"
// modelXXXXXXX.bin F,FF F,3F,FF\r\n
#define LEN_MODELS_IDX_LINE \
(LEN_MODEL_FILENAME + sizeof(" F,FF F,3F,FF\r\n") - 1)
#define DEFAULT_MODEL_SORT NAME_ASC
struct ModelHeader;
@@ -76,15 +72,11 @@ class ModelCell
SimpleModuleData moduleData[NUM_MODULES];
explicit ModelCell(const char *fileName);
explicit ModelCell(const char *fileName, uint8_t len);
void setModelName(char *name);
void setModelName(char *name, uint8_t len);
void setRfData(ModelHeader *header, ModuleData* moduleData);
void setModelId(uint8_t moduleIdx, uint8_t id);
void setRfModuleData(uint8_t moduleIdx, ModuleData *modData);
bool fetchRfData();
};
typedef std::vector<std::string> LabelsVector;
@@ -109,7 +101,6 @@ class ModelMap : protected std::multimap<uint16_t, ModelCell *>
ModelsVector getUnlabeledModels();
ModelsVector getAllModels();
ModelsVector getModelsByLabel(const std::string &);
ModelsVector getModelsByLabels(const LabelsVector &);
ModelsVector getModelsInLabels(const LabelsVector &lbls);
LabelsVector getLabelsByModel(ModelCell *);
std::map<std::string, bool> getSelectedLabels(ModelCell *);
@@ -126,11 +117,6 @@ class ModelMap : protected std::multimap<uint16_t, ModelCell *>
bool renameLabel(const std::string &from, std::string to,
std::function<void(const char *file, int progress)> progress = nullptr);
std::string getCurrentLabel() { return currentlabel; };
void setCurrentLabel(const std::string &lbl)
{
currentlabel = lbl;
setDirty();
}
std::string getBulletLabelString(ModelCell *, const char *noresults = "");
void setDirty(bool save = false);
void resetDirty() { _isDirty = false; }
@@ -215,14 +201,8 @@ class ModelsList : public ModelsVector
ModelCell *getCurrentModel() const { return currentModel; }
unsigned int getModelsCount() const
{
return std::vector<ModelCell *>::size();
}
ModelCell *addModel(const char *name, bool save = true, ModelCell *copyCell = nullptr);
bool removeModel(ModelCell *model);
bool moveModelTo(unsigned curindex, unsigned toindex);
bool isModelIdUnique(uint8_t moduleIdx, char *warn_buf, size_t warn_buf_len);
uint8_t findNextUnusedModelId(uint8_t moduleIdx);
@@ -239,7 +219,6 @@ class ModelsList : public ModelsVector
FIL file;
bool loadYaml();
bool loadYamlDirScanner();
};
extern ModelsList modelslist;