Ejemplo n.º 1
0
        protected virtual void SetItems()
        {
            item1 = new MenuItem(i => "Read: " + readedCodingData.ToHex(' '), item =>
            {
                IntegratedHeatingAndAirConditioning.ReadCodingData();
                IsCodingDataReaded = true;
            }, MenuItemType.Button, MenuItemAction.None);

            item2 = new MenuItem(i => "Write: " + IntegratedHeatingAndAirConditioning.CodingData.ToHex(' '), item =>
            {
                IntegratedHeatingAndAirConditioning.WriteCodingData();
                IsCodingDataReaded = false;
            }, MenuItemType.Text, MenuItemAction.None);

            item3 = new MenuItem(i => "Aux Heater: " + IntegratedHeatingAndAirConditioning.AuxilaryHeaterActivationMode.ToStringValue(), item =>
            {
                IntegratedHeatingAndAirConditioning.AuxilaryHeaterActivationMode =
                    IntegratedHeatingAndAirConditioning.AuxilaryHeaterActivationMode == AuxilaryHeaterActivationMode.Normal
                    ? AuxilaryHeaterActivationMode.Kbus: AuxilaryHeaterActivationMode.Normal;
            }, MenuItemType.Button, MenuItemAction.Refresh);

            item4 = new MenuItem(i => "Aux Heating ", item =>
            {
                IntegratedHeatingAndAirConditioning.AuxilaryHeating = item.IsChecked;
            }, MenuItemType.Checkbox, MenuItemAction.Refresh);

            AddItem(item1);
            AddItem(item2);
            AddItem(item3);
            AddItem(item4);

            this.AddBackButton();
        }
Ejemplo n.º 2
0
        public void ShouldRestoreAuxilaryHeaterStatus_IfThereWasRestart_DuringAuxilaryHeaterWorking()
        {
            AuxilaryHeaterEmulator.Init(2000);
            Launcher.Launch(Launcher.LaunchMode.WPF);
            Settings.Instance.SuspendAuxilaryHeaterResponseEmulation = false;

            ManualResetEvent waitHandle = new ManualResetEvent(false);

            AuxilaryHeater.StatusChanged += (status) =>
            {
                if (status == AuxilaryHeaterStatus.Working)
                {
                    waitHandle.Set();
                }
            };

            IntegratedHeatingAndAirConditioning.StartAuxilaryHeater();
            bool result = waitHandle.Wait(5000);

            Assert.IsTrue(result);


            waitHandle.Reset();
            AuxilaryHeater.Status = AuxilaryHeaterStatus.Unknown;
            result = waitHandle.Wait(3000);
            Assert.IsTrue(result);
            Assert.IsTrue(AuxilaryHeater.Status == AuxilaryHeaterStatus.Working);
        }
