/// <summary> /// Returns the next available slot number in the Fusion UserConfigurableAssetDetails collection /// </summary> /// <param name="room"></param> /// <returns></returns> public static uint GetNextAvailableAssetNumber(FusionRoom room) { uint slotNum = 0; foreach (var item in room.UserConfigurableAssetDetails) { if (item.Number > slotNum) { slotNum = item.Number; } } if (slotNum < 5) { slotNum = 5; } else { slotNum = slotNum + 1; } Debug.Console(2, "#Next available fusion asset number is: {0}", slotNum); return(slotNum); }
protected override void MapDisplayToRoomJoins(int displayIndex, int joinOffset, DisplayBase display) { string displayName = string.Format("Display {0} - ", displayIndex); if (display == (Room as EssentialsHuddleVtc1Room).DefaultDisplay) { // Power on var defaultDisplayPowerOn = FusionRoom.CreateOffsetBoolSig((uint)joinOffset, displayName + "Power On", eSigIoMask.InputOutputSig); defaultDisplayPowerOn.OutputSig.UserObject = new Action <bool>(b => { if (!b) { display.PowerOn(); } }); display.PowerIsOnFeedback.LinkInputSig(defaultDisplayPowerOn.InputSig); // Power Off var defaultDisplayPowerOff = FusionRoom.CreateOffsetBoolSig((uint)joinOffset + 1, displayName + "Power Off", eSigIoMask.InputOutputSig); defaultDisplayPowerOn.OutputSig.UserObject = new Action <bool>(b => { if (!b) { display.PowerOff(); } });; display.PowerIsOnFeedback.LinkInputSig(defaultDisplayPowerOn.InputSig); // Current Source var defaultDisplaySourceNone = FusionRoom.CreateOffsetBoolSig((uint)joinOffset + 8, displayName + "Source None", eSigIoMask.InputOutputSig); defaultDisplaySourceNone.OutputSig.UserObject = new Action <bool>(b => { if (!b) { (Room as EssentialsHuddleVtc1Room).RunRouteAction("roomOff"); } });; } }
internal void FusionRegisterInternal() { var ipId = FusionShouldRegister(); try { if (ipId > 0) { IpIdFactory.Block(ipId, IpIdFactory.DeviceType.Fusion); Fusion = new FusionRoom(ipId, System.ControlSystem, Name, Guid.NewGuid().ToString()); Fusion.Description = "Fusion for " + Name; Fusion.FusionStateChange += OnFusionStateChange; Fusion.OnlineStatusChange += OnFusionOnlineStatusChange; Fusion.FusionAssetStateChange += FusionOnFusionAssetStateChange; } else { return; } } catch (Exception e) { CloudLog.Exception(e); } try { FusionShouldRegisterUserSigs(); } catch (Exception e) { CloudLog.Exception(e); } try { FusionShouldRegisterAssets(); } catch (Exception e) { CloudLog.Exception(e); } try { var regResult = Fusion.Register(); if (regResult != eDeviceRegistrationUnRegistrationResponse.Success) { CloudLog.Error("Error registering fusion in room {0} with IpId 0x{1:X2}, result = {2}", Id, ipId, regResult); } } catch (Exception e) { CloudLog.Exception(e); } }
/// <summary> /// Constructor of the Control System Class. Make sure the constructor always exists. /// If it doesn't exit, the code will not run on your 3-Series processor. /// </summary> public ControlSystem() : base() { // Set the number of system and user threads which you want to use in your program . // User threads are created using the CrestronThread class // System threads are used for CTimers/CrestronInvoke/Async Socket operations // At this point the threads cannot be created but we should // define the max number of threads which we will use in the system. // the right number depends on your project; do not make this number unnecessarily large Thread.MaxNumberOfUserThreads = 20; #if UseStaticGUID // Create the room object (parent of the assets and attributes). this contains all of the events you will need myRoom = new FusionRoom(0xf0, this, "SSP Fusion Room (Static)", "BA65B6F1-DC9B-47f5-8577-F32782045380"); // this uses a status guid i created with the "Create GUID" tool (Tools Menu >> Create GUID). Select "Registry Format" // Add some assets, there are several types you can add myRoom.AddAsset(eAssetType.OccupancySensor, 1, "Occupancy Sensor", "Occupancy Sensor", "540E4FA9-97BE-4e21-A87E-C37E5B150FD0"); myRoom.AddAsset(eAssetType.StaticAsset, 2, "Xpanel", "UI", "8081EA14-4869-4b86-877B-0075366BA8C6"); myRoom.AddAsset(eAssetType.LightingLoad, 3, "Lights", "Lighting Load", "A74A1501-78E6-4a19-B0A8-F004C999F896"); #endif #if !UseStaticGUID // Create the room object (parent of the assets and attributes). this contains all of the events you will need myRoom = new FusionRoom(0xf1, this, "SSP Fusion Room (Dynamic)", GuidManager.GetGuid("FusionRoom")); // this is the same as above but will create a unique guid at first start up, then read from file after that // Add some assets, there are several types you can add myRoom.AddAsset(eAssetType.OccupancySensor, 1, "Occupancy Sensor", "Occupancy Sensor", GuidManager.GetGuid("SensorAsset")); myRoom.AddAsset(eAssetType.StaticAsset, 2, "Xpanel", "UI", GuidManager.GetGuid("XpanelAsset")); myRoom.AddAsset(eAssetType.LightingLoad, 3, "Lights", "Lighting Load", GuidManager.GetGuid("Lights")); #endif // assign a more friendly reference to these assets and cast to the propper type mySensorAsset = (FusionOccupancySensor)myRoom.UserConfigurableAssetDetails[1].Asset; myTouchScreenAsset = (FusionStaticAsset)myRoom.UserConfigurableAssetDetails[2].Asset; myLightingLoad = (FusionLightingLoad)myRoom.UserConfigurableAssetDetails[3].Asset; // adjust parameters for the assets, some have required parameters myTouchScreenAsset.ParamMake.Value = "Crestron"; myTouchScreenAsset.ParamModel.Value = "TSW-1052-B-S"; myLightingLoad.ParamDimmable = false; myLightingLoad.ParamMeterType = eMeterType.Simulated; // Add some custom sigs (attributes) // the attribute IDs start at 50, just like in simpl, but the SDK will add 49 to the number you provide here. The following three lines create one attribute of each type with ID "50" myRoom.AddSig(eSigType.Bool, 1, "_Digital Attribute", eSigIoMask.InputOutputSig); // bool = digital, this is set for InputOutputSig (i.e. read from fusion / write to fusion) myRoom.AddSig(eSigType.String, 1, "_Serial Attribute", eSigIoMask.InputSigOnly); // string = serial, this is set for InputSigOnly (i.e. write to fusion) myRoom.AddSig(eSigType.UShort, 1, "_Analog Attribyte", eSigIoMask.OutputSigOnly); // ushort = analog, this is set for OutputSigOnly (i.e. read from fusion) // subscribe to events myRoom.FusionAssetStateChange += new FusionAssetStateEventHandler(myRoom_FusionAssetStateChange); myRoom.FusionStateChange += new FusionStateEventHandler(myRoom_FusionStateChange); myRoom.OnlineStatusChange += new OnlineStatusChangeEventHandler(myRoom_OnlineStatusChange); myRoom.Register(); // I usually add some sort of check to make sure it is registered okay, but i'm lazy today TouchscreenOnlineToggleTimer = new CTimer(TouchScreenOnlineToggleCallback, null, Timeout.Infinite, Timeout.Infinite); }
/// <summary> /// Adds an asset to the StaticAssets collection and returns the new asset /// </summary> /// <param name="room"></param> /// <param name="uid"></param> /// <param name="assetName"></param> /// <param name="type"></param> /// <param name="instanceId"></param> /// <returns></returns> public FusionAsset AddStaticAsset(FusionRoom room, int uid, string assetName, string type, string instanceId) { var slotNum = GetNextAvailableAssetNumber(room); Debug.Console(2, "Adding Fusion Asset: {0} of Type: {1} at Slot Number: {2} with GUID: {3}", assetName, type, slotNum, instanceId); var tempAsset = new FusionAsset(slotNum, assetName, type, instanceId); StaticAssets.Add(uid, tempAsset); return(tempAsset); }
public FusionManager(CrestronControlSystem cs, uint ipid, string roomName) { try { this.cs = cs; Trace("Constructor running."); // create new FusionRoom object string roomID = new Guid().ToString(); room = new FusionRoom(ipid, cs, roomName, roomID); // add assets AddAssets(); // add event handlers room.OnlineStatusChange += new OnlineStatusChangeEventHandler(OnlineStatusChange); room.FusionStateChange += new FusionStateEventHandler(FusionStateChange); room.FusionAssetStateChange += new FusionAssetStateEventHandler(AssetStateChange); // generate rvi file FusionRVI.GenerateFileForAllFusionDevices(); // attempt to register eDeviceRegistrationUnRegistrationResponse response = room.Register(); if (response == eDeviceRegistrationUnRegistrationResponse.Success) { Trace("Room registered successfully."); } else { Trace("Room failed to register: " + response); } } catch (Exception e) { string traceMessage = "Exception caught in constructor: " + e.Message + e.StackTrace; Trace(traceMessage); ErrorLog.Error(traceMessage); } }
// These methods are overridden because they access the room class which is of a different type protected override void CreateSymbolAndBasicSigs(uint ipId) { Debug.Console(1, this, "Creating Fusion Room symbol with GUID: {0}", RoomGuid); FusionRoom = new FusionRoom(ipId, Global.ControlSystem, Room.Name, RoomGuid); FusionRoom.ExtenderRoomViewSchedulingDataReservedSigs.Use(); FusionRoom.ExtenderFusionRoomDataReservedSigs.Use(); FusionRoom.Register(); FusionRoom.FusionStateChange += FusionRoom_FusionStateChange; FusionRoom.ExtenderRoomViewSchedulingDataReservedSigs.DeviceExtenderSigChange += FusionRoomSchedule_DeviceExtenderSigChange; FusionRoom.ExtenderFusionRoomDataReservedSigs.DeviceExtenderSigChange += ExtenderFusionRoomDataReservedSigs_DeviceExtenderSigChange; FusionRoom.OnlineStatusChange += FusionRoom_OnlineStatusChange; CrestronConsole.AddNewConsoleCommand(RequestFullRoomSchedule, "FusReqRoomSchedule", "Requests schedule of the room for the next 24 hours", ConsoleAccessLevelEnum.AccessOperator); CrestronConsole.AddNewConsoleCommand(ModifyMeetingEndTimeConsoleHelper, "FusReqRoomSchMod", "Ends or extends a meeting by the specified time", ConsoleAccessLevelEnum.AccessOperator); CrestronConsole.AddNewConsoleCommand(CreateAsHocMeeting, "FusCreateMeeting", "Creates and Ad Hoc meeting for on hour or until the next meeting", ConsoleAccessLevelEnum.AccessOperator); // Room to fusion room Room.OnFeedback.LinkInputSig(FusionRoom.SystemPowerOn.InputSig); // Moved to CurrentRoomSourceNameSig = FusionRoom.CreateOffsetStringSig(84, "Display 1 - Current Source", eSigIoMask.InputSigOnly); // Don't think we need to get current status of this as nothing should be alive yet. (Room as EssentialsHuddleVtc1Room).CurrentSourceChange += Room_CurrentSourceInfoChange; FusionRoom.SystemPowerOn.OutputSig.SetSigFalseAction((Room as EssentialsHuddleVtc1Room).PowerOnToDefaultOrLastSource); FusionRoom.SystemPowerOff.OutputSig.SetSigFalseAction(() => (Room as EssentialsHuddleVtc1Room).RunRouteAction("roomOff")); // NO!! room.RoomIsOn.LinkComplementInputSig(FusionRoom.SystemPowerOff.InputSig); CrestronEnvironment.EthernetEventHandler += CrestronEnvironment_EthernetEventHandler; }
/// <summary> /// Creates a static asset for the codec and maps the joins to the main room symbol /// </summary> void SetUpCodec() { try { var codec = (Room as EssentialsHuddleVtc1Room).VideoCodec; if (codec == null) { Debug.Console(1, this, "Cannot link codec to Fusion because codec is null"); return; } codec.UsageTracker = new UsageTracking(codec); codec.UsageTracker.UsageIsTracked = true; codec.UsageTracker.DeviceUsageEnded += UsageTracker_DeviceUsageEnded; var codecPowerOnAction = new Action <bool>(b => { if (!b) { codec.StandbyDeactivate(); } }); var codecPowerOffAction = new Action <bool>(b => { if (!b) { codec.StandbyActivate(); } }); // Map FusionRoom Attributes: // Codec volume var codecVolume = FusionRoom.CreateOffsetUshortSig(50, "Volume - Fader01", eSigIoMask.InputOutputSig); codecVolume.OutputSig.UserObject = new Action <ushort>(b => (codec as IBasicVolumeWithFeedback).SetVolume(b)); (codec as IBasicVolumeWithFeedback).VolumeLevelFeedback.LinkInputSig(codecVolume.InputSig); // In Call Status CodecIsInCall = FusionRoom.CreateOffsetBoolSig(69, "Conf - VC 1 In Call", eSigIoMask.InputSigOnly); codec.CallStatusChange += new EventHandler <PepperDash.Essentials.Devices.Common.Codec.CodecCallStatusItemChangeEventArgs>(codec_CallStatusChange); // Online status if (codec is ICommunicationMonitor) { var c = codec as ICommunicationMonitor; var codecOnline = FusionRoom.CreateOffsetBoolSig(122, "Online - VC 1", eSigIoMask.InputSigOnly); codecOnline.InputSig.BoolValue = c.CommunicationMonitor.Status == MonitorStatus.IsOk; c.CommunicationMonitor.StatusChange += (o, a) => { codecOnline.InputSig.BoolValue = a.Status == MonitorStatus.IsOk; }; Debug.Console(0, this, "Linking '{0}' communication monitor to Fusion '{1}'", codec.Key, "Online - VC 1"); } // Codec IP Address bool codecHasIpInfo = false; var codecComm = codec.Communication; string codecIpAddress = string.Empty; int codecIpPort = 0; StringSigData codecIpAddressSig; StringSigData codecIpPortSig; if (codecComm is GenericSshClient) { codecIpAddress = (codecComm as GenericSshClient).Hostname; codecIpPort = (codecComm as GenericSshClient).Port; codecHasIpInfo = true; } else if (codecComm is GenericTcpIpClient) { codecIpAddress = (codecComm as GenericTcpIpClient).Hostname; codecIpPort = (codecComm as GenericTcpIpClient).Port; codecHasIpInfo = true; } if (codecHasIpInfo) { codecIpAddressSig = FusionRoom.CreateOffsetStringSig(121, "IP Address - VC", eSigIoMask.InputSigOnly); codecIpAddressSig.InputSig.StringValue = codecIpAddress; codecIpPortSig = FusionRoom.CreateOffsetStringSig(150, "IP Port - VC", eSigIoMask.InputSigOnly); codecIpPortSig.InputSig.StringValue = codecIpPort.ToString(); } var tempAsset = new FusionAsset(); var deviceConfig = ConfigReader.ConfigObject.Devices.FirstOrDefault(c => c.Key.Equals(codec.Key)); if (FusionStaticAssets.ContainsKey(deviceConfig.Uid)) { tempAsset = FusionStaticAssets[deviceConfig.Uid]; } else { // Create a new asset tempAsset = new FusionAsset(FusionRoomGuids.GetNextAvailableAssetNumber(FusionRoom), codec.Name, "Codec", ""); FusionStaticAssets.Add(deviceConfig.Uid, tempAsset); } var codecAsset = FusionRoom.CreateStaticAsset(tempAsset.SlotNumber, tempAsset.Name, "Display", tempAsset.InstanceId); codecAsset.PowerOn.OutputSig.UserObject = codecPowerOnAction; codecAsset.PowerOff.OutputSig.UserObject = codecPowerOffAction; codec.StandbyIsOnFeedback.LinkComplementInputSig(codecAsset.PowerOn.InputSig); // TODO: Map relevant attributes on asset symbol codecAsset.TrySetMakeModel(codec); codecAsset.TryLinkAssetErrorToCommunication(codec); } catch (Exception e) { Debug.Console(1, this, "Error setting up codec in Fusion: {0}", e); } }
protected override void SetUpDisplay() { try { //Setup Display Usage Monitoring var displays = DeviceManager.AllDevices.Where(d => d is DisplayBase); // Consider updating this in multiple display systems foreach (DisplayBase display in displays) { display.UsageTracker = new UsageTracking(display); display.UsageTracker.UsageIsTracked = true; display.UsageTracker.DeviceUsageEnded += new EventHandler <DeviceUsageEventArgs>(UsageTracker_DeviceUsageEnded); } var defaultDisplay = (Room as EssentialsHuddleVtc1Room).DefaultDisplay as DisplayBase; if (defaultDisplay == null) { Debug.Console(1, this, "Cannot link null display to Fusion because default display is null"); return; } var dispPowerOnAction = new Action <bool>(b => { if (!b) { defaultDisplay.PowerOn(); } }); var dispPowerOffAction = new Action <bool>(b => { if (!b) { defaultDisplay.PowerOff(); } }); // Display to fusion room sigs FusionRoom.DisplayPowerOn.OutputSig.UserObject = dispPowerOnAction; FusionRoom.DisplayPowerOff.OutputSig.UserObject = dispPowerOffAction; defaultDisplay.PowerIsOnFeedback.LinkInputSig(FusionRoom.DisplayPowerOn.InputSig); if (defaultDisplay is IDisplayUsage) { (defaultDisplay as IDisplayUsage).LampHours.LinkInputSig(FusionRoom.DisplayUsage.InputSig); } MapDisplayToRoomJoins(1, 158, defaultDisplay); var deviceConfig = ConfigReader.ConfigObject.Devices.FirstOrDefault(d => d.Key.Equals(defaultDisplay.Key)); //Check for existing asset in GUIDs collection var tempAsset = new FusionAsset(); if (FusionStaticAssets.ContainsKey(deviceConfig.Uid)) { tempAsset = FusionStaticAssets[deviceConfig.Uid]; } else { // Create a new asset tempAsset = new FusionAsset(FusionRoomGuids.GetNextAvailableAssetNumber(FusionRoom), defaultDisplay.Name, "Display", ""); FusionStaticAssets.Add(deviceConfig.Uid, tempAsset); } var dispAsset = FusionRoom.CreateStaticAsset(tempAsset.SlotNumber, tempAsset.Name, "Display", tempAsset.InstanceId); dispAsset.PowerOn.OutputSig.UserObject = dispPowerOnAction; dispAsset.PowerOff.OutputSig.UserObject = dispPowerOffAction; defaultDisplay.PowerIsOnFeedback.LinkInputSig(dispAsset.PowerOn.InputSig); // NO!! display.PowerIsOn.LinkComplementInputSig(dispAsset.PowerOff.InputSig); // Use extension methods dispAsset.TrySetMakeModel(defaultDisplay); dispAsset.TryLinkAssetErrorToCommunication(defaultDisplay); } catch (Exception e) { Debug.Console(1, this, "Error setting up display in Fusion: {0}", e); } }