using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL;
using Tango.BL.Entities;
using Tango.Integration.Operation;
using Tango.PMR.Integration;
using Tango.Settings;
using Tango.Transport.Adapters;
using Tango.Transport.Transporters;
namespace Tango.Integration.ExternalBridge
{
///
/// Represents an external bridge USB client.
///
///
/// This isn't really an external bridge client, but merely a transporter for communicating with a Tango machine embedded device.
///
///
///
public class ExternalBridgeUsbClient : MachineOperator, IExternalBridgeClient
{
private String _serialNumber;
///
/// Gets the machine serial number.
///
public String SerialNumber
{
get { return _serialNumber; }
set
{
_serialNumber = value;
RaisePropertyChangedAuto();
}
}
private String _comPort;
///
/// Gets or sets the serial COM port.
///
public String ComPort
{
get { return _comPort; }
set { _comPort = value; RaisePropertyChangedAuto(); }
}
private UsbSerialBaudRates _baudRate;
///
/// Gets or sets the baud rate.
///
public UsbSerialBaudRates BaudRate
{
get { return _baudRate; }
set { _baudRate = value; RaisePropertyChangedAuto(); }
}
private String _Device;
///
/// Gets or sets the USB device name.
///
public String Device
{
get { return _Device; }
set { _Device = value; RaisePropertyChangedAuto(); }
}
///
/// Gets or sets a value indicating whether transport compression is required by the remote machine.
///
public bool CompressionEnabled { get; set; }
///
/// Connects the transport component.
///
///
public override async Task Connect()
{
if (Status != MachineStatuses.Upgrading)
{
await Disconnect();
Adapter = new UsbTransportAdapter(ComPort) { BaudRate = BaudRate };
}
await base.Connect();
}
///
/// Gets a value indicating whether this client requires authentication.
///
public bool RequiresAuthentication => false;
///
/// Initializes a new instance of the class.
///
/// The COM port.
/// The device.
public ExternalBridgeUsbClient(String comPort, String device,UsbSerialBaudRates baudRate = UsbSerialBaudRates.BR_115200)
{
ComponentName = $"External Bridge USB Client {_component_counter++}";
ComPort = comPort;
Device = device;
BaudRate = baudRate;
UseKeepAlive = false;
EnableDiagnostics = true;
}
///
/// Returns a that represents this instance.
///
///
/// A that represents this instance.
///
public override string ToString()
{
return Device;
}
///
/// Gets the database machine associated with this client.
///
public Machine Machine { get; private set; }
///
/// Sets the database machine.
///
/// The machine.
public void SetMachine(Machine machine)
{
Machine = machine;
}
}
}