WiP: write basic model data and models list

This commit is contained in:
Raphael Coeffic
2021-12-31 10:53:09 +01:00
parent a7781deb6a
commit b73ffb5e08
9 changed files with 298 additions and 115 deletions
@@ -21,7 +21,7 @@
#include "yaml_modeldata.h"
#include "modeldata.h"
const YamlLookupTable timerModeLut = {
static const YamlLookupTable timerModeLut = {
{TimerData::TIMERMODE_OFF, "OFF"},
{TimerData::TIMERMODE_ON, "ON"},
{TimerData::TIMERMODE_START, "START"},
@@ -30,7 +30,7 @@ const YamlLookupTable timerModeLut = {
{TimerData::TIMERMODE_THR_START, "THR_START"},
};
const YamlLookupTable trainerModeLut = {
static const YamlLookupTable trainerModeLut = {
{ TRAINER_MODE_OFF, "OFF" },
{ TRAINER_MODE_MASTER_JACK, "MASTER_TRAINER_JACK" },
{ TRAINER_MODE_SLAVE_JACK, "SLAVE" },
@@ -41,3 +41,172 @@ const YamlLookupTable trainerModeLut = {
{ TRAINER_MODE_SLAVE_BLUETOOTH, "SLAVE_BT" },
{ TRAINER_MODE_MULTI, "MASTER_MULTI" },
};
namespace YAML
{
Node convert<TimerData>::encode(const TimerData& rhs)
{
Node node;
node["swtch"] = rhs.swtch;
node["mode"] = timerModeLut << rhs.mode;
node["name"] = rhs.name;
node["minuteBeep"] = rhs.minuteBeep;
node["countdownBeep"] = rhs.countdownBeep;
node["start"] = rhs.val;
node["persistent"] = rhs.persistent;
node["countdownStart"] = rhs.countdownStart;
node["value"] = rhs.pvalue;
return node;
}
bool convert<TimerData>::decode(const Node& node, TimerData& rhs)
{
node["swtch"] >> rhs.swtch;
node["mode"] >> timerModeLut >> rhs.mode;
node["name"] >> rhs.name;
node["minuteBeep"] >> rhs.minuteBeep;
node["countdownBeep"] >> rhs.countdownBeep;
node["start"] >> rhs.val;
node["persistent"] >> rhs.persistent;
node["countdownStart"] >> rhs.countdownStart;
node["value"] >> rhs.pvalue;
return true;
}
Node convert<ModelData>::encode(const ModelData& rhs)
{
Node node;
node["header"]["name"] = rhs.name;
node["header"]["bitmap"] = rhs.bitmap;
// TODO: modelId
for (int i=0; i<CPN_MAX_TIMERS; i++) {
Node timer;
timer = rhs.timers[i];
node["timers"][std::to_string(i)] = timer;
}
node["noGlobalFunctions"] = rhs.noGlobalFunctions;
node["thrTrim"] = rhs.thrTrim;
node["trimInc"] = rhs.trimInc;
node["displayTrims"] = rhs.trimsDisplay;
node["disableThrottleWarning"] = rhs.disableThrottleWarning;
// node[] = rhs.beepANACenter;
node["extendedLimits"] = rhs.extendedLimits;
node["extendedTrims"] = rhs.extendedTrims;
node["throttleReversed"] = rhs.throttleReversed;
// flightModeData[]
// mixData[]
// limitData[]
// inputNames[]
// expoData[]
// curves[]
// logicalSw[]
// customFn[]
// swashRingData
// thrTraceSrc
// switchWarningStates
// thrTrimSwitch
// potsWarningMode
// potsWarnEnabled[]
// potsWarnPosition[]
node["displayChecklist"] = rhs.displayChecklist;
// gvarData[]
// mavlink ???
// telemetryProtocol ???
// frsky
// rssiSource
// rssiAlarms
node["trainerMode"] = trainerModeLut << rhs.trainerMode;
// moduleData[]
// scriptData[]
// sensorData[]
node["toplcdTimer"] = rhs.toplcdTimer;
// customScreens
// topBarData
node["view"] = rhs.view;
node["modelRegistrationID"] = rhs.registrationId;
return node;
}
bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
{
if (!node.IsMap()) return false;
if (node["header"]) {
const auto& header = node["header"];
if (!header.IsMap()) return false;
header["name"] >> rhs.name;
header["bitmap"] >> rhs.bitmap;
// TODO: modelId
}
if (node["timers"]) {
const auto& timers = node["timers"];
if (!timers.IsMap()) return false;
timers >> rhs.timers;
}
node["noGlobalFunctions"] >> rhs.noGlobalFunctions;
node["thrTrim"] >> rhs.thrTrim;
node["trimInc"] >> rhs.trimInc;
node["displayTrims"] >> rhs.trimsDisplay;
node["disableThrottleWarning"] >> rhs.disableThrottleWarning;
// node[] >> rhs.beepANACenter;
node["extendedLimits"] >> rhs.extendedLimits;
node["extendedTrims"] >> rhs.extendedTrims;
node["throttleReversed"] >> rhs.throttleReversed;
// flightModeData[]
// mixData[]
// limitData[]
// inputNames[]
// expoData[]
// curves[]
// logicalSw[]
// customFn[]
// swashRingData
// thrTraceSrc
// switchWarningStates
// thrTrimSwitch
// potsWarningMode
// potsWarnEnabled[]
// potsWarnPosition[]
node["displayChecklist"] >> rhs.displayChecklist;
// gvarData[]
// mavlink ???
// telemetryProtocol ???
// frsky
// rssiSource
// rssiAlarms
node["trainerMode"] >> trainerModeLut >> rhs.trainerMode;
// moduleData[]
// scriptData[]
// sensorData[]
node["toplcdTimer"] >> rhs.toplcdTimer;
// customScreens
// topBarData
node["view"] >> rhs.view;
node["modelRegistrationID"] >> rhs.registrationId;
return true;
}
} // namespace YAML