Ejemplo n.º 3
0
        //protected override void ProcessRadioMessage(Message m)
        //{
        //base.ProcessRadioMessage(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 switch by nav";
        //            break;
        //        case 0x02:
        //            m.ReceiverDescription = "Screen switch 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;
        //}
        //}

        protected void ProcessToRadioMessage(Message m)
        {
            // BM buttons
            if (m.Data[0] == 0x48 && m.Data.Length == 2)
            {
                switch (m.Data[1])
                {
                // 'Phone' button
                case 0x08:
                    m.ReceiverDescription = "Phone press";
                    break;

                case 0x48:
                    OnPhoneButtonHold();
                    m.ReceiverDescription = "Phone hold";
                    break;

                case 0x88:
                    IsEnabled             = true;
                    m.ReceiverDescription = "Phone release";
                    break;

                // 'AuxilaryHeater/Clock' button
                case 0x07:
                    break;

                case 0x47:
                    break;

                case 0x87:
                    IntegratedHeatingAndAirConditioning.StartAuxilaryHeater();
                    break;

                // '<>' button
                case 0x14:
                case 0x54:
                    break;

                case 0x94:
                    IntegratedHeatingAndAirConditioning.StopAuxilaryHeater();
                    break;

                // 'Tone' button
                case 0x04:
                    IsEnabled             = false;
                    m.ReceiverDescription = "TONE press";
                    break;

                case 0x44:
                    Manager.Instance.EnqueueMessage(new Message(DeviceAddress.Diagnostic, DeviceAddress.DigitalSignalProcessingAudioAmplifier, "DSP2.PRG->JOBNAME:RESET", 0x1C, 0x00));
                    m.ReceiverDescription = "TONE hold";
                    break;

                case 0x84:
                    m.ReceiverDescription = "TONE release";
                    break;

                // 'Select' button
                case 0x20:
                    IsEnabled             = false;
                    m.ReceiverDescription = "SELECT press";
                    break;

                case 0x60:
                    Manager.Instance.EnqueueMessage(new Message(DeviceAddress.Diagnostic, DeviceAddress.DigitalSignalProcessingAudioAmplifier, "DSP2.PRG->JOBNAME:DSP_SELBSTTEST ", 0x30));
                    m.ReceiverDescription = "SELECT hold";
                    break;

                case 0xA0:
                    m.ReceiverDescription = "SELECT release";
                    break;

                // 'Next' button
                case 0x00:
                    m.ReceiverDescription = "Next press";
                    break;

                case 0x40:
                    m.ReceiverDescription = "Next hold";
                    break;

                case 0x80:
                    m.ReceiverDescription = "Next release";
                    break;

                // 'Mode' button
                case 0x23:
                    m.ReceiverDescription = "MODE press";
                    break;

                case 0x63:
                    m.ReceiverDescription = "MODE hold";
                    break;

                case 0xA3:
                    m.ReceiverDescription = "MODE released.";
                    break;

                // 'Eject' button
                case 0x24:
                    break;

                case 0x64:
                    OnEjectButtonHold();
                    break;

                case 0xA4:
                    break;

                // 'Menu' button
                case 0x34:     // pressed
                    m.ReceiverDescription = "MENU press";
                    break;

                case 0x74:     // hold > 1s
                    OnMenuButtonHold();
                    m.ReceiverDescription = "MENU hold";
                    break;

                case 0xB4:     // released
                    m.ReceiverDescription = "MENU release";
                    IsEnabled             = false;
                    break;
                }
            }

            if (mediaEmulator.IsEnabled)
            {
                // BM buttons
                if (m.Data[0] == 0x48 && m.Data.Length == 2)
                {
                    switch (m.Data[1])
                    {
                    // switch screen
                    case 0x30:     // pressed
                        IsEnabled = !IsEnabled;
                        //if (screenSwitched) { UpdateScreen(); }
                        m.ReceiverDescription = "SwitchScreen press";
                        break;

                    case 0x70:     // hold
                        m.ReceiverDescription = "SwitchScreen hold";
                        break;

                    case 0xB0:     // released
                        m.ReceiverDescription = "SwitchScreen release";
                        break;
                    }
                }
            }

            if (IsEnabled)
            {
                // item click
                if (m.Data.Length == 4 && m.Data.StartsWith(Bordmonitor.DataItemClicked) && 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;
                }
            }
        }
