Jump to content
The simFlight Network Forums

Recommended Posts

Posted

I'm having a couple of problems as I try to implement FS2K2 COM radio freq changing via rotaries.

1. I have a rotary decoder that runs through a 64 button USB input device. This input is translated to keypress macros by a helper application (KB emulator). Using the (latest) FSUIPC Options "Keys" tab I mapped some key combinations to various selections. I found that ADF and NAV mapping worked perfectly but many coms did not: e.g. selecting "com stdby whole increase" from the dropdown actually caused the selected keypress to map to the pilot's AP course selector and "com stdby fract increase mapped to the copilot's AP course selector. Is the "keys" function of FSUIPC a "caveat emptor" area throughout with regard to FS2K2? If so, has anyone charted the dropdown selections and created a mappings table that shows what each selection really does in FS2K2?

2. Offset 034E (and similar) are described as "4 digits in BCD format. A freq of 123.45 is represented by 0x2345. The leading 1 is assumed." Well when I read that offset and display the value in my vb.net test procedure I get (e.g.) "6567" for the offset value with the FS COM1 freq set to 120.07. This looks like some combination of BCD and Hex conversion but I just can't solve the puzzle. I want to increment/dec either the "(1)20" or the ".07" when the rotary turns but how do I manipulate "6567" to accomplish this in my sub that captures the rotary input i.e. what is the formula for conversion? This is probably incredibly obvious but it is escaping me (straight hex conversion was close as decimal 6567 = 19A7h, but I would then have to parse each digit of the resultant hex # and if >9 set to 0 and carry left...got rather involved and I expect there must be an easier way).

Thanks for any help you can provide!

Scott

Posted
I found that ADF and NAV mapping worked perfectly but many coms did not: e.g. selecting "com stdby whole increase" from the dropdown actually caused the selected keypress to map to the pilot's AP course selector and "com stdby fract increase mapped to the copilot's AP course selector. Is the "keys" function of FSUIPC a "caveat emptor" area throughout with regard to FS2K2? If so, has anyone charted the dropdown selections and created a mappings table that shows what each selection really does in FS2K2?

My Latin is a bit rusty, but if you mean has anyone tried all the possible FS controls listed in CONTROLS.DLL (which is where FSUIPC gets them) and reported on the results, then the answer is no. Do you want to volunteer for this?

It is rather odd to find that these are mapped so oddly inside FS. But I think you'll find that the plain "COM RADIO ..." (i.e. not the Standby) controls do actually operate the Standby.

It is not surprising that MS did not bring all these controls through to the user interface for assignment in their own dialogues!

Offset 034E (and similar) are described as "4 digits in BCD format. A freq of 123.45 is represented by 0x2345. The leading 1 is assumed." Well when I read that offset and display the value in my vb.net test procedure I get (e.g.) "6567" for the offset value with the FS COM1 freq set to 120.07.

You definitely have some errors in your code then. 120.07 would be encoded as 0x2007 which is 8199 in decimal. You cannot get 6567 from any BCD encoding as this is 0x19A7 and the digit "A" has no place in BCD.

Just think of BCD as having 4 bits per digit. i.e. 0x2007 is, bit by bit:

0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 1

If you AND the value with 15 (1 1 1 1 in binary) you'll get the last digit as a number (7) in this case. Add the character '0' to this and you get the character '7' for display. Repeated shift down by 4 bits and do the same again and you get the correct characters for the other three. Insert the decimal point and add the leading '1' and you are there.

This BCD method of encoding frequencies in FS has been the same now for many many years and there are plenty of applications using it with no problems. Stop thinking numerically, think of it as merely packing characters into smaller spaces, and just unpack it as I suggest.

I would then have to parse each digit of the resultant hex # and if >9 set to 0 and carry left...got rather involved and I expect there must be an easier way).

No, there's no shortcuts if you want to increment and decrement BCD. And remember that many of the frequencies are invalid. The last digit can only be 0, 2, 5, or 7. These represent 0.000, 0.025 0.050 and 0.075 so if you want to do it numerically you would have to convert something like 0x2007 to decimal 20070 then increment by 25 and convert back again, ignoring the last digit (0 or 5).

To convert 0x2007 to decimal 20070 you'd take the value of the top 4 bits (2) and multiply by 10000 then the next 4 and multiply by 1000 and add, and so on. Vice versa converting back -- you use division, on the remainders each time.

