Пример #1
0
        private void FireAlarmListenerOnStatusChanged(FireAlarmListener listener, FireAlarmStatus status)
        {
            var mute = status == FireAlarmStatus.Alert;

            CloudLog.Warn("Fire Alarm Interface changed status to: {0}", status.ToString());

            try
            {
                PromptUsers(prompt => { }, "FIRE ALARM", "Please listen for announcements", 300, null,
                            new PromptAction
                {
                    ActionName = "OK",
                    ActionType = PromptActionType.Acknowledge
                });
            }
            catch (Exception e)
            {
                CloudLog.Exception(e);
            }

            if (Dsp != null && Dsp.ContainsComponentWithName("fire.mute"))
            {
                var muteGainBlock = Dsp["fire.mute"] as IAudioLevelControl;
                if (muteGainBlock != null && muteGainBlock.SupportsMute)
                {
                    CloudLog.Notice("Dsp mute {0} set to {1}", muteGainBlock.Name, mute ? "muted" : "unmuted");
                    muteGainBlock.Muted = mute;
                    return;
                }
            }

            foreach (var room in Rooms.Cast <ARoom>().Where(room => room.ProgramVolume != null))
            {
                CloudLog.Warn("Fire Alarm {0} program volume in Room {1}", mute ? "muted" : "unmuted", room.Name);
                room.ProgramVolume.Muted = mute;
            }
        }