Ejemplo n.º 4
0
        protected virtual void SetItems()
        {
            //AddItem(new MenuItem(i => i.IsChecked ? Localization.Current.TurnOff : Localization.Current.TurnOn,
            //    i =>
            //    {
            //        if (i.IsChecked)
            //        {
            //            Manager.Instance.EnqueueMessage(MessageStopAuxilaryHeater);
            //        }
            //        else
            //        {
            //            Manager.Instance.EnqueueMessage(MessageStartAuxilaryHeater);
            //        }
            //    }, MenuItemType.Checkbox));

            //AddItem(new MenuItem(i => SteuernZuheizerOn, i =>
            //{
            //    DBusManager.Port.WriteBufferSize = 0;

            //    AuxilaryHeater.StartAuxilaryHeaterOverDBus();
            //}, MenuItemType.Button, MenuItemAction.None));

            //AddItem(new MenuItem(i => SteuernZuheizerOff, i =>
            //{
            //    DBusManager.Port.WriteBufferSize = 0;

            //    AuxilaryHeater.StopAuxilaryHeaterOverDBus();
            //}, MenuItemType.Button, MenuItemAction.None));

            string label1 = "W>IHKA: 93 00 22";

            AddItem(new MenuItem(i => label1, i =>
            {
                Logger.Debug("Pressed: " + label1);
                KBusManager.Instance.EnqueueMessage(AuxilaryHeater.AuxilaryHeaterWorkingResponse);
            }, MenuItemType.Button, MenuItemAction.None));

            string label2 = "IHKA>W: 92 00 21";

            AddItem(new MenuItem(i => label2, i =>
            {
                Logger.Debug("Pressed: " + label2);
                KBusManager.Instance.EnqueueMessage(IntegratedHeatingAndAirConditioning.StopAuxilaryHeater1);
            }, MenuItemType.Button, MenuItemAction.None));

            string label3 = "IHKA>W: 92 00 11";

            AddItem(new MenuItem(i => label3, i =>
            {
                Logger.Debug("Pressed: " + label3);
                KBusManager.Instance.EnqueueMessage(IntegratedHeatingAndAirConditioning.StopAuxilaryHeater2);
            }, MenuItemType.Button, MenuItemAction.None));

            AddItem(new MenuItem(i => "StartAuxilaryHeater", i =>
            {
                IntegratedHeatingAndAirConditioning.StartAuxilaryHeater();
            }, MenuItemType.Button, MenuItemAction.None));

            AddItem(new MenuItem(i => "StopAuxilaryHeater", i =>
            {
                IntegratedHeatingAndAirConditioning.StopAuxilaryHeater();
            }, MenuItemType.Button, MenuItemAction.None));

            this.AddBackButton();
        }
