1
0
Fork 0

Use Emesary interface rather than airportinfo()

This commit is contained in:
Stuart Buchanan 2018-01-13 21:07:32 +00:00
parent d306e7ba10
commit f6f5efe9f4
7 changed files with 190 additions and 49 deletions

View file

@ -200,7 +200,6 @@ var AirportInfo =
} else {
# We're not currently editing an element, so move to the next cursor position.
me.cursorElements[me.crsrIdx].unhighlightElement();
print("Old cursor index " ~ me.crsrIdx);
me.crsrIdx = math.mod(me.crsrIdx + incr_or_decr, size(me.cursorElements));
while ((me.cursorElements[me.crsrIdx].getValue() == nil) or
@ -209,7 +208,6 @@ var AirportInfo =
me.crsrIdx = math.mod(me.crsrIdx + incr_or_decr, size(me.cursorElements));
}
print("New cursor index " ~ me.crsrIdx ~ " " ~ size(me.cursorElements));
me.cursorElements[me.crsrIdx].highlightElement();
}
},

View file

@ -33,21 +33,18 @@ var AirportInfoController =
obj.crsrToggle = 0;
obj.current_zoom = 7;
# Initial airport is our current location.
var current_apt = airportinfo("airport");
obj.setAirport(current_apt.id);
obj.setZoom(7);
obj.setZoom(obj.current_zoom);
return obj;
},
setAirport : func(id)
{
if (id == me.airport) return;
var apt = airportinfo(id);
var apt = me.getAirport(id);
if (apt != nil) {
me.airport = id;
me.info= airportinfo(id);
me.info = apt;
}
# Reset airport display. We do this irrespective of whether the id
@ -136,8 +133,33 @@ var AirportInfoController =
# Reset controller if required when the page is displayed or hidden
ondisplay : func() {
me.RegisterWithEmesary();
if (me.airport == "") {
# Initial airport is our current location.
# Needs to be done here as the data provider may not be set up when
# we are created.
var current_apt = me.getAirport("airport");
me.setAirport(current_apt.id);
}
},
offdisplay : func() {
me.DeRegisterWithEmesary();
},
getAirport : func(id) {
# Use Emesary to get the airport
var notification = notifications.PFDEventNotification.new(
"MFD",
1,
notifications.PFDEventNotification.NavData,
{Id: "AirportByID", Value: id});
var response = me._transmitter.NotifyAll(notification);
if (! me._transmitter.IsFailed(response)) {
return notification.EventParameter.Value;
} else {
return nil;
}
},
};

View file

@ -0,0 +1,98 @@
#
# Emesary interface to access nav data such as airport information, fixes etc.
#
var NavDataInterface = {
new : func (device)
{
var obj = { parents : [ NavDataInterface ] };
# Emesary
obj._recipient = nil;
obj._transmitter = emesary.GlobalTransmitter;
obj._registered = 0;
obj._device = device;
return obj;
},
# Find the airports within 200nm and return them.
getNearestAirports : func()
{
# To make this more efficient for areas with a high density of airports, we'll try
# a small radius first and expand until we have reached 200nm or have 25 airports.
var radius = 0;
var apts = [];
while ((radius <= 200) and (size(apts) < 25)) {
radius = radius + 50;
apts = findAirportsWithinRange(radius);
}
if (size(apts) > 25) {
apts = subvec(apts, 0, 25);
}
return apts;
},
# Find a specific airport by ID
getAirportById : func(id)
{
var apt = airportinfo(id);
return apt;
},
RegisterWithEmesary : func()
{
if (me._recipient == nil){
me._recipient = emesary.Recipient.new("DataInterface");
var pfd_obj = me._device;
var controller = me;
me._recipient.Receive = func(notification)
{
if (notification.Device_Id == pfd_obj.device_id
and notification.NotificationType == notifications.PFDEventNotification.DefaultType) {
if (notification.Event_Id == notifications.PFDEventNotification.NavData
and notification.EventParameter != nil)
{
var id = notification.EventParameter.Id;
if (id == "NearestAirports") {
notification.EventParameter.Value = controller.getNearestAirports();
return emesary.Transmitter.ReceiptStatus_Finished;
}
if (id == "AirportByID") {
var apt = controller.getAirportById(notification.EventParameter.Value);
notification.EventParameter.Value = apt;
return emesary.Transmitter.ReceiptStatus_Finished;
}
}
}
return emesary.Transmitter.ReceiptStatus_NotProcessed;
};
}
me._transmitter.Register(me._recipient);
me._registered = 1;
},
DeRegisterWithEmesary : func()
{
# remove registration from transmitter; but keep the recipient once it is created.
if (me._registered == 1) me._transmitter.DeRegister(me._recipient);
me._registered = 0;
},
start : func() {
me.RegisterWithEmesary();
},
stop : func() {
me.DeRegisterWithEmesary();
},
};

View file

