public static DBusMessage ModifyMS43Message(DMEAnalogValues av, Message message)
 {
     var data = message.Data.Skip(0);
     data[30] = ToByte((av.WideBandLambda - 0.5) * 255); // TODO why not? TBD with JMG
     data[31] = ToByte(av.IntakePressure / 10);
     return new DBusMessage(DeviceAddress.DME, message.ReceiverDescription, data);
 }
Beispiel #2
0
 public static bool CanParse(Message message)
 {
     return message.SourceDevice == DeviceAddress.DME
         && message.DestinationDevice == DeviceAddress.Diagnostic
         && message.Data.Length == 42
         && message.Data[0] == 0xA0;
 }
 public override void Parse(Message message)
 {
     base.Parse(message);
     var d = message.Data;
     LambdaHeatingAfterCats1 = -1; // byte #30 is used for AFR instead
     LambdaHeatingAfterCats2 = -1; // byte #31 is used for IntakePressure instead
     WideBandLambda = (double)d[30] / 255 + 0.5; // TODO fix - not JMG formula!
     AFR = WideBandLambda * 14.7;
     IntakePressure = d[31] * 10; // 0..2550 hPa
 }
Beispiel #4
0
 public override void Parse(Message message)
 {
     base.Parse(message);
     var d = message.Data;
     LambdaHeatingAfterCats1 = -1; // byte #30 is used for AFR instead
     LambdaHeatingAfterCats2 = -1; // byte #31 is used for IntakePressure instead
     WideBandLambda = d[30] * 0.0009914 - 31.98155; // TODO ??? fix
     AFR = WideBandLambda * 14.7;
     IntakePressure = d[31] * 10; // 0..2550 hPa
 }
Beispiel #5
0
 static void LightControlModule_LightStatusReceived(iBus.Message message, LightStatusEventArgs args)
 {
     if (IgnoreFrontLightsError && args.ErrorFrontLeftLights && args.ErrorFrontRightsLights)
     {
         var data = (byte[])message.Data.Clone();
         data[4] = data[4].RemoveBits(0x30);
         var m = new Message(DeviceAddress.LightControlModule, DeviceAddress.GlobalBroadcastAddress, data);
         Manager.EnqueueMessage(m);
     }
 }
Beispiel #6
0
 public async Task SendMessage(Message message)
 {
     if (!IsConnected)
     {
         throw new Exception("Not connected.");
     }
     dataWriter.WriteBuffer(message.Packet.AsBuffer());
     await dataWriter.StoreAsync();
     //await dataWriter.FlushAsync();
 }
 public static void SendMessage(Message m)
 {
     if (HasConnection)
     {
         try
         {
             client.SendCommand(m.Packet, client.SPPLink, m.ToString());
         }
         catch (Exception ex)
         {
             Logger.Error(ex, "Internal to WT32", "> BT");
         }
     }
 }
Beispiel #8
0
 public bool Matches(Message m)
 {
     switch (Match)
     {
         case MessageReceiverRegistration.MatchType.Source:
             if (Source == m.SourceDevice)
             {
                 return true;
             }
             break;
         case MessageReceiverRegistration.MatchType.Destination:
             if (Destination == m.DestinationDevice
                 || m.DestinationDevice == DeviceAddress.Broadcast
                 || m.DestinationDevice == DeviceAddress.GlobalBroadcastAddress)
             {
                 return true;
             }
             break;
         case MessageReceiverRegistration.MatchType.SourceAndDestination:
             if (Source == m.SourceDevice
                 && (Destination == m.DestinationDevice
                     || m.DestinationDevice == DeviceAddress.Broadcast
                     || m.DestinationDevice == DeviceAddress.GlobalBroadcastAddress))
             {
                 return true;
             }
             break;
         case MessageReceiverRegistration.MatchType.SourceOrDestination:
             if (Source == m.SourceDevice
                 || Destination == m.DestinationDevice
                 || m.DestinationDevice == DeviceAddress.Broadcast
                 || m.DestinationDevice == DeviceAddress.GlobalBroadcastAddress)
             {
                 return true;
             }
             break;
     }
     return false;
 }
Beispiel #9
0
 public MessageEventArgs(Message message)
 {
     Message = message;
 }
