WiP
TODO: support conversions from BIN to YAML.
This commit is contained in:
@@ -160,7 +160,9 @@ if(${STORAGE} STREQUAL SDCARD)
|
|||||||
set(SRC ${SRC} storage/sdcard_raw.cpp)
|
set(SRC ${SRC} storage/sdcard_raw.cpp)
|
||||||
add_definitions(-DSDCARD_RAW)
|
add_definitions(-DSDCARD_RAW)
|
||||||
elseif(${STORAGE_FORMAT} STREQUAL YAML)
|
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)
|
add_definitions(-DSDCARD_YAML)
|
||||||
include(storage/yaml/CMakeLists.txt)
|
include(storage/yaml/CMakeLists.txt)
|
||||||
#add_subdirectory(storage/yaml)
|
#add_subdirectory(storage/yaml)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
#include "conversions.h"
|
#include "conversions.h"
|
||||||
|
|
||||||
#if defined(COLORLCD) && !defined(SDCARD_YAML)
|
#if defined(COLORLCD)
|
||||||
#include "storage/modelslist.h"
|
#include "storage/modelslist.h"
|
||||||
#include "storage/sdcard_common.h"
|
#include "storage/sdcard_common.h"
|
||||||
|
|
||||||
@@ -99,7 +99,10 @@ void convertRadioData(int version)
|
|||||||
|
|
||||||
char path[256];
|
char path[256];
|
||||||
getModelPath(path, filename);
|
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?
|
//TODO: what should be done with this error?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,11 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// opens radio.bin or model file
|
// opens radio.bin or model file
|
||||||
const char * openFile(const char * fullpath, FIL * file, uint16_t * size, uint8_t * version);
|
const char* openFileBin(const char* fullpath, FIL* file, uint16_t* size,
|
||||||
const char * writeFile(const char * fullpath, const uint8_t * data, 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);
|
void getModelPath(char * path, const char * filename);
|
||||||
|
|
||||||
|
|||||||
@@ -23,9 +23,9 @@
|
|||||||
#include "modelslist.h"
|
#include "modelslist.h"
|
||||||
#include "conversions/conversions.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;
|
FIL file;
|
||||||
unsigned char buf[8];
|
unsigned char buf[8];
|
||||||
@@ -57,22 +57,32 @@ const char * writeFile(const char * filename, const uint8_t * data, uint16_t siz
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * writeModel()
|
// TODO: move to "common"
|
||||||
|
const char * writeModelBin()
|
||||||
{
|
{
|
||||||
char path[256];
|
char path[256];
|
||||||
getModelPath(path, g_eeGeneral.currModelFilename);
|
getModelPath(path, g_eeGeneral.currModelFilename);
|
||||||
|
|
||||||
sdCheckAndCreateDirectory(MODELS_PATH);
|
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);
|
FRESULT result = f_open(file, fullpath, FA_OPEN_EXISTING | FA_READ);
|
||||||
if (result != FR_OK) {
|
if (result != FR_OK) {
|
||||||
return SDCARD_ERROR(result);
|
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) {
|
if (f_size(file) < 8) {
|
||||||
f_close(file);
|
f_close(file);
|
||||||
return STR_INCOMPATIBLE;
|
return STR_INCOMPATIBLE;
|
||||||
@@ -81,16 +91,15 @@ const char * openFile(const char * fullpath, FIL * file, uint16_t * size, uint8_
|
|||||||
UINT read;
|
UINT read;
|
||||||
char buf[8];
|
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))) {
|
if ((result != FR_OK) || (read != sizeof(buf))) {
|
||||||
f_close(file);
|
f_close(file);
|
||||||
return SDCARD_ERROR(result);
|
return SDCARD_ERROR(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: move this code into some checkCompatibleFormat()
|
|
||||||
|
|
||||||
*version = (uint8_t)buf[4];
|
*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);
|
f_close(file);
|
||||||
return STR_INCOMPATIBLE;
|
return STR_INCOMPATIBLE;
|
||||||
}
|
}
|
||||||
@@ -99,7 +108,8 @@ const char * openFile(const char * fullpath, FIL * file, uint16_t * size, uint8_
|
|||||||
return nullptr;
|
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;
|
FIL file;
|
||||||
UINT read;
|
UINT read;
|
||||||
@@ -107,7 +117,7 @@ const char * loadFile(const char * fullpath, uint8_t * data, uint16_t maxsize, u
|
|||||||
|
|
||||||
TRACE("loadFile(%s)", fullpath);
|
TRACE("loadFile(%s)", fullpath);
|
||||||
|
|
||||||
const char * err = openFile(fullpath, &file, &size, version);
|
const char * err = openFileBin(fullpath, &file, &size, version);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
@@ -122,7 +132,7 @@ const char * loadFile(const char * fullpath, uint8_t * data, uint16_t maxsize, u
|
|||||||
return nullptr;
|
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];
|
char path[256];
|
||||||
getModelPath(path, filename);
|
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;
|
uint8_t version;
|
||||||
const char * error = loadFile(path, (uint8_t *)&g_eeGeneral, sizeof(g_eeGeneral), &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;
|
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;
|
FIL file;
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,6 @@
|
|||||||
|
|
||||||
#include "FatFs/ff.h"
|
#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
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user