@ -119,6 +119,8 @@ var NearestAirports =
},
updateAirports : func(apts) {
if (apts == nil) return;
var airportlist = [];
for (var i = 0; i < size(apts); i = i + 1) {
var apt = apts[i];
@ -150,6 +152,9 @@ var NearestAirports =
}
},
updateAirportData : func(apt) {
if (apt == nil) return;
me.setTextElement("Name", apt.name);
me.setTextElement("Alt", sprintf("%ift", M2FT * apt.elevation));

View file

@ -21,35 +21,6 @@ var NearestAirportsController =
return obj;
},
getAirports : func() {
# Find the airports within 200nm and display them.
# To make this more efficient for areas with a high density of airports, we'll try
# small radii first.
var radius = 0;
var apts = [];
#
# TODO: Use Emesary to query APT data - allows support for multiple
# data sources / abstraction.
#
#var airportNotification = notifications.PFDEventNotification.new(blah);
#var response = Emesary.GlobalTransmitter.notifyAll(airportNotification);
#if (response.isSuccess()) {
# me.page.updateAirports(airportNotification.value);
#}
while ((radius <= 200) and (size(apts) < 25)) {
radius = radius + 50;
apts = findAirportsWithinRange(radius);
}
if (size(apts) > 25) {
apts = subvec(apts, 0, 25);
}
me.page.updateAirports(apts);
},
selectAirports : func() {
me.selectGroup(NearestAirportsController.UIGROUP.APT)
},
@ -95,8 +66,9 @@ var NearestAirportsController =
if (me._currentGroup == NearestAirportsController.UIGROUP.APT) {
me.page.airportSelect.incrSmall(value);
var apt_id = me.page.getSelectedAirportID();
var apt_info = airportinfo(apt_id);
me.page.updateAirportData(apt_info);
var aptdata = me.getAirport(apt_id);
if (aptdata != nil) me.page.updateAirportData(aptdata);
}
if (me._currentGroup == NearestAirportsController.UIGROUP.RNWY) {
@ -106,15 +78,17 @@ var NearestAirportsController =
var rwy = me.page.runwaySelect.getValue();
if ((rwy != nil) and (rwy != "")) {
var apt_info = airportinfo(apt_id);
var apt_info = me.getAirport(apt_id);
# Names in the runway selection are of the form "NNN-MMM", e.g. 11R-29L
# We just want the first of these.
var idx = find("-", rwy);
if (idx != -1) {
rwy = substr(rwy, 0, idx);
var rwy_info = apt_info.runways[rwy];
me.page.updateRunwayInfo(rwy_info);
if (apt_info != nil) {
# Names in the runway selection are of the form "NNN-MMM", e.g. 11R-29L
# We just want the first of these.
var idx = find("-", rwy);
if (idx != -1) {
rwy = substr(rwy, 0, idx);
var rwy_info = apt_info.runways[rwy];
me.page.updateRunwayInfo(rwy_info);
}
}
}
}
@ -138,7 +112,7 @@ var NearestAirportsController =
if (me._currentGroup == NearestAirportsController.UIGROUP.APT) {
me.page.airportSelect.incrLarge(value);
var apt_id = me.page.getSelectedAirportID();
var apt_info = airportinfo(apt_id);
var apt_info = me.getAirport(apt_id);
me.page.updateAirportData(apt_info);
}
@ -153,7 +127,7 @@ var NearestAirportsController =
# If the airport group is selected, the ENT key selects the next airport
me.page.airportSelect.incrLarge(value);
var apt_id = me.page.getSelectedAirportID();
var apt_info = airportinfo(apt_id);
var apt_info = me.getAirport(apt_id);
me.page.updateAirportData(apt_info);
return emesary.Transmitter.ReceiptStatus_Finished;
}
@ -200,4 +174,38 @@ var NearestAirportsController =
me.page.mfd.NavigationMap.controller.enableDTO(0);
me.DeRegisterWithEmesary();
},
getAirports : func() {
var notification = notifications.PFDEventNotification.new(
"MFD",
1,
notifications.PFDEventNotification.NavData,
{Id: "NearestAirports", Value: nil});
var response = me._transmitter.NotifyAll(notification);
if (! me._transmitter.IsFailed(response)) {
me.page.updateAirports(notification.EventParameter.Value);
} else {
return nil;
}
},
getAirport : func(id) {
# Use Emesary to get the airport
var notification = notifications.PFDEventNotification.new(
"MFD",
1,
notifications.PFDEventNotification.NavData,
{Id: "AirportByID", Value: id});
var response = me._transmitter.NotifyAll(notification);
if (! me._transmitter.IsFailed(response)) {
return notification.EventParameter.Value;
} else {
return nil;
}
},
};

View file

@ -554,6 +554,7 @@ var PFDEventNotification =
HardKeyPushed : 4, #event parameter contains single { Id: , Value: } tuple
EngineData : 5, #event parameter contains an array of hashes, each containing information about a given engine.
NavComData : 6, #event parameter contains a hash of updated Nav/Com settings
NavData : 7, #event parameter contrains a singel { Id: , Value: } tuple requesting a paricular type of NavData
DefaultType : "PFDEventNotification",

View file

@ -18,6 +18,7 @@
var eisPublisher = nil;
var navcomPublisher = nil;
var navcomUpdater = nil;
var navdataInterface = nil
]]></open>
<close><![CDATA[
@ -33,6 +34,9 @@
navcomUpdater.stop();
navcomUpdater = nil;
navdataInterface.stop();
navdataInterface =nil;
]]></close>
</nasal>
@ -497,6 +501,8 @@
io.load_nasal(nasal_dir ~ 'Interfaces/GenericEISPublisher.nas', "fg1000");
io.load_nasal(nasal_dir ~ 'Interfaces/GenericNavComPublisher.nas', "fg1000");
io.load_nasal(nasal_dir ~ 'Interfaces/GenericNavComUpdater.nas', "fg1000");
io.load_nasal(nasal_dir ~ 'Interfaces/NavDataInterface.nas', "fg1000");
mfd = fg1000.MFD.new(myCanvas);
eisPublisher = fg1000.GenericEISPublisher.new();
@ -508,6 +514,9 @@
navcomUpdater = fg1000.GenericNavComUpdater.new(mfd.getDevice());
navcomUpdater.start();
navdataInterface = fg1000.NavDataInterface.new(mfd.getDevice());
navdataInterface.start();
softkeypushed = 0;
# Connect the buttons - using the provided model index to get the right ones from the model binding
var softkey_listener = setlistener("/sim/gui/dialogs/fg1000/softkey-pressed", func(v)