TODO: support conversions from BIN to YAML.
This commit is contained in:
Raphael Coeffic
2021-11-10 11:06:59 +01:00
parent ce75a1a48d
commit 6c73b5ba0a
5 changed files with 42 additions and 24 deletions
+3 -1
View File
@@ -160,7 +160,9 @@ if(${STORAGE} STREQUAL SDCARD)
set(SRC ${SRC} storage/sdcard_raw.cpp)
add_definitions(-DSDCARD_RAW)
elseif(${STORAGE_FORMAT} STREQUAL YAML)
set(SRC ${SRC} storage/sdcard_yaml.cpp)
# TODO: how do we check if the conversions
# should be done from SD card or EEPROM?
set(SRC ${SRC} storage/sdcard_yaml.cpp storage/sdcard_raw.cpp)
add_definitions(-DSDCARD_YAML)
include(storage/yaml/CMakeLists.txt)
#add_subdirectory(storage/yaml)
@@ -22,7 +22,7 @@
#include "opentx.h"
#include "conversions.h"
#if defined(COLORLCD) && !defined(SDCARD_YAML)
#if defined(COLORLCD)
#include "storage/modelslist.h"
#include "storage/sdcard_common.h"
@@ -99,7 +99,10 @@ void convertRadioData(int version)
char path[256];
getModelPath(path, filename);
error = writeFile(path, (uint8_t *)&g_model, sizeof(g_model));
//TODO: if YAML is used, output to YAML directly
error = writeFileBin(path, (uint8_t *)&g_model, sizeof(g_model));
//TODO: what should be done with this error?
}
+5 -2
View File
@@ -35,8 +35,11 @@
#endif
// opens radio.bin or model file
const char * openFile(const char * fullpath, FIL * file, uint16_t * size, uint8_t * version);
const char * writeFile(const char * fullpath, const uint8_t * data, uint16_t size);
const char* openFileBin(const char* fullpath, FIL* file, uint16_t* size,
uint8_t* version);
const char* writeFileBin(const char* fullpath, const uint8_t* data,
uint16_t size);
void getModelPath(char * path, const char * filename);
+28 -18
View File
@@ -23,9 +23,9 @@
#include "modelslist.h"
#include "conversions/conversions.h"
const char * writeFile(const char * filename, const uint8_t * data, uint16_t size)
const char * writeFileBin(const char * filename, const uint8_t * data, uint16_t size)
{
TRACE("writeFile(%s)", filename);
TRACE("writeFileBin(%s)", filename);
FIL file;
unsigned char buf[8];
@@ -57,22 +57,32 @@ const char * writeFile(const char * filename, const uint8_t * data, uint16_t siz
return NULL;
}
const char * writeModel()
// TODO: move to "common"
const char * writeModelBin()
{
char path[256];
getModelPath(path, g_eeGeneral.currModelFilename);
sdCheckAndCreateDirectory(MODELS_PATH);
return writeFile(path, (uint8_t *)&g_model, sizeof(g_model));
return writeFileBin(path, (uint8_t *)&g_model, sizeof(g_model));
}
const char * openFile(const char * fullpath, FIL * file, uint16_t * size, uint8_t * version)
// TODO: move partly to common
const char * openFile(const char * fullpath, FIL * file)
{
FRESULT result = f_open(file, fullpath, FA_OPEN_EXISTING | FA_READ);
if (result != FR_OK) {
return SDCARD_ERROR(result);
}
return nullptr;
}
const char* openFileBin(const char * fullpath, FIL * file, uint16_t * size, uint8_t * version)
{
const char* err = openFile(fullpath, file);
if (err) return err;
if (f_size(file) < 8) {
f_close(file);
return STR_INCOMPATIBLE;
@@ -81,16 +91,15 @@ const char * openFile(const char * fullpath, FIL * file, uint16_t * size, uint8_
UINT read;
char buf[8];
result = f_read(file, (uint8_t *)buf, sizeof(buf), &read);
FRESULT result = f_read(file, (uint8_t *)buf, sizeof(buf), &read);
if ((result != FR_OK) || (read != sizeof(buf))) {
f_close(file);
return SDCARD_ERROR(result);
}
//TODO: move this code into some checkCompatibleFormat()
*version = (uint8_t)buf[4];
if (*(uint32_t*)&buf[0] != OTX_FOURCC || *version < FIRST_CONV_EEPROM_VER || *version > EEPROM_VER || buf[5] != 'M') {
if (*(uint32_t *)&buf[0] != OTX_FOURCC || *version < FIRST_CONV_EEPROM_VER ||
*version > EEPROM_VER || buf[5] != 'M') {
f_close(file);
return STR_INCOMPATIBLE;
}
@@ -99,7 +108,8 @@ const char * openFile(const char * fullpath, FIL * file, uint16_t * size, uint8_
return nullptr;
}
const char * loadFile(const char * fullpath, uint8_t * data, uint16_t maxsize, uint8_t * version)
static const char *loadFile(const char *fullpath, uint8_t *data,
uint16_t maxsize, uint8_t *version)
{
FIL file;
UINT read;
@@ -107,7 +117,7 @@ const char * loadFile(const char * fullpath, uint8_t * data, uint16_t maxsize, u
TRACE("loadFile(%s)", fullpath);
const char * err = openFile(fullpath, &file, &size, version);
const char * err = openFileBin(fullpath, &file, &size, version);
if (err)
return err;
@@ -122,7 +132,7 @@ const char * loadFile(const char * fullpath, uint8_t * data, uint16_t maxsize, u
return nullptr;
}
const char * readModel(const char * filename, uint8_t * buffer, uint32_t size, uint8_t * version)
const char * readModelBin(const char * filename, uint8_t * buffer, uint32_t size, uint8_t * version)
{
char path[256];
getModelPath(path, filename);
@@ -130,7 +140,7 @@ const char * readModel(const char * filename, uint8_t * buffer, uint32_t size, u
}
const char * loadRadioSettings(const char * path)
const char * loadRadioSettingsBin(const char * path)
{
uint8_t version;
const char * error = loadFile(path, (uint8_t *)&g_eeGeneral, sizeof(g_eeGeneral), &version);
@@ -150,17 +160,17 @@ const char * loadRadioSettings(const char * path)
return nullptr;
}
const char * loadRadioSettings()
const char * loadRadioSettingsBin()
{
return loadRadioSettings(RADIO_SETTINGS_PATH);
return loadRadioSettingsBin(RADIO_SETTINGS_PATH);
}
const char * writeGeneralSettings()
const char * writeGeneralSettingsBin()
{
return writeFile(RADIO_SETTINGS_PATH, (uint8_t *)&g_eeGeneral, sizeof(g_eeGeneral));
return writeFileBin(RADIO_SETTINGS_PATH, (uint8_t *)&g_eeGeneral, sizeof(g_eeGeneral));
}
void storageCreateModelsList()
void storageCreateModelsListBin()
{
FIL file;
+1 -1
View File
@@ -24,6 +24,6 @@
#include "FatFs/ff.h"
const char * openFile(const char * fullpath, FIL* file, uint16_t* size);
//const char * openFileBin(const char * fullpath, FIL* file, uint16_t* size);
#endif