I think all you need to do is add a setting for ground_alt, for example in conf/settings/fixedwing_basic.xml add:
<dl_setting MAX="4000" MIN="0" STEP="1" VAR="ground_alt"/>
This will 2 things:
- add a control in the GCS where you can see and change the value of that variable in the airborne code.
- periodically send a message from the plane with the value of that variable
The message you need to capture is DL_VALUE. This is sent one variable at a time so you need to wait for the correct index and then take note of that value. To know which is the correct index you have two options:
1- check in var/aircrafts/<your aircraft name>/ap/generated/settings.h where it says #define SETTINGS. Look at which position ground_alt appears. If it is at position 4 then the index is 3.
2- if you know the current value of the variable (you can look in the GCS) then you can see in the Messages windows the DL_VALUE messages and wait until one has the correct value, then that is the index you need
Apparently the GCS does not show the correct AGL because it does not read the ground_alt value.