MersurementOp presunuta do Camera komponentu.

This commit is contained in:
Milan Hanajik
2017-01-27 09:56:58 +01:00
parent e8966f6705
commit 2a4d95bd7b
@@ -10,10 +10,14 @@ using System.Threading;
using System.Timers;
using log4net;
using Config.Entities;
using TBF.BenchControl.Network.Telnet;
namespace TBF.BenchControl.Network.Camera.CLP1611
{
public class Camera : ComponentBase, GenericDevices.ICamera, Generic.IDevice
/// <summary>
/// This class implements: (1) Camera device, (2) Measurement operation
/// </summary>
public class Camera : ComponentBase, GenericDevices.ICamera, Generic.IDevice, IOperation
{
private static readonly ILog log = LogManager.GetLogger(typeof(Camera));
public override string ToString()
@@ -165,30 +169,6 @@ namespace TBF.BenchControl.Network.Camera.CLP1611
public IOperation LiveStreamOp(bool hiRes)
{
return new LiveStreamOp(this, Telnet, hiRes ? "clp/hrlivestream.sh" : "clp/livestream.sh");
}
public IOperation MeasurementOp()
{
if (Telnet != null)
{
return new MeasurementOp(this, NetAdapter.IPAddress.ToString(), measurementUdpPortNr, roiParams);
}
else
{
return null;
}
}
public IOperation GrabImageOp()
{
return null;
}
/// <summary>
/// Detect the camera with specified hardware address (DIP switches)
/// </summary>
@@ -293,6 +273,86 @@ namespace TBF.BenchControl.Network.Camera.CLP1611
}
public IOperation LiveStreamOp(bool hiRes)
{
return new LiveStreamOp(this, Telnet, hiRes ? "clp/hrlivestream.sh" : "clp/livestream.sh");
}
public IOperation GrabImageOp()
{
return null;
}
public IOperation MeasurementOp()
{
if (Telnet != null)
{
//new MeasurementOp(this, NetAdapter.IPAddress.ToString(), measurementUdpPortNr, roiParams);
return this;
}
else
{
return null;
}
}
string command;
bool measurementCommandSent;
bool connectionEstablished;
public void Start()
{
/// Prepare the telent command
StringBuilder sb = new StringBuilder();
foreach (var s in roiParams) sb.AppendFormat(" {0}", s);
command = string.Format("clp/Measurement -udp {0} {1}{2}{3} 1 1 0 0 0",
ipAddress,
measurementUdpPortNr,
CameraCfg.UseTestImages ? (" -l " + CameraCfg.TestImagesCount.ToString()) : string.Empty,
sb);
measurementCommandSent = false;
connectionEstablished = false;
/// If ready send (=enqueue) the command
if (Telnet.State == TelnetClient.TelnetState.Inactive)
{
Telnet.Enqueue(new Telnet.Command(CmdAction.SEND_STRING, command));
measurementCommandSent = true;
}
}
public Event Run()
{
if (!measurementCommandSent)
{
/// When ready send (=enqueue) the command
if (Telnet.State == TelnetClient.TelnetState.Inactive)
{
Telnet.Enqueue(new Telnet.Command(CmdAction.SEND_STRING, command));
measurementCommandSent = true;
}
}
else if (!connectionEstablished)
{
connectionEstablished = true;
}
return Event.None;
}
public void Stop()
{
if (measurementCommandSent)
{
Telnet.Enqueue(new Telnet.Command(CmdAction.SEND_COMMAND, TelnetClient.CtrlCCommand));
}
}
void MeasurementUdpListener()
{
StringBuilder toBeProcessed = new StringBuilder();