BCD/decimal conversion
As Flight Simulator published radio freqencies in BCD, it is necessary to convert them before computing frequency change.
Note: frequencies are not fully published in BCD. For example, for COM frequencies (VHF freq), the initial “1″ is not published, the central dot is not, and the final “5″ or “0″ is also not. FS assumes that 118.075 BCD equivalent is 1807.
Here is an extract from convlib.cpp (OnePanel software):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | long bcd2dec(DWORD unsigned long bcd) { unsigned long dec=0; int size,f,g; size = (bcd > 32768) ? 16 : 4 ; int p=1; for (f=0;f<size;f++) { dec+=(bcd%10)*p; bcd=bcd/10; p*=16; } return dec; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | long dec2bcd(DWORD unsigned long dec) { unsigned long bcd=0; int size,f; int p=1; size = (dec > 65536) ? 16 : 4 ; for (f=0;f<size;f++) { bcd+=((dec>>(f*4)) & 15)*p; p*=10; } return bcd; } |
Related posts:
- Howto access and publish addon specific variables with FSUIPC Flight Simulator addons often have specific internal variables that are not published in FSUIPC standard offsets. These values could be interresting for cockpit building. For example, A2A P47 addon does...
- Arduino encoder library Encoder library is published by pjrc The code #include "Encoder.h" Encoder encoder(2, 4); void setup() { attachInterrupt(0, doEncoder, CHANGE); Serial.begin (115200); Serial.println("start"); } void loop(){ // do some stuff here...
- Access Variables/Property tree in FS,FlightGear and XPlane How to talk with your simulator ? Add-ons developper or cockpit builders have to access flight simulator variables, to mange or display them. If coding is not your cup of...