Compare commits

...

5 Commits

4 changed files with 68 additions and 24 deletions

View File

@@ -101,6 +101,8 @@ namespace PepperDash.Essentials.Bridges
public EiscApi(DeviceConfig dc) :
base(dc.Key)
{
JoinMaps = new Dictionary<string, JoinMapBaseAdvanced>();
PropertiesConfig = JsonConvert.DeserializeObject<EiscApiPropertiesConfig>(dc.Properties.ToString());
Eisc = new ThreeSeriesTcpIpEthernetIntersystemCommunications(PropertiesConfig.Control.IpIdInt, PropertiesConfig.Control.TcpSshProperties.Address, Global.ControlSystem);
@@ -119,6 +121,9 @@ namespace PepperDash.Essentials.Bridges
if (device != null)
{
Debug.Console(1, this, "Linking Device: '{0}'", device.Key);
if (device is IBridge) // Check for this first to allow bridges in plugins to override existing bridges that apply to the same type.
{
(device as IBridge).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey);
@@ -126,6 +131,7 @@ namespace PepperDash.Essentials.Bridges
}
else if (device is IBridgeAdvanced)
{
Debug.Console(2, this, "'{0}' is IBridgeAdvanced", device.Key);
(device as IBridgeAdvanced).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey, this);
}
else if (device is PepperDash.Essentials.Core.Monitoring.SystemMonitorController)
@@ -261,6 +267,7 @@ namespace PepperDash.Essentials.Bridges
foreach (var joinMap in JoinMaps)
{
Debug.Console(0, "Join map for device '{0}':", joinMap.Key);
joinMap.Value.PrintJoinMapInfo();
}
}
@@ -279,6 +286,7 @@ namespace PepperDash.Essentials.Bridges
return;
}
Debug.Console(0, "Join map for device '{0}' on EISC '{1}':", deviceKey, this.Key);
joinMap.PrintJoinMapInfo();
}

View File

