Pulling in 670 branch changes

This commit is contained in:
Heath Volmer
2018-02-08 12:35:08 -07:00
54 changed files with 58842 additions and 9907 deletions

View File

@@ -19,7 +19,7 @@ namespace PepperDash.Essentials
{
GenericHttpSseClient SseClient;
CCriticalSection FileLock;
//CCriticalSection FileLock;
/// <summary>
/// Prevents post operations from stomping on each other and getting lost
@@ -44,7 +44,7 @@ namespace PepperDash.Essentials
string SystemUuid;
public List<CotijaEssentialsHuddleSpaceRoomBridge> CotijaRooms { get; private set; }
public List<CotijaBridgeBase> CotijaRooms { get; private set; }
long ButtonHeartbeatInterval = 1000;
@@ -60,7 +60,7 @@ namespace PepperDash.Essentials
Config = config;
Debug.Console(0, this, "Mobile UI controller initializing for server:{0}", config.ServerUrl);
CotijaRooms = new List<CotijaEssentialsHuddleSpaceRoomBridge>();
CotijaRooms = new List<CotijaBridgeBase>();
//CrestronConsole.AddNewConsoleCommand(s => RegisterSystemToServer(),
// "CotiInitializeHttpClient", "Initializes a new HTTP client connection to a specified URL", ConsoleAccessLevelEnum.AccessOperator);
@@ -153,34 +153,37 @@ namespace PepperDash.Essentials
/// <param name="url">URL of the server, including the port number, if not 80. Format: "serverUrlOrIp:port"</param>
void RegisterSystemToServer()
{
#warning THIS SHOULD NOT GO until the config is ready - in cases of config populated from elsewhere (DDVC)
try
{
string filePath = string.Format(@"\NVRAM\Program{0}\configurationFile.json", Global.ControlSystem.ProgramNumber);
string postBody = null;
var confObject = ConfigReader.ConfigObject;
string postBody = JsonConvert.SerializeObject(confObject);
SystemUuid = confObject.SystemUuid;
if (string.IsNullOrEmpty(filePath))
{
Debug.Console(0, this, "Error reading file. No path specified.");
return;
}
//if (string.IsNullOrEmpty(filePath))
//{
// Debug.Console(0, this, "Error reading file. No path specified.");
// return;
//}
FileLock = new CCriticalSection();
#warning NEIL I think we need to review this usage. Don't think it ever blocks
// FileLock = new CCriticalSection();
//#warning NEIL I think we need to review this usage. Don't think it ever blocks
if (FileLock.TryEnter())
{
Debug.Console(1, this, "Reading configuration file to extract system UUID...");
// if (FileLock.TryEnter())
// {
// Debug.Console(1, this, "Reading configuration file to extract system UUID...");
postBody = File.ReadToEnd(filePath, Encoding.ASCII);
// postBody = File.ReadToEnd(filePath, Encoding.ASCII);
Debug.Console(2, this, "{0}", postBody);
// Debug.Console(2, this, "{0}", postBody);
FileLock.Leave();
}
// FileLock.Leave();
// }
if (string.IsNullOrEmpty(postBody))
{
Debug.Console(1, "Post Body is null or empty");
Debug.Console(1, this, "ERROR: Config post body is empty. Cannot register with server.");
}
else
{
@@ -188,11 +191,9 @@ namespace PepperDash.Essentials
Client = new HttpClient();
Client.Verbose = true;
Client.KeepAlive = true;
SystemUuid = Essentials.ConfigReader.ConfigObject.SystemUuid;
string url = string.Format("http://{0}/api/system/join/{1}", Config.ServerUrl, SystemUuid);
Debug.Console(1, this, "Sending config to {0}", url);
string url = string.Format("http://{0}/api/system/join/{1}", Config.ServerUrl, SystemUuid);
Debug.Console(1, this, "Joining server at {0}", url);
HttpClientRequest request = new HttpClientRequest();
request.Url.Parse(url);
@@ -200,13 +201,13 @@ namespace PepperDash.Essentials
request.Header.SetHeaderValue("Content-Type", "application/json");
request.ContentString = postBody;
Client.DispatchAsync(request, PostConnectionCallback);
var err = Client.DispatchAsync(request, PostConnectionCallback);
}
}
catch (Exception e)
{
Debug.Console(0, this, "Error Initilizing Room: {0}", e);
Debug.Console(0, this, "ERROR: Initilizing Room: {0}", e);
}
}
@@ -316,6 +317,7 @@ namespace PepperDash.Essentials
/// <param name="err"></param>
void PostConnectionCallback(HttpClientResponse resp, HTTP_CALLBACK_ERROR err)
{
Debug.Console(1, this, "PostConnectionCallback err: {0}", err);
try
{
if (resp != null && resp.Code == 200)
@@ -326,11 +328,7 @@ namespace PepperDash.Essentials
ServerReconnectTimer = null;
}
#warning The SSE Client from a previous session might need to be killed...
//if (SseClient == null)
//{
ConnectSseClient(null);
//}
ConnectSseClient(null);
}
else
{

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
namespace PepperDash.Essentials.Room.Cotija
{
public interface IDelayedConfiguration
{
event EventHandler<EventArgs> ConfigurationIsReady;
}
}

View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using PepperDash.Core;
using PepperDash.Essentials.Core;
namespace PepperDash.Essentials
{
/// <summary>
///
/// </summary>
public abstract class CotijaBridgeBase: Device
{
public CotijaSystemController Parent { get; private set; }
public CotijaBridgeBase(string key, string name)
: base(key, name)
{
}
/// <summary>
///
/// </summary>
/// <param name="parent"></param>
public void AddParent(CotijaSystemController parent)
{
Parent = parent;
}
}
}

View File

@@ -10,10 +10,13 @@ using Newtonsoft.Json.Linq;
using PepperDash.Core;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Room.Config;
namespace PepperDash.Essentials.Room.Cotija
{
public class CotijaDdvc01RoomBridge : Device
public class CotijaDdvc01RoomBridge : CotijaBridgeBase, IDelayedConfiguration
{
public class BoolJoin
{
@@ -108,17 +111,28 @@ namespace PepperDash.Essentials.Room.Cotija
public const uint ConfigRoomURI = 505;
}
/// <summary>
/// Fires when the config is ready, to be used by the controller class to forward config to server
/// </summary>
public event EventHandler<EventArgs> ConfigurationIsReady;
public ThreeSeriesTcpIpEthernetIntersystemCommunications EISC { get; private set; }
CotijaSystemController Parent;
/// <summary>
///
/// </summary>
public bool ConfigIsLoaded { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="name"></param>
/// <param name="ipId"></param>
public CotijaDdvc01RoomBridge(string key, string name, uint ipId)
: base(key, name)
{
Key = key;
try
{
EISC = new ThreeSeriesTcpIpEthernetIntersystemCommunications(ipId, "127.0.0.2", Global.ControlSystem);
@@ -133,22 +147,23 @@ namespace PepperDash.Essentials.Room.Cotija
}
/// <summary>
/// Finish wiring up everything after all devices are created
/// Finish wiring up everything after all devices are created. The base class will hunt down the related
/// parent controller and link them up.
/// </summary>
/// <returns></returns>
public override bool CustomActivate()
{
Parent = DeviceManager.AllDevices.FirstOrDefault(d => d is CotijaSystemController) as CotijaSystemController;
if (Parent == null)
{
Debug.Console(0, this, "ERROR: Cannot build CotijaDdvc01RoomBridge. System controller not present");
return false;
}
SetupFunctions();
SetupFeedbacks();
EISC.SigChange += EISC_SigChange;
EISC.OnlineStatusChange += (o, a) =>
{
if (a.DeviceOnLine)
LoadConfigValues();
};
// load config if it's already there
if (EISC.IsOnline) // || EISC.BooleanInput[BoolJoin.ConfigIsReady].BoolValue)
LoadConfigValues();
return base.CustomActivate();
}
@@ -234,8 +249,6 @@ namespace PepperDash.Essentials.Room.Cotija
// Config things
EISC.SetSigTrueAction(BoolJoin.ConfigIsReady, LoadConfigValues);
}
/// <summary>
@@ -243,7 +256,89 @@ namespace PepperDash.Essentials.Room.Cotija
/// </summary>
void LoadConfigValues()
{
Debug.Console(1, this, "Loading configuration from DDVC01 EISC bridge");
ConfigIsLoaded = false;
var co = ConfigReader.ConfigObject;
//Room
if (co.Rooms == null)
co.Rooms = new List<EssentialsRoomConfig>();
if (co.Rooms.Count == 0)
co.Rooms.Add(new EssentialsRoomConfig());
var rm = co.Rooms[0];
rm.Name = EISC.StringInput[501].StringValue;
rm.Key = "room1";
rm.Type = "ddvc01";
DDVC01RoomPropertiesConfig rmProps;
if (rm.Properties == null)
rmProps = new DDVC01RoomPropertiesConfig();
else
rmProps = JsonConvert.DeserializeObject<DDVC01RoomPropertiesConfig>(rm.Properties.ToString());
rmProps.Help = new EssentialsHelpPropertiesConfig();
rmProps.Help.Message = EISC.StringInput[502].StringValue;
rmProps.Help.CallButtonText = EISC.StringInput[503].StringValue;
rmProps.RoomPhoneNumber = EISC.StringInput[504].StringValue;
rmProps.RoomURI = EISC.StringInput[505].StringValue;
rmProps.SpeedDials = new List<DDVC01SpeedDial>();
// add speed dials as long as there are more - up to 4
for (uint i = 512; i <= 519; i = i + 2)
{
var num = EISC.StringInput[i].StringValue;
if (string.IsNullOrEmpty(num))
break;
var name = EISC.StringInput[i + 1].StringValue;
rmProps.SpeedDials.Add(new DDVC01SpeedDial { Number = num, Name = name});
}
// volume control names
var volCount = EISC.UShortInput[701].UShortValue;
rmProps.VolumeSliderNames = new List<string>();
for(uint i = 701; i <= 700 + volCount; i++)
{
rmProps.VolumeSliderNames.Add(EISC.StringInput[i].StringValue);
}
// There should be cotija devices in here, I think...
if(co.Devices == null)
co.Devices = new List<DeviceConfig>();
// Source list! This might be brutal!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
rmProps.SourceListKey = "default";
co.SourceLists = new Dictionary<string,Dictionary<string,SourceListItem>>();
var newSl = new Dictionary<string, SourceListItem>();
// add sources...
for (uint i = 0; i<= 19; i++)
{
var name = EISC.StringInput[601 + i].StringValue;
if(string.IsNullOrEmpty(name))
break;
var icon = EISC.StringInput[651 + i].StringValue;
var key = EISC.StringInput[671 + i].StringValue;
var type = EISC.StringInput[701 + i].StringValue;
var newSLI = new SourceListItem{
Icon = icon,
Name = name,
Order = (int)i + 1,
SourceKey = key,
};
// add dev to devices list
var devConf = new DeviceConfig {
Group = "ddvc01",
Key = key,
Name = name,
Type = type
};
co.Devices.Add(devConf);
}
co.SourceLists.Add("default", newSl);
Debug.Console(0, this, "******* CONFIG FROM DDVC: \r{0}", JsonConvert.SerializeObject(ConfigReader.ConfigObject, Formatting.Indented));
ConfigIsLoaded = true;
// send config changed status???

View File

@@ -10,15 +10,19 @@ using PepperDash.Essentials.Room.Cotija;
namespace PepperDash.Essentials
{
public class CotijaEssentialsHuddleSpaceRoomBridge
public class CotijaEssentialsHuddleSpaceRoomBridge : CotijaBridgeBase
{
CotijaSystemController Parent;
public EssentialsHuddleSpaceRoom Room { get; private set; }
public CotijaEssentialsHuddleSpaceRoomBridge(CotijaSystemController parent, EssentialsHuddleSpaceRoom room)
/// <summary>
///
/// </summary>
/// <param name="parent"></param>
/// <param name="room"></param>
public CotijaEssentialsHuddleSpaceRoomBridge(EssentialsHuddleSpaceRoom room):
base("cotijaController", "Cotija Controller")
{
Parent = parent;
Room = room;
// we add actions to the messaging system with a path, and a related action. Custom action