Skip to content

Commit

Permalink
Merge pull request #186 from PepperDash/feature-2/camera-list-config
Browse files Browse the repository at this point in the history
Feature 2/camera list config
  • Loading branch information
andrew-welker authored Mar 5, 2025
2 parents 1a05cf1 + fb9fbe8 commit eb03e93
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 137 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,5 @@ FodyWeavers.xsd
# JetBrains Rider
*.sln.iml
*.projectinfo

output/
Binary file removed output/PepperDashCore.2.0.0-local.clz
Binary file not shown.
256 changes: 124 additions & 132 deletions src/Comm/GenericSshClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,138 +14,138 @@ namespace PepperDash.Core
///
/// </summary>
public class GenericSshClient : Device, ISocketStatusWithStreamDebugging, IAutoReconnect
{
private const string SPlusKey = "Uninitialized SshClient";
{
private const string SPlusKey = "Uninitialized SshClient";
/// <summary>
/// Object to enable stream debugging
/// </summary>
public CommunicationStreamDebugging StreamDebugging { get; private set; }

/// <summary>
/// Event that fires when data is received. Delivers args with byte array
/// </summary>
public event EventHandler<GenericCommMethodReceiveBytesArgs> BytesReceived;
/// <summary>
/// Event that fires when data is received. Delivers args with byte array
/// </summary>
public event EventHandler<GenericCommMethodReceiveBytesArgs> BytesReceived;

/// <summary>
/// Event that fires when data is received. Delivered as text.
/// </summary>
public event EventHandler<GenericCommMethodReceiveTextArgs> TextReceived;
/// <summary>
/// Event that fires when data is received. Delivered as text.
/// </summary>
public event EventHandler<GenericCommMethodReceiveTextArgs> TextReceived;

/// <summary>
/// Event when the connection status changes.
/// </summary>
public event EventHandler<GenericSocketStatusChageEventArgs> ConnectionChange;
/// <summary>
/// Event when the connection status changes.
/// </summary>
public event EventHandler<GenericSocketStatusChageEventArgs> ConnectionChange;

///// <summary>
/////
///// </summary>
//public event GenericSocketStatusChangeEventDelegate SocketStatusChange;

/// <summary>
/// Address of server
/// </summary>
public string Hostname { get; set; }
/// <summary>
/// Address of server
/// </summary>
public string Hostname { get; set; }

/// <summary>
/// Port on server
/// </summary>
public int Port { get; set; }
/// <summary>
/// Port on server
/// </summary>
public int Port { get; set; }

/// <summary>
/// Username for server
/// </summary>
public string Username { get; set; }
/// <summary>
/// Username for server
/// </summary>
public string Username { get; set; }

/// <summary>
/// And... Password for server. That was worth documenting!
/// </summary>
public string Password { get; set; }
/// <summary>
/// And... Password for server. That was worth documenting!
/// </summary>
public string Password { get; set; }

/// <summary>
/// True when the server is connected - when status == 2.
/// </summary>
public bool IsConnected
{
// returns false if no client or not connected
/// <summary>
/// True when the server is connected - when status == 2.
/// </summary>
public bool IsConnected
{
// returns false if no client or not connected
get { return Client != null && ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED; }
}
}

/// <summary>
/// S+ helper for IsConnected
/// </summary>
public ushort UIsConnected
{
get { return (ushort)(IsConnected ? 1 : 0); }
}
/// <summary>
/// S+ helper for IsConnected
/// </summary>
public ushort UIsConnected
{
get { return (ushort)(IsConnected ? 1 : 0); }
}

/// <summary>
///
/// </summary>
public SocketStatus ClientStatus
{
get { return _ClientStatus; }
private set
{
if (_ClientStatus == value)
return;
_ClientStatus = value;
OnConnectionChange();
}
}
SocketStatus _ClientStatus;
/// <summary>
///
/// </summary>
public SocketStatus ClientStatus
{
get { return _ClientStatus; }
private set
{
if (_ClientStatus == value)
return;
_ClientStatus = value;
OnConnectionChange();
}
}
SocketStatus _ClientStatus;

/// <summary>
/// Contains the familiar Simpl analog status values. This drives the ConnectionChange event
/// and IsConnected with be true when this == 2.
/// </summary>
public ushort UStatus
{
get { return (ushort)_ClientStatus; }
}
/// <summary>
/// Contains the familiar Simpl analog status values. This drives the ConnectionChange event
/// and IsConnected with be true when this == 2.
/// </summary>
public ushort UStatus
{
get { return (ushort)_ClientStatus; }
}

/// <summary>
/// Determines whether client will attempt reconnection on failure. Default is true
/// </summary>
public bool AutoReconnect { get; set; }
/// <summary>
/// Determines whether client will attempt reconnection on failure. Default is true
/// </summary>
public bool AutoReconnect { get; set; }

/// <summary>
/// Will be set and unset by connect and disconnect only
/// </summary>
public bool ConnectEnabled { get; private set; }
/// <summary>
/// Will be set and unset by connect and disconnect only
/// </summary>
public bool ConnectEnabled { get; private set; }

/// <summary>
/// S+ helper for AutoReconnect
/// </summary>
public ushort UAutoReconnect
{
get { return (ushort)(AutoReconnect ? 1 : 0); }
set { AutoReconnect = value == 1; }
}
/// <summary>
/// S+ helper for AutoReconnect
/// </summary>
public ushort UAutoReconnect
{
get { return (ushort)(AutoReconnect ? 1 : 0); }
set { AutoReconnect = value == 1; }
}

/// <summary>
/// Millisecond value, determines the timeout period in between reconnect attempts.
/// Set to 5000 by default
/// </summary>
public int AutoReconnectIntervalMs { get; set; }
/// <summary>
/// Millisecond value, determines the timeout period in between reconnect attempts.
/// Set to 5000 by default
/// </summary>
public int AutoReconnectIntervalMs { get; set; }

SshClient Client;
SshClient Client;

ShellStream TheStream;
ShellStream TheStream;

CTimer ReconnectTimer;
CTimer ReconnectTimer;

//Lock object to prevent simulatneous connect/disconnect operations
//private CCriticalSection connectLock = new CCriticalSection();
private SemaphoreSlim connectLock = new SemaphoreSlim(1);

private bool DisconnectLogged = false;

/// <summary>
/// Typical constructor.
/// </summary>
public GenericSshClient(string key, string hostname, int port, string username, string password) :
base(key)
{
/// <summary>
/// Typical constructor.
/// </summary>
public GenericSshClient(string key, string hostname, int port, string username, string password) :
base(key)
{
StreamDebugging = new CommunicationStreamDebugging(key);
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
Key = key;
Expand Down Expand Up @@ -182,14 +182,6 @@ public GenericSshClient()
}, System.Threading.Timeout.Infinite);
}

/// <summary>
/// Just to help S+ set the key
/// </summary>
public void Initialize(string key)
{
Key = key;
}

/// <summary>
/// Handles closing this up when the program shuts down
/// </summary>
Expand All @@ -201,14 +193,14 @@ void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventType progr
{
this.LogDebug("Program stopping. Closing connection");
Disconnect();
}
}
}
}
}
}

