using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core;
using Tango.Integration.Operation;
using Tango.Integration.ExternalBridge;
using Tango.PMR.Diagnostics;
using Tango.PPC.Common.Application;
using Tango.PPC.Common.Connection;
namespace Tango.PPC.Common.Diagnostics
{
///
/// Represents the default diagnostics frame provider.
///
///
public class DefaultDiagnosticsFrameProvider : ExtendedObject, IDiagnosticsFrameProvider
{
private IMachineProvider _machineProvider;
private bool _disable;
///
/// Disables the frame delivery from the current connected machine and enables the manual push frame method.
///
public bool Disable
{
get { return _disable; }
set
{
_disable = value;
}
}
///
/// Occurs when a new data frame is available.
///
public event EventHandler FrameReceived;
///
/// Initializes a new instance of the class.
///
/// The application manager.
public DefaultDiagnosticsFrameProvider(IMachineProvider machineProvider)
{
_machineProvider = machineProvider;
machineProvider.MachineOperator.DiagnosticsDataAvailable += MachineOperator_DiagnosticsDataAvailable;
}
///
/// Handles the Machine Operator Diagnostics Data Available event.
///
/// The source of the event.
/// The event arguments.
private void MachineOperator_DiagnosticsDataAvailable(object sender, StartDiagnosticsResponse frame)
{
if (!Disable)
{
OnFrameReceived(frame);
}
}
///
/// Push frames manual. (Only when Disable = true)
///
/// The frame.
public void PushFrame(StartDiagnosticsResponse frame)
{
if (Disable)
{
OnFrameReceived(frame);
}
}
///
/// Raises the event.
///
/// The frame.
protected virtual void OnFrameReceived(StartDiagnosticsResponse frame)
{
FrameReceived?.Invoke(this, frame);
}
}
}