#Correctly wrapping Transponder code

1 messages · Page 1 of 1 (latest)

shrewd skiff
#

hey,
this is more a question for calculator code but since google is terribly useless and LLMS just hallucinate i thought id ask here.
im trying to write code that controls the transponder code with two rotary switches. one for the first two digits and another for the last 2.
now since squaqwk codes only go to 7 when reaching 0 it needs to become 7 and i seam unable to make that conditional work, ive tried the following to check for 0:
(A:TRANSPONDER CODE:1, Number) 100 / floor 10 mod 0 == if{ and (A:TRANSPONDER CODE:1, Bco16) 8 >> 15 & 15 0 == if{(curtesy LLM) but neither work.

Has anyone a idea how to solve this?

subtle cloak
#

which sim and aircraft is this for

shrewd skiff
subtle cloak
#

but how you control the value is specific to sim and aircraft the 737 has dual encoders to set teh code so your controls can just control those directly. panels which feature a keypad design will need more work. some aircrafts internal code will overwrite the default var with whatever is stored in code

shrewd skiff
#

but how you control the value is specific to sim and aircraft
that part isnt entirely correct.
fenix, pmdg and so on add custom LVars ontop and some logic but they work with simvars in the end.
Which is also why volanta and vpilot do not care about your aircraft

subtle cloak
#

yes thats true they write to the default simvar for compatibly but they may not let you write to it as well. however give me a few mins and will work out some examples

shrewd skiff
#

(A:TRANSPONDER CODE:1, Bco16) is writable, my issue is simply checking whether a specific digit has a specific value, setting the value itself works

subtle cloak
#

ok give me a few minutes and i can work out a working example

shrewd skiff
#

thanks 🙏

subtle cloak
#

ok took me a while but finally have working codes
First two digits inc

l0 100 / flr 10 % 64 * + s1
l0 10 / flr 10 % 8 * s2 + 
l0 10 % 1 * s3 + s0
l2 l3 + 1 + 64 % s5
l5 8 / flr s3
l5 8 % flr s4
l0 512 / flr s1
l0 64 / 8 % flr s2
l1 4096 * l2 256 * + l3 16 * + l4 + (>A:TRANSPONDER CODE:1,bco16)```
First two digits dec
```(A:TRANSPONDER CODE:1,number) s0 1000 / flr 512 * 
l0 100 / flr 10 % 64 * + s1
l0 10 / flr 10 % 8 * s2 + 
l0 10 % 1 * s3 + s0
l2 l3 + 63 + 64 % s5
l5 8 / flr s3
l5 8 % flr s4
l0 512 / flr s1
l0 64 / 8 % flr s2
l1 4096 * l2 256 * + l3 16 * + l4 + (>A:TRANSPONDER CODE:1,bco16)```
Last two digits inc
```(A:TRANSPONDER CODE:1,number) s0 1000 / flr 512 * 
l0 100 / flr 10 % 64 * + s1
l0 10 / flr 10 % 8 * s2 + 
l0 10 % 1 * s3 +
l2 l3 + 1 + 63 % l1 + s0
l0 512 / flr s1
l0 64 / 8 % flr s2
l0 8 / 8 % flr s3
l0 8 % flr s4
l1 4096 * l2 256 * + l3 16 * + l4 + (>A:TRANSPONDER CODE:1,bco16)```
Last two digits dec
```(A:TRANSPONDER CODE:1,number) s0 1000 / flr 512 * 
l0 100 / flr 10 % 64 * + s1
l0 10 / flr 10 % 8 * s2 + 
l0 10 % 1 * s3 +
l2 l3 + 1 - 63 % l1 + s0
l0 512 / flr s1
l0 64 / 8 % flr s2
l0 8 / 8 % flr s3
l0 8 % flr s4
l1 4096 * l2 256 * + l3 16 * + l4 + (>A:TRANSPONDER CODE:1,bco16)```
subtle cloak
#

tested in the a300, fbw a320 & pmdg 737 all working ok

elder marlin
#

I haven't really analyzed the conversion code to get bco16. I would suggest letting the simulator do the conversion. I did this some time ago.
Store the decimal number to a user specified Lvar with units of number, then when the code has been completed, turn around and send this same lvar, now with units of bco16 to the A:TRANSPONDER CODE variable.

shrewd skiff
shrewd skiff
#

Heyhey,
the last two digits work perfectly, but the first two, thousands and hundreds seam to also decrease/increase the last two.
I tried to play around with l2 l3 + 1 + 64 % s5 and l2 l3 + 63 + 64 % s5
but to no luck and frankly, i tried understanding what it does but couldnt sorry...so im reaching out again.

subtle cloak
#

I'm currently away from my SIM this week. But I'll take a look when I can

elder marlin
#

For 1 2 digits DEC

(A:TRANSPONDER CODE:1,number) 100 / flr sp0
l0 10 % 0 == if{ l0 3 - } els{ l0 1 - } 0 max 77 min s0
l0 100 * (A:TRANSPONDER CODE:1,number) 100 % + (>L:XPNDR_TEMP,number)
(L:XPNDR_TEMP,bco16) (>A:TRANSPONDER CODE:1,bco16)
#

For 1 2 digits INC

(A:TRANSPONDER CODE:1,number) 100 / flr sp0
l0 10 % 7 == if{ l0 3 + } els{ l0 1 + } 0 max 77 min sp0
l0 100 * (A:TRANSPONDER CODE:1,number) 100 % + (>L:XPNDR_TEMP,number)
(L:XPNDR_TEMP,bco16) (>A:TRANSPONDER CODE:1,bco16)
#

Digits 3 4 DEC

(A:TRANSPONDER CODE:1,number) 100 % sp0
l0 10 % 0 == if{ l0 3 - } els{ l0 1 - } 0 max 77 min sp0
(A:TRANSPONDER CODE:1,number) 100 / flr 100 * l0 + (>L:XPNDR_TEMP,number)
(L:XPNDR_TEMP,bco16) (>A:TRANSPONDER CODE:1,bco16)
#

Digits 3 4 INC

(A:TRANSPONDER CODE:1,number) 100 % sp0
l0 10 % 7 == if{ l0 3 + } els{ l0 1 + } 0 max 77 min sp0
(A:TRANSPONDER CODE:1,number) 100 / flr 100 * l0 + (>L:XPNDR_TEMP,number)
(L:XPNDR_TEMP,bco16) (>A:TRANSPONDER CODE:1,bco16)
#

this code does not wrap around the number

shrewd skiff
elder marlin
shrewd skiff
#

nvm works now after your edit

elder marlin
#

yeah, I edited about one hour ago after reviewing again the code, it seems I copied an old version

shrewd skiff
#

All good

#

i assume l0, sp0, s0 have to do with storing and loading some kind of variables?

elder marlin
#

I since modified the code to do the wrap around, so it goes from 7700 to 0000

shrewd skiff
#

🙏 Thanks

elder marlin
#

would you like that version?

shrewd skiff
#

no this is fine

elder marlin
shrewd skiff
#

sp is store and pop

elder marlin
#

sp0 = store in register 0, popping value from the stack

#

l0 = load from register 0 to top of stack

shrewd skiff
#

makes sense

#

is there a good resource to get deeper into calculator code? i dont see much in the doc for msfs

elder marlin
#

there is an RPN guide in the msfs sdk website

shrewd skiff
#

ah okay, then i didnt look deep enough yet.

shrewd skiff
#

thanks!

#

Thank you both very much for the great help!