Пример #2
0
        protected ASystem(CrestronControlSystem controlSystem)
            : base(controlSystem, Assembly.GetExecutingAssembly())
        {
            Debug.WriteInfo("System.ctor()", "Started");

            BootStatus          = "Loading System Type \"" + GetType().Name + "\"";
            BootProgressPercent = 5;

            SoftwareUpdate.SoftwareUpdate.UpdateShouldLoad += LoadUpdate;

            CrestronConsole.AddNewConsoleCommand(parameters =>
            {
                if (parameters.Trim() == "?")
                {
                    CrestronConsole.ConsoleCommandResponse(
                        "Start running a test script. Options here are as follows:\r\n" +
                        "  count  - set the number of times the script should loop and change sources\r\n" +
                        "  number - set the number to dial if the codec is selected\r\n" +
                        "for example: \"TestScriptStart count 10 number 1234");
                    return;
                }

                var args = new Dictionary <string, string>();

                try
                {
                    var matches = Regex.Matches(parameters, @"(?:(\w+)\s+(\w+))");

                    foreach (Match match in matches)
                    {
                        args[match.Groups[1].Value] = match.Groups[2].Value;
                    }
                }
                catch (Exception e)
                {
                    CrestronConsole.ConsoleCommandResponse("Error parsing args, {0}", e.Message);
                    return;
                }

                try
                {
                    TestScriptStart(args);
                }
                catch (Exception e)
                {
                    CrestronConsole.ConsoleCommandResponse("Error: {0}", e.Message);
                }
            }, "TestScriptStart", "Start a test script", ConsoleAccessLevelEnum.AccessOperator);

            CrestronConsole.AddNewConsoleCommand(parameters => TestScriptStop(), "TestScriptStop",
                                                 "Stop running the test script", ConsoleAccessLevelEnum.AccessOperator);

            CrestronConsole.AddNewConsoleCommand(parameters =>
            {
                try
                {
                    var id          = uint.Parse(parameters);
                    Rooms[1].Source = id == 0 ? null : Sources[id];
                    CrestronConsole.ConsoleCommandResponse("Selected source \"{0}\" in Room \"{1}\"", Sources[id],
                                                           Rooms[1].Name);
                }
                catch (Exception e)
                {
                    CrestronConsole.ConsoleCommandResponse("Error: {0}", e.Message);
                }
            }, "Source", "Select a source by ID for the first room", ConsoleAccessLevelEnum.AccessOperator);

            CrestronConsole.AddNewConsoleCommand(parameters =>
            {
                try
                {
                    foreach (var source in Sources)
                    {
                        CrestronConsole.ConsoleCommandResponse("Source {0}: {1}", source.Id, source.Name);
                    }
                }
                catch (Exception e)
                {
                    CrestronConsole.ConsoleCommandResponse("Error: {0}", e.Message);
                }
            }, "ListSources", "List sources by IDs", ConsoleAccessLevelEnum.AccessOperator);

            StartWebApp(9001);

            if (ConfigManager.Config.SystemType == SystemType.NotConfigured)
            {
                return;
            }

            var config = ConfigManager.Config;

            Debug.WriteInfo("System.ctor()", "Config loaded");

            #region System Switcher

            BootStatus          = "Loading switcher configuration";
            BootProgressPercent = 6;

            if (config.SwitcherType != SystemSwitcherType.NotInstalled)
            {
                try
                {
                    switch (config.SwitcherType)
                    {
                    case SystemSwitcherType.BigDmFrame:
                        Switcher = new BigDmSwitcher(controlSystem as ControlSystem,
                                                     config.SwitcherConfig);
                        Switcher.InputStatusChanged += LocalSwitcherOnInputStatusChanged;
                        break;

                    case SystemSwitcherType.DmFrame:
                        Switcher = new DmSwitcher(controlSystem as ControlSystem,
                                                  config.SwitcherConfig);
                        Switcher.InputStatusChanged += LocalSwitcherOnInputStatusChanged;
                        break;
                    }
                }
                catch (Exception e)
                {
                    CloudLog.Exception(e, "Error loading System Video Switcher");
                }
            }

            #endregion

            var controllers = config.OneBeyondAddresses.ToDictionary(address => address.Key,
                                                                     address => new OneBeyond(address.Value, address.Key));

            _oneBeyondControllers = new ReadOnlyDictionary <uint, OneBeyond>(controllers);

            #region DSP

            BootStatus          = "Loading dsp configuration";
            BootProgressPercent = 7;

            if (config.DspConfig != null && config.DspConfig.Enabled)
            {
                Dsp = new QsysCore(new[] { config.DspConfig.DeviceAddressString }, config.DspConfig.Name,
                                   config.DspConfig.Username, config.DspConfig.Password);
                Dsp.HasIntitialized += DspOnHasIntitialized;
            }

            #endregion

            #region Rooms

            BootStatus          = "Loading Room Configs";
            BootProgressPercent = 10;

            foreach (var roomConfig in config.Rooms
                     .Where(r => r.Enabled)
                     .OrderBy(r => r.Id))
            {
                Debug.WriteInfo("System.ctor()", "Setting up {0} room \"{1}\"", config.SystemType, roomConfig.Name);
                try
                {
                    var room = (ARoom)Assembly.GetExecutingAssembly()
                               .GetType(roomConfig.RoomType)
                               .GetConstructor(new CType[] { GetType(), typeof(RoomConfig) })
                               .Invoke(new object[] { this, roomConfig });
                    WebApp.AddXpanelLink(string.Format("/dashboard/app/xpanel/xpanel?room={0}", room.Id), room.Name);
                }
                catch (Exception e)
                {
                    CloudLog.Exception(e, "Failed to load room type \"{0}\"", roomConfig.RoomType);
                }
            }

            #endregion

            #region Global Sources

            if (config.GlobalSources != null)
            {
                foreach (var sourceConfig in config.GlobalSources
                         .Where(s => s.Enabled)
                         .OrderBy(s => s.Id))
                {
                    Debug.WriteInfo("System.ctor()", "Setting up global source \"{0}\", {1}", sourceConfig.Name,
                                    sourceConfig.SourceType);

                    switch (sourceConfig.SourceType)
                    {
                    case SourceType.AppleTV:
                        var appleTV = new AppleTV(controlSystem.IROutputPorts[sourceConfig.DeviceAddressNumber]);
                        new GenericSource(this, sourceConfig, appleTV);
                        break;

                    case SourceType.PC:
                        new PCSource(this, sourceConfig);
                        break;

                    default:
                        new GenericSource(this, sourceConfig);
                        break;
                    }
                }
            }

            #endregion

            #region User Interfaces

            BootStatus          = "Loading UI Controllers";
            BootProgressPercent = 15;
#if DEBUG
            Debug.WriteInfo("Setting up User Interfaces", "Count = {0}", config.UserInterfaces.Count(ui => ui.Enabled));
            Debug.WriteInfo(JToken.FromObject(config.UserInterfaces).ToString(Formatting.Indented));
#endif

            foreach (var uiConfig in config.UserInterfaces.Where(ui => ui.Enabled))
            {
                try
                {
                    Debug.WriteInfo("System.ctor()", "Setting up UIController \"{0}\", {1} 0x{2:X2}", uiConfig.Name,
                                    uiConfig.DeviceType, uiConfig.DeviceAddressNumber);

                    if (uiConfig.UIControllerType == UIControllerType.RemoteMpc)
                    {
                        var isc = new ThreeSeriesTcpIpEthernetIntersystemCommunications(uiConfig.DeviceAddressNumber,
                                                                                        uiConfig.DeviceAddressString, controlSystem);
                        var mpcUi = new MpcUIController(this, isc, Rooms.ContainsKey(uiConfig.DefaultRoom)
                            ? Rooms[uiConfig.DefaultRoom]
                            : null);
                        mpcUi.Register();
                        continue;
                    }

                    var uiAssembly = Assembly.LoadFrom(@"Crestron.SimplSharpPro.UI.dll");
                    var type       = uiAssembly.GetType("Crestron.SimplSharpPro.UI." + uiConfig.DeviceType);
                    BasicTriListWithSmartObject panel;
                    var ctor = type.GetConstructor(new CType[] { typeof(UInt32), typeof(ControlSystem) });
                    panel = (BasicTriListWithSmartObject)
                            ctor.Invoke(new object[] { uiConfig.DeviceAddressNumber, controlSystem });

                    var app = panel as CrestronApp;
                    if (app != null && !string.IsNullOrEmpty(uiConfig.DeviceAddressString))
                    {
                        app.ParameterProjectName.Value = uiConfig.DeviceAddressString;
                    }

                    if (panel != null)
                    {
                        panel.Description = uiConfig.Name;
                    }

                    UIController ui = null;

                    RoomBase defaultRoom;
                    switch (uiConfig.UIControllerType)
                    {
                    case UIControllerType.TechPanel:
                        defaultRoom = Rooms.ContainsKey(uiConfig.DefaultRoom)
                                ? Rooms[uiConfig.DefaultRoom]
                                : null;
                        ui = new RoomUIController(this, panel, defaultRoom, true);
                        break;

                    case UIControllerType.UserPanel:
                        defaultRoom = Rooms.ContainsKey(uiConfig.DefaultRoom)
                                ? Rooms[uiConfig.DefaultRoom]
                                : null;
                        ui = new RoomUIController(this, panel, defaultRoom, false);
                        break;
                    }

                    foreach (var room in uiConfig.AllowedRoomIds)
                    {
                        ui.AddRoomToAllowedRooms(Rooms[room]);
                    }

                    if (ui != null)
                    {
                        ui.Register();
                    }
                }
                catch (Exception e)
                {
                    CloudLog.Exception(e, "Error loading UI device {0} 0x{1:X2}", uiConfig.DeviceType,
                                       uiConfig.DeviceAddressNumber);
                }
            }

            UIControllers.SetupCustomTime(Serials.Time);
            UIControllers.SetupCustomDate(Serials.Date);

            #endregion

            if (this is FireAlarmMonitorSystem)
            {
                return;
            }

            var fireInterfaceAddress = ConfigManager.GetCustomValue("FireAlarmInterfaceAddress") as string;
            if (string.IsNullOrEmpty(fireInterfaceAddress))
            {
                return;
            }
            _fireAlarmListener = new FireAlarmListener(fireInterfaceAddress);
            _fireAlarmListener.StatusChanged += FireAlarmListenerOnStatusChanged;
        }