refs #242, allows to change FSX cockpit from context

* Data definitions for FSX events
* BCD conversion for COM and transponder
* Update Cockpit method in context
* Renamed setOwnAircraft -> updateOwnAircraftFromSim
This commit is contained in:
Klaus Basan
2014-05-31 02:24:07 +02:00
parent ba217fed57
commit 035575870b
8 changed files with 194 additions and 26 deletions

View File

@@ -0,0 +1,39 @@
#include "bcdconversions.h"
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Aviation;
namespace BlackSim
{
namespace FsCommon
{
quint32 CBcdConversions::comFrequencyToBcdHz(const BlackMisc::PhysicalQuantities::CFrequency &comFrequency)
{
// FSX documentation is wrong, we need to use kHz + 2 digits, not Hz
quint32 f = comFrequency.valueRounded(CFrequencyUnit::kHz(), 0) / 10;
f = dec2Bcd(f);
return f;
}
quint32 CBcdConversions::transponderCodeToBcd(const BlackMisc::Aviation::CTransponder &transponder)
{
// FSX documentation is wrong, we need to use kHz + 2 digits, not Hz
quint32 t = transponder.getTransponderCode();
t = dec2Bcd(t);
return t;
}
quint32 CBcdConversions::hornerScheme(quint32 num, quint32 divider, quint32 factor)
{
quint32 remainder = 0, quotient = 0, result = 0;
remainder = num % divider;
quotient = num / divider;
if (!(quotient == 0 && remainder == 0))
result += hornerScheme(quotient, divider, factor) * factor + remainder;
return result;
}
} // namespace
} // namespace

View File

@@ -0,0 +1,42 @@
#ifndef BLACKSIM_FSCOMMON_BCDCONVERSIONS_H
#define BLACKSIM_FSCOMMON_BCDCONVERSIONS_H
#include "blackmisc/pqfrequency.h"
#include "blackmisc/aviotransponder.h"
#include <QtGlobal>
namespace BlackSim
{
namespace FsCommon
{
/*!
* \brief BCD conversions for FS
*/
class CBcdConversions
{
public:
//! BCD -> decimal
static quint32 bcd2Dec(quint32 bcdNum) { return hornerScheme(bcdNum, 0x10, 10); }
//! Decimal -> BCD
static quint32 dec2Bcd(quint32 decNum) { return hornerScheme(decNum, 10, 0x10); }
//! COM Frequency to BCD
static quint32 comFrequencyToBcdHz(const BlackMisc::PhysicalQuantities::CFrequency &comFrequency);
//! Transponder code to BCD
static quint32 transponderCodeToBcd(const BlackMisc::Aviation::CTransponder &transponder);
private:
//! Constructor, only static methods
CBcdConversions() {}
//! Horner scheme
static quint32 hornerScheme(quint32 num, quint32 divider, quint32 factor);
};
}
}
#endif // guard