Keith's LUA Help thread.

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Message
Author
User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Keith's LUA Help thread.

#251 Post by Keith Baxter »

Ralph wrote: Sat Feb 13, 2021 6:13 am tostring() ? Or wasn't that what you mean?
Hi no not that easy Ralph.

I have this xplane dataref. sim/cockpit2/tcas/targets/modeS_id int[64] y integer 24bit (0-16777215 or 0 - 0xFFFFFF) unique ID of the airframe. This is also known as the ADS-B "hexcode"

How to convert this to text??
I did try and look it up. This does not work so I am sure I am way off.

Code: Select all

local hex_to_char = {}
for idx = 0, 255 do
    hex_to_char[("%02X"):format(idx)] = string.char(idx)
    hex_to_char[("%02x"):format(idx)] = string.char(idx)
end
Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Keith's LUA Help thread.

#252 Post by Keith Baxter »

Hi,

I think this refers to what the dataref is indicating.

https://en.wikipedia.org/wiki/Aviation_ ... tion_modes

Code: Select all

ICAO 24-bit address
Mode S equipped aircraft are assigned a unique ICAO 24-bit address or (informally) Mode-S "hex code" upon national registration and this address becomes a part of the aircraft's Certificate of Registration. Normally, the address is never changed, however, the transponders are reprogrammable and, occasionally, are moved from one aircraft to another (presumably for operational or cost purposes), either by maintenance or by changing the appropriate entry in the aircraft's Flight management system.

There are 16,777,214 (224-2) unique ICAO 24-bit addresses (hex codes) available.[4][5] The ICAO 24-bit address can be represented in three digital formats: hexadecimal, octal, and binary. These addresses are used to provide a unique identity normally allocated to an individual aircraft or registration.

As an example, following is the ICAO 24-bit address assigned to the Shuttle Carrier Aircraft with the registration N905NA:[6][7]

Hexadecimal: AC82EC
Octal: 53101354
Binary: 101011001000001011101100 (Note: occasionally, spaces are added for visual clarity, thus 1010 1100 1000 0010 1110 1100 {Hex big endian} and 001 101 110 100 000 100 110 101 {Octal little endian})
Decimal: 11305708
These are all the same 24-bit address of the Shuttle Carrier Aircraft, represented in different numeral systems (see above).[Codebox=text file=Untitled.txt][/Codebox]

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Keith's LUA Help thread.

#253 Post by Sling »

Keith,

This has been about for ages so it's not specifically an ADSB thing. Normally you apply to your local regulator everytime a new aircraft is about to be added to the register and they issue the hex code.

You may not also know that each code starts with the a unique id for the country of origin. so all aircraft registered in the same country tend to begin with the same first 2 hex characters.

Back to your need. Are you wanting to convert the xplane INT value into the 6 digit hex code and then display using string?
Last edited by Sling on Sat Feb 13, 2021 10:18 am, edited 1 time in total.

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Keith's LUA Help thread.

#254 Post by Sling »

If that's what you want then something like this could work. There's probably a cleaner way to do it but this was my first thought.

Code: Select all

