175 lines
4.9 KiB
C#
175 lines
4.9 KiB
C#
using Common;
|
|
using Config.Entities;
|
|
using log4net;
|
|
using System;
|
|
|
|
///
|
|
/// Copyright (c) 2017 Sensus Metering Systems
|
|
///
|
|
using System.IO;
|
|
using System.Xml.Serialization;
|
|
using TBF.Resources;
|
|
using TBF.Rig.Generic;
|
|
|
|
namespace TBF.Rig.Network.Camera.RoiForFixedStartCJMS11
|
|
{
|
|
public class ProcedureParams : ProcedureParamsBase, IParamsProvider, IProcedureParams
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(ProcedureParams));
|
|
|
|
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(ProcedureParams) })[0];
|
|
public override XmlSerializer GetSerializer() { return Serializer; }
|
|
|
|
///PulsePerMeter [l^-1]
|
|
public double PulsesPerLtr;
|
|
/// <summary>
|
|
/// delta time gap for send parameter
|
|
/// </summary>
|
|
/// <description>delta time for send parameter 500ms is minimum</description>
|
|
public int RoiDeltaTimeMs;
|
|
|
|
/// <summary>
|
|
/// count of picture for send > 1 / grabImage == 0|1 parameter - switch method
|
|
/// </summary>
|
|
/// <description>count of picture for send > 1 / grabImage == 0|1 parameter - switch method</description>
|
|
public int RoiPicCount;
|
|
|
|
string[] paramNames = new string[]
|
|
{
|
|
Strings.PulsesPerLtr,
|
|
Strings.PictureCouts,
|
|
Strings.DelaySendImage,
|
|
};
|
|
|
|
|
|
|
|
public override void InitializeAll()
|
|
{
|
|
PulsesPerLtr = 1.0;
|
|
RoiPicCount = 1; //default value 1 => grab Image
|
|
RoiDeltaTimeMs = 500; //delta time for send parameter 500ms is minimum
|
|
}
|
|
|
|
public override string ParamName(int i) { return paramNames[i]; }
|
|
public override int ParamsCount() { return paramNames.Length; }
|
|
|
|
public override string ToString(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: return PulsesPerLtr.ToString();
|
|
case 1: return RoiPicCount.ToString();
|
|
case 2: return RoiDeltaTimeMs.ToString();
|
|
default: return string.Empty;
|
|
}
|
|
}
|
|
|
|
/// Retrieves parameters from UI controls
|
|
public CfgUpdateFlags UpdateParam(int i, string strValue)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: PulsesPerLtr = Utils.ParseUDouble(strValue); return CfgUpdateFlags.None;
|
|
case 1: RoiPicCount = Int32.Parse(strValue); return CfgUpdateFlags.None;
|
|
case 2: RoiDeltaTimeMs = Int32.Parse(strValue); return CfgUpdateFlags.None;
|
|
default: return CfgUpdateFlags.None;
|
|
}
|
|
}
|
|
|
|
/// Verifies whether strings in UI controls represent valid parameters
|
|
public bool ValidateParam(int i, string strValue, out string message)
|
|
{
|
|
message = string.Empty;
|
|
|
|
double dummy;
|
|
int dummyInt;
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
if (Utils.TryParseUDouble(strValue, out dummy)) return true;
|
|
break;
|
|
case 1:
|
|
if (!Int32.TryParse(strValue, out dummyInt) || (dummyInt < 0 || dummyInt > 50))
|
|
{
|
|
message = ParamName(i) + " is invalid. Param must be between 0 and 50!";
|
|
return false;
|
|
}
|
|
return true;
|
|
case 2:
|
|
if (!Int32.TryParse(strValue, out dummyInt) || (dummyInt < 500 || dummyInt < 5500))
|
|
{
|
|
message = ParamName(i) + " is invalid. Param must be between 500 and 5500!";
|
|
return false;
|
|
}
|
|
return true;
|
|
default:
|
|
message = "Invalid index";
|
|
return false;
|
|
}
|
|
|
|
message = ParamName(i) + " is invalid";
|
|
return false;
|
|
}
|
|
|
|
void CopyContentTo(ProcedureParams prms)
|
|
{
|
|
prms.PulsesPerLtr = this.PulsesPerLtr;
|
|
prms.RoiDeltaTimeMs = this.RoiDeltaTimeMs;
|
|
prms.RoiPicCount = this.RoiPicCount;
|
|
}
|
|
|
|
public IParamsProvider Clone()
|
|
{
|
|
ProcedureParams pars = new ProcedureParams();
|
|
CopyContentTo(pars);
|
|
return pars;
|
|
}
|
|
|
|
public override bool UpdateFromDbEntity(ComponentProcedure dbEntity)
|
|
{
|
|
if (dbEntity == null) return false;
|
|
try
|
|
{
|
|
ProcedureParams tmp = Serializer.Deserialize(new StringReader(dbEntity.Parameters)) as ProcedureParams;
|
|
|
|
procedureParamsEntity = dbEntity;
|
|
componentName = dbEntity.CmpntName;
|
|
procedure = dbEntity.Procedure;
|
|
|
|
if (tmp != null)
|
|
{
|
|
tmp.CopyContentTo(this);
|
|
return true;
|
|
}
|
|
else return false;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.DebugFormat(
|
|
"Error during Procedure parameters deserialization. CmpntName='{0}', Procedure='{1}', Parameters='{2}', Exception: {3}",
|
|
dbEntity?.CmpntName,
|
|
dbEntity?.Procedure,
|
|
dbEntity?.Parameters,
|
|
ex
|
|
);
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public ProcedureParams() { }
|
|
|
|
public ProcedureParams(bool initialize)
|
|
{
|
|
if (initialize) InitializeAll();
|
|
}
|
|
|
|
public ProcedureParams(ComponentProcedure procedureParamsEntity, string componentName, Procedure procedure)
|
|
{
|
|
this.procedureParamsEntity = procedureParamsEntity;
|
|
this.componentName = componentName;
|
|
this.procedure = procedure;
|
|
}
|
|
}
|
|
}
|