using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using PepperDash.Core;
using Serilog.Events;
namespace PepperDash.Essentials.Core.Devices;
///
/// A device that monitors the communication status of a communication client. Useful for monitoring TCP, serial, or telnet clients.
///
public class GenericCommunicationMonitoredDevice : Device, ICommunicationMonitor
{
IBasicCommunication Client;
///
/// Gets or sets the CommunicationMonitor
///
public StatusMonitorBase CommunicationMonitor { get; private set; }
///
/// Constructor
///
/// key of the device
/// name of the device
/// communication client
/// poll string
/// poll time
/// warning time
/// error time
public GenericCommunicationMonitoredDevice(string key, string name, IBasicCommunication comm, string pollString,
long pollTime, long warningTime, long errorTime)
: base(key, name)
{
Client = comm;
CommunicationMonitor = new GenericCommunicationMonitor(this, Client, pollTime, warningTime, errorTime, pollString);
// ------------------------------------------------------DELETE THIS
CommunicationMonitor.StatusChange += (o, a) =>
{
Debug.LogMessage(LogEventLevel.Verbose, this, "Communication monitor status change: {0}", a.Status);
};
}
///
/// Constructor with default times
///
/// key of the device
/// name of the device
/// communication client
/// poll string
public GenericCommunicationMonitoredDevice(string key, string name, IBasicCommunication comm, string pollString)
: this(key, name, comm, pollString, 30000, 120000, 300000)
{
}
///
/// CustomActivate method
///
///
protected override bool CustomActivate()
{
CommunicationMonitor.Start();
return true;
}
///
/// Deactivate method
///
public override bool Deactivate()
{
CommunicationMonitor.Stop();
return true;
}
}