Updates to complete SamsungMDC driver addition

This commit is contained in:
Neil Dorin
2017-07-27 14:33:06 -06:00
parent 7abccd8865
commit 5d0f50677a
14 changed files with 567 additions and 558 deletions

View File

@@ -1,99 +1,110 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DM;
using Crestron.SimplSharpPro.DM.Endpoints;
using Crestron.SimplSharpPro.DM.Endpoints.Transmitters;
using PepperDash.Core;
namespace PepperDash.Essentials.Core
{
/// <summary>
///
/// </summary>
public abstract class DisplayBase : Device, IHasFeedback, IRoutingSinkWithSwitching, IPower, IWarmingCooling
{
public BoolFeedback PowerIsOnFeedback { get; protected set; }
public BoolFeedback IsCoolingDownFeedback { get; protected set; }
public BoolFeedback IsWarmingUpFeedback { get; private set; }
public uint WarmupTime { get; set; }
public uint CooldownTime { get; set; }
/// <summary>
/// Bool Func that will provide a value for the PowerIsOn Output. Must be implemented
/// by concrete sub-classes
/// </summary>
abstract protected Func<bool> PowerIsOnFeedbackFunc { get; }
abstract protected Func<bool> IsCoolingDownFeedbackFunc { get; }
abstract protected Func<bool> IsWarmingUpFeedbackFunc { get; }
protected CTimer WarmupTimer;
protected CTimer CooldownTimer;
#region IRoutingInputs Members
public RoutingPortCollection<RoutingInputPort> InputPorts { get; private set; }
#endregion
public DisplayBase(string key, string name)
: base(key, name)
{
PowerIsOnFeedback = new BoolFeedback(CommonBoolCue.PowerOnFeedback, PowerIsOnFeedbackFunc);
IsCoolingDownFeedback = new BoolFeedback(CommonBoolCue.IsCoolingDown, IsCoolingDownFeedbackFunc);
IsWarmingUpFeedback = new BoolFeedback(CommonBoolCue.IsWarmingUp, IsWarmingUpFeedbackFunc);
InputPorts = new RoutingPortCollection<RoutingInputPort>();
}
public abstract void PowerOn();
public abstract void PowerOff();
public abstract void PowerToggle();
public virtual List<Feedback> Feedbacks
{
get
{
return new List<Feedback>
{
PowerIsOnFeedback,
IsCoolingDownFeedback,
IsWarmingUpFeedback
};
}
}
public abstract void ExecuteSwitch(object selector);
}
/// <summary>
///
/// </summary>
public abstract class TwoWayDisplayBase : DisplayBase
{
public static MockDisplay DefaultDisplay {
get
{
if (_DefaultDisplay == null)
_DefaultDisplay = new MockDisplay("default", "Default Display");
return _DefaultDisplay;
}
}
static MockDisplay _DefaultDisplay;
public TwoWayDisplayBase(string key, string name)
: base(key, name)
{
WarmupTime = 7000;
CooldownTime = 15000;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DM;
using Crestron.SimplSharpPro.DM.Endpoints;
using Crestron.SimplSharpPro.DM.Endpoints.Transmitters;
using PepperDash.Core;
namespace PepperDash.Essentials.Core
{
/// <summary>
///
/// </summary>
public abstract class DisplayBase : Device, IHasFeedback, IRoutingSinkWithSwitching, IPower, IWarmingCooling
{
public BoolFeedback PowerIsOnFeedback { get; protected set; }
public BoolFeedback IsCoolingDownFeedback { get; protected set; }
public BoolFeedback IsWarmingUpFeedback { get; private set; }
public uint WarmupTime { get; set; }
public uint CooldownTime { get; set; }
/// <summary>
/// Bool Func that will provide a value for the PowerIsOn Output. Must be implemented
/// by concrete sub-classes
/// </summary>
abstract protected Func<bool> PowerIsOnFeedbackFunc { get; }
abstract protected Func<bool> IsCoolingDownFeedbackFunc { get; }
abstract protected Func<bool> IsWarmingUpFeedbackFunc { get; }
protected CTimer WarmupTimer;
protected CTimer CooldownTimer;
#region IRoutingInputs Members
public RoutingPortCollection<RoutingInputPort> InputPorts { get; private set; }
#endregion
public DisplayBase(string key, string name)
: base(key, name)
{
PowerIsOnFeedback = new BoolFeedback(CommonBoolCue.PowerOnFeedback, PowerIsOnFeedbackFunc);
IsCoolingDownFeedback = new BoolFeedback(CommonBoolCue.IsCoolingDown, IsCoolingDownFeedbackFunc);
IsWarmingUpFeedback = new BoolFeedback(CommonBoolCue.IsWarmingUp, IsWarmingUpFeedbackFunc);
InputPorts = new RoutingPortCollection<RoutingInputPort>();
}
public abstract void PowerOn();
public abstract void PowerOff();
public abstract void PowerToggle();
public virtual List<Feedback> Feedbacks
{
get
{
return new List<Feedback>
{
PowerIsOnFeedback,
IsCoolingDownFeedback,
IsWarmingUpFeedback
};
}
}
public abstract void ExecuteSwitch(object selector);
}
/// <summary>
///
/// </summary>
public abstract class TwoWayDisplayBase : DisplayBase
{
public StringFeedback CurrentInputFeedback { get; private set; }
abstract protected Func<string> CurrentInputFeedbackFunc { get; }
public static MockDisplay DefaultDisplay
{
get
{
if (_DefaultDisplay == null)
_DefaultDisplay = new MockDisplay("default", "Default Display");
return _DefaultDisplay;
}
}
static MockDisplay _DefaultDisplay;
public TwoWayDisplayBase(string key, string name)
: base(key, name)
{
CurrentInputFeedback = new StringFeedback(CurrentInputFeedbackFunc);
WarmupTime = 7000;
CooldownTime = 15000;
Feedbacks.Add(CurrentInputFeedback);
}
}
}

View File

@@ -33,6 +33,7 @@ namespace PepperDash.Essentials.Core
protected override Func<bool> PowerIsOnFeedbackFunc { get { return () => _PowerIsOn; } }
protected override Func<bool> IsCoolingDownFeedbackFunc { get { return () => _IsCoolingDown; } }
protected override Func<bool> IsWarmingUpFeedbackFunc { get { return () => _IsWarmingUp; } }
protected override Func<string> CurrentInputFeedbackFunc { get { return () => "Not Implemented"; } }
int VolumeHeldRepeatInterval = 200;
ushort VolumeInterval = 655;

View File

@@ -1,200 +1,201 @@
using System;
using System.Collections.Generic;
using PepperDash.Core;
namespace PepperDash.Essentials.Core
{
/// <summary>
/// Base class for RoutingInput and Output ports
/// </summary>
public abstract class RoutingPort : IKeyed
{
public string Key { get; private set; }
public eRoutingSignalType Type { get; private set; }
public eRoutingPortConnectionType ConnectionType { get; private set; }
public readonly object Selector;
public bool IsInternal { get; private set; }
public RoutingPort(string key, eRoutingSignalType type, eRoutingPortConnectionType connType, object selector, bool isInternal)
{
Key = key;
Type = type;
ConnectionType = connType;
Selector = selector;
IsInternal = IsInternal;
}
}
public enum eRoutingSignalType
{
Audio,
Video,
AudioVideo
}
public enum eRoutingPortConnectionType
{
None, BackplaneOnly, DisplayPort, Dvi, Hdmi, Rgb, Vga, LineAudio, DigitalAudio, Sdi,
Composite, Component, DmCat, DmMmFiber, DmSmFiber, Speaker
}
/// <summary>
/// Basic RoutingInput with no statuses.
/// </summary>
public class RoutingInputPort : RoutingPort
{
/// <summary>
/// The IRoutingInputs object this lives on
/// </summary>
public IRoutingInputs ParentDevice { get; private set; }
/// <summary>
/// Constructor for a basic RoutingInputPort
/// </summary>
/// <param name="selector">An object used to refer to this port in the IRouting device's ExecuteSwitch method.
/// May be string, number, whatever</param>
/// <param name="parent">The IRoutingInputs object this lives on</param>
public RoutingInputPort(string key, eRoutingSignalType type, eRoutingPortConnectionType connType,
object selector, IRoutingInputs parent)
: this (key, type, connType, selector, parent, false)
{
}
/// <summary>
/// Constructor for a virtual routing input port that lives inside a device. For example
/// the ports that link a DM card to a DM matrix bus
/// </summary>
/// <param name="isInternal">true for internal ports</param>
public RoutingInputPort(string key, eRoutingSignalType type, eRoutingPortConnectionType connType,
object selector, IRoutingInputs parent, bool isInternal)
: base(key, type, connType, selector, isInternal)
{
if (parent == null)
throw new ArgumentNullException("parent");
ParentDevice = parent;
}
///// <summary>
///// Static method to get a named port from a named device
///// </summary>
///// <returns>Returns null if device or port doesn't exist</returns>
//public static RoutingInputPort GetDevicePort(string deviceKey, string portKey)
//{
// var sourceDev = DeviceManager.GetDeviceForKey(deviceKey) as IRoutingInputs;
// if (sourceDev == null)
// return null;
// return sourceDev.InputPorts[portKey];
//}
///// <summary>
///// Static method to get a named port from a card in a named ICardPortsDevice device
///// Uses ICardPortsDevice.GetChildInputPort
///// </summary>
///// <param name="cardKey">'input-N'</param>
///// <returns>null if device, card or port doesn't exist</returns>
//public static RoutingInputPort GetDeviceCardPort(string deviceKey, string cardKey, string portKey)
//{
// var sourceDev = DeviceManager.GetDeviceForKey(deviceKey) as ICardPortsDevice;
// if (sourceDev == null)
// return null;
// return sourceDev.GetChildInputPort(cardKey, portKey);
//}
}
/// <summary>
/// A RoutingInputPort for devices like DM-TX and DM input cards.
/// Will provide video statistics on connected signals
/// </summary>
public class RoutingInputPortWithVideoStatuses : RoutingInputPort
{
/// <summary>
/// Video statuses attached to this port
/// </summary>
public VideoStatusOutputs VideoStatus { get; private set; }
/// <summary>
/// Constructor
/// </summary>
/// <param name="selector">An object used to refer to this port in the IRouting device's ExecuteSwitch method.
/// May be string, number, whatever</param>
/// <param name="parent">The IRoutingInputs object this lives on</param>
/// <param name="funcs">A VideoStatusFuncsWrapper used to assign the callback funcs that will get
/// the values for the various stats</param>
public RoutingInputPortWithVideoStatuses(string key,
eRoutingSignalType type, eRoutingPortConnectionType connType, object selector,
IRoutingInputs parent, VideoStatusFuncsWrapper funcs) :
base(key, type, connType, selector, parent)
{
VideoStatus = new VideoStatusOutputs(funcs);
}
}
public class RoutingOutputPort : RoutingPort
{
/// <summary>
/// The IRoutingOutputs object this port lives on
/// </summary>
public IRoutingOutputs ParentDevice { get; private set; }
public InUseTracking InUseTracker { get; private set; }
/// <summary>
/// </summary>
/// <param name="selector">An object used to refer to this port in the IRouting device's ExecuteSwitch method.
/// May be string, number, whatever</param>
/// <param name="parent">The IRoutingOutputs object this port lives on</param>
public RoutingOutputPort(string key, eRoutingSignalType type, eRoutingPortConnectionType connType,
object selector, IRoutingOutputs parent)
: this(key, type, connType, selector, parent, false)
{
}
public RoutingOutputPort(string key, eRoutingSignalType type, eRoutingPortConnectionType connType,
object selector, IRoutingOutputs parent, bool isInternal)
: base(key, type, connType, selector, isInternal)
{
if (parent == null)
throw new ArgumentNullException("parent");
ParentDevice = parent;
InUseTracker = new InUseTracking();
}
public override string ToString()
{
return ParentDevice.Key + ":" + Key;
}
///// <summary>
///// Static method to get a named port from a named device
///// </summary>
///// <returns>Returns null if device or port doesn't exist</returns>
//public static RoutingOutputPort GetDevicePort(string deviceKey, string portKey)
//{
// var sourceDev = DeviceManager.GetDeviceForKey(deviceKey) as IRoutingOutputs;
// if (sourceDev == null)
// return null;
// var port = sourceDev.OutputPorts[portKey];
// if (port == null)
// Debug.Console(0, "WARNING: Device '{0}' does does not contain output port '{1}'", deviceKey, portKey);
// return port;
//}
///// <summary>
///// Static method to get a named port from a card in a named ICardPortsDevice device
///// Uses ICardPortsDevice.GetChildOutputPort on that device
///// </summary>
///// <param name="cardKey">'input-N' or 'output-N'</param>
///// <returns>null if device, card or port doesn't exist</returns>
//public static RoutingOutputPort GetDeviceCardPort(string deviceKey, string cardKey, string portKey)
//{
// var sourceDev = DeviceManager.GetDeviceForKey(deviceKey) as ICardPortsDevice;
// if (sourceDev == null)
// return null;
// var port = sourceDev.GetChildOutputPort(cardKey, portKey);
//}
}
using System;
using System.Collections.Generic;
using PepperDash.Core;
namespace PepperDash.Essentials.Core
{
/// <summary>
/// Base class for RoutingInput and Output ports
/// </summary>
public abstract class RoutingPort : IKeyed
{
public string Key { get; private set; }
public eRoutingSignalType Type { get; private set; }
public eRoutingPortConnectionType ConnectionType { get; private set; }
public readonly object Selector;
public bool IsInternal { get; private set; }
public object FeedbackMatchObject { get; set; }
public RoutingPort(string key, eRoutingSignalType type, eRoutingPortConnectionType connType, object selector, bool isInternal)
{
Key = key;
Type = type;
ConnectionType = connType;
Selector = selector;
IsInternal = IsInternal;
}
}
public enum eRoutingSignalType
{
Audio,
Video,
AudioVideo
}
public enum eRoutingPortConnectionType
{
None, BackplaneOnly, DisplayPort, Dvi, Hdmi, Rgb, Vga, LineAudio, DigitalAudio, Sdi,
Composite, Component, DmCat, DmMmFiber, DmSmFiber, Speaker
}
/// <summary>
/// Basic RoutingInput with no statuses.
/// </summary>
public class RoutingInputPort : RoutingPort
{
/// <summary>
/// The IRoutingInputs object this lives on
/// </summary>
public IRoutingInputs ParentDevice { get; private set; }
/// <summary>
/// Constructor for a basic RoutingInputPort
/// </summary>
/// <param name="selector">An object used to refer to this port in the IRouting device's ExecuteSwitch method.
/// May be string, number, whatever</param>
/// <param name="parent">The IRoutingInputs object this lives on</param>
public RoutingInputPort(string key, eRoutingSignalType type, eRoutingPortConnectionType connType,
object selector, IRoutingInputs parent)
: this (key, type, connType, selector, parent, false)
{
}
/// <summary>
/// Constructor for a virtual routing input port that lives inside a device. For example
/// the ports that link a DM card to a DM matrix bus
/// </summary>
/// <param name="isInternal">true for internal ports</param>
public RoutingInputPort(string key, eRoutingSignalType type, eRoutingPortConnectionType connType,
object selector, IRoutingInputs parent, bool isInternal)
: base(key, type, connType, selector, isInternal)
{
if (parent == null)
throw new ArgumentNullException("parent");
ParentDevice = parent;
}
///// <summary>
///// Static method to get a named port from a named device
///// </summary>
///// <returns>Returns null if device or port doesn't exist</returns>
//public static RoutingInputPort GetDevicePort(string deviceKey, string portKey)
//{
// var sourceDev = DeviceManager.GetDeviceForKey(deviceKey) as IRoutingInputs;
// if (sourceDev == null)
// return null;
// return sourceDev.InputPorts[portKey];
//}
///// <summary>
///// Static method to get a named port from a card in a named ICardPortsDevice device
///// Uses ICardPortsDevice.GetChildInputPort
///// </summary>
///// <param name="cardKey">'input-N'</param>
///// <returns>null if device, card or port doesn't exist</returns>
//public static RoutingInputPort GetDeviceCardPort(string deviceKey, string cardKey, string portKey)
//{
// var sourceDev = DeviceManager.GetDeviceForKey(deviceKey) as ICardPortsDevice;
// if (sourceDev == null)
// return null;
// return sourceDev.GetChildInputPort(cardKey, portKey);
//}
}
/// <summary>
/// A RoutingInputPort for devices like DM-TX and DM input cards.
/// Will provide video statistics on connected signals
/// </summary>
public class RoutingInputPortWithVideoStatuses : RoutingInputPort
{
/// <summary>
/// Video statuses attached to this port
/// </summary>
public VideoStatusOutputs VideoStatus { get; private set; }
/// <summary>
/// Constructor
/// </summary>
/// <param name="selector">An object used to refer to this port in the IRouting device's ExecuteSwitch method.
/// May be string, number, whatever</param>
/// <param name="parent">The IRoutingInputs object this lives on</param>
/// <param name="funcs">A VideoStatusFuncsWrapper used to assign the callback funcs that will get
/// the values for the various stats</param>
public RoutingInputPortWithVideoStatuses(string key,
eRoutingSignalType type, eRoutingPortConnectionType connType, object selector,
IRoutingInputs parent, VideoStatusFuncsWrapper funcs) :
base(key, type, connType, selector, parent)
{
VideoStatus = new VideoStatusOutputs(funcs);
}
}
public class RoutingOutputPort : RoutingPort
{
/// <summary>
/// The IRoutingOutputs object this port lives on
/// </summary>
public IRoutingOutputs ParentDevice { get; private set; }
public InUseTracking InUseTracker { get; private set; }
/// <summary>
/// </summary>
/// <param name="selector">An object used to refer to this port in the IRouting device's ExecuteSwitch method.
/// May be string, number, whatever</param>
/// <param name="parent">The IRoutingOutputs object this port lives on</param>
public RoutingOutputPort(string key, eRoutingSignalType type, eRoutingPortConnectionType connType,
object selector, IRoutingOutputs parent)
: this(key, type, connType, selector, parent, false)
{
}
public RoutingOutputPort(string key, eRoutingSignalType type, eRoutingPortConnectionType connType,
object selector, IRoutingOutputs parent, bool isInternal)
: base(key, type, connType, selector, isInternal)
{
if (parent == null)
throw new ArgumentNullException("parent");
ParentDevice = parent;
InUseTracker = new InUseTracking();
}
public override string ToString()
{
return ParentDevice.Key + ":" + Key;
}
///// <summary>
///// Static method to get a named port from a named device
///// </summary>
///// <returns>Returns null if device or port doesn't exist</returns>
//public static RoutingOutputPort GetDevicePort(string deviceKey, string portKey)
//{
// var sourceDev = DeviceManager.GetDeviceForKey(deviceKey) as IRoutingOutputs;
// if (sourceDev == null)
// return null;
// var port = sourceDev.OutputPorts[portKey];
// if (port == null)
// Debug.Console(0, "WARNING: Device '{0}' does does not contain output port '{1}'", deviceKey, portKey);
// return port;
//}
///// <summary>
///// Static method to get a named port from a card in a named ICardPortsDevice device
///// Uses ICardPortsDevice.GetChildOutputPort on that device
///// </summary>
///// <param name="cardKey">'input-N' or 'output-N'</param>
///// <returns>null if device, card or port doesn't exist</returns>
//public static RoutingOutputPort GetDeviceCardPort(string deviceKey, string cardKey, string portKey)
//{
// var sourceDev = DeviceManager.GetDeviceForKey(deviceKey) as ICardPortsDevice;
// if (sourceDev == null)
// return null;
// var port = sourceDev.GetChildOutputPort(cardKey, portKey);
//}
}
}

View File

@@ -29,8 +29,9 @@ namespace PepperDash.Essentials.Core.Routing
public const string DisplayPortOut = "displayPortOut";
public const string DmIn = "dmIn";
public const string DmOut = "dmOut";
public const string DviIn = "dviIn";
public const string DviOut = "dviOut";
public const string DviIn = "dviIn";
public const string DviIn1 = "dviIn1";
public const string DviOut = "dviOut";
public const string HdmiIn = "hdmiIn";
public const string HdmiIn1 = "hdmiIn1";
public const string HdmiIn2 = "hdmiIn2";
@@ -39,7 +40,9 @@ namespace PepperDash.Essentials.Core.Routing
public const string HdmiIn5 = "hdmiIn5";
public const string HdmiIn6 = "hdmiIn6";
public const string HdmiOut = "hdmiOut";
public const string RgbIn = "rgbIn";
public const string RgbIn = "rgbIn";
public const string RgbIn1 = "rgbIn1";
public const string RgbIn2 = "rgbIn2";
public const string VgaIn = "vgaIn";
public const string VgaOut = "vgaOut";
}

View File

@@ -42,7 +42,7 @@ namespace PepperDash.Essentials.Devices.Displays
{
var comm = CommFactory.CreateCommForDevice(dc);
if (comm != null)
return new SamsungMDC(dc.Key, dc.Name, comm, Convert.ToByte(dc.Properties["byte"]));
return new SamsungMDC(dc.Key, dc.Name, comm, dc.Properties["id"].Value<string>());
}
}

View File

@@ -64,6 +64,8 @@ namespace PepperDash.Essentials.Devices.Displays
protected override Func<bool> PowerIsOnFeedbackFunc { get { return () => _PowerIsOn; } }
protected override Func<bool> IsCoolingDownFeedbackFunc { get { return () => _IsCoolingDown; } }
protected override Func<bool> IsWarmingUpFeedbackFunc { get { return () => _IsWarmingUp; } }
protected override Func<string> CurrentInputFeedbackFunc { get { return () => "Not Implemented"; } }
/// <summary>
/// Constructor for IBasicCommunication

View File

@@ -19,144 +19,50 @@ namespace PepperDash.Essentials.Devices.Displays
public CommunicationGather PortGather { get; private set; }
public StatusMonitorBase CommunicationMonitor { get; private set; }
private StringBuilder Buffer = new StringBuilder();
#region Command constants
public string Ack
{
get { return AssembleCommand(string.Format("\xAA\xFF{0}\x03A", ID)); }
}
public string Nak
{
get { return AssembleCommand(string.Format("\xAA\xFF{0}\x03N", ID)); }
}
public string Ack { get; private set; }
public string Nak { get; private set; }
// Power Commands
public string PowerGetCmd
{
get { return AssembleCommand(string.Format("\x11{0}\x00", ID)); }
}
public string PowerGetCmd { get; private set; }
public string PowerOnCmd
{
get { return AssembleCommand(string.Format("\x11{0}\x01\x01", ID)); }
}
public string PowerOnCmd { get; private set; }
public string PowerOffCmd
{
get { return AssembleCommand(string.Format("\x11{0}\x01\x00", ID)); }
}
public string PowerOffCmd { get; private set; }
// Input Commands
public string InputGetCmd
{
get { return AssembleCommand(string.Format("\x14{0}\x00", ID)); }
}
public string InputGetCmd { get; private set; }
public string Dp1Cmd
{
get { return AssembleCommand(string.Format("\x14{0}\x01\x25", ID)); }
}
public string Hdmi1Cmd
{
get { return AssembleCommand(string.Format("\x14{0}\x01\x21", ID)); }
}
public string Hdmi2Cmd
{
get { return AssembleCommand(string.Format("\x14{0}\x01\x23", ID)); }
}
public string Hdmi3Cmd
{
get { return AssembleCommand(string.Format("\x14{0}\x01\x32", ID)); }
}
public string Dvi1Cmd
{
get { return AssembleCommand(string.Format("\x14{0}\x01\x18", ID)); }
}
public string Rgb1Cmd
{
get { return AssembleCommand(string.Format("\x14{0}\x01\x14", ID)); }
}
public string Rgb2Cmd
{
get { return AssembleCommand(string.Format("\x14{0}\x01\x1E", ID)); }
}
public string Video1Cmd
{
get { return AssembleCommand(string.Format("\x14{0}\x01\x08", ID)); }
}
public string Dp1Cmd { get; private set; }
public string Hdmi1Cmd { get; private set; }
public string Hdmi2Cmd { get; private set; }
public string Hdmi3Cmd { get; private set; }
public string Dvi1Cmd { get; private set; }
public string Video1Cmd { get; private set; }
public string Rgb1Cmd { get; private set; }
public string Rgb2Cmd { get; private set; }
// Volume Commands
public string MuteGetCmd
{
get { return AssembleCommand(string.Format("\x13{0}\x00", ID)); }
}
public string MuteGetCmd { get; private set; }
public string MuteOnCmd
{
get { return AssembleCommand(string.Format("\x13{0}\x01\x01", ID)); }
}
public string MuteOnCmd { get; private set; }
public string MuteOffCmd
{
get { return AssembleCommand(string.Format("\x13{0}\x01\x00", ID)); }
}
public string MuteOffCmd { get; private set; }
public string VolumeGetCmd
{
get { return AssembleCommand(string.Format("\x12{0}\x00", ID)); }
}
public string VolumeGetCmd { get; private set; }
/// <summary>
/// To be appended with the requested volume level. Does not include checksum calculation
/// </summary>
public string VolumeLevelPartialCmd
{
get { return string.Format("\x12{0}\x01", ID); }
}
public string VolumeLevelPartialCmd { get; private set; }
//public string InputGetCmd = "";
//public const string Hdmi1Cmd = "";
//public const string Hdmi2Cmd = "";
//public const string Hdmi3Cmd = "";
//public const string Hdmi4Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x38\x33\x03\x79\x0D";
//public const string Dp1Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x30\x46\x03\x04\x0D";
//public const string Dp2Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x31\x30\x03\x73\x0D";
//public const string Dvi1Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x30\x33\x03\x71\x0d";
//public const string Video1Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x30\x35\x03\x77\x0D";
//public const string VgaCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x30\x31\x03\x73\x0D";
//public const string RgbCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x30\x32\x03\x70\x0D";
//public const string PowerOnCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x30\x33\x44\x36\x30\x30\x30\x31\x03\x73\x0D";
//public const string PowerOffCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x30\x33\x44\x36\x30\x30\x30\x34\x03\x76\x0D";
//public const string PowerToggleIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x30\x33\x30\x33\x03\x02\x0D";
//public const string MuteOffCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x38\x44\x30\x30\x30\x30\x03\x08\x0D";
//public const string MuteOnCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x38\x44\x30\x30\x30\x31\x03\x09\x0D";
//public const string MuteToggleIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x31\x42\x30\x33\x03\x72\x0D";
//public const string MuteGetCmd = "\x01\x30\x41\x30\x43\x30\x36\x02\x30\x30\x38\x44\x03\x79\x0D";
//public const string VolumeGetCmd = "\x01\x30\x41\x30\x43\x30\x36\x02\x30\x30\x36\x32\x03\x01\x0D";
//public const string VolumeLevelPartialCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x32"; //\x46\x46\x46\x46\x03\xNN\x0D
//public const string VolumeUpCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x31\x30\x41\x44\x30\x30\x30\x31\x03\x71\x0D";
//public const string VolumeDownCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x31\x30\x41\x44\x30\x30\x30\x32\x03\x72\x0D";
//public const string MenuIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x32\x30\x30\x33\x03\x03\x0D";
//public const string UpIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x31\x35\x30\x33\x03\x05\x0D";
//public const string DownIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x31\x34\x30\x33\x03\x04\x0D";
//public const string LeftIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x32\x31\x30\x33\x03\x02\x0D";
//public const string RightIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x32\x32\x30\x33\x03\x01\x0D";
//public const string SelectIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x32\x33\x30\x33\x03\x00\x0D";
//public const string ExitIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x31\x46\x30\x33\x03\x76\x0D";
#endregion
@@ -167,17 +73,22 @@ namespace PepperDash.Essentials.Devices.Displays
/// </summary>
/// <param name="command"></param>
/// <returns></returns>
private string AssembleCommand(string command)
private string AppendChecksum(string command)
{
int checksum = 0;
var bytes = command.ToCharArray();
//var bytes = command.ToCharArray();
for (int i = 1; i < bytes.Length; i++)
byte[] bytes = Encoding.ASCII.GetBytes(command);
for (int i = 1; i < bytes.Length; i++) /*Convert.ToByte(bytes[i]*/
{
checksum = checksum + Convert.ToByte(bytes[i]);
checksum = checksum + bytes[i];
}
if (checksum >= 0x100) // Check if value is greater than 0x100 and if so, remove the first digit by subtracting 0x100
checksum = checksum - 0x100;
var checksumByte = Convert.ToByte(checksum);
string result = string.Format("{0}{1}", command, (char)checksumByte);
@@ -191,82 +102,144 @@ namespace PepperDash.Essentials.Devices.Displays
bool _IsCoolingDown;
ushort _VolumeLevel;
bool _IsMuted;
object _CurrentInputPort;
#warning Add Input FeedbackFunc object
RoutingInputPort _CurrentInputPort;
protected override Func<bool> PowerIsOnFeedbackFunc { get { return () => _PowerIsOn; } }
protected override Func<bool> IsCoolingDownFeedbackFunc { get { return () => _IsCoolingDown; } }
protected override Func<bool> IsWarmingUpFeedbackFunc { get { return () => _IsWarmingUp; } }
protected override Func<string> CurrentInputFeedbackFunc { get { return () => _CurrentInputPort.Key; } }
/// <summary>
/// Constructor for IBasicCommunication
/// </summary>
public SamsungMDC(string key, string name, IBasicCommunication comm, byte id)
public SamsungMDC(string key, string name, IBasicCommunication comm, string id)
: base(key, name)
{
Communication = comm;
ID = id;
Init();
Communication.TextReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(Communication_TextReceived);
ID = id == null ? (byte)0x01 : Convert.ToByte(id); // If id is null, set default value of 0x01, otherwise assign value passed in constructor
Init();
}
/// <summary>
/// Constructor for TCP
/// </summary>
public SamsungMDC(string key, string name, string hostname, int port, byte id)
public SamsungMDC(string key, string name, string hostname, int port, string id)
: base(key, name)
{
Communication = new GenericTcpIpClient(key + "-tcp", hostname, port, 5000);
ID = id;
Init();
Communication.TextReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(Communication_TextReceived);
ID = id == null ? (byte)0x01 : Convert.ToByte(id); // If id is null, set default value of 0x01, otherwise assign value passed in constructor
Init();
}
/// <summary>
/// Constructor for COM
/// </summary>
public SamsungMDC(string key, string name, ComPort port, ComPort.ComPortSpec spec, byte id)
public SamsungMDC(string key, string name, ComPort port, ComPort.ComPortSpec spec, string id)
: base(key, name)
{
Communication = new ComPortController(key + "-com", port, spec);
ID = id;
Init();
Communication.TextReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(Communication_TextReceived);
ID = id == null ? (byte)0x01 : Convert.ToByte(id); // If id is null, set default value of 0x01, otherwise assign value passed in constructor
Init();
}
void AddRoutingInputPort(RoutingInputPort port, string cmdPrefix, byte fbMatch)
{
port.FeedbackMatchObject = fbMatch;
InputPorts.Add(port);
}
void Init()
{
PortGather = new CommunicationGather(Communication, '\x0d');
PortGather.LineReceived += this.Port_LineReceived;
CommunicationMonitor = new GenericCommunicationMonitor(this, Communication, 30000, 120000, 300000, "xx\x0d");
InputPorts.Add(new RoutingInputPort(RoutingPortNames.HdmiIn1, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi1), this));
InputPorts.Add(new RoutingInputPort(RoutingPortNames.HdmiIn2, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi2), this));
InputPorts.Add(new RoutingInputPort(RoutingPortNames.HdmiIn3, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi3), this));
InputPorts.Add(new RoutingInputPort(RoutingPortNames.DisplayPortIn1, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.DisplayPort, new Action(InputDisplayPort1), this));
InputPorts.Add(new RoutingInputPort(RoutingPortNames.DviIn, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Dvi, new Action(InputDvi1), this));
InputPorts.Add(new RoutingInputPort(RoutingPortNames.CompositeIn, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Composite, new Action(InputVideo1), this));
InputPorts.Add(new RoutingInputPort(RoutingPortNames.VgaIn, eRoutingSignalType.Video,
eRoutingPortConnectionType.Vga, new Action(InputRgb1), this));
InputPorts.Add(new RoutingInputPort(RoutingPortNames.RgbIn, eRoutingSignalType.Video,
eRoutingPortConnectionType.Rgb, new Action(new Action(InputRgb2)), this));
CommunicationMonitor = new GenericCommunicationMonitor(this, Communication, 30000, 120000, 300000, AppendChecksum(string.Format("\x11{0}\x01\x01", ID)));
#warning Add missing input ports
// Build Command Strings
Ack = AppendChecksum(string.Format("\xAA\xFF{0}\x03A", ID));
Nak = AppendChecksum(string.Format("\xAA\xFF{0}\x03N", ID));
//Power Commands
PowerGetCmd = AppendChecksum(string.Format("\x11{0}\x00", ID));
PowerOnCmd = AppendChecksum(string.Format("\x11{0}\x01\x01", ID));
PowerOffCmd = AppendChecksum(string.Format("\x11{0}\x01\x00", ID));
//Input Commands
InputGetCmd = AppendChecksum(string.Format("\x14{0}\x00", ID));
string cmdPrefix = string.Format("\x14{0}\x01", ID);
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.HdmiIn1, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi1), this), cmdPrefix, 0x21);
Hdmi1Cmd = string.Format("{0}{1}", cmdPrefix, 0x21);
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.HdmiIn2, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi2), this), cmdPrefix, 0x23);
Hdmi2Cmd = string.Format("{0}{1}", cmdPrefix, 0x23);
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.HdmiIn3, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi3), this), cmdPrefix, 0x32);
Hdmi3Cmd = string.Format("{0}{1}", cmdPrefix, 0x32);
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.DisplayPortIn1, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.DisplayPort, new Action(InputDisplayPort1), this), cmdPrefix, 0x25);
Dp1Cmd = string.Format("{0}{1}", cmdPrefix, 0x25);
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.DviIn, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Dvi, new Action(InputDvi1), this), cmdPrefix, 0x18);
Dvi1Cmd = string.Format("{0}{1}", cmdPrefix, 0x18);
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.CompositeIn, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Composite, new Action(InputVideo1), this), cmdPrefix, 0x08);
Video1Cmd = string.Format("{0}{1}", cmdPrefix, 0x08);
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.RgbIn1, eRoutingSignalType.Video,
eRoutingPortConnectionType.Vga, new Action(InputRgb1), this), cmdPrefix, 0x14);
Rgb1Cmd = string.Format("{0}{1}", cmdPrefix, 0x14);
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.RgbIn2, eRoutingSignalType.Video,
eRoutingPortConnectionType.Rgb, new Action(new Action(InputRgb2)), this), cmdPrefix, 0x1E);
Rgb2Cmd = string.Format("{0}{1}", cmdPrefix, 0x1E);
// Mute Commands
MuteGetCmd = AppendChecksum(string.Format("\x13{0}\x00", ID));
MuteOnCmd = AppendChecksum(string.Format("\x13{0}\x01\x01", ID));
MuteOffCmd = AppendChecksum(string.Format("\x13{0}\x01\x00", ID));
// Volume Commands
VolumeGetCmd = AppendChecksum(string.Format("\x12{0}\x00", ID));
VolumeLevelPartialCmd = string.Format("\x12{0}\x01", ID);
VolumeLevelFeedback = new IntFeedback(() => { return _VolumeLevel; });
MuteFeedback = new BoolFeedback(() => _IsMuted);
// new BoolCueActionPair(CommonBoolCue.Menu, b => { if(b) Send(MenuIrCmd); }),
// new BoolCueActionPair(CommonBoolCue.Up, b => { if(b) Send(UpIrCmd); }),
// new BoolCueActionPair(CommonBoolCue.Down, b => { if(b) Send(DownIrCmd); }),
// new BoolCueActionPair(CommonBoolCue.Left, b => { if(b) Send(LeftIrCmd); }),
// new BoolCueActionPair(CommonBoolCue.Right, b => { if(b) Send(RightIrCmd); }),
// new BoolCueActionPair(CommonBoolCue.Select, b => { if(b) Send(SelectIrCmd); }),
// new BoolCueActionPair(CommonBoolCue.Exit, b => { if(b) Send(ExitIrCmd); }),
//};
// Query initial device status
Send(PowerGetCmd);
Send(InputGetCmd);
Send(VolumeGetCmd);
Send(MuteGetCmd);
}
~SamsungMDC()
@@ -295,109 +268,128 @@ namespace PepperDash.Essentials.Devices.Displays
}
}
void Port_LineReceived(object dev, GenericCommMethodReceiveTextArgs args)
{
if (Debug.Level == 2)
Debug.Console(2, this, "Received: '{0}'", ComTextHelper.GetEscapedText(args.Text));
void Communication_TextReceived(object sender, GenericCommMethodReceiveTextArgs e)
{
Buffer.Append(e.Text);
if (args.Text.IndexOf(Ack) > -1)
{
var bytes = args.Text.ToCharArray();
if (Debug.Level == 2)
Debug.Console(2, this, "Received: '{0}'", ComTextHelper.GetEscapedText(e.Text));
var commandByte = bytes[5];
ParseData();
}
var dataByte = bytes[6];
void ParseData()
{
if(Buffer.Length < 8) // Message length must be > 8 bytes
return;
switch (commandByte)
{
case '\x11': // Power State
{
if (dataByte == '\x00')
{
if (_PowerIsOn)
{
_IsWarmingUp = false;
_IsCoolingDown = true;
IsCoolingDownFeedback.FireUpdate();
IsWarmingUpFeedback.FireUpdate();
_PowerIsOn = false;
}
}
else if (dataByte == '\x01')
{
if (!_PowerIsOn)
{
_IsCoolingDown = false;
_IsWarmingUp = true;
IsCoolingDownFeedback.FireUpdate();
IsWarmingUpFeedback.FireUpdate();
_PowerIsOn = true;
}
}
var sample = Buffer.ToString();
PowerIsOnFeedback.FireUpdate();
break;
}
case '\x12': // Volume Level
{
_VolumeLevel = (ushort)Scale(dataByte, 0, 100, 0, 65535);
var messageStart = sample.IndexOf("\xAA\xFF");
VolumeLevelFeedback.FireUpdate();
break;
}
case '\x13': // Mute State
{
if (dataByte == '\x00')
{
_IsMuted = false;
}
else if (dataByte == '\x01')
{
_IsMuted = true;
}
MuteFeedback.FireUpdate();
break;
}
case '\x14': // Input State
{
switch (dataByte)
{
case '\x25': // DisplayPort
{
#warning Handle input port types
//_CurrentInputPort =
break;
}
}
break;
}
case '\x15': // Aspect Ratio
{
break;
}
default:
{
Debug.Console(2, this, "Unreckocnized Response Command Type: {0}", commandByte);
break;
}
}
}
else if (args.Text.IndexOf(Nak) > -1)
if (messageStart > -1)
{
Debug.Console(2, this, "Nak received");
}
}
StringBuilder garbage;
if(messageStart > 0) // Check for leftover bytes before first full message and remove
garbage = Buffer.Remove(0, messageStart - 1);
var chunk = Buffer.Remove(messageStart, 8); // Remove first message
var message = chunk.ToString();
if (message.IndexOf(Ack) > -1) // Check to see if Ack message
{
var bytes = message.ToCharArray();
var commandByte = bytes[5];
var dataByte = bytes[6];
switch (commandByte)
{
case '\x11': // Power State
{
var currentState = _PowerIsOn;
if (dataByte == '\x00')
_PowerIsOn = false;
else if (dataByte == '\x01')
_PowerIsOn = true;
if(currentState != _PowerIsOn)
PowerIsOnFeedback.FireUpdate();
break;
}
case '\x12': // Volume Level
{
_VolumeLevel = (ushort)Scale(dataByte, 0, 100, 0, 65535);
VolumeLevelFeedback.FireUpdate();
break;
}
case '\x13': // Mute State
{
if (dataByte == '\x00')
{
_IsMuted = false;
}
else if (dataByte == '\x01')
{
_IsMuted = true;
}
MuteFeedback.FireUpdate();
break;
}
case '\x14': // Input State
{
var currentInput = InputPorts.FirstOrDefault(i => i.FeedbackMatchObject.Equals(dataByte));
if (currentInput != null)
{
_CurrentInputPort = currentInput;
CurrentInputFeedback.FireUpdate();
}
break;
}
case '\x15': // Aspect Ratio
{
// Not implemented yet
break;
}
default:
{
Debug.Console(2, this, "Unreckocnized Response Command Type: {0}", commandByte);
break;
}
}
}
else if (message.IndexOf(Nak) > -1)
{
Debug.Console(2, this, "Nak received");
}
}
}
/// <summary>
/// Append checksup and send command to device
/// </summary>
/// <param name="s"></param>
void Send(string s)
{
var cmd = AppendChecksum(s);
if (Debug.Level == 2)
Debug.Console(2, this, "Send: '{0}'", ComTextHelper.GetEscapedText(s));
Communication.SendText(s);
Debug.Console(2, this, "Send: '{0}'", ComTextHelper.GetEscapedText(cmd));
Communication.SendText(cmd);
}
@@ -506,9 +498,8 @@ namespace PepperDash.Essentials.Devices.Displays
var scaledLevel = Scale(level, 0, 65535, 0, 100);
var levelString = string.Format("{0}{1}", VolumeLevelPartialCmd, Convert.ToByte(scaledLevel));
var command = AssembleCommand(levelString);
Debug.Console(2, this, "Volume:{0}", ComTextHelper.GetEscapedText(command));
Send(command);
Debug.Console(2, this, "Volume:{0}", ComTextHelper.GetEscapedText(levelString));
Send(levelString);
_VolumeLevel = level;
VolumeLevelFeedback.FireUpdate();
}

View File

@@ -29,8 +29,8 @@ namespace PepperDash.Essentials
/// </summary>
public override void InitializeSystem()
{
//CrestronConsole.AddNewConsoleCommand(s => GoWithLoad(), "go", "Reloads configuration file",
// ConsoleAccessLevelEnum.AccessOperator);
CrestronConsole.AddNewConsoleCommand(s => GoWithLoad(), "go", "Reloads configuration file",
ConsoleAccessLevelEnum.AccessOperator);
//CrestronConsole.AddNewConsoleCommand(s => TearDown(), "ungo", "Reloads configuration file",
// ConsoleAccessLevelEnum.AccessOperator);
CrestronConsole.AddNewConsoleCommand(s =>
@@ -40,7 +40,7 @@ namespace PepperDash.Essentials
},
"listtielines", "Prints out all tie lines", ConsoleAccessLevelEnum.AccessOperator);
GoWithLoad();
//GoWithLoad();
}
/// <summary>