dec = 11305708
hex = {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"}
ICAO_hex_str = ""

for i = 1, 6 do
    hex_rem = dec % 16
    hex_rem_char = hex[hex_rem + 1]
    dec = math.floor(dec / 16)
    ICAO_hex_str = hex_rem_char .. ICAO_hex_str
end

print(ICAO_hex_str)


User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Keith's LUA Help thread.

#255 Post by Keith Baxter »

Sling wrote: Sat Feb 13, 2021 9:53 am Keith,

This has been about for ages so it's not specifically an ADSB thing. Normally you apply to your local regulator everytime a new aircraft is about to be added to the register and they issue the hex code.

You may not also know that each code starts with the a unique id for the country of origin. so all aircraft registered in the same country tend to begin with the same first 2 hex characters.

Back to your need. Are you wanting to convert the xplane INT value into the 6 digit hex code and then convert to a string?
Tony,

I am on the Map Traffic page. The G1000 has an option to add the "Flight ID"
This dataref I hope will do that. I could just display the dataref value but I think that this dataref , once converted will return the aircraft ID.

This might have implications if plugin Traffic is in place. It is a writable dataref so I would thing those plugins do that.


Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Keith's LUA Help thread.

#256 Post by Sling »

Keith Baxter wrote: Sat Feb 13, 2021 10:20 am I am on the Map Traffic page. The G1000 has an option to add the "Flight ID"
This dataref I hope will do that. I could just display the dataref value but I think that this dataref , once converted will return the aircraft ID.
If i'm not mistaken the flight ID is not automatically the ICAO code. This is the same option you get in modern transponders. From memory you can normally tell it to use the ICAO (which it will already know from its installation settings) or enter your own ID. That could be tail number or as the name suggests a flight ID number. This can be used for commercial ops when a flight ID is used. Pilots do not enter the ICAO hex code as its tied to the airframe and is a maintenance function anyhow.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Keith's LUA Help thread.

#257 Post by Keith Baxter »

Sling wrote: Sat Feb 13, 2021 10:29 am
Keith Baxter wrote: Sat Feb 13, 2021 10:20 am I am on the Map Traffic page. The G1000 has an option to add the "Flight ID"
This dataref I hope will do that. I could just display the dataref value but I think that this dataref , once converted will return the aircraft ID.
If i'm not mistaken the flight ID is not automatically the ICAO code. This is the same option you get in modern transponders. From memory you can normally tell it to use the ICAO (which it will already know from its installation settings) or enter your own ID. That could be tail number or as the name suggests a flight ID number. This can be used for commercial ops when a flight ID is used. Pilots do not enter the ICAO hex code as its tied to the airframe and is a maintenance function anyhow.
Tony,

Yes I understand all that.

I will look at the code you posted just now.

I am not sure but I think that dataref is used by the likes of vatsim etc. So that must have some common interpretation.

I am on this page so It is important to understand the data and future offerings.
ice_screenshot_20210213-122803.png
NOTE TO THOSE NOT AWARE: All graphics in this image are done in canvas_draw()

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Keith's LUA Help thread.

#258 Post by Keith Baxter »

Hi,

The advisory flight ID I am referring to is the one bottom right traffic indicator. This is visible by choice within the map menu setup.
So it is important to work properly.

Somehow surprised that this has not come up before.
@Ralph @Sling Is this a first for someone using AM ??

ice_screenshot_20210213-152430.png
Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Keith's LUA Help thread.

#259 Post by Sling »

Keith,

As i said in my previous post that is a flight id and not the 6 digit hex code. In the case you posted it's the tail number. I'm not sure that there is a generic dataref(s) for the flight id of other aircraft. If you don't have data you can't populate the field.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Keith's LUA Help thread.

#260 Post by Keith Baxter »

[quote=Sling post_id=33218 time=1613225726 user_id=551]
Keith,

As i said in my previous post that is a flight id and not the 6 digit hex code. In the case you posted it's the tail number. I'm not sure that there is a generic dataref(s) for the flight id of other aircraft. If you don't have data you can't populate the field.
[/quote]

Tony,

Yes it is a flight ID of the airframe.

I do not believe that LR would create such a dataref if it was merely a numeric reference.

In DatarefTool type in "tcas mode" and you should get two datarefs. These are the ID/(flight ID) of the Al aircraft from what you selected in here....

[attachment=0]ice_screenshot_20210213-163226.png[/attachment]

Tony I say this because for each airframe added or subtracted in the above menu, the dataref [i] value within those daterefs change indicating a ID of sorts.


I will pop LR a note to inquire

Keith
Attachments
ice_screenshot_20210213-163226.png
Last edited by Keith Baxter on Sat Feb 13, 2021 2:51 pm, edited 1 time in total.
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

Post Reply