mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-16 02:06:08 +08:00
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:
39
src/blacksim/fscommon/bcdconversions.cpp
Normal file
39
src/blacksim/fscommon/bcdconversions.cpp
Normal 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
|
||||
42
src/blacksim/fscommon/bcdconversions.h
Normal file
42
src/blacksim/fscommon/bcdconversions.h
Normal 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
|
||||
Reference in New Issue
Block a user