- 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.
98 lines
2.8 KiB
C#
98 lines
2.8 KiB
C#
using System;
|
|
using System.Text.RegularExpressions;
|
|
using log4net;
|
|
using TBF.Rig.Network.Camera.CJMS11.POJO;
|
|
|
|
namespace TBF.Rig.Network.Camera.CJMS11
|
|
{
|
|
public class JmsPacket
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(JmsPacket));
|
|
|
|
private JmsMessage jmsMessage;
|
|
private string messageOrigin;
|
|
|
|
public string MessageOrigin { get => messageOrigin; }
|
|
|
|
public JmsMessage JmsMessage
|
|
{
|
|
get => jmsMessage;
|
|
set => jmsMessage = value;
|
|
}
|
|
|
|
public JmsPacket(string message)
|
|
{
|
|
messageOrigin = message;
|
|
|
|
try
|
|
{
|
|
if (ParseMessage(messageOrigin))
|
|
{
|
|
//success
|
|
}
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.Error("Error parsing message: " + e.Message);
|
|
}
|
|
}
|
|
|
|
private bool ParseMessage(string message)
|
|
{
|
|
message = message.Trim();
|
|
if (message.Length < 1) return false;
|
|
|
|
this.jmsMessage = JmsMessageFromString(message);
|
|
|
|
return true;
|
|
}
|
|
|
|
public static JmsMessage JmsMessageFromString(string message)
|
|
{
|
|
// Equivalent regex pattern
|
|
var pattern = new Regex(@"^(ACK|NACK):\s*(\S+)\s*(?:~(.*)~)?\s*END$", RegexOptions.Singleline);
|
|
|
|
var match = pattern.Match(message);
|
|
if (match.Success)
|
|
{
|
|
string status = match.Groups[1].Value;
|
|
string commandStr = match.Groups[2].Value;
|
|
string payload = match.Groups[3].Success ? match.Groups[3].Value : "";
|
|
|
|
return new JmsMessage(status, commandStr, payload);
|
|
}
|
|
else
|
|
{
|
|
throw new ArgumentException($"Message format not recognized: {message}");
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public static ParsedImage ImageParser(string payloadImage)
|
|
{
|
|
// Equivalent regex pattern
|
|
var imagePattern = new Regex(@"IMAGE:([A-Z0-9_]+):\s*(.*?)\s*~IMAGE_END", RegexOptions.Singleline);
|
|
|
|
var match = imagePattern.Match(payloadImage);
|
|
if (match.Success)
|
|
{
|
|
string encoding = match.Groups[1].Value;
|
|
string imageData = match.Groups[2].Value;
|
|
|
|
return new ParsedImage(ImageTypeEnum.GetCommandM(encoding), imageData);
|
|
}
|
|
else
|
|
{
|
|
throw new ArgumentException($"Payload does not match expected image format: {payloadImage}");
|
|
}
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Format("JmsPacket -> original message: {0} -> JmsMessage: {1}", messageOrigin, jmsMessage.ToString());
|
|
}
|
|
}
|
|
|
|
} |