Ejemplo n.º 5
0
        public static void Launch(LaunchMode launchMode = LaunchMode.MicroFramework)
        {
            try
            {
                Comfort.Init();
                IntegratedHeatingAndAirConditioning.Init();

                _resetCause = GHI.Processor.Watchdog.LastResetCause;

                blueLed   = new OutputPort(FEZPandaIII.Gpio.Led1, false);
                greenLed  = new OutputPort(FEZPandaIII.Gpio.Led2, false);
                orangeLed = new OutputPort(FEZPandaIII.Gpio.Led3, _resetCause == GHI.Processor.Watchdog.ResetCause.Watchdog);
                redLed    = new OutputPort(FEZPandaIII.Gpio.Led4, false);

#if (NETMF && RELEASE) || (OnBoardMonitorEmulator && !DebugOnRealDeviceOverFTDI)
                _useWatchdog = true;
#endif
                if (_useWatchdog)
                {
                    GHI.Processor.Watchdog.Enable(watchDogTimeoutInMilliseconds);
                }

                settings = Settings.Instance;

                FileLogger.Create();
                InitManagers();

                InstrumentClusterElectronics.DateTimeChanged += DateTimeChanged;

                Logger.Debug("Watchdog.ResetCause: " + (_resetCause == GHI.Processor.Watchdog.ResetCause.Normal ? "Normal" : "Watchdog"));
                if (_useWatchdog)
                {
                    Logger.Debug("Watchdog enabled with timeout: " + watchDogTimeoutInMilliseconds);
                }

                //SettingsScreen.Instance.Status = version.Length > 11 ? version.Replace(" ", "") : version;
                //Localization.SetCurrent(RussianLocalization.SystemName); //Localization.SetCurrent(settings.Language);
                //Comfort.AutoLockDoors = settings.AutoLockDoors;
                //Comfort.AutoUnlockDoors = settings.AutoUnlockDoors;
                //Comfort.AutoCloseWindows = settings.AutoCloseWindows;
                //Comfort.AutoCloseSunroof = settings.AutoCloseSunroof;

                #region MassStorage
                //Controller.DeviceConnectFailed += (sss, eee) =>
                //{
                //    Logger.Error("DeviceConnectFailed!");
                //    LedBlinkingQueueThreadWorker.Enqueue(new LedBlinkingItem(redLed, 1, 100));

                //    ControllerState = UsbMountState.DeviceConnectFailed;
                //    _removableMediaInsertedSync.Set();
                //};
                //Controller.UnknownDeviceConnected += (ss, ee) =>
                //{
                //    Logger.Error("UnknownDeviceConnected!");
                //    LedBlinkingQueueThreadWorker.Enqueue(new LedBlinkingItem(redLed, 2, 100));

                //    ControllerState = UsbMountState.UnknownDeviceConnected;
                //    _removableMediaInsertedSync.Set();
                //};
                //Controller.MassStorageConnected += (sender, massStorage) =>
                //{
                //    Logger.Debug("Controller MassStorageConnected!");
                //    LedBlinkingQueueThreadWorker.Enqueue(new LedBlinkingItem(orangeLed, 2, 100));
                //    ControllerState = UsbMountState.MassStorageConnected;

                RemovableMedia.Insert += (s, e) =>
                {
                    LedBlinkingQueueThreadWorker.Enqueue(new LedBlinkingItem(orangeLed, 3, 100));

                    string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
                    settings = Settings.Init(rootDirectory + "\\imBMW.ini");
                    FileLogger.Init(rootDirectory + "\\logs", () => VolumeInfo.GetVolumes()[0].FlushAll());
                    Logger.Debug("Logger initialized.");

                    MassStorageMountState = MassStorageMountState.Mounted;
                    _removableMediaInsertedSync.Set();
                };

                RemovableMedia.Eject += (s, e) =>
                {
                    FileLogger.Eject();
                    Logger.Print("RemovableMedia Ejected!");
                    LedBlinkingQueueThreadWorker.Enqueue(new LedBlinkingItem(greenLed, 3, 100));
                    MassStorageMountState = MassStorageMountState.Unmounted;
                };

                //_massStorage = massStorage;
                _massStorage = new SDCard(SDCard.SDInterface.SPI);
                _massStorage.Mount();
                //};
#if RELEASE
                //Controller.Start();
#else
#if NETMF
                // WARNING! Be aware, without this line you can get 'Controller -> DeviceConnectFailed' each time when you start debugging...
                if (Debugger.IsAttached)
#endif
                {
                    //Controller.Start();
                }
#endif
                #endregion

                LedBlinkingQueueThreadWorker.Enqueue(new LedBlinkingItem(orangeLed, 1, 200));
                bool isSignalled = _removableMediaInsertedSync.WaitOne(Debugger.IsAttached ? 10000 : 10000, true);
                if (!isSignalled) // No Storage inserted
                {
                    InstrumentClusterElectronics.ShowNormalTextWithGong(MassStorageMountState.ToStringValue());
                    FrontDisplay.RefreshLEDs(LedType.RedBlinking, append: true);
                    LedBlinkingQueueThreadWorker.Enqueue(new LedBlinkingItem(redLed, 3, 100));
                }
                else
                {
                    if (MassStorageMountState == MassStorageMountState.DeviceConnectFailed || MassStorageMountState == MassStorageMountState.UnknownDeviceConnected)
                    {
                        InstrumentClusterElectronics.ShowNormalTextWithGong(MassStorageMountState.ToStringValue());
                        FrontDisplay.RefreshLEDs(LedType.Red, append: true);
                        LedBlinkingQueueThreadWorker.Enqueue(new LedBlinkingItem(redLed, 4, 100));
                        ResetBoard();
                    }
                }
                Logger.Debug("MassStorage state: " + MassStorageMountState.ToStringValue());

                InstrumentClusterElectronics.RequestDateTime();

                Init();

                Logger.Debug("Started!");

                BordmonitorMenu.MenuButtonHold += () =>
                {
                    FrontDisplay.RefreshLEDs(LedType.Empty);

                    if (Emulator.IsEnabled)
                    {
                        Emulator.PlayerIsPlayingChanged += (s, isPlayingChangedValue) =>
                        {
                            if (!isPlayingChangedValue)
                            {
                                ResetBoard();
                            }
                        };
                        Radio.PressOnOffToggle();
                        //Emulator.IsEnabled = false;
                    }
                    else
                    {
                        ResetBoard();
                    }
                };
                BordmonitorMenu.PhoneButtonHold += () =>
                {
                    VolumioRestApiPlayer.Reboot();
                    Logger.Warning("Reboot request sent.");
                };
                BordmonitorMenu.EjectButtonHold += () =>
                {
                    UnmountMassStorage();
                    _massStorage = null;
                    Logger.Warning("UNMOUNTED!");
                };

                Manager.Instance.AddMessageReceiverForSourceDevice(DeviceAddress.InstrumentClusterElectronics, m =>
                {
                    if (m.Data[0] == 0x11 && m.Data.Length == 2) // Ignition status
                    {
                        GHI.Processor.Watchdog.ResetCounter();
                    }
                });
                requestIgnitionStateTimer = new Timer(RequestIgnitionStateTimerHandler, null, 0, requestIgnitionStateTimerPeriod);

                imBMWTest();

                Logger.Debug("Actions inited!");

                if (launchMode == LaunchMode.MicroFramework)
                {
                    Thread.Sleep(Timeout.Infinite);
                }
            }
            catch (Exception ex)
            {
                LedBlinking(new LedBlinkingItem(redLed, 5, 200));
                Thread.Sleep(200);
                redLed.Write(true);
                Logger.Error(ex, "while modules initialization");
                ResetBoard();
            }
        }
