mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-16 05:05:00 +00:00
Compare commits
20 Commits
hotfix/fil
...
1.13.5-hot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c4c44d02f5 | ||
|
|
3716dd0824 | ||
|
|
ebe8ee5653 | ||
|
|
372cf86613 | ||
|
|
67c99a9ad4 | ||
|
|
31085d42a9 | ||
|
|
39e1e5167b | ||
|
|
7f916d1d2f | ||
|
|
7c7f087898 | ||
|
|
898dab1d9a | ||
|
|
c53cad8119 | ||
|
|
82e8b4b203 | ||
|
|
8c3b891255 | ||
|
|
10fc8ee30b | ||
|
|
8da8b8c584 | ||
|
|
c7e0326b8c | ||
|
|
465aa947cf | ||
|
|
3b2fa8aec5 | ||
|
|
ffa864c71b | ||
|
|
112a2b7382 |
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
using PepperDash.Essentials.Core;
|
using PepperDash.Essentials.Core;
|
||||||
@@ -8,6 +9,7 @@ namespace PepperDash_Essentials_Core.Devices
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interface for any device that is able to control it'spower and has a configurable reboot time
|
/// Interface for any device that is able to control it'spower and has a configurable reboot time
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Obsolete("PepperDash_Essentials_Core.Devices is Deprecated - use PepperDash.Essentials.Core")]
|
||||||
public interface IHasPowerCycle : IKeyName, IHasPowerControlWithFeedback
|
public interface IHasPowerCycle : IKeyName, IHasPowerControlWithFeedback
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -24,6 +26,7 @@ namespace PepperDash_Essentials_Core.Devices
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interface for any device that contains a collection of IHasPowerReboot Devices
|
/// Interface for any device that contains a collection of IHasPowerReboot Devices
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Obsolete("PepperDash_Essentials_Core.Devices is Deprecated - use PepperDash.Essentials.Core")]
|
||||||
public interface IHasControlledPowerOutlets : IKeyName
|
public interface IHasControlledPowerOutlets : IKeyName
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
using Crestron.SimplSharp;
|
||||||
|
using PepperDash.Core;
|
||||||
|
|
||||||
|
namespace PepperDash.Essentials.Core
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interface for any device that has a battery that can be monitored
|
||||||
|
/// </summary>
|
||||||
|
public interface IHasBatteryStats : IKeyName
|
||||||
|
{
|
||||||
|
int BatteryPercentage { get; }
|
||||||
|
int BatteryCautionThresholdPercentage { get; }
|
||||||
|
int BatteryWarningThresholdPercentage { get; }
|
||||||
|
BoolFeedback BatteryIsWarningFeedback { get; }
|
||||||
|
BoolFeedback BatteryIsCautionFeedback { get; }
|
||||||
|
BoolFeedback BatteryIsOkFeedback { get; }
|
||||||
|
IntFeedback BatteryPercentageFeedback { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Interface for any device that has a battery that can be monitored and the ability to charge and discharge
|
||||||
|
/// </summary>
|
||||||
|
public interface IHasBatteryCharging : IHasBatteryStats
|
||||||
|
{
|
||||||
|
BoolFeedback BatteryIsCharging { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Interface for any device that has multiple batteries that can be monitored
|
||||||
|
/// </summary>
|
||||||
|
public interface IHasBatteries : IKeyName
|
||||||
|
{
|
||||||
|
ReadOnlyDictionary<string, IHasBatteryStats> Batteries { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IHasBatteryStatsExtended : IHasBatteryStats
|
||||||
|
{
|
||||||
|
int InputVoltage { get; }
|
||||||
|
int OutputVoltage { get; }
|
||||||
|
int InptuCurrent { get; }
|
||||||
|
int OutputCurrent { get; }
|
||||||
|
|
||||||
|
IntFeedback InputVoltageFeedback { get; }
|
||||||
|
IntFeedback OutputVoltageFeedback { get; }
|
||||||
|
IntFeedback InputCurrentFeedback { get; }
|
||||||
|
IntFeedback OutputCurrentFeedback { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Interface for any device that is able to control its power, has a configurable reboot time, and has batteries that can be monitored
|
||||||
|
/// </summary>
|
||||||
|
public interface IHasPowerCycleWithBattery : IHasPowerCycle, IHasBatteryStats
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Interface for any device that is able to control it's power and has a configurable reboot time
|
||||||
|
/// </summary>
|
||||||
|
public interface IHasPowerCycle : IKeyName, IHasPowerControlWithFeedback
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Delay between power off and power on for reboot
|
||||||
|
/// </summary>
|
||||||
|
int PowerCycleTimeMs { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reboot outlet
|
||||||
|
/// </summary>
|
||||||
|
void PowerCycle();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Interface for any device that contains a collection of IHasPowerReboot Devices
|
||||||
|
/// </summary>
|
||||||
|
public interface IHasControlledPowerOutlets : IKeyName
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Collection of IPduOutlets
|
||||||
|
/// </summary>
|
||||||
|
ReadOnlyDictionary<int, IHasPowerCycle> PduOutlets { get; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,18 +9,18 @@ using Crestron.SimplSharpPro.CrestronThread;
|
|||||||
|
|
||||||
namespace PepperDash.Essentials.Core
|
namespace PepperDash.Essentials.Core
|
||||||
{
|
{
|
||||||
public static class FileIO
|
public static class FileIO
|
||||||
{
|
{
|
||||||
|
|
||||||
static CCriticalSection fileLock = new CCriticalSection();
|
static CCriticalSection fileLock = new CCriticalSection();
|
||||||
public delegate void GotFileEventHandler(object sender, FileEventArgs e);
|
public delegate void GotFileEventHandler(object sender, FileEventArgs e);
|
||||||
public static event GotFileEventHandler GotFileEvent;
|
public static event GotFileEventHandler GotFileEvent;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the full file info from a path/filename, can include wildcards.
|
/// Get the full file info from a path/filename, can include wildcards.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileName"></param>
|
/// <param name="fileName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static FileInfo[] GetFiles(string fileName)
|
public static FileInfo[] GetFiles(string fileName)
|
||||||
{
|
{
|
||||||
string fullFilePath = Global.FilePathPrefix + fileName;
|
string fullFilePath = Global.FilePathPrefix + fileName;
|
||||||
@@ -54,228 +54,228 @@ namespace PepperDash.Essentials.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the data from string path/filename
|
/// Get the data from string path/filename
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileName"></param>
|
/// <param name="fileName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string ReadDataFromFile(string fileName)
|
public static string ReadDataFromFile(string fileName)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return ReadDataFromFile(GetFile(fileName));
|
return ReadDataFromFile(GetFile(fileName));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO read failed: \r{0}", e);
|
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO read failed: \r{0}", e);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the data with fileInfo object
|
/// Get the data with fileInfo object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileName"></param>
|
/// <param name="fileName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string ReadDataFromFile(FileInfo file)
|
public static string ReadDataFromFile(FileInfo file)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (fileLock.TryEnter())
|
if (fileLock.TryEnter())
|
||||||
{
|
{
|
||||||
DirectoryInfo dirInfo = new DirectoryInfo(file.DirectoryName);
|
DirectoryInfo dirInfo = new DirectoryInfo(file.DirectoryName);
|
||||||
Debug.Console(2, "FileIO Getting Data {0}", file.FullName);
|
Debug.Console(2, "FileIO Getting Data {0}", file.FullName);
|
||||||
|
|
||||||
if (File.Exists(file.FullName))
|
if (File.Exists(file.FullName))
|
||||||
{
|
{
|
||||||
using (StreamReader r = new StreamReader(file.FullName))
|
using (StreamReader r = new StreamReader(file.FullName))
|
||||||
{
|
{
|
||||||
return r.ReadToEnd();
|
return r.ReadToEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Console(2, "File {0} does not exsist", file.FullName);
|
Debug.Console(2, "File {0} does not exsist", file.FullName);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Error, "FileIO Unable to enter FileLock");
|
Debug.Console(0, Debug.ErrorLogLevel.Error, "FileIO Unable to enter FileLock");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO read failed: \r{0}", e);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (fileLock != null && !fileLock.Disposed)
|
||||||
|
fileLock.Leave();
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
}
|
||||||
{
|
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO read failed: \r{0}", e);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (fileLock != null && !fileLock.Disposed)
|
|
||||||
fileLock.Leave();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void ReadDataFromFileASync(string fileName)
|
public static void ReadDataFromFileASync(string fileName)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ReadDataFromFileASync(GetFile(fileName));
|
ReadDataFromFileASync(GetFile(fileName));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO read failed: \r{0}", e);
|
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO read failed: \r{0}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ReadDataFromFileASync(FileInfo file)
|
public static void ReadDataFromFileASync(FileInfo file)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CrestronInvoke.BeginInvoke(o => _ReadDataFromFileASync(file));
|
CrestronInvoke.BeginInvoke(o => _ReadDataFromFileASync(file));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO read failed: \r{0}", e);
|
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO read failed: \r{0}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void _ReadDataFromFileASync(FileInfo file)
|
private static void _ReadDataFromFileASync(FileInfo file)
|
||||||
{
|
{
|
||||||
string data;
|
string data;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (fileLock.TryEnter())
|
if (fileLock.TryEnter())
|
||||||
{
|
{
|
||||||
DirectoryInfo dirInfo = new DirectoryInfo(file.Name);
|
DirectoryInfo dirInfo = new DirectoryInfo(file.Name);
|
||||||
Debug.Console(2, "FileIO Getting Data {0}", file.FullName);
|
Debug.Console(2, "FileIO Getting Data {0}", file.FullName);
|
||||||
|
|
||||||
|
|
||||||
if (File.Exists(file.FullName))
|
if (File.Exists(file.FullName))
|
||||||
{
|
{
|
||||||
using (StreamReader r = new StreamReader(file.FullName))
|
using (StreamReader r = new StreamReader(file.FullName))
|
||||||
{
|
{
|
||||||
data = r.ReadToEnd();
|
data = r.ReadToEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Console(2, "File {0} Does not exsist", file.FullName);
|
Debug.Console(2, "File {0} Does not exsist", file.FullName);
|
||||||
data = "";
|
data = "";
|
||||||
}
|
}
|
||||||
GotFileEvent.Invoke(null, new FileEventArgs(data));
|
GotFileEvent.Invoke(null, new FileEventArgs(data));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Error, "FileIO Unable to enter FileLock");
|
Debug.Console(0, Debug.ErrorLogLevel.Error, "FileIO Unable to enter FileLock");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO read failed: \r{0}", e);
|
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO read failed: \r{0}", e);
|
||||||
data = "";
|
data = "";
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (fileLock != null && !fileLock.Disposed)
|
if (fileLock != null && !fileLock.Disposed)
|
||||||
fileLock.Leave();
|
fileLock.Leave();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="data"></param>
|
/// <param name="data"></param>
|
||||||
/// <param name="filePath"></param>
|
/// <param name="filePath"></param>
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="data"></param>
|
/// <param name="data"></param>
|
||||||
/// <param name="filePath"></param>
|
/// <param name="filePath"></param>
|
||||||
public static void WriteDataToFile(string data, string filePath)
|
public static void WriteDataToFile(string data, string filePath)
|
||||||
{
|
{
|
||||||
Thread _WriteFileThread;
|
Thread _WriteFileThread;
|
||||||
_WriteFileThread = new Thread((O) => _WriteFileMethod(data, Global.FilePathPrefix + "/" + filePath), null, Thread.eThreadStartOptions.CreateSuspended);
|
_WriteFileThread = new Thread((O) => _WriteFileMethod(data, Global.FilePathPrefix + "/" + filePath), null, Thread.eThreadStartOptions.CreateSuspended);
|
||||||
_WriteFileThread.Priority = Thread.eThreadPriority.LowestPriority;
|
_WriteFileThread.Priority = Thread.eThreadPriority.LowestPriority;
|
||||||
_WriteFileThread.Start();
|
_WriteFileThread.Start();
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Notice, "New WriteFile Thread");
|
Debug.Console(0, Debug.ErrorLogLevel.Notice, "New WriteFile Thread");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static object _WriteFileMethod(string data, string filePath)
|
static object _WriteFileMethod(string data, string filePath)
|
||||||
{
|
{
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to write file: '{0}'", filePath);
|
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to write file: '{0}'", filePath);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (fileLock.TryEnter())
|
if (fileLock.TryEnter())
|
||||||
{
|
{
|
||||||
|
|
||||||
using (StreamWriter sw = new StreamWriter(filePath))
|
using (StreamWriter sw = new StreamWriter(filePath))
|
||||||
{
|
{
|
||||||
sw.Write(data);
|
sw.Write(data);
|
||||||
sw.Flush();
|
sw.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Error, "FileIO Unable to enter FileLock");
|
Debug.Console(0, Debug.ErrorLogLevel.Error, "FileIO Unable to enter FileLock");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO write failed: \r{0}", e);
|
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO write failed: \r{0}", e);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (fileLock != null && !fileLock.Disposed)
|
if (fileLock != null && !fileLock.Disposed)
|
||||||
fileLock.Leave();
|
fileLock.Leave();
|
||||||
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool FileIoUnitTest()
|
public static bool FileIoUnitTest()
|
||||||
{
|
{
|
||||||
var testData = "Testing FileIO";
|
var testData = "Testing FileIO";
|
||||||
FileIO.WriteDataToFile(testData, "\\user\\FileIOTest.pdt");
|
FileIO.WriteDataToFile(testData, "\\user\\FileIOTest.pdt");
|
||||||
|
|
||||||
var file = FileIO.GetFile("\\user\\*FileIOTest*");
|
var file = FileIO.GetFile("\\user\\*FileIOTest*");
|
||||||
|
|
||||||
|
var readData = FileIO.ReadDataFromFile(file);
|
||||||
|
Debug.Console(0, "Returned {0}", readData);
|
||||||
|
File.Delete(file.FullName);
|
||||||
|
if (testData == readData)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var readData = FileIO.ReadDataFromFile(file);
|
}
|
||||||
Debug.Console(0, "Returned {0}", readData);
|
public class FileEventArgs
|
||||||
File.Delete(file.FullName);
|
{
|
||||||
if (testData == readData)
|
public FileEventArgs(string data) { Data = data; }
|
||||||
{
|
public string Data { get; private set; } // readonly
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public class FileEventArgs
|
|
||||||
{
|
|
||||||
public FileEventArgs(string data) { Data = data; }
|
|
||||||
public string Data { get; private set; } // readonly
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -200,6 +200,7 @@
|
|||||||
<Compile Include="Crestron IO\Relay\GenericRelayDevice.cs" />
|
<Compile Include="Crestron IO\Relay\GenericRelayDevice.cs" />
|
||||||
<Compile Include="Crestron IO\Relay\ISwitchedOutput.cs" />
|
<Compile Include="Crestron IO\Relay\ISwitchedOutput.cs" />
|
||||||
<Compile Include="Crestron IO\StatusSign\StatusSignController.cs" />
|
<Compile Include="Crestron IO\StatusSign\StatusSignController.cs" />
|
||||||
|
<Compile Include="Devices\PowerInterfaces.cs" />
|
||||||
<Compile Include="Web\RequestHandlers\AppDebugRequestHandler.cs" />
|
<Compile Include="Web\RequestHandlers\AppDebugRequestHandler.cs" />
|
||||||
<Compile Include="Web\RequestHandlers\GetFeedbacksForDeviceRequestHandler.cs" />
|
<Compile Include="Web\RequestHandlers\GetFeedbacksForDeviceRequestHandler.cs" />
|
||||||
<Compile Include="Web\EssentialsWebApiHelpers.cs" />
|
<Compile Include="Web\EssentialsWebApiHelpers.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user