tbf/TBF/Rig/Network/Camera/RoiForFixedStartCJMS11/Roi.cs
Michal Buzik 0daefb93bb Add CJMS11 enhancements, logging, and resolution support
- Extended CJMS11 camera handling with new functionalities, including image grabbing, resolution configuration, and improved ROI support.
- Added new `ToString` method implementations for enhanced debugging and logging in key classes like `JmsMessage`, `JmsPacket`, and `RoiCfg`.
- Introduced additional commands (`start_stream_images`, `stop_stream_images`) in `CommandM` and its enum.
- Implemented new resolution handling in `RoiCfg` with support for configurable image frames.
- Refactored resolution-related UI elements in `RoiCfgCtrl` to add a dropdown for selecting resolution.
- Made minor UX improvements by replacing inconsistent string formats with verbatim strings in console messages.
- Updated project dependencies with new resolution-related utilities (`Frame` and `ResolutionFrames`).
- Resolved camera-specific symbolic issues by transitioning to `CJMS11.Camera` over prior naming inconsistencies.
2025-07-18 08:50:22 +02:00

145 lines
4.2 KiB
C#

///
/// Copyright (c) 2017-2021 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
using System.Text;
using log4net;
using Common;
using Config.Entities;
using TBF.Rig.GenericDevices;
namespace TBF.Rig.Network.Camera.RoiForFixedStartCJMS11
{
public class Roi : ComponentBase, GenericDevices.IRegReaderStillCamera
{
/// TODO: Implement support for sharing one camera by multiple ROI-s
private static readonly ILog log = LogManager.GetLogger(typeof(Roi));
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
readonly RoiCfg roiCfg;
///
/// Camera and ICamera
///
public readonly CJMS11.Camera NetCamera;
public GenericDevices.ICamera Camera { get { return NetCamera as GenericDevices.ICamera; } }
public int Position
{
get
{
int firstDigitPos = Name.IndexOfAny(new char[] { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' });
int position;
return (firstDigitPos < 0) ? 0 : (int.TryParse(Name.Substring(firstDigitPos), out position) ? position : 0);
}
}
public RegisterReaderType RegisterReaderType { get { return RegisterReaderType.Manual; } }
public double PulsesPerLtr { get { return roiCfg.ProcParams.PulsesPerLtr; } }
public double LtrsPerPulse { get { return (PulsesPerLtr <= float.Epsilon) ? 1.0 : (1 / PulsesPerLtr); } }
double beginWMState;
public double BeginWMState
{
get { return beginWMState; }
set { beginWMState = value; }
}
double endWMState;
public double EndWMState
{
get { return endWMState; }
set { endWMState = value; }
}
public double WMVolume { get { return endWMState - beginWMState; } }
public int WMPulses { get { return (int)(WMVolume / LtrsPerPulse); } }
public int WMRefPulses { get { return StateMachine.ControlBoardMain.RefPulses; ; } }
public Roi() { }
public Roi(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
: base(cfg)
{
roiCfg = cfg as RoiCfg;
NetCamera = TbfComponents.FindComponent(cfg.ParentName, components) as CJMS11.Camera;
log.Warn(this.ToString());
}
public override void Initialize()
{
Clear();
}
#region Configuration Change Handling
public static void OnCfgChange(object sender, CfgChangeArgs args)
{
if (CfgChangeHandler == null) return;
try { CfgChangeHandler(sender, args); }
catch (Exception e) { log.Error("CfgChangeHandler(...) failed", e); }
}
public static event EventHandler<CfgChangeArgs> CfgChangeHandler;
public override void StartChangeHandler()
{
CfgChangeHandler += delegate(object sender, CfgChangeArgs args)
{
RoiCfg tmpcfg = args.Cfg as RoiCfg;
if (tmpcfg != null && tmpcfg.Name.Equals(Name))
{
if (args.Command == CfgChangeCmd.CfgChange)
{
roiCfg.BlackAndWhite = tmpcfg.BlackAndWhite;
roiCfg.LowResolution = tmpcfg.LowResolution;
roiCfg.ImageRotation = tmpcfg.ImageRotation;
}
}
};
}
#endregion Configuration Change Handling
public void Clear()
{
log.DebugFormat("{0}:Clear()", Name);
beginWMState = 0;
endWMState = 0;
}
public IOperation GrabImageOp(string imageFileName)
{
return GrabImageOp(imageFileName, roiCfg.BlackAndWhite, roiCfg.LowResolution, roiCfg.ImageRotation);
}
public IOperation GrabImageOp(string imageFileName,
bool blackAndWhite, bool lowResolution, ImageRotation imageRotation)
{
if (NetCamera != null)
{
///TODO BUMI - implementing grabing multiple images
/// 1. Create a list of image file names
/// 2. implement count of images to grab
/// 3. implement grabing multiple images
/// TODO: Implement support for sharing one camera by multiple ROI-s
return NetCamera.GrabImagesOp(new string[] { imageFileName }, blackAndWhite, lowResolution, imageRotation);
}
else
return null;
}
public IValve GetValve()
{
return null;
}
}
}