Pete

Posted

[**My Latin is a bit rusty, but if you mean has anyone tried all the possible FS controls listed in CONTROLS.DLL (which is where FSUIPC gets them) and reported on the results, then the answer is no. Do you want to volunteer for this? **]

I will be happy to report all of my results when finished as the more of these I can use the less code I have to write !

[**You definitely have some errors in your code then. 120.07 would be encoded as 0x2007 which is 8199 in decimal. You cannot get 6567 from any BCD encoding as this is 0x19A7 and the digit "A" has no place in BCD.**]

I used the 'stock' code from the FSUIPC vb.net sdk for read/write/process/get. Here is an example read function. The reference to the variable FSCOM1 is passed to this function which reads the offset from fsuipc and passes it to the ref:

Private Function ReadCOM1(ByRef _FSCOM1 As Integer, ByRef _intError As Integer) As Boolean

'Declare Vars

Dim blnStatus As Boolean

Dim t_FSCOM1 As Integer 'token

'Do Stuff

blnStatus = myFSUIPC.FSUIPC_Read(&H34E, 2, t_FSCOM1, _intError) 'Obtain COM1 setting (2 bytes at offset 034E)

If blnStatus Then

'Read Successful

blnStatus = myFSUIPC.FSUIPC_Process(_intError)

If blnStatus Then

'Process Successful

blnStatus = myFSUIPC.FSUIPC_Get(t_FSCOM1, _FSCOM1)

If blnStatus Then

'Get Successful

Return True

End If

End If

End If

If Not blnStatus Then

'Error Occured

Return False

End If

End Function 'ReadCOM1

The read is successful (I convert the result to string and display) but I don't get a BCD! However hexing what I do get yields the BCD or close to it e.g. for 120.60 in COM1 I get 8288 as a result (hex of 8288 = 2060).

Is there an error in the vb.net sdk? Although my example uses its functions as class methods I got the same results using the sdk itself as an executable app.

Thanks for the great treatise on BCD. I just need to actually FIND the BCD so I can manipulate it!

Can any vb.net programmers chip in here as well? A good bit of the "under the hood" stuff in the sdk is over my head!

Thanks,

Scott

Posted
[i used the 'stock' code from the FSUIPC vb.net sdk for read/write/process/get.

I'm not saying you are in error READING the value, only in interpreting it. It is no use showing me examples of VB.anything, I'm afraid. If your code is in error I hope someone who uses this language can jump in and help you. But I am not he, sorry.

The read is successful (I convert the result to string and display) but I don't get a BCD! However hexing what I do get yields the BCD or close to it e.g. for 120.60 in COM1 I get 8288 as a result (hex of 8288 = 2060).

You are therefore not understanding what "BCD" means. 120.60 is represented in BCD by 0x2060 which is decimal 8288. so when you read 8288 this is correct for a frequency of 120.60. What can be more obvious than this? You already just proved it to yourself!!

Please use FSInterrogate where you can see the values read in all sorts of formats, all at once! Then maybe you will understand?

Thanks for the great treatise on BCD. I just need to actually FIND the BCD so I can manipulate it!

If you get 8288 in decimal as you say, this IS the BCD (Binary-Coded-Decimal) version of 2060 as in hex it is 0x2060, as you already so clearly pointed out! Why are you asking HOW to "get the BCD" when you've "got it"?????

Pete

Posted
[You are therefore not understanding what "BCD" means. 120.60 is represented in BCD by 0x2060 which is decimal 8288. so when you read 8288 this is correct for a frequency of 120.60. What can be more obvious than this? You already just proved it to yourself!!

If you get 8288 in decimal as you say, this IS the BCD (Binary-Coded-Decimal) version of 2060 as in hex it is 0x2060, as you already so clearly pointed out! Why are you asking HOW to "get the BCD" when you've "got it"?????

Pete

A thousand apologies...I had reasoned this out exactly as you say but then somehow miscopied the value 6567 for 120.07! I couldn't fit this into the paradigm - but only because it is a mistake. The actual BCD conversion is 8199 as confirmed by my sample app and binary calculator. Arrrrrggh!

OK, now I need to write the function to parse the digits and then case test, etc. Thanks for your help!

Scott

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.