Jump to content
The simFlight Network Forums

reading nav frequency


Recommended Posts

I use readSW(0x0350) to read nav1 but all i get is a number like 4976 (for 113.700). Can someone explain me what i am doing wrong here? I am a PHP developer and this is going to me my first try with lua so dont blame me for not know that please :)

Link to comment
Share on other sites

I use readSW(0x0350) to read nav1 but all i get is a number like 4976 (for 113.700). Can someone explain me what i am doing wrong here?

It is all precisely as documented, FS stored the frequencies in "BCD" (binary coded decimal), and only the 4 digits: 1370 in your example. The 100 digit is taken as read.

Hex 0x1370 = decimal 4976. But you don't want the decimal. You want the separate groups of 4 bits for each digit.

Hes 1370 is made up of 16 bits which are viewed in groups of 4, each running for 0 to F (A-F are used to represent 10-15). In this case, because they represent decimal numbers, you'll never see A-F in any case.

If you want to convert to a string for display, you either need to use logical shifts and 'ands' to isolate each 4 bits and convert those to characters, or more easily, use the string.format function in Lua to get the hex digits in printable form, like:

str = string.format("1%02X.%02X", math.floor(value/256), math.mod(value,256))

I've not tested that, mind, but you should get the idea.

Pete

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.