feat: Support for 8s Cell Sensor such as FrSky FLVS ADV (#2302)

* first commit for FrSky 8s Lipo Sensor

FLVS Advanced transfers up to 8 cell voltages for Cels sensor

* correcting mistake made transferring local change to PR

* complementary extension of Companion telemetry simulator to enable simulation of  8 cells

* change to allow selection of cells 7 and 8 in calculated sensor with formula Cell

* (cpn) Add bin and yml conversions and basic semantic version helper

Co-authored-by: elecpower <neilh713@tpg.com.au>
This commit is contained in:
Michael
2022-09-27 20:06:26 +10:00
committed by GitHub
co-authored by elecpower
parent 513578643c
commit 73861554ec
27 changed files with 255 additions and 22 deletions
@@ -34,6 +34,7 @@
#include "output_data.h"
#include "eeprominterface.h"
#include "version.h"
#include "helpers.h"
#include <string>
@@ -1140,6 +1141,19 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
node["functionSwitchStartConfig"] >> rhs.functionSwitchStartConfig;
node["functionSwitchLogicalState"] >> rhs.functionSwitchLogicalState;
node["switchNames"] >> rhs.functionSwitchNames;
// preferably perform conversions here to avoid cluttering the field decodes
if (SemanticVersion(QString(rhs.semver)) < SemanticVersion("2.8.0")) {
// Cells 7 and 8 introduced requiring Highest and Delta to be shifted + 2
for (int i = 0; i < CPN_MAX_SENSORS; i++) {
SensorData &sd = rhs.sensorData[i];
if (!sd.isEmpty() && sd.type == SensorData::TELEM_TYPE_CALCULATED &&
sd.formula == SensorData::TELEM_FORMULA_CELL && sd.index > 6)
sd.index += 2;
}
}
return true;
}
@@ -2066,6 +2066,12 @@ class SensorField: public TransformedField {
}
}
// Cells 7 and 8 introduced in v2.8 requiring Highest and Delta to be shifted + 2
if (version < 221) {
if (sensor.formula == SensorData::TELEM_FORMULA_CELL && sensor.index > 6)
sensor.index += 2;
}
qCDebug(eepromImport) << QString("imported %1").arg(internalField.getName());
}
+2
View File
@@ -76,6 +76,8 @@ class SensorData {
TELEM_CELL_INDEX_4,
TELEM_CELL_INDEX_5,
TELEM_CELL_INDEX_6,
TELEM_CELL_INDEX_7,
TELEM_CELL_INDEX_8,
TELEM_CELL_INDEX_HIGHEST,
TELEM_CELL_INDEX_DELTA,
TELEM_CELL_INDEX_LAST = TELEM_CELL_INDEX_DELTA
+84
View File
@@ -726,3 +726,87 @@ QString Helpers::removeAccents(const QString & str)
}
return result;
}
SemanticVersion::SemanticVersion(QString vers)
{
if (!isValid(vers))
return;
QStringList strl = vers.split(".");
version.major = strl.at(0).toInt();
version.minor = strl.at(1).toInt();
if (strl.count() > 2) {
if (!strl.at(2).contains("-")) {
version.patch = strl.at(2).toInt();
} else {
QStringList ptch = strl.at(2).toLower().split("-");
version.patch = ptch.at(0).toInt();
if (ptch.at(1).left(2) == "rc") {
version.preReleaseType = PR_RC;
version.preReleaseNumber = ptch.at(1).mid(2).toInt();
} else if (ptch.at(1).left(5) == "alpha") {
version.preReleaseType = PR_ALPHA;
version.preReleaseNumber = ptch.at(1).mid(5).toInt();
} else if (ptch.at(1).left(4) == "beta") {
version.preReleaseType = PR_BETA;
version.preReleaseNumber = ptch.at(1).mid(4).toInt();
}
}
}
}
bool SemanticVersion::isValid(QString vers)
{
if (vers.trimmed().isEmpty())
return false;
QStringList strl = vers.split(".");
if (strl.count() < 2)
return false;
return true;
}
QString SemanticVersion::toString() const
{
QString ret(QString("%1.%2.%3").arg(version.major).arg(version.minor).arg(version.patch));
if (version.preReleaseType != PR_NONE) {
ret.append("-");
if (version.preReleaseType == PR_RC)
ret.append("RC");
else if (version.preReleaseType == PR_ALPHA)
ret.append("ALPHA");
else if (version.preReleaseType == PR_BETA)
ret.append("BETA");
ret.append(QString::number(version.preReleaseNumber));
}
return ret;
}
int SemanticVersion::compare(const SemanticVersion& other)
{
if (version.major != other.version.major) {
return version.major - other.version.major;
}
if (version.minor != other.version.minor) {
return version.minor - other.version.minor;
}
if (version.patch != other.version.patch) {
return version.patch - other.version.patch;
}
if (version.preReleaseType != other.version.preReleaseType) {
return version.preReleaseType - other.version.preReleaseType;
}
if (version.preReleaseNumber != other.version.preReleaseNumber) {
return version.preReleaseNumber - other.version.preReleaseNumber;
}
return 0;
}
+55
View File
@@ -240,3 +240,58 @@ private:
};
extern Stopwatch gStopwatch;
class SemanticVersion
{
public:
explicit SemanticVersion(QString vers);
~SemanticVersion() = default;;
bool isValid(const QString vers);
QString toString() const;
bool operator==(const SemanticVersion& rhs) {
return compare(rhs) == 0;
}
bool operator!=(const SemanticVersion& rhs) {
return compare(rhs) != 0;
}
bool operator>(const SemanticVersion& rhs) {
return compare(rhs) > 0;
}
bool operator>=(const SemanticVersion& rhs) {
return compare(rhs) >= 0;
}
bool operator<(const SemanticVersion& rhs) {
return compare(rhs) < 0;
}
bool operator<=(const SemanticVersion& rhs) {
return compare(rhs) <= 0;
}
private:
enum PreRelease {
PR_ALPHA = 0,
PR_BETA = 1,
PR_RC = 2,
PR_NONE = 3
};
struct Version {
int major = 0;
int minor = 1;
int patch = 0;
PreRelease preReleaseType = PR_NONE;
int preReleaseNumber = 0;
};
Version version;
int compare(const SemanticVersion& other);
};
+19 -1
View File
@@ -442,6 +442,8 @@ void TelemetrySimulator::generateTelemetryFrame()
cellValues[3] = ui->cell4->value();
cellValues[4] = ui->cell5->value();
cellValues[5] = ui->cell6->value();
cellValues[6] = ui->cell7->value();
cellValues[7] = ui->cell8->value();
generateSportPacket(buffer, ui->cells_inst->text().toInt(&ok, 0) - 1, DATA_FRAME, CELLS_FIRST_ID, flvss->setAllCells_GetNextPair(cellValues));
}
else {
@@ -547,6 +549,7 @@ void TelemetrySimulator::FlvssEmulator::encodeAllCells()
cellData1 = encodeCellPair(numCells, 0, cellFloats[0], cellFloats[1]);
if (numCells > 2) cellData2 = encodeCellPair(numCells, 2, cellFloats[2], cellFloats[3]); else cellData2 = 0;
if (numCells > 4) cellData3 = encodeCellPair(numCells, 4, cellFloats[4], cellFloats[5]); else cellData3 = 0;
if (numCells > 6) cellData4 = encodeCellPair(numCells, 6, cellFloats[6], cellFloats[7]); else cellData4 = 0;
}
void TelemetrySimulator::FlvssEmulator::splitIntoCells(double totalVolts)
@@ -564,7 +567,7 @@ void TelemetrySimulator::FlvssEmulator::splitIntoCells(double totalVolts)
numCells = numCells > MAXCELLS ? MAXCELLS : numCells; // force into valid cell count in case of input out of range
}
uint32_t TelemetrySimulator::FlvssEmulator::setAllCells_GetNextPair(double cellValues[6])
uint32_t TelemetrySimulator::FlvssEmulator::setAllCells_GetNextPair(double cellValues[MAXCELLS])
{
numCells = 0;
for (uint32_t i = 0; i < MAXCELLS; i++) {
@@ -603,6 +606,9 @@ uint32_t TelemetrySimulator::FlvssEmulator::setAllCells_GetNextPair(double cellV
case 4:
cellData = cellData3;
break;
case 6:
cellData = cellData4;
break;
}
nextCellNum += 2;
return cellData;
@@ -1198,6 +1204,10 @@ void TelemetrySimulator::on_saveTelemetryvalues_clicked()
out<<"\r\n";
out << ui -> cell6 -> text();
out<<"\r\n";
out << ui -> cell7 -> text();
out<<"\r\n";
out << ui -> cell8 -> text();
out<<"\r\n";
out << ui -> aspeed -> text();
out<<"\r\n";
out << ui -> gps_alt -> text();
@@ -1330,6 +1340,14 @@ void TelemetrySimulator::on_loadTelemetryvalues_clicked()
ns = n.toDouble();
ui -> cell6 -> setValue(ns);
n = in.readLine();
ns = n.toDouble();
ui -> cell7 -> setValue(ns);
n = in.readLine();
ns = n.toDouble();
ui -> cell8 -> setValue(ns);
n = in.readLine();
ns = n.toDouble();
ui -> aspeed -> setValue(ns);
+4 -3
View File
@@ -171,19 +171,20 @@ class TelemetrySimulator : public QWidget
class FlvssEmulator
{
public:
uint32_t setAllCells_GetNextPair(double cellValues[6]);
static const uint32_t MAXCELLS = 6;
static const uint32_t MAXCELLS = 8;
uint32_t setAllCells_GetNextPair(double cellValues[MAXCELLS]);
private:
void encodeAllCells();
void splitIntoCells(double totalVolts);
static uint32_t encodeCellPair(uint8_t cellNum, uint8_t firstCellNo, double cell1, double cell2);
double cellFloats[6];
double cellFloats[MAXCELLS];
uint32_t nextCellNum;
uint32_t numCells;
uint32_t cellData1;
uint32_t cellData2;
uint32_t cellData3;
uint32_t cellData4;
}; // FlvssEmulator
class GPSEmulator
+50
View File
@@ -2587,6 +2587,54 @@ hh:mm:ss</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QDoubleSpinBox" name="cell7">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="maximum">
<double>8.190000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value">
<double>4.200000000000000</double>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="cell8">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="maximum">
<double>8.190000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value">
<double>4.200000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item row="6" column="2">
@@ -3184,6 +3232,8 @@ Timestamp</string>
<tabstop>cell4</tabstop>
<tabstop>cell5</tabstop>
<tabstop>cell6</tabstop>
<tabstop>cell7</tabstop>
<tabstop>cell8</tabstop>
<tabstop>aspd_inst</tabstop>
<tabstop>aspeed</tabstop>
<tabstop>gpsa_inst</tabstop>