Ejemplo n.º 6
0
        public void ShouldStartAndStopAuxilaryHeater()
        {
            AuxilaryHeaterEmulator.Init(2000);
            Launcher.Launch(Launcher.LaunchMode.WPF);
            Settings.Instance.SuspendAuxilaryHeaterResponseEmulation = false;

            ManualResetEvent     waitHandle = new ManualResetEvent(false);
            AuxilaryHeaterStatus status1    = AuxilaryHeaterStatus.Unknown;
            AuxilaryHeaterStatus status2    = AuxilaryHeaterStatus.Unknown;
            AuxilaryHeaterStatus status3    = AuxilaryHeaterStatus.Unknown;

            AuxilaryHeater.StatusChanged += (status) =>
            {
                if (status == AuxilaryHeaterStatus.Starting)
                {
                    status1 = AuxilaryHeaterStatus.Starting;
                }

                if (status == AuxilaryHeaterStatus.Started)
                {
                    status2 = AuxilaryHeaterStatus.Started;
                }

                if (status == AuxilaryHeaterStatus.Working)
                {
                    status3 = AuxilaryHeaterStatus.Working;
                }

                if (status == AuxilaryHeaterStatus.Working)
                {
                    waitHandle.Set();
                }
            };

            IntegratedHeatingAndAirConditioning.StartAuxilaryHeater();
            bool result = waitHandle.Wait(5000);

            Assert.IsTrue(result);
            Assert.IsTrue(status1 == AuxilaryHeaterStatus.Starting);
            Assert.IsTrue(status2 == AuxilaryHeaterStatus.Started);
            Assert.IsTrue(status3 == AuxilaryHeaterStatus.Working);


            waitHandle.Reset();
            AuxilaryHeaterStatus status4 = AuxilaryHeaterStatus.Stopping;
            AuxilaryHeaterStatus status5 = AuxilaryHeaterStatus.Stopped;

            AuxilaryHeater.StatusChanged += (status) =>
            {
                if (status == AuxilaryHeaterStatus.Stopping)
                {
                    status4 = AuxilaryHeaterStatus.Stopping;
                }

                if (status == AuxilaryHeaterStatus.Stopped)
                {
                    status5 = AuxilaryHeaterStatus.Stopped;
                }

                if (status == AuxilaryHeaterStatus.Stopped)
                {
                    waitHandle.Set();
                }
            };

            IntegratedHeatingAndAirConditioning.StopAuxilaryHeater();
            result = waitHandle.Wait(3000);
            Assert.IsTrue(result);
            Assert.IsTrue(status4 == AuxilaryHeaterStatus.Stopping);
            Assert.IsTrue(status5 == AuxilaryHeaterStatus.Stopped);
        }