Properly patch filenames in models.yml & handle missing files
This commit is contained in:
@@ -99,9 +99,13 @@ void convertBinRadioData(const char * path, int version)
|
|||||||
|
|
||||||
const char* error = nullptr;
|
const char* error = nullptr;
|
||||||
for (auto category_ptr : modelslist.getCategories()) {
|
for (auto category_ptr : modelslist.getCategories()) {
|
||||||
for (auto model_ptr : *category_ptr) {
|
|
||||||
|
|
||||||
uint8_t model_version;
|
auto model_it = category_ptr->begin();
|
||||||
|
|
||||||
|
while(model_it != category_ptr->end()) {
|
||||||
|
|
||||||
|
uint8_t model_version = 0;
|
||||||
|
auto* model_ptr = *model_it;
|
||||||
char* filename = model_ptr->modelFilename;
|
char* filename = model_ptr->modelFilename;
|
||||||
|
|
||||||
TRACE("converting '%s' (%d/%d)", filename, converted, to_convert);
|
TRACE("converting '%s' (%d/%d)", filename, converted, to_convert);
|
||||||
@@ -110,19 +114,22 @@ void convertBinRadioData(const char * path, int version)
|
|||||||
// read only the version number (size=0)
|
// read only the version number (size=0)
|
||||||
error = readModelBin(filename, nullptr, 0, &model_version);
|
error = readModelBin(filename, nullptr, 0, &model_version);
|
||||||
if (!error) {
|
if (!error) {
|
||||||
|
|
||||||
// TODO: error handling
|
// TODO: error handling
|
||||||
error = convertBinModelData(filename, model_version);
|
error = convertBinModelData(filename, model_version);
|
||||||
if (error) {
|
++model_it;
|
||||||
// add error counter?
|
|
||||||
continue;
|
} else {
|
||||||
}
|
TRACE("ERROR reading '%s': %s", filename, error);
|
||||||
|
|
||||||
|
// remove that file from the models list
|
||||||
|
++model_it;
|
||||||
|
category_ptr->removeModel(model_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
converted++;
|
converted++;
|
||||||
|
|
||||||
#if defined(SIMU)
|
#if defined(SIMU)
|
||||||
RTOS_WAIT_MS(200);
|
RTOS_WAIT_MS(200);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -136,7 +143,20 @@ void convertBinRadioData(const char * path, int version)
|
|||||||
modelslist.load();
|
modelslist.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* convertBinModelData(const char* filename, int version)
|
void patchFilenameToYaml(char* str)
|
||||||
|
{
|
||||||
|
constexpr unsigned bin_len = sizeof(MODELS_EXT) - 1;
|
||||||
|
constexpr unsigned yml_len = sizeof(YAML_EXT) - 1;
|
||||||
|
|
||||||
|
// patch file extension
|
||||||
|
const char* ext = strrchr(str, '.');
|
||||||
|
if (ext && (strlen(ext) == bin_len) &&
|
||||||
|
!strncmp(ext, STR_MODELS_EXT, bin_len)) {
|
||||||
|
memcpy((void*)ext, (void*)STR_YAML_EXT, yml_len + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* convertBinModelData(char* filename, int version)
|
||||||
{
|
{
|
||||||
TRACE("convertModelData(%s)", filename);
|
TRACE("convertModelData(%s)", filename);
|
||||||
|
|
||||||
@@ -159,6 +179,8 @@ const char* convertBinModelData(const char* filename, int version)
|
|||||||
version = 221;
|
version = 221;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
patchFilenameToYaml(filename);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
// Entry points for converting radio & model data
|
// Entry points for converting radio & model data
|
||||||
void convertBinRadioData(const char * path, int version);
|
void convertBinRadioData(const char * path, int version);
|
||||||
const char* convertBinModelData(const char * path, int version);
|
const char* convertBinModelData(char * filename, int version);
|
||||||
|
|
||||||
bool eeConvert();
|
bool eeConvert();
|
||||||
void eeConvertModel(int id, int version);
|
void eeConvertModel(int id, int version);
|
||||||
|
|||||||
@@ -41,18 +41,7 @@ namespace yaml_conv_220 {
|
|||||||
|
|
||||||
#if defined(STORAGE_MODELSLIST)
|
#if defined(STORAGE_MODELSLIST)
|
||||||
|
|
||||||
void patchFilenameToYaml(char* str)
|
void patchFilenameToYaml(char* str);
|
||||||
{
|
|
||||||
constexpr unsigned bin_len = sizeof(MODELS_EXT) - 1;
|
|
||||||
constexpr unsigned yml_len = sizeof(YAML_EXT) - 1;
|
|
||||||
|
|
||||||
// patch file extension
|
|
||||||
const char* ext = strrchr(str, '.');
|
|
||||||
if (ext && (strlen(ext) == bin_len) &&
|
|
||||||
!strncmp(ext, STR_MODELS_EXT, bin_len)) {
|
|
||||||
memcpy((void*)ext, (void*)STR_YAML_EXT, yml_len + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char* convertData_220_to_221(
|
static const char* convertData_220_to_221(
|
||||||
const char* path, unsigned size, const YamlNode* root_node,
|
const char* path, unsigned size, const YamlNode* root_node,
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ const char * createModel()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char * loadModel(const char * filename, bool alarms)
|
const char * loadModel(char * filename, bool alarms)
|
||||||
{
|
{
|
||||||
uint8_t version;
|
uint8_t version;
|
||||||
preModelLoad();
|
preModelLoad();
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ const char* writeFileYaml(const char* path, const YamlNode* root_node, uint8_t*
|
|||||||
void getModelPath(char * path, const char * filename);
|
void getModelPath(char * path, const char * filename);
|
||||||
|
|
||||||
const char * readModel(const char * filename, uint8_t * buffer, uint32_t size, uint8_t * version);
|
const char * readModel(const char * filename, uint8_t * buffer, uint32_t size, uint8_t * version);
|
||||||
const char * loadModel(const char * filename, bool alarms=true);
|
const char * loadModel(char * filename, bool alarms=true);
|
||||||
const char * createModel();
|
const char * createModel();
|
||||||
const char * writeModel();
|
const char * writeModel();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user