Beispiel #10
0
 public void Process(Message m)
 {
     if (Matches(m))
     {
         Callback(m);
     }
 }
Beispiel #11
0
        public static void ProcessMessage(Message m)
        {
            #if DEBUG
            m.PerformanceInfo.TimeStartedProcessing = DateTime.Now;
            #endif

            MessageEventArgs args = null;
            try
            {
                var e = BeforeMessageReceived;
                if (e != null)
                {
                    args = new MessageEventArgs(m);
                    e(args);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "on before message received " + m.ToPrettyString());
            }

            if (args != null && args.Cancel)
            {
                return;
            }

            foreach (MessageReceiverRegistration receiver in MessageReceiverList)
            {
                try
                {
                    receiver.Process(m);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, "while processing message: " + m.ToPrettyString());
                }
            }

            #if DEBUG
            m.PerformanceInfo.TimeEndedProcessing = DateTime.Now;
            #endif

            try
            {
                var e = AfterMessageReceived;
                if (e != null)
                {
                    if (args == null)
                    {
                        args = new MessageEventArgs(m);
                    }
                    e(args);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "on after message received " + m.ToPrettyString());
            }
        }
Beispiel #12
0
 public static void EnqueueMessage(Message m)
 {
     /*
     if (iBus is SerialPortEcho)
     {
         ProcessMessage(m);
         return;
     }
     if (iBus is SerialPortHub)
     {
         SendMessage(m);
         return;
     }*/
     #if DEBUG
     m.PerformanceInfo.TimeEnqueued = DateTime.Now;
     #endif
     try
     {
         messageWriteQueue.Enqueue(m);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #13
0
        void ProcessRadioMessage(Message m)
        {
            if (m.Data.Length == 3 && m.Data[0] == 0x38 && m.Data[1] == 0x06)
            {
                // switch cd buttons:
                //   2 - select
                //
                //   3 - prev
                //   4 - next
                //
                //   5 - back
                //   6 - home
                byte cdNumber = m.Data[2];
                switch (cdNumber)
                {
                    case 0x02:
                        PressedSelect();
                        break;
                    case 0x03:
                        ScrollPrev();
                        break;
                    case 0x04:
                        ScrollNext();
                        break;
                    case 0x05:
                        PressedBack();
                        break;
                    case 0x06:
                        PressedHome();
                        break;
                }
                m.ReceiverDescription = "Change CD: " + cdNumber;
            }
            else if (m.Data.Length == 3 && m.Data[0] == 0x38 && m.Data[1] == 0x0A)
            {
                switch (m.Data[2])
                {
                    case 0x00:
                        if (CurrentScreen != mediaEmulator.Player.Menu)
                        {
                            UpdateScreen(MenuScreenUpdateReason.Refresh);
                        }
                        mediaEmulator.Player.Next();
                        m.ReceiverDescription = "Next track";
                        break;
                    case 0x01:
                        if (CurrentScreen != mediaEmulator.Player.Menu)
                        {
                            UpdateScreen(MenuScreenUpdateReason.Refresh);
                        }
                        mediaEmulator.Player.Prev();
                        m.ReceiverDescription = "Prev track";
                        break;
                }
            }
            // TODO bind rnd, scan

            if (IsEnabled && Radio.HasMID && m.DestinationDevice == DeviceAddress.MultiInfoDisplay)
            {
                if (m.Data.StartsWith(DataMIDCDC))
                {
                    UpdateScreen(MenuScreenUpdateReason.Refresh);
                    wereMIDButtonsOverriden = false;
                    m.ReceiverDescription = "CD 1-01";
                }
                else if (m.Data.Compare(DataMIDFirstButtons))
                {
                    wereMIDButtonsOverriden = false;
                    m.ReceiverDescription = "Disk change buttons display";
                }
                else if (m.Data.Compare(MaskMIDLastButtons, MessageMIDLastButtons.Data))
                {
                    m.ReceiverDescription = MessageMIDLastButtons.ReceiverDescription;
                    MessageMIDLastButtons = m; // to save statuses of TP, RND and SC flags
                    if (!wereMIDButtonsOverriden)
                    {
                        Manager.EnqueueMessage(MessageMIDMenuButtons, m);
                        wereMIDButtonsOverriden = true;
                    }
                    else
                    {
                        wereMIDButtonsOverriden = false;
                    }
                }
            }
        }
Beispiel #14
0
 public virtual bool Compare(Message message)
 {
     return SourceDevice == message.SourceDevice
         && DestinationDevice == message.DestinationDevice
         && Data.Compare(message.Data);
 }
Beispiel #15
0
 public MS43JMGAnalogValues(Message message, DateTime loggerStarted)
     : base(message, loggerStarted)
 {
 }
Beispiel #16
0
 public void SendCommand(Message message, Link link, string description = null)
 {
     if (description == null)
     {
         description = message.ToString();
     }
     SendCommand(message.Packet, link, description);
 }
Beispiel #17
0
 public override bool Compare(Message message)
 {
     return SourceDevice == message.SourceDevice && Data.Compare(message.Data);
 }
Beispiel #18
0
 protected virtual int GetPacketLength(Message m)
 {
     return m.PacketLength;
 }
Beispiel #19
0
 protected override int GetPacketLength(Message m)
 {
     return ((DBusMessage)m).PacketLength;
 }
Beispiel #20
0
        protected void ProcessRadioMessage(Message m)
        {
            if (!IsEnabled)
            {
                return;
            }

            var isRefresh = m.Data.Compare(Bordmonitor.MessageRefreshScreen.Data);
            if (isRefresh)
            {
                m.ReceiverDescription = "Screen refresh";
                skipClearTillRefresh = false;
                if (skipRefreshScreen)
                {
                    skipRefreshScreen = false;
                    return;
                }
            }
            var isClear = m.Data.Compare(Bordmonitor.MessageClearScreen.Data);
            if (isClear)
            {
                m.ReceiverDescription = "Screen clear";
                if (skipClearScreen || skipClearTillRefresh)
                {
                    skipClearScreen = false;
                    return;
                }
            }
            if (isClear || isRefresh)
            {
                if (IsScreenSwitched)
                {
                    IsScreenSwitched = false;
                }

                if (disableRadioMenu || isClear)
                {
                    disableRadioMenu = false;
                    Bordmonitor.DisableRadioMenu();
                    return;
                }

                // TODO test "INFO" button
                UpdateScreen(MenuScreenUpdateReason.Refresh);
                return;
            }

            // Screen switch
            // 0x46 0x01 - switched by nav, after 0x45 0x91 from nav (eg. "menu" button)
            // 0x46 0x02 - switched by radio ("switch" button).
            if (m.Data.Length == 2 && m.Data[0] == 0x46 && (m.Data[1] == 0x01 || m.Data[1] == 0x02))
            {
                switch (m.Data[1])
                {
                    case 0x01:
                        m.ReceiverDescription = "Screen SW by nav";
                        break;
                    case 0x02:
                        m.ReceiverDescription = "Screen SW by rad";
                        skipClearScreen = true; // to prevent on "clear screen" update on switch to BC/nav
                        break;
                }
                IsScreenSwitched = true;
                return;
            }

            /*if (m.Data.Compare(Bordmonitor.DataAUX))
            {
                IsScreenSwitched = false;
                UpdateScreen(); // TODO prevent flickering
                return;
            }*/

            if (m.Data.StartsWith(Bordmonitor.DataShowTitle) && (lastTitle == null || !lastTitle.Data.Compare(m.Data)))
            {
                IsScreenSwitched = false;
                disableRadioMenu = true;
                UpdateScreen(MenuScreenUpdateReason.Refresh);
                return;
            }
        }
Beispiel #21
0
 public MS43JMGAnalogValues(Message message)
     : base(message)
 {
 }
Beispiel #22
0
        protected override void DrawScreen(MenuScreenUpdateEventArgs args)
        {
            CancelRefreshScreenWithDelay();
            string showText;
            TextAlign align = TextAlign.Left;
            switch (args.Reason)
            {
                case MenuScreenUpdateReason.Navigation:
                    showText = CurrentScreen.Title;
                    if (showText.Length < Radio.DisplayTextMaxLen)
                    {
                        showText = CharIcons.NetRect + showText;
                    }
                    if (showText.Length < Radio.DisplayTextMaxLen)
                    {
                        showText += CharIcons.NetRect;
                    }
                    align = TextAlign.Center;
                    RefreshScreenWithDelay(MenuScreenUpdateReason.Scroll);
                    break;
                case MenuScreenUpdateReason.StatusChanged:
                    if (CurrentScreen.Status == String.Empty)
                    {
                        UpdateScreen(MenuScreenUpdateReason.Refresh);
                        return;
                    }
                    showText = CurrentScreen.Status;
                    align = TextAlign.Center;
                    RefreshScreenWithDelay();
                    break;
                default:
                    showText = GetShownItemString();
                    var separator = showText.IndexOf(": ");
                    if (separator >= 0)
                    {
                        if (args.Reason == MenuScreenUpdateReason.Scroll)
                        {
                            showText = showText.Substring(0, separator + 1);
                            RefreshScreenWithDelay();
                        }
                        else
                        {
                            showText = showText.Substring(separator + 2);
                        }
                    }
                    break;
            }

            Message[] midButtons = null;
            if (Radio.HasMID && !wereMIDButtonsOverriden)
            {
                midButtons = new Message[] { MessageMIDMenuButtons, MessageMIDLastButtons };
                wereMIDButtonsOverriden = true;
            }
            Radio.DisplayTextWithDelay(showText, align, midButtons);
        }
Beispiel #23
0
 public virtual void Parse(Message message)
 {
     if (!CanParse(message))
     {
         throw new Exception("Not MS43 analog values message");
     }
     var d = message.Data;
     RPM = (d[1] << 8) + d[2];
     Speed = d[3];
     Pedal = ((d[4] << 8) + d[5]) * 0.0018311;
     Throttle = ((d[6] << 8) + d[7]) * 0.0018311;
     AirMass = ((d[8] << 8) + d[9]) * 0.25;
     IntakeTemp = d[10] * 0.75 - 48;
     CoolantTemp = d[11] * 0.75 - 48;
     OilTemp = d[12] * 0.796 - 48;
     CoolantRadiatorTemp = d[13] * 0.75 - 48;
     IgnitionAngle = -d[14] * 0.375 + 72;
     InjectionTime = ((d[15] << 8) + d[16]) * 0.0053333;
     ISAPWM_IS = ((d[17] << 8) + d[18]) * 0.0015;
     ISAPWM_ISA = ((d[19] << 8) + d[20]) * 0.0015;
     VanosPositionIntake = d[21] * 0.375 + 60;
     VanosPositionExhaust = -d[22] * 0.375 - 60;
     VoltageKL15 = d[23] * 0.10156;
     LambdaIntegrator1 = ((d[24] << 8) + d[25]) * 0.000015259 + 0.5;
     LambdaIntegrator2 = ((d[26] << 8) + d[27]) * 0.000015259 + 0.5;
     LambdaHeatingBeforeCats1 = d[28] * 0.391;
     LambdaHeatingBeforeCats2 = d[29] * 0.391;
     LambdaHeatingAfterCats1 = d[30] * 0.391;
     LambdaHeatingAfterCats2 = d[31] * 0.391;
     AirMassPerStroke = ((d[32] << 8) + d[33]) * 0.0212;
     KnockSensor2 = ((d[34] << 8) + d[35]) * 0.0000778;
     KnockSensor5 = ((d[36] << 8) + d[37]) * 0.0000778;
     ElectricFanSpeed = d[38] * 0.39063;
     AtmosphericPressure = (int)(((d[39] << 8) + d[40]) * 0.08292);
     VoltageBattery = d[41] * 0.10156;
 }
Beispiel #24
0
 public MS43AnalogValues(Message message)
 {
     Parse(message);
 }
Beispiel #25
0
        protected override void DrawScreen(MenuScreenUpdateEventArgs args)
        {
            if (isDrawing)
            {
                return; // TODO test
            }
            lock (drawLock)
            {
                isDrawing = true;
                skipRefreshScreen = true;
                skipClearTillRefresh = true; // TODO test no screen items lost
                base.DrawScreen(args);

                var messages = new Message[FastMenuDrawing ? 4 : 13];
                var n = 0;
                messages[n++] = Bordmonitor.ShowText(CurrentScreen.Status ?? String.Empty, BordmonitorFields.Status, 0, false, false);
                lastTitle = Bordmonitor.ShowText(CurrentScreen.Title ?? String.Empty, BordmonitorFields.Title, 0, false, false);
                messages[n++] = lastTitle;
                byte[] itemsBytes = null;
                for (byte i = 0; i < 10; i++)
                {
                    var index = GetItemIndex(i, true);
                    var item = CurrentScreen.GetItem(index);
                    if (FastMenuDrawing)
                    {
                        if (item == null && itemsBytes != null)
                        {
                            itemsBytes = itemsBytes.Combine(0x06);
                            continue;
                        }
                        var m = DrawItem(item, i);
                        if (itemsBytes == null)
                        {
                            itemsBytes = m.Data;
                        }
                        else
                        {
                            var d = m.Data.Skip(3);
                            d[0] = 0x06;
                            itemsBytes = itemsBytes.Combine(d);
                        }
                    }
                    else
                    {
                        if (item == null && n > 2)
                        {
                            var prevMess = messages[n-1];
                            messages[n - 1] = new Message(prevMess.SourceDevice, prevMess.DestinationDevice, prevMess.ReceiverDescription, prevMess.Data.Combine(0x06));
                        }
                        else
                        {
                            messages[n++] = DrawItem(item, i);
                        }
                        messages[n - 1].AfterSendDelay = 40;
                    }
                }
                if (FastMenuDrawing)
                {
                    itemsBytes = itemsBytes.Combine(0x06);
                    messages[n++] = new Message(DeviceAddress.Radio, DeviceAddress.GraphicsNavigationDriver, "Fill screen items", itemsBytes);
                }
                messages[n++] = Bordmonitor.MessageRefreshScreen;
                skipRefreshScreen = true;
                skipClearTillRefresh = true;
                Manager.EnqueueMessage(messages);
                isDrawing = false;
            }
        }
Beispiel #26
0
 public MS43AnalogValues(Message message, DateTime loggerStarted)
     : base(loggerStarted)
 {
     Parse(message);
 }
Beispiel #27
0
        protected void ProcessToRadioMessage(Message m)
        {
            if (!IsEnabled)
            {
                return;
            }

            // item click
            if (m.Data.Length == 4 && m.Data.StartsWith(0x31, 0x60, 0x00) && m.Data[3] <= 9)
            {
                var index = GetItemIndex(m.Data[3], true);
                m.ReceiverDescription = "Screen item click #" + index;
                var item = CurrentScreen.GetItem(index);
                if (item != null)
                {
                    item.Click();
                }
                return;
            }

            // BM buttons
            if (m.Data.Length == 2 && m.Data[0] == 0x48)
            {
                switch (m.Data[1])
                {
                    case 0x14: // <>
                        m.ReceiverDescription = "BM button <> - navigate home";
                        NavigateHome();
                        break;
                    case 0x07:
                        m.ReceiverDescription = "BM button Clock - navigate BC";
                        NavigateAfterHome(BordcomputerScreen.Instance);
                        break;
                    case 0x20:
                        m.ReceiverDescription = "BM button Sel"; // - navigate player";
                        // TODO fix in cdc mode
                        //NavigateAfterHome(HomeScreen.Instance.PlayerScreen);
                        break;
                    case 0x30:
                        m.ReceiverDescription = "BM button Switch Screen";
                        /*if (screenSwitched)
                        {
                            UpdateScreen();
                        }*/
                        break;
                    case 0x23:
                        m.ReceiverDescription = "BM button Mode";
                        IsEnabled = false;
                        Bordmonitor.EnableRadioMenu(); // TODO test [and remove]
                        break;
                    case 0x04:
                        m.ReceiverDescription = "BM button Tone";
                        // TODO fix Tone - skip clear till aux title
                        IsEnabled = false;
                        //Bordmonitor.EnableRadioMenu(); // TODO test [and remove]
                        break;
                    case 0x10:
                        m.ReceiverDescription = "BM Button < prev track";
                        mediaEmulator.Player.Prev();
                        break;
                    case 0x00:
                        m.ReceiverDescription = "BM Button > next track";
                        mediaEmulator.Player.Next();
                        break;
                }
                return;
            }
        }
Beispiel #28
0
 void parser_MessageReceived(Message message)
 {
     if (message is InternalMessage)
     {
         OnInternalMessageReceived((InternalMessage)message);
     }
     else
     {
         Manager.ProcessMessage(message);
     }
 }