davidfournier1969 Posted October 13, 2014 Report Posted October 13, 2014 I have been working on a script to drive the latest in Garmin's portables, the area 796. I have the Garmin Interface Control Document and have about 90% of the moving map working. Note - The unit does seem to partially work with the FSUIPC AV400 format, but acts strange sometimes. I just decided to rewrite the entire interface using Lua and really haven't had much trouble until now. How would the latitude/longitude offsets be treated in Lua to convert them from decimal degrees, to degrees, minutes, and hundredths of minutes? The only thing I can think of is some kind of bit masking/logic routine to split apart the integer degree value from the decimal degree value. Then I could perform the necessary calculations, etc to take it down to ddd mmhh (2 or three digit degrees, two digit minutes, followed immediately by two digit hundredths of minutes). It seems like string handling in Lua isn't one of it's strong parts. I'm happy to share the full Interface control document with anyone that wants it. It's just part of a bigger document for an install of a real GNS 530. I'm not even sure why it's in there. Any thoughts? In a nutshell, ddd.ddddddd each from FSX latitude/longitude offsets to a format of ddd mmhh to be sent to the Garmin. I already have the N, S, E, W, signing figured out, along with everything else the unit needs to display own aircraft speed, altitude, track and flight plans. Thanks in advance. Dave
Pete Dowson Posted October 13, 2014 Report Posted October 13, 2014 How would the latitude/longitude offsets be treated in Lua to convert them from decimal degrees, to degrees, minutes, and hundredths of minutes? The only thing I can think of is some kind of bit masking/logic routine to split apart the integer degree value from the decimal degree value. Then I could perform the necessary calculations, etc to take it down to ddd mmhh (2 or three digit degrees, two digit minutes, followed immediately by two digit hundredths of minutes). It seems like string handling in Lua isn't one of it's strong parts. In a nutshell, ddd.ddddddd each from FSX latitude/longitude offsets to a format of ddd mmhh to be sent to the Garmin. I already have the N, S, E, W, signing figured out, along with everything else the unit needs to display own aircraft speed, altitude, track and flight plans. You would best handle it all in numeric form, not in string form. Then compute degrees = math.floor(value) minutes = 60*(value - degrees) Then just use the string.format features in the usual way, as in C etc. Pete
davidfournier1969 Posted October 13, 2014 Author Report Posted October 13, 2014 Thanks Pete, your calcs work great. Here's what I have for the longitutde: lon = ipc.readDBL(0x6018); londegs = math.floor(lon); lonmins = 60*(lon - londegs); lonminstr = string.format("&04f", lonmins); com.write(dev, lonminstr, 4); to format the minutes 4 digit field as a string, but I can't seem to get rid of the decimal. it's giving me 7.38 instead of the needed 0738.
Pete Dowson Posted October 13, 2014 Report Posted October 13, 2014 Thanks Pete, your calcs work great. Here's what I have for the longitutde: lon = ipc.readDBL(0x6018); londegs = math.floor(lon); lonmins = 60*(lon - londegs); lonminstr = string.format("&04f", lonmins); com.write(dev, lonminstr, 4); to format the minutes 4 digit field as a string, but I can't seem to get rid of the decimal. it's giving me 7.38 instead of the needed 0738. Oh, in that case you would need to change the last but one line there to lonmins = 6000*(lon - londegs) or even lonmins = math.floor(6000*(lon - londegs)) BTW Lua does not need ; at the end of each statement. They do no harm though. Pete
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now