@@ -290,12 +290,13 @@ namespace PepperDash.Essentials
/// </summary>
public void LoadDevices()
{
// Instantiate the Device Factories
new CoreDeviceFactory();
// Build the processor wrapper class
DeviceManager.AddDevice(new PepperDash.Essentials.Core.Devices.CrestronProcessor("processor"));
// Add global System Monitor device
DeviceManager.AddDevice(new PepperDash.Essentials.Core.Monitoring.SystemMonitorController("systemMonitor"));

View File

@@ -48,7 +48,6 @@ namespace PepperDash.Essentials.Core
var typeName = dc.Type.ToLower();
// Check for types that have been added by plugin dlls.
if (FactoryMethods.ContainsKey(typeName))
{
@@ -57,11 +56,11 @@ namespace PepperDash.Essentials.Core
}
// Check "core" types
if (typeName == "genericcomm")
{
Debug.Console(1, "Factory Attempting to create new Generic Comm Device");
return new GenericComm(dc);
}
//if (typeName == "genericcomm")
//{
// Debug.Console(1, "Factory Attempting to create new Generic Comm Device");
// return new GenericComm(dc);
//}
if (typeName == "ceniodigin104")
{
var control = CommFactory.GetControlPropertiesConfig(dc);

View File

@@ -88,14 +88,17 @@ namespace PepperDash.Essentials.Core
// Get the joins of each type and print them
Debug.Console(0, "Digitals:");
var digitals = Joins.Where(j => (j.Value.JoinType & eJoinType.Digital) == eJoinType.Digital).ToDictionary(j => j.Key, j => j.Value);
Debug.Console(2, "Found {0} Digital Joins", digitals.Count);
PrintJoinList(GetSortedJoins(digitals));
Debug.Console(0, "Analogs:");
var analogs = Joins.Where(j => (j.Value.JoinType & eJoinType.Analog) == eJoinType.Analog).ToDictionary(j => j.Key, j => j.Value);
Debug.Console(2, "Found {0} Analog Joins", analogs.Count);
PrintJoinList(GetSortedJoins(analogs));
Debug.Console(0, "Serials:");
var serials = Joins.Where(j => (j.Value.JoinType & eJoinType.Serial) == eJoinType.Serial).ToDictionary(j => j.Key, j => j.Value);
Debug.Console(2, "Found {0} Serial Joins", serials.Count);
PrintJoinList(GetSortedJoins(serials));
}
@@ -166,23 +169,47 @@ namespace PepperDash.Essentials.Core
/// <summary>
/// The collection of joins and associated metadata
/// </summary>
public Dictionary<string, JoinDataComplete> Joins = new Dictionary<string, JoinDataComplete>();
public Dictionary<string, JoinDataComplete> Joins { get; private set; }
protected JoinMapBaseAdvanced(uint joinStart)
{
Joins = new Dictionary<string, JoinDataComplete>();
_joinOffset = joinStart - 1;
}
protected void AddJoins()
{
// Add all the JoinDataComplete properties to the Joins Dictionary and pass in the offset
Joins = GetType()
.GetCType()
.GetProperties()
.Where(prop => prop.IsDefined(typeof(JoinNameAttribute), false))
.Select(prop => (JoinDataComplete)prop.GetValue(this, null))
.ToDictionary(join => join.GetNameAttribute(), join =>
//Joins = this.GetType()
// .GetCType()
// .GetFields(BindingFlags.Public | BindingFlags.Instance)
// .Where(field => field.IsDefined(typeof(JoinNameAttribute), true))
// .Select(field => (JoinDataComplete)field.GetValue(this))
// .ToDictionary(join => join.GetNameAttribute(), join =>
// {
// join.SetJoinOffset(_joinOffset);
// return join;
// });
var type = this.GetType();
var cType = type.GetCType();
var fields = cType.GetFields(BindingFlags.Public | BindingFlags.Instance);
foreach (var field in fields)
{
if (field.IsDefined(typeof(JoinNameAttribute), true))
{
JoinDataComplete value = field.GetValue(this) as JoinDataComplete;
if (value != null)
{
join.SetJoinOffset(_joinOffset);
return join;
});
value.SetJoinOffset(_joinOffset);
Joins.Add(value.GetNameAttribute(typeof(JoinDataComplete)), value);
}
}
}
PrintJoinMapInfo();
}
@@ -197,14 +224,17 @@ namespace PepperDash.Essentials.Core
// Get the joins of each type and print them
Debug.Console(0, "Digitals:");
var digitals = Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Digital) == eJoinType.Digital).ToDictionary(j => j.Key, j => j.Value);
Debug.Console(2, "Found {0} Digital Joins", digitals.Count);
PrintJoinList(GetSortedJoins(digitals));
Debug.Console(0, "Analogs:");
var analogs = Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Analog) == eJoinType.Analog).ToDictionary(j => j.Key, j => j.Value);
Debug.Console(2, "Found {0} Analog Joins", analogs.Count);
PrintJoinList(GetSortedJoins(analogs));
Debug.Console(0, "Serials:");
var serials = Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Serial) == eJoinType.Serial).ToDictionary(j => j.Key, j => j.Value);
Debug.Console(2, "Found {0} Serial Joins", serials.Count);
PrintJoinList(GetSortedJoins(serials));
}
@@ -410,26 +440,32 @@ namespace PepperDash.Essentials.Core
_data = customJoinData;
}
public string GetNameAttribute()
public string GetNameAttribute(Type t)
{
string name = string.Empty;
JoinNameAttribute attribute = (JoinNameAttribute)Attribute.GetCustomAttribute(typeof(JoinDataComplete), typeof(JoinNameAttribute));
JoinNameAttribute attribute = (JoinNameAttribute)Attribute.GetCustomAttribute(t, typeof(JoinNameAttribute));
if (attribute != null)
{
name = attribute.Name;
Debug.Console(2, "JoinName Attribute value: {0}", name);
}
return name;
}
}
[AttributeUsage(AttributeTargets.Field)]
[AttributeUsage(AttributeTargets.All)]
public class JoinNameAttribute : Attribute
{
public string Name { get; set; }
private string _Name;
public JoinNameAttribute(string name)
{
Name = name;
_Name = name;
}
public string Name
{
get { return _Name; }
}
}
}