From 76cfa2c07785b91ae9ca3b2602e3e486949a8ee4 Mon Sep 17 00:00:00 2001
From: Stuart Buchanan <stuart_d_buchanan@yahoo.co.uk>
Date: Thu, 12 Mar 2020 17:25:34 +0000
Subject: [PATCH] FG1000 and MFD handle non-MFD Emesary notifications

Previously the FG1000 and MFD assumed that all notifications received
via Emesary had a Device_Id field.  This is true for
notifications.PFDEventNotification.DefaultType but not for other
messages - e.g. those generated by the AN SPN 46  system on the
carrier.

The effect of this was that when Nimitz was loaded, the FG1000 stopped
working with various errors.

This fix checks the notification type before the Device_Id.
---
 Aircraft/Instruments-3d/FG1000/Nasal/MFDPageController.nas | 4 ++--
 Nasal/canvas/MFD_Generic.nas                               | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/Aircraft/Instruments-3d/FG1000/Nasal/MFDPageController.nas b/Aircraft/Instruments-3d/FG1000/Nasal/MFDPageController.nas
index 97d3f1d1a..ebe32b8dc 100644
--- a/Aircraft/Instruments-3d/FG1000/Nasal/MFDPageController.nas
+++ b/Aircraft/Instruments-3d/FG1000/Nasal/MFDPageController.nas
@@ -112,8 +112,8 @@ RegisterWithEmesary : func()
     var controller = me;
     me._recipient.Receive = func(notification)
     {
-      if (notification.Device_Id == pfd_obj.device_id
-          and notification.NotificationType == notifications.PFDEventNotification.DefaultType) {
+      if (notification.NotificationType == notifications.PFDEventNotification.DefaultType and
+          notification.Device_Id == pfd_obj.device_id) {
         if (notification.Event_Id == notifications.PFDEventNotification.HardKeyPushed
             and notification.EventParameter != nil)
         {
diff --git a/Nasal/canvas/MFD_Generic.nas b/Nasal/canvas/MFD_Generic.nas
index 218b3e374..4921bd5d6 100644
--- a/Nasal/canvas/MFD_Generic.nas
+++ b/Nasal/canvas/MFD_Generic.nas
@@ -219,8 +219,8 @@ var PFD_Device =
             var pfd_obj = me;
             me.Recipient.Receive = func(notification)
               {
-                  if (notification.Device_Id == pfd_obj.device_id
-                      and notification.NotificationType == notifications.PFDEventNotification.DefaultType) {
+                  if (notification.NotificationType == notifications.PFDEventNotification.DefaultType and
+                      notification.Device_Id == pfd_obj.device_id) {
                       if (notification.Event_Id == notifications.PFDEventNotification.SoftKeyPushed
                           and notification.EventParameter != nil)
                         {