YAML storage (#7071)

YAML storage
This commit is contained in:
Raphael Coeffic
2019-11-12 14:50:05 +01:00
committed by Bertrand Songis
parent bb2ca31dad
commit 8b4d2b698d
69 changed files with 5577 additions and 425 deletions
@@ -316,6 +316,7 @@ void convertModelData_218_to_219(ModelData &model)
#endif
#if defined(PCBHORUS)
#if defined(FIXME) //TODO
memcpy(newModel.screenData, oldModel.screenData,
sizeof(newModel.screenData) +
sizeof(newModel.topbarData));
@@ -342,7 +343,7 @@ void convertModelData_218_to_219(ModelData &model)
ZoneOptionValue & option = zoneData->widgetData.options[0];
option.unsignedValue = convertSource_218_to_219(option.unsignedValue);
}
#endif
#else
newModel.screensType = oldModel.frsky.screensType;
memmove(&newModel.screens, &oldModel.frsky.screens, sizeof(newModel.screens));
@@ -611,7 +611,8 @@ PACK(struct RadioData_v218 {
static inline void check_struct_218()
{
#if defined(PCBHORUS)
CHKSIZE(ModelData_v218, 9380);
// FIXME !!!
CHKSIZE(ModelData_v218, 10664);
#elif defined(PCBX9E)
CHKSIZE(ModelData_v218, 6520);
#elif defined(PCBX9D)
+10
View File
@@ -18,6 +18,9 @@
* GNU General Public License for more details.
*/
#ifndef _EEPROM_COMMON_H_
#define _EEPROM_COMMON_H_
#define EEPROM_MIN_MODEL_SIZE 256
uint16_t eeLoadModelData(uint8_t id);
@@ -36,3 +39,10 @@ void storageClearRadioSettings();
bool storageReadRadioSettings(bool allowFixes = true);
void storageReadCurrentModel();
#if defined(EEPROM_RLC)
#include "eeprom_rlc.h"
#else
#include "eeprom_raw.h"
#endif
#endif
+79
View File
@@ -0,0 +1,79 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "opentx.h"
//#include "eeprom_common.h"
void eepromCheck()
{
}
void storageFormat()
{
}
bool eepromOpen()
{
return true;
}
uint16_t eeLoadModelData(uint8_t index)
{
modelDefault(index);
return sizeof(g_model);
}
bool eeLoadGeneral()
{
generalDefault();
return true;
}
void eeLoadModelName(uint8_t id, char *name)
{
memclear(name, sizeof(g_model.header.name));
}
bool eeModelExists(uint8_t id)
{
return true;
}
void storageCheck(bool immediately)
{
}
void eeLoadModelHeader(uint8_t id, ModelHeader * header)
{
memclear(header, sizeof(ModelHeader));
}
bool eeCopyModel(uint8_t dst, uint8_t src)
{
return true;
}
void eeSwapModels(uint8_t id1, uint8_t id2)
{
}
void eeDeleteModel(uint8_t idx)
{
}
+199 -7
View File
@@ -21,6 +21,11 @@
#include "modelslist.h"
using std::list;
#if defined(SDCARD_YAML)
#include "yaml/yaml_parser.h"
#include "yaml/yaml_modelslist.h"
#endif
ModelsList modelslist;
ModelCell::ModelCell(const char * name):
@@ -29,6 +34,16 @@ ModelCell::ModelCell(const char * name):
strncpy(modelFilename, name, sizeof(modelFilename));
}
ModelCell::ModelCell(const char * name, uint8_t len)
: valid_rfData(false)
{
if (len > sizeof(modelFilename)-1)
len = sizeof(modelFilename)-1;
memcpy(modelFilename, name, len);
modelFilename[len] = '\0';
}
ModelCell::~ModelCell()
{
}
@@ -45,15 +60,132 @@ 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 != NULL)
*tmp = 0;
}
//resetBuffer();
}
void ModelCell::setModelId(uint8_t moduleIdx, uint8_t id)
{
modelId[moduleIdx] = id;
}
// void ModelCell::resetBuffer()
// {
// if (buffer) {
// delete buffer;
// buffer = NULL;
// }
// }
// const BitmapBuffer * ModelCell::getBuffer()
// {
// if (!buffer) {
// loadBitmap();
// }
// return buffer;
// }
// void ModelCell::loadBitmap()
// {
// uint8_t version;
// PACK(struct {
// ModelHeader header;
// TimerData timers[MAX_TIMERS];
// }) partialmodel;
// const char * error = NULL;
// BitmapBuffer * tmp_buffer;
// if (strncmp(modelFilename, g_eeGeneral.currModelFilename, LEN_MODEL_FILENAME) == 0) {
// memcpy(&partialmodel.header, &g_model.header, sizeof(partialmodel));
// }
// else {
// #if !defined (SDCARD_YAML)
// error = readModel(modelFilename, (uint8_t *)&partialmodel.header, sizeof(partialmodel), &version);
// // LEN_BITMAP_NAME has now 4 bytes more
// if (version <= 218) {
// memmove(partialmodel.timers, &(partialmodel.header.bitmap[10]), sizeof(TimerData)*MAX_TIMERS);
// memclear(&(partialmodel.header.bitmap[10]), 4);
// }
// #else
// memset(&partialmodel.header,0,sizeof(partialmodel));
// #endif
// }
// if ((modelName[0] == 0) && ! error)
// setModelName(partialmodel.header.name); // resets buffer!!!
// tmp_buffer = new BitmapBuffer(BMP_RGB565, MODELCELL_WIDTH, MODELCELL_HEIGHT);
// if (tmp_buffer == NULL) {
// return;
// }
// tmp_buffer->clear(TEXT_BGCOLOR);
// if (error) {
// tmp_buffer->drawText(5, 2, "(Invalid Model)", TEXT_COLOR);
// tmp_buffer->drawBitmapPattern(5, 23, LBM_LIBRARY_SLOT, TEXT_COLOR);
// }
// else {
// char timer[LEN_TIMER_STRING];
// tmp_buffer->drawSizedText(5, 2, modelName, /*LEN_MODEL_NAME*/strlen(modelName),
// SMLSIZE|TEXT_COLOR);
// getTimerString(timer, 0);
// for (uint8_t i = 0; i < MAX_TIMERS; i++) {
// if (partialmodel.timers[i].mode > 0 && partialmodel.timers[i].persistent) {
// getTimerString(timer, partialmodel.timers[i].value);
// break;
// }
// }
// tmp_buffer->drawText(101, 40, timer, TEXT_COLOR);
// for (int i=0; i<4; i++) {
// tmp_buffer->drawBitmapPattern(104+i*11, 25, LBM_SCORE0, TITLE_BGCOLOR);
// }
// GET_FILENAME(filename, BITMAPS_PATH, partialmodel.header.bitmap, "");
// const BitmapBuffer * bitmap = BitmapBuffer::load(filename);
// if (bitmap) {
// tmp_buffer->drawScaledBitmap(bitmap, 5, 24, 56, 32);
// delete bitmap;
// }
// else {
// tmp_buffer->drawBitmapPattern(5, 23, LBM_LIBRARY_SLOT, TEXT_COLOR);
// }
// }
// tmp_buffer->drawSolidHorizontalLine(5, 19, 143, LINE_COLOR);
// buffer = tmp_buffer;
// }
void ModelCell::save(FIL* file)
{
#if !defined(SDCARD_YAML)
f_puts(modelFilename, file);
f_putc('\n', file);
#else
f_puts(" - filename: ", file);
f_puts(modelFilename, file);
f_putc('\n', file);
f_puts(" name: ", file);
f_puts(modelName, file);
f_putc('\n', file);
#endif
}
void ModelCell::setRfData(ModelData* model)
@@ -82,6 +214,7 @@ void ModelCell::setRfModuleData(uint8_t moduleIdx, ModuleData* modData)
bool ModelCell::fetchRfData()
{
#if !defined(SDCARD_YAML)
//TODO: use g_model in case fetching data for current model
//
char buf[256];
@@ -126,7 +259,11 @@ bool ModelCell::fetchRfData()
error:
f_close(&file);
return false;
return false;
#else
return false;
#endif
}
ModelsCategory::ModelsCategory(const char * name)
@@ -134,6 +271,15 @@ ModelsCategory::ModelsCategory(const char * name)
strncpy(this->name, name, sizeof(this->name));
}
ModelsCategory::ModelsCategory(const char * name, uint8_t len)
{
if (len > sizeof(this->name)-1)
len = sizeof(this->name)-1;
memcpy(this->name, name, len);
this->name[len] = '\0';
}
ModelsCategory::~ModelsCategory()
{
for (auto * model: *this) {
@@ -143,6 +289,8 @@ ModelsCategory::~ModelsCategory()
ModelCell * ModelsCategory::addModel(const char * name)
{
if (!name) return NULL;
ModelCell * result = new ModelCell(name);
push_back(result);
return result;
@@ -183,10 +331,16 @@ void ModelsCategory::moveModel(ModelCell * model, int8_t step)
void ModelsCategory::save(FIL * file)
{
#if !defined(SDCARD_YAML)
f_puts("[", file);
f_puts(name, file);
f_puts("]", file);
f_putc('\n', file);
#else
f_puts("- name: ", file);
f_puts(name, file);
f_putc('\n', file);
#endif
for (list<ModelCell *>::iterator it = begin(); it != end(); ++it) {
(*it)->save(file);
}
@@ -228,8 +382,15 @@ bool ModelsList::load()
if (loaded)
return true;
#if !defined(SDCARD_YAML)
FRESULT result = f_open(&file, RADIO_MODELSLIST_PATH, FA_OPEN_EXISTING | FA_READ);
#else
FRESULT result = f_open(&file, RADIO_MODELSLIST_YAML_PATH, FA_OPEN_EXISTING | FA_READ);
#endif
if (result == FR_OK) {
#if !defined(SDCARD_YAML)
// TXT reader
while (readNextLine(line, LEN_MODELS_IDX_LINE)) {
int len = strlen(line); // TODO could be returned by readNextLine
if (len > 2 && line[0] == '[' && line[len-1] == ']') {
@@ -248,12 +409,32 @@ bool ModelsList::load()
currentCategory = category;
currentModel = model;
}
//parseModulesData(model, rf_data_str);
//TRACE("model=<%s>, valid_rfData=<%i>",model->modelFilename,model->valid_rfData);
model->fetchRfData();
modelsCount += 1;
}
}
#else
// YAML reader
TRACE("YAML modelslist reader");
YamlParser yp; //TODO: move to re-usable buffer
yp.init(get_modelslist_parser_calls(), get_modelslist_iter());
UINT bytes_read=0;
while (f_read(&file, line, sizeof(line), &bytes_read) == FR_OK) {
// reached EOF?
if (bytes_read == 0)
break;
if (yp.parse(line, bytes_read) != YamlParser::CONTINUE_PARSING)
break;
}
// debug output
//modelslist.dump();
#endif
f_close(&file);
}
@@ -276,12 +457,18 @@ bool ModelsList::load()
void ModelsList::save()
{
#if !defined(SDCARD_YAML)
FRESULT result = f_open(&file, RADIO_MODELSLIST_PATH, FA_CREATE_ALWAYS | FA_WRITE);
#else
FRESULT result = f_open(&file, RADIO_MODELSLIST_YAML_PATH, FA_CREATE_ALWAYS | FA_WRITE);
#endif
if (result != FR_OK) {
return;
}
for (list<ModelsCategory *>::iterator it = categories.begin(); it != categories.end(); ++it) {
for (list<ModelsCategory *>::iterator it = categories.begin();
it != categories.end(); ++it) {
(*it)->save(&file);
}
@@ -317,11 +504,16 @@ bool ModelsList::readNextLine(char * line, int maxlen)
return false;
}
ModelsCategory * ModelsList::createCategory()
ModelsCategory * ModelsList::createCategory(bool save)
{
ModelsCategory * result = new ModelsCategory("Category");
return createCategory("Category", save);
}
ModelsCategory * ModelsList::createCategory(const char* name, bool save)
{
ModelsCategory * result = new ModelsCategory(name);
categories.push_back(result);
save();
if (save) this->save();
return result;
}
+19 -1
View File
@@ -23,7 +23,11 @@
#include <stdint.h>
#include <list>
#include "sdcard.h"
#if !defined(SDCARD_YAML)
#include "sdcard_raw.h"
#endif
#define MODELCELL_WIDTH 172
#define MODELCELL_HEIGHT 59
@@ -48,11 +52,13 @@ class ModelCell
SimpleModuleData moduleData[NUM_MODULES];
explicit ModelCell(const char * name);
explicit ModelCell(const char * name, uint8_t len);
~ModelCell();
void save(FIL* file);
void setModelName(char* name);
void setModelName(char* name, uint8_t len);
void setRfData(ModelData* model);
void setModelId(uint8_t moduleIdx, uint8_t id);
@@ -69,11 +75,13 @@ public:
char name[LEN_MODEL_FILENAME+1];
explicit ModelsCategory(const char * name);
explicit ModelsCategory(const char * name, uint8_t len);
~ModelsCategory();
ModelCell * addModel(const char * name);
void removeModel(ModelCell * model);
void moveModel(ModelCell * model, int8_t step);
void save(FIL * file);
};
@@ -100,6 +108,11 @@ public:
{
return categories;
}
std::list<ModelsCategory *>& getCategories()
{
return categories;
}
void setCurrentCategorie(ModelsCategory * cat);
@@ -115,6 +128,10 @@ public:
return currentModel;
}
void incModelsCount() {
modelsCount++;
}
unsigned int getModelsCount() const
{
return modelsCount;
@@ -122,7 +139,8 @@ public:
bool readNextLine(char * line, int maxlen);
ModelsCategory * createCategory();
ModelsCategory * createCategory(bool save=true);
ModelsCategory * createCategory(const char * name, bool save=true);
void removeCategory(ModelsCategory * category);
ModelCell * addModel(ModelsCategory * category, const char * name);
+1
View File
@@ -19,6 +19,7 @@
*/
#include "opentx.h"
#include "rambackup.h"
namespace Backup {
#define BACKUP
+36
View File
@@ -0,0 +1,36 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _RAMBACKUP_H_
#define _RAMBACKUP_H_
#include "rlc.h"
PACK(struct RamBackup {
uint16_t size;
uint8_t data[4094];
});
extern RamBackup * ramBackup;
void rambackupWrite();
bool rambackupRestore();
#endif
+2
View File
@@ -22,6 +22,8 @@
#include <assert.h>
#include "debug.h"
#include "rlc.h"
#define CHECK_DST_SIZE() \
if (cur-dst >= (int)dstsize) { \
TRACE("RLC encoding size too big"); \
+27
View File
@@ -0,0 +1,27 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _RLC_H_
#define _RLC_H_
unsigned int compress(uint8_t * dst, unsigned int dstsize, const uint8_t * src, unsigned int len);
unsigned int uncompress(uint8_t * dst, unsigned int dstsize, const uint8_t * src, unsigned int len);
#endif
+161
View File
@@ -0,0 +1,161 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "opentx.h"
#include "storage.h"
#include "sdcard_common.h"
#include "modelslist.h"
#include "conversions/conversions.h"
// defined either in sdcard_raw.cpp or sdcard_yaml.cpp
void storageCreateModelsList();
void getModelPath(char * path, const char * filename)
{
strcpy(path, STR_MODELS_PATH);
path[sizeof(MODELS_PATH)-1] = '/';
strcpy(&path[sizeof(MODELS_PATH)], filename);
}
void storageEraseAll(bool warn)
{
TRACE("storageEraseAll");
#if defined(LIBOPENUI)
// the theme has not been loaded before
static_cast<ThemeBase*>(theme)->load();
#endif
generalDefault();
modelDefault(1);
if (warn) {
ALERT(STR_STORAGE_WARNING, STR_BAD_RADIO_DATA, AU_BAD_RADIODATA);
}
RAISE_ALERT(STR_STORAGE_WARNING, STR_STORAGE_FORMAT, NULL, AU_NONE);
storageFormat();
storageDirty(EE_GENERAL|EE_MODEL);
storageCheck(true);
}
void storageFormat()
{
sdCheckAndCreateDirectory(RADIO_PATH);
sdCheckAndCreateDirectory(MODELS_PATH);
storageCreateModelsList();
}
void storageCheck(bool immediately)
{
if (storageDirtyMsk & EE_GENERAL) {
TRACE("eeprom write general");
storageDirtyMsk -= EE_GENERAL;
const char * error = writeGeneralSettings();
if (error) {
TRACE("writeGeneralSettings error=%s", error);
}
}
if (storageDirtyMsk & EE_MODEL) {
TRACE("eeprom write model");
storageDirtyMsk -= EE_MODEL;
const char * error = writeModel();
if (error) {
TRACE("writeModel error=%s", error);
}
}
}
const char * createModel()
{
preModelLoad();
char filename[LEN_MODEL_FILENAME+1];
memset(filename, 0, sizeof(filename));
strcpy(filename, MODEL_FILENAME_PATTERN);
int index = findNextFileIndex(filename, LEN_MODEL_FILENAME, MODELS_PATH);
if (index > 0) {
modelDefault(index);
memcpy(g_eeGeneral.currModelFilename, filename, sizeof(g_eeGeneral.currModelFilename));
storageDirty(EE_GENERAL);
storageDirty(EE_MODEL);
storageCheck(true);
}
postModelLoad(false);
return g_eeGeneral.currModelFilename;
}
const char * loadModel(const char * filename, bool alarms)
{
uint8_t version;
preModelLoad();
const char * error = readModel(filename, (uint8_t *)&g_model, sizeof(g_model), &version);
if (error) {
TRACE("loadModel error=%s", error);
}
if (error) {
modelDefault(0) ;
storageCheck(true);
alarms = false;
}
else if (version < EEPROM_VER) {
convertModelData(version);
}
postModelLoad(alarms);
return error;
}
void storageReadAll()
{
TRACE("storageReadAll");
if (loadRadioSettings() != nullptr) {
storageEraseAll(true);
}
for (uint8_t i = 0; languagePacks[i] != nullptr; i++) {
if (!strncmp(g_eeGeneral.ttsLanguage, languagePacks[i]->id, 2)) {
currentLanguagePackIdx = i;
currentLanguagePack = languagePacks[i];
}
}
if (loadModel(g_eeGeneral.currModelFilename, false) != nullptr) {
sdCheckAndCreateDirectory(MODELS_PATH);
createModel();
}
// Wipe models list in case
// it's being reloaded after USB connection
modelslist.clear();
// and reload the list
modelslist.load();
}
+51
View File
@@ -0,0 +1,51 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _SDCARD_COMMON_H_
#define _SDCARD_COMMON_H_
#include "ff.h"
#define DEFAULT_CATEGORY "Models"
#if defined(SDCARD_RAW)
#define DEFAULT_MODEL_FILENAME "model1.bin"
#define MODEL_FILENAME_PATTERN "model.bin"
#elif defined(SDCARD_YAML)
#define DEFAULT_MODEL_FILENAME "model1.yml"
#define MODEL_FILENAME_PATTERN "model.yml"
#endif
// opens radio.bin or model file
const char * openFile(const char * fullpath, FIL * file, uint16_t * size, uint8_t * version);
void getModelPath(char * path, const char * filename);
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 * createModel();
const char * writeModel();
const char * loadRadioSettings();
const char * writeGeneralSettings();
const char * loadRadioSettings(const char * path);
const char * loadRadioSettings();
#endif // _SDCARD_RAW_H_
+2 -133
View File
@@ -22,13 +22,6 @@
#include "modelslist.h"
#include "conversions/conversions.h"
void getModelPath(char * path, const char * filename)
{
strcpy(path, STR_MODELS_PATH);
path[sizeof(MODELS_PATH)-1] = '/';
strcpy(&path[sizeof(MODELS_PATH)], filename);
}
const char * writeFile(const char * filename, const uint8_t * data, uint16_t size)
{
TRACE("writeFile(%s)", filename);
@@ -91,6 +84,8 @@ const char * openFile(const char * fullpath, FIL * file, uint16_t * size, uint8_
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') {
f_close(file);
@@ -131,32 +126,6 @@ const char * readModel(const char * filename, uint8_t * buffer, uint32_t size, u
return loadFile(path, buffer, size, version);
}
const char * loadModel(const char * filename, bool alarms)
{
uint8_t version;
preModelLoad();
const char * error = readModel(filename, (uint8_t *)&g_model, sizeof(g_model), &version);
if (error) {
TRACE("loadModel error=%s", error);
}
if (error) {
modelDefault(0) ;
storageCheck(true);
alarms = false;
}
#if defined(EEPROM_CONVERSIONS)
else if (version < EEPROM_VER) {
convertModelData(version);
}
#endif
postModelLoad(alarms);
return error;
}
const char * loadRadioSettings(const char * path)
{
@@ -188,55 +157,6 @@ const char * writeGeneralSettings()
return writeFile(RADIO_SETTINGS_PATH, (uint8_t *)&g_eeGeneral, sizeof(g_eeGeneral));
}
void storageCheck(bool immediately)
{
if (storageDirtyMsk & EE_GENERAL) {
TRACE("Storage write general");
storageDirtyMsk -= EE_GENERAL;
const char * error = writeGeneralSettings();
if (error) {
TRACE("writeGeneralSettings error=%s", error);
}
}
if (storageDirtyMsk & EE_MODEL) {
TRACE("Storage write current model");
storageDirtyMsk -= EE_MODEL;
const char * error = writeModel();
if (error) {
TRACE("writeModel error=%s", error);
}
}
}
void storageReadAll()
{
TRACE("storageReadAll");
if (loadRadioSettings() != nullptr) {
storageEraseAll(true);
}
for (uint8_t i = 0; languagePacks[i] != nullptr; i++) {
if (!strncmp(g_eeGeneral.ttsLanguage, languagePacks[i]->id, 2)) {
currentLanguagePackIdx = i;
currentLanguagePack = languagePacks[i];
}
}
if (loadModel(g_eeGeneral.currModelFilename, false) != nullptr) {
sdCheckAndCreateDirectory(MODELS_PATH);
createModel();
}
// Wipe models list in case
// it's being reloaded after USB connection
modelslist.clear();
// and reload the list
modelslist.load();
}
void storageCreateModelsList()
{
FIL file;
@@ -247,54 +167,3 @@ void storageCreateModelsList()
f_close(&file);
}
}
void storageFormat()
{
sdCheckAndCreateDirectory(RADIO_PATH);
sdCheckAndCreateDirectory(MODELS_PATH);
storageCreateModelsList();
}
const char * createModel()
{
preModelLoad();
char filename[LEN_MODEL_FILENAME+1];
memset(filename, 0, sizeof(filename));
strcpy(filename, "model.bin");
unsigned int index = findNextFileIndex(filename, LEN_MODEL_FILENAME, MODELS_PATH);
if (index > 0) {
modelDefault(index);
memcpy(g_eeGeneral.currModelFilename, filename, sizeof(g_eeGeneral.currModelFilename));
storageDirty(EE_GENERAL);
storageDirty(EE_MODEL);
storageCheck(true);
}
postModelLoad(false);
return g_eeGeneral.currModelFilename;
}
void storageEraseAll(bool warn)
{
TRACE("storageEraseAll");
#if defined(LIBOPENUI)
// the theme has not been loaded before
static_cast<ThemeBase*>(theme)->load();
#endif
generalDefault();
modelDefault(1);
if (warn) {
ALERT(STR_STORAGE_WARNING, STR_BAD_RADIO_DATA, AU_BAD_RADIODATA);
}
RAISE_ALERT(STR_STORAGE_WARNING, STR_STORAGE_FORMAT, NULL, AU_NONE);
storageFormat();
storageDirty(EE_GENERAL|EE_MODEL);
storageCheck(true);
}
+3 -43
View File
@@ -1,48 +1,8 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _SDCARD_RAW_H_
#define _SDCARD_RAW_H_
#include "ff.h"
#include "FatFs/ff.h"
#define DEFAULT_CATEGORY "Models"
#define DEFAULT_MODEL_FILENAME "model1.bin"
const char * openFile(const char * fullpath, FIL* file, uint16_t* size);
// opens radio.bin or model file
const char * openFile(const char * fullpath, FIL * file, uint16_t * size, uint8_t * version);
void getModelPath(char * path, const char * filename);
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 * createModel();
const char * loadRadioSettings(const char * path);
const char * loadRadioSettings();
PACK(struct RamBackup {
uint16_t size;
uint8_t data[4094];
});
extern RamBackup * ramBackup;
#endif // _SDCARD_RAW_H_
#endif
+194
View File
@@ -0,0 +1,194 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "opentx.h"
#include "storage.h"
#include "sdcard_common.h"
#include "modelslist.h"
#include "yaml/yaml_tree_walker.h"
#include "yaml/yaml_parser.h"
#include "yaml/yaml_datastructs.h"
const char * readYamlFile(const char* fullpath, const YamlParserCalls* calls, void* parser_ctx)
{
FIL file;
UINT bytes_read;
FRESULT result = f_open(&file, fullpath, FA_OPEN_EXISTING | FA_READ);
if (result != FR_OK) {
return SDCARD_ERROR(result);
}
YamlParser yp; //TODO: move to re-usable buffer
yp.init(calls, parser_ctx);
char buffer[32];
while (f_read(&file, buffer, sizeof(buffer), &bytes_read) == FR_OK) {
// reached EOF?
if (bytes_read == 0)
break;
if (yp.parse(buffer, bytes_read) != YamlParser::CONTINUE_PARSING)
break;
}
f_close(&file);
return NULL;
}
//
// Generic storage interface
//
void storageCreateModelsList()
{
modelslist.clear();
ModelsCategory* cat = modelslist.createCategory(DEFAULT_CATEGORY, false);
cat->addModel(DEFAULT_MODEL_FILENAME);
modelslist.save();
}
//
// SDCARD storage interface
//
const char * loadRadioSettings()
{
// YAML reader
TRACE("YAML radio settings reader");
YamlTreeWalker tree;
tree.reset(get_radiodata_nodes(), (uint8_t*)&g_eeGeneral);
return readYamlFile(RADIO_SETTINGS_YAML_PATH, YamlTreeWalker::get_parser_calls(), &tree);
}
struct yaml_writer_ctx {
FIL* file;
FRESULT result;
};
static bool yaml_writer(void* opaque, const char* str, size_t len)
{
UINT bytes_written;
yaml_writer_ctx* ctx = (yaml_writer_ctx*)opaque;
TRACE_NOCRLF("%.*s",len,str);
ctx->result = f_write(ctx->file, str, len, &bytes_written);
return (ctx->result == FR_OK) && (bytes_written == len);
}
const char * writeGeneralSettings()
{
// YAML reader
TRACE("YAML radio settings writer");
FIL file;
FRESULT result = f_open(&file, RADIO_SETTINGS_YAML_PATH, FA_CREATE_ALWAYS | FA_WRITE);
if (result != FR_OK) {
return SDCARD_ERROR(result);
}
YamlTreeWalker tree;
tree.reset(get_radiodata_nodes(), (uint8_t*)&g_eeGeneral);
yaml_writer_ctx ctx;
ctx.file = &file;
ctx.result = FR_OK;
if (!tree.generate(yaml_writer, &ctx)) {
if (ctx.result != FR_OK) {
f_close(&file);
return SDCARD_ERROR(ctx.result);
}
}
f_close(&file);
return NULL;
}
const char * readModel(const char * filename, uint8_t * buffer, uint32_t size, uint8_t * version)
{
// YAML reader
TRACE("YAML model reader");
char path[256];
getModelPath(path, filename);
YamlTreeWalker tree;
tree.reset(get_modeldata_nodes(), buffer);
// wipe memory before reading YAML
memset(buffer,0,size);
//#if defined(FLIGHT_MODES) && defined(GVARS)
// reset GVars to default values
// Note: taken from opentx.cpp::modelDefault()
//TODO: new func in gvars
for (int p=1; p<MAX_FLIGHT_MODES; p++) {
for (int i=0; i<MAX_GVARS; i++) {
g_model.flightModeData[p].gvars[i] = GVAR_MAX+1;
}
}
//#endif
return readYamlFile(path, YamlTreeWalker::get_parser_calls(), &tree);
}
const char * writeModel()
{
// YAML reader
TRACE("YAML model writer");
char path[256];
getModelPath(path, g_eeGeneral.currModelFilename);
FIL file;
FRESULT result = f_open(&file, path, FA_CREATE_ALWAYS | FA_WRITE);
if (result != FR_OK) {
return SDCARD_ERROR(result);
}
YamlTreeWalker tree;
tree.reset(get_modeldata_nodes(), (uint8_t*)&g_model);
yaml_writer_ctx ctx;
ctx.file = &file;
ctx.result = FR_OK;
if (!tree.generate(yaml_writer, &ctx)) {
if (ctx.result != FR_OK) {
f_close(&file);
return SDCARD_ERROR(ctx.result);
}
}
f_close(&file);
return NULL;
}
+14 -12
View File
@@ -43,32 +43,34 @@ extern tmr10ms_t rambackupDirtyTime10ms;
#define TIME_TO_RAMBACKUP() (rambackupDirtyMsk && (tmr10ms_t)(get_tmr10ms() - rambackupDirtyTime10ms) >= (tmr10ms_t)100)
#endif
//
// Generic storage interface
//
void storageEraseAll(bool warn);
void storageFormat();
void storageReadAll();
void storageDirty(uint8_t msk);
void storageCheck(bool immediately);
//
// Generic storage functions (implemented in storage_common.cpp)
//
void storageDirty(uint8_t msk);
void storageFlushCurrentModel();
void postRadioSettingsLoad();
void preModelLoad();
void postModelLoad(bool alarms);
void checkExternalAntenna();
#if defined(EEPROM_RLC)
#if defined(EEPROM)
#include "eeprom_common.h"
#include "eeprom_rlc.h"
#elif defined(EEPROM)
#include "eeprom_common.h"
#include "eeprom_raw.h"
#elif defined(SDCARD)
#include "sdcard_raw.h"
#endif
#if defined(SDCARD_RAW) || defined(SDCARD_YAML)
#include "sdcard_common.h"
#endif
#if defined(RAMBACKUP)
void rambackupWrite();
bool rambackupRestore();
unsigned int compress(uint8_t * dst, unsigned int dstsize, const uint8_t * src, unsigned int len);
unsigned int uncompress(uint8_t * dst, unsigned int dstsize, const uint8_t * src, unsigned int len);
#include "rambackup.h"
#endif
#endif // _STORAGE_H_
+46
View File
@@ -0,0 +1,46 @@
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set(SRC ${SRC} storage/yaml/yaml_tree_walker.cpp
storage/yaml/yaml_parser.cpp
storage/yaml/yaml_bits.cpp
storage/yaml/yaml_modelslist.cpp
storage/yaml/yaml_datastructs.cpp)
if(PCB STREQUAL X12S)
set(YAML_GEN_OUTPUT storage/yaml/yaml_datastructs_x12s.cpp)
elseif(PCB STREQUAL X10)
set(YAML_GEN_OUTPUT storage/yaml/yaml_datastructs_x10.cpp)
else()
message(FATAL_ERROR "PCB '${PCB}' is not supported by YAML storage")
endif()
set(YAML_GEN ${RADIO_DIRECTORY}/util/generate_yaml.py)
set(YAML_GEN_TEMPLATE ${RADIO_DIRECTORY}/util/yaml_parser.tmpl)
SET(YAML_NODES "\"RadioData,ModelData\"")
set(YAML_GEN_ARGS myeeprom.h ${YAML_GEN_TEMPLATE} ${YAML_NODES} -DYAML_GENERATOR)
get_property(flags DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY COMPILE_DEFINITIONS)
foreach(flag ${flags})
#message(STATUS "dir='${dir}'")
set(YAML_GEN_ARGS ${YAML_GEN_ARGS} -D${flag})
endforeach()
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
foreach(dir ${dirs})
#message(STATUS "dir='${dir}'")
set(YAML_GEN_ARGS ${YAML_GEN_ARGS} -I${dir})
endforeach()
set(YAML_GEN_ARGS ${YAML_GEN_ARGS} -DRTOS_COOS -Wno-inconsistent-missing-override)
#message(STATUS "YAML_GEN_ARGS=${YAML_GEN_ARGS}")
add_custom_target(yaml_data
WORKING_DIRECTORY ${RADIO_DIRECTORY}/src
COMMAND ${PYTHON_EXECUTABLE} ${YAML_GEN} ${YAML_GEN_ARGS} > ${YAML_GEN_OUTPUT}
DEPENDS ${RADIO_DIRECTORY}/src/datastructs.h
${RADIO_DIRECTORY}/src/dataconstants.h
${RADIO_DIRECTORY}/src/myeeprom.h
${RADIO_DIRECTORY}/util/generate_yaml.py
)
+137
View File
@@ -0,0 +1,137 @@
#include <stdio.h>
#include "yaml_bits.h"
#include "yaml_parser.h"
#define MASK_LOWER(bits) ((1 << (bits)) - 1)
#define MASK_UPPER(bits) (0xFF << bits)
void yaml_put_bits(uint8_t* dst, uint32_t i, uint32_t bit_ofs, uint32_t bits)
{
i &= ((1UL << bits) - 1);
if (bit_ofs) {
*dst &= MASK_LOWER(bit_ofs);
*(dst++) |= (i << bit_ofs) & 0xFF;
if (bits <= 8 - bit_ofs)
return;
bits -= 8 - bit_ofs;
i = i >> (8 - bit_ofs);
}
while(bits >= 8) {
*(dst++) = i & 0xFF;
bits -= 8;
i = i >> 8;
}
if (bits) {
uint8_t mask = MASK_UPPER(bits);
*dst &= mask;
*dst |= i & ~mask;
}
}
uint32_t yaml_get_bits(uint8_t* src, uint32_t bit_ofs, uint32_t bits)
{
uint32_t i = 0;
uint32_t bit_shift = 0;
if (bit_ofs) {
i = (*(src++) & MASK_UPPER(bit_ofs)) >> bit_ofs;
if (bits <= 8 - bit_ofs) {
i &= MASK_LOWER(bits);
return i;
}
bit_shift = 8 - bit_ofs;
bits -= bit_shift;
}
while(bits >= 8) {
i |= (uint32_t)*(src++) << bit_shift;
bits -= 8;
bit_shift += 8;
}
if (bits) {
i |= ((uint32_t)*src & MASK_LOWER(bits)) << bit_shift;
}
return i;
}
bool yaml_is_zero(uint8_t* data, uint32_t bitoffs, uint32_t bits)
{
return !yaml_get_bits(data + (bitoffs>>3UL), bitoffs & 0x7, bits);
}
int32_t yaml_str2int(const char* val, uint8_t val_len)
{
bool neg = false;
int i_val = 0;
for(uint8_t i=0; i < val_len; i++) {
if (val[i] == '-')
neg = true;
else if (val[i] >= '0' && val[i] <= '9') {
i_val = i_val * 10 + (val[i] - '0');
}
}
return neg ? -i_val : i_val;
}
uint32_t yaml_str2uint(const char* val, uint8_t val_len)
{
uint32_t i_val = 0;
for(uint8_t i=0; i < val_len; i++) {
if (val[i] >= '0' && val[i] <= '9') {
i_val = i_val * 10 + (val[i] - '0');
}
}
return i_val;
}
static char int2str_buffer[MAX_STR] = {0};
static const char _int2str_lookup[] = { '0', '1', '2', '3', '4', '5', '6' , '7', '8', '9' };
char* yaml_unsigned2str(uint32_t i)
{
char* c = &(int2str_buffer[MAX_STR-2]);
do {
*(c--) = _int2str_lookup[i % 10];
i = i / 10;
} while((c > int2str_buffer) && i);
return (c + 1);
}
char* yaml_signed2str(int32_t i)
{
if (i < 0) {
char* c = yaml_unsigned2str(-i);
*(--c) = '-';
return c;
}
return yaml_unsigned2str((uint32_t)i);
}
int32_t yaml_to_signed(uint32_t i, uint32_t bits)
{
if (i & (1 << (bits-1))) {
i |= 0xFFFFFFFF << bits;
}
return i;
}
+20
View File
@@ -0,0 +1,20 @@
#ifndef _yaml_bits_h_
#define _yaml_bits_h_
#include <stdint.h>
void yaml_put_bits(uint8_t* dst, uint32_t i, uint32_t bit_ofs, uint32_t bits);
uint32_t yaml_get_bits(uint8_t* src, uint32_t bit_ofs, uint32_t bits);
// assumes bits is a multiple of 8
bool yaml_is_zero(uint8_t* data, uint32_t bitoffs, uint32_t bits);
int32_t yaml_str2int(const char* val, uint8_t val_len);
uint32_t yaml_str2uint(const char* val, uint8_t val_len);
char* yaml_unsigned2str(uint32_t i);
char* yaml_signed2str(int32_t i);
int32_t yaml_to_signed(uint32_t i, uint32_t bits);
#endif
@@ -0,0 +1,13 @@
#include "opentx.h"
#include "yaml_node.h"
#include "yaml_datastructs_funcs.cpp"
#if defined(PCBX10)
#include "yaml_datastructs_x10.cpp"
#elif defined(PCBX12S)
#include "yaml_datastructs_x12s.cpp"
#else
#error "Board not supported by YAML storage"
#endif
@@ -0,0 +1,9 @@
#ifndef _YAML_DATASTRUCTS_H_
#define _YAML_DATASTRUCTS_H_
struct YamlNode;
const YamlNode* get_radiodata_nodes();
const YamlNode* get_modeldata_nodes();
#endif
@@ -0,0 +1,361 @@
#include "opentx.h"
#include "yaml_bits.h"
#include "yaml_tree_walker.h"
#define GVAR_SMALL 128
static uint32_t in_read_weight(const YamlNode* node, const char* val, uint8_t val_len)
{
if ((val_len == 4)
&& (val[0] == '-')
&& (val[1] == 'G')
&& (val[2] == 'V')
&& (val[3] >= '1')
&& (val[3] <= '9')) {
TRACE("%.*s -> %i\n", val_len, val, GVAR_SMALL - (val[3] - '0'));
return GVAR_SMALL - (val[3] - '0'); // -GVx => 128 - x
}
if ((val_len == 3)
&& (val[0] == 'G')
&& (val[1] == 'V')
&& (val[2] >= '1')
&& (val[2] <= '9')) {
TRACE("%.*s -> %i\n", val_len, val, -GVAR_SMALL + (val[2] - '1'));
return -GVAR_SMALL + (val[2] - '1'); // GVx => -128 + (x-1)
}
return (uint32_t)yaml_str2int(val, val_len);
}
static bool in_write_weight(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque)
{
int32_t sval = yaml_to_signed(val,node->size);
if (sval > GVAR_SMALL-11 && sval < GVAR_SMALL-1) {
char n = GVAR_SMALL - sval + '0';
return wf(opaque, "-GV", 3) && wf(opaque, &n, 1);
}
else if (sval < -GVAR_SMALL+11 && sval > -GVAR_SMALL+1) {
char n = val - GVAR_SMALL + '1';
return wf(opaque, "GV", 2) && wf(opaque, &n, 1);
}
char* s = yaml_signed2str(sval);
return wf(opaque, s, strlen(s));
}
extern const struct YamlIdStr enum_MixSources[];
static uint32_t r_mixSrcRaw(const YamlNode* node, const char* val, uint8_t val_len)
{
if (val_len > 0 && val[0] == 'I') {
return yaml_str2uint(val+1, val_len-1) + MIXSRC_FIRST_INPUT;
}
return yaml_parse_enum(enum_MixSources, val, val_len);
}
static bool w_mixSrcRaw(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque)
{
const char* str = nullptr;
if (val >= MIXSRC_FIRST_INPUT
&& val <= MIXSRC_LAST_INPUT) {
if (!wf(opaque, "I", 1))
return false;
str = yaml_unsigned2str(val - MIXSRC_FIRST_INPUT);
}
else {
str = yaml_output_enum(val, enum_MixSources);
}
if (str) {
return wf(opaque, str, strlen(str));
}
return true;
}
static uint32_t r_vbat_min(const YamlNode* node, const char* val, uint8_t val_len)
{
int32_t v = yaml_str2int(val, val_len);
return (uint32_t)(v - 90);
}
static bool w_vbat_min(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque)
{
char* s = yaml_signed2str(yaml_to_signed(val,node->size) + 90);
return wf(opaque, s, strlen(s));
}
static uint32_t r_vbat_max(const YamlNode* node, const char* val, uint8_t val_len)
{
int32_t v = yaml_str2int(val, val_len);
return (uint32_t)(v - 120);
}
static bool w_vbat_max(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque)
{
char* s = yaml_signed2str(yaml_to_signed(val,node->size) + 120);
return wf(opaque, s, strlen(s));
}
static uint8_t select_zov(uint8_t* data, uint32_t bitoffs)
{
data += bitoffs >> 3UL;
data -= sizeof(ZoneOptionValueEnum);
ZoneOptionValueEnum* p_zovt = (ZoneOptionValueEnum*)data;
return *p_zovt;
}
static uint8_t select_mod_type(uint8_t* data, uint32_t bitoffs)
{
data += bitoffs >> 3UL;
data -= offsetof(ModuleData, ppm);
switch(((ModuleData*)data)->type) {
case MODULE_TYPE_NONE:
case MODULE_TYPE_PPM:
case MODULE_TYPE_DSM2:
case MODULE_TYPE_CROSSFIRE:
return 1;
case MODULE_TYPE_MULTIMODULE:
return 2;
case MODULE_TYPE_XJT_PXX1:
case MODULE_TYPE_R9M_PXX1:
case MODULE_TYPE_R9M_LITE_PXX1:
case MODULE_TYPE_R9M_LITE_PRO_PXX1:
return 3;
case MODULE_TYPE_SBUS:
return 4;
case MODULE_TYPE_ISRM_PXX2:
case MODULE_TYPE_R9M_PXX2:
case MODULE_TYPE_R9M_LITE_PXX2:
case MODULE_TYPE_R9M_LITE_PRO_PXX2:
case MODULE_TYPE_XJT_LITE_PXX2:
return 5;
}
return 0;
}
static uint8_t select_custom_fn(uint8_t* data, uint32_t bitoffs)
{
// always use 'all'
return 1;
}
static uint8_t select_script_input(uint8_t* data, uint32_t bitoffs)
{
// always use 'value'
return 0;
}
static uint8_t select_id1(uint8_t* data, uint32_t bitoffs)
{
// always use 'id'
return 0;
}
static uint8_t select_id2(uint8_t* data, uint32_t bitoffs)
{
// always use 'instance'
return 0;
}
static uint8_t select_sensor_cfg(uint8_t* data, uint32_t bitoffs)
{
// always use 'param'
return 5;
}
static uint32_t sw_read(const char* val, uint8_t val_len)
{
return yaml_parse_enum(enum_MixSources, val, val_len) - MIXSRC_FIRST_SWITCH;
}
static bool sw_write(uint32_t idx, yaml_writer_func wf, void* opaque)
{
const char* str = yaml_output_enum(idx + MIXSRC_FIRST_SWITCH, enum_MixSources);
return wf(opaque, str, strlen(str));
}
static const struct YamlIdStr enum_SwitchConfig[] = {
{ SWITCH_NONE, "none" },
{ SWITCH_TOGGLE, "toggle" },
{ SWITCH_2POS, "2pos" },
{ SWITCH_3POS, "3pos" },
{ 0, NULL }
};
static const struct YamlNode struct_switchConfig[] = {
YAML_IDX_CUST( "sw", sw_read, sw_write ),
YAML_ENUM( "type", 2, enum_SwitchConfig),
YAML_END
};
static uint32_t pot_read(const char* val, uint8_t val_len)
{
return yaml_parse_enum(enum_MixSources, val, val_len) - MIXSRC_FIRST_POT;
}
static bool pot_write(uint32_t idx, yaml_writer_func wf, void* opaque)
{
const char* str = yaml_output_enum(idx + MIXSRC_FIRST_POT, enum_MixSources);
return wf(opaque, str, strlen(str));
}
static const struct YamlIdStr enum_PotConfig[] = {
{ POT_NONE, "none" },
{ POT_WITH_DETENT, "with_detent" },
{ POT_MULTIPOS_SWITCH, "multipos_switch" },
{ POT_WITHOUT_DETENT, "without_detent" },
{ 0, NULL }
};
static const struct YamlNode struct_potConfig[] = {
YAML_IDX_CUST( "pot", pot_read, pot_write ),
YAML_ENUM( "type", 2, enum_PotConfig),
YAML_END
};
static uint32_t slider_read(const char* val, uint8_t val_len)
{
return yaml_parse_enum(enum_MixSources, val, val_len) - MIXSRC_FIRST_SLIDER;
}
static bool slider_write(uint32_t idx, yaml_writer_func wf, void* opaque)
{
const char* str = yaml_output_enum(idx + MIXSRC_FIRST_SLIDER, enum_MixSources);
return wf(opaque, str, strlen(str));
}
static const struct YamlIdStr enum_SliderConfig[] = {
{ SLIDER_NONE, "none" },
{ SLIDER_WITH_DETENT, "with_detent" },
{ 0, NULL }
};
static const struct YamlNode struct_sliderConfig[] = {
YAML_IDX_CUST( "sl", slider_read, slider_write ),
YAML_ENUM( "type", 1, enum_SliderConfig),
YAML_END
};
extern const struct YamlIdStr enum_SwitchSources[];
static uint32_t r_swtchSrc(const YamlNode* node, const char* val, uint8_t val_len)
{
int32_t ival=0;
bool neg = false;
if (val_len > 0 && val[0] == '!') {
neg = true;
val++;
val_len--;
}
if (val_len > 3
&& val[0] == '6'
&& val[1] == 'P'
&& (val[2] >= '0' && val[2] <= '9')
&& (val[3] >= '0' && val[3] < (XPOTS_MULTIPOS_COUNT + '0'))) {
ival = (val[2] - '0') * XPOTS_MULTIPOS_COUNT + (val[3] - '0')
+ SWSRC_FIRST_MULTIPOS_SWITCH;
}
else if (val_len >= 2
&& val[0] == 'L'
&& (val[1] >= '0' && val[1] <= '9')) {
ival = SWSRC_FIRST_LOGICAL_SWITCH + yaml_str2int(val+1, val_len-1) - 1;
}
//TODO: Flight modes ('FM[0-9]')
//TODO: Sensors ('Sensor[0-9]')
else {
ival = yaml_parse_enum(enum_SwitchSources, val, val_len);
}
return neg ? -ival : ival;
}
static bool w_swtchSrc(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque)
{
int32_t sval = yaml_to_signed(val, node->size);
if (sval < 0) {
wf(opaque, "!", 1);
sval = abs(sval);
}
const char* str = NULL;
if (sval >= SWSRC_FIRST_MULTIPOS_SWITCH
&& sval <= SWSRC_LAST_MULTIPOS_SWITCH) {
wf(opaque, "6P", 2);
// pot #: start with 6P1
sval -= SWSRC_FIRST_MULTIPOS_SWITCH;
str = yaml_unsigned2str(sval / XPOTS_MULTIPOS_COUNT);
wf(opaque,str, strlen(str));
// position
str = yaml_unsigned2str(sval % XPOTS_MULTIPOS_COUNT);
return wf(opaque,str, strlen(str));
}
else if (sval >= SWSRC_FIRST_LOGICAL_SWITCH
&& sval <= SWSRC_LAST_LOGICAL_SWITCH) {
wf(opaque, "L", 1);
str = yaml_unsigned2str(sval - SWSRC_FIRST_LOGICAL_SWITCH + 1);
return wf(opaque,str, strlen(str));
}
else if (sval >= SWSRC_FIRST_FLIGHT_MODE
&& sval <= SWSRC_LAST_FLIGHT_MODE) {
//TODO
return true;
}
else if (sval >= SWSRC_FIRST_SENSOR
&& sval <= SWSRC_LAST_SENSOR) {
//TODO
return true;
}
str = yaml_output_enum(sval, enum_SwitchSources);
return wf(opaque, str, strlen(str));
}
static bool cfn_is_active(uint8_t* data, uint32_t bitoffs)
{
data += bitoffs >> 3UL;
return ((CustomFunctionData*)data)->swtch;
}
static bool gvar_is_active(uint8_t* data, uint32_t bitoffs)
{
gvar_t* gvar = (gvar_t*)(data + (bitoffs>>3UL));
return *gvar != GVAR_MAX+1;
}
static bool fmd_is_active(uint8_t* data, uint32_t bitoffs)
{
uint32_t data_ofs = bitoffs >> 3UL;
if (data_ofs == offsetof(ModelData, flightModeData)) {
return !yaml_is_zero(data, bitoffs, sizeof(FlightModeData)*8);
}
bool is_active = !yaml_is_zero(data, bitoffs,
(sizeof(FlightModeData)
- sizeof(FlightModeData::gvars))*8);
FlightModeData* fmd = (FlightModeData*)(data + data_ofs);
for (uint8_t i=0; i<MAX_GVARS; i++) {
is_active |= fmd->gvars[i] != GVAR_MAX+1;
}
return is_active;
}
@@ -0,0 +1,770 @@
// generated by generate_yaml.py
//
// Enums first
//
const struct YamlIdStr enum_Functions[] = {
{ FUNC_OVERRIDE_CHANNEL, "OVERRIDE_CHANNEL" },
{ FUNC_TRAINER, "TRAINER" },
{ FUNC_INSTANT_TRIM, "INSTANT_TRIM" },
{ FUNC_RESET, "RESET" },
{ FUNC_SET_TIMER, "SET_TIMER" },
{ FUNC_ADJUST_GVAR, "ADJUST_GVAR" },
{ FUNC_VOLUME, "VOLUME" },
{ FUNC_SET_FAILSAFE, "SET_FAILSAFE" },
{ FUNC_RANGECHECK, "RANGECHECK" },
{ FUNC_BIND, "BIND" },
{ FUNC_FIRST_WITHOUT_ENABLE, "FIRST_WITHOUT_ENABLE" },
{ FUNC_PLAY_SOUND, "PLAY_SOUND" },
{ FUNC_PLAY_TRACK, "PLAY_TRACK" },
{ FUNC_PLAY_VALUE, "PLAY_VALUE" },
{ FUNC_RESERVE4, "RESERVE4" },
{ FUNC_PLAY_SCRIPT, "PLAY_SCRIPT" },
{ FUNC_RESERVE5, "RESERVE5" },
{ FUNC_BACKGND_MUSIC, "BACKGND_MUSIC" },
{ FUNC_BACKGND_MUSIC_PAUSE, "BACKGND_MUSIC_PAUSE" },
{ FUNC_VARIO, "VARIO" },
{ FUNC_HAPTIC, "HAPTIC" },
{ FUNC_LOGS, "LOGS" },
{ FUNC_BACKLIGHT, "BACKLIGHT" },
{ FUNC_SCREENSHOT, "SCREENSHOT" },
{ FUNC_MAX, "MAX" },
{ 0, NULL }
};
const struct YamlIdStr enum_ZoneOptionValueEnum[] = {
{ ZOV_Unsigned, "Unsigned" },
{ ZOV_Signed, "Signed" },
{ ZOV_Bool, "Bool" },
{ ZOV_String, "String" },
{ 0, NULL }
};
const struct YamlIdStr enum_MixSources[] = {
{ MIXSRC_NONE, "NONE" },
{ MIXSRC_Rud, "Rud" },
{ MIXSRC_Ele, "Ele" },
{ MIXSRC_Thr, "Thr" },
{ MIXSRC_Ail, "Ail" },
{ MIXSRC_S1, "S1" },
{ MIXSRC_6POS, "6POS" },
{ MIXSRC_S2, "S2" },
{ MIXSRC_EXT1, "EXT1" },
{ MIXSRC_EXT2, "EXT2" },
{ MIXSRC_LS, "LS" },
{ MIXSRC_RS, "RS" },
{ MIXSRC_MOUSE1, "MOUSE1" },
{ MIXSRC_MOUSE2, "MOUSE2" },
{ MIXSRC_MAX, "MAX" },
{ MIXSRC_CYC1, "CYC1" },
{ MIXSRC_CYC2, "CYC2" },
{ MIXSRC_CYC3, "CYC3" },
{ MIXSRC_TrimRud, "TrimRud" },
{ MIXSRC_TrimEle, "TrimEle" },
{ MIXSRC_TrimThr, "TrimThr" },
{ MIXSRC_TrimAil, "TrimAil" },
{ MIXSRC_TrimT5, "TrimT5" },
{ MIXSRC_TrimT6, "TrimT6" },
{ MIXSRC_SA, "SA" },
{ MIXSRC_SB, "SB" },
{ MIXSRC_SC, "SC" },
{ MIXSRC_SD, "SD" },
{ MIXSRC_SE, "SE" },
{ MIXSRC_SF, "SF" },
{ MIXSRC_SG, "SG" },
{ MIXSRC_SH, "SH" },
{ MIXSRC_SI, "SI" },
{ MIXSRC_SJ, "SJ" },
{ MIXSRC_SW1, "SW1" },
{ MIXSRC_CH1, "CH1" },
{ MIXSRC_CH2, "CH2" },
{ MIXSRC_CH3, "CH3" },
{ MIXSRC_CH4, "CH4" },
{ MIXSRC_CH5, "CH5" },
{ MIXSRC_CH6, "CH6" },
{ MIXSRC_CH7, "CH7" },
{ MIXSRC_CH8, "CH8" },
{ MIXSRC_CH9, "CH9" },
{ MIXSRC_CH10, "CH10" },
{ MIXSRC_CH11, "CH11" },
{ MIXSRC_CH12, "CH12" },
{ MIXSRC_CH13, "CH13" },
{ MIXSRC_CH14, "CH14" },
{ MIXSRC_CH15, "CH15" },
{ MIXSRC_CH16, "CH16" },
{ MIXSRC_GVAR1, "GVAR1" },
{ MIXSRC_TX_VOLTAGE, "TX_VOLTAGE" },
{ MIXSRC_TX_TIME, "TX_TIME" },
{ MIXSRC_TIMER1, "TIMER1" },
{ MIXSRC_TIMER2, "TIMER2" },
{ MIXSRC_TIMER3, "TIMER3" },
{ 0, NULL }
};
const struct YamlIdStr enum_LogicalSwitchesFunctions[] = {
{ LS_FUNC_NONE, "FUNC_NONE" },
{ LS_FUNC_VEQUAL, "FUNC_VEQUAL" },
{ LS_FUNC_VALMOSTEQUAL, "FUNC_VALMOSTEQUAL" },
{ LS_FUNC_VPOS, "FUNC_VPOS" },
{ LS_FUNC_VNEG, "FUNC_VNEG" },
{ LS_FUNC_RANGE, "FUNC_RANGE" },
{ LS_FUNC_APOS, "FUNC_APOS" },
{ LS_FUNC_ANEG, "FUNC_ANEG" },
{ LS_FUNC_AND, "FUNC_AND" },
{ LS_FUNC_OR, "FUNC_OR" },
{ LS_FUNC_XOR, "FUNC_XOR" },
{ LS_FUNC_EDGE, "FUNC_EDGE" },
{ LS_FUNC_EQUAL, "FUNC_EQUAL" },
{ LS_FUNC_GREATER, "FUNC_GREATER" },
{ LS_FUNC_LESS, "FUNC_LESS" },
{ LS_FUNC_DIFFEGREATER, "FUNC_DIFFEGREATER" },
{ LS_FUNC_ADIFFEGREATER, "FUNC_ADIFFEGREATER" },
{ LS_FUNC_TIMER, "FUNC_TIMER" },
{ LS_FUNC_STICKY, "FUNC_STICKY" },
{ LS_FUNC_COUNT, "FUNC_COUNT" },
{ LS_FUNC_MAX, "FUNC_MAX" },
{ 0, NULL }
};
const struct YamlIdStr enum_SwitchSources[] = {
{ SWSRC_NONE, "NONE" },
{ SWSRC_SA0, "SA0" },
{ SWSRC_SA1, "SA1" },
{ SWSRC_SA2, "SA2" },
{ SWSRC_SB0, "SB0" },
{ SWSRC_SB1, "SB1" },
{ SWSRC_SB2, "SB2" },
{ SWSRC_SC0, "SC0" },
{ SWSRC_SC1, "SC1" },
{ SWSRC_SC2, "SC2" },
{ SWSRC_SD0, "SD0" },
{ SWSRC_SD1, "SD1" },
{ SWSRC_SD2, "SD2" },
{ SWSRC_SE0, "SE0" },
{ SWSRC_SE1, "SE1" },
{ SWSRC_SE2, "SE2" },
{ SWSRC_SF0, "SF0" },
{ SWSRC_SF1, "SF1" },
{ SWSRC_SF2, "SF2" },
{ SWSRC_SG0, "SG0" },
{ SWSRC_SG1, "SG1" },
{ SWSRC_SG2, "SG2" },
{ SWSRC_SH0, "SH0" },
{ SWSRC_SH1, "SH1" },
{ SWSRC_SH2, "SH2" },
{ SWSRC_SI0, "SI0" },
{ SWSRC_SI1, "SI1" },
{ SWSRC_SI2, "SI2" },
{ SWSRC_SJ0, "SJ0" },
{ SWSRC_SJ1, "SJ1" },
{ SWSRC_SJ2, "SJ2" },
{ SWSRC_TrimRudLeft, "TrimRudLeft" },
{ SWSRC_TrimRudRight, "TrimRudRight" },
{ SWSRC_TrimEleDown, "TrimEleDown" },
{ SWSRC_TrimEleUp, "TrimEleUp" },
{ SWSRC_TrimThrDown, "TrimThrDown" },
{ SWSRC_TrimThrUp, "TrimThrUp" },
{ SWSRC_TrimAilLeft, "TrimAilLeft" },
{ SWSRC_TrimAilRight, "TrimAilRight" },
{ SWSRC_TrimT5Down, "TrimT5Down" },
{ SWSRC_TrimT5Up, "TrimT5Up" },
{ SWSRC_TrimT6Down, "TrimT6Down" },
{ SWSRC_TrimT6Up, "TrimT6Up" },
{ SWSRC_SW1, "SW1" },
{ SWSRC_SW2, "SW2" },
{ SWSRC_ON, "ON" },
{ SWSRC_ONE, "ONE" },
{ SWSRC_TELEMETRY_STREAMING, "TELEMETRY_STREAMING" },
{ SWSRC_RADIO_ACTIVITY, "RADIO_ACTIVITY" },
{ SWSRC_OFF, "OFF" },
{ 0, NULL }
};
const struct YamlIdStr enum_ModuleType[] = {
{ MODULE_TYPE_NONE, "TYPE_NONE" },
{ MODULE_TYPE_PPM, "TYPE_PPM" },
{ MODULE_TYPE_XJT_PXX1, "TYPE_XJT_PXX1" },
{ MODULE_TYPE_ISRM_PXX2, "TYPE_ISRM_PXX2" },
{ MODULE_TYPE_DSM2, "TYPE_DSM2" },
{ MODULE_TYPE_CROSSFIRE, "TYPE_CROSSFIRE" },
{ MODULE_TYPE_MULTIMODULE, "TYPE_MULTIMODULE" },
{ MODULE_TYPE_R9M_PXX1, "TYPE_R9M_PXX1" },
{ MODULE_TYPE_R9M_PXX2, "TYPE_R9M_PXX2" },
{ MODULE_TYPE_R9M_LITE_PXX1, "TYPE_R9M_LITE_PXX1" },
{ MODULE_TYPE_R9M_LITE_PXX2, "TYPE_R9M_LITE_PXX2" },
{ MODULE_TYPE_R9M_LITE_PRO_PXX1, "TYPE_R9M_LITE_PRO_PXX1" },
{ MODULE_TYPE_R9M_LITE_PRO_PXX2, "TYPE_R9M_LITE_PRO_PXX2" },
{ MODULE_TYPE_SBUS, "TYPE_SBUS" },
{ MODULE_TYPE_XJT_LITE_PXX2, "TYPE_XJT_LITE_PXX2" },
{ MODULE_TYPE_FLYSKY, "TYPE_FLYSKY" },
{ MODULE_TYPE_COUNT, "TYPE_COUNT" },
{ MODULE_TYPE_MAX, "TYPE_MAX" },
{ 0, NULL }
};
//
// Structs last
//
static const struct YamlNode struct_CalibData[] = {
YAML_IDX,
YAML_SIGNED( "mid", 16 ),
YAML_SIGNED( "spanNeg", 16 ),
YAML_SIGNED( "spanPos", 16 ),
YAML_END
};
static const struct YamlNode struct_signed_16[] = {
YAML_IDX,
YAML_SIGNED( "val", 16 ),
YAML_END
};
static const struct YamlNode struct_TrainerMix[] = {
YAML_IDX,
YAML_UNSIGNED( "srcChn", 6 ),
YAML_UNSIGNED( "mode", 2 ),
YAML_SIGNED( "studWeight", 8 ),
YAML_END
};
static const struct YamlNode struct_TrainerData[] = {
YAML_ARRAY("calib", 16, 4, struct_signed_16, NULL),
YAML_ARRAY("mix", 16, 4, struct_TrainerMix, NULL),
YAML_END
};
static const struct YamlNode struct_anonymous_1[] = {
YAML_STRING("name", 6),
YAML_END
};
static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 16 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 16 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
YAML_STRUCT("play", 48, struct_anonymous_1, NULL),
YAML_STRUCT("all", 48, struct_anonymous_2, NULL),
YAML_STRUCT("clear", 48, struct_anonymous_3, NULL),
YAML_END
};
static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 48, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
YAML_IDX,
YAML_STRING("val", 3),
YAML_END
};
static const struct YamlNode union_ZoneOptionValue_elmts[] = {
YAML_UNSIGNED( "unsignedValue", 32 ),
YAML_SIGNED( "signedValue", 32 ),
YAML_UNSIGNED( "boolValue", 32 ),
YAML_STRING("stringValue", 8),
YAML_END
};
static const struct YamlNode struct_ZoneOptionValueTyped[] = {
YAML_IDX,
YAML_ENUM("type", 32, enum_ZoneOptionValueEnum),
YAML_UNION("value", 64, union_ZoneOptionValue_elmts, select_zov),
YAML_END
};
static const struct YamlNode struct_ThemeBase__PersistentData[] = {
YAML_ARRAY("options", 96, 5, struct_ZoneOptionValueTyped, NULL),
YAML_END
};
static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "version", 8 ),
YAML_UNSIGNED( "variant", 16 ),
YAML_ARRAY("calib", 48, 15, struct_CalibData, NULL),
YAML_UNSIGNED( "chkSum", 16 ),
YAML_UNSIGNED( "vBatWarn", 8 ),
YAML_SIGNED( "txVoltageCalibration", 8 ),
YAML_UNSIGNED( "backlightMode", 3 ),
YAML_SIGNED( "antennaMode", 2 ),
YAML_UNSIGNED( "disableRtcWarning", 1 ),
YAML_PADDING( 2 ),
YAML_STRUCT("trainer", 128, struct_TrainerData, NULL),
YAML_UNSIGNED( "view", 8 ),
YAML_PADDING( 2 ),
YAML_UNSIGNED( "fai", 1 ),
YAML_SIGNED( "beepMode", 2 ),
YAML_UNSIGNED( "alarmsFlash", 1 ),
YAML_UNSIGNED( "disableMemoryWarning", 1 ),
YAML_UNSIGNED( "disableAlarmWarning", 1 ),
YAML_UNSIGNED( "stickMode", 2 ),
YAML_SIGNED( "timezone", 5 ),
YAML_UNSIGNED( "adjustRTC", 1 ),
YAML_UNSIGNED( "inactivityTimer", 8 ),
YAML_UNSIGNED( "telemetryBaudrate", 3 ),
YAML_UNSIGNED( "splashSpares", 3 ),
YAML_SIGNED( "hapticMode", 2 ),
YAML_SIGNED( "switchesDelay", 8 ),
YAML_UNSIGNED( "lightAutoOff", 8 ),
YAML_UNSIGNED( "templateSetup", 8 ),
YAML_SIGNED( "PPM_Multiplier", 8 ),
YAML_SIGNED( "hapticLength", 8 ),
YAML_SIGNED( "beepLength", 3 ),
YAML_SIGNED( "hapticStrength", 3 ),
YAML_UNSIGNED( "gpsFormat", 1 ),
YAML_UNSIGNED( "unexpectedShutdown", 1 ),
YAML_UNSIGNED( "speakerPitch", 8 ),
YAML_SIGNED( "speakerVolume", 8 ),
YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ),
YAML_SIGNED_CUST( "vBatMax", 8, r_vbat_max, w_vbat_max ),
YAML_UNSIGNED( "backlightBright", 8 ),
YAML_UNSIGNED( "globalTimer", 32 ),
YAML_UNSIGNED( "bluetoothBaudrate", 4 ),
YAML_UNSIGNED( "bluetoothMode", 4 ),
YAML_UNSIGNED( "countryCode", 2 ),
YAML_SIGNED( "pwrOnSpeed", 3 ),
YAML_SIGNED( "pwrOffSpeed", 3 ),
YAML_UNSIGNED( "imperial", 1 ),
YAML_UNSIGNED( "jitterFilter", 1 ),
YAML_UNSIGNED( "disableRssiPoweroffAlarm", 1 ),
YAML_UNSIGNED( "USBMode", 2 ),
YAML_UNSIGNED( "jackMode", 2 ),
YAML_PADDING( 1 ),
YAML_STRING("ttsLanguage", 2),
YAML_SIGNED( "beepVolume", 4 ),
YAML_SIGNED( "wavVolume", 4 ),
YAML_SIGNED( "varioVolume", 4 ),
YAML_SIGNED( "backgroundVolume", 4 ),
YAML_SIGNED( "varioPitch", 8 ),
YAML_SIGNED( "varioRange", 8 ),
YAML_SIGNED( "varioRepeat", 8 ),
YAML_ARRAY("customFn", 72, 64, struct_CustomFunctionData, cfn_is_active),
YAML_UNSIGNED( "auxSerialMode", 8 ),
YAML_ARRAY("switchConfig", 2, 16, struct_switchConfig, nullptr),
YAML_ARRAY("potsConfig", 2, 8, struct_potConfig, nullptr),
YAML_ARRAY("slidersConfig", 1, 8, struct_sliderConfig, nullptr),
YAML_ARRAY("switchNames", 24, 10, struct_string_24, NULL),
YAML_ARRAY("anaNames", 24, 13, struct_string_24, NULL),
YAML_STRING("currModelFilename", 17),
YAML_PADDING( 1 ),
YAML_UNSIGNED( "blOffBright", 7 ),
YAML_STRING("bluetoothName", 10),
YAML_STRING("themeName", 8),
YAML_STRUCT("themeData", 480, struct_ThemeBase__PersistentData, NULL),
YAML_STRING("ownerRegistrationID", 8),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
YAML_IDX,
YAML_UNSIGNED( "val", 8 ),
YAML_END
};
static const struct YamlNode struct_ModelHeader[] = {
YAML_STRING("name", 15),
YAML_ARRAY("modelId", 8, 2, struct_unsigned_8, NULL),
YAML_STRING("bitmap", 14),
YAML_END
};
static const struct YamlNode struct_TimerData[] = {
YAML_IDX,
YAML_UNSIGNED( "start", 22 ),
YAML_SIGNED( "swtch", 10 ),
YAML_SIGNED( "value", 22 ),
YAML_UNSIGNED( "mode", 3 ),
YAML_UNSIGNED( "countdownBeep", 2 ),
YAML_UNSIGNED( "minuteBeep", 1 ),
YAML_UNSIGNED( "persistent", 2 ),
YAML_SIGNED( "countdownStart", 2 ),
YAML_STRING("name", 8),
YAML_END
};
static const struct YamlNode struct_CurveRef[] = {
YAML_UNSIGNED( "type", 8 ),
YAML_SIGNED( "value", 8 ),
YAML_END
};
static const struct YamlNode struct_MixData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "weight", 11, in_read_weight, in_write_weight ),
YAML_UNSIGNED( "destCh", 5 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_UNSIGNED( "carryTrim", 1 ),
YAML_UNSIGNED( "mixWarn", 2 ),
YAML_UNSIGNED( "mltpx", 2 ),
YAML_PADDING( 1 ),
YAML_SIGNED( "offset", 14 ),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED( "flightModes", 9 ),
YAML_STRUCT("curve", 16, struct_CurveRef, NULL),
YAML_UNSIGNED( "delayUp", 8 ),
YAML_UNSIGNED( "delayDown", 8 ),
YAML_UNSIGNED( "speedUp", 8 ),
YAML_UNSIGNED( "speedDown", 8 ),
YAML_STRING("name", 6),
YAML_END
};
static const struct YamlNode struct_LimitData[] = {
YAML_IDX,
YAML_SIGNED( "min", 11 ),
YAML_SIGNED( "max", 11 ),
YAML_SIGNED( "ppmCenter", 10 ),
YAML_SIGNED( "offset", 11 ),
YAML_UNSIGNED( "symetrical", 1 ),
YAML_UNSIGNED( "revert", 1 ),
YAML_PADDING( 3 ),
YAML_SIGNED( "curve", 8 ),
YAML_STRING("name", 6),
YAML_END
};
static const struct YamlNode struct_ExpoData[] = {
YAML_IDX,
YAML_UNSIGNED( "mode", 2 ),
YAML_UNSIGNED( "scale", 14 ),
YAML_ENUM("srcRaw", 10, enum_MixSources),
YAML_SIGNED( "carryTrim", 6 ),
YAML_UNSIGNED( "chn", 5 ),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED( "flightModes", 9 ),
YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ),
YAML_PADDING( 1 ),
YAML_STRING("name", 6),
YAML_SIGNED( "offset", 8 ),
YAML_STRUCT("curve", 16, struct_CurveRef, NULL),
YAML_END
};
static const struct YamlNode struct_CurveHeader[] = {
YAML_IDX,
YAML_UNSIGNED( "type", 1 ),
YAML_UNSIGNED( "smooth", 1 ),
YAML_SIGNED( "points", 6 ),
YAML_STRING("name", 3),
YAML_END
};
static const struct YamlNode struct_signed_8[] = {
YAML_IDX,
YAML_SIGNED( "val", 8 ),
YAML_END
};
static const struct YamlNode struct_LogicalSwitchData[] = {
YAML_IDX,
YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions),
YAML_SIGNED( "v1", 10 ),
YAML_SIGNED( "v3", 10 ),
YAML_SIGNED( "andsw", 9 ),
YAML_UNSIGNED( "andswtype", 1 ),
YAML_PADDING( 2 ),
YAML_SIGNED( "v2", 16 ),
YAML_UNSIGNED( "delay", 8 ),
YAML_UNSIGNED( "duration", 8 ),
YAML_END
};
static const struct YamlNode struct_SwashRingData[] = {
YAML_UNSIGNED( "type", 8 ),
YAML_UNSIGNED( "value", 8 ),
YAML_UNSIGNED( "collectiveSource", 8 ),
YAML_UNSIGNED( "aileronSource", 8 ),
YAML_UNSIGNED( "elevatorSource", 8 ),
YAML_SIGNED( "collectiveWeight", 8 ),
YAML_SIGNED( "aileronWeight", 8 ),
YAML_SIGNED( "elevatorWeight", 8 ),
YAML_END
};
static const struct YamlNode struct_trim_t[] = {
YAML_IDX,
YAML_SIGNED( "value", 11 ),
YAML_UNSIGNED( "mode", 5 ),
YAML_END
};
static const struct YamlNode struct_FlightModeData[] = {
YAML_IDX,
YAML_ARRAY("trim", 16, 6, struct_trim_t, NULL),
YAML_STRING("name", 10),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_PADDING( 7 ),
YAML_UNSIGNED( "fadeIn", 8 ),
YAML_UNSIGNED( "fadeOut", 8 ),
YAML_ARRAY("gvars", 16, 9, struct_signed_16, gvar_is_active),
YAML_END
};
static const struct YamlNode struct_GVarData[] = {
YAML_IDX,
YAML_STRING("name", 3),
YAML_UNSIGNED( "min", 12 ),
YAML_UNSIGNED( "max", 12 ),
YAML_UNSIGNED( "popup", 1 ),
YAML_UNSIGNED( "prec", 1 ),
YAML_UNSIGNED( "unit", 2 ),
YAML_PADDING( 4 ),
YAML_END
};
static const struct YamlNode struct_VarioData[] = {
YAML_UNSIGNED( "source", 7 ),
YAML_UNSIGNED( "centerSilent", 1 ),
YAML_SIGNED( "centerMax", 8 ),
YAML_SIGNED( "centerMin", 8 ),
YAML_SIGNED( "min", 8 ),
YAML_SIGNED( "max", 8 ),
YAML_END
};
static const struct YamlNode struct_RssiAlarmData[] = {
YAML_SIGNED( "disabled", 1 ),
YAML_PADDING( 1 ),
YAML_SIGNED( "warning", 6 ),
YAML_PADDING( 2 ),
YAML_SIGNED( "critical", 6 ),
YAML_END
};
static const struct YamlNode struct_anonymous_5[] = {
YAML_SIGNED( "delay", 6 ),
YAML_UNSIGNED( "pulsePol", 1 ),
YAML_UNSIGNED( "outputType", 1 ),
YAML_SIGNED( "frameLength", 8 ),
YAML_END
};
static const struct YamlNode struct_anonymous_6[] = {
YAML_UNSIGNED( "rfProtocolExtra", 2 ),
YAML_PADDING( 3 ),
YAML_UNSIGNED( "customProto", 1 ),
YAML_UNSIGNED( "autoBindMode", 1 ),
YAML_UNSIGNED( "lowPowerMode", 1 ),
YAML_SIGNED( "optionValue", 8 ),
YAML_END
};
static const struct YamlNode struct_anonymous_7[] = {
YAML_UNSIGNED( "power", 2 ),
YAML_PADDING( 2 ),
YAML_UNSIGNED( "receiverTelemetryOff", 1 ),
YAML_UNSIGNED( "receiverHigherChannels", 1 ),
YAML_SIGNED( "antennaMode", 2 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_anonymous_8[] = {
YAML_PADDING( 6 ),
YAML_UNSIGNED( "noninverted", 1 ),
YAML_PADDING( 1 ),
YAML_SIGNED( "refreshRate", 8 ),
YAML_END
};
static const struct YamlNode struct_string_64[] = {
YAML_IDX,
YAML_STRING("val", 8),
YAML_END
};
static const struct YamlNode struct_anonymous_9[] = {
YAML_UNSIGNED( "receivers", 8 ),
YAML_ARRAY("receiverName", 64, 3, struct_string_64, NULL),
YAML_END
};
static const struct YamlNode union_anonymous_4_elmts[] = {
YAML_ARRAY("raw", 8, 25, struct_unsigned_8, NULL),
YAML_STRUCT("ppm", 16, struct_anonymous_5, NULL),
YAML_STRUCT("multi", 16, struct_anonymous_6, NULL),
YAML_STRUCT("pxx", 16, struct_anonymous_7, NULL),
YAML_STRUCT("sbus", 16, struct_anonymous_8, NULL),
YAML_STRUCT("pxx2", 200, struct_anonymous_9, NULL),
YAML_END
};
static const struct YamlNode struct_ModuleData[] = {
YAML_IDX,
YAML_ENUM("type", 4, enum_ModuleType),
YAML_SIGNED( "rfProtocol", 4 ),
YAML_UNSIGNED( "channelsStart", 8 ),
YAML_SIGNED( "channelsCount", 8 ),
YAML_UNSIGNED( "failsafeMode", 4 ),
YAML_UNSIGNED( "subType", 3 ),
YAML_UNSIGNED( "invertedSerial", 1 ),
YAML_UNION("mod", 200, union_anonymous_4_elmts, select_mod_type),
YAML_END
};
static const struct YamlNode struct_TrainerModuleData[] = {
YAML_UNSIGNED( "mode", 3 ),
YAML_PADDING( 5 ),
YAML_UNSIGNED( "channelsStart", 8 ),
YAML_SIGNED( "channelsCount", 8 ),
YAML_SIGNED( "frameLength", 8 ),
YAML_SIGNED( "delay", 6 ),
YAML_UNSIGNED( "pulsePol", 1 ),
YAML_PADDING( 1 ),
YAML_END
};
static const struct YamlNode union_ScriptDataInput_elmts[] = {
YAML_SIGNED( "value", 16 ),
YAML_UNSIGNED( "source", 16 ),
YAML_END
};
static const struct YamlNode union_ScriptDataInput[] = {
YAML_IDX,
YAML_UNION("u", 16, union_ScriptDataInput_elmts, select_script_input),
YAML_END
};
static const struct YamlNode struct_ScriptData[] = {
YAML_IDX,
YAML_STRING("file", 6),
YAML_STRING("name", 6),
YAML_ARRAY("inputs", 16, 6, union_ScriptDataInput, NULL),
YAML_END
};
static const struct YamlNode struct_string_32[] = {
YAML_IDX,
YAML_STRING("val", 4),
YAML_END
};
static const struct YamlNode union_anonymous_10_elmts[] = {
YAML_UNSIGNED( "id", 16 ),
YAML_UNSIGNED( "persistentValue", 16 ),
YAML_END
};
static const struct YamlNode struct_anonymous_12[] = {
YAML_UNSIGNED( "physID", 5 ),
YAML_UNSIGNED( "rxIndex", 3 ),
YAML_END
};
static const struct YamlNode union_anonymous_11_elmts[] = {
YAML_STRUCT("frskyInstance", 8, struct_anonymous_12, NULL),
YAML_UNSIGNED( "instance", 8 ),
YAML_UNSIGNED( "formula", 8 ),
YAML_END
};
static const struct YamlNode struct_anonymous_14[] = {
YAML_UNSIGNED( "ratio", 16 ),
YAML_SIGNED( "offset", 16 ),
YAML_END
};
static const struct YamlNode struct_anonymous_15[] = {
YAML_UNSIGNED( "source", 8 ),
YAML_UNSIGNED( "index", 8 ),
YAML_PADDING( 16 ),
YAML_END
};
static const struct YamlNode struct_anonymous_16[] = {
YAML_ARRAY("sources", 8, 4, struct_signed_8, NULL),
YAML_END
};
static const struct YamlNode struct_anonymous_17[] = {
YAML_UNSIGNED( "source", 8 ),
YAML_PADDING( 24 ),
YAML_END
};
static const struct YamlNode struct_anonymous_18[] = {
YAML_UNSIGNED( "gps", 8 ),
YAML_UNSIGNED( "alt", 8 ),
YAML_PADDING( 16 ),
YAML_END
};
static const struct YamlNode union_anonymous_13_elmts[] = {
YAML_STRUCT("custom", 32, struct_anonymous_14, NULL),
YAML_STRUCT("cell", 32, struct_anonymous_15, NULL),
YAML_STRUCT("calc", 32, struct_anonymous_16, NULL),
YAML_STRUCT("consumption", 32, struct_anonymous_17, NULL),
YAML_STRUCT("dist", 32, struct_anonymous_18, NULL),
YAML_UNSIGNED( "param", 32 ),
YAML_END
};
static const struct YamlNode struct_TelemetrySensor[] = {
YAML_IDX,
YAML_UNION("id1", 16, union_anonymous_10_elmts, select_id1),
YAML_UNION("id2", 8, union_anonymous_11_elmts, select_id2),
YAML_STRING("label", 4),
YAML_UNSIGNED( "subId", 8 ),
YAML_UNSIGNED( "type", 1 ),
YAML_PADDING( 1 ),
YAML_UNSIGNED( "unit", 6 ),
YAML_UNSIGNED( "prec", 2 ),
YAML_UNSIGNED( "autoOffset", 1 ),
YAML_UNSIGNED( "filter", 1 ),
YAML_UNSIGNED( "logs", 1 ),
YAML_UNSIGNED( "persistent", 1 ),
YAML_UNSIGNED( "onlyPositive", 1 ),
YAML_PADDING( 1 ),
YAML_UNION("cfg", 32, union_anonymous_13_elmts, select_sensor_cfg),
YAML_END
};
static const struct YamlNode struct_Widget__PersistentData[] = {
YAML_ARRAY("options", 96, 5, struct_ZoneOptionValueTyped, NULL),
YAML_END
};
static const struct YamlNode struct_ZonePersistentData[] = {
YAML_IDX,
YAML_STRING("widgetName", 10),
YAML_STRUCT("widgetData", 480, struct_Widget__PersistentData, NULL),
YAML_END
};
static const struct YamlNode struct_Layout__PersistentData[] = {
YAML_ARRAY("zones", 576, 10, struct_ZonePersistentData, NULL),
YAML_ARRAY("options", 96, 10, struct_ZoneOptionValueTyped, NULL),
YAML_END
};
static const struct YamlNode struct_CustomScreenData[] = {
YAML_IDX,
YAML_STRING("layoutName", 10),
YAML_STRUCT("layoutData", 6720, struct_Layout__PersistentData, NULL),
YAML_END
};
static const struct YamlNode struct_Topbar__PersistentData[] = {
YAML_ARRAY("zones", 576, 4, struct_ZonePersistentData, NULL),
YAML_ARRAY("options", 96, 1, struct_ZoneOptionValueTyped, NULL),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
YAML_STRUCT("header", 248, struct_ModelHeader, NULL),
YAML_ARRAY("timers", 128, 3, struct_TimerData, NULL),
YAML_UNSIGNED( "telemetryProtocol", 3 ),
YAML_UNSIGNED( "thrTrim", 1 ),
YAML_UNSIGNED( "noGlobalFunctions", 1 ),
YAML_UNSIGNED( "displayTrims", 2 ),
YAML_UNSIGNED( "ignoreSensorIds", 1 ),
YAML_SIGNED( "trimInc", 3 ),
YAML_UNSIGNED( "disableThrottleWarning", 1 ),
YAML_UNSIGNED( "displayChecklist", 1 ),
YAML_UNSIGNED( "extendedLimits", 1 ),
YAML_UNSIGNED( "extendedTrims", 1 ),
YAML_UNSIGNED( "throttleReversed", 1 ),
YAML_UNSIGNED( "beepANACenter", 16 ),
YAML_ARRAY("mixData", 160, 64, struct_MixData, NULL),
YAML_ARRAY("limitData", 104, 32, struct_LimitData, NULL),
YAML_ARRAY("expoData", 136, 64, struct_ExpoData, NULL),
YAML_ARRAY("curves", 32, 32, struct_CurveHeader, NULL),
YAML_ARRAY("points", 8, 512, struct_signed_8, NULL),
YAML_ARRAY("logicalSw", 72, 64, struct_LogicalSwitchData, NULL),
YAML_ARRAY("customFn", 72, 64, struct_CustomFunctionData, cfn_is_active),
YAML_STRUCT("swashR", 64, struct_SwashRingData, NULL),
YAML_ARRAY("flightModeData", 352, 9, struct_FlightModeData, fmd_is_active),
YAML_UNSIGNED( "thrTraceSrc", 8 ),
YAML_UNSIGNED( "switchWarningState", 32 ),
YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL),
YAML_STRUCT("varioData", 40, struct_VarioData, NULL),
YAML_UNSIGNED( "rssiSource", 8 ),
YAML_STRUCT("rssiAlarms", 16, struct_RssiAlarmData, NULL),
YAML_PADDING( 6 ),
YAML_UNSIGNED( "potsWarnMode", 2 ),
YAML_ARRAY("moduleData", 232, 2, struct_ModuleData, NULL),
YAML_ARRAY("failsafeChannels", 16, 32, struct_signed_16, NULL),
YAML_STRUCT("trainerData", 40, struct_TrainerModuleData, NULL),
YAML_ARRAY("scriptsData", 192, 9, struct_ScriptData, NULL),
YAML_ARRAY("inputNames", 32, 32, struct_string_32, NULL),
YAML_UNSIGNED( "potsWarnEnabled", 8 ),
YAML_ARRAY("potsWarnPosition", 8, 9, struct_signed_8, NULL),
YAML_ARRAY("telemetrySensors", 112, 60, struct_TelemetrySensor, NULL),
YAML_ARRAY("screenData", 6800, 5, struct_CustomScreenData, NULL),
YAML_STRUCT("topbarData", 2400, struct_Topbar__PersistentData, NULL),
YAML_UNSIGNED( "view", 8 ),
YAML_STRING("modelRegistrationID", 8),
YAML_END
};
#define MAX_RADIODATA_MODELDATA_STR_LEN 24
static const struct YamlNode __RadioData_root_node = YAML_ROOT( struct_RadioData );
const YamlNode* get_radiodata_nodes()
{
return &__RadioData_root_node;
}
static const struct YamlNode __ModelData_root_node = YAML_ROOT( struct_ModelData );
const YamlNode* get_modeldata_nodes()
{
return &__ModelData_root_node;
}
@@ -0,0 +1,771 @@
// generated by generate_yaml.py
//
// Enums first
//
const struct YamlIdStr enum_Functions[] = {
{ FUNC_OVERRIDE_CHANNEL, "OVERRIDE_CHANNEL" },
{ FUNC_TRAINER, "TRAINER" },
{ FUNC_INSTANT_TRIM, "INSTANT_TRIM" },
{ FUNC_RESET, "RESET" },
{ FUNC_SET_TIMER, "SET_TIMER" },
{ FUNC_ADJUST_GVAR, "ADJUST_GVAR" },
{ FUNC_VOLUME, "VOLUME" },
{ FUNC_SET_FAILSAFE, "SET_FAILSAFE" },
{ FUNC_RANGECHECK, "RANGECHECK" },
{ FUNC_BIND, "BIND" },
{ FUNC_FIRST_WITHOUT_ENABLE, "FIRST_WITHOUT_ENABLE" },
{ FUNC_PLAY_SOUND, "PLAY_SOUND" },
{ FUNC_PLAY_TRACK, "PLAY_TRACK" },
{ FUNC_PLAY_VALUE, "PLAY_VALUE" },
{ FUNC_RESERVE4, "RESERVE4" },
{ FUNC_PLAY_SCRIPT, "PLAY_SCRIPT" },
{ FUNC_RESERVE5, "RESERVE5" },
{ FUNC_BACKGND_MUSIC, "BACKGND_MUSIC" },
{ FUNC_BACKGND_MUSIC_PAUSE, "BACKGND_MUSIC_PAUSE" },
{ FUNC_VARIO, "VARIO" },
{ FUNC_HAPTIC, "HAPTIC" },
{ FUNC_LOGS, "LOGS" },
{ FUNC_BACKLIGHT, "BACKLIGHT" },
{ FUNC_SCREENSHOT, "SCREENSHOT" },
{ FUNC_MAX, "MAX" },
{ 0, NULL }
};
const struct YamlIdStr enum_ZoneOptionValueEnum[] = {
{ ZOV_Unsigned, "Unsigned" },
{ ZOV_Signed, "Signed" },
{ ZOV_Bool, "Bool" },
{ ZOV_String, "String" },
{ 0, NULL }
};
const struct YamlIdStr enum_MixSources[] = {
{ MIXSRC_NONE, "NONE" },
{ MIXSRC_Rud, "Rud" },
{ MIXSRC_Ele, "Ele" },
{ MIXSRC_Thr, "Thr" },
{ MIXSRC_Ail, "Ail" },
{ MIXSRC_S1, "S1" },
{ MIXSRC_6POS, "6POS" },
{ MIXSRC_S2, "S2" },
{ MIXSRC_S3, "S3" },
{ MIXSRC_S4, "S4" },
{ MIXSRC_LS, "LS" },
{ MIXSRC_RS, "RS" },
{ MIXSRC_MOUSE1, "MOUSE1" },
{ MIXSRC_MOUSE2, "MOUSE2" },
{ MIXSRC_MAX, "MAX" },
{ MIXSRC_CYC1, "CYC1" },
{ MIXSRC_CYC2, "CYC2" },
{ MIXSRC_CYC3, "CYC3" },
{ MIXSRC_TrimRud, "TrimRud" },
{ MIXSRC_TrimEle, "TrimEle" },
{ MIXSRC_TrimThr, "TrimThr" },
{ MIXSRC_TrimAil, "TrimAil" },
{ MIXSRC_TrimT5, "TrimT5" },
{ MIXSRC_TrimT6, "TrimT6" },
{ MIXSRC_SA, "SA" },
{ MIXSRC_SB, "SB" },
{ MIXSRC_SC, "SC" },
{ MIXSRC_SD, "SD" },
{ MIXSRC_SE, "SE" },
{ MIXSRC_SF, "SF" },
{ MIXSRC_SG, "SG" },
{ MIXSRC_SH, "SH" },
{ MIXSRC_SI, "SI" },
{ MIXSRC_SJ, "SJ" },
{ MIXSRC_SW1, "SW1" },
{ MIXSRC_CH1, "CH1" },
{ MIXSRC_CH2, "CH2" },
{ MIXSRC_CH3, "CH3" },
{ MIXSRC_CH4, "CH4" },
{ MIXSRC_CH5, "CH5" },
{ MIXSRC_CH6, "CH6" },
{ MIXSRC_CH7, "CH7" },
{ MIXSRC_CH8, "CH8" },
{ MIXSRC_CH9, "CH9" },
{ MIXSRC_CH10, "CH10" },
{ MIXSRC_CH11, "CH11" },
{ MIXSRC_CH12, "CH12" },
{ MIXSRC_CH13, "CH13" },
{ MIXSRC_CH14, "CH14" },
{ MIXSRC_CH15, "CH15" },
{ MIXSRC_CH16, "CH16" },
{ MIXSRC_GVAR1, "GVAR1" },
{ MIXSRC_TX_VOLTAGE, "TX_VOLTAGE" },
{ MIXSRC_TX_TIME, "TX_TIME" },
{ MIXSRC_TX_GPS, "TX_GPS" },
{ MIXSRC_TIMER1, "TIMER1" },
{ MIXSRC_TIMER2, "TIMER2" },
{ MIXSRC_TIMER3, "TIMER3" },
{ 0, NULL }
};
const struct YamlIdStr enum_LogicalSwitchesFunctions[] = {
{ LS_FUNC_NONE, "FUNC_NONE" },
{ LS_FUNC_VEQUAL, "FUNC_VEQUAL" },
{ LS_FUNC_VALMOSTEQUAL, "FUNC_VALMOSTEQUAL" },
{ LS_FUNC_VPOS, "FUNC_VPOS" },
{ LS_FUNC_VNEG, "FUNC_VNEG" },
{ LS_FUNC_RANGE, "FUNC_RANGE" },
{ LS_FUNC_APOS, "FUNC_APOS" },
{ LS_FUNC_ANEG, "FUNC_ANEG" },
{ LS_FUNC_AND, "FUNC_AND" },
{ LS_FUNC_OR, "FUNC_OR" },
{ LS_FUNC_XOR, "FUNC_XOR" },
{ LS_FUNC_EDGE, "FUNC_EDGE" },
{ LS_FUNC_EQUAL, "FUNC_EQUAL" },
{ LS_FUNC_GREATER, "FUNC_GREATER" },
{ LS_FUNC_LESS, "FUNC_LESS" },
{ LS_FUNC_DIFFEGREATER, "FUNC_DIFFEGREATER" },
{ LS_FUNC_ADIFFEGREATER, "FUNC_ADIFFEGREATER" },
{ LS_FUNC_TIMER, "FUNC_TIMER" },
{ LS_FUNC_STICKY, "FUNC_STICKY" },
{ LS_FUNC_COUNT, "FUNC_COUNT" },
{ LS_FUNC_MAX, "FUNC_MAX" },
{ 0, NULL }
};
const struct YamlIdStr enum_SwitchSources[] = {
{ SWSRC_NONE, "NONE" },
{ SWSRC_SA0, "SA0" },
{ SWSRC_SA1, "SA1" },
{ SWSRC_SA2, "SA2" },
{ SWSRC_SB0, "SB0" },
{ SWSRC_SB1, "SB1" },
{ SWSRC_SB2, "SB2" },
{ SWSRC_SC0, "SC0" },
{ SWSRC_SC1, "SC1" },
{ SWSRC_SC2, "SC2" },
{ SWSRC_SD0, "SD0" },
{ SWSRC_SD1, "SD1" },
{ SWSRC_SD2, "SD2" },
{ SWSRC_SE0, "SE0" },
{ SWSRC_SE1, "SE1" },
{ SWSRC_SE2, "SE2" },
{ SWSRC_SF0, "SF0" },
{ SWSRC_SF1, "SF1" },
{ SWSRC_SF2, "SF2" },
{ SWSRC_SG0, "SG0" },
{ SWSRC_SG1, "SG1" },
{ SWSRC_SG2, "SG2" },
{ SWSRC_SH0, "SH0" },
{ SWSRC_SH1, "SH1" },
{ SWSRC_SH2, "SH2" },
{ SWSRC_SI0, "SI0" },
{ SWSRC_SI1, "SI1" },
{ SWSRC_SI2, "SI2" },
{ SWSRC_SJ0, "SJ0" },
{ SWSRC_SJ1, "SJ1" },
{ SWSRC_SJ2, "SJ2" },
{ SWSRC_TrimRudLeft, "TrimRudLeft" },
{ SWSRC_TrimRudRight, "TrimRudRight" },
{ SWSRC_TrimEleDown, "TrimEleDown" },
{ SWSRC_TrimEleUp, "TrimEleUp" },
{ SWSRC_TrimThrDown, "TrimThrDown" },
{ SWSRC_TrimThrUp, "TrimThrUp" },
{ SWSRC_TrimAilLeft, "TrimAilLeft" },
{ SWSRC_TrimAilRight, "TrimAilRight" },
{ SWSRC_TrimT5Down, "TrimT5Down" },
{ SWSRC_TrimT5Up, "TrimT5Up" },
{ SWSRC_TrimT6Down, "TrimT6Down" },
{ SWSRC_TrimT6Up, "TrimT6Up" },
{ SWSRC_SW1, "SW1" },
{ SWSRC_SW2, "SW2" },
{ SWSRC_ON, "ON" },
{ SWSRC_ONE, "ONE" },
{ SWSRC_TELEMETRY_STREAMING, "TELEMETRY_STREAMING" },
{ SWSRC_RADIO_ACTIVITY, "RADIO_ACTIVITY" },
{ SWSRC_OFF, "OFF" },
{ 0, NULL }
};
const struct YamlIdStr enum_ModuleType[] = {
{ MODULE_TYPE_NONE, "TYPE_NONE" },
{ MODULE_TYPE_PPM, "TYPE_PPM" },
{ MODULE_TYPE_XJT_PXX1, "TYPE_XJT_PXX1" },
{ MODULE_TYPE_ISRM_PXX2, "TYPE_ISRM_PXX2" },
{ MODULE_TYPE_DSM2, "TYPE_DSM2" },
{ MODULE_TYPE_CROSSFIRE, "TYPE_CROSSFIRE" },
{ MODULE_TYPE_MULTIMODULE, "TYPE_MULTIMODULE" },
{ MODULE_TYPE_R9M_PXX1, "TYPE_R9M_PXX1" },
{ MODULE_TYPE_R9M_PXX2, "TYPE_R9M_PXX2" },
{ MODULE_TYPE_R9M_LITE_PXX1, "TYPE_R9M_LITE_PXX1" },
{ MODULE_TYPE_R9M_LITE_PXX2, "TYPE_R9M_LITE_PXX2" },
{ MODULE_TYPE_R9M_LITE_PRO_PXX1, "TYPE_R9M_LITE_PRO_PXX1" },
{ MODULE_TYPE_R9M_LITE_PRO_PXX2, "TYPE_R9M_LITE_PRO_PXX2" },
{ MODULE_TYPE_SBUS, "TYPE_SBUS" },
{ MODULE_TYPE_XJT_LITE_PXX2, "TYPE_XJT_LITE_PXX2" },
{ MODULE_TYPE_FLYSKY, "TYPE_FLYSKY" },
{ MODULE_TYPE_COUNT, "TYPE_COUNT" },
{ MODULE_TYPE_MAX, "TYPE_MAX" },
{ 0, NULL }
};
//
// Structs last
//
static const struct YamlNode struct_CalibData[] = {
YAML_IDX,
YAML_SIGNED( "mid", 16 ),
YAML_SIGNED( "spanNeg", 16 ),
YAML_SIGNED( "spanPos", 16 ),
YAML_END
};
static const struct YamlNode struct_signed_16[] = {
YAML_IDX,
YAML_SIGNED( "val", 16 ),
YAML_END
};
static const struct YamlNode struct_TrainerMix[] = {
YAML_IDX,
YAML_UNSIGNED( "srcChn", 6 ),
YAML_UNSIGNED( "mode", 2 ),
YAML_SIGNED( "studWeight", 8 ),
YAML_END
};
static const struct YamlNode struct_TrainerData[] = {
YAML_ARRAY("calib", 16, 4, struct_signed_16, NULL),
YAML_ARRAY("mix", 16, 4, struct_TrainerMix, NULL),
YAML_END
};
static const struct YamlNode struct_anonymous_1[] = {
YAML_STRING("name", 6),
YAML_END
};
static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 16 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 16 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
YAML_STRUCT("play", 48, struct_anonymous_1, NULL),
YAML_STRUCT("all", 48, struct_anonymous_2, NULL),
YAML_STRUCT("clear", 48, struct_anonymous_3, NULL),
YAML_END
};
static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 48, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
YAML_IDX,
YAML_STRING("val", 3),
YAML_END
};
static const struct YamlNode union_ZoneOptionValue_elmts[] = {
YAML_UNSIGNED( "unsignedValue", 32 ),
YAML_SIGNED( "signedValue", 32 ),
YAML_UNSIGNED( "boolValue", 32 ),
YAML_STRING("stringValue", 8),
YAML_END
};
static const struct YamlNode struct_ZoneOptionValueTyped[] = {
YAML_IDX,
YAML_ENUM("type", 32, enum_ZoneOptionValueEnum),
YAML_UNION("value", 64, union_ZoneOptionValue_elmts, select_zov),
YAML_END
};
static const struct YamlNode struct_ThemeBase__PersistentData[] = {
YAML_ARRAY("options", 96, 5, struct_ZoneOptionValueTyped, NULL),
YAML_END
};
static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "version", 8 ),
YAML_UNSIGNED( "variant", 16 ),
YAML_ARRAY("calib", 48, 15, struct_CalibData, NULL),
YAML_UNSIGNED( "chkSum", 16 ),
YAML_UNSIGNED( "vBatWarn", 8 ),
YAML_SIGNED( "txVoltageCalibration", 8 ),
YAML_UNSIGNED( "backlightMode", 3 ),
YAML_SIGNED( "antennaMode", 2 ),
YAML_UNSIGNED( "disableRtcWarning", 1 ),
YAML_PADDING( 2 ),
YAML_STRUCT("trainer", 128, struct_TrainerData, NULL),
YAML_UNSIGNED( "view", 8 ),
YAML_PADDING( 2 ),
YAML_UNSIGNED( "fai", 1 ),
YAML_SIGNED( "beepMode", 2 ),
YAML_UNSIGNED( "alarmsFlash", 1 ),
YAML_UNSIGNED( "disableMemoryWarning", 1 ),
YAML_UNSIGNED( "disableAlarmWarning", 1 ),
YAML_UNSIGNED( "stickMode", 2 ),
YAML_SIGNED( "timezone", 5 ),
YAML_UNSIGNED( "adjustRTC", 1 ),
YAML_UNSIGNED( "inactivityTimer", 8 ),
YAML_UNSIGNED( "telemetryBaudrate", 3 ),
YAML_UNSIGNED( "splashSpares", 3 ),
YAML_SIGNED( "hapticMode", 2 ),
YAML_SIGNED( "switchesDelay", 8 ),
YAML_UNSIGNED( "lightAutoOff", 8 ),
YAML_UNSIGNED( "templateSetup", 8 ),
YAML_SIGNED( "PPM_Multiplier", 8 ),
YAML_SIGNED( "hapticLength", 8 ),
YAML_SIGNED( "beepLength", 3 ),
YAML_SIGNED( "hapticStrength", 3 ),
YAML_UNSIGNED( "gpsFormat", 1 ),
YAML_UNSIGNED( "unexpectedShutdown", 1 ),
YAML_UNSIGNED( "speakerPitch", 8 ),
YAML_SIGNED( "speakerVolume", 8 ),
YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ),
YAML_SIGNED_CUST( "vBatMax", 8, r_vbat_max, w_vbat_max ),
YAML_UNSIGNED( "backlightBright", 8 ),
YAML_UNSIGNED( "globalTimer", 32 ),
YAML_UNSIGNED( "bluetoothBaudrate", 4 ),
YAML_UNSIGNED( "bluetoothMode", 4 ),
YAML_UNSIGNED( "countryCode", 2 ),
YAML_SIGNED( "pwrOnSpeed", 3 ),
YAML_SIGNED( "pwrOffSpeed", 3 ),
YAML_UNSIGNED( "imperial", 1 ),
YAML_UNSIGNED( "jitterFilter", 1 ),
YAML_UNSIGNED( "disableRssiPoweroffAlarm", 1 ),
YAML_UNSIGNED( "USBMode", 2 ),
YAML_UNSIGNED( "jackMode", 2 ),
YAML_PADDING( 1 ),
YAML_STRING("ttsLanguage", 2),
YAML_SIGNED( "beepVolume", 4 ),
YAML_SIGNED( "wavVolume", 4 ),
YAML_SIGNED( "varioVolume", 4 ),
YAML_SIGNED( "backgroundVolume", 4 ),
YAML_SIGNED( "varioPitch", 8 ),
YAML_SIGNED( "varioRange", 8 ),
YAML_SIGNED( "varioRepeat", 8 ),
YAML_ARRAY("customFn", 72, 64, struct_CustomFunctionData, cfn_is_active),
YAML_UNSIGNED( "auxSerialMode", 8 ),
YAML_ARRAY("switchConfig", 2, 16, struct_switchConfig, nullptr),
YAML_ARRAY("potsConfig", 2, 8, struct_potConfig, nullptr),
YAML_ARRAY("slidersConfig", 1, 8, struct_sliderConfig, nullptr),
YAML_ARRAY("switchNames", 24, 10, struct_string_24, NULL),
YAML_ARRAY("anaNames", 24, 13, struct_string_24, NULL),
YAML_STRING("currModelFilename", 17),
YAML_PADDING( 1 ),
YAML_UNSIGNED( "blOffBright", 7 ),
YAML_STRING("bluetoothName", 10),
YAML_STRING("themeName", 8),
YAML_STRUCT("themeData", 480, struct_ThemeBase__PersistentData, NULL),
YAML_STRING("ownerRegistrationID", 8),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
YAML_IDX,
YAML_UNSIGNED( "val", 8 ),
YAML_END
};
static const struct YamlNode struct_ModelHeader[] = {
YAML_STRING("name", 15),
YAML_ARRAY("modelId", 8, 2, struct_unsigned_8, NULL),
YAML_STRING("bitmap", 14),
YAML_END
};
static const struct YamlNode struct_TimerData[] = {
YAML_IDX,
YAML_UNSIGNED( "start", 22 ),
YAML_SIGNED( "swtch", 10 ),
YAML_SIGNED( "value", 22 ),
YAML_UNSIGNED( "mode", 3 ),
YAML_UNSIGNED( "countdownBeep", 2 ),
YAML_UNSIGNED( "minuteBeep", 1 ),
YAML_UNSIGNED( "persistent", 2 ),
YAML_SIGNED( "countdownStart", 2 ),
YAML_STRING("name", 8),
YAML_END
};
static const struct YamlNode struct_CurveRef[] = {
YAML_UNSIGNED( "type", 8 ),
YAML_SIGNED( "value", 8 ),
YAML_END
};
static const struct YamlNode struct_MixData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "weight", 11, in_read_weight, in_write_weight ),
YAML_UNSIGNED( "destCh", 5 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_UNSIGNED( "carryTrim", 1 ),
YAML_UNSIGNED( "mixWarn", 2 ),
YAML_UNSIGNED( "mltpx", 2 ),
YAML_PADDING( 1 ),
YAML_SIGNED( "offset", 14 ),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED( "flightModes", 9 ),
YAML_STRUCT("curve", 16, struct_CurveRef, NULL),
YAML_UNSIGNED( "delayUp", 8 ),
YAML_UNSIGNED( "delayDown", 8 ),
YAML_UNSIGNED( "speedUp", 8 ),
YAML_UNSIGNED( "speedDown", 8 ),
YAML_STRING("name", 6),
YAML_END
};
static const struct YamlNode struct_LimitData[] = {
YAML_IDX,
YAML_SIGNED( "min", 11 ),
YAML_SIGNED( "max", 11 ),
YAML_SIGNED( "ppmCenter", 10 ),
YAML_SIGNED( "offset", 11 ),
YAML_UNSIGNED( "symetrical", 1 ),
YAML_UNSIGNED( "revert", 1 ),
YAML_PADDING( 3 ),
YAML_SIGNED( "curve", 8 ),
YAML_STRING("name", 6),
YAML_END
};
static const struct YamlNode struct_ExpoData[] = {
YAML_IDX,
YAML_UNSIGNED( "mode", 2 ),
YAML_UNSIGNED( "scale", 14 ),
YAML_ENUM("srcRaw", 10, enum_MixSources),
YAML_SIGNED( "carryTrim", 6 ),
YAML_UNSIGNED( "chn", 5 ),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED( "flightModes", 9 ),
YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ),
YAML_PADDING( 1 ),
YAML_STRING("name", 6),
YAML_SIGNED( "offset", 8 ),
YAML_STRUCT("curve", 16, struct_CurveRef, NULL),
YAML_END
};
static const struct YamlNode struct_CurveHeader[] = {
YAML_IDX,
YAML_UNSIGNED( "type", 1 ),
YAML_UNSIGNED( "smooth", 1 ),
YAML_SIGNED( "points", 6 ),
YAML_STRING("name", 3),
YAML_END
};
static const struct YamlNode struct_signed_8[] = {
YAML_IDX,
YAML_SIGNED( "val", 8 ),
YAML_END
};
static const struct YamlNode struct_LogicalSwitchData[] = {
YAML_IDX,
YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions),
YAML_SIGNED( "v1", 10 ),
YAML_SIGNED( "v3", 10 ),
YAML_SIGNED( "andsw", 9 ),
YAML_UNSIGNED( "andswtype", 1 ),
YAML_PADDING( 2 ),
YAML_SIGNED( "v2", 16 ),
YAML_UNSIGNED( "delay", 8 ),
YAML_UNSIGNED( "duration", 8 ),
YAML_END
};
static const struct YamlNode struct_SwashRingData[] = {
YAML_UNSIGNED( "type", 8 ),
YAML_UNSIGNED( "value", 8 ),
YAML_UNSIGNED( "collectiveSource", 8 ),
YAML_UNSIGNED( "aileronSource", 8 ),
YAML_UNSIGNED( "elevatorSource", 8 ),
YAML_SIGNED( "collectiveWeight", 8 ),
YAML_SIGNED( "aileronWeight", 8 ),
YAML_SIGNED( "elevatorWeight", 8 ),
YAML_END
};
static const struct YamlNode struct_trim_t[] = {
YAML_IDX,
YAML_SIGNED( "value", 11 ),
YAML_UNSIGNED( "mode", 5 ),
YAML_END
};
static const struct YamlNode struct_FlightModeData[] = {
YAML_IDX,
YAML_ARRAY("trim", 16, 6, struct_trim_t, NULL),
YAML_STRING("name", 10),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_PADDING( 7 ),
YAML_UNSIGNED( "fadeIn", 8 ),
YAML_UNSIGNED( "fadeOut", 8 ),
YAML_ARRAY("gvars", 16, 9, struct_signed_16, gvar_is_active),
YAML_END
};
static const struct YamlNode struct_GVarData[] = {
YAML_IDX,
YAML_STRING("name", 3),
YAML_UNSIGNED( "min", 12 ),
YAML_UNSIGNED( "max", 12 ),
YAML_UNSIGNED( "popup", 1 ),
YAML_UNSIGNED( "prec", 1 ),
YAML_UNSIGNED( "unit", 2 ),
YAML_PADDING( 4 ),
YAML_END
};
static const struct YamlNode struct_VarioData[] = {
YAML_UNSIGNED( "source", 7 ),
YAML_UNSIGNED( "centerSilent", 1 ),
YAML_SIGNED( "centerMax", 8 ),
YAML_SIGNED( "centerMin", 8 ),
YAML_SIGNED( "min", 8 ),
YAML_SIGNED( "max", 8 ),
YAML_END
};
static const struct YamlNode struct_RssiAlarmData[] = {
YAML_SIGNED( "disabled", 1 ),
YAML_PADDING( 1 ),
YAML_SIGNED( "warning", 6 ),
YAML_PADDING( 2 ),
YAML_SIGNED( "critical", 6 ),
YAML_END
};
static const struct YamlNode struct_anonymous_5[] = {
YAML_SIGNED( "delay", 6 ),
YAML_UNSIGNED( "pulsePol", 1 ),
YAML_UNSIGNED( "outputType", 1 ),
YAML_SIGNED( "frameLength", 8 ),
YAML_END
};
static const struct YamlNode struct_anonymous_6[] = {
YAML_UNSIGNED( "rfProtocolExtra", 2 ),
YAML_PADDING( 3 ),
YAML_UNSIGNED( "customProto", 1 ),
YAML_UNSIGNED( "autoBindMode", 1 ),
YAML_UNSIGNED( "lowPowerMode", 1 ),
YAML_SIGNED( "optionValue", 8 ),
YAML_END
};
static const struct YamlNode struct_anonymous_7[] = {
YAML_UNSIGNED( "power", 2 ),
YAML_PADDING( 2 ),
YAML_UNSIGNED( "receiverTelemetryOff", 1 ),
YAML_UNSIGNED( "receiverHigherChannels", 1 ),
YAML_SIGNED( "antennaMode", 2 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_anonymous_8[] = {
YAML_PADDING( 6 ),
YAML_UNSIGNED( "noninverted", 1 ),
YAML_PADDING( 1 ),
YAML_SIGNED( "refreshRate", 8 ),
YAML_END
};
static const struct YamlNode struct_string_64[] = {
YAML_IDX,
YAML_STRING("val", 8),
YAML_END
};
static const struct YamlNode struct_anonymous_9[] = {
YAML_UNSIGNED( "receivers", 8 ),
YAML_ARRAY("receiverName", 64, 3, struct_string_64, NULL),
YAML_END
};
static const struct YamlNode union_anonymous_4_elmts[] = {
YAML_ARRAY("raw", 8, 25, struct_unsigned_8, NULL),
YAML_STRUCT("ppm", 16, struct_anonymous_5, NULL),
YAML_STRUCT("multi", 16, struct_anonymous_6, NULL),
YAML_STRUCT("pxx", 16, struct_anonymous_7, NULL),
YAML_STRUCT("sbus", 16, struct_anonymous_8, NULL),
YAML_STRUCT("pxx2", 200, struct_anonymous_9, NULL),
YAML_END
};
static const struct YamlNode struct_ModuleData[] = {
YAML_IDX,
YAML_ENUM("type", 4, enum_ModuleType),
YAML_SIGNED( "rfProtocol", 4 ),
YAML_UNSIGNED( "channelsStart", 8 ),
YAML_SIGNED( "channelsCount", 8 ),
YAML_UNSIGNED( "failsafeMode", 4 ),
YAML_UNSIGNED( "subType", 3 ),
YAML_UNSIGNED( "invertedSerial", 1 ),
YAML_UNION("mod", 200, union_anonymous_4_elmts, select_mod_type),
YAML_END
};
static const struct YamlNode struct_TrainerModuleData[] = {
YAML_UNSIGNED( "mode", 3 ),
YAML_PADDING( 5 ),
YAML_UNSIGNED( "channelsStart", 8 ),
YAML_SIGNED( "channelsCount", 8 ),
YAML_SIGNED( "frameLength", 8 ),
YAML_SIGNED( "delay", 6 ),
YAML_UNSIGNED( "pulsePol", 1 ),
YAML_PADDING( 1 ),
YAML_END
};
static const struct YamlNode union_ScriptDataInput_elmts[] = {
YAML_SIGNED( "value", 16 ),
YAML_UNSIGNED( "source", 16 ),
YAML_END
};
static const struct YamlNode union_ScriptDataInput[] = {
YAML_IDX,
YAML_UNION("u", 16, union_ScriptDataInput_elmts, select_script_input),
YAML_END
};
static const struct YamlNode struct_ScriptData[] = {
YAML_IDX,
YAML_STRING("file", 6),
YAML_STRING("name", 6),
YAML_ARRAY("inputs", 16, 6, union_ScriptDataInput, NULL),
YAML_END
};
static const struct YamlNode struct_string_32[] = {
YAML_IDX,
YAML_STRING("val", 4),
YAML_END
};
static const struct YamlNode union_anonymous_10_elmts[] = {
YAML_UNSIGNED( "id", 16 ),
YAML_UNSIGNED( "persistentValue", 16 ),
YAML_END
};
static const struct YamlNode struct_anonymous_12[] = {
YAML_UNSIGNED( "physID", 5 ),
YAML_UNSIGNED( "rxIndex", 3 ),
YAML_END
};
static const struct YamlNode union_anonymous_11_elmts[] = {
YAML_STRUCT("frskyInstance", 8, struct_anonymous_12, NULL),
YAML_UNSIGNED( "instance", 8 ),
YAML_UNSIGNED( "formula", 8 ),
YAML_END
};
static const struct YamlNode struct_anonymous_14[] = {
YAML_UNSIGNED( "ratio", 16 ),
YAML_SIGNED( "offset", 16 ),
YAML_END
};
static const struct YamlNode struct_anonymous_15[] = {
YAML_UNSIGNED( "source", 8 ),
YAML_UNSIGNED( "index", 8 ),
YAML_PADDING( 16 ),
YAML_END
};
static const struct YamlNode struct_anonymous_16[] = {
YAML_ARRAY("sources", 8, 4, struct_signed_8, NULL),
YAML_END
};
static const struct YamlNode struct_anonymous_17[] = {
YAML_UNSIGNED( "source", 8 ),
YAML_PADDING( 24 ),
YAML_END
};
static const struct YamlNode struct_anonymous_18[] = {
YAML_UNSIGNED( "gps", 8 ),
YAML_UNSIGNED( "alt", 8 ),
YAML_PADDING( 16 ),
YAML_END
};
static const struct YamlNode union_anonymous_13_elmts[] = {
YAML_STRUCT("custom", 32, struct_anonymous_14, NULL),
YAML_STRUCT("cell", 32, struct_anonymous_15, NULL),
YAML_STRUCT("calc", 32, struct_anonymous_16, NULL),
YAML_STRUCT("consumption", 32, struct_anonymous_17, NULL),
YAML_STRUCT("dist", 32, struct_anonymous_18, NULL),
YAML_UNSIGNED( "param", 32 ),
YAML_END
};
static const struct YamlNode struct_TelemetrySensor[] = {
YAML_IDX,
YAML_UNION("id1", 16, union_anonymous_10_elmts, select_id1),
YAML_UNION("id2", 8, union_anonymous_11_elmts, select_id2),
YAML_STRING("label", 4),
YAML_UNSIGNED( "subId", 8 ),
YAML_UNSIGNED( "type", 1 ),
YAML_PADDING( 1 ),
YAML_UNSIGNED( "unit", 6 ),
YAML_UNSIGNED( "prec", 2 ),
YAML_UNSIGNED( "autoOffset", 1 ),
YAML_UNSIGNED( "filter", 1 ),
YAML_UNSIGNED( "logs", 1 ),
YAML_UNSIGNED( "persistent", 1 ),
YAML_UNSIGNED( "onlyPositive", 1 ),
YAML_PADDING( 1 ),
YAML_UNION("cfg", 32, union_anonymous_13_elmts, select_sensor_cfg),
YAML_END
};
static const struct YamlNode struct_Widget__PersistentData[] = {
YAML_ARRAY("options", 96, 5, struct_ZoneOptionValueTyped, NULL),
YAML_END
};
static const struct YamlNode struct_ZonePersistentData[] = {
YAML_IDX,
YAML_STRING("widgetName", 10),
YAML_STRUCT("widgetData", 480, struct_Widget__PersistentData, NULL),
YAML_END
};
static const struct YamlNode struct_Layout__PersistentData[] = {
YAML_ARRAY("zones", 576, 10, struct_ZonePersistentData, NULL),
YAML_ARRAY("options", 96, 10, struct_ZoneOptionValueTyped, NULL),
YAML_END
};
static const struct YamlNode struct_CustomScreenData[] = {
YAML_IDX,
YAML_STRING("layoutName", 10),
YAML_STRUCT("layoutData", 6720, struct_Layout__PersistentData, NULL),
YAML_END
};
static const struct YamlNode struct_Topbar__PersistentData[] = {
YAML_ARRAY("zones", 576, 4, struct_ZonePersistentData, NULL),
YAML_ARRAY("options", 96, 1, struct_ZoneOptionValueTyped, NULL),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
YAML_STRUCT("header", 248, struct_ModelHeader, NULL),
YAML_ARRAY("timers", 128, 3, struct_TimerData, NULL),
YAML_UNSIGNED( "telemetryProtocol", 3 ),
YAML_UNSIGNED( "thrTrim", 1 ),
YAML_UNSIGNED( "noGlobalFunctions", 1 ),
YAML_UNSIGNED( "displayTrims", 2 ),
YAML_UNSIGNED( "ignoreSensorIds", 1 ),
YAML_SIGNED( "trimInc", 3 ),
YAML_UNSIGNED( "disableThrottleWarning", 1 ),
YAML_UNSIGNED( "displayChecklist", 1 ),
YAML_UNSIGNED( "extendedLimits", 1 ),
YAML_UNSIGNED( "extendedTrims", 1 ),
YAML_UNSIGNED( "throttleReversed", 1 ),
YAML_UNSIGNED( "beepANACenter", 16 ),
YAML_ARRAY("mixData", 160, 64, struct_MixData, NULL),
YAML_ARRAY("limitData", 104, 32, struct_LimitData, NULL),
YAML_ARRAY("expoData", 136, 64, struct_ExpoData, NULL),
YAML_ARRAY("curves", 32, 32, struct_CurveHeader, NULL),
YAML_ARRAY("points", 8, 512, struct_signed_8, NULL),
YAML_ARRAY("logicalSw", 72, 64, struct_LogicalSwitchData, NULL),
YAML_ARRAY("customFn", 72, 64, struct_CustomFunctionData, cfn_is_active),
YAML_STRUCT("swashR", 64, struct_SwashRingData, NULL),
YAML_ARRAY("flightModeData", 352, 9, struct_FlightModeData, fmd_is_active),
YAML_UNSIGNED( "thrTraceSrc", 8 ),
YAML_UNSIGNED( "switchWarningState", 32 ),
YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL),
YAML_STRUCT("varioData", 40, struct_VarioData, NULL),
YAML_UNSIGNED( "rssiSource", 8 ),
YAML_STRUCT("rssiAlarms", 16, struct_RssiAlarmData, NULL),
YAML_PADDING( 6 ),
YAML_UNSIGNED( "potsWarnMode", 2 ),
YAML_ARRAY("moduleData", 232, 2, struct_ModuleData, NULL),
YAML_ARRAY("failsafeChannels", 16, 32, struct_signed_16, NULL),
YAML_STRUCT("trainerData", 40, struct_TrainerModuleData, NULL),
YAML_ARRAY("scriptsData", 192, 9, struct_ScriptData, NULL),
YAML_ARRAY("inputNames", 32, 32, struct_string_32, NULL),
YAML_UNSIGNED( "potsWarnEnabled", 8 ),
YAML_ARRAY("potsWarnPosition", 8, 9, struct_signed_8, NULL),
YAML_ARRAY("telemetrySensors", 112, 60, struct_TelemetrySensor, NULL),
YAML_ARRAY("screenData", 6800, 5, struct_CustomScreenData, NULL),
YAML_STRUCT("topbarData", 2400, struct_Topbar__PersistentData, NULL),
YAML_UNSIGNED( "view", 8 ),
YAML_STRING("modelRegistrationID", 8),
YAML_END
};
#define MAX_RADIODATA_MODELDATA_STR_LEN 24
static const struct YamlNode __RadioData_root_node = YAML_ROOT( struct_RadioData );
const YamlNode* get_radiodata_nodes()
{
return &__RadioData_root_node;
}
static const struct YamlNode __ModelData_root_node = YAML_ROOT( struct_ModelData );
const YamlNode* get_modeldata_nodes()
{
return &__ModelData_root_node;
}
+37
View File
@@ -0,0 +1,37 @@
#ifndef _YAML_DEFS_H_
#define _YAML_DEFS_H_
#if defined(YAML_GENERATOR)
/* private definitions */
#define _yaml_note(label) #label
#define _yaml_attribute(attr) __attribute__((annotate(attr)))
/* public definitions */
#define ENUM(label) _yaml_attribute("enum:" _yaml_note(label))
#define SKIP _yaml_attribute("skip:true")
#define USE_IDX _yaml_attribute("idx:true")
#define FUNC(name) _yaml_attribute("func:" _yaml_note(name))
#define NAME(label) _yaml_attribute("name:" _yaml_note(label))
#define CUST(read,write) \
_yaml_attribute("read:" _yaml_note(read)) \
_yaml_attribute("write:" _yaml_note(write))
#define ARRAY(elmt_size,elmt_type,fcn) \
_yaml_attribute("array:" _yaml_note(elmt_size) "|" \
_yaml_note(elmt_type) "|" _yaml_note(fcn))
#else
#define ENUM(label)
#define SKIP
#define USE_IDX
#define FUNC(name)
#define NAME(label)
#define CUST(read,write)
#define ARRAY(elmt_size,elmt_type,fcn)
#endif
#endif
+136
View File
@@ -0,0 +1,136 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "yaml_modelslist.h"
#include "yaml_parser.h"
#include "storage/modelslist.h"
using std::list;
struct modelslist_iter
{
enum Level {
Root=0,
Category=1,
Model=2
};
ModelsList* root;
uint8_t level;
char current_attr[16]; // set after find_node()
};
static modelslist_iter __modelslist_iter_inst;
void* get_modelslist_iter()
{
__modelslist_iter_inst.root = &modelslist;
__modelslist_iter_inst.level = 0;
return &__modelslist_iter_inst;
}
static bool to_parent(void* ctx)
{
modelslist_iter* mi = (modelslist_iter*)ctx;
if (mi->level == modelslist_iter::Root) {
return false;
}
mi->level--;
return true;
}
static bool to_child(void* ctx)
{
modelslist_iter* mi = (modelslist_iter*)ctx;
if (mi->level == modelslist_iter::Model) {
return false;
}
mi->level++;
return true;
}
static bool to_next_elmt(void* ctx)
{
modelslist_iter* mi = (modelslist_iter*)ctx;
if (mi->level == modelslist_iter::Root) {
return false;
}
return true;
}
static bool find_node(void* ctx, char* buf, uint8_t len)
{
modelslist_iter* mi = (modelslist_iter*)ctx;
if (len > sizeof(modelslist_iter::current_attr)-1)
len = sizeof(modelslist_iter::current_attr)-1;
memcpy(mi->current_attr, buf, len);
mi->current_attr[len] = '\0';
return true;
}
static void set_attr(void* ctx, char* buf, uint8_t len)
{
modelslist_iter* mi = (modelslist_iter*)ctx;
list<ModelsCategory *>& cats = mi->root->getCategories();
switch(mi->level) {
case modelslist_iter::Category: {
ModelsCategory* cat = new ModelsCategory(buf,len);
cats.push_back(cat);
} break;
case modelslist_iter::Model:
if (!strcmp(mi->current_attr,"filename")) {
if (!cats.empty()) {
ModelCell* model = new ModelCell(buf, len);
cats.back()->push_back(model);
mi->root->incModelsCount();
}
}
else if (!strcmp(mi->current_attr,"name")) {
if (!cats.empty()) {
ModelsCategory* cat = cats.back();
if (!cat->empty()) {
ModelCell* model = cat->back();
model->setModelName(buf,len);
}
}
}
break;
}
}
static const YamlParserCalls modelslistCalls = {
to_parent,
to_child,
to_next_elmt,
find_node,
set_attr
};
const YamlParserCalls* get_modelslist_parser_calls()
{
return &modelslistCalls;
}
+29
View File
@@ -0,0 +1,29 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _YAML_MODELSLIST_H_
#define _YAML_MODELSLIST_H_
struct YamlParserCalls;
void* get_modelslist_iter();
const YamlParserCalls* get_modelslist_parser_calls();
#endif
+174
View File
@@ -0,0 +1,174 @@
#ifndef _node_h_
#define _node_h_
#include <stdint.h>
#include <stddef.h>
#include "yaml_parser.h"
#define NODE_STACK_DEPTH 12
enum YamlDataType {
YDT_NONE=0,
YDT_IDX,
YDT_SIGNED,
YDT_UNSIGNED,
YDT_STRING,
YDT_ARRAY,
YDT_ENUM,
YDT_UNION,
YDT_PADDING
};
struct YamlIdStr
{
int id;
const char* str;
};
// return false if error
typedef bool (*yaml_writer_func)(void* opaque, const char* str, size_t len);
struct YamlNode
{
typedef bool (*is_active_func)(uint8_t* data, uint32_t bitoffs);
typedef uint32_t (*cust_to_uint_func)(const YamlNode* node, const char* val, uint8_t val_len);
typedef bool (*uint_to_cust_func)(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque);
typedef uint8_t (*select_member_func)(uint8_t* data, uint32_t bitoffs);
typedef uint32_t (*cust_idx_read_func)(const char* val, uint8_t val_len);
typedef bool (*cust_idx_write_func)(uint32_t idx, yaml_writer_func wf, void* opaque);
uint8_t type;
uint32_t size; // bits
uint8_t tag_len;
const char* tag;
union {
struct {
const YamlNode* child;
union {
struct {
is_active_func is_active;
uint16_t elmts; // maximum number of elements
} _a;
select_member_func select_member;
} u;
} _array;
struct {
const YamlIdStr* choices;
} _enum;
struct {
cust_to_uint_func cust_to_uint;
uint_to_cust_func uint_to_cust;
} _cust;
struct {
cust_idx_read_func read;
cust_idx_write_func write;
} _cust_idx;
} u;
};
#if !defined(_MSC_VER)
#define YAML_TAG(str) \
.tag_len=(sizeof(str)-1), .tag=(str)
#define YAML_IDX \
{ .type=YDT_IDX, .size=0, YAML_TAG("idx") }
#define YAML_IDX_CUST(tag, f_read, f_write) \
{ .type=YDT_IDX, .size=0, YAML_TAG(tag), .u={._cust_idx={.read=(f_read), .write=(f_write) }} }
#define YAML_SIGNED(tag, bits) \
{ .type=YDT_SIGNED, .size=(bits), YAML_TAG(tag) }
#define YAML_UNSIGNED(tag, bits) \
{ .type=YDT_UNSIGNED, .size=(bits), YAML_TAG(tag) }
#define YAML_SIGNED_CUST(tag, bits, f_cust_to_uint, f_uint_to_cust) \
{ .type=YDT_SIGNED, .size=(bits), YAML_TAG(tag), .u={._cust={ .cust_to_uint=f_cust_to_uint, .uint_to_cust=f_uint_to_cust }} }
#define YAML_UNSIGNED_CUST(tag, bits, f_cust_to_uint, f_uint_to_cust) \
{ .type=YDT_UNSIGNED, .size=(bits), YAML_TAG(tag), .u={._cust={ .cust_to_uint=f_cust_to_uint, .uint_to_cust=f_uint_to_cust }} }
#define YAML_STRING(tag, max_len) \
{ .type=YDT_STRING, .size=((max_len)<<3), YAML_TAG(tag) }
#define YAML_STRUCT(tag, bits, nodes, f_is_active) \
{ .type=YDT_ARRAY, .size=(bits), YAML_TAG(tag), .u={._array={ .child=(nodes), .u={ ._a={.is_active=(f_is_active), .elmts=1 }}}} }
#define YAML_ARRAY(tag, bits, max_elmts, nodes, f_is_active) \
{ .type=YDT_ARRAY, .size=(bits), YAML_TAG(tag), .u={._array={ .child=(nodes), .u={ ._a={.is_active=(f_is_active), .elmts=(max_elmts) }}}} }
#define YAML_ENUM(tag, bits, id_strs) \
{ .type=YDT_ENUM, .size=(bits), YAML_TAG(tag), .u={._enum={ .choices=(id_strs) }} }
#define YAML_UNION(tag, bits, nodes, f_sel_m) \
{ .type=YDT_UNION, .size=(bits), YAML_TAG(tag), .u={._array={ .child=(nodes), .u={.select_member=(f_sel_m) }}} }
#define YAML_PADDING(bits) \
{ .type=YDT_PADDING, .size=(bits) }
#define YAML_END \
{ .type=YDT_NONE }
#define YAML_ROOT(nodes) \
{ .type=YDT_ARRAY, .size=0, .tag_len=0, .tag=NULL, \
.u={ \
._array={ .child=(nodes), \
.u={._a={.is_active=NULL, .elmts=1 }} \
}} \
}
#else // MSVC++ compat
#define YAML_TAG(str) \
(sizeof(str)-1), (str)
#define YAML_IDX \
{ YDT_IDX , 0, YAML_TAG("idx") }
#define YAML_SIGNED(tag, bits) \
{ YDT_SIGNED, (bits), YAML_TAG(tag) }
#define YAML_UNSIGNED(tag, bits) \
{ YDT_UNSIGNED, (bits), YAML_TAG(tag) }
#define YAML_SIGNED_CUST(tag, bits, f_cust_to_uint, f_uint_to_cust) \
{ YDT_SIGNED, (bits), YAML_TAG(tag), {{ (const YamlNode*)f_cust_to_uint, {{ (YamlNode::is_active_func)f_uint_to_cust, 0 }}}} }
#define YAML_UNSIGNED_CUST(tag, bits, f_cust_to_uint, f_uint_to_cust) \
{ YDT_UNSIGNED, (bits), YAML_TAG(tag), {{ (const YamlNode*)f_cust_to_uint, {{ (YamlNode::is_active_func)f_uint_to_cust, 0}}}} }
#define YAML_STRING(tag, max_len) \
{ YDT_STRING, ((max_len)<<3), YAML_TAG(tag) }
#define YAML_STRUCT(tag, bits, nodes, f_is_active) \
{ YDT_ARRAY, (bits), YAML_TAG(tag), {{ (nodes), {{ (f_is_active), 1 }}}} }
#define YAML_ARRAY(tag, bits, max_elmts, nodes, f_is_active) \
{ YDT_ARRAY, (bits), YAML_TAG(tag), {{ (nodes), {{ (f_is_active), (max_elmts) }}}} }
#define YAML_ENUM(tag, bits, id_strs) \
{ YDT_ENUM, (bits), YAML_TAG(tag), {{ (const YamlNode*)(id_strs) }} }
#define YAML_UNION(tag, bits, nodes, f_sel_m) \
{ YDT_UNION, (bits), YAML_TAG(tag), {{ (nodes), {{ (YamlNode::is_active_func)(f_sel_m), 0 }}}} }
#define YAML_PADDING(bits) \
{ YDT_PADDING, (bits) }
#define YAML_END \
{ YDT_NONE }
#define YAML_ROOT(nodes) \
{ YDT_ARRAY, 0, 0, NULL, {{ (nodes), {{ NULL, 1 }}}} }
#endif
#endif
+256
View File
@@ -0,0 +1,256 @@
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include "yaml_parser.h"
#include "debug.h"
YamlParser::YamlParser()
{
}
void YamlParser::init(const YamlParserCalls* parser_calls, void* parser_ctx)
{
indent = 0;
level = 0;
memset(indents, 0, sizeof(indents));
calls = parser_calls;
ctx = parser_ctx;
reset();
}
void YamlParser::reset()
{
state = ps_Indent;
indents[level] = indent;
indent = scratch_len = 0;
node_found = false;
}
bool YamlParser::toChild()
{
bool ret = calls->to_child(ctx);
if (ret) level++;
return ret;
}
bool YamlParser::toParent()
{
if (!level)
return false;
bool ret = calls->to_parent(ctx);
if (ret) level--;
return ret;
}
uint8_t YamlParser::getLastIndent()
{
return indents[level];
}
YamlParser::YamlResult
YamlParser::parse(const char* buffer, unsigned int size)
{
#define CONCAT_STR(s,s_len,c) \
{ \
if(s_len < MAX_STR) \
s[s_len++] = c; \
else { \
TRACE("STRING_OVERFLOW"); \
return STRING_OVERFLOW; \
} \
}
const char* c = buffer;
const char* end = c + size;
while(c < end) {
switch(state) {
case ps_Indent:
if (*c == '-') {
state = ps_Dash;
++indent;
break;
}
// trap
case ps_Dash:
if (*c == ' ') { // skip space(s), should be only one??
++indent;
break;
}
if (indent < getLastIndent()) {
// go up as many levels as necessary
do {
if (!toParent()) {
TRACE("STOP (no parent)!\n");
return DONE_PARSING;
}
} while (indent < getLastIndent());
if (state == ps_Dash) {
if (!calls->to_next_elmt(ctx)) {
return DONE_PARSING;
}
}
}
// go down one level
else if (indent > getLastIndent()) {
if (!toChild()) {
TRACE("STOP (stack full)!\n");
return DONE_PARSING; // ERROR
}
}
// same level, next element
else if (state == ps_Dash) {
if (!calls->to_next_elmt(ctx)) {
return DONE_PARSING;
}
}
state = ps_Attr;
CONCAT_STR(scratch_buf, scratch_len, *c);
break;
case ps_Attr:
if (*c == ' ') {// assumes nothing else comes after spaces start
node_found = calls->find_node(ctx, scratch_buf, scratch_len);
if (!node_found) {
TRACE("YAML_PARSER: Could not find node '%.*s' (1)\n",
scratch_len, scratch_buf);
}
state = ps_AttrSP;
break;
}
if (*c != ':')
CONCAT_STR(scratch_buf, scratch_len, *c);
// trap
case ps_AttrSP:
if (*c == '\r' || *c == '\n') {
if (state == ps_Attr) {
node_found = calls->find_node(ctx, scratch_buf, scratch_len);
if (!node_found) {
TRACE("YAML_PARSER: Could not find node '%.*s' (2)\n",
scratch_len, scratch_buf);
}
}
state = ps_CRLF;
continue;
}
if (*c == ':') {
if (state == ps_Attr) {
node_found = calls->find_node(ctx, scratch_buf, scratch_len);
if (!node_found) {
TRACE("YAML_PARSER: Could not find node '%.*s' (3)\n",
scratch_len, scratch_buf);
}
}
state = ps_Sep;
break;
}
break;
case ps_Sep:
if (*c == ' ')
break;
if (*c == '\r' || *c == '\n'){
state = ps_CRLF;
continue;
}
state = ps_Val;
scratch_len = 0;
if (*c == '\"') {
state = ps_ValQuo;
break;
}
CONCAT_STR(scratch_buf, scratch_len, *c);
break;
case ps_ValQuo:
if (*c == '\"') {
state = ps_Val;
break;
}
if (*c == '\\') {
state = ps_ValEsc1;
break;
}
CONCAT_STR(scratch_buf, scratch_len, *c);
break;
case ps_ValEsc1:
if (*c == 'x') {
state = ps_ValEsc2;
break;
}
//TODO: more escapes needed???
TRACE("unknown escape char '%c'",*c);
return DONE_PARSING;
case ps_ValEsc2:
if(scratch_len >= MAX_STR) {
TRACE("STRING_OVERFLOW");
return STRING_OVERFLOW;
}
else if (*c >= '0' && *c <= '9') {
scratch_buf[scratch_len] = (*c - '0') << 4;
state = ps_ValEsc3;
break;
}
else if (*c >= 'A' && *c <= 'F') {
scratch_buf[scratch_len] = (*c - 'A' + 10) << 4;
state = ps_ValEsc3;
break;
}
TRACE("wrong hex digit '%c'",*c);
return DONE_PARSING;
case ps_ValEsc3:
if (*c >= '0' && *c <= '9') {
scratch_buf[scratch_len++] |= (*c - '0');
state = ps_ValQuo;
break;
}
else if (*c >= 'A' && *c <= 'F') {
scratch_buf[scratch_len++] |= (*c - 'A' + 10);
state = ps_ValQuo;
break;
}
TRACE("wrong hex digit '%c'",*c);
return DONE_PARSING;
case ps_Val:
if (*c == ' ' || *c == '\r' || *c == '\n') {
// set attribute
if (node_found) {
calls->set_attr(ctx, scratch_buf, scratch_len);
}
state = ps_CRLF;
continue;
}
if (*c == '\"') {
state = ps_ValQuo;
break;
}
CONCAT_STR(scratch_buf, scratch_len, *c);
break;
case ps_CRLF:
if (*c == '\n') {
// reset state at EOL
reset();
}
break;
}
c++;
} // for each char
return CONTINUE_PARSING;
}
+79
View File
@@ -0,0 +1,79 @@
#ifndef _yaml_parser_h_
#define _yaml_parser_h_
#include <stdint.h>
#define MAX_STR 40
#define MAX_DEPTH 16 // 12 real + 4 virtual
struct YamlParserCalls
{
bool (*to_parent) (void* ctx);
bool (*to_child) (void* ctx);
bool (*to_next_elmt) (void* ctx);
bool (*find_node) (void* ctx, char* buf, uint8_t len);
void (*set_attr) (void* ctx, char* buf, uint8_t len);
};
class YamlParser
{
enum ParserState {
ps_Indent=0,
ps_Dash,
ps_Attr,
ps_AttrSP,
ps_Sep,
ps_Val,
ps_ValQuo,
ps_ValEsc1,
ps_ValEsc2,
ps_ValEsc3,
ps_CRLF
};
// last indents for each level
uint8_t indents[MAX_DEPTH];
// current indent
uint8_t indent;
// current level
uint8_t level;
// parser state
uint8_t state;
// scratch buffer w/ 16 bytes
// used for attribute and values
char scratch_buf[MAX_STR];
uint8_t scratch_len;
bool node_found;
// tree iterator state
const YamlParserCalls* calls;
void* ctx;
// Reset parser state for next line
void reset();
bool toChild();
bool toParent();
uint8_t getLastIndent();
public:
enum YamlResult {
DONE_PARSING,
CONTINUE_PARSING,
STRING_OVERFLOW
};
YamlParser();
void init(const YamlParserCalls* parser_calls, void* parser_ctx);
YamlResult parse(const char* buffer, unsigned int size);
};
#endif
+620
View File
@@ -0,0 +1,620 @@
#include "debug.h"
#include "yaml_node.h"
#include "yaml_bits.h"
#include "yaml_tree_walker.h"
#include "yaml_parser.h"
#include <string.h>
#define MIN(a,b) (a < b ? a : b)
static void copy_string(char* dst, const char* src, uint8_t len)
{
memcpy(dst,src,len);
dst[len] = '\0';
}
uint32_t yaml_parse_enum(const struct YamlIdStr* choices, const char* val, uint8_t val_len)
{
while (choices->str) {
// we have a match!
if (!strncmp(val, choices->str, val_len))
break;
choices++;
}
return choices->id;
}
static void yaml_set_attr(uint8_t* ptr, uint32_t bit_ofs, const YamlNode* node,
const char* val, uint8_t val_len)
{
uint32_t i = 0;
//TRACE("set(%s, %.*s, bit-ofs=%u, bits=%u)\n",
// node->tag, val_len, val, bit_ofs, node->size);
ptr += bit_ofs >> 3UL;
bit_ofs &= 0x07;
if (node->type == YDT_STRING) {
//assert(!bit_ofs);
copy_string((char*)ptr, val, MIN(val_len, node->size - 1));
return;
}
switch(node->type) {
case YDT_SIGNED:
i = node->u._cust.cust_to_uint ? node->u._cust.cust_to_uint(node, val, val_len)
: (uint32_t)yaml_str2int(val, val_len);
break;
case YDT_UNSIGNED:
i = node->u._cust.cust_to_uint ? node->u._cust.cust_to_uint(node, val, val_len)
: yaml_str2uint(val, val_len);
break;
case YDT_ENUM:
i = yaml_parse_enum(node->u._enum.choices, val, val_len);
break;
default:
break;
}
yaml_put_bits(ptr, i, bit_ofs, node->size);
}
const char* yaml_output_enum(int32_t i, const struct YamlIdStr* choices)
{
//TRACE("<choice = %d>", i);
while(choices->str) {
if (i == choices->id)
break;
choices++;
}
return choices->str;
}
static const char hex_digits[] {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
static bool yaml_output_string(const char* str, uint32_t max_len,
yaml_writer_func wf, void* opaque)
{
if (!wf(opaque, "\"", 1))
return false;
while(*str && max_len > 0) {
if (*str >= 0x20 && *str <= 0x7E) {
if (!wf(opaque, str++, 1)) return false;
max_len--;
}
else {
if (!wf(opaque, "\\x", 2)) return false;
if (!wf(opaque, &(hex_digits[((uint8_t)*str) >> 4]), 1)) return false;
if (!wf(opaque, &(hex_digits[((uint8_t)*str) & 0x0F]), 1)) return false;
str++; max_len--;
}
}
if (!wf(opaque, "\"", 1))
return false;
return true;
}
static bool yaml_output_attr(uint8_t* ptr, uint32_t bit_ofs, const YamlNode* node,
yaml_writer_func wf, void* opaque)
{
if (node->type == YDT_NONE)
return false;
if (node->type == YDT_PADDING)
return true;
// output tag
if (!wf(opaque, node->tag, node->tag_len))
return false;
if (!wf(opaque, ": ", 2))
return false;
if (ptr) {
ptr += bit_ofs >> 3UL;
bit_ofs &= 0x07;
const char* p_out = NULL;
if (node->type == YDT_STRING) {
//assert(!bit_ofs);
if (!yaml_output_string((const char*)ptr, (node->size)>>3UL, wf, opaque))
return false;
}
else {
unsigned int i = yaml_get_bits(ptr, bit_ofs, node->size);
if ((node->type == YDT_SIGNED || node->type == YDT_UNSIGNED)
&& node->u._cust.uint_to_cust) {
return node->u._cust.uint_to_cust(node, i, wf, opaque)
&& wf(opaque, "\r\n", 2);
}
else {
switch(node->type) {
case YDT_SIGNED:
p_out = yaml_signed2str((int)yaml_to_signed(i, node->size));
break;
case YDT_UNSIGNED:
p_out = yaml_unsigned2str(i);
break;
case YDT_ENUM:
p_out = yaml_output_enum(i, node->u._enum.choices);
break;
case YDT_ARRAY:
case YDT_UNION:
default:
break;
}
}
}
if (p_out && !wf(opaque, p_out, strlen(p_out)))
return false;
}
return wf(opaque, "\r\n", 2);
}
YamlTreeWalker::YamlTreeWalker()
: stack_level(NODE_STACK_DEPTH),
virt_level(0),
anon_union(0)
{
memset(stack,0,sizeof(stack));
}
void YamlTreeWalker::reset(const YamlNode* node, uint8_t* data)
{
this->data = data;
stack_level = NODE_STACK_DEPTH;
virt_level = 0;
push();
setNode(node);
rewind();
}
bool YamlTreeWalker::push()
{
if (full())
return false;
stack_level--;
memset(&(stack[stack_level]), 0, sizeof(State));
return true;
}
bool YamlTreeWalker::pop()
{
if (empty())
return false;
memset(&(stack[stack_level]), 0, sizeof(State));
stack_level++;
return true;
}
// Rewind to the current node's first attribute
// (and reset the bit offset)
void YamlTreeWalker::rewind()
{
if (getNode()->type == YDT_ARRAY
|| getNode()->type == YDT_UNION) {
setAttrIdx(0);
setAttrOfs(getLevelOfs());
}
}
// Increment the cursor until a match is found or the end of
// the current collection (node of type YDT_NONE) is reached.
//
// return true if a match has been found.
bool YamlTreeWalker::findNode(const char* tag, uint8_t tag_len)
{
if (virt_level)
return false;
rewind();
const struct YamlNode* attr = getAttr();
while(attr && attr->type != YDT_NONE) {
if ((tag_len == attr->tag_len)
&& !strncmp(tag, attr->tag, tag_len)) {
return true; // attribute found!
}
toNextAttr();
attr = getAttr();
}
return false;
}
// Get the current bit offset
unsigned int YamlTreeWalker::getBitOffset()
{
return stack[stack_level].getOfs();
}
bool YamlTreeWalker::toParent()
{
if(virt_level) {
virt_level--;
return true;
}
if (!pop())
return false;
return !empty();
}
bool YamlTreeWalker::toChild()
{
const struct YamlNode* attr = getAttr();
if (!attr
|| (attr->type != YDT_ARRAY
&& attr->type != YDT_UNION)) {
virt_level++;
return true;
}
if (!push()) {
virt_level++;
return false;
}
setNode(attr);
setAttrOfs(getLevelOfs());
attr = getAttr();
if ((attr->type == YDT_UNION) && (attr->tag_len == 0)) {
toChild();
anon_union++;
}
return true;
}
bool YamlTreeWalker::toNextElmt()
{
const struct YamlNode* node = getNode();
if (!virt_level && (node->type == YDT_ARRAY
|| node->type == YDT_UNION)) {
if (node->type == YDT_UNION) {
return false;
}
if (getElmts() >= node->u._array.u._a.elmts - 1)
return false;
incElmts();
rewind();
}
return true;
}
bool YamlTreeWalker::isElmtEmpty(uint8_t* data)
{
if (virt_level)
return true;
if (!data)
return false;
const struct YamlNode* node = getNode();
uint32_t bit_ofs = 0;
if (node->type == YDT_ARRAY) {
bit_ofs = ((uint32_t)getElmts())
* getNode()->size
+ getLevelOfs();
// assume structs aligned on 8bit boundaries
if (node->u._array.u._a.is_active)
return !node->u._array.u._a.is_active(data, bit_ofs);
return yaml_is_zero(data, bit_ofs, node->size);
}
else if ((node->type == YDT_UNION) && hasParent()) {
bit_ofs = getLevelOfs();
TRACE("<not empty>");
return false;//node->u._array.u.select_member; //TODO!
// // assume structs aligned on 8bit boundaries
// && !node->_array.is_active(data + (bit_ofs >> 3));
}
return false;
}
void YamlTreeWalker::toNextAttr()
{
const struct YamlNode* node = getNode();
const struct YamlNode* attr = NULL;
if (node->type != YDT_UNION) {
attr = getAttr();
uint32_t attr_bit_ofs = getAttrOfs();
if (attr->type == YDT_ARRAY)
attr_bit_ofs += ((uint32_t)attr->u._array.u._a.elmts * attr->size);
else
attr_bit_ofs += attr->size;
setAttrOfs(attr_bit_ofs);
}
incAttr();
// anonymous union handling
attr = getAttr();
if ((attr->type == YDT_UNION) && (attr->tag_len == 0)) {
toChild();
anon_union++;
}
else if ((attr->type == YDT_NONE)
&& (getNode()->type == YDT_UNION)
&& anon_union) {
anon_union--;
toParent();
toNextAttr();
}
}
void YamlTreeWalker::setAttrValue(char* buf, uint8_t len)
{
if (!buf || !len)
return;
const YamlNode* attr = getAttr();
if (attr->type == YDT_IDX) {
uint32_t i = 0;
if (attr->u._cust_idx.read)
i = attr->u._cust_idx.read(buf, len);
else
i = yaml_str2uint(buf, len);
while ((i > getElmts()) && toNextElmt());
}
else {
yaml_set_attr(data, getBitOffset(), attr, buf, len);
//walker.dump_stack();
}
}
bool YamlTreeWalker::generate(yaml_writer_func wf, void* opaque)
{
bool new_elmt = false;
while (true) {
const struct YamlNode* attr = getAttr();
if (attr->type == YDT_PADDING) {
toNextAttr();
continue;
}
// end of this level, go up or die
if (attr->type == YDT_NONE) {
const struct YamlNode* node = getNode();
if (node->type != YDT_ARRAY && node->type != YDT_UNION)
return false; // Error in the structure (probably)
// if parent is a union, no need to output the other elements...
const YamlNode* parent = getParent();
if (parent && (parent->type == YDT_UNION)) {
if (!toParent())
return false;
}
else {
// walk to next non-empty element
while (toNextElmt()) {
if (!isElmtEmpty(data)) {
new_elmt = true;
break;
}
}
if (new_elmt)
continue;
}
// no next element, go up
if (!toParent())
return true;
toNextAttr();
continue;
}
else if (attr->type == YDT_ARRAY || attr->type == YDT_UNION) {
if (!toChild())
return false; // TODO: error handling???
const struct YamlNode* node = getNode();
if (node->type == YDT_UNION && node->u._array.u.select_member) {
// output union tag, select member and go up one level
// output union tag
for(int i=2; i < getLevel(); i++)
if (!wf(opaque, " ", 3))
return false;
if (!yaml_output_attr(NULL, 0, node, wf, opaque))
return false; // TODO: error handling???
// grab attr idx...
uint8_t idx = node->u._array.u.select_member(data, getBitOffset());
//TRACE("<idx = %d>", idx);
setAttrIdx(idx);
attr = getAttr();
for(int i=1; i < getLevel(); i++)
if (!wf(opaque, " ", 3))
return false;
if (!yaml_output_attr(data, getBitOffset(), attr, wf, opaque))
return false; // TODO: error handling???
if (attr->type != YDT_ARRAY
&& attr->type != YDT_UNION) {
if (!toParent())
return false;
toNextAttr();
}
else {
if (!toChild() && !toParent())
return false;
}
continue;
}
// walk to next non-empty element
do {
if (!isElmtEmpty(data)) {
new_elmt = true;
break;
}
new_elmt = false;
} while (toNextElmt());
if (new_elmt) {
// non-empty element present in a new structure/array
// let's output the attribute
for(int i=2; i < getLevel(); i++)
if (!wf(opaque, " ", 3))
return false;
if (!yaml_output_attr(NULL, 0, getNode(), wf, opaque))
return false; // TODO: error handling???
continue;
}
// no next element, go up
if (!toParent())
return true;
toNextAttr();
continue;
}
if (new_elmt) {
for(int i=2; i < getLevel(); i++)
if (!wf(opaque, " ", 3))
return false;
if (!wf(opaque, " - ", 3))
return false;
new_elmt = false;
}
else {
for(int i=1; i < getLevel(); i++)
if (!wf(opaque, " ", 3))
return false;
}
if (attr->type == YDT_IDX) {
if (!wf(opaque, attr->tag, attr->tag_len))
return false;
if (!wf(opaque, ": ", 2))
return false;
if (attr->u._cust_idx.write) {
if (!attr->u._cust_idx.write(getElmts(),wf,opaque))
return false;
}
else {
char* idx = yaml_unsigned2str(getElmts());
if (!wf(opaque, idx, strlen(idx)))
return false;
}
if (!wf(opaque, "\r\n", 2))
return false;
}
else if (!yaml_output_attr(data, getBitOffset(), attr, wf, opaque))
return false; // TODO: error handling???
toNextAttr();
}
return true;
}
void YamlTreeWalker::dump_stack()
{
for (int i=0; i<NODE_STACK_DEPTH; i++) {
TRACE(" [%p|%u|%i|%i]",
stack[i].node,stack[i].bit_ofs,
stack[i].attr_idx,stack[i].elmts);
}
TRACE("\n");
}
static bool to_parent(void* ctx)
{
return ((YamlTreeWalker*)ctx)->toParent();
}
static bool to_child(void* ctx)
{
return ((YamlTreeWalker*)ctx)->toChild();
}
static bool to_next_elmt(void* ctx)
{
return ((YamlTreeWalker*)ctx)->toNextElmt();
}
static bool find_node(void* ctx, char* buf, uint8_t len)
{
return ((YamlTreeWalker*)ctx)->findNode(buf,len);
}
static void set_attr(void* ctx, char* buf, uint8_t len)
{
return ((YamlTreeWalker*)ctx)->setAttrValue(buf,len);
}
const YamlParserCalls YamlTreeWalkerCalls = {
to_parent,
to_child,
to_next_elmt,
find_node,
set_attr
};
const YamlParserCalls* YamlTreeWalker::get_parser_calls()
{
return &YamlTreeWalkerCalls;
}
+122
View File
@@ -0,0 +1,122 @@
#ifndef _YAML_TREE_WALKER_H_
#define _YAML_TREE_WALKER_H_
#include <stdint.h>
#include "yaml_node.h"
struct YamlParserCalls;
class YamlTreeWalker
{
struct State {
const YamlNode* node;
uint32_t bit_ofs;
int8_t attr_idx;
uint16_t elmts;
inline uint32_t getOfs() {
return bit_ofs + node->size * elmts;
}
};
State stack[NODE_STACK_DEPTH];
uint8_t stack_level;
uint8_t virt_level;
uint8_t anon_union;
uint8_t* data;
uint32_t getAttrOfs() { return stack[stack_level].bit_ofs; }
uint32_t getLevelOfs() {
if (hasParent()) {
return stack[stack_level + 1].getOfs();
}
return 0;
}
const YamlNode* getParent() {
if (hasParent())
return stack[stack_level + 1].node;
return nullptr;
}
void setNode(const YamlNode* node) { stack[stack_level].node = node; }
void setAttrIdx(uint8_t idx) { stack[stack_level].attr_idx = idx; }
void setAttrOfs(unsigned int ofs) { stack[stack_level].bit_ofs = ofs; }
void incAttr() { stack[stack_level].attr_idx++; }
void incElmts() { stack[stack_level].elmts++; }
bool empty() { return stack_level == NODE_STACK_DEPTH; }
bool full() { return stack_level == 0; }
bool hasParent() { return stack_level < NODE_STACK_DEPTH -1; }
// return true on success
bool push();
bool pop();
// Rewind to the current node's first attribute
// (and reset the bit offset)
void rewind();
public:
YamlTreeWalker();
void reset(const YamlNode* node, uint8_t* data);
int getLevel() {
return NODE_STACK_DEPTH - stack_level
+ virt_level - anon_union;
}
const YamlNode* getNode() {
return stack[stack_level].node;
}
const YamlNode* getAttr() {
int8_t idx = stack[stack_level].attr_idx;
if (idx >= 0)
return &(stack[stack_level].node->u._array.child[idx]);
return NULL;
}
uint16_t getElmts() {
return stack[stack_level].elmts;
}
// Increment the cursor until a match is found or the end of
// the current collection (node of type YDT_NONE) is reached.
//
// return true if a match has been found.
bool findNode(const char* tag, uint8_t tag_len);
// Get the current bit offset
unsigned int getBitOffset();
bool toParent();
bool toChild();
bool toNextElmt();
void toNextAttr();
bool isElmtEmpty(uint8_t* data);
void setAttrValue(char* buf, uint8_t len);
bool generate(yaml_writer_func wf, void* opaque);
void dump_stack();
static const YamlParserCalls* get_parser_calls();
};
// utils
uint32_t yaml_parse_enum(const struct YamlIdStr* choices, const char* val, uint8_t val_len);
const char* yaml_output_enum(int32_t i, const struct YamlIdStr* choices);
#endif