/// <summary>
/// Connect to the server, using the provided properties.
/// </summary>
public void Connect()
/// <summary>
/// Connect to the server, using the provided properties.
/// </summary>
public void Connect()
{
// Don't go unless everything is here
if (string.IsNullOrEmpty(Hostname) || Port < 1 || Port > 65535
Expand Down Expand Up @@ -347,7 +339,7 @@ public void Disconnect()
}

KillClient(SocketStatus.SOCKET_STATUS_BROKEN_LOCALLY);
}
}

/// <summary>
/// Kills the stream, cleans up the client and sets it to null
Expand Down Expand Up @@ -468,18 +460,18 @@ void Client_ErrorOccurred(object sender, ExceptionEventArgs e)
ReconnectTimer.Reset(AutoReconnectIntervalMs);
}
});
}
}

/// <summary>
/// Helper for ConnectionChange event
/// </summary>
void OnConnectionChange()
{
if (ConnectionChange != null)
ConnectionChange(this, new GenericSocketStatusChageEventArgs(this));
}
/// <summary>
/// Helper for ConnectionChange event
/// </summary>
void OnConnectionChange()
{
if (ConnectionChange != null)
ConnectionChange(this, new GenericSocketStatusChageEventArgs(this));
}

#region IBasicCommunication Members
#region IBasicCommunication Members

/// <summary>
/// Sends text to the server
Expand Down Expand Up @@ -582,20 +574,20 @@ public class SshConnectionChangeEventArgs : EventArgs
/// </summary>
public ushort Status { get { return Client.UStatus; } }

/// <summary>
/// <summary>
/// S+ Constructor
/// </summary>
public SshConnectionChangeEventArgs() { }
/// </summary>
public SshConnectionChangeEventArgs() { }

/// <summary>
/// EventArgs class
/// </summary>
/// <param name="isConnected">Connection State</param>
/// <param name="client">The Client</param>
public SshConnectionChangeEventArgs(bool isConnected, GenericSshClient client)
{
IsConnected = isConnected;
Client = client;
}
}
}
{
IsConnected = isConnected;
Client = client;
}
}
}
2 changes: 1 addition & 1 deletion src/CommunicationExtras.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public interface ISocketStatus : IBasicCommunication
/// <summary>
/// The current socket status of the client
/// </summary>
[JsonProperty("clinetStatus")]
[JsonProperty("clientStatus")]
[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
SocketStatus ClientStatus { get; }
}
Expand Down
19 changes: 16 additions & 3 deletions src/Config/PortalConfigReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,22 @@ public static JObject MergeConfigs(JObject doubleConfig)
merged.Add("destinationLists",
Merge(template["destinationLists"], system["destinationLists"], "destinationLists"));

// Template tie lines take precedence. Config tool doesn't do them at system
// level anyway...
if (template["tieLines"] != null)

if (system["cameraLists"] == null)
merged.Add("cameraLists", template["cameraLists"]);
else
merged.Add("cameraLists", Merge(template["cameraLists"], system["cameraLists"], "cameraLists"));

if (system["audioControlPointLists"] == null)
merged.Add("audioControlPointLists", template["audioControlPointLists"]);
else
merged.Add("audioControlPointLists",
Merge(template["audioControlPointLists"], system["audioControlPointLists"], "audioControlPointLists"));


// Template tie lines take precedence. Config tool doesn't do them at system
// level anyway...
if (template["tieLines"] != null)
merged.Add("tieLines", template["tieLines"]);
else if (system["tieLines"] != null)
merged.Add("tieLines", system["tieLines"]);
Expand Down
3 changes: 2 additions & 1 deletion src/PepperDash.Core.4Series.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
<Company>PepperDash Technologies</Company>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/PepperDash/PepperDashCore</RepositoryUrl>
<PackageTags>crestron;4series;</PackageTags>
<PackageTags>crestron;4series;</PackageTags>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<InformationalVersion>$(Version)</InformationalVersion>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
</PropertyGroup>
Expand Down

0 comments on commit eb03e93